未验证 提交 c617ad84 编写于 作者: O openharmony_ci 提交者: Gitee

!8990 【OpenHarmony 4.0.7.2】【安全子系统】【master】XTS Adaptation requirements

Merge pull request !8990 from qiaozzzh/0612_1
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
import { describe, beforeAll, afterEach, it, expect } from "@ohos/hypium"; import { describe, beforeAll, afterEach, it, expect } from "@ohos/hypium";
import * as asyPromise from "./utils/asymmetric/publicAsymmetricPromise"; import * as asyPromise from "./utils/asymmetric/publicAsymmetricPromise";
import * as asyCallback from "./utils/asymmetric/publicAsymmetricCallback"; import * as asyCallback from "./utils/asymmetric/publicAsymmetricCallback";
import cryptoFramework from "@ohos.security.cryptoFramework";
export default function AsymmetricCryptographyJsunit() { export default function AsymmetricCryptographyJsunit() {
describe("AsymmetricCryptographyJsunit", function () { describe("AsymmetricCryptographyJsunit", function () {
...@@ -398,21 +399,16 @@ export default function AsymmetricCryptographyJsunit() { ...@@ -398,21 +399,16 @@ export default function AsymmetricCryptographyJsunit() {
"Security_crypto_framework_ASymmetric_Encryption_RSA_1400", "Security_crypto_framework_ASymmetric_Encryption_RSA_1400",
0, 0,
async function (done) { async function (done) {
await asyCallback let rsaGenerator = cryptoFramework.createAsyKeyGenerator("RSA4096");
.encryptAndDecryptNormalProcessNull( let cipherGeneratorEncrypt = cryptoFramework.createCipher("RSA4096|PKCS1");
"RSA4096", let globalRsaKeyPair = rsaGenerator.generateKeyPair();
"RSA4096|PKCS1" try {
) await cipherGeneratorEncrypt.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, globalRsaKeyPair, null);
.then((data) => {
expect(data == "Error: doFinal failed.").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_1400 catch error: " +
err
);
expect(null).assertFail(); expect(null).assertFail();
}); } catch (err) {
console.error("err is:" + err.code);
expect(err.code).assertEqual(401);
}
done(); done();
} }
); );
......
...@@ -87,6 +87,7 @@ export default function AsymmetricCryptographyJsSecondunit() { ...@@ -87,6 +87,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
async function (done) { async function (done) {
try { try {
cryptoFramework.createAsyKeyGenerator("RSA256"); cryptoFramework.createAsyKeyGenerator("RSA256");
expect(null).assertFail();
} catch (err) { } catch (err) {
console.error("err is:" + err.code); console.error("err is:" + err.code);
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
...@@ -94,6 +95,7 @@ export default function AsymmetricCryptographyJsSecondunit() { ...@@ -94,6 +95,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
try { try {
cryptoFramework.createAsyKeyGenerator("NULL"); cryptoFramework.createAsyKeyGenerator("NULL");
expect(null).assertFail();
} catch (err) { } catch (err) {
console.error("err is:" + err.code); console.error("err is:" + err.code);
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
...@@ -116,24 +118,28 @@ export default function AsymmetricCryptographyJsSecondunit() { ...@@ -116,24 +118,28 @@ export default function AsymmetricCryptographyJsSecondunit() {
let rsaGenerator = cryptoFramework.createAsyKeyGenerator("RSA3072"); let rsaGenerator = cryptoFramework.createAsyKeyGenerator("RSA3072");
await rsaGenerator.generateKeyPair(); await rsaGenerator.generateKeyPair();
cryptoFramework.createSign("RSA4096|NULL|SHA256"); cryptoFramework.createSign("RSA4096|NULL|SHA256");
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
try { try {
cryptoFramework.createSign("RSA4096|PKCS1|NULL"); cryptoFramework.createSign("RSA4096|PKCS1|NULL");
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
try { try {
cryptoFramework.createSign("RSA4096|PKCS1|SHA122"); cryptoFramework.createSign("RSA4096|PKCS1|SHA122");
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
try { try {
cryptoFramework.createSign("RSA4096|PKCS5|SHA256"); cryptoFramework.createSign("RSA4096|PKCS5|SHA256");
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
...@@ -213,24 +219,28 @@ export default function AsymmetricCryptographyJsSecondunit() { ...@@ -213,24 +219,28 @@ export default function AsymmetricCryptographyJsSecondunit() {
let rsaGenerator = cryptoFramework.createAsyKeyGenerator("RSA3072"); let rsaGenerator = cryptoFramework.createAsyKeyGenerator("RSA3072");
await rsaGenerator.generateKeyPair(); await rsaGenerator.generateKeyPair();
cryptoFramework.createVerify("RSA4096|NULL|SHA256"); cryptoFramework.createVerify("RSA4096|NULL|SHA256");
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
try { try {
cryptoFramework.createVerify("RSA4096|PKCS1|NULL"); cryptoFramework.createVerify("RSA4096|PKCS1|NULL");
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
try { try {
cryptoFramework.createVerify("RSA4096|PKCS1|SHA122"); cryptoFramework.createVerify("RSA4096|PKCS1|SHA122");
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
try { try {
cryptoFramework.createVerify("RSA4096|PKCS5|SHA256"); cryptoFramework.createVerify("RSA4096|PKCS5|SHA256");
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
...@@ -374,6 +384,7 @@ export default function AsymmetricCryptographyJsSecondunit() { ...@@ -374,6 +384,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
async function (done) { async function (done) {
try { try {
cryptoFramework.createAsyKeyGenerator("ECC1"); cryptoFramework.createAsyKeyGenerator("ECC1");
expect(null).assertFail();
} catch (err) { } catch (err) {
console.error("err is:" + err.code); console.error("err is:" + err.code);
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
...@@ -381,6 +392,7 @@ export default function AsymmetricCryptographyJsSecondunit() { ...@@ -381,6 +392,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
try { try {
cryptoFramework.createAsyKeyGenerator(""); cryptoFramework.createAsyKeyGenerator("");
expect(null).assertFail();
} catch (err) { } catch (err) {
console.error("err is:" + err.code); console.error("err is:" + err.code);
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
...@@ -403,21 +415,25 @@ export default function AsymmetricCryptographyJsSecondunit() { ...@@ -403,21 +415,25 @@ export default function AsymmetricCryptographyJsSecondunit() {
let rsaGenerator = cryptoFramework.createAsyKeyGenerator("ECC224"); let rsaGenerator = cryptoFramework.createAsyKeyGenerator("ECC224");
await rsaGenerator.generateKeyPair(); await rsaGenerator.generateKeyPair();
cryptoFramework.createSign("ECC224|SHA257"); cryptoFramework.createSign("ECC224|SHA257");
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
try { try {
cryptoFramework.createSign("ECC224|NULL"); cryptoFramework.createSign("ECC224|NULL");
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
try { try {
cryptoFramework.createSign("NULL|SHA1"); cryptoFramework.createSign("NULL|SHA1");
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
try { try {
cryptoFramework.createSign("ECC1|SHA1"); cryptoFramework.createSign("ECC1|SHA1");
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
...@@ -438,21 +454,25 @@ export default function AsymmetricCryptographyJsSecondunit() { ...@@ -438,21 +454,25 @@ export default function AsymmetricCryptographyJsSecondunit() {
try { try {
cryptoFramework.createAsyKeyGenerator("RSA3072"); cryptoFramework.createAsyKeyGenerator("RSA3072");
cryptoFramework.createVerify("ECC1|SHA256"); cryptoFramework.createVerify("ECC1|SHA256");
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
try { try {
cryptoFramework.createVerify("NULL|SHA256"); cryptoFramework.createVerify("NULL|SHA256");
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
try { try {
cryptoFramework.createVerify("ECC224|SHA122"); cryptoFramework.createVerify("ECC224|SHA122");
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
try { try {
cryptoFramework.createVerify("ECC224|NULL"); cryptoFramework.createVerify("ECC224|NULL");
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
...@@ -600,12 +620,14 @@ export default function AsymmetricCryptographyJsSecondunit() { ...@@ -600,12 +620,14 @@ export default function AsymmetricCryptographyJsSecondunit() {
async function (done) { async function (done) {
try { try {
cryptoFramework.createKeyAgreement("ECC5"); cryptoFramework.createKeyAgreement("ECC5");
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
try { try {
cryptoFramework.createKeyAgreement(null); cryptoFramework.createKeyAgreement(null);
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
...@@ -638,6 +660,7 @@ export default function AsymmetricCryptographyJsSecondunit() { ...@@ -638,6 +660,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
let keyAgrementGenerator = cryptoFramework.createKeyAgreement("ECC256"); let keyAgrementGenerator = cryptoFramework.createKeyAgreement("ECC256");
try { try {
await keyAgrementGenerator.generateSecret(null, null); await keyAgrementGenerator.generateSecret(null, null);
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
...@@ -656,6 +679,7 @@ export default function AsymmetricCryptographyJsSecondunit() { ...@@ -656,6 +679,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
} }
try { try {
await keyAgrementGenerator.generateSecret(null, keyPair2.pubKey) await keyAgrementGenerator.generateSecret(null, keyPair2.pubKey)
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
...@@ -688,6 +712,7 @@ export default function AsymmetricCryptographyJsSecondunit() { ...@@ -688,6 +712,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
let keyAgrementGenerator = cryptoFramework.createKeyAgreement("ECC521"); let keyAgrementGenerator = cryptoFramework.createKeyAgreement("ECC521");
try { try {
await keyAgrementGenerator.generateSecret(keyPair1.prikey, keyPair2.pubKey) await keyAgrementGenerator.generateSecret(keyPair1.prikey, keyPair2.pubKey)
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
......
...@@ -17,9 +17,6 @@ import { describe, beforeAll, afterEach, it, expect } from "@ohos/hypium"; ...@@ -17,9 +17,6 @@ import { describe, beforeAll, afterEach, it, expect } from "@ohos/hypium";
import { import {
testHMACDigestPromise, testHMACDigestPromise,
testMDDigestPromise, testMDDigestPromise,
testHMACErrorAlgorithm,
testHMACDigestPromiseErrorKey,
testHMACDigestPromiseDatablobNull,
testHMACDigestPromiseDatablobLong, testHMACDigestPromiseDatablobLong,
} from "./utils/digestalgorithm/publicDigestPromise"; } from "./utils/digestalgorithm/publicDigestPromise";
import { import {
...@@ -29,6 +26,11 @@ import { ...@@ -29,6 +26,11 @@ import {
testMDErrorAlgorithmNull, testMDErrorAlgorithmNull,
testMDDigestCallbackLen, testMDDigestCallbackLen,
} from "./utils/digestalgorithm/publicDigestCallback"; } from "./utils/digestalgorithm/publicDigestCallback";
import {
stringTouInt8Array,
uInt8ArrayToShowStr,
uInt8ArrayToString,
} from "./utils/common/publicDoString";
import cryptoFramework from "@ohos.security.cryptoFramework"; import cryptoFramework from "@ohos.security.cryptoFramework";
...@@ -202,18 +204,21 @@ export default function DigestAlgorithmJsunit() { ...@@ -202,18 +204,21 @@ export default function DigestAlgorithmJsunit() {
} }
}) })
}) })
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
try { try {
await mdGenerator.update(0); await mdGenerator.update(0);
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
try { try {
await mdGenerator.digest(); await mdGenerator.digest();
} catch (err) { } catch (err) {
console.error("1111111 " + err.code); console.error("err is " + err.code);
expect(err.code).assertEqual(401)
} }
done(); done();
}); });
...@@ -304,13 +309,20 @@ export default function DigestAlgorithmJsunit() { ...@@ -304,13 +309,20 @@ export default function DigestAlgorithmJsunit() {
* @tc.desc Use the Promise Style of Interface * @tc.desc Use the Promise Style of Interface
*/ */
it("Security_crypto_framework_HMAC_0600", 0, async function (done) { it("Security_crypto_framework_HMAC_0600", 0, async function (done) {
await testHMACErrorAlgorithm("SHA5", null) try {
.then((data) => { cryptoFramework.createMac("SHA5");
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail(); expect(null).assertFail();
}); } catch (err) {
console.error("[Promise]: error code: " + err.code + ", message is: " + err.message);
expect(err.code).assertEqual(801);
}
try {
cryptoFramework.createMac(null);
expect(null).assertFail();
} catch (err) {
console.error("[Promise]: error code: " + err.code + ", message is: " + err.message);
expect(err.code).assertEqual(401);
}
done(); done();
}); });
...@@ -320,13 +332,23 @@ export default function DigestAlgorithmJsunit() { ...@@ -320,13 +332,23 @@ export default function DigestAlgorithmJsunit() {
* @tc.desc Use the Promise Style of Interface * @tc.desc Use the Promise Style of Interface
*/ */
it("Security_crypto_framework_HMAC_0700", 0, async function (done) { it("Security_crypto_framework_HMAC_0700", 0, async function (done) {
await testHMACDigestPromiseErrorKey("SHA512", "RSA1024|PRIMES_2") let globalHMAC = cryptoFramework.createMac("SHA512");
.then((data) => { let globalsymKeyGenerator = cryptoFramework.createAsyKeyGenerator("RSA1024|PRIMES_2");
expect(data == null).assertTrue(); let key = globalsymKeyGenerator.generateKeyPair();
}) try {
.catch((err) => { await globalHMAC.init(key);
expect(null).assertFail(); expect(null).assertFail();
}); } catch (err) {
console.error("[Promise]init(key): error code: " + err.code + ", message is: " + err.message);
expect(err.code).assertEqual(401);
};
try {
await globalHMAC.init(null);
expect(null).assertFail();
} catch (err) {
console.error("[Promise]init(null): error code: " + err.code + ", message is: " + err.message);
expect(err.code).assertEqual(401);
};
done(); done();
}); });
...@@ -336,13 +358,17 @@ export default function DigestAlgorithmJsunit() { ...@@ -336,13 +358,17 @@ export default function DigestAlgorithmJsunit() {
* @tc.desc Use the Promise Style of Interface * @tc.desc Use the Promise Style of Interface
*/ */
it("Security_crypto_framework_HMAC_0800", 0, async function (done) { it("Security_crypto_framework_HMAC_0800", 0, async function (done) {
await testHMACDigestPromiseDatablobNull("SHA512", "3DES192") let globalHMAC = cryptoFramework.createMac("SHA512");
.then((data) => { let globalsymKeyGenerator = cryptoFramework.createSymKeyGenerator("3DES192");
expect(data == null).assertTrue(); let key = await globalsymKeyGenerator.generateSymKey();
}) await globalHMAC.init(key);
.catch((err) => { try {
await globalHMAC.update(null);
expect(null).assertFail(); expect(null).assertFail();
}); } catch (err) {
console.error("[Promise]init(null): error code: " + err.code + ", message is: " + err.message);
expect(err.code).assertEqual(401);
}
done(); done();
}); });
......
...@@ -82,6 +82,7 @@ export default function SecurityRandomJsunit() { ...@@ -82,6 +82,7 @@ export default function SecurityRandomJsunit() {
} }
try { try {
await randomGenerator.generateRandom(null); await randomGenerator.generateRandom(null);
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
...@@ -100,6 +101,7 @@ export default function SecurityRandomJsunit() { ...@@ -100,6 +101,7 @@ export default function SecurityRandomJsunit() {
} }
try { try {
await randomGenerator.generateRandom(2147483648); await randomGenerator.generateRandom(2147483648);
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
...@@ -115,11 +117,13 @@ export default function SecurityRandomJsunit() { ...@@ -115,11 +117,13 @@ export default function SecurityRandomJsunit() {
let randomGenerator = cryptoFramework.createRandom(); let randomGenerator = cryptoFramework.createRandom();
try { try {
randomGenerator.setSeed(null); randomGenerator.setSeed(null);
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
try { try {
randomGenerator.setSeed(0); randomGenerator.setSeed(0);
expect(null).assertFail();
} catch (err) { } catch (err) {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} }
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
import { describe, beforeAll, afterEach, it, expect } from "@ohos/hypium"; import { describe, beforeAll, afterEach, it, expect } from "@ohos/hypium";
import * as symPromise from "./utils/symmetric/publicSymmetricPromise"; import * as symPromise from "./utils/symmetric/publicSymmetricPromise";
import * as symCallback from "./utils/symmetric/publicSymmetricCallback"; import * as symCallback from "./utils/symmetric/publicSymmetricCallback";
import * as publicModule from "./utils/common/publicDoString";
import cryptoFramework from "@ohos.security.cryptoFramework";
export default function SymmetricCryptographyJsunit() { export default function SymmetricCryptographyJsunit() {
describe("SymmetricCryptographyJsunit", function () { describe("SymmetricCryptographyJsunit", function () {
...@@ -382,34 +384,20 @@ export default function SymmetricCryptographyJsunit() { ...@@ -382,34 +384,20 @@ export default function SymmetricCryptographyJsunit() {
"Security_crypto_framework_Symmetric_Encryption_AES_1300", "Security_crypto_framework_Symmetric_Encryption_AES_1300",
0, 0,
async function (done) { async function (done) {
await symPromise try {
.createSymKeyGeneratorFail( cryptoFramework.createSymKeyGenerator("AES257");
"AES257",
)
.then((data) => {
expect(data == "Error: create C generator fail.").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_1300 catch error: " +
err
);
expect(null).assertFail(); expect(null).assertFail();
}); } catch (err) {
await symPromise console.error("err is :" + err.code);
.createSymKeyGeneratorFail( expect(err.code).assertEqual(801);
"AESNULL", }
) try {
.then((data) => { cryptoFramework.createSymKeyGenerator("AESNULL");
expect(data == "Error: create C generator fail.").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_1300 catch error: " +
err
);
expect(null).assertFail(); expect(null).assertFail();
}); } catch (err) {
console.error("err is :" + err.code);
expect(err.code).assertEqual(801);
}
done(); done();
} }
); );
...@@ -423,34 +411,20 @@ export default function SymmetricCryptographyJsunit() { ...@@ -423,34 +411,20 @@ export default function SymmetricCryptographyJsunit() {
"Security_crypto_framework_Symmetric_Encryption_AES_1400", "Security_crypto_framework_Symmetric_Encryption_AES_1400",
0, 0,
async function (done) { async function (done) {
await symPromise try {
.createSymCipherFail( cryptoFramework.createCipher("AES128|NULL|PKCS7");
"AES128|NULL|PKCS7",
)
.then((data) => {
expect(data == "Error: create C cipher fail!").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_1400 catch error: " +
err
);
expect(null).assertFail(); expect(null).assertFail();
}); } catch (err) {
await symPromise console.error("err is :" + err.code);
.createSymCipherFail( expect(err.code).assertEqual(801);
"AES128|ADF|PKCS7", }
) try {
.then((data) => { cryptoFramework.createCipher("AES128|ADF|PKCS7");
expect(data == "Error: create C cipher fail!").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_1400 catch error: " +
err
);
expect(null).assertFail(); expect(null).assertFail();
}); } catch (err) {
console.error("err is :" + err.code);
expect(err.code).assertEqual(801);
}
done(); done();
} }
); );
...@@ -464,34 +438,20 @@ export default function SymmetricCryptographyJsunit() { ...@@ -464,34 +438,20 @@ export default function SymmetricCryptographyJsunit() {
"Security_crypto_framework_Symmetric_Encryption_AES_1500", "Security_crypto_framework_Symmetric_Encryption_AES_1500",
0, 0,
async function (done) { async function (done) {
await symPromise try {
.createSymCipherFail( cryptoFramework.createCipher("AES128|GCM|NULL");
"AES128|GCM|NULL",
)
.then((data) => {
expect(data == "Error: create C cipher fail!").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_1500 catch error: " +
err
);
expect(null).assertFail(); expect(null).assertFail();
}); } catch (err) {
await symPromise console.error("err is :" + err.code);
.createSymCipherFail( expect(err.code).assertEqual(801);
"AES128|GCM|CCCC", }
) try {
.then((data) => { cryptoFramework.createCipher("AES128|GCM|CCCC");
expect(data == "Error: create C cipher fail!").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_1500 catch error: " +
err
);
expect(null).assertFail(); expect(null).assertFail();
}); } catch (err) {
console.error("err is :" + err.code);
expect(err.code).assertEqual(801);
}
done(); done();
} }
); );
...@@ -662,9 +622,9 @@ export default function SymmetricCryptographyJsunit() { ...@@ -662,9 +622,9 @@ export default function SymmetricCryptographyJsunit() {
.catch((err) => { .catch((err) => {
console.error( console.error(
"Security_crypto_framework_Symmetric_Encryption_3DES_0600 catch error: " + "Security_crypto_framework_Symmetric_Encryption_3DES_0600 catch error: " +
err err.code
); );
expect(err == "Error: doFinal failed.").assertTrue(); expect(err.code).assertEqual(17630001);
}); });
done(); done();
} }
...@@ -679,38 +639,22 @@ export default function SymmetricCryptographyJsunit() { ...@@ -679,38 +639,22 @@ export default function SymmetricCryptographyJsunit() {
"Security_crypto_framework_Symmetric_Encryption_3DES_0700", "Security_crypto_framework_Symmetric_Encryption_3DES_0700",
0, 0,
async function (done) { async function (done) {
await symPromise try {
.encryptAndDecryptNormalProcess( let symKeyGenerator = cryptoFramework.createSymKeyGenerator("3DES192");
"3DES192", expect(symKeyGenerator != null).assertTrue();
"3DES192|null|PKCS7", let SymKey = await symKeyGenerator.generateSymKey();
"genIvParamsSpec" expect(SymKey != null).assertTrue();
) cryptoFramework.createCipher("3DES192|null|PKCS7");
.then((data) => { expect(null).assertFail();
expect(data == "Error: create C cipher fail!").assertTrue(); } catch (err) {
}) expect(err.code).assertEqual(801);
.catch((err) => { }
console.error( try {
"Security_crypto_framework_Symmetric_Encryption_3DES_0700 catch error: " + cryptoFramework.createCipher("3DES192|DDD|PKCS7");
err expect(null).assertFail();
); } catch (err) {
expect(null).assertTrue(); expect(err.code).assertEqual(801);
}); }
await symPromise
.encryptAndDecryptNormalProcess(
"3DES192",
"3DES192|DDD|PKCS7",
"genIvParamsSpec"
)
.then((data) => {
expect(data == "Error: create C cipher fail!").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_3DES_0700 catch error: " +
err
);
expect(null).assertTrue();
});
done(); done();
} }
); );
...@@ -724,38 +668,22 @@ export default function SymmetricCryptographyJsunit() { ...@@ -724,38 +668,22 @@ export default function SymmetricCryptographyJsunit() {
"Security_crypto_framework_Symmetric_Encryption_3DES_0800", "Security_crypto_framework_Symmetric_Encryption_3DES_0800",
0, 0,
async function (done) { async function (done) {
await symPromise try {
.encryptAndDecryptNormalProcess( let symKeyGenerator = cryptoFramework.createSymKeyGenerator("3DES192");
"3DES192", expect(symKeyGenerator != null).assertTrue();
"3DES192|ECB|null", let SymKey = await symKeyGenerator.generateSymKey();
"genIvParamsSpec" expect(SymKey != null).assertTrue();
) cryptoFramework.createCipher("3DES192|ECB|null");
.then((data) => { expect(null).assertFail();
expect(data == "Error: create C cipher fail!").assertTrue(); } catch (err) {
}) expect(err.code).assertEqual(801);
.catch((err) => { }
console.error( try {
"Security_crypto_framework_Symmetric_Encryption_3DES_0800 catch error: " + cryptoFramework.createCipher("3DES192|ECB|CCCCC");
err expect(null).assertFail();
); } catch (err) {
expect(null).assertTrue(); expect(err.code).assertEqual(801);
}); }
await symPromise
.encryptAndDecryptNormalProcess(
"3DES192",
"3DES192|ECB|CCCCC",
"genIvParamsSpec"
)
.then((data) => {
expect(data == "Error: create C cipher fail!").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_3DES_0800 catch error: " +
err
);
expect(null).assertTrue();
});
done(); done();
} }
); );
...@@ -798,22 +726,20 @@ export default function SymmetricCryptographyJsunit() { ...@@ -798,22 +726,20 @@ export default function SymmetricCryptographyJsunit() {
"Security_crypto_framework_Symmetric_Encryption_AES_3000", "Security_crypto_framework_Symmetric_Encryption_AES_3000",
0, 0,
async function (done) { async function (done) {
await symPromise let symKeyGenerator = cryptoFramework.createSymKeyGenerator("AES256");
.encryptAndDecryptNormalProcessSpecialdata( expect(symKeyGenerator != null).assertTrue();
"AES256", let symKey = await symKeyGenerator.generateSymKey();
"AES256|CCM|PKCS7", expect(symKey != null).assertTrue();
"genCcmParamsSpec" let cipherGenerator = cryptoFramework.createCipher("AES256|CCM|PKCS7");
) expect(cipherGenerator != null).assertTrue();
.then((data) => { await cipherGenerator.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, publicModule.genCcmParamsSpec());
expect(data == "TypeError: Cannot read property length of null").assertTrue(); try {
}) await cipherGenerator.update(null);
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_3000 catch error: " +
err
);
expect(null).assertFail(); expect(null).assertFail();
}); } catch (err) {
console.error("Security_crypto_framework_Symmetric_Encryption_AES_3000 catch error: " + err.code);
expect(err.code).assertEqual(401);
}
done(); done();
} }
); );
......
...@@ -551,82 +551,11 @@ async function signAndVerifyNormalProcessSuperdata(asyAlgoName, signVerifyAlgoNa ...@@ -551,82 +551,11 @@ async function signAndVerifyNormalProcessSuperdata(asyAlgoName, signVerifyAlgoNa
}); });
} }
async function encryptAndDecryptNormalProcessNull(asyAlgoName, cipherAlgoName) {
var globalCipherText;
var globalRsaKeyPair;
var encryptMode = cryptoFramework.CryptoMode.ENCRYPT_MODE;
var decryptMode = cryptoFramework.CryptoMode.DECRYPT_MODE;
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(asyAlgoName);
expect(rsaGenerator != null).assertTrue();
var cipherGeneratorEncrypt = createAsyCipher(cipherAlgoName);
expect(cipherGeneratorEncrypt != null).assertTrue();
var cipherGeneratorDecrypt = createAsyCipher(cipherAlgoName);
expect(cipherGeneratorDecrypt != null).assertTrue();
generateAsyKeyPair(rsaGenerator)
.then((rsaKeyPair) => {
expect(rsaKeyPair != null).assertTrue();
globalRsaKeyPair = rsaKeyPair;
return initCipher(
cipherGeneratorEncrypt,
encryptMode,
globalRsaKeyPair.pubKey,
null
);
})
.then((initData) => {
expect(initData === "init success").assertTrue();
return doFinalCipher(cipherGeneratorEncrypt, encryptMode, null);
})
.then((finalOutput) => {
expect(finalOutput != null).assertTrue();
globalCipherText = finalOutput;
console.log(
"cipherOutput: " + uInt8ArrayToShowStr(globalCipherText.data)
);
return initCipher(
cipherGeneratorDecrypt,
decryptMode,
globalRsaKeyPair.priKey,
null
);
})
.then((initData) => {
expect(initData === "init success").assertTrue();
return doFinalCipher(
cipherGeneratorDecrypt,
decryptMode,
globalCipherText
);
})
.then((finalOutput) => {
if (finalOutput == null) {
console.error("[Callback]decrypt doFinal out is null");
} else {
console.log(
"[Callback]decrypt doFinal out hex: " +
uInt8ArrayToShowStr(finalOutput.data)
);
}
let decryptData = uInt8ArrayToString(finalOutput.data);
reject();
})
.catch((err) => {
console.error(
"[Callback] encryptAndDecryptNormalProcess catch err:" + err
);
resolve(err);
});
});
}
export { export {
encryptAndDecryptNormalProcess, encryptAndDecryptNormalProcess,
signAndVerifyNormalProcess, signAndVerifyNormalProcess,
convertKeyEncryptAndDecryptProcess, convertKeyEncryptAndDecryptProcess,
keyAgreementProcess, keyAgreementProcess,
encryptAndDecryptNormalProcessSuperdata, encryptAndDecryptNormalProcessSuperdata,
signAndVerifyNormalProcessSuperdata, signAndVerifyNormalProcessSuperdata
encryptAndDecryptNormalProcessNull
}; };
...@@ -111,130 +111,6 @@ async function testHMACDigestPromise(HMACAlgoName, keyAlgoName) { ...@@ -111,130 +111,6 @@ async function testHMACDigestPromise(HMACAlgoName, keyAlgoName) {
}); });
} }
async function testHMACErrorAlgorithm(HMACAlgoName1, HMACAlgoName2) {
var globalHMAC;
var globalText = "my test data";
var inBlob = {
data: stringTouInt8Array(globalText),
};
return new Promise((resolve, reject) => {
try {
globalHMAC = cryptoFramework.createMac(HMACAlgoName1);
reject();
} catch (error) {
console.error("[Promise]: error code1: " + error.code + ", message is: " + error.message);
expect(error.code == 801).assertTrue();
}
try {
globalHMAC = cryptoFramework.createMac(HMACAlgoName2);
reject();
} catch (error) {
console.error("[Promise]: error code2: " + error.code + ", message is: " + error.message);
expect(error.code == 401).assertTrue();
resolve();
}
});
}
async function testHMACDigestPromiseErrorKey(HMACAlgoName, keyAlgoName) {
var globalHMAC;
var globalText = "my test data";
let globalsymKeyGenerator;
var inBlob = {
data: stringTouInt8Array(globalText),
};
return new Promise((resolve, reject) => {
globalHMAC = cryptoFramework.createMac(HMACAlgoName);
expect(globalHMAC != null).assertTrue();
console.warn("mac= " + globalHMAC);
console.warn("HMAC algName is: " + globalHMAC.algName);
console.log("start to call createSymKeyGenerator()");
try {
globalsymKeyGenerator = cryptoFramework.createAsyKeyGenerator(keyAlgoName);
} catch (error) {
console.error("[Promise]: error code1: " + error.code + ", message is: " + error.message);
}
console.warn("symKeyGenerator algName:" + globalsymKeyGenerator.algName);
expect(globalsymKeyGenerator != null).assertTrue();
console.log("createSymKeyGenerator ok");
let key = globalsymKeyGenerator.generateKeyPair();
try {
var promiseMacInit = globalHMAC.init(key);
expect(promiseMacInit == null).assertTrue();
reject();
} catch (error) {
console.error("[Promise]init(key): error code: " + error.code + ", message is: " + error.message);
expect(error.code == 401).assertTrue();
resolve();
};
try {
var promiseMacInit = globalHMAC.init(null);
expect(promiseMacInit == null).assertTrue();
reject();
} catch (error) {
console.error("[Promise]init(null): error code: " + error.code + ", message is: " + error.message);
expect(error.code == 401).assertTrue();
resolve();
};
});
}
async function testHMACDigestPromiseDatablobNull(HMACAlgoName, keyAlgoName) {
var globalHMAC;
var globalText = "my test data";
var globalsymKeyGenerator;
var inBlob = {
data: stringTouInt8Array(globalText),
};
return new Promise((resolve, reject) => {
globalHMAC = cryptoFramework.createMac(HMACAlgoName);
expect(globalHMAC != null).assertTrue();
console.warn("mac= " + globalHMAC);
console.warn("HMAC algName is: " + globalHMAC.algName);
console.log("start to call createSymKeyGenerator()");
globalsymKeyGenerator = cryptoFramework.createSymKeyGenerator(keyAlgoName);
console.warn("symKeyGenerator algName:" + globalsymKeyGenerator.algName);
expect(globalsymKeyGenerator != null).assertTrue();
console.log("createSymKeyGenerator ok");
console.warn("symKeyGenerator algName:" + globalsymKeyGenerator.algName);
globalsymKeyGenerator
.generateSymKey()
.then((key) => {
expect(key != null).assertTrue();
console.warn("generateSymKey ok");
console.warn("key algName:" + key.algName);
console.warn("key format:" + key.format);
var encodedKey = key.getEncoded();
console.warn(
"key getEncoded hex: " + uInt8ArrayToShowStr(encodedKey.data)
);
var promiseMacInit = globalHMAC.init(key);
return promiseMacInit;
})
.then(() => {
try {
var promiseMacUpdate = globalHMAC.update(null);
console.warn("promiseMacUpdate:" + promiseMacUpdate);
} catch (error) {
console.error("[Promise]: error code: " + error.code + ", message is: " + error.message);
expect(error.code == 401).assertTrue();
resolve();
}
})
.then(() => {
var promiseMacdoFinal = globalHMAC.doFinal();
return promiseMacdoFinal;
})
.catch((err) => {
console.error("[promise]catch err:" + err);
reject(err);
});
});
}
async function testHMACDigestPromiseDatablobLong(HMACAlgoName, keyAlgoName, DatablobLen) { async function testHMACDigestPromiseDatablobLong(HMACAlgoName, keyAlgoName, DatablobLen) {
var globalHMAC; var globalHMAC;
var globalsymKeyGenerator; var globalsymKeyGenerator;
...@@ -293,5 +169,5 @@ async function testHMACDigestPromiseDatablobLong(HMACAlgoName, keyAlgoName, Data ...@@ -293,5 +169,5 @@ async function testHMACDigestPromiseDatablobLong(HMACAlgoName, keyAlgoName, Data
}); });
}); });
} }
export { testMDDigestPromise, testHMACDigestPromise, testHMACErrorAlgorithm,
testHMACDigestPromiseErrorKey, testHMACDigestPromiseDatablobNull, testHMACDigestPromiseDatablobLong }; export { testMDDigestPromise, testHMACDigestPromise, testHMACDigestPromiseDatablobLong};
...@@ -560,7 +560,6 @@ async function encryptAndDecryptNormalProcessSuperdata( ...@@ -560,7 +560,6 @@ async function encryptAndDecryptNormalProcessSuperdata(
for (i = 0; i < globalTextLen; i++) { for (i = 0; i < globalTextLen; i++) {
globalText += t.charAt(Math.floor(Math.random() * n)); globalText += t.charAt(Math.floor(Math.random() * n));
} }
console.warn("globalText1111111111111111111111111111111: " + globalText);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var symKeyGenerator = createSymKeyGenerator(symAlgoName); var symKeyGenerator = createSymKeyGenerator(symAlgoName);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册