diff --git a/security/cryptoFramework/js_api_test_one/src/main/js/test/AsymmetricCryptography.test.js b/security/cryptoFramework/js_api_test_one/src/main/js/test/AsymmetricCryptography.test.js index 5f2cdc79f8bf798690df6147a71118a42ec58b6d..336213023daa409809b2af74162f5fea0db4385f 100644 --- a/security/cryptoFramework/js_api_test_one/src/main/js/test/AsymmetricCryptography.test.js +++ b/security/cryptoFramework/js_api_test_one/src/main/js/test/AsymmetricCryptography.test.js @@ -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,15 @@ 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); + } catch (err) { + console.error("err is:" + err.code); + expect(err.code).assertEqual(401); + } done(); } ); diff --git a/security/cryptoFramework/js_api_test_one/src/main/js/test/AsymmetricCryptographySecond.test.js b/security/cryptoFramework/js_api_test_one/src/main/js/test/AsymmetricCryptographySecond.test.js index 3650b202dda5bd2ea73a84b8c374508647182070..d71ac3ea6f60fd98b745e95ebc25ea3a30ab902b 100644 --- a/security/cryptoFramework/js_api_test_one/src/main/js/test/AsymmetricCryptographySecond.test.js +++ b/security/cryptoFramework/js_api_test_one/src/main/js/test/AsymmetricCryptographySecond.test.js @@ -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); } diff --git a/security/cryptoFramework/js_api_test_one/src/main/js/test/DigestAlgorithm.test.js b/security/cryptoFramework/js_api_test_one/src/main/js/test/DigestAlgorithm.test.js index b9f85760a6e5e30cb582de09d2310990501b8767..7ae43e2cd156fe33f64a29fbd476cc87b431fd5c 100644 --- a/security/cryptoFramework/js_api_test_one/src/main/js/test/DigestAlgorithm.test.js +++ b/security/cryptoFramework/js_api_test_one/src/main/js/test/DigestAlgorithm.test.js @@ -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"; @@ -213,7 +215,8 @@ export default function DigestAlgorithmJsunit() { 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 +307,18 @@ 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"); + } catch (err) { + console.error("[Promise]: error code: " + err.code + ", message is: " + err.message); + expect(err.code).assertEqual(801); + } + try { + cryptoFramework.createMac(null); + } catch (err) { + console.error("[Promise]: error code: " + err.code + ", message is: " + err.message); + expect(err.code).assertEqual(401); + } done(); }); @@ -320,13 +328,21 @@ 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); + } 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); + } catch (err) { + console.error("[Promise]init(null): error code: " + err.code + ", message is: " + err.message); + expect(err.code).assertEqual(401); + }; done(); }); @@ -336,13 +352,16 @@ 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); + } catch (err) { + console.error("[Promise]init(null): error code: " + err.code + ", message is: " + err.message); + expect(err.code).assertEqual(401); + } done(); }); diff --git a/security/cryptoFramework/js_api_test_one/src/main/js/test/SecurityRandom.test.js b/security/cryptoFramework/js_api_test_one/src/main/js/test/SecurityRandom.test.js index 1ab9dd3f8f09f244e6a87ec580c745473b72aedf..657a775973d677539191159ba78b7e0ecc2266a2 100644 --- a/security/cryptoFramework/js_api_test_one/src/main/js/test/SecurityRandom.test.js +++ b/security/cryptoFramework/js_api_test_one/src/main/js/test/SecurityRandom.test.js @@ -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); } diff --git a/security/cryptoFramework/js_api_test_one/src/main/js/test/SymmetricCryptography.test.js b/security/cryptoFramework/js_api_test_one/src/main/js/test/SymmetricCryptography.test.js index a51711a5f5ac1e65124a197c7c974223a60a785c..74c57da6948f4e410fac7f12dbeebedd56000226 100644 --- a/security/cryptoFramework/js_api_test_one/src/main/js/test/SymmetricCryptography.test.js +++ b/security/cryptoFramework/js_api_test_one/src/main/js/test/SymmetricCryptography.test.js @@ -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,19 @@ 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); + } catch (err) { + console.error("Security_crypto_framework_Symmetric_Encryption_AES_3000 catch error: " + err.code); + expect(err.code).assertEqual(401); + } done(); } ); diff --git a/security/cryptoFramework/js_api_test_one/src/main/js/test/utils/asymmetric/publicAsymmetricCallback.js b/security/cryptoFramework/js_api_test_one/src/main/js/test/utils/asymmetric/publicAsymmetricCallback.js index 3b397e13cb0baa74b2cc803ccfda14e97863c361..5561867a69e4822292cc4ffbc2581350e7f9d7d3 100644 --- a/security/cryptoFramework/js_api_test_one/src/main/js/test/utils/asymmetric/publicAsymmetricCallback.js +++ b/security/cryptoFramework/js_api_test_one/src/main/js/test/utils/asymmetric/publicAsymmetricCallback.js @@ -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 }; diff --git a/security/cryptoFramework/js_api_test_one/src/main/js/test/utils/digestalgorithm/publicDigestPromise.js b/security/cryptoFramework/js_api_test_one/src/main/js/test/utils/digestalgorithm/publicDigestPromise.js index 3e55628a3da4b3da040bd50737e4dc7c9124c3c7..d252856c3a2cc19afd2e88aa2dc89726394e158f 100644 --- a/security/cryptoFramework/js_api_test_one/src/main/js/test/utils/digestalgorithm/publicDigestPromise.js +++ b/security/cryptoFramework/js_api_test_one/src/main/js/test/utils/digestalgorithm/publicDigestPromise.js @@ -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}; diff --git a/security/cryptoFramework/js_api_test_one/src/main/js/test/utils/symmetric/publicSymmetricPromise.js b/security/cryptoFramework/js_api_test_one/src/main/js/test/utils/symmetric/publicSymmetricPromise.js index 8cbdf9026203be5a34e8159a0c356b9116c26794..54c50cddbf6892b0a08cac4aea24300f088daf58 100644 --- a/security/cryptoFramework/js_api_test_one/src/main/js/test/utils/symmetric/publicSymmetricPromise.js +++ b/security/cryptoFramework/js_api_test_one/src/main/js/test/utils/symmetric/publicSymmetricPromise.js @@ -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);