未验证 提交 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 @@
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 AsymmetricCryptographyJsunit() {
describe("AsymmetricCryptographyJsunit", function () {
......@@ -398,21 +399,16 @@ export default function AsymmetricCryptographyJsunit() {
"Security_crypto_framework_ASymmetric_Encryption_RSA_1400",
0,
async function (done) {
await asyCallback
.encryptAndDecryptNormalProcessNull(
"RSA4096",
"RSA4096|PKCS1"
)
.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();
});
let rsaGenerator = cryptoFramework.createAsyKeyGenerator("RSA4096");
let cipherGeneratorEncrypt = cryptoFramework.createCipher("RSA4096|PKCS1");
let globalRsaKeyPair = rsaGenerator.generateKeyPair();
try {
await cipherGeneratorEncrypt.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, globalRsaKeyPair, null);
expect(null).assertFail();
} catch (err) {
console.error("err is:" + err.code);
expect(err.code).assertEqual(401);
}
done();
}
);
......
......@@ -87,6 +87,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
async function (done) {
try {
cryptoFramework.createAsyKeyGenerator("RSA256");
expect(null).assertFail();
} catch (err) {
console.error("err is:" + err.code);
expect(err.code).assertEqual(401);
......@@ -94,6 +95,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
try {
cryptoFramework.createAsyKeyGenerator("NULL");
expect(null).assertFail();
} catch (err) {
console.error("err is:" + err.code);
expect(err.code).assertEqual(401);
......@@ -116,24 +118,28 @@ export default function AsymmetricCryptographyJsSecondunit() {
let rsaGenerator = cryptoFramework.createAsyKeyGenerator("RSA3072");
await rsaGenerator.generateKeyPair();
cryptoFramework.createSign("RSA4096|NULL|SHA256");
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createSign("RSA4096|PKCS1|NULL");
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createSign("RSA4096|PKCS1|SHA122");
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createSign("RSA4096|PKCS5|SHA256");
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
......@@ -213,24 +219,28 @@ export default function AsymmetricCryptographyJsSecondunit() {
let rsaGenerator = cryptoFramework.createAsyKeyGenerator("RSA3072");
await rsaGenerator.generateKeyPair();
cryptoFramework.createVerify("RSA4096|NULL|SHA256");
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createVerify("RSA4096|PKCS1|NULL");
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createVerify("RSA4096|PKCS1|SHA122");
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createVerify("RSA4096|PKCS5|SHA256");
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
......@@ -374,6 +384,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
async function (done) {
try {
cryptoFramework.createAsyKeyGenerator("ECC1");
expect(null).assertFail();
} catch (err) {
console.error("err is:" + err.code);
expect(err.code).assertEqual(401);
......@@ -381,6 +392,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
try {
cryptoFramework.createAsyKeyGenerator("");
expect(null).assertFail();
} catch (err) {
console.error("err is:" + err.code);
expect(err.code).assertEqual(401);
......@@ -403,21 +415,25 @@ export default function AsymmetricCryptographyJsSecondunit() {
let rsaGenerator = cryptoFramework.createAsyKeyGenerator("ECC224");
await rsaGenerator.generateKeyPair();
cryptoFramework.createSign("ECC224|SHA257");
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createSign("ECC224|NULL");
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createSign("NULL|SHA1");
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createSign("ECC1|SHA1");
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
......@@ -438,21 +454,25 @@ export default function AsymmetricCryptographyJsSecondunit() {
try {
cryptoFramework.createAsyKeyGenerator("RSA3072");
cryptoFramework.createVerify("ECC1|SHA256");
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createVerify("NULL|SHA256");
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createVerify("ECC224|SHA122");
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createVerify("ECC224|NULL");
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
......@@ -600,12 +620,14 @@ export default function AsymmetricCryptographyJsSecondunit() {
async function (done) {
try {
cryptoFramework.createKeyAgreement("ECC5");
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createKeyAgreement(null);
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
......@@ -638,6 +660,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
let keyAgrementGenerator = cryptoFramework.createKeyAgreement("ECC256");
try {
await keyAgrementGenerator.generateSecret(null, null);
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
......@@ -656,6 +679,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
}
try {
await keyAgrementGenerator.generateSecret(null, keyPair2.pubKey)
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
......@@ -688,6 +712,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
let keyAgrementGenerator = cryptoFramework.createKeyAgreement("ECC521");
try {
await keyAgrementGenerator.generateSecret(keyPair1.prikey, keyPair2.pubKey)
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
......
......@@ -17,9 +17,6 @@ import { describe, beforeAll, afterEach, it, expect } from "@ohos/hypium";
import {
testHMACDigestPromise,
testMDDigestPromise,
testHMACErrorAlgorithm,
testHMACDigestPromiseErrorKey,
testHMACDigestPromiseDatablobNull,
testHMACDigestPromiseDatablobLong,
} from "./utils/digestalgorithm/publicDigestPromise";
import {
......@@ -29,6 +26,11 @@ import {
testMDErrorAlgorithmNull,
testMDDigestCallbackLen,
} from "./utils/digestalgorithm/publicDigestCallback";
import {
stringTouInt8Array,
uInt8ArrayToShowStr,
uInt8ArrayToString,
} from "./utils/common/publicDoString";
import cryptoFramework from "@ohos.security.cryptoFramework";
......@@ -202,18 +204,21 @@ export default function DigestAlgorithmJsunit() {
}
})
})
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await mdGenerator.update(0);
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await mdGenerator.digest();
} catch (err) {
console.error("1111111 " + err.code);
console.error("err is " + err.code);
expect(err.code).assertEqual(401)
}
done();
});
......@@ -304,13 +309,20 @@ export default function DigestAlgorithmJsunit() {
* @tc.desc Use the Promise Style of Interface
*/
it("Security_crypto_framework_HMAC_0600", 0, async function (done) {
await testHMACErrorAlgorithm("SHA5", null)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
try {
cryptoFramework.createMac("SHA5");
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();
});
......@@ -320,13 +332,23 @@ export default function DigestAlgorithmJsunit() {
* @tc.desc Use the Promise Style of Interface
*/
it("Security_crypto_framework_HMAC_0700", 0, async function (done) {
await testHMACDigestPromiseErrorKey("SHA512", "RSA1024|PRIMES_2")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
let globalHMAC = cryptoFramework.createMac("SHA512");
let globalsymKeyGenerator = cryptoFramework.createAsyKeyGenerator("RSA1024|PRIMES_2");
let key = globalsymKeyGenerator.generateKeyPair();
try {
await globalHMAC.init(key);
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();
});
......@@ -336,13 +358,17 @@ export default function DigestAlgorithmJsunit() {
* @tc.desc Use the Promise Style of Interface
*/
it("Security_crypto_framework_HMAC_0800", 0, async function (done) {
await testHMACDigestPromiseDatablobNull("SHA512", "3DES192")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
let globalHMAC = cryptoFramework.createMac("SHA512");
let globalsymKeyGenerator = cryptoFramework.createSymKeyGenerator("3DES192");
let key = await globalsymKeyGenerator.generateSymKey();
await globalHMAC.init(key);
try {
await globalHMAC.update(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();
});
......
......@@ -82,6 +82,7 @@ export default function SecurityRandomJsunit() {
}
try {
await randomGenerator.generateRandom(null);
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
......@@ -100,6 +101,7 @@ export default function SecurityRandomJsunit() {
}
try {
await randomGenerator.generateRandom(2147483648);
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
......@@ -115,11 +117,13 @@ export default function SecurityRandomJsunit() {
let randomGenerator = cryptoFramework.createRandom();
try {
randomGenerator.setSeed(null);
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
randomGenerator.setSeed(0);
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(401);
}
......
......@@ -16,6 +16,8 @@
import { describe, beforeAll, afterEach, it, expect } from "@ohos/hypium";
import * as symPromise from "./utils/symmetric/publicSymmetricPromise";
import * as symCallback from "./utils/symmetric/publicSymmetricCallback";
import * as publicModule from "./utils/common/publicDoString";
import cryptoFramework from "@ohos.security.cryptoFramework";
export default function SymmetricCryptographyJsunit() {
describe("SymmetricCryptographyJsunit", function () {
......@@ -382,34 +384,20 @@ export default function SymmetricCryptographyJsunit() {
"Security_crypto_framework_Symmetric_Encryption_AES_1300",
0,
async function (done) {
await symPromise
.createSymKeyGeneratorFail(
"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();
});
await symPromise
.createSymKeyGeneratorFail(
"AESNULL",
)
.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();
});
try {
cryptoFramework.createSymKeyGenerator("AES257");
expect(null).assertFail();
} catch (err) {
console.error("err is :" + err.code);
expect(err.code).assertEqual(801);
}
try {
cryptoFramework.createSymKeyGenerator("AESNULL");
expect(null).assertFail();
} catch (err) {
console.error("err is :" + err.code);
expect(err.code).assertEqual(801);
}
done();
}
);
......@@ -423,34 +411,20 @@ export default function SymmetricCryptographyJsunit() {
"Security_crypto_framework_Symmetric_Encryption_AES_1400",
0,
async function (done) {
await symPromise
.createSymCipherFail(
"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();
});
await symPromise
.createSymCipherFail(
"AES128|ADF|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();
});
try {
cryptoFramework.createCipher("AES128|NULL|PKCS7");
expect(null).assertFail();
} catch (err) {
console.error("err is :" + err.code);
expect(err.code).assertEqual(801);
}
try {
cryptoFramework.createCipher("AES128|ADF|PKCS7");
expect(null).assertFail();
} catch (err) {
console.error("err is :" + err.code);
expect(err.code).assertEqual(801);
}
done();
}
);
......@@ -464,34 +438,20 @@ export default function SymmetricCryptographyJsunit() {
"Security_crypto_framework_Symmetric_Encryption_AES_1500",
0,
async function (done) {
await symPromise
.createSymCipherFail(
"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();
});
await symPromise
.createSymCipherFail(
"AES128|GCM|CCCC",
)
.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();
});
try {
cryptoFramework.createCipher("AES128|GCM|NULL");
expect(null).assertFail();
} catch (err) {
console.error("err is :" + err.code);
expect(err.code).assertEqual(801);
}
try {
cryptoFramework.createCipher("AES128|GCM|CCCC");
expect(null).assertFail();
} catch (err) {
console.error("err is :" + err.code);
expect(err.code).assertEqual(801);
}
done();
}
);
......@@ -662,9 +622,9 @@ export default function SymmetricCryptographyJsunit() {
.catch((err) => {
console.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();
}
......@@ -679,38 +639,22 @@ export default function SymmetricCryptographyJsunit() {
"Security_crypto_framework_Symmetric_Encryption_3DES_0700",
0,
async function (done) {
await symPromise
.encryptAndDecryptNormalProcess(
"3DES192",
"3DES192|null|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();
});
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();
});
try {
let symKeyGenerator = cryptoFramework.createSymKeyGenerator("3DES192");
expect(symKeyGenerator != null).assertTrue();
let SymKey = await symKeyGenerator.generateSymKey();
expect(SymKey != null).assertTrue();
cryptoFramework.createCipher("3DES192|null|PKCS7");
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(801);
}
try {
cryptoFramework.createCipher("3DES192|DDD|PKCS7");
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(801);
}
done();
}
);
......@@ -724,38 +668,22 @@ export default function SymmetricCryptographyJsunit() {
"Security_crypto_framework_Symmetric_Encryption_3DES_0800",
0,
async function (done) {
await symPromise
.encryptAndDecryptNormalProcess(
"3DES192",
"3DES192|ECB|null",
"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();
});
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();
});
try {
let symKeyGenerator = cryptoFramework.createSymKeyGenerator("3DES192");
expect(symKeyGenerator != null).assertTrue();
let SymKey = await symKeyGenerator.generateSymKey();
expect(SymKey != null).assertTrue();
cryptoFramework.createCipher("3DES192|ECB|null");
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(801);
}
try {
cryptoFramework.createCipher("3DES192|ECB|CCCCC");
expect(null).assertFail();
} catch (err) {
expect(err.code).assertEqual(801);
}
done();
}
);
......@@ -798,22 +726,20 @@ export default function SymmetricCryptographyJsunit() {
"Security_crypto_framework_Symmetric_Encryption_AES_3000",
0,
async function (done) {
await symPromise
.encryptAndDecryptNormalProcessSpecialdata(
"AES256",
"AES256|CCM|PKCS7",
"genCcmParamsSpec"
)
.then((data) => {
expect(data == "TypeError: Cannot read property length of null").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_3000 catch error: " +
err
);
expect(null).assertFail();
});
let symKeyGenerator = cryptoFramework.createSymKeyGenerator("AES256");
expect(symKeyGenerator != null).assertTrue();
let symKey = await symKeyGenerator.generateSymKey();
expect(symKey != null).assertTrue();
let cipherGenerator = cryptoFramework.createCipher("AES256|CCM|PKCS7");
expect(cipherGenerator != null).assertTrue();
await cipherGenerator.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, publicModule.genCcmParamsSpec());
try {
await cipherGenerator.update(null);
expect(null).assertFail();
} catch (err) {
console.error("Security_crypto_framework_Symmetric_Encryption_AES_3000 catch error: " + err.code);
expect(err.code).assertEqual(401);
}
done();
}
);
......
......@@ -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 {
encryptAndDecryptNormalProcess,
signAndVerifyNormalProcess,
convertKeyEncryptAndDecryptProcess,
keyAgreementProcess,
encryptAndDecryptNormalProcessSuperdata,
signAndVerifyNormalProcessSuperdata,
encryptAndDecryptNormalProcessNull
signAndVerifyNormalProcessSuperdata
};
......@@ -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) {
var globalHMAC;
var globalsymKeyGenerator;
......@@ -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(
for (i = 0; i < globalTextLen; i++) {
globalText += t.charAt(Math.floor(Math.random() * n));
}
console.warn("globalText1111111111111111111111111111111: " + globalText);
return new Promise((resolve, reject) => {
var symKeyGenerator = createSymKeyGenerator(symAlgoName);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册