提交 88812bb7 编写于 作者: Q qiaozzzh

XTS configuration

Signed-off-by: Nqiaozzzh <qiaozhang@huawei.com>
Change-Id: Ib34ecf79c0e160817a4805d80b19659f95788b13
上级 b59548bd
......@@ -18,25 +18,11 @@ import { describe, beforeAll, afterEach, it, expect } from "@ohos/hypium";
import * as asyCallback from "./utils/asysmmetricspec/publicAsymmetricSpecCallback";
import * as asyPromise from "./utils/asysmmetricspec/publicAsymmetricSpecPromise";
import * as common from "./utils/common/publicDoSpec";
import * as callback from "./utils/asymmetric/publicAsymmetricCallback";
import * as promise from "./utils/asymmetric/publicAsymmetricPromise";
function genRsa2048KeyPairSpec() {
return common.genRsa2048KeyPairSpec();
}
function genDsa2048CommonSpec() {
return common.genDsa2048CommonSpecBigE();
}
function genRsa2048CommonSpec() {
return common.genRsa2048CommonSpec();
}
function genRsa2048PubKetSpec() {
return common.genRsa2048PubKetSpec();
}
function genDsa2048KeyPairSpec() {
return common.genDsa2048KeyPairSpecBigE();
}
......@@ -49,76 +35,13 @@ function genEccKeyTypeSpec(keyType) {
return common.genEccKeySpec(keyType);
}
function genEccCommonSpecErr() {
let fieldFp = {
fieldType: "Fp",
p: BigInt("0xffffffffffffffffffffffffffffffff000000000000000000000001"),
};
let G = {
x: BigInt("0xb70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21"),
y: BigInt("0xbd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34"),
};
let eccCommonSpec = {
algName: "ECC",
specType: 5,
field: fieldFp,
a: BigInt("0xfffffffffffffffffffffffffffffffefffffffffffffffffffffffe"),
b: BigInt("0xb4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4"),
g: G,
n: BigInt("0xffffffffffffffffffffffffffff16a2e0b8f03e13dd29455c5c2a3d"),
h: 1,
};
return eccCommonSpec;
}
function genDsaKeyPairSpecErr() {
let dsaCommonSpec = common.genDsa2048CommonSpecBigE();
let dsaKeyPairSpec = {
algName: "DSA",
specType: cryptoFramework.AsyKeySpecType.KEY_PAIR_SPEC,
params: dsaCommonSpec,
sk: "111112222111",
pk: BigInt(
"0x178fa8118492ec8347c76ab092af5a2037a36479d2d03dcde061888821cc745dce4c5147f0c55c4c827aaf72adb9" +
"e053f278b7f0b5487f8a3a18d19f8b7da547b795ab98f87b7450568e57f0eef5b7baab8586f92bef4156a0a49fb73800460aa6f1f" +
"c1fd84e85449243215d6eccc2cb26310d21c4bd8d24bcd91819d7dcf1e7935048032cae2ee749885f9357279936b420abfca72bf2" +
"d998d7d4349d9650589aea54f3eef56314ee85837476e15295c3f7eb04047ba7281bccea4a4e84dad89c79d89b66892fcfacd779f" +
"9a9d8451378b90014c97e22518667b09f261123c838d7701d158e4d4f959740a1c27e011872f410e68d52167ff2c9f8338b33b7ce"
),
};
return dsaKeyPairSpec;
}
function genRsaKeyPairSpecErr() {
let nIn = BigInt(
"0x9260d0750ae117eee55c3f3deaba74917521a262ee76007cdf8a56755ad73a1598a1408410a01434c3f5bc54a88" +
"b57fa19fc4328daea0750a4c44e88cff3b2382621b80f670464433e4336e6d003e8cd65bff211da144b88291c2259a00a72b711c116ef7" +
"686e8fee34e4d933c868187bdc26f7be071493c86f7a5941c3510806ad67b0f94d88f5cf5c02a092821d8626e8932b65c5bd8c92049c21" +
"0932b7afa7ac59c0e886ae5c1edb00d8ce2c57633db26bd6639bff73cee82be9275c402b4cf2a4388da8cf8c64eefe1c5a0f5ab8057c39" +
"fa5c0589c3e253f0960332300f94bea44877b588e1edbde97cf2360727a09b775262d7ee552b3319b9266f05a25"
);
let rsaCommSpec = {
n: nIn,
algName: "RSA",
specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC,
};
let rsaKeyPairSpec = {
params: rsaCommSpec,
sk: "11121",
pk: "11121",
algName: "RSA",
specType: cryptoFramework.AsyKeySpecType.KEY_PAIR_SPEC,
};
return rsaKeyPairSpec;
}
export default function AsyKeyGeneratorBySpecJsunit() {
describe("AsyKeyGeneratorBySpecJsunit", function () {
console.info("##########start AsyKeyGeneratorBySpecJsunit##########");
beforeAll(function () {});
afterEach(function () {});
beforeAll(function () {
});
afterEach(function () {
});
/**
* @tc.number Security_CryptoFramework_GeneratorBySpec_Func_0100
......@@ -338,267 +261,5 @@ export default function AsyKeyGeneratorBySpecJsunit() {
done();
}
);
/**
* @tc.number Security_CryptoFramework_GeneratorBySpec_Func_0900
* @tc.name ECC PriKey generation Pubkey
* @tc.desc the asyKeySpec is eccPrikeySpec, Use the promise Style of Interface
*/
it(
"Security_CryptoFramework_GeneratorBySpec_Func_0900",
0,
async function (done) {
let asyKeyPairSpec = cryptoFramework.createAsyKeyGeneratorBySpec(
genEccKeyTypeSpec(cryptoFramework.AsyKeySpecType.PRIVATE_KEY_SPEC)
);
asyKeyPairSpec
.generatePubKey()
.then((pubKey) => {
console.log("pubKey" + pubKey);
expect(null).assertFail();
})
.catch((err) => {
console.error(
"generatePubTopriSpecFailed Security_CryptoFramework_GeneratorBySpec_Func_0900" +
" failed. error is " +
err
);
expect(err.code == 401).assertTrue();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_GeneratorBySpec_Func_1000
* @tc.name ECC PubKey generation Prikey
* @tc.desc the asyKeySpec is eccPubkeySpec, Use the callback Style of Interface
*/
it(
"Security_CryptoFramework_GeneratorBySpec_Func_1000",
0,
async function (done) {
let asyKeyPairSpec = cryptoFramework.createAsyKeyGeneratorBySpec(
genEccKeyTypeSpec(cryptoFramework.AsyKeySpecType.PUBLIC_KEY_SPEC)
);
asyKeyPairSpec
.generatePriKey()
.then((priKey) => {
console.log("priKey" + priKey);
expect(null).assertFail();
})
.catch((err) => {
console.error(
"generatePubTopriSpecFailed Security_CryptoFramework_GeneratorBySpec_Func_1000" +
" failed. error is " +
err
);
expect(err.code == 401).assertTrue();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_GeneratorBySpec_Func_1100
* @tc.name RSA Key generation scenario by spec
* @tc.desc the asyKeySpec is genRsa2048CommonSpec, Use the callback Style of Interface
*/
it(
"Security_CryptoFramework_GeneratorBySpec_Func_1100",
0,
async function (done) {
asyCallback
.generateByCommonSpec(genRsa2048CommonSpec(), "RSA")
.then((result) => {
console.log("result :" + result);
expect(null).assertFail();
})
.catch((err) => {
console.error(
"Security_CryptoFramework_GeneratorBySpec_Func_1100 catch err " +
err
);
expect(err.code == 401).assertTrue();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_GeneratorBySpec_Func_1200
* @tc.name RSA Key generation scenario by spec
* @tc.desc the asyKeySpec is genRsa2048PubKetSpec, Use the promise Style of Interface
*/
it(
"Security_CryptoFramework_GeneratorBySpec_Func_1200",
0,
async function (done) {
asyPromise
.generateByPubKeySpec(genRsa2048PubKetSpec(), "RSA")
.then((result) => {
expect(result).assertTrue();
})
.catch((err) => {
console.error(
"Security_CryptoFramework_GeneratorBySpec_Func_1200 catch err " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_GeneratorBySpec_Func_1300
* @tc.name RSA Key generation scenario by spec
* @tc.desc the asyKeySpec is genRsa2048KeyPairSpec, Use the promise Style of Interface
*/
it(
"Security_CryptoFramework_GeneratorBySpec_Func_1300",
0,
async function (done) {
asyPromise
.generateByKeyPairSpec(genRsa2048KeyPairSpec(), "RSA")
.then((result) => {
expect(result).assertTrue();
})
.catch((err) => {
console.error(
"Security_CryptoFramework_GeneratorBySpec_Func_1300 catch err " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_GeneratorBySpec_Func_1400
* @tc.name RSA pubKey generation prikey failed
* @tc.desc the asyKeySpec is genRsa2048PubKetSpec, Use the callback Style of Interface
*/
it(
"Security_CryptoFramework_GeneratorBySpec_Func_1400",
0,
async function (done) {
let asyKeyPairSpec = cryptoFramework.createAsyKeyGeneratorBySpec(
genRsa2048PubKetSpec()
);
asyKeyPairSpec
.generatePriKey()
.then((priKey) => {
console.log("priKey" + priKey);
expect(null).assertFail();
})
.catch((err) => {
console.error(
"generatePubTopriSpecFailed generateSpecAsyKeyPair failed. error is " +
err
);
expect(err.code == 401).assertTrue();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_GeneratorBySpec_Func_1500
* @tc.name create key parser failed
* @tc.desc Pass in an exception parameter error EccCommonStruct and call it as a async
* @tc.desc Pass in an exception parameter error RsaKeyPairStruct and call it as a async
* @tc.desc Pass in an exception parameter error DsaKeyPairStruct and call it as a async
*/
it(
"Security_CryptoFramework_GeneratorBySpec_Func_1500",
0,
async function (done) {
try {
cryptoFramework.createAsyKeyGeneratorBySpec(genEccCommonSpecErr());
expect(null).assertFail();
} catch (err) {
console.error(
"Security_CryptoFramework_GeneratorBySpec_Func_1500 catch err " +
err
);
expect(err.code == 401).assertTrue();
}
try {
cryptoFramework.createAsyKeyGeneratorBySpec(genRsaKeyPairSpecErr());
expect(null).assertFail();
} catch (err) {
console.error(
"Security_CryptoFramework_GeneratorBySpec_Func_1500 catch err " +
err
);
expect(err.code == 401).assertTrue();
}
try {
cryptoFramework.createAsyKeyGeneratorBySpec(genDsaKeyPairSpecErr());
expect(null).assertFail();
} catch (err) {
console.error(
"Security_CryptoFramework_GeneratorBySpec_Func_1500 catch err " +
err
);
expect(err.code == 401).assertTrue();
}
done();
}
);
/**
* @tc.number Security_CryptoFramework_GeneratorBySpec_Func_1600
* @tc.name relatively pubkey and prikey
* @tc.desc the asyKeySpec is genDsaKeyPairSpecErr, Use the promise Style of Interface
*/
it(
"Security_CryptoFramework_GeneratorBySpec_Func_1600",
0,
async function (done) {
promise
.keyGenerationBySpecProcess(genDsa2048KeyPairSpec())
.then((result) => {
expect(result).assertTrue();
})
.catch((err) => {
console.error(
"Security_CryptoFramework_GeneratorBySpec_Func_1600 catch err " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_GeneratorBySpec_Func_1700
* @tc.name relatively pubkey and prikey
* @tc.desc the asyKeySpec is "DSA", Use the callback Style of Interface
*/
it(
"Security_CryptoFramework_GeneratorBySpec_Func_1700",
0,
async function (done) {
callback
.keyGenerationBySpecProcess("DSA2048")
.then((result) => {
expect(result).assertTrue();
})
.catch((err) => {
console.error(
"Security_CryptoFramework_GeneratorBySpec_Func_1700 catch err " +
err
);
expect(null).assertFail();
});
done();
}
);
});
}
/*
* Copyright (C) 2022-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import cryptoFramework from "@ohos.security.cryptoFramework";
import { describe, beforeAll, afterEach, it, expect } from "@ohos/hypium";
import * as asyCallback from "./utils/asysmmetricspec/publicAsymmetricSpecCallback";
import * as asyPromise from "./utils/asysmmetricspec/publicAsymmetricSpecPromise";
import * as common from "./utils/common/publicDoSpec";
import * as callback from "./utils/asymmetric/publicAsymmetricCallback";
import * as promise from "./utils/asymmetric/publicAsymmetricPromise";
function genRsa2048KeyPairSpec() {
return common.genRsa2048KeyPairSpec();
}
function genRsa2048CommonSpec() {
return common.genRsa2048CommonSpec();
}
function genRsa2048PubKetSpec() {
return common.genRsa2048PubKetSpec();
}
function genDsa2048KeyPairSpec() {
return common.genDsa2048KeyPairSpecBigE();
}
function genEccKeyTypeSpec(keyType) {
return common.genEccKeySpec(keyType);
}
function genEccCommonSpecErr() {
let fieldFp = {
fieldType: "Fp",
p: BigInt("0xffffffffffffffffffffffffffffffff000000000000000000000001"),
};
let G = {
x: BigInt("0xb70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21"),
y: BigInt("0xbd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34"),
};
let eccCommonSpec = {
algName: "ECC",
specType: 5,
field: fieldFp,
a: BigInt("0xfffffffffffffffffffffffffffffffefffffffffffffffffffffffe"),
b: BigInt("0xb4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4"),
g: G,
n: BigInt("0xffffffffffffffffffffffffffff16a2e0b8f03e13dd29455c5c2a3d"),
h: 1,
};
return eccCommonSpec;
}
function genDsaKeyPairSpecErr() {
let dsaCommonSpec = common.genDsa2048CommonSpecBigE();
let dsaKeyPairSpec = {
algName: "DSA",
specType: cryptoFramework.AsyKeySpecType.KEY_PAIR_SPEC,
params: dsaCommonSpec,
sk: "111112222111",
pk: BigInt(
"0x178fa8118492ec8347c76ab092af5a2037a36479d2d03dcde061888821cc745dce4c5147f0c55c4c827aaf72adb9" +
"e053f278b7f0b5487f8a3a18d19f8b7da547b795ab98f87b7450568e57f0eef5b7baab8586f92bef4156a0a49fb73800460aa6f1f" +
"c1fd84e85449243215d6eccc2cb26310d21c4bd8d24bcd91819d7dcf1e7935048032cae2ee749885f9357279936b420abfca72bf2" +
"d998d7d4349d9650589aea54f3eef56314ee85837476e15295c3f7eb04047ba7281bccea4a4e84dad89c79d89b66892fcfacd779f" +
"9a9d8451378b90014c97e22518667b09f261123c838d7701d158e4d4f959740a1c27e011872f410e68d52167ff2c9f8338b33b7ce"
),
};
return dsaKeyPairSpec;
}
function genRsaKeyPairSpecErr() {
let nIn = BigInt(
"0x9260d0750ae117eee55c3f3deaba74917521a262ee76007cdf8a56755ad73a1598a1408410a01434c3f5bc54a88" +
"b57fa19fc4328daea0750a4c44e88cff3b2382621b80f670464433e4336e6d003e8cd65bff211da144b88291c2259a00a72b711c116ef7" +
"686e8fee34e4d933c868187bdc26f7be071493c86f7a5941c3510806ad67b0f94d88f5cf5c02a092821d8626e8932b65c5bd8c92049c21" +
"0932b7afa7ac59c0e886ae5c1edb00d8ce2c57633db26bd6639bff73cee82be9275c402b4cf2a4388da8cf8c64eefe1c5a0f5ab8057c39" +
"fa5c0589c3e253f0960332300f94bea44877b588e1edbde97cf2360727a09b775262d7ee552b3319b9266f05a25"
);
let rsaCommSpec = {
n: nIn,
algName: "RSA",
specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC,
};
let rsaKeyPairSpec = {
params: rsaCommSpec,
sk: "11121",
pk: "11121",
algName: "RSA",
specType: cryptoFramework.AsyKeySpecType.KEY_PAIR_SPEC,
};
return rsaKeyPairSpec;
}
export default function AsyKeyGeneratorBySpecTwoJsunit() {
describe("AsyKeyGeneratorBySpecTwoJsunit", function () {
console.info("##########start AsyKeyGeneratorBySpecTwoJsunit##########");
beforeAll(function () {});
afterEach(function () {});
/**
* @tc.number Security_CryptoFramework_GeneratorBySpec_Func_0900
* @tc.name ECC PriKey generation Pubkey
* @tc.desc the asyKeySpec is eccPrikeySpec, Use the promise Style of Interface
*/
it(
"Security_CryptoFramework_GeneratorBySpec_Func_0900",
0,
async function (done) {
let asyKeyPairSpec = cryptoFramework.createAsyKeyGeneratorBySpec(
genEccKeyTypeSpec(cryptoFramework.AsyKeySpecType.PRIVATE_KEY_SPEC)
);
asyKeyPairSpec
.generatePubKey()
.then((pubKey) => {
console.log("pubKey" + pubKey);
expect(null).assertFail();
})
.catch((err) => {
console.error(
"generatePubTopriSpecFailed Security_CryptoFramework_GeneratorBySpec_Func_0900" +
" failed. error is " +
err
);
expect(err.code == 401).assertTrue();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_GeneratorBySpec_Func_1000
* @tc.name ECC PubKey generation Prikey
* @tc.desc the asyKeySpec is eccPubkeySpec, Use the callback Style of Interface
*/
it(
"Security_CryptoFramework_GeneratorBySpec_Func_1000",
0,
async function (done) {
let asyKeyPairSpec = cryptoFramework.createAsyKeyGeneratorBySpec(
genEccKeyTypeSpec(cryptoFramework.AsyKeySpecType.PUBLIC_KEY_SPEC)
);
asyKeyPairSpec
.generatePriKey()
.then((priKey) => {
console.log("priKey" + priKey);
expect(null).assertFail();
})
.catch((err) => {
console.error(
"generatePubTopriSpecFailed Security_CryptoFramework_GeneratorBySpec_Func_1000" +
" failed. error is " +
err
);
expect(err.code == 401).assertTrue();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_GeneratorBySpec_Func_1100
* @tc.name RSA Key generation scenario by spec
* @tc.desc the asyKeySpec is genRsa2048CommonSpec, Use the callback Style of Interface
*/
it(
"Security_CryptoFramework_GeneratorBySpec_Func_1100",
0,
async function (done) {
asyCallback
.generateByCommonSpec(genRsa2048CommonSpec(), "RSA")
.then((result) => {
console.log("result :" + result);
expect(null).assertFail();
})
.catch((err) => {
console.error(
"Security_CryptoFramework_GeneratorBySpec_Func_1100 catch err " +
err
);
expect(err.code == 401).assertTrue();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_GeneratorBySpec_Func_1200
* @tc.name RSA Key generation scenario by spec
* @tc.desc the asyKeySpec is genRsa2048PubKetSpec, Use the promise Style of Interface
*/
it(
"Security_CryptoFramework_GeneratorBySpec_Func_1200",
0,
async function (done) {
asyPromise
.generateByPubKeySpec(genRsa2048PubKetSpec(), "RSA")
.then((result) => {
expect(result).assertTrue();
})
.catch((err) => {
console.error(
"Security_CryptoFramework_GeneratorBySpec_Func_1200 catch err " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_GeneratorBySpec_Func_1300
* @tc.name RSA Key generation scenario by spec
* @tc.desc the asyKeySpec is genRsa2048KeyPairSpec, Use the promise Style of Interface
*/
it(
"Security_CryptoFramework_GeneratorBySpec_Func_1300",
0,
async function (done) {
asyPromise
.generateByKeyPairSpec(genRsa2048KeyPairSpec(), "RSA")
.then((result) => {
expect(result).assertTrue();
})
.catch((err) => {
console.error(
"Security_CryptoFramework_GeneratorBySpec_Func_1300 catch err " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_GeneratorBySpec_Func_1400
* @tc.name RSA pubKey generation prikey failed
* @tc.desc the asyKeySpec is genRsa2048PubKetSpec, Use the callback Style of Interface
*/
it(
"Security_CryptoFramework_GeneratorBySpec_Func_1400",
0,
async function (done) {
let asyKeyPairSpec = cryptoFramework.createAsyKeyGeneratorBySpec(
genRsa2048PubKetSpec()
);
asyKeyPairSpec
.generatePriKey()
.then((priKey) => {
console.log("priKey" + priKey);
expect(null).assertFail();
})
.catch((err) => {
console.error(
"generatePubTopriSpecFailed generateSpecAsyKeyPair failed. error is " +
err
);
expect(err.code == 401).assertTrue();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_GeneratorBySpec_Func_1500
* @tc.name create key parser failed
* @tc.desc Pass in an exception parameter error EccCommonStruct and call it as a async
* @tc.desc Pass in an exception parameter error RsaKeyPairStruct and call it as a async
* @tc.desc Pass in an exception parameter error DsaKeyPairStruct and call it as a async
*/
it(
"Security_CryptoFramework_GeneratorBySpec_Func_1500",
0,
async function (done) {
try {
cryptoFramework.createAsyKeyGeneratorBySpec(genEccCommonSpecErr());
expect(null).assertFail();
} catch (err) {
console.error(
"Security_CryptoFramework_GeneratorBySpec_Func_1500 catch err " +
err
);
expect(err.code == 401).assertTrue();
}
try {
cryptoFramework.createAsyKeyGeneratorBySpec(genRsaKeyPairSpecErr());
expect(null).assertFail();
} catch (err) {
console.error(
"Security_CryptoFramework_GeneratorBySpec_Func_1500 catch err " +
err
);
expect(err.code == 401).assertTrue();
}
try {
cryptoFramework.createAsyKeyGeneratorBySpec(genDsaKeyPairSpecErr());
expect(null).assertFail();
} catch (err) {
console.error(
"Security_CryptoFramework_GeneratorBySpec_Func_1500 catch err " +
err
);
expect(err.code == 401).assertTrue();
}
done();
}
);
/**
* @tc.number Security_CryptoFramework_GeneratorBySpec_Func_1600
* @tc.name relatively pubkey and prikey
* @tc.desc the asyKeySpec is genDsaKeyPairSpecErr, Use the promise Style of Interface
*/
it(
"Security_CryptoFramework_GeneratorBySpec_Func_1600",
0,
async function (done) {
promise
.keyGenerationBySpecProcess(genDsa2048KeyPairSpec())
.then((result) => {
expect(result).assertTrue();
})
.catch((err) => {
console.error(
"Security_CryptoFramework_GeneratorBySpec_Func_1600 catch err " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_GeneratorBySpec_Func_1700
* @tc.name relatively pubkey and prikey
* @tc.desc the asyKeySpec is "DSA", Use the callback Style of Interface
*/
it(
"Security_CryptoFramework_GeneratorBySpec_Func_1700",
0,
async function (done) {
callback
.keyGenerationBySpecProcess("DSA2048")
.then((result) => {
expect(result).assertTrue();
})
.catch((err) => {
console.error(
"Security_CryptoFramework_GeneratorBySpec_Func_1700 catch err " +
err
);
expect(null).assertFail();
});
done();
}
);
});
}
......@@ -13,22 +13,26 @@
* limitations under the License.
*/
import SecurityRandomSyncJsunit from "./SecurityRandomSync.test";
import SecuritySignatureVerificationJsunit from "./SecuritySignatureVerification.test";
import SecurityKeyAgreementJsunit from "./SecurityKeyAgreement.test";
import AsyKeyGeneratorBySpecJsunit from "./AsyKeyGeneratorBySpec.test";
import AsyGetKeySpecBySpecJsunit from "./AsyGetKeySpecBySpec.test";
import SecurityCipherJsunit from "./SecurityCipher.test";
import SecuritySignatureVerificationSM2Jsunit from "./SecuritySignatureVerificationSM2.test";
import SecurityCipherSM2SM4Jsunit from "./SecurityCipherSM2SM4.test";
import DigestAlgorithmSm3Jsunit from "./DigestAlgorithmSm3.test";
import SecurityRandomSyncJsunit from './SecurityRandomSync.test';
import SecuritySignatureVerificationTwoJsunit from './SecuritySignatureVerificationTwo.test';
import SecuritySignatureVerificationJsunit from './SecuritySignatureVerification.test';
import SecurityKeyAgreementJsunit from './SecurityKeyAgreement.test';
import AsyKeyGeneratorBySpecJsunit from './AsyKeyGeneratorBySpec.test';
import AsyKeyGeneratorBySpecTwoJsunit from './AsyKeyGeneratorBySpecTwo.test';
import AsyGetKeySpecBySpecJsunit from './AsyGetKeySpecBySpec.test';
import SecurityCipherJsunit from './SecurityCipher.test';
import SecuritySignatureVerificationSM2Jsunit from './SecuritySignatureVerificationSM2.test';
import SecurityCipherSM2SM4Jsunit from './SecurityCipherSM2SM4.test';
import DigestAlgorithmSm3Jsunit from './DigestAlgorithmSm3.test';
export default function testsuite() {
SecurityRandomSyncJsunit();
SecuritySignatureVerificationJsunit();
SecuritySignatureVerificationTwoJsunit();
SecurityKeyAgreementJsunit();
AsyGetKeySpecBySpecJsunit();
AsyKeyGeneratorBySpecJsunit();
AsyKeyGeneratorBySpecTwoJsunit();
SecurityCipherJsunit();
SecuritySignatureVerificationSM2Jsunit();
SecurityCipherSM2SM4Jsunit();
......
......@@ -24,8 +24,10 @@ export default function SecuritySignatureVerificationJsunit() {
console.log(
"##########start SecuritySignatureVerificationJsunit##########"
);
beforeAll(function () {});
afterEach(function () {});
beforeAll(function () {
});
afterEach(function () {
});
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_0100
......@@ -594,1102 +596,7 @@ export default function SecuritySignatureVerificationJsunit() {
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_1900
* @tc.name Use createAsyKeyGenerator to Create DSA asyKeySpec
* and Signature verification combination scenario testing
* @tc.desc Pass in the DSAKeyPar structure with a signature verification type of "DSA|SHA224"
* and use a callback style interface
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_1900",
0,
async function (done) {
await asyCallback
.signAndVerifyBySpecProcess(
asyCommon.genDsa2048CommonSpecBigE(),
"DSA|SHA224"
)
.then((result) => {
expect(result).assertTrue();
})
.catch((err) => {
console.error(
"AsyCallback signAndVerifyBySpecProcess catch error: " + err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_2000
* @tc.name Use createAsyKeyGenerator to Create DSA asyKeySpec
* and Signature verification combination scenario testing
* @tc.desc Pass in the DSAKeyPar structure with a signature verification type of "DSA1024|SHA224"
* and use a callback style interface
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_2000",
0,
async function (done) {
await asyCallback
.signAndVerifyBySpecProcess(
asyCommon.genDsa2048CommonSpecBigE(),
"DSA1024|SHA224"
)
.then((result) => {
expect(result).assertTrue();
})
.catch((err) => {
console.error(
"AsyCallback signAndVerifyBySpecProcess catch error: " + err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_2100
* @tc.name Use createAsyKeyGenerator to Create DSA asyKeySpec
* and Signature verification combination scenario testing
* @tc.desc Pass in the DSAKeyPar structure with a signature verification type of "DSA2048|SHA256"
* and use a promise style interface
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_2100",
0,
async function (done) {
await asyPromise
.signAndVerifyBySpecProcess(
asyCommon.genDsa2048CommonSpecBigE(),
"DSA2048|SHA256"
)
.then((result) => {
expect(result).assertTrue();
})
.catch((err) => {
console.error(
"AsyPromise signAndVerifyBySpecProcess catch error: " + err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_2200
* @tc.name Use createAsyKeyGenerator to Create DSA asyKeySpec
* and Signature verification combination scenario testing
* @tc.desc Pass in the DSAKeyPar structure with a signature verification type of "DSA3072|SHA384"
* and use a callback style interface
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_2200",
0,
async function (done) {
await asyCallback
.signAndVerifyBySpecProcess(
asyCommon.genDsa2048CommonSpecBigE(),
"DSA3072|SHA384"
)
.then((result) => {
expect(result).assertTrue();
})
.catch((err) => {
console.error(
"AsyCallback signAndVerifyBySpecProcess catch error: " + err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_2300
* @tc.name Scenario testing of signature verification and key generation and conversion combination
* @tc.desc Pass in key generation parameter "DSA1024|PRIMES_2",
* signature verification parameter "DSA1024|SHA1",
* and use a promise style interface
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_2300",
0,
async function (done) {
await asyPromise
.signAndVerifyNormalProcess("DSA1024", "DSA1024|SHA1")
.then((result) => {
expect(result).assertTrue();
})
.catch((err) => {
console.error(
"AyPromise signAndVerifyBySpecProcess catch error: " + err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_2400
* @tc.name Scenario testing of signature verification and key generation and conversion combination
* @tc.desc Pass in key generation parameter "DSA2048|PRIMES_2",
* signature verification parameter "DSA2048|SHA256",
* and use a callback style interface
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_2400",
0,
async function (done) {
await asyCallback
.signAndVerifyNormalProcess("DSA2048", "DSA2048|SHA256")
.then((result) => {
expect(result == true).assertTrue();
})
.catch((err) => {
console.error(
"AsyCallback signAndVerifyBySpecProcess catch error: " + err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_2500
* @tc.name Scenario testing of signature verification and key generation and conversion combination
* @tc.desc Pass in key generation parameter "DSA3072|PRIMES_2",
* signature verification parameter "DSA3072|SHA384",
* and use a promise style interface
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_2500",
0,
async function (done) {
await asyPromise
.signAndVerifyNormalProcess("DSA3072", "DSA3072|SHA384")
.then((result) => {
expect(result).assertTrue();
})
.catch((err) => {
console.error(
"AsyPromise signAndVerifyNormalProcess catch error: " + err
);
expect(err.code == 401).assertTrue();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_2600
* @tc.name Exception in creating signature object
* @tc.desc Pass in an exception parameter "RSA10000|PKCS1|SHA224" and call it as a synchronously
* @tc.desc Pass in an exception parameter null and call it as a synchronously
* @tc.desc Pass in an exception parameter "RSA1024PKCS1MD5RSA1024PKCS1MD5RSA1024PKCS1MD5" and
* call it as a synchronously
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_2600",
0,
async function (done) {
try {
cryptoFramework.createSign("RSA10000|PKCS1|SHA224");
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_2600 1 err" +
err
);
expect(err.code == 401).assertTrue();
}
try {
cryptoFramework.createSign(null);
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_2600 2 err" +
err
);
expect(err.code == 401).assertTrue();
}
try {
cryptoFramework.createSign(
"RSA1024PKCS1MD5RSA1024PKCS1MD5RSA1024PKCS1MD5"
);
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_2600 3 err" +
err
);
expect(err.code == 401).assertTrue();
}
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_2700
* @tc.name Exception while initializing rsa signature object
* @tc.desc Pass in an exception parameter null and call it as a async
* @tc.desc Pass in the two public keys generated by the exception parameter rsa and call them as async
* @tc.desc Pass in the public key generated by the exception parameter dsa and call it as a async
* @tc.desc Pass in an exception parameter "sroundpriKey" and call it as a async
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_2700",
0,
async function (done) {
let specGenerator = cryptoFramework.createAsyKeyGeneratorBySpec(
asyCommon.genRsa2048KeyPairSpec()
);
let signGenerator = cryptoFramework.createSign("RSA1024|PKCS1|SHA224");
let signKeyPair;
await new Promise((resolve, reject) => {
specGenerator.generateKeyPair((err, keyPair) => {
if (err) {
reject(err);
} else {
signKeyPair = keyPair;
resolve();
}
});
});
try {
signGenerator.init(null);
expect(null).assertFail();
} catch (err) {
expect(err.code == 401).assertTrue();
}
try {
signGenerator.init(signKeyPair.priKey, signKeyPair.priKey);
expect(null).assertFail();
} catch (err) {
expect(err.code == 401).assertTrue();
}
let dsaGenerator = cryptoFramework.createAsyKeyGeneratorBySpec(
asyCommon.genDsa2048KeyPairSpecBigE()
);
let dsaKeyPair;
await new Promise((resolve, reject) => {
dsaGenerator.generateKeyPair((err, keyPair) => {
if (err) {
reject(err);
} else {
dsaKeyPair = keyPair;
resolve();
}
});
});
try {
await signGenerator.init(dsaKeyPair.pubKey);
expect(null).assertFail();
} catch (err) {
expect(err.code == 401).assertTrue();
}
try {
signGenerator.init("sroundpriKey");
expect(null).assertFail();
} catch (err) {
expect(err.code == 401).assertTrue();
}
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_2800
* @tc.name Exception in adding signature data to rsa objects
* @tc.desc Call it as a promise without passing in parameters
* @tc.desc Pass in two exception parameters "This is a sign test" and "This is a sign test"
* and call them as promise
* @tc.desc Pass in an exception parameter null and call it as a promise
* @tc.desc Pass in an exception parameter of "This is a sign test" multiplied by 1000 times and call it promise
* @tc.desc The signature object was not initialized, and the data to be signed "This is a sign test"
* was passed in as a promise to be called
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_2800",
0,
async function (done) {
await asyPromise
.updateAbnormalParameterProcess(
asyCommon.genRsa2048KeyPairSpec(),
"RSA1024|PKCS1|SHA224",
0
)
.then((data) => {
console.log("data 1 : " + data);
expect(null).assertFail();
})
.catch((err) => {
console.error(
"AsyPromise updateAbnormalParameterProcess 1 catch error: " + err
);
expect(err.code == 401).assertTrue();
});
await asyPromise
.updateAbnormalParameterProcess(
asyCommon.genRsa2048KeyPairSpec(),
"RSA1024|PKCS1|SHA224",
1
)
.then((data) => {
console.log("data 2 : " + data);
expect(null).assertFail();
})
.catch((err) => {
console.error(
"AsyPromise updateAbnormalParameterProcess 2 catch error: " + err
);
expect(err.code == 401).assertTrue();
});
await asyPromise
.updateAbnormalParameterProcess(
asyCommon.genRsa2048KeyPairSpec(),
"RSA1024|PKCS1|SHA224",
2
)
.then((data) => {
console.log("data 3 : " + data);
expect(null).assertFail();
})
.catch((err) => {
console.error(
"AsyPromise updateAbnormalParameterProcess 3 catch error: " + err
);
expect(err.code == 401).assertTrue();
});
await asyPromise
.updateAbnormalParameterProcess(
asyCommon.genRsa2048KeyPairSpec(),
"RSA1024|PKCS1|SHA224",
3
)
.then((data) => {
console.log("data 4 : " + data);
expect(null).assertFail();
})
.catch((err) => {
console.error(
"AsyPromise updateAbnormalParameterProcess 4 catch error: " + err
);
expect(err.code == 401).assertTrue();
});
await asyPromise
.updateAbnormalParameterProcess(
asyCommon.genRsa2048KeyPairSpec(),
"RSA1024|PKCS1|SHA224",
4
)
.then((data) => {
console.log("data 5 : " + data);
expect(null).assertFail();
})
.catch((err) => {
console.error(
"AsyPromise updateAbnormalParameterProcess 5 catch error: " + err
);
expect(err.code == 401).assertTrue();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_2900
* @tc.name Signature data anomaly
* @tc.desc Pass in an exception parameter "This is a sign test" and "This is a sign test"
* call it in the form of a callback
* @tc.descPass in an exception parameter null and call it as a callback
* @tc.desc Pass in an exception parameter "" and call it as a callback
* @tc.desc The signature object was not initialized, and the data to be signed 'This is a sign test'
* was passed in as a callback to be called
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_2900",
0,
async function (done) {
await asyCallback
.signAbnormalParameterProcess(
asyCommon.genRsa2048KeyPairSpec(),
"RSA1024|PKCS1|SHA224",
0
)
.then((data) => {
console.log("data 1 : " + data);
expect(null).assertFail();
})
.catch((err) => {
console.error(
"AsyCallback signAbnormalParameterProcess 1 catch error: " + err
);
expect(err.code == 401).assertTrue();
});
await asyCallback
.signAbnormalParameterProcess(
asyCommon.genRsa2048KeyPairSpec(),
"RSA1024|PKCS1|SHA224",
1
)
.then((data) => {
console.log("data 2 : " + data);
expect(data != null).assertTrue();
})
.catch((err) => {
console.error(
"AsyCallback signAbnormalParameterProcess 2 catch error: " + err
);
expect(err.code == undefined).assertTrue();
});
await asyCallback
.signAbnormalParameterProcess(
asyCommon.genRsa2048KeyPairSpec(),
"RSA1024|PKCS1|SHA224",
2
)
.then((data) => {
console.log("data 3 : " + data);
expect(null).assertFail();
})
.catch((err) => {
console.error(
"AsyCallback signAbnormalParameterProcess 3 catch error: " + err
);
expect(err.code == 401).assertTrue();
});
await asyCallback
.signAbnormalParameterProcess(
asyCommon.genRsa2048KeyPairSpec(),
"RSA1024|PKCS1|SHA224",
3
)
.then((data) => {
console.log("data 4 : " + data);
expect(null).assertFail();
})
.catch((err) => {
console.error(
"AsyCallback signAbnormalParameterProcess 4 catch error: " + err
);
expect(err.code == 401).assertTrue();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_3000
* @tc.name Exception in signature setting parameter mode
* @tc.desc Pass in exception parameter mode 1024, parameter 2, and call it synchronously
* @tc.desc Pass in exception parameter mode cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM,
* parameter 4294967296, and call it synchronously
* @tc.desc Pass in exception parameter mode cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM, parameter "string",
* and call it synchronously
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_3000",
0,
async function (done) {
let signGenerator = cryptoFramework.createSign(
"RSA1024|PSS|SHA224|MGF1_SHA224"
);
try {
signGenerator.setSignSpec(1024, 2);
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_3100 1 err" +
err
);
expect(err.code == 401).assertTrue();
}
try {
signGenerator.setSignSpec(
cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM,
4294967296
);
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_3100 2 err" +
err
);
expect(err.code == 401).assertTrue();
}
try {
signGenerator.setSignSpec(
cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM,
"string"
);
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_3100 5 err" +
err
);
expect(err.code == 401).assertTrue();
}
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_3100
* @tc.name Exception in signature getting parameter mode
* @tc.desc Pass in exception parameter mode 10000, and call it synchronously
* @tc.desc Pass in exception parameter mode 6, and call it synchronously
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_3100",
0,
async function (done) {
let signGenerator = cryptoFramework.createSign(
"RSA1024|PSS|SHA224|MGF1_SHA224"
);
try {
signGenerator.getSignSpec(10000);
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_3100 1 err" +
err
);
expect(err.code == 401).assertTrue();
}
try {
signGenerator.getSignSpec(6);
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_3100 4 err" +
err
);
expect(err.code == 401).assertTrue();
}
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_3200
* @tc.name Abnormal situation of creating verification objects
* @tc.desc Pass in an exception parameter "RSA10000|SHA224" and call it as a synchronously
* @tc.desc Pass in an exception parameter null and call it as a synchronously
* @tc.desc Pass in an exception parameter "RSA1024PKCS1MD5RSA1024PKCS1MD5RSA1024PKCS1MD5" and
* call it as a synchronously
* @tc.desc Pass in an exception parameter "DSA512|PKCS1|MD5" and call it as a synchronously
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_3200",
0,
async function (done) {
try {
cryptoFramework.createVerify("RSA10000|SHA224");
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_3200 1 catch err" +
err
);
expect(err.code == 401).assertTrue();
}
try {
cryptoFramework.createVerify(null);
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_3200 2 catch err" +
err
);
expect(err.code == 401).assertTrue();
}
try {
cryptoFramework.createVerify(
"RSA1024PKCS1MD5RSA1024PKCS1MD5RSA1024PKCS1MD5"
);
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_3200 3 catch err" +
err
);
expect(err.code == 401).assertTrue();
}
try {
cryptoFramework.createVerify("DSA512|PKCS1|MD5");
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_3200 5 catch err" +
err
);
expect(err.code == 401).assertTrue();
}
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_3300
* @tc.name Abnormal situation of initialization verification object
* @tc.desc Pass in an exception parameter null and call it as a async
* @tc.desc Pass in the two public keys generated by the exception parameter rsa and call them as async
* @tc.desc Pass in the public key generated by the exception parameter dsa and call it as a async
* @tc.desc Pass in an exception parameter "sroundpriKey" and call it as a async
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_3300",
0,
async function (done) {
let specGenerator = cryptoFramework.createAsyKeyGeneratorBySpec(
asyCommon.genRsa2048KeyPairSpec()
);
let verifyGenerator = cryptoFramework.createVerify(
"RSA1024|PKCS1|SHA224"
);
let verifyKeyPair;
await new Promise((resolve, reject) => {
specGenerator.generateKeyPair((err, keyPair) => {
if (err) {
reject(err);
} else {
verifyKeyPair = keyPair;
resolve();
}
});
});
try {
verifyGenerator.init(null);
expect(null).assertFail();
} catch (err) {
expect(err.code == 401).assertTrue();
}
try {
verifyGenerator.init(verifyKeyPair.pubKey, verifyKeyPair.pubKey);
expect(null).assertFail();
} catch (err) {
expect(err.code == 401).assertTrue();
}
let dsaGenerator = cryptoFramework.createAsyKeyGeneratorBySpec(
asyCommon.genDsa2048KeyPairSpecBigE()
);
let dsaKeyPair;
await new Promise((resolve, reject) => {
dsaGenerator.generateKeyPair((err, keyPair) => {
if (err) {
reject(err);
} else {
dsaKeyPair = keyPair;
resolve();
}
});
});
try {
await verifyGenerator.init(dsaKeyPair.pubKey);
expect(null).assertFail();
} catch (err) {
expect(err.code == 401).assertTrue();
}
try {
verifyGenerator.init("sroundpriKey");
expect(null).assertFail();
} catch (err) {
expect(err.code == 401).assertTrue();
}
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_3400
* @tc.name Abnormal situation of additional signature verification data
* @tc.desc Call it as a promise without passing in parameters
* @tc.desc Pass in an exception parameter null and call it as a promise
* @tc.desc Pass in an exception parameter "" and call it as a promise
* @tc.desc Pass in two exception parameters "This is a sign test" and "This is a sign test"
* and call them as promise
* @tc.desc The verify object was not initialized, and the data to be signed "This is a sign test"
* was passed in as a promise to be called
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_3400",
0,
async function (done) {
await asyPromise
.verifyUpdateAbnormalParameterProcess(
asyCommon.genRsa2048KeyPairSpec(),
"RSA1024|PKCS1|SHA224",
0
)
.then((data) => {
console.log("data 1 : " + data);
expect(null).assertFail();
})
.catch((err) => {
console.error(
"AsyPromise verifyUpdateAbnormalParameterProcess 1 catch error: " +
err
);
expect(err.code == 401).assertTrue();
});
await asyPromise
.verifyUpdateAbnormalParameterProcess(
asyCommon.genRsa2048KeyPairSpec(),
"RSA1024|PKCS1|SHA224",
1
)
.then((data) => {
console.log("data 2 : " + data);
expect(null).assertFail();
})
.catch((err) => {
console.error(
"AsyPromise verifyUpdateAbnormalParameterProcess 2 catch error: " +
err
);
expect(err.code == 401).assertTrue();
});
await asyPromise
.verifyUpdateAbnormalParameterProcess(
asyCommon.genRsa2048KeyPairSpec(),
"RSA1024|PKCS1|SHA224",
2
)
.then((data) => {
console.log("data 3 : " + data);
expect(null).assertFail();
})
.catch((err) => {
console.error(
"AsyPromise verifyUpdateAbnormalParameterProcess 3 catch error: " +
err
);
expect(err.code == 401).assertTrue();
});
await asyPromise
.verifyUpdateAbnormalParameterProcess(
asyCommon.genRsa2048KeyPairSpec(),
"RSA1024|PKCS1|SHA224",
3
)
.then((data) => {
console.log("data 4 : " + data);
expect(null).assertFail();
})
.catch((err) => {
console.error(
"AsyPromise verifyUpdateAbnormalParameterProcess 4 catch error: " +
err
);
expect(err.code == 401).assertTrue();
});
await asyPromise
.verifyUpdateAbnormalParameterProcess(
asyCommon.genRsa2048KeyPairSpec(),
"RSA1024|PKCS1|SHA224",
4
)
.then((data) => {
console.log("data 5 : " + data);
expect(null).assertFail();
})
.catch((err) => {
console.error(
"AsyPromise verifyUpdateAbnormalParameterProcess 5 catch error: " +
err
);
expect(err.code == 401).assertTrue();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_3500
* @tc.name Abnormal situation of visa verification signature data
* @tc.desc Call it as a callback without passing in parameters
* @tc.desc Pass in an exception parameter null and call it as a callback
* @tc.desc Pass in an exception parameter "" and call it as a callback
* @tc.desc Pass in an exception parameter "This is a sign test" and "This is a sign test"
* call it in the form of a callback
* @tc.desc The verify object was not initialized, and the data to be signed 'This is a sign test'
* was passed in as a callback to be called
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_3500",
0,
async function (done) {
await asyCallback
.verifyAbnormalParameterProcess(
asyCommon.genRsa2048KeyPairSpec(),
"RSA1024|PKCS1|SHA224",
0
)
.then((data) => {
console.log("data 1 : " + data);
expect(null).assertFail();
})
.catch((err) => {
console.error(
"AsyCallback verifyAbnormalParameterProcess 1 catch error: " + err
);
expect(err.code == 401).assertTrue();
});
await asyCallback
.verifyAbnormalParameterProcess(
asyCommon.genRsa2048KeyPairSpec(),
"RSA1024|PKCS1|SHA224",
1
)
.then((data) => {
console.log("data 2 : " + data);
expect(null).assertFail();
})
.catch((err) => {
console.error(
"AsyCallback verifyAbnormalParameterProcess 2 catch error: " + err
);
expect(err.code == 401).assertTrue();
});
await asyCallback
.verifyAbnormalParameterProcess(
asyCommon.genRsa2048KeyPairSpec(),
"RSA1024|PKCS1|SHA224",
2
)
.then((data) => {
console.log("data 3 : " + data);
expect(null).assertFail();
})
.catch((err) => {
console.error(
"AsyCallback verifyAbnormalParameterProcess 3 catch error: " + err
);
expect(err.code == 401).assertTrue();
});
await asyCallback
.verifyAbnormalParameterProcess(
asyCommon.genRsa2048KeyPairSpec(),
"RSA1024|PKCS1|SHA224",
3
)
.then((data) => {
console.log("data 4 : " + data);
expect(null).assertFail();
})
.catch((err) => {
console.error(
"AsyCallback verifyAbnormalParameterProcess 4 catch error: " + err
);
expect(err.code == 401).assertTrue();
});
await asyCallback
.verifyAbnormalParameterProcess(
asyCommon.genRsa2048KeyPairSpec(),
"RSA1024|PKCS1|SHA224",
4
)
.then((data) => {
console.log("data 4 : " + data);
expect(null).assertFail();
})
.catch((err) => {
console.error(
"AsyCallback verifyAbnormalParameterProcess 4 catch error: " + err
);
expect(err.code == 401).assertTrue();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_3600
* @tc.name Abnormal situation of parameter mode for signature verification setting
* @tc.desc Pass in exception parameter mode cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM,
* parameter 0, and call it synchronously
* @tc.desc Pass in exception parameter mode cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM,
* parameter -1, and call it synchronously
* @tc.desc Pass in exception parameter mode 1024, parameter 2, and call it synchronously
* @tc.desc Pass in exception parameter mode cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM,
* parameter 65535, and call it synchronously
* @tc.desc Pass in exception parameter mode cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM, parameter "string",
* and call it synchronously
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_3600",
0,
async function (done) {
let verifyGenerator = cryptoFramework.createVerify(
"RSA1024|PKCS1|SHA224"
);
try {
verifyGenerator.setVerifySpec(
cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM,
0
);
expect(null).assertFail();
} catch (err) {
expect(err.code == 401).assertTrue();
}
try {
verifyGenerator.setVerifySpec(
cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM,
-1
);
expect(null).assertFail();
} catch (err) {
expect(err.code == 401).assertTrue();
}
try {
verifyGenerator.setVerifySpec(1024, 2);
expect(null).assertFail();
} catch (err) {
expect(err.code == 401).assertTrue();
}
try {
verifyGenerator.setVerifySpec(
cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM,
65535
);
expect(null).assertFail();
} catch (err) {
expect(err.code == 401).assertTrue();
}
try {
verifyGenerator.setVerifySpec(
cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM,
"string"
);
expect(null).assertFail();
} catch (err) {
expect(err.code == 401).assertTrue();
}
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_3700
* @tc.name Abnormal situation of parameter mode for signature verification getting
* @tc.desc Pass in exception parameter mode 10000, and call it synchronously
* @tc.desc Call it as a synchronously without passing in parameters
* @tc.desc Pass in exception parameter mode 6, and call it synchronously
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_3700",
0,
async function (done) {
let verifyGenerator = cryptoFramework.createVerify(
"RSA1024|PKCS1|SHA224"
);
try {
verifyGenerator.getVerifySpec(10000);
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_3700 1 err" +
err
);
expect(err.code == 401).assertTrue();
}
try {
verifyGenerator.getVerifySpec(
cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM
);
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_3700 2 err" +
err
);
expect(err.code == 401).assertTrue();
}
try {
verifyGenerator.getVerifySpec(6);
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_3700 4 err" +
err
);
expect(err.code == 401).assertTrue();
}
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_3800
* @tc.name Signature verification and corresponding algorithm for obtaining signatures
* @tc.desc Pass in algorithm name "RSA1024|PKCS1|SHA512" and call it using the promise method
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_3800",
0,
async function (done) {
try {
let signGenerator = cryptoFramework.createSign(
"RSA1024|PKCS1|SHA512"
);
expect(signGenerator.algName == "RSA1024|PKCS1|SHA512").assertTrue();
let verifyGenerator = cryptoFramework.createVerify(
"RSA1024|PKCS1|SHA512"
);
expect(
verifyGenerator.algName == "RSA1024|PKCS1|SHA512"
).assertTrue();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_3800 catch err: " +
err
);
expect(err.code == 401).assertTrue();
}
done();
}
);
});
}
......@@ -13,22 +13,12 @@
* limitations under the License.
*/
import {
describe,
beforeAll,
afterEach,
it,
expect,
afterAll,
} from "@ohos/hypium";
import { describe, beforeAll, afterEach, it, expect, afterAll, } from "@ohos/hypium";
import * as asyPromise from "./utils/asymmetric/publicAsymmetricPromise";
import * as asyCallback from "./utils/asymmetric/publicAsymmetricCallback";
import * as asyCommon from "./utils/asymmetric/publicAsymmetricCommon";
import cryptoFramework from "@ohos.security.cryptoFramework";
import {
stringTouInt8Array,
uInt8ArrayToShowStr,
} from "./utils/common/publicDoString";
import { stringTouInt8Array, uInt8ArrayToShowStr, } from "./utils/common/publicDoString";
export default function SecuritySignatureVerificationSM2Jsunit() {
describe("SecuritySignatureVerificationSM2Jsunit", function () {
......@@ -37,6 +27,7 @@ export default function SecuritySignatureVerificationSM2Jsunit() {
);
var asyKeyPair;
beforeAll(async function () {
async function genAsyKeyPair() {
try {
let asyGenerator = asyCommon.createAsyKeyGenerator("SM2_256");
......@@ -49,7 +40,8 @@ export default function SecuritySignatureVerificationSM2Jsunit() {
asyKeyPair = await genAsyKeyPair();
});
afterAll(function () {});
afterAll(function () {
});
/**
* @tc.number Security_CryptoFramework_SignatureVerificationSM2_Func_0100
......@@ -375,7 +367,9 @@ export default function SecuritySignatureVerificationSM2Jsunit() {
0,
async function (done) {
let globalText = "This is a sign test";
let input = { data: stringTouInt8Array(globalText) };
let input = {
data: stringTouInt8Array(globalText)
};
let signGenerator = cryptoFramework.createSign("SM2_256|SM3");
try {
await signGenerator.update(input);
......@@ -416,7 +410,9 @@ export default function SecuritySignatureVerificationSM2Jsunit() {
0,
async function (done) {
let globalText = "This is a sign test";
let input = { data: stringTouInt8Array(globalText) };
let input = {
data: stringTouInt8Array(globalText)
};
let signGenerator = cryptoFramework.createSign("SM2_256|SM3");
await signGenerator.init(asyKeyPair.priKey);
......@@ -543,101 +539,6 @@ export default function SecuritySignatureVerificationSM2Jsunit() {
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerificationSM2_Func_1200
* @tc.name Abnormal situation of additional signature verification data
* @tc.desc Call it as a promise without passing in parameters
* @tc.desc Pass in an exception parameter null and call it as a promise
* @tc.desc Pass in two exception parameters "This is a sign test" and "This is a sign test"
* and call them as promise
* @tc.desc The verify object was not initialized, and the data to be signed "This is a sign test"
* was passed in as a promise to be called
*/
it(
"Security_CryptoFramework_SignatureVerificationSM2_Func_1200",
0,
async function (done) {
await asyPromise
.verifyUpdateAbnormalParameterSM2Process("SM2_256", "SM2_256|SM3", 0)
.then((data) => {
expect(null).assertFail();
})
.catch((err) => {
expect(err.code == 401).assertTrue();
});
await asyPromise
.verifyUpdateAbnormalParameterSM2Process("SM2_256", "SM2_256|SM3", 1)
.then((data) => {
expect(null).assertFail();
})
.catch((err) => {
expect(err.code == 401).assertTrue();
});
await asyPromise
.verifyUpdateAbnormalParameterSM2Process("SM2_256", "SM2_256|SM3", 3)
.then((data) => {
expect(null).assertFail();
})
.catch((err) => {
expect(err.code == 401).assertTrue();
});
await asyPromise
.verifyUpdateAbnormalParameterSM2Process("SM2_256", "SM2_256|SM3", 4)
.then((data) => {
expect(null).assertFail();
})
.catch((err) => {
expect(err.code == 401).assertTrue();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerificationSM2_Func_1300
* @tc.name Abnormal situation of visa verification signature data
* @tc.desc Call it as a callback without passing in parameters
* @tc.desc Pass in an exception parameter null and call it as a callback
* @tc.desc Pass in an exception parameter "This is a sign test" and "This is a sign test"
* call it in the form of a callback
*/
it(
"Security_CryptoFramework_SignatureVerificationSM2_Func_1300",
0,
async function (done) {
await asyCallback
.verifyAbnormalParameterSM2Process("SM2_256", "SM2_256|SM3", 0)
.then((data) => {
expect(null).assertFail();
})
.catch((err) => {
expect(err.code == 401).assertTrue();
});
await asyCallback
.verifyAbnormalParameterSM2Process("SM2_256", "SM2_256|SM3", 1)
.then((data) => {
expect(null).assertFail();
})
.catch((err) => {
expect(err.code == 401).assertTrue();
});
await asyCallback
.verifyAbnormalParameterSM2Process("SM2_256", "SM2_256|SM3", 3)
.then((data) => {
expect(null).assertFail();
})
.catch((err) => {
expect(err.code == 401).assertTrue();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerificationSM2_Func_1400
* @tc.name Test signature verification and pass in ultra long parameters
......@@ -657,7 +558,9 @@ export default function SecuritySignatureVerificationSM2Jsunit() {
for (let i = 0; i < 350; i++) {
globalText += t.charAt(Math.floor(Math.random() * t.length));
}
let input = { data: stringTouInt8Array(globalText) };
let input = {
data: stringTouInt8Array(globalText)
};
let rsaGenerator = cryptoFramework.createAsyKeyGenerator("SM2_256");
let signGenerator = cryptoFramework.createSign("SM2_256|SM3");
let verifyGenerator = cryptoFramework.createVerify("SM2_256|SM3");
......
/*
* Copyright (C) 2022-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, beforeAll, afterEach, it, expect } from "@ohos/hypium";
import * as asyPromise from "./utils/asymmetric/publicAsymmetricPromise";
import * as asyCommon from "./utils/common/publicDoSpec";
import * as asyCallback from "./utils/asymmetric/publicAsymmetricCallback";
import cryptoFramework from "@ohos.security.cryptoFramework";
export default function SecuritySignatureVerificationTwoJsunit() {
describe("SecuritySignatureVerificationTwoJsunit", function () {
console.log(
"##########start SecuritySignatureVerificationJsunit##########"
);
beforeAll(function () {
});
afterEach(function () {
});
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_1900
* @tc.name Use createAsyKeyGenerator to Create DSA asyKeySpec
* and Signature verification combination scenario testing
* @tc.desc Pass in the DSAKeyPar structure with a signature verification type of "DSA|SHA224"
* and use a callback style interface
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_1900",
0,
async function (done) {
await asyCallback
.signAndVerifyBySpecProcess(
asyCommon.genDsa2048CommonSpecBigE(),
"DSA|SHA224"
)
.then((result) => {
expect(result).assertTrue();
})
.catch((err) => {
console.error(
"AsyCallback signAndVerifyBySpecProcess catch error: " + err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_2000
* @tc.name Use createAsyKeyGenerator to Create DSA asyKeySpec
* and Signature verification combination scenario testing
* @tc.desc Pass in the DSAKeyPar structure with a signature verification type of "DSA1024|SHA224"
* and use a callback style interface
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_2000",
0,
async function (done) {
await asyCallback
.signAndVerifyBySpecProcess(
asyCommon.genDsa2048CommonSpecBigE(),
"DSA1024|SHA224"
)
.then((result) => {
expect(result).assertTrue();
})
.catch((err) => {
console.error(
"AsyCallback signAndVerifyBySpecProcess catch error: " + err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_2100
* @tc.name Use createAsyKeyGenerator to Create DSA asyKeySpec
* and Signature verification combination scenario testing
* @tc.desc Pass in the DSAKeyPar structure with a signature verification type of "DSA2048|SHA256"
* and use a promise style interface
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_2100",
0,
async function (done) {
await asyPromise
.signAndVerifyBySpecProcess(
asyCommon.genDsa2048CommonSpecBigE(),
"DSA2048|SHA256"
)
.then((result) => {
expect(result).assertTrue();
})
.catch((err) => {
console.error(
"AsyPromise signAndVerifyBySpecProcess catch error: " + err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_2200
* @tc.name Use createAsyKeyGenerator to Create DSA asyKeySpec
* and Signature verification combination scenario testing
* @tc.desc Pass in the DSAKeyPar structure with a signature verification type of "DSA3072|SHA384"
* and use a callback style interface
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_2200",
0,
async function (done) {
await asyCallback
.signAndVerifyBySpecProcess(
asyCommon.genDsa2048CommonSpecBigE(),
"DSA3072|SHA384"
)
.then((result) => {
expect(result).assertTrue();
})
.catch((err) => {
console.error(
"AsyCallback signAndVerifyBySpecProcess catch error: " + err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_2300
* @tc.name Scenario testing of signature verification and key generation and conversion combination
* @tc.desc Pass in key generation parameter "DSA1024|PRIMES_2",
* signature verification parameter "DSA1024|SHA1",
* and use a promise style interface
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_2300",
0,
async function (done) {
await asyPromise
.signAndVerifyNormalProcess("DSA1024", "DSA1024|SHA1")
.then((result) => {
expect(result).assertTrue();
})
.catch((err) => {
console.error(
"AyPromise signAndVerifyBySpecProcess catch error: " + err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_2400
* @tc.name Scenario testing of signature verification and key generation and conversion combination
* @tc.desc Pass in key generation parameter "DSA2048|PRIMES_2",
* signature verification parameter "DSA2048|SHA256",
* and use a callback style interface
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_2400",
0,
async function (done) {
await asyCallback
.signAndVerifyNormalProcess("DSA2048", "DSA2048|SHA256")
.then((result) => {
expect(result == true).assertTrue();
})
.catch((err) => {
console.error(
"AsyCallback signAndVerifyBySpecProcess catch error: " + err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_2500
* @tc.name Scenario testing of signature verification and key generation and conversion combination
* @tc.desc Pass in key generation parameter "DSA3072|PRIMES_2",
* signature verification parameter "DSA3072|SHA384",
* and use a promise style interface
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_2500",
0,
async function (done) {
await asyPromise
.signAndVerifyNormalProcess("DSA3072", "DSA3072|SHA384")
.then((result) => {
expect(result).assertTrue();
})
.catch((err) => {
console.error(
"AsyPromise signAndVerifyNormalProcess catch error: " + err
);
expect(err.code == 401).assertTrue();
});
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_2600
* @tc.name Exception in creating signature object
* @tc.desc Pass in an exception parameter "RSA10000|PKCS1|SHA224" and call it as a synchronously
* @tc.desc Pass in an exception parameter null and call it as a synchronously
* @tc.desc Pass in an exception parameter "RSA1024PKCS1MD5RSA1024PKCS1MD5RSA1024PKCS1MD5" and
* call it as a synchronously
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_2600",
0,
async function (done) {
try {
cryptoFramework.createSign("RSA10000|PKCS1|SHA224");
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_2600 1 err" +
err
);
expect(err.code == 401).assertTrue();
}
try {
cryptoFramework.createSign(null);
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_2600 2 err" +
err
);
expect(err.code == 401).assertTrue();
}
try {
cryptoFramework.createSign(
"RSA1024PKCS1MD5RSA1024PKCS1MD5RSA1024PKCS1MD5"
);
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_2600 3 err" +
err
);
expect(err.code == 401).assertTrue();
}
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_2700
* @tc.name Exception while initializing rsa signature object
* @tc.desc Pass in an exception parameter null and call it as a async
* @tc.desc Pass in the two public keys generated by the exception parameter rsa and call them as async
* @tc.desc Pass in the public key generated by the exception parameter dsa and call it as a async
* @tc.desc Pass in an exception parameter "sroundpriKey" and call it as a async
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_2700",
0,
async function (done) {
let specGenerator = cryptoFramework.createAsyKeyGeneratorBySpec(
asyCommon.genRsa2048KeyPairSpec()
);
let signGenerator = cryptoFramework.createSign("RSA1024|PKCS1|SHA224");
let signKeyPair;
await new Promise((resolve, reject) => {
specGenerator.generateKeyPair((err, keyPair) => {
if (err) {
reject(err);
} else {
signKeyPair = keyPair;
resolve();
}
});
});
try {
signGenerator.init(null);
expect(null).assertFail();
} catch (err) {
expect(err.code == 401).assertTrue();
}
try {
signGenerator.init(signKeyPair.priKey, signKeyPair.priKey);
expect(null).assertFail();
} catch (err) {
expect(err.code == 401).assertTrue();
}
let dsaGenerator = cryptoFramework.createAsyKeyGeneratorBySpec(
asyCommon.genDsa2048KeyPairSpecBigE()
);
let dsaKeyPair;
await new Promise((resolve, reject) => {
dsaGenerator.generateKeyPair((err, keyPair) => {
if (err) {
reject(err);
} else {
dsaKeyPair = keyPair;
resolve();
}
});
});
try {
await signGenerator.init(dsaKeyPair.pubKey);
expect(null).assertFail();
} catch (err) {
expect(err.code == 401).assertTrue();
}
try {
signGenerator.init("sroundpriKey");
expect(null).assertFail();
} catch (err) {
expect(err.code == 401).assertTrue();
}
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_2800
* @tc.name Exception in adding signature data to rsa objects
* @tc.desc Call it as a promise without passing in parameters
* @tc.desc Pass in two exception parameters "This is a sign test" and "This is a sign test"
* and call them as promise
* @tc.desc Pass in an exception parameter null and call it as a promise
* @tc.desc Pass in an exception parameter of "This is a sign test" multiplied by 1000 times and call it promise
* @tc.desc The signature object was not initialized, and the data to be signed "This is a sign test"
* was passed in as a promise to be called
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_2800",
0,
async function (done) {
try {
await asyPromise.updateAbnormalParameterProcess(asyCommon.genRsa2048KeyPairSpec(), "RSA1024|PKCS1|SHA224", 1);
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await asyPromise.updateAbnormalParameterProcess(asyCommon.genRsa2048KeyPairSpec(), "RSA1024|PKCS1|SHA224", 2);
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await asyPromise.updateAbnormalParameterProcess(asyCommon.genRsa2048KeyPairSpec(), "RSA1024|PKCS1|SHA224", 3);
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await asyPromise.updateAbnormalParameterProcess(asyCommon.genRsa2048KeyPairSpec(), "RSA1024|PKCS1|SHA224", 4);
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_2900
* @tc.name Signature data anomaly
* @tc.desc Pass in an exception parameter "This is a sign test" and "This is a sign test"
* call it in the form of a callback
* @tc.descPass in an exception parameter null and call it as a callback
* @tc.desc Pass in an exception parameter "" and call it as a callback
* @tc.desc The signature object was not initialized, and the data to be signed 'This is a sign test'
* was passed in as a callback to be called
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_2900",
0,
async function (done) {
try {
await asyCallback.signAbnormalParameterProcess(asyCommon.genRsa2048KeyPairSpec(), "RSA1024|PKCS1|SHA224", 1);
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await asyCallback.signAbnormalParameterProcess(asyCommon.genRsa2048KeyPairSpec(), "RSA1024|PKCS1|SHA224", 2);
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await asyCallback.signAbnormalParameterProcess(asyCommon.genRsa2048KeyPairSpec(), "RSA1024|PKCS1|SHA224", 3);
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_3000
* @tc.name Exception in signature setting parameter mode
* @tc.desc Pass in exception parameter mode 1024, parameter 2, and call it synchronously
* @tc.desc Pass in exception parameter mode cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM,
* parameter 4294967296, and call it synchronously
* @tc.desc Pass in exception parameter mode cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM, parameter "string",
* and call it synchronously
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_3000",
0,
async function (done) {
let signGenerator = cryptoFramework.createSign(
"RSA1024|PSS|SHA224|MGF1_SHA224"
);
try {
signGenerator.setSignSpec(1024, 2);
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_3100 1 err" +
err
);
expect(err.code == 401).assertTrue();
}
try {
signGenerator.setSignSpec(
cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM,
4294967296
);
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_3100 2 err" +
err
);
expect(err.code == 401).assertTrue();
}
try {
signGenerator.setSignSpec(
cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM,
"string"
);
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_3100 5 err" +
err
);
expect(err.code == 401).assertTrue();
}
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_3100
* @tc.name Exception in signature getting parameter mode
* @tc.desc Pass in exception parameter mode 10000, and call it synchronously
* @tc.desc Pass in exception parameter mode 6, and call it synchronously
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_3100",
0,
async function (done) {
let signGenerator = cryptoFramework.createSign(
"RSA1024|PSS|SHA224|MGF1_SHA224"
);
try {
signGenerator.getSignSpec(10000);
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_3100 1 err" +
err
);
expect(err.code == 401).assertTrue();
}
try {
signGenerator.getSignSpec(6);
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_3100 4 err" +
err
);
expect(err.code == 401).assertTrue();
}
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_3200
* @tc.name Abnormal situation of creating verification objects
* @tc.desc Pass in an exception parameter "RSA10000|SHA224" and call it as a synchronously
* @tc.desc Pass in an exception parameter null and call it as a synchronously
* @tc.desc Pass in an exception parameter "RSA1024PKCS1MD5RSA1024PKCS1MD5RSA1024PKCS1MD5" and
* call it as a synchronously
* @tc.desc Pass in an exception parameter "DSA512|PKCS1|MD5" and call it as a synchronously
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_3200",
0,
async function (done) {
try {
cryptoFramework.createVerify("RSA10000|SHA224");
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_3200 1 catch err" +
err
);
expect(err.code == 401).assertTrue();
}
try {
cryptoFramework.createVerify(null);
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_3200 2 catch err" +
err
);
expect(err.code == 401).assertTrue();
}
try {
cryptoFramework.createVerify(
"RSA1024PKCS1MD5RSA1024PKCS1MD5RSA1024PKCS1MD5"
);
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_3200 3 catch err" +
err
);
expect(err.code == 401).assertTrue();
}
try {
cryptoFramework.createVerify("DSA512|PKCS1|MD5");
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_3200 5 catch err" +
err
);
expect(err.code == 401).assertTrue();
}
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_3300
* @tc.name Abnormal situation of initialization verification object
* @tc.desc Pass in an exception parameter null and call it as a async
* @tc.desc Pass in the two public keys generated by the exception parameter rsa and call them as async
* @tc.desc Pass in the public key generated by the exception parameter dsa and call it as a async
* @tc.desc Pass in an exception parameter "sroundpriKey" and call it as a async
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_3300",
0,
async function (done) {
let specGenerator = cryptoFramework.createAsyKeyGeneratorBySpec(
asyCommon.genRsa2048KeyPairSpec()
);
let verifyGenerator = cryptoFramework.createVerify(
"RSA1024|PKCS1|SHA224"
);
let verifyKeyPair;
await new Promise((resolve, reject) => {
specGenerator.generateKeyPair((err, keyPair) => {
if (err) {
reject(err);
} else {
verifyKeyPair = keyPair;
resolve();
}
});
});
try {
verifyGenerator.init(null);
expect(null).assertFail();
} catch (err) {
expect(err.code == 401).assertTrue();
}
try {
verifyGenerator.init(verifyKeyPair.pubKey, verifyKeyPair.pubKey);
expect(null).assertFail();
} catch (err) {
expect(err.code == 401).assertTrue();
}
let dsaGenerator = cryptoFramework.createAsyKeyGeneratorBySpec(
asyCommon.genDsa2048KeyPairSpecBigE()
);
let dsaKeyPair;
await new Promise((resolve, reject) => {
dsaGenerator.generateKeyPair((err, keyPair) => {
if (err) {
reject(err);
} else {
dsaKeyPair = keyPair;
resolve();
}
});
});
try {
await verifyGenerator.init(dsaKeyPair.pubKey);
expect(null).assertFail();
} catch (err) {
expect(err.code == 401).assertTrue();
}
try {
verifyGenerator.init("sroundpriKey");
expect(null).assertFail();
} catch (err) {
expect(err.code == 401).assertTrue();
}
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_3400
* @tc.name Abnormal situation of additional signature verification data
* @tc.desc Call it as a promise without passing in parameters
* @tc.desc Pass in an exception parameter null and call it as a promise
* @tc.desc Pass in an exception parameter "" and call it as a promise
* @tc.desc Pass in two exception parameters "This is a sign test" and "This is a sign test"
* and call them as promise
* @tc.desc The verify object was not initialized, and the data to be signed "This is a sign test"
* was passed in as a promise to be called
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_3400",
0,
async function (done) {
try {
await asyPromise.verifyUpdateAbnormalParameterProcess(asyCommon.genRsa2048KeyPairSpec(), "RSA1024|PKCS1|SHA224", 1);
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await asyPromise.verifyUpdateAbnormalParameterProcess(asyCommon.genRsa2048KeyPairSpec(), "RSA1024|PKCS1|SHA224", 2);
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await asyPromise.verifyUpdateAbnormalParameterProcess(asyCommon.genRsa2048KeyPairSpec(), "RSA1024|PKCS1|SHA224", 3);
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await asyPromise.verifyUpdateAbnormalParameterProcess(asyCommon.genRsa2048KeyPairSpec(), "RSA1024|PKCS1|SHA224", 4);
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_3500
* @tc.name Abnormal situation of visa verification signature data
* @tc.desc Call it as a callback without passing in parameters
* @tc.desc Pass in an exception parameter null and call it as a callback
* @tc.desc Pass in an exception parameter "" and call it as a callback
* @tc.desc Pass in an exception parameter "This is a sign test" and "This is a sign test"
* call it in the form of a callback
* @tc.desc The verify object was not initialized, and the data to be signed 'This is a sign test'
* was passed in as a callback to be called
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_3500",
0,
async function (done) {
try {
let status = await asyCallback.verifyAbnormalParameterProcess(asyCommon.genRsa2048KeyPairSpec(), "RSA1024|PKCS1|SHA224", 1);
expect(status).assertFalse();
} catch (err) {
expect(null).assertFail();
}
try {
await asyCallback.verifyAbnormalParameterProcess(asyCommon.genRsa2048KeyPairSpec(), "RSA1024|PKCS1|SHA224", 2);
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await asyCallback.verifyAbnormalParameterProcess(asyCommon.genRsa2048KeyPairSpec(), "RSA1024|PKCS1|SHA224", 3);
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
let status = await asyCallback.verifyAbnormalParameterProcess(asyCommon.genRsa2048KeyPairSpec(), "RSA1024|PKCS1|SHA224", 4);
expect(status).assertFalse();
} catch (err) {
expect(null).assertFail();
}
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_3600
* @tc.name Abnormal situation of parameter mode for signature verification setting
* @tc.desc Pass in exception parameter mode cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM,
* parameter 0, and call it synchronously
* @tc.desc Pass in exception parameter mode cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM,
* parameter -1, and call it synchronously
* @tc.desc Pass in exception parameter mode 1024, parameter 2, and call it synchronously
* @tc.desc Pass in exception parameter mode cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM,
* parameter 65535, and call it synchronously
* @tc.desc Pass in exception parameter mode cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM, parameter "string",
* and call it synchronously
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_3600",
0,
async function (done) {
let verifyGenerator = cryptoFramework.createVerify(
"RSA1024|PKCS1|SHA224"
);
try {
verifyGenerator.setVerifySpec(
cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM,
0
);
expect(null).assertFail();
} catch (err) {
expect(err.code == 401).assertTrue();
}
try {
verifyGenerator.setVerifySpec(
cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM,
-1
);
expect(null).assertFail();
} catch (err) {
expect(err.code == 401).assertTrue();
}
try {
verifyGenerator.setVerifySpec(1024, 2);
expect(null).assertFail();
} catch (err) {
expect(err.code == 401).assertTrue();
}
try {
verifyGenerator.setVerifySpec(
cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM,
65535
);
expect(null).assertFail();
} catch (err) {
expect(err.code == 401).assertTrue();
}
try {
verifyGenerator.setVerifySpec(
cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM,
"string"
);
expect(null).assertFail();
} catch (err) {
expect(err.code == 401).assertTrue();
}
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_3700
* @tc.name Abnormal situation of parameter mode for signature verification getting
* @tc.desc Pass in exception parameter mode 10000, and call it synchronously
* @tc.desc Call it as a synchronously without passing in parameters
* @tc.desc Pass in exception parameter mode 6, and call it synchronously
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_3700",
0,
async function (done) {
let verifyGenerator = cryptoFramework.createVerify(
"RSA1024|PKCS1|SHA224"
);
try {
verifyGenerator.getVerifySpec(10000);
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_3700 1 err" +
err
);
expect(err.code == 401).assertTrue();
}
try {
verifyGenerator.getVerifySpec(
cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM
);
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_3700 2 err" +
err
);
expect(err.code == 401).assertTrue();
}
try {
verifyGenerator.getVerifySpec(6);
expect(null).assertFail();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_3700 4 err" +
err
);
expect(err.code == 401).assertTrue();
}
done();
}
);
/**
* @tc.number Security_CryptoFramework_SignatureVerification_Func_3800
* @tc.name Signature verification and corresponding algorithm for obtaining signatures
* @tc.desc Pass in algorithm name "RSA1024|PKCS1|SHA512" and call it using the promise method
*/
it(
"Security_CryptoFramework_SignatureVerification_Func_3800",
0,
async function (done) {
try {
let signGenerator = cryptoFramework.createSign(
"RSA1024|PKCS1|SHA512"
);
expect(signGenerator.algName == "RSA1024|PKCS1|SHA512").assertTrue();
let verifyGenerator = cryptoFramework.createVerify(
"RSA1024|PKCS1|SHA512"
);
expect(
verifyGenerator.algName == "RSA1024|PKCS1|SHA512"
).assertTrue();
} catch (err) {
console.log(
"Security_CryptoFramework_SignatureVerification_Func_3800 catch err: " +
err
);
expect(err.code == 401).assertTrue();
}
done();
}
);
}
);
}
......@@ -16,11 +16,7 @@
import { expect } from "@ohos/hypium";
import * as asyCommon from "../common/publicDoSpec";
import cryptoFramework from "@ohos.security.cryptoFramework";
import {
stringTouInt8Array,
uInt8ArrayToShowStr,
uInt8ArrayToString,
} from "../common/publicDoString";
import { stringTouInt8Array, uInt8ArrayToShowStr, uInt8ArrayToString, } from "../common/publicDoString";
import {
createAsyKeyGenerator,
createAsyKeyGeneratorBySpec,
......@@ -158,53 +154,6 @@ async function signForSign(signGenerator, dataBlob) {
});
}
async function signForSignFailed(signGenerator, dataBlob, itemType) {
return new Promise((resolve, reject) => {
switch (itemType) {
case 0:
signGenerator.sign((err, signOutput) => {
if (err) {
reject(err);
} else {
resolve(signOutput);
}
});
break;
case 1:
signGenerator.sign(null, (err, signOutput) => {
if (err) {
reject(err);
} else {
resolve(signOutput);
}
});
break;
case 2:
signGenerator.sign("", (err, signOutput) => {
if (err) {
reject(err);
} else {
resolve(signOutput);
}
});
break;
case 3:
signGenerator.sign(dataBlob, dataBlob, (err, signOutput) => {
if (err) {
reject(err);
} else {
resolve(signOutput);
}
});
break;
default:
reject("err");
break;
}
});
}
async function initVerify(verifyGenerator, pubKey) {
return new Promise((resolve, reject) => {
verifyGenerator.init(pubKey, (err) => {
......@@ -251,70 +200,6 @@ async function verifyForVerify(verifyGenerator, dataBlob, signDataBlob) {
});
}
async function verifyForVerifyFailed(
verifyGenerator,
dataBlob,
signDataBlob,
verifyType
) {
return new Promise((resolve, reject) => {
switch (verifyType) {
case 0:
verifyGenerator.verify(dataBlob, (err, verifyOutput) => {
if (err) {
reject(err);
} else {
resolve(verifyOutput);
}
});
break;
case 1:
verifyGenerator.verify(dataBlob, null, (err, verifyOutput) => {
if (err) {
reject(err);
} else {
resolve(verifyOutput);
}
});
break;
case 2:
verifyGenerator.verify(dataBlob, "", (err, verifyOutput) => {
if (err) {
reject(err);
} else {
resolve(verifyOutput);
}
});
break;
case 3:
verifyGenerator.verify(
dataBlob,
signDataBlob,
signDataBlob,
(err, verifyOutput) => {
if (err) {
reject(err);
} else {
resolve(verifyOutput);
}
}
);
break;
case 4:
verifyGenerator.verify(dataBlob, signDataBlob, (err, verifyOutput) => {
if (err) {
reject(err);
} else {
resolve(verifyOutput);
}
});
break;
default:
reject("err");
}
});
}
async function encryptAndDecryptNormalProcess(asyAlgoName, cipherAlgoName) {
var globalCipherText;
var globalRsaKeyPair;
......@@ -569,73 +454,31 @@ async function signAbnormalParameterProcess(
signVerifyAlgoName,
signType
) {
var globalRsaKeyPair;
var globalText = "This is a sign test";
var input = { data: stringTouInt8Array(globalText) };
return new Promise((resolve, reject) => {
let globalText = "This is a sign test";
let input = { data: stringTouInt8Array(globalText) };
try {
let specGenerator = createAsyKeyGeneratorBySpec(asyKeySpec);
let signGenerator = createAsySign(signVerifyAlgoName);
let keyPairPromise = specGenerator.generateKeyPair();
keyPairPromise
.then((keyPair) => {
globalRsaKeyPair = keyPair;
if (signType == 3) {
resolve(signForSignFailed(signGenerator, input, signType));
let keyPair = await specGenerator.generateKeyPair();
switch (signType) {
case 1:
await initSign(signGenerator, keyPair.priKey);
await updateSign(signGenerator, input);
await signForSign(signGenerator, "");
break;
case 2:
await initSign(signGenerator, keyPair.priKey);
await updateSign(signGenerator, input);
await signForSign(signGenerator, 111);
break;
default:
await signForSign(signGenerator, input);
break;
}
return initSign(signGenerator, globalRsaKeyPair.priKey);
})
.then((initSignOut) => {
console.log(
"[Callback] signAbnormalParameterProcess initSignOut:" + initSignOut
);
resolve(signForSignFailed(signGenerator, input, signType));
})
.catch((err) => {
reject(err);
});
});
}
async function verifyAbnormalParameterProcess(
asyKeySpec,
verifyAlgoName,
verifyType
) {
var globalRsaKeyPair;
var globalSignBlob;
var globalText = "This is a sign test";
var input = { data: stringTouInt8Array(globalText) };
return new Promise((resolve, reject) => {
let specGenerator = createAsyKeyGeneratorBySpec(asyKeySpec);
let verifyGenerator = createAsyVerify(verifyAlgoName);
let keyPairPromise = specGenerator.generateKeyPair();
keyPairPromise
.then((keyPair) => {
globalRsaKeyPair = keyPair;
if (verifyType == 4) {
resolve(verifyForVerify(verifyGenerator, input, globalSignBlob));
} catch (err) {
console.error("[Callback] signAbnormalParameterProcess catch err: " + err);
throw err;
}
return initVerify(verifyGenerator, globalRsaKeyPair.pubKey);
})
.then((initVerifyOut) => {
console.log(
"[Callback] verifyAbnormalParameterProcess initVerifyOut:" +
initVerifyOut
);
resolve(
verifyForVerifyFailed(
verifyGenerator,
input,
globalSignBlob,
verifyType
)
);
})
.catch((err) => {
reject(err);
});
});
}
async function encryptSetAndGetSpecInitProcess(asyKeyPairSpec, cipherAlgoName) {
......@@ -826,42 +669,41 @@ async function keyGenerationBySpecProcess(asyAlgoName) {
});
}
async function verifyAbnormalParameterSM2Process(
async function verifyAbnormalParameterProcess(
asyKeySpec,
verifyAlgoName,
signVerifyAlgoName,
verifyType
) {
var globalRsaKeyPair;
var globalSignBlob;
var globalText = "This is a sign test";
var input = { data: stringTouInt8Array(globalText) };
return new Promise((resolve, reject) => {
let specGenerator = createAsyKeyGenerator(asyKeySpec);
let verifyGenerator = createAsyVerify(verifyAlgoName);
let keyPairPromise = specGenerator.generateKeyPair();
keyPairPromise
.then((keyPair) => {
globalRsaKeyPair = keyPair;
return initVerify(verifyGenerator, globalRsaKeyPair.pubKey);
})
.then((initVerifyOut) => {
console.log(
"[Callback] verifyAbnormalParameterProcess initVerifyOut:" +
initVerifyOut
);
resolve(
verifyForVerifyFailed(
verifyGenerator,
input,
globalSignBlob,
verifyType
)
);
})
.catch((err) => {
reject(err);
});
});
let globalText = "This is a sign test";
let input = { data: stringTouInt8Array(globalText) };
try {
let specGenerator = createAsyKeyGeneratorBySpec(asyKeySpec);
let signGenerator = createAsySign(signVerifyAlgoName);
let verifyGenerator = createAsyVerify(signVerifyAlgoName);
let keyPair = await specGenerator.generateKeyPair();
await initSign(signGenerator, keyPair.priKey);
await updateSign(signGenerator, input);
let signBlob = await signForSign(signGenerator, input);
switch (verifyType) {
case 1:
await initVerify(verifyGenerator, keyPair.pubKey);
await updateVerify(verifyGenerator, input);
return await verifyForVerify(verifyGenerator, null, signBlob);
case 2:
await initVerify(verifyGenerator, keyPair.pubKey);
await updateVerify(verifyGenerator, input);
return await verifyForVerify(verifyGenerator, '', signBlob);
case 3:
await initVerify(verifyGenerator, keyPair.pubKey);
await updateVerify(verifyGenerator, input);
return await verifyForVerify(verifyGenerator, input, null);
default:
return await verifyForVerify(verifyGenerator, input, signBlob);
}
} catch (err) {
console.error("[Callback] verifyUpdateAbnormalParameterProcess catch err: " + err);
throw err;
}
}
export {
......@@ -873,6 +715,5 @@ export {
keyGenerationBySpecProcess,
signAndVerifySetAndGetSpecProcess,
signAbnormalParameterProcess,
verifyAbnormalParameterProcess,
verifyAbnormalParameterSM2Process,
verifyAbnormalParameterProcess
};
......@@ -14,11 +14,7 @@
*/
import cryptoFramework from "@ohos.security.cryptoFramework";
import {
stringTouInt8Array,
uInt8ArrayToShowStr,
uInt8ArrayToString,
} from "../common/publicDoString";
import { stringTouInt8Array, uInt8ArrayToShowStr, uInt8ArrayToString, } from "../common/publicDoString";
import {
createAsyKeyGenerator,
createAsyKeyGeneratorBySpec,
......@@ -145,67 +141,6 @@ async function updateSign(signGenerator, dataBlob) {
});
}
async function updateSignFailed(signGenerator, dataBlob, itemType) {
return new Promise((resolve, reject) => {
switch (itemType) {
case 0:
signGenerator
.update()
.then(() => {
resolve("update success");
})
.catch((err) => {
reject(err);
});
break;
case 1:
signGenerator
.update(null)
.then(() => {
resolve("update success");
})
.catch((err) => {
reject(err);
});
break;
case 2:
signGenerator
.update("")
.then(() => {
resolve("update success");
})
.catch((err) => {
reject(err);
});
break;
case 3:
let data = dataBlob;
for (let i = 1; i < 5000; i++) {
data = data + data;
}
signGenerator
.update(data)
.then(() => {
resolve("update success");
})
.catch((err) => {
reject(err);
});
break;
default:
signGenerator
.update(dataBlob)
.then(() => {
resolve("update success");
})
.catch((err) => {
reject(err);
});
break;
}
});
}
async function signForSign(signGenerator, dataBlob) {
return new Promise((resolve, reject) => {
signGenerator
......@@ -253,57 +188,6 @@ async function updateVerify(verifyGenerator, dataBlob) {
});
}
async function updateVerifyFailed(verifyGenerator, dataBlob, itemType) {
return new Promise((resolve, reject) => {
if (itemType == 0) {
verifyGenerator
.update()
.then(() => {
resolve("update success");
})
.catch((err) => {
reject(err);
});
} else if (itemType == 1) {
verifyGenerator
.update(null)
.then(() => {
resolve("update success");
})
.catch((err) => {
reject(err);
});
} else if (itemType == 2) {
verifyGenerator
.update("")
.then(() => {
resolve("update success");
})
.catch((err) => {
reject(err);
});
} else if (itemType == 3) {
verifyGenerator
.update(dataBlob, dataBlob)
.then(() => {
resolve("update success");
})
.catch((err) => {
reject(err);
});
} else {
verifyGenerator
.update(dataBlob)
.then(() => {
resolve("update success");
})
.catch((err) => {
reject(err);
});
}
});
}
async function verifyForVerify(verifyGenerator, dataBlob, signDataBlob) {
return new Promise((resolve, reject) => {
verifyGenerator
......@@ -808,35 +692,33 @@ async function updateAbnormalParameterProcess(
signVerifyAlgoName,
updateType
) {
var globalRsaKeyPair;
var globalText = "This is a sign test";
var input = { data: stringTouInt8Array(globalText) };
return new Promise((resolve, reject) => {
let globalText = "This is a sign test";
let input = { data: stringTouInt8Array(globalText) };
try {
let specGenerator = createAsyKeyGeneratorBySpec(asyKeySpec);
let signGenerator = createAsySign(signVerifyAlgoName);
let keyPairPromise = specGenerator.generateKeyPair();
keyPairPromise
.then((keyPair) => {
globalRsaKeyPair = keyPair;
if (updateType == 4) {
resolve(updateSignFailed(signGenerator, input, updateType));
let keyPair = await specGenerator.generateKeyPair();
switch (updateType) {
case 1:
await initSign(signGenerator, keyPair.priKey);
await updateSign(signGenerator, null);
break;
case 2:
await initSign(signGenerator, keyPair.priKey);
await updateSign(signGenerator, '');
break;
case 3:
await initSign(signGenerator, keyPair.priKey);
await updateSign(signGenerator, 222);
break;
default:
await updateSign(signGenerator, input);
break;
}
} catch (err) {
console.error("[Promise] updateAbnormalParameterProcess catch err: " + err);
throw err;
}
return initSign(signGenerator, globalRsaKeyPair.priKey);
})
.then((initSignOut) => {
console.log(
"[promise] updateAbnormalParameterProcess initSignOut:" + initSignOut
);
resolve(updateSignFailed(signGenerator, input, updateType));
})
.catch((err) => {
console.error(
"[promise] updateAbnormalParameterProcess catch err:" + err
);
reject(err);
});
});
}
async function verifyUpdateAbnormalParameterProcess(
......@@ -844,57 +726,37 @@ async function verifyUpdateAbnormalParameterProcess(
signVerifyAlgoName,
updateType
) {
var globalRsaKeyPair;
var globalText = "This is a sign test";
var input = { data: stringTouInt8Array(globalText) };
return new Promise((resolve, reject) => {
let globalText = "This is a sign test";
let input = { data: stringTouInt8Array(globalText) };
try {
let specGenerator = createAsyKeyGeneratorBySpec(asyKeySpec);
let signGenerator = createAsySign(signVerifyAlgoName);
let verifyGenerator = createAsyVerify(signVerifyAlgoName);
let keyPairPromise = specGenerator.generateKeyPair();
keyPairPromise
.then((rsaKeyPair) => {
globalRsaKeyPair = rsaKeyPair;
return initSign(signGenerator, globalRsaKeyPair.priKey);
})
.then((initSignOut) => {
console.log(
"[promise] verifyUpdateAbnormalParameterProcess initSignOut:" +
initSignOut
);
return updateSign(signGenerator, input);
})
.then((updateSignOut) => {
console.log(
"[promise] verifyUpdateAbnormalParameterProcess updateSignOut:" +
updateSignOut
);
return signForSign(signGenerator, input);
})
.then((signOut) => {
console.log(
"[promise] verifyUpdateAbnormalParameterProcess signOut:" + signOut
);
if (updateType == 4) {
resolve(updateVerifyFailed(verifyGenerator, input, updateType));
let keyPair = await specGenerator.generateKeyPair();
await initSign(signGenerator, keyPair.priKey);
await updateSign(signGenerator, input);
await signForSign(signGenerator, input);
switch (updateType) {
case 1:
await initVerify(verifyGenerator, keyPair.pubKey);
await updateVerify(verifyGenerator, null);
break;
case 2:
await initVerify(verifyGenerator, keyPair.pubKey);
await updateVerify(verifyGenerator, '');
break;
case 3:
await initVerify(verifyGenerator, keyPair.pubKey);
await updateVerify(verifyGenerator, 222);
break;
default:
await updateVerify(verifyGenerator, input);
break;
}
} catch (err) {
console.error("[Promise] verifyUpdateAbnormalParameterProcess catch err: " + err);
throw err;
}
return initVerify(verifyGenerator, globalRsaKeyPair.pubKey);
})
.then((initVerifyOut) => {
console.log(
"[promise] verifyUpdateAbnormalParameterProcess initVerifyOut:" +
initVerifyOut
);
resolve(updateVerifyFailed(verifyGenerator, input, updateType));
})
.catch((err) => {
console.error(
"[promise] VerifyUpdateAbnormalParameterProcess catch err:" + err
);
reject(err);
});
});
}
async function generateSpecKeyPair(asyKeySpec) {
......@@ -954,64 +816,6 @@ async function keyGenerationBySpecProcess(asyKeySpec) {
});
}
async function verifyUpdateAbnormalParameterSM2Process(
asyKeySpec,
signVerifyAlgoName,
updateType
) {
var globalRsaKeyPair;
var globalText = "This is a sign test";
var input = { data: stringTouInt8Array(globalText) };
return new Promise((resolve, reject) => {
let specGenerator = createAsyKeyGenerator(asyKeySpec);
let signGenerator = createAsySign(signVerifyAlgoName);
let verifyGenerator = createAsyVerify(signVerifyAlgoName);
let keyPairPromise = specGenerator.generateKeyPair();
keyPairPromise
.then((rsaKeyPair) => {
globalRsaKeyPair = rsaKeyPair;
return initSign(signGenerator, globalRsaKeyPair.priKey);
})
.then((initSignOut) => {
console.log(
"[Promise] verifyUpdateAbnormalParameterProcess initSignOut:" +
initSignOut
);
return updateSign(signGenerator, input);
})
.then((updateSignOut) => {
console.log(
"[Promise] verifyUpdateAbnormalParameterProcess updateSignOut:" +
updateSignOut
);
return signForSign(signGenerator, input);
})
.then((signOut) => {
console.log(
"[Promise] verifyUpdateAbnormalParameterProcess signOut:" + signOut
);
if (updateType == 4) {
resolve(updateVerifyFailed(verifyGenerator, input, updateType));
}
return initVerify(verifyGenerator, globalRsaKeyPair.pubKey);
})
.then((initVerifyOut) => {
console.log(
"[Promise] verifyUpdateAbnormalParameterProcess initVerifyOut:" +
initVerifyOut
);
resolve(updateVerifyFailed(verifyGenerator, input, updateType));
})
.catch((err) => {
console.error(
"[Promise] verifyUpdateAbnormalParameterProcess catch err:" + err
);
reject(err);
});
});
}
export {
encryptAndDecryptNormalProcess,
signAndVerifyNormalProcess,
......@@ -1024,6 +828,5 @@ export {
signAndVerifySetAndGetSpecProcess,
updateAbnormalParameterProcess,
verifyUpdateAbnormalParameterProcess,
keyGenerationBySpecProcess,
verifyUpdateAbnormalParameterSM2Process,
keyGenerationBySpecProcess
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册