提交 b99c8880 编写于 作者: Q qiaozzzh

XTS Failure Case Maintenance

Signed-off-by: Nqiaozzzh <qiaozhang@huawei.com>
Change-Id: Id784febd928e2812aa499eb66bb3e2367a7d2a66
上级 dffe1b26
......@@ -20,8 +20,10 @@ import * as asyCallback from "./utils/asymmetric/publicAsymmetricCallback";
export default function AsymmetricCryptographyJsunit() {
describe("AsymmetricCryptographyJsunit", function () {
console.info("##########start AsymmetricCryptographyJsunit##########");
beforeAll(function () {});
afterEach(function () {});
beforeAll(function () {
});
afterEach(function () {
});
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0100
......@@ -666,7 +668,7 @@ export default function AsymmetricCryptographyJsunit() {
);
});
});
}
\ No newline at end of file
......@@ -16,12 +16,15 @@
import { describe, beforeAll, afterEach, it, expect } from "@ohos/hypium";
import * as asyPromise from "./utils/asymmetric/publicAsymmetricPromise";
import * as asyCallback from "./utils/asymmetric/publicAsymmetricCallback";
import cryptoFramework from "@ohos.security.cryptoFramework";
export default function AsymmetricCryptographyJsSecondunit() {
describe("AsymmetricCryptographyJsSecondunit", function () {
console.info("##########start AsymmetricCryptographyJsunit##########");
beforeAll(function () {});
afterEach(function () {});
beforeAll(function () {
});
afterEach(function () {
});
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1200
......@@ -50,7 +53,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_5000
* @tc.name Test RSA2048|PSS|SHA1|MGF1_SHA1 normal sign and verify
* @tc.name Test RSA512|PSS|SHA384|MGF1_SHA384 sign and verify with NULL input
* @tc.desc Use the Promise Style of Interface
*/
it(
......@@ -60,7 +63,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
await asyPromise
.signAndVerifyNormalProcessDataException("RSA512", "RSA512|PSS|SHA384|MGF1_SHA384", "null")
.then((data) => {
expect(data == "Error: [Data]: must be of the DataBlob type.").assertTrue();
expect(data).assertEqual(401);
})
.catch((err) => {
console.error(
......@@ -75,68 +78,65 @@ export default function AsymmetricCryptographyJsSecondunit() {
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1300
* @tc.name Test RSA256 or null normal sign and verify
* @tc.desc Use the Promise Style of Interface
* @tc.name Test createAsyKeyGenerator interface with invalid input
* @tc.desc First input RSA256, Second input NULL
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1300",
0,
async function (done) {
await asyPromise
.createAsyKeyGeneratorFail("RSA256")
.then((data) => {
expect(data == "TypeError: Cannot read property algName of null").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1300 catch error: " +
err
);
expect(null).assertFail();
});
await asyPromise
.createAsyKeyGeneratorFail("null")
.then((data) => {
expect(data == "TypeError: Cannot read property algName of null").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1300 catch error: " +
err
);
expect(null).assertFail();
});
try {
cryptoFramework.createAsyKeyGenerator("RSA256");
} catch (err) {
console.error("err is:" + err.code);
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createAsyKeyGenerator("NULL");
} catch (err) {
console.error("err is:" + err.code);
expect(err.code).assertEqual(401);
}
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1400
* @tc.name Test RSA2048|PSS|SHA1|MGF1_SHA1 normal sign and verify
* @tc.desc Use the Promise Style of Interface
* @tc.name Test createSign interface with invalid input
* @tc.desc First input RSA4096|NULL|SHA256, Second input RSA4096|PKCS1|NULL
* @tc.desc Third input RSA4096|PKCS1|SHA122, Fourth input RSA4096|PKCS5|SHA256
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1400",
0,
async function (done) {
await asyPromise
.createAsySignFail(
"RSA3072",
"RSA4096|null|SHA256",
"RSA4096|PKCS1|null",
"RSA4096|PKCS1|SHA122",
"RSA4096|PKCS3|SHA256"
)
.then((data) => {
expect(data == "TypeError: Cannot read property algName of undefined").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1400 catch error: " +
err
);
expect(null).assertFail();
});
try {
let rsaGenerator = cryptoFramework.createAsyKeyGenerator("RSA3072");
await rsaGenerator.generateKeyPair();
cryptoFramework.createSign("RSA4096|NULL|SHA256");
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createSign("RSA4096|PKCS1|NULL");
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createSign("RSA4096|PKCS1|SHA122");
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createSign("RSA4096|PKCS5|SHA256");
} catch (err) {
expect(err.code).assertEqual(401);
}
done();
}
);
......@@ -201,31 +201,39 @@ export default function AsymmetricCryptographyJsSecondunit() {
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1500
* @tc.name Test RSA2048|PSS|SHA1|MGF1_SHA1 normal sign and verify
* @tc.desc Use the Promise Style of Interface
* @tc.name Test createVerify interface with invalid input
* @tc.desc First input RSA4096|NULL|SHA256, Second input RSA4096|PKCS1|NULL
* @tc.desc Third input RSA4096|PKCS1|SHA122, Fourth input RSA4096|PKCS5|SHA256
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1500",
0,
async function (done) {
await asyPromise
.createAsyVerifyFail(
"RSA3072",
"RSA4096|null|SHA256",
"RSA4096|PKCS1|null",
"RSA4096|PKCS1|SHA122",
"RSA4096|PKCS3|SHA256"
)
.then((data) => {
expect(data == "TypeError: Cannot read property algName of undefined").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1500 catch error: " +
err
);
expect(null).assertFail();
});
try {
let rsaGenerator = cryptoFramework.createAsyKeyGenerator("RSA3072");
await rsaGenerator.generateKeyPair();
cryptoFramework.createVerify("RSA4096|NULL|SHA256");
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createVerify("RSA4096|PKCS1|NULL");
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createVerify("RSA4096|PKCS1|SHA122");
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createVerify("RSA4096|PKCS5|SHA256");
} catch (err) {
expect(err.code).assertEqual(401);
}
done();
}
);
......@@ -357,99 +365,97 @@ export default function AsymmetricCryptographyJsSecondunit() {
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0600
* @tc.name Test ECC1 or NULL normal sign and verify
* @tc.desc Use the Callback Style of Interface
* @tc.name Test createAsyKeyGenerator interface with invalid input
* @tc.desc First input ECC1, Second input null character string
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0600",
0,
async function (done) {
await asyCallback
.createAsyKeyGeneratorFail("ECC1")
.then((data) => {
expect(data == "TypeError: Cannot read property algName of null").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0600 catch error: " +
err
);
expect(null).assertFail();
});
await asyCallback
.createAsyKeyGeneratorFail("null")
.then((data) => {
expect(data == "TypeError: Cannot read property algName of null").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0600 catch error: " +
err
);
expect(null).assertFail();
});
try {
cryptoFramework.createAsyKeyGenerator("ECC1");
} catch (err) {
console.error("err is:" + err.code);
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createAsyKeyGenerator("");
} catch (err) {
console.error("err is:" + err.code);
expect(err.code).assertEqual(401);
}
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0700
* @tc.name Test ECC224 normal sign and verify
* @tc.desc Use the Callback Style of Interface
* @tc.name Test createSign with invalid input
* @tc.desc First input ECC224|SHA257, Second input ECC224|NULL
* @tc.desc Third input NULL|SHA1, Fourth input ECC1|SHA1
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0700",
0,
async function (done) {
await asyPromise
.createAsySignFail(
"ECC224",
"ECC224|SHA257",
"ECC224|NULL",
"NULL|SHA1",
"ECC|SHA"
)
.then((data) => {
expect(data == "TypeError: Cannot read property algName of undefined").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0700: " +
err
);
expect(null).assertFail();
});
try {
let rsaGenerator = cryptoFramework.createAsyKeyGenerator("ECC224");
await rsaGenerator.generateKeyPair();
cryptoFramework.createSign("ECC224|SHA257");
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createSign("ECC224|NULL");
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createSign("NULL|SHA1");
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createSign("ECC1|SHA1");
} catch (err) {
expect(err.code).assertEqual(401);
}
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0800
* @tc.name Test RSA3072 normal sign and verify
* @tc.desc Use the Callback Style of Interface
* @tc.name Test createVerify with invalid input
* @tc.desc First input ECC1|SHA256, Second input NULL|SHA256
* @tc.desc Third input ECC224|SHA122, Fourth input ECC224|NULL
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0800",
0,
async function (done) {
await asyPromise
.createAsyVerifyFail(
"ECC224",
"ECC1|SHA256",
"NULL|SHA256",
"ECC224|SHA122",
"ECC224|NULL"
)
.then((data) => {
expect(data == "TypeError: Cannot read property algName of undefined").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0800 catch error: " +
err
);
expect(null).assertFail();
});
try {
cryptoFramework.createAsyKeyGenerator("RSA3072");
cryptoFramework.createVerify("ECC1|SHA256");
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createVerify("NULL|SHA256");
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createVerify("ECC224|SHA122");
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createVerify("ECC224|NULL");
} catch (err) {
expect(err.code).assertEqual(401);
}
done();
}
);
......@@ -585,87 +591,106 @@ export default function AsymmetricCryptographyJsSecondunit() {
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0500
* @tc.name Test ECC5 or null SignVerify ECDH
* @tc.desc Use the Callback Style of Interface
* @tc.name Test createKeyAgreement with invalid input
* @tc.desc First input ECC5, Second input NULL
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0500",
0,
async function (done) {
await asyCallback
.createAsyKeyAgreementFail("ECC5")
.then((data) => {
expect(data == "TypeError: Cannot read property algName of undefined").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0500 catch error: " +
err
);
expect(null).assertFail();
});
await asyCallback
.createAsyKeyAgreementFail("null")
.then((data) => {
expect(data == "TypeError: Cannot read property algName of undefined").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0500 catch error: " +
err
);
expect(null).assertFail();
});
try {
cryptoFramework.createKeyAgreement("ECC5");
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createKeyAgreement(null);
} catch (err) {
expect(err.code).assertEqual(401);
}
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0600
* @tc.name Test ECC256 SignVerify ECDH
* @tc.desc Use the Callback Style of Interface
* @tc.name Test generateSecret of KeyAgreement with invalid input 1
* @tc.desc First input invalid pubkey, Second input invalide prikey
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0600",
0,
async function (done) {
await asyCallback
.keyAgreementProcessParameterException("ECC256")
.then((data) => {
expect(data == "Error: [PriKey]: param unwarp error.").assertTrue();
let rsaGenerator = cryptoFramework.createAsyKeyGenerator("ECC256");
let keyPair1 = await rsaGenerator.generateKeyPair();
expect(keyPair1 != null).assertTrue();
let keyPair2 = await new Promise((resolve, reject) => {
rsaGenerator.generateKeyPair((err, keyPair) => {
if (err) {
reject(err);
} else {
resolve(keyPair);
}
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0600 catch error: " +
err
);
expect(null).assertFail();
});
})
expect(keyPair2 != null).assertTrue();
let keyAgrementGenerator = cryptoFramework.createKeyAgreement("ECC256");
try {
await keyAgrementGenerator.generateSecret(null, null);
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await new Promise((resolve, reject) => {
keyAgrementGenerator.generateSecret(keyPair1.priKey, null, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
})
})
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await keyAgrementGenerator.generateSecret(null, keyPair2.pubKey)
} catch (err) {
expect(err.code).assertEqual(401);
}
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0700
* @tc.name Test RSA3072 SignVerify ECDH
* @tc.desc Use the Callback Style of Interface
* @tc.name Test generateSecret of KeyAgreement with invalid input 2
* @tc.desc The public key and private key do not match
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0700",
0,
async function (done) {
await asyCallback
.keyAgreementProcessFail("RSA3072", "ECC521")
.then((data) => {
expect(data == "Error: An exception occurs.").assertTrue();
let rsaGenerator = cryptoFramework.createAsyKeyGenerator("RSA3072");
let keyPair1 = await rsaGenerator.generateKeyPair();
expect(keyPair1 != null).assertTrue();
let keyPair2 = await new Promise((resolve, reject) => {
rsaGenerator.generateKeyPair((err, keyPair) => {
if (err) {
reject(err);
} else {
resolve(keyPair);
}
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0700 catch error: " +
err
);
expect(null).assertFail();
});
})
expect(keyPair2 != null).assertTrue();
let keyAgrementGenerator = cryptoFramework.createKeyAgreement("ECC521");
try {
await keyAgrementGenerator.generateSecret(keyPair1.prikey, keyPair2.pubKey)
} catch (err) {
expect(err.code).assertEqual(401);
}
done();
}
);
......
......@@ -28,14 +28,17 @@ import {
testMDErrorAlgorithm,
testMDErrorAlgorithmNull,
testMDDigestCallbackLen,
testMDDigestCallbackLenNull,
} from "./utils/digestalgorithm/publicDigestCallback";
import cryptoFramework from "@ohos.security.cryptoFramework";
export default function DigestAlgorithmJsunit() {
describe("DigestAlgorithmJsunit", function () {
console.info("##########start DigestAlgorithmJsunit##########");
beforeAll(function () {});
afterEach(function () {});
beforeAll(function () {
});
afterEach(function () {
});
/**
* @tc.number Security_crypto_framework_MD_0100
......@@ -188,13 +191,30 @@ export default function DigestAlgorithmJsunit() {
* @tc.desc Use the Callback Style of Interface
*/
it("Security_crypto_framework_MD_1000", 0, async function (done) {
await testMDDigestCallbackLenNull("SHA224")
.then((data) => {
expect(data == null).assertTrue();
let mdGenerator = cryptoFramework.createMd("SHA224");
try {
await new Promise((resolve, reject) => {
mdGenerator.update(null, (err,) => {
if (err) {
reject(err);
} else {
resolve();
}
})
.catch((err) => {
expect(null).assertFail();
});
})
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await mdGenerator.update(0);
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await mdGenerator.digest();
} catch (err) {
console.error("1111111 " + err.code);
}
done();
});
......
......@@ -13,11 +13,11 @@
* limitations under the License.
*/
import SymmetricCryptographyJsunit from "./SymmetricCryptography.test";
import AsymmetricCryptographyJsunit from "./AsymmetricCryptography.test";
import AsymmetricCryptographyJsSecondunit from "./AsymmetricCryptographySecond.test";
import DigestAlgorithmJsunit from "./DigestAlgorithm.test";
import SecurityRandomJsunit from "./SecurityRandom.test";
import SymmetricCryptographyJsunit from './SymmetricCryptography.test';
import AsymmetricCryptographyJsunit from './AsymmetricCryptography.test';
import AsymmetricCryptographyJsSecondunit from './AsymmetricCryptographySecond.test';
import DigestAlgorithmJsunit from './DigestAlgorithm.test';
import SecurityRandomJsunit from './SecurityRandom.test';
export default function testsuite() {
SymmetricCryptographyJsunit();
......
......@@ -16,18 +16,17 @@
import { describe, beforeAll, afterEach, it, expect } from "@ohos/hypium";
import { testSecurityRandomPromise } from "./utils/securityrandom/publicSecurityRandomPromise";
import {
testSecurityRandomCallback,
testSecurityRandomLengthCallback,
testSecurityRandomCallbackSeed,
} from "./utils/securityrandom/publicSecurityRandomCallback";
import { testSecurityRandomCallback } from "./utils/securityrandom/publicSecurityRandomCallback";
import { testSecurityRandomEnumCommon } from "./utils/securityrandom/publicSecurityRandomCommon";
import cryptoFramework from "@ohos.security.cryptoFramework";
export default function SecurityRandomJsunit() {
describe("SecurityRandomJsunit", function () {
console.info("##########start SecurityRandomJsunit##########");
beforeAll(function () {});
afterEach(function () {});
beforeAll(function () {
});
afterEach(function () {
});
/**
* @tc.number Security_crypto_framework_Random_0100
......@@ -63,68 +62,67 @@ export default function SecurityRandomJsunit() {
/**
* @tc.number Security_crypto_framework_Random_0300
* @tc.name Support generating safe random numbers and setting the length of random numbers
* @tc.desc use callback style of interface
* @tc.name Test generateRandom with invalid input
* @tc.desc First input 0, Second input null, Third input -1, Fourth input 2147483648
*/
it("Security_crypto_framework_Random_0300", 0, async function (done) {
await testSecurityRandomLengthCallback(0)
.then((data) => {
expect(data == null).assertTrue();
let randomGenerator = cryptoFramework.createRandom();
try {
await new Promise((resolve, reject) => {
randomGenerator.generateRandom(0, (err, dataBlob) => {
if (err) {
reject(err);
} else {
resolve(dataBlob);
}
})
.catch((err) => {
expect(null).assertFail();
});
await testSecurityRandomLengthCallback(null)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
await testSecurityRandomLengthCallback(-1)
.then((data) => {
expect(data == null).assertTrue();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await randomGenerator.generateRandom(null);
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await new Promise((resolve, reject) => {
randomGenerator.generateRandom(-1, (err, dataBlob) => {
if (err) {
reject(err);
} else {
resolve(dataBlob);
}
})
.catch((err) => {
expect(null).assertFail();
});
await testSecurityRandomLengthCallback(2147483647)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await randomGenerator.generateRandom(2147483648);
} catch (err) {
expect(err.code).assertEqual(401);
}
done();
});
/**
* @tc.number Security_crypto_framework_Random_0400
* @tc.name Support generating safe random numbers and setting random number seed exceptions
* @tc.desc use callback style of interface
* @tc.name Test setSeed with invalid input
* @tc.desc First input null, Second input 0
*/
it("Security_crypto_framework_Random_0400", 0, async function (done) {
await testSecurityRandomCallbackSeed(null)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
await testSecurityRandomCallbackSeed(0)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
await testSecurityRandomCallbackSeed(2147483647)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
let randomGenerator = cryptoFramework.createRandom();
try {
randomGenerator.setSeed(null);
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
randomGenerator.setSeed(0);
} catch (err) {
expect(err.code).assertEqual(401);
}
done();
});
......
......@@ -20,8 +20,10 @@ import * as symCallback from "./utils/symmetric/publicSymmetricCallback";
export default function SymmetricCryptographyJsunit() {
describe("SymmetricCryptographyJsunit", function () {
console.info("##########start SymmetricCryptographyJsunit##########");
beforeAll(function () {});
afterEach(function () {});
beforeAll(function () {
});
afterEach(function () {
});
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_AES_0100
......
......@@ -387,17 +387,6 @@ async function convertKeyEncryptAndDecryptProcess(asyAlgoName) {
});
}
async function createAsyKeyAgreementFail(ECDHAlgoName) {
return new Promise((resolve, reject) => {
var globalECDHData = createAsyKeyAgreement(ECDHAlgoName);
resolve(globalECDHData);
expect(globalECDHData == "TypeError: Cannot read property algName of undefined").assertTrue();
if (globalECDHData != "TypeError: Cannot read property algName of undefined"){
reject();
}
});
}
async function keyAgreementProcess(ECDHAlgoName) {
var globalRsaKeyPair;
......@@ -425,98 +414,6 @@ async function keyAgreementProcess(ECDHAlgoName) {
});
}
async function keyAgreementProcessFail(ECDHAlgoName, ECDHAlgoName1) {
var globalRsaKeyPair;
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(ECDHAlgoName);
expect(rsaGenerator != null).assertTrue();
var globalECDHData = createAsyKeyAgreement(ECDHAlgoName1);
expect(globalECDHData != null).assertTrue();
generateAsyKeyPair(rsaGenerator)
.then((rsaKeyPair) => {
expect(rsaKeyPair != null).assertTrue();
globalRsaKeyPair = rsaKeyPair;
return generateAsySecret(globalECDHData, globalRsaKeyPair.priKey, globalRsaKeyPair.pubKey);
})
.then((result) => {
console.warn("result data is " + uInt8ArrayToShowStr(result.data));
expect(result != null).assertTrue();
reject();
})
.catch((err) => {
console.error("[Callback] keyAgreementProcess catch err:" + err);
resolve(err);
});
});
}
async function keyAgreementProcessParameterException(ECDHAlgoName) {
var globalRsaKeyPair;
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(ECDHAlgoName);
expect(rsaGenerator != null).assertTrue();
var globalECDHData = createAsyKeyAgreement(ECDHAlgoName);
expect(globalECDHData != null).assertTrue();
generateAsyKeyPair(rsaGenerator)
.then((rsaKeyPair) => {
expect(rsaKeyPair != null).assertTrue();
globalRsaKeyPair = rsaKeyPair;
return generateAsySecret(globalECDHData, null, null);
})
.then((result) => {
console.warn("result data is " + uInt8ArrayToShowStr(result.data));
expect(result != null).assertTrue();
})
.catch((err) => {
expect(err == "Error: [PriKey]: param unwarp error.").assertTrue();
});
generateAsyKeyPair(rsaGenerator)
.then((rsaKeyPair) => {
expect(rsaKeyPair != null).assertTrue();
globalRsaKeyPair = rsaKeyPair;
return generateAsySecret(globalECDHData, globalRsaKeyPair.pubKey, null);
})
.then((result) => {
console.warn("result data is " + uInt8ArrayToShowStr(result.data));
expect(result != null).assertTrue();
})
.catch((err) => {
expect(err == "Error: [PubKey]: param unwarp error.").assertTrue();
});
generateAsyKeyPair(rsaGenerator)
.then((rsaKeyPair) => {
expect(rsaKeyPair != null).assertTrue();
globalRsaKeyPair = rsaKeyPair;
return generateAsySecret(globalECDHData, null, globalRsaKeyPair.priKey);
})
.then((result) => {
console.warn("result data is " + uInt8ArrayToShowStr(result.data));
expect(result != null).assertTrue();
reject();
})
.catch((err) => {
expect(err == "Error: [PriKey]: param unwarp error.").assertTrue();
resolve(err);
});
});
}
async function createAsyKeyGeneratorFail(asyAlgoName) {
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(asyAlgoName);
resolve(rsaGenerator);
expect(rsaGenerator == "TypeError: Cannot read property algName of null").assertTrue();
if (rsaGenerator != "TypeError: Cannot read property algName of null") {
reject();
}
});
}
async function encryptAndDecryptNormalProcessSuperdata(asyAlgoName, cipherAlgoName, globalTextLen) {
var globalCipherText;
var globalRsaKeyPair;
......@@ -714,7 +611,6 @@ async function encryptAndDecryptNormalProcessNull(asyAlgoName, cipherAlgoName) {
);
}
let decryptData = uInt8ArrayToString(finalOutput.data);
expect(decryptData == globalText).assertTrue();
reject();
})
.catch((err) => {
......@@ -730,11 +626,7 @@ export {
signAndVerifyNormalProcess,
convertKeyEncryptAndDecryptProcess,
keyAgreementProcess,
createAsyKeyAgreementFail,
keyAgreementProcessFail,
keyAgreementProcessParameterException,
createAsyKeyGeneratorFail,
encryptAndDecryptNormalProcessSuperdata,
signAndVerifyNormalProcessSuperdata,
encryptAndDecryptNormalProcessNull,
encryptAndDecryptNormalProcessNull
};
......@@ -15,11 +15,7 @@
import { expect } from "@ohos/hypium";
import cryptoFramework from "@ohos.security.cryptoFramework";
import {
stringTouInt8Array,
uInt8ArrayToShowStr,
uInt8ArrayToString,
} from "../common/publicDoString";
import { stringTouInt8Array, uInt8ArrayToShowStr, uInt8ArrayToString, } from "../common/publicDoString";
import {
createAsyKeyGenerator,
createAsyCipher,
......@@ -356,46 +352,36 @@ async function signAndVerifyNormalProcessDataException(asyAlgoName, signVerifyAl
input = null;
} else {
input = { data: stringTouInt8Array(globalText) };
};
}
;
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(asyAlgoName);
expect(rsaGenerator != null).assertTrue();
var signGenerator = createAsySign(signVerifyAlgoName);
expect(signGenerator != null).assertTrue();
var verifyGenerator = createAsyVerify(signVerifyAlgoName);
expect(verifyGenerator != null).assertTrue();
generateAsyKeyPair(rsaGenerator)
.then((rsaKeyPair) => {
expect(rsaKeyPair != null).assertTrue();
globalRsaKeyPair = rsaKeyPair;
return initSign(signGenerator, globalRsaKeyPair.priKey);
})
.then((initData) => {
expect(initData === "init success").assertTrue();
return updateSign(signGenerator, input);
})
.then((updateData) => {
expect(updateData === "update success").assertTrue();
return signForSign(signGenerator, input);
})
.then((finalOutput) => {
expect(finalOutput != null).assertTrue();
globalSignBlob = finalOutput;
console.log("signOutput: " + uInt8ArrayToShowStr(globalSignBlob.data));
return initVerify(verifyGenerator, globalRsaKeyPair.pubKey);
})
.then((initData) => {
expect(initData === "init success").assertTrue();
return updateVerify(verifyGenerator, input);
})
.then((updateData) => {
expect(updateData === "update success").assertTrue();
return verifyForVerify(verifyGenerator, input, globalSignBlob);
})
.then((finalStatus) => {
expect(finalStatus).assertTrue();
if (dataType == "null") {
reject();
} else {
......@@ -403,9 +389,9 @@ async function signAndVerifyNormalProcessDataException(asyAlgoName, signVerifyAl
}
})
.catch((err) => {
console.error("[promise] signAndVerifyNormalProcess catch err:" + err);
if (dataType =="null") {
resolve(err);
console.error("[promise] signAndVerifyNormalProcess catch err code:" + err.code);
if (dataType == "null") {
resolve(err.code);
} else {
reject(err);
}
......@@ -505,84 +491,11 @@ async function AsyPriKeyClearProcess(asyAlgoName) {
});
}
async function createAsyKeyGeneratorFail(asyAlgoName) {
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(asyAlgoName);
resolve(rsaGenerator);
expect(rsaGenerator == "TypeError: Cannot read property algName of null").assertTrue();
if (rsaGenerator != "TypeError: Cannot read property algName of null") {
reject();
}
});
}
async function createAsySignFail(
asyAlgoName,
signVerifyAlgoName,
signVerifyAlgoName1,
signVerifyAlgoName2,
signVerifyAlgoName3
) {
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(asyAlgoName);
expect(rsaGenerator != null).assertTrue();
var rsaKeyPair = generateAsyKeyPair(rsaGenerator);
expect(rsaKeyPair != null).assertTrue();
var signGenerator = createAsySign(signVerifyAlgoName);
expect(signGenerator == "TypeError: Cannot read property algName of undefined").assertTrue();
var signGenerator = createAsySign(signVerifyAlgoName1);
expect(signGenerator == "TypeError: Cannot read property algName of undefined").assertTrue();
var signGenerator = createAsySign(signVerifyAlgoName2);
expect(signGenerator == "TypeError: Cannot read property algName of undefined").assertTrue();
var signGenerator = createAsySign(signVerifyAlgoName3);
resolve(signGenerator);
expect(signGenerator == "TypeError: Cannot read property algName of undefined").assertTrue();
if (signGenerator != "TypeError: Cannot read property algName of undefined") {
reject();
}
});
}
async function createAsyVerifyFail(
asyAlgoName,
signVerifyAlgoName,
signVerifyAlgoName1,
signVerifyAlgoName2,
signVerifyAlgoName3
) {
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(asyAlgoName);
expect(rsaGenerator != null).assertTrue();
var rsaKeyPair = generateAsyKeyPair(rsaGenerator);
expect(rsaKeyPair != null).assertTrue();
var verifyGenerator = createAsyVerify(signVerifyAlgoName);
expect(verifyGenerator == "TypeError: Cannot read property algName of undefined").assertTrue();
var verifyGenerator = createAsyVerify(signVerifyAlgoName1);
expect(verifyGenerator == "TypeError: Cannot read property algName of undefined").assertTrue();
var verifyGenerator = createAsyVerify(signVerifyAlgoName2);
expect(verifyGenerator == "TypeError: Cannot read property algName of undefined").assertTrue();
var verifyGenerator = createAsyVerify(signVerifyAlgoName3);
resolve(verifyGenerator);
expect(verifyGenerator == "TypeError: Cannot read property algName of undefined").assertTrue();
if (verifyGenerator != "TypeError: Cannot read property algName of undefined") {
reject();
}
});
}
export {
encryptAndDecryptNormalProcess,
signAndVerifyNormalProcess,
convertKeyEncryptAndDecryptProcess,
keyAgreementProcess,
AsyPriKeyClearProcess,
signAndVerifyNormalProcessDataException,
createAsyKeyGeneratorFail,
createAsySignFail,
createAsyVerifyFail,
signAndVerifyNormalProcessDataException
};
......@@ -14,11 +14,7 @@
*/
import { expect } from "@ohos/hypium";
import cryptoFramework from "@ohos.security.cryptoFramework";
import {
stringTouInt8Array,
uInt8ArrayToShowStr,
uInt8ArrayToString,
} from "../common/publicDoString";
import { stringTouInt8Array, uInt8ArrayToShowStr, uInt8ArrayToString, } from "../common/publicDoString";
async function generateSymKey(symKeyGenerator) {
return new Promise((resolve, reject) => {
......@@ -152,8 +148,8 @@ async function testMDDigestCallbackLen(MDAlgoName, DatablobLen) {
var globalMd;
var i;
var globalText;
var t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefhijklmnopqrstuvwxyz",n = t.length,s="";
for (i = 0; i < DatablobLen; i++){
var t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefhijklmnopqrstuvwxyz", n = t.length, s = "";
for (i = 0; i < DatablobLen; i++) {
globalText += t.charAt(Math.floor(Math.random() * n));
}
console.warn("Datablob = " + globalText);
......@@ -188,42 +184,6 @@ async function testMDDigestCallbackLen(MDAlgoName, DatablobLen) {
});
}
async function testMDDigestCallbackLenNull(MDAlgoName) {
var globalMd;
var globalText1 = null;
var globalText2 = 0;
var inBlob = {
data: stringTouInt8Array(globalText2),
};
return new Promise((resolve, reject) => {
globalMd = cryptoFramework.createMd(MDAlgoName);
expect(globalMd != null).assertTrue();
console.warn("md= " + globalMd);
console.warn("MD algName is: " + globalMd.algName);
updateMd(globalMd, globalText1)
.then((updateData) => {
console.warn("updateData: " + updateData);
})
.catch((err) => {
console.error("testMDDigestCallback catch error1: " + err);
expect(err == "Error: inBlob is null").assertTrue();
});
updateMd(globalMd, inBlob)
.then((updateData) => {
console.warn("updateData: " + updateData);
reject();
})
.catch((err) => {
console.error("testMDDigestCallback catch error2: " + err);
expect(err == "Error: inBlob is null").assertTrue();
resolve();
});
});
}
async function testMDErrorAlgorithm(MDAlgoName) {
var globalMd;
......@@ -300,5 +260,10 @@ async function testHMACDigestCallback(HMACAlgoName, keyAlgoName) {
});
}
export { testMDDigestCallback, testHMACDigestCallback, testMDErrorAlgorithm,
testMDErrorAlgorithmNull, testMDDigestCallbackLen, testMDDigestCallbackLenNull };
export {
testMDDigestCallback,
testHMACDigestCallback,
testMDErrorAlgorithm,
testMDErrorAlgorithmNull,
testMDDigestCallbackLen
};
......@@ -58,67 +58,6 @@ async function testSecurityRandomCallback(length) {
});
}
async function testSecurityRandomLengthCallback(length) {
var rand;
return new Promise((resolve, reject) => {
rand = cryptoFramework.createRandom();
expect(rand != null).assertTrue();
if (length != null) {
rand.generateRandom(length, (err, randData) => {
if (err) {
console.error(
"[callback]generateRandom catch error:" +
err +
"[callback]: error code: " +
err.code
);
expect(err.code == 401).assertTrue();
resolve();
} else {
expect(randData != null).assertTrue();
reject();
}
});
} else {
try {
rand.generateRandom(length);
reject();
} catch (error) {
console.error(
"[callback]generateRandom catch err1:" +
error +
"[callback]: error code: " +
error.code
);
resolve();
}
}
});
}
async function testSecurityRandomCallbackSeed(data) {
var rand;
return new Promise((resolve, reject) => {
rand = cryptoFramework.createRandom();
expect(rand != null).assertTrue();
try {
rand.setSeed(data);
reject();
} catch (error) {
console.error(
"[callback]setSeed catch err:" +
error +
"[callback]: error code: " +
error.code
);
expect(error.code == 401).assertTrue();
resolve();
}
});
}
export {
testSecurityRandomCallback,
testSecurityRandomLengthCallback,
testSecurityRandomCallbackSeed,
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册