From e6f29d257c0b7177c7c536265e97b9c879f217a7 Mon Sep 17 00:00:00 2001 From: qiaozzzh Date: Mon, 21 Nov 2022 17:49:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=9D=9E=E5=AF=B9=E7=A7=B0?= =?UTF-8?q?=E5=8A=A0=E8=A7=A3=E5=AF=86=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qiaozzzh Change-Id: Idb095ca68f7bef07bfa7cb3ff9c9085b5b3449a1 --- .../cryptoFramework/js_api_test_one/Test.json | 1 + .../js/test/AsymmetricCryptography.test.js | 1442 +++++++++++++++-- .../asymmetric/publicAsymmetricCallback.js | 332 ++++ .../asymmetric/publicAsymmetricPromise.js | 142 ++ 4 files changed, 1775 insertions(+), 142 deletions(-) diff --git a/security/cryptoFramework/js_api_test_one/Test.json b/security/cryptoFramework/js_api_test_one/Test.json index 9dd37b781..1573856c5 100644 --- a/security/cryptoFramework/js_api_test_one/Test.json +++ b/security/cryptoFramework/js_api_test_one/Test.json @@ -4,6 +4,7 @@ "type": "OHJSUnitTest", "test-timeout": "900000", "shell-timeout": "900000", + "testcase-timeout": "180000", "bundle-name": "com.openharmony.cryptoFramework1", "package-name": "com.openharmony.cryptoFramework1" }, 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 f80e5f292..762159978 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 @@ -29,26 +29,26 @@ export default function AsymmetricCryptographyJsunit() { * @tc.desc Use the Callback Style of Interface */ it( - "Security_crypto_framework_ASymmetric_Encryption_RSA_0100", - 0, - async function (done) { - await asyCallback - .encryptAndDecryptNormalProcess( - "RSA1024|PRIMES_2", - "RSA1024|PKCS1|SHA256" - ) - .then((data) => { - expect(data == null).assertTrue(); - }) - .catch((err) => { - console.error( - "Security_crypto_framework_ASymmetric_Encryption_RSA_0100 catch error: " + - err - ); - expect(null).assertFail(); - }); - done(); - } + "Security_crypto_framework_ASymmetric_Encryption_RSA_0100", + 0, + async function (done) { + await asyCallback + .encryptAndDecryptNormalProcess( + "RSA1024|PRIMES_2", + "RSA1024|PKCS1|SHA256" + ) + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_Encryption_RSA_0100 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } ); /** @@ -57,26 +57,362 @@ export default function AsymmetricCryptographyJsunit() { * @tc.desc Use the Promise Style of Interface */ it( - "Security_crypto_framework_ASymmetric_Encryption_RSA_0200", - 0, - async function (done) { - await asyPromise - .encryptAndDecryptNormalProcess( - "RSA2048|PRIMES_2", - "RSA2048|PKCS1|MD5" - ) - .then((data) => { - expect(data == null).assertTrue(); - }) - .catch((err) => { - console.error( - "Security_crypto_framework_ASymmetric_Encryption_RSA_0200 catch error: " + - err - ); - expect(null).assertFail(); - }); - done(); - } + "Security_crypto_framework_ASymmetric_Encryption_RSA_0200", + 0, + async function (done) { + await asyPromise + .encryptAndDecryptNormalProcess( + "RSA2048|PRIMES_2", + "RSA2048|PKCS1|MD5" + ) + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_Encryption_RSA_0200 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0300 + * @tc.name Test RSA3072 normal encryption and decryption + * @tc.desc Use the Callback Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_Encryption_RSA_0300", + 0, + async function (done) { + await asyCallback + .encryptAndDecryptNormalProcess( + "RSA3072", + "RSA3072|PKCS1|SHA224" + ) + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_Encryption_RSA_0300 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0400 + * @tc.name Test RSA4096 normal encryption and decryption + * @tc.desc Use the Promise Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_Encryption_RSA_0400", + 0, + async function (done) { + await asyPromise + .encryptAndDecryptNormalProcess( + "RSA4096", + "RSA4096|PKCS1_OAEP|MD5|MGF1_SHA512" + ) + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_Encryption_RSA_0400 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0500 + * @tc.name Test RSA3072 normal encryption and decryption + * @tc.desc Use the Callback Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_Encryption_RSA_0500", + 0, + async function (done) { + await asyCallback + .encryptAndDecryptNormalProcess( + "RSA8192", + "RSA8192|PKCS1_OAEP|SHA1|MGF1_SHA384" + ) + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_Encryption_RSA_0500 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0600 + * @tc.name Test RSA3072|PKCS1|SHA256 normal encryption and decryption + * @tc.desc Use the Promise Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_Encryption_RSA_0600", + 0, + async function (done) { + await asyPromise + .encryptAndDecryptNormalProcess( + "RSA3072|PRIMES_3", + "RSA3072|PKCS1|SHA256" + ) + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_Encryption_RSA_0600 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0700 + * @tc.name Test RSA3072|PKCS1|SHA512 normal encryption and decryption + * @tc.desc Use the Callback Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_Encryption_RSA_0700", + 0, + async function (done) { + await asyCallback + .encryptAndDecryptNormalProcess( + "RSA3072", + "RSA3072|PKCS1|SHA512" + ) + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_Encryption_RSA_0700 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0800 + * @tc.name Test RSA3072|PKCS1_OAEP|SHA224|MGF1_SHA256 normal encryption and decryption + * @tc.desc Use the Promise Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_Encryption_RSA_0800", + 0, + async function (done) { + await asyPromise + .encryptAndDecryptNormalProcess( + "RSA3072", + "RSA3072|PKCS1_OAEP|SHA224|MGF1_SHA256" + ) + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_Encryption_RSA_0800 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0900 + * @tc.name Test RSA512|PKCS1_OAEP|SHA256|MGF1_SHA224 normal encryption and decryption + * @tc.desc Use the Callback Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_Encryption_RSA_0900", + 0, + async function (done) { + await asyCallback + .encryptAndDecryptNormalProcess( + "RSA1024", + "RSA1024|PKCS1_OAEP|SHA256|MGF1_SHA224" + ) + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_Encryption_RSA_0900 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_1000 + * @tc.name Test RSA3072|PKCS1_OAEP|SHA384|MGF1_SHA1 normal encryption and decryption + * @tc.desc Use the Promise Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_Encryption_RSA_1000", + 0, + async function (done) { + await asyPromise + .encryptAndDecryptNormalProcess( + "RSA3072|PRIMES_3", + "RSA3072|PKCS1_OAEP|SHA384|MGF1_SHA1" + ) + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_Encryption_RSA_1000 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_1100 + * @tc.name Test RSA3072|PKCS1_OAEP|SHA512|MGF1_MD5 normal encryption and decryption + * @tc.desc Use the Callback Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_Encryption_RSA_1100", + 0, + async function (done) { + await asyCallback + .encryptAndDecryptNormalProcess( + "RSA3072", + "RSA3072|PKCS1_OAEP|SHA512|MGF1_MD5" + ) + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_Encryption_RSA_1100 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_1200 + * @tc.name Test RSA3072|PKCS1 normal encryption and decryption + * @tc.desc Use the Promise Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_Encryption_RSA_1200", + 0, + async function (done) { + await asyPromise + .encryptAndDecryptNormalProcess( + "RSA3072", + "RSA3072|PKCS1" + ) + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_Encryption_RSA_1200 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_1300 + * @tc.name Test RSA4096|PKCS1 normal encryption and decryption + * @tc.desc Use the Callback Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_Encryption_RSA_1300", + 0, + async function (done) { + await asyCallback + .encryptAndDecryptNormalProcess( + "RSA4096", + "RSA4096|PKCS1" + ) + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_Encryption_RSA_1300 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_1400 + * @tc.name Test RSA4096|PKCS1 normal encryption and decryption + * @tc.desc Use the Callback Style of Interface + */ + it( + "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(); + }); + done(); + } ); /** @@ -85,23 +421,23 @@ export default function AsymmetricCryptographyJsunit() { * @tc.desc Use the Callback Style of Interface */ it( - "Security_crypto_framework_ASymmetric_SignVerify_RSA_0100", - 0, - async function (done) { - await asyCallback - .signAndVerifyNormalProcess("RSA1024|PRIMES_2", "RSA1024|PKCS1|MD5") - .then((data) => { - expect(data == null).assertTrue(); - }) - .catch((err) => { - console.error( - "Security_crypto_framework_ASymmetric_SignVerify_RSA_0100 catch error: " + - err - ); - expect(null).assertFail(); - }); - done(); - } + "Security_crypto_framework_ASymmetric_SignVerify_RSA_0100", + 0, + async function (done) { + await asyCallback + .signAndVerifyNormalProcess("RSA1024|PRIMES_2", "RSA1024|PKCS1|MD5") + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_0100 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } ); /** @@ -110,23 +446,708 @@ export default function AsymmetricCryptographyJsunit() { * @tc.desc Use the Promise Style of Interface */ it( - "Security_crypto_framework_ASymmetric_SignVerify_RSA_0200", - 0, - async function (done) { - await asyPromise - .signAndVerifyNormalProcess("RSA2048|PRIMES_2", "RSA2048|PKCS1|SHA1") - .then((data) => { - expect(data == null).assertTrue(); - }) - .catch((err) => { - console.error( - "Security_crypto_framework_ASymmetric_SignVerify_RSA_0200 catch error: " + - err - ); - expect(null).assertFail(); - }); - done(); - } + "Security_crypto_framework_ASymmetric_SignVerify_RSA_0200", + 0, + async function (done) { + await asyPromise + .signAndVerifyNormalProcess("RSA2048|PRIMES_2", "RSA2048|PKCS1|SHA1") + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_0200 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0300 + * @tc.name Test RSA3072|PKCS1|SHA224 normal sign and verify + * @tc.desc Use the Callback Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_0300", + 0, + async function (done) { + await asyCallback + .signAndVerifyNormalProcess("RSA3072|PRIMES_2", "RSA3072|PKCS1|SHA224") + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_0300 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0400 + * @tc.name Test RSA2048|PKCS1|SHA1 normal sign and verify + * @tc.desc Use the Promise Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_0400", + 0, + async function (done) { + await asyPromise + .signAndVerifyNormalProcess("RSA4096|PRIMES_2", "RSA4096|PKCS1|SHA256") + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_0400 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0500 + * @tc.name Test RSA8192|PKCS1|SHA384 normal sign and verify + * @tc.desc Use the Promise Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_0500", + 0, + async function (done) { + await asyPromise + .signAndVerifyNormalProcess("RSA8192|PRIMES_3", "RSA8192|PKCS1|SHA384") + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_0500 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0600 + * @tc.name Test RSA512|PKCS1|SHA512 normal sign and verify + * @tc.desc Use the Promise Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_0600", + 0, + async function (done) { + await asyPromise + .signAndVerifyNormalProcess("RSA512|PRIMES_2", "RSA512|PKCS1|SHA256") + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_0600 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0700 + * @tc.name Test RSA1024|PKCS1|MD5|MGF1_MD5 normal sign and verify + * @tc.desc Use the Callback Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_0700", + 0, + async function (done) { + await asyCallback + .signAndVerifyNormalProcess("RSA1024", "RSA1024|PKCS1|MD5|MGF1_MD5") + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_0700 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0800 + * @tc.name Test RSA2048|PSS|SHA1|MGF1_SHA1 normal sign and verify + * @tc.desc Use the Promise Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_0800", + 0, + async function (done) { + await asyPromise + .signAndVerifyNormalProcess("RSA2048", "RSA2048|PSS|SHA1|MGF1_SHA1") + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_0800 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0900 + * @tc.name Test RSA3072|PSS|SHA224|MGF1_SHA224 normal sign and verify + * @tc.desc Use the Callback Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_0900", + 0, + async function (done) { + await asyCallback + .signAndVerifyNormalProcess("RSA3072", "RSA3072|PSS|SHA224|MGF1_SHA224") + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_0900 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1000 + * @tc.name Test RSA4096|PSS|SHA256|MGF1_SHA256 normal sign and verify + * @tc.desc Use the Callback Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_1000", + 0, + async function (done) { + await asyCallback + .signAndVerifyNormalProcess("RSA4096", "RSA4096|PSS|SHA256|MGF1_SHA256") + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_1000 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1100 + * @tc.name Test RSA2048|PSS|SHA1|MGF1_SHA1 normal sign and verify + * @tc.desc Use the Promise Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_1100", + 0, + async function (done) { + await asyPromise + .signAndVerifyNormalProcess("RSA8192", "RSA8192|PSS|SHA512|MGF1_SHA512") + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_1100 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1200 + * @tc.name Test RSA2048|PSS|SHA1|MGF1_SHA1 normal sign and verify + * @tc.desc Use the Promise Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_1200", + 0, + async function (done) { + await asyPromise + .signAndVerifyNormalProcess("RSA512", "RSA512|PSS|SHA384|MGF1_SHA384") + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_1200 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_5000 + * @tc.name Test RSA2048|PSS|SHA1|MGF1_SHA1 normal sign and verify + * @tc.desc Use the Promise Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_5000", + 0, + async function (done) { + await asyPromise + .signAndVerifyNormalProcessDataException("RSA512", "RSA512|PSS|SHA384|MGF1_SHA384", "null") + .then((data) => { + expect(data == "Error: [Data]: must be of the DataBlob type.").assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_5000 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1300 + * @tc.name Test RSA256 or null normal sign and verify + * @tc.desc Use the Promise Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_1300", + 0, + async function (done) { + await asyPromise + .createAsyKeyGeneratorFail("RSA256") + .then((data) => { + expect(data == "TypeError: Cannot read property algName of null").assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_1300 catch error: " + + err + ); + expect(null).assertFail(); + }); + await asyPromise + .createAsyKeyGeneratorFail("null") + .then((data) => { + expect(data == "TypeError: Cannot read property algName of null").assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_1300 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1400 + * @tc.name Test RSA2048|PSS|SHA1|MGF1_SHA1 normal sign and verify + * @tc.desc Use the Promise Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_1400", + 0, + async function (done) { + await asyPromise + .createAsySignFail( + "RSA3072", + "RSA4096|null|SHA256", + "RSA4096|PKCS1|null", + "RSA4096|PKCS1|SHA122", + "RSA4096|PKCS3|SHA256" + ) + .then((data) => { + expect(data == "TypeError: Cannot read property algName of undefined").assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_1400 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_2000 + * @tc.name Test RSA4096|PKCS1 normal encryption and decryption + * @tc.desc Use the Callback Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_Encryption_RSA_2000", + 0, + async function (done) { + await asyCallback + .encryptAndDecryptNormalProcessSuperdata( + "RSA4096", + "RSA4096|PKCS1", + "490" + ) + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_Encryption_RSA_2000 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_2100 + * @tc.name Test RSA3072|PKCS1|SHA224 normal sign and verify + * @tc.desc Use the Callback Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_2100", + 0, + async function (done) { + await asyCallback + .signAndVerifyNormalProcessSuperdata( + "RSA3072", + "RSA3072|PKCS1|SHA224", + "350" + ) + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_2100 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1500 + * @tc.name Test RSA2048|PSS|SHA1|MGF1_SHA1 normal sign and verify + * @tc.desc Use the Promise Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_1500", + 0, + async function (done) { + await asyPromise + .createAsyVerifyFail( + "RSA3072", + "RSA4096|null|SHA256", + "RSA4096|PKCS1|null", + "RSA4096|PKCS1|SHA122", + "RSA4096|PKCS3|SHA256" + ) + .then((data) => { + expect(data == "TypeError: Cannot read property algName of undefined").assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_RSA_1500 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0100 + * @tc.name Test ECC224|SHA256 normal sign and verify + * @tc.desc Use the Callback Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0100", + 0, + async function (done) { + await asyCallback + .signAndVerifyNormalProcess("ECC224", "ECC224|SHA256") + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0100 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0200 + * @tc.name Test ECC256|SHA1 normal sign and verify + * @tc.desc Use the Promise Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0200", + 0, + async function (done) { + await asyPromise + .signAndVerifyNormalProcess("ECC256", "ECC256|SHA1") + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0200 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0300 + * @tc.name Test ECC224|SHA256 normal sign and verify + * @tc.desc Use the Callback Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0300", + 0, + async function (done) { + await asyCallback + .signAndVerifyNormalProcess("ECC384", "ECC384|SHA224") + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0300 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0400 + * @tc.name Test ECC521|SHA384 normal sign and verify + * @tc.desc Use the Callback Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0400", + 0, + async function (done) { + await asyPromise + .signAndVerifyNormalProcess("ECC512", "ECC512|SHA384") + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0400 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0500 + * @tc.name Test ECC224|SHA512 normal sign and verify + * @tc.desc Use the Callback Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0500", + 0, + async function (done) { + await asyPromise + .signAndVerifyNormalProcess("ECC224", "ECC224|SHA512") + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0500 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0600 + * @tc.name Test ECC1 or NULL normal sign and verify + * @tc.desc Use the Callback Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0600", + 0, + async function (done) { + await asyCallback + .createAsyKeyGeneratorFail("ECC1") + .then((data) => { + expect(data == "TypeError: Cannot read property algName of null").assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0600 catch error: " + + err + ); + expect(null).assertFail(); + }); + await asyCallback + .createAsyKeyGeneratorFail("null") + .then((data) => { + expect(data == "TypeError: Cannot read property algName of null").assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0600 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0700 + * @tc.name Test ECC224 normal sign and verify + * @tc.desc Use the Callback Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0700", + 0, + async function (done) { + await asyPromise + .createAsySignFail( + "ECC224", + "ECC224|SHA257", + "ECC224|NULL", + "NULL|SHA1", + "ECC|SHA" + ) + .then((data) => { + expect(data == "TypeError: Cannot read property algName of undefined").assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0700: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0800 + * @tc.name Test RSA3072 normal sign and verify + * @tc.desc Use the Callback Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0800", + 0, + async function (done) { + await asyPromise + .createAsyVerifyFail( + "ECC224", + "ECC1|SHA256", + "NULL|SHA256", + "ECC224|SHA122", + "ECC224|NULL" + ) + .then((data) => { + expect(data == "TypeError: Cannot read property algName of undefined").assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0800 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0900 + * @tc.name Test ECC224|SHA512 normal sign and verify + * @tc.desc Use the Callback Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0900", + 0, + async function (done) { + await asyCallback + .signAndVerifyNormalProcessSuperdata( + "ECC224", + "ECC224|SHA512", + "350" + ) + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0900 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } ); /** @@ -135,23 +1156,23 @@ export default function AsymmetricCryptographyJsunit() { * @tc.desc Use the Promise Style of Interface */ it( - "Security_crypto_framework_ASymmetric_SignVerify_ECDH_0100", - 0, - async function (done) { - await asyPromise - .keyAgreementProcess("ECC224") - .then((data) => { - expect(data == null).assertTrue(); - }) - .catch((err) => { - console.error( - "Security_crypto_framework_ASymmetric_SignVerify_ECDH_0100 catch error: " + - err - ); - expect(null).assertFail(); - }); - done(); - } + "Security_crypto_framework_ASymmetric_SignVerify_ECDH_0100", + 0, + async function (done) { + await asyPromise + .keyAgreementProcess("ECC224") + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_ECDH_0100 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } ); /** @@ -160,23 +1181,160 @@ export default function AsymmetricCryptographyJsunit() { * @tc.desc Use the Callback Style of Interface */ it( - "Security_crypto_framework_ASymmetric_SignVerify_ECDH_0200", - 0, - async function (done) { - await asyCallback - .keyAgreementProcess("ECC256") - .then((data) => { - expect(data == null).assertTrue(); - }) - .catch((err) => { - console.error( - "Security_crypto_framework_ASymmetric_SignVerify_ECDH_0200 catch error: " + - err - ); - expect(null).assertFail(); - }); - done(); - } + "Security_crypto_framework_ASymmetric_SignVerify_ECDH_0200", + 0, + async function (done) { + await asyCallback + .keyAgreementProcess("ECC256") + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_ECDH_0200 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0300 + * @tc.name Test ECC384 SignVerify ECDH + * @tc.desc Use the Promise Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_ECDH_0300", + 0, + async function (done) { + await asyPromise + .keyAgreementProcess("ECC384") + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_ECDH_0300 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0400 + * @tc.name Test ECC512 SignVerify ECDH + * @tc.desc Use the Callback Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_ECDH_0400", + 0, + async function (done) { + await asyCallback + .keyAgreementProcess("ECC512") + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_ECDH_0400 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0500 + * @tc.name Test ECC5 or null SignVerify ECDH + * @tc.desc Use the Callback Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_ECDH_0500", + 0, + async function (done) { + await asyCallback + .createAsyKeyAgreementFail("ECC5") + .then((data) => { + expect(data == "TypeError: Cannot read property algName of undefined").assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_ECDH_0500 catch error: " + + err + ); + expect(null).assertFail(); + }); + await asyCallback + .createAsyKeyAgreementFail("null") + .then((data) => { + expect(data == "TypeError: Cannot read property algName of undefined").assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_ECDH_0500 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0600 + * @tc.name Test ECC256 SignVerify ECDH + * @tc.desc Use the Callback Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_ECDH_0600", + 0, + async function (done) { + await asyCallback + .keyAgreementProcessParameterException("ECC256") + .then((data) => { + expect(data == "Error: [PriKey]: param unwarp error.").assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_ECDH_0600 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0700 + * @tc.name Test RSA3072 SignVerify ECDH + * @tc.desc Use the Callback Style of Interface + */ + it( + "Security_crypto_framework_ASymmetric_SignVerify_ECDH_0700", + 0, + async function (done) { + await asyCallback + .keyAgreementProcessFail("RSA3072", "ECC512") + .then((data) => { + expect(data == "Error: An exception occurs.").assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_SignVerify_ECDH_0700 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } ); /** @@ -185,23 +1343,23 @@ export default function AsymmetricCryptographyJsunit() { * @tc.desc Use RSA3072|PRIMES_2 algorithm */ it( - "Security_crypto_framework_ASymmetric_Encryption_RSA_3300", - 0, - async function (done) { - await asyPromise - .convertKeyEncryptAndDecryptProcess("RSA3072|PRIMES_2") - .then((data) => { - expect(data == null).assertTrue(); - }) - .catch((err) => { - console.error( - "Security_crypto_framework_ASymmetric_Encryption_RSA_3300 catch error: " + - err - ); - expect(null).assertFail(); - }); - done(); - } + "Security_crypto_framework_ASymmetric_Encryption_RSA_3300", + 0, + async function (done) { + await asyPromise + .convertKeyEncryptAndDecryptProcess("RSA3072|PRIMES_2") + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_Encryption_RSA_3300 catch error: " + + err + ); + expect(null).assertFail(); + }); + done(); + } ); /** @@ -210,23 +1368,23 @@ export default function AsymmetricCryptographyJsunit() { * @tc.desc Use RSA1024|PRIMES_2 algorithm */ it( - "Security_crypto_framework_ASymmetric_Encryption_RSA_3100", - 0, - async function (done) { - await asyPromise - .AsyPriKeyClearProcess("RSA1024|PRIMES_2") - .then((data) => { - expect(data == null).assertTrue(); - }) - .catch((err) => { - console.error( - "Security_crypto_framework_ASymmetric_Encryption_RSA_3100 catch error: " + - err - ); - expect(null).assertFail(); - }); - done(); - } + "Security_crypto_framework_ASymmetric_Encryption_RSA_3100", + 0, + async function (done) { + await asyPromise + .AsyPriKeyClearProcess("RSA1024|PRIMES_2") + .then((data) => { + expect(data == null).assertTrue(); + }) + .catch((err) => { + console.error( + "Security_crypto_framework_ASymmetric_Encryption_RSA_3100 catch error: " + + err + ); + expect(null).assertFail(); + }); + 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 2e9c0216b..8df5d7e11 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 @@ -391,6 +391,17 @@ async function convertKeyEncryptAndDecryptProcess(asyAlgoName) { }); } +async function createAsyKeyAgreementFail(ECDHAlgoName) { + return new Promise((resolve, reject) => { + var globalECDHData = createAsyKeyAgreement(ECDHAlgoName); + resolve(globalECDHData); + expect(globalECDHData == "TypeError: Cannot read property algName of undefined").assertTrue(); + if (globalECDHData != "TypeError: Cannot read property algName of undefined"){ + reject(); + } + }); +} + async function keyAgreementProcess(ECDHAlgoName) { var globalPubKey; var globalPriKey; @@ -420,9 +431,330 @@ async function keyAgreementProcess(ECDHAlgoName) { }); } +async function keyAgreementProcessFail(ECDHAlgoName, ECDHAlgoName1) { + var globalPubKey; + var globalPriKey; + + return new Promise((resolve, reject) => { + var rsaGenerator = createAsyKeyGenerator(ECDHAlgoName); + expect(rsaGenerator != null).assertTrue(); + var globalECDHData = createAsyKeyAgreement(ECDHAlgoName1); + expect(globalECDHData != null).assertTrue(); + + generateAsyKeyPair(rsaGenerator) + .then((rsaKeyPair) => { + expect(rsaKeyPair != null).assertTrue(); + globalPubKey = rsaKeyPair.pubKey; + globalPriKey = rsaKeyPair.priKey; + return generateAsySecret(globalECDHData, globalPriKey, globalPubKey); + }) + .then((result) => { + console.warn("result data is " + uInt8ArrayToShowStr(result.data)); + expect(result != null).assertTrue(); + reject(); + }) + .catch((err) => { + console.error("[Callback] keyAgreementProcess catch err:" + err); + resolve(err); + }); + }); +} + +async function keyAgreementProcessParameterException(ECDHAlgoName) { + var globalPubKey; + var globalPriKey; + + return new Promise((resolve, reject) => { + var rsaGenerator = createAsyKeyGenerator(ECDHAlgoName); + expect(rsaGenerator != null).assertTrue(); + var globalECDHData = createAsyKeyAgreement(ECDHAlgoName); + expect(globalECDHData != null).assertTrue(); + + generateAsyKeyPair(rsaGenerator) + .then((rsaKeyPair) => { + expect(rsaKeyPair != null).assertTrue(); + globalPubKey = rsaKeyPair.pubKey; + globalPriKey = rsaKeyPair.priKey; + return generateAsySecret(globalECDHData, null, null); + }) + .then((result) => { + console.warn("result data is " + uInt8ArrayToShowStr(result.data)); + expect(result != null).assertTrue(); + }) + .catch((err) => { + expect(err == "Error: [PriKey]: param unwarp error.").assertTrue(); + }); + generateAsyKeyPair(rsaGenerator) + .then((rsaKeyPair) => { + expect(rsaKeyPair != null).assertTrue(); + globalPubKey = rsaKeyPair.pubKey; + globalPriKey = rsaKeyPair.priKey; + return generateAsySecret(globalECDHData, globalPubKey, null); + }) + .then((result) => { + console.warn("result data is " + uInt8ArrayToShowStr(result.data)); + expect(result != null).assertTrue(); + }) + .catch((err) => { + expect(err == "Error: [PubKey]: param unwarp error.").assertTrue(); + }); + generateAsyKeyPair(rsaGenerator) + .then((rsaKeyPair) => { + expect(rsaKeyPair != null).assertTrue(); + globalPubKey = rsaKeyPair.pubKey; + globalPriKey = rsaKeyPair.priKey; + return generateAsySecret(globalECDHData, null, globalPriKey); + }) + .then((result) => { + console.warn("result data is " + uInt8ArrayToShowStr(result.data)); + expect(result != null).assertTrue(); + reject(); + }) + .catch((err) => { + expect(err == "Error: [PriKey]: param unwarp error.").assertTrue(); + resolve(err); + }); + }); +} + +async function createAsyKeyGeneratorFail(asyAlgoName) { + + return new Promise((resolve, reject) => { + var rsaGenerator = createAsyKeyGenerator(asyAlgoName); + resolve(rsaGenerator); + expect(rsaGenerator == "TypeError: Cannot read property algName of null").assertTrue(); + if (rsaGenerator != "TypeError: Cannot read property algName of null") { + reject(); + } + }); +} + +async function encryptAndDecryptNormalProcessSuperdata(asyAlgoName, cipherAlgoName, globalTextLen) { + var globalCipherText; + var globalPubKey; + var globalPriKey; + var globalText; + var i; + var encryptMode = cryptoFramework.CryptoMode.ENCRYPT_MODE; + var decryptMode = cryptoFramework.CryptoMode.DECRYPT_MODE; + var t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefhijklmnopqrstuvwxyz",n = t.length,s=""; + for (i = 0; i < globalTextLen; i++) { + globalText += t.charAt(Math.floor(Math.random() * n)); + } + var input = { data: stringTouInt8Array(globalText) }; + + 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(); + globalPubKey = rsaKeyPair.pubKey; + globalPriKey = rsaKeyPair.priKey; + return initCipher( + cipherGeneratorEncrypt, + encryptMode, + globalPubKey, + null + ); + }) + .then((initData) => { + expect(initData === "init success").assertTrue(); + return doFinalCipher(cipherGeneratorEncrypt, encryptMode, input); + }) + .then((finalOutput) => { + expect(finalOutput != null).assertTrue(); + globalCipherText = finalOutput; + console.log( + "cipherOutput: " + uInt8ArrayToShowStr(globalCipherText.data) + ); + return initCipher( + cipherGeneratorDecrypt, + decryptMode, + globalPriKey, + 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); + expect(decryptData == globalText).assertTrue(); + resolve(); + }) + .catch((err) => { + console.error( + "[Callback] encryptAndDecryptNormalProcess catch err:" + err + ); + reject(err); + }); + }); +} + +async function signAndVerifyNormalProcessSuperdata(asyAlgoName, signVerifyAlgoName, globalTextLen) { + var globalSignBlob; + var globalPubKey; + var globalPriKey; + var globalText; + var i; + var t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefhijklmnopqrstuvwxyz",n = t.length,s=""; + for (i = 0; i < globalTextLen; i++) { + globalText += t.charAt(Math.floor(Math.random() * n)); + } + var input = { data: stringTouInt8Array(globalText) }; + + return new Promise((resolve, reject) => { + var rsaGenerator = createAsyKeyGenerator(asyAlgoName); + expect(rsaGenerator != null).assertTrue(); + var signGenerator = createAsySign(signVerifyAlgoName); + expect(signGenerator != null).assertTrue(); + var verifyGenerator = createAsyVerify(signVerifyAlgoName); + expect(verifyGenerator != null).assertTrue(); + + generateAsyKeyPair(rsaGenerator) + .then((rsaKeyPair) => { + expect(rsaKeyPair != null).assertTrue(); + globalPubKey = rsaKeyPair.pubKey; + globalPriKey = rsaKeyPair.priKey; + return initSign(signGenerator, globalPriKey); + }) + .then((initData) => { + expect(initData === "init success").assertTrue(); + return updateSign(signGenerator, input); + }) + .then((updateData) => { + expect(updateData === "update success").assertTrue(); + return signForSign(signGenerator, input); + }) + .then((finalOutput) => { + expect(finalOutput != null).assertTrue(); + globalSignBlob = finalOutput; + console.log("signOutput: " + uInt8ArrayToShowStr(globalSignBlob.data)); + return initVerify(verifyGenerator, globalPubKey); + }) + .then((initData) => { + expect(initData === "init success").assertTrue(); + return updateVerify(verifyGenerator, input); + }) + .then((updateData) => { + expect(updateData === "update success").assertTrue(); + return verifyForVerify(verifyGenerator, input, globalSignBlob); + }) + .then((finalStatus) => { + expect(finalStatus).assertTrue(); + resolve(); + }) + .catch((err) => { + console.error("[Callback] signAndVerifyNormalProcess catch err:" + err); + reject(err); + }); + }); +} + +async function encryptAndDecryptNormalProcessNull(asyAlgoName, cipherAlgoName) { + var globalCipherText; + var globalPubKey; + var globalPriKey; +// var globalText = null; +// var input = { data: stringTouInt8Array(globalText) }; + 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(); + globalPubKey = rsaKeyPair.pubKey; + globalPriKey = rsaKeyPair.priKey; + return initCipher( + cipherGeneratorEncrypt, + encryptMode, + globalPubKey, + 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, + globalPriKey, + 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); + expect(decryptData == globalText).assertTrue(); + reject(); + }) + .catch((err) => { + console.error( + "[Callback] encryptAndDecryptNormalProcess catch err:" + err + ); + resolve(err); + }); + }); +} export { encryptAndDecryptNormalProcess, signAndVerifyNormalProcess, convertKeyEncryptAndDecryptProcess, keyAgreementProcess, + createAsyKeyAgreementFail, + keyAgreementProcessFail, + keyAgreementProcessParameterException, + createAsyKeyGeneratorFail, + encryptAndDecryptNormalProcessSuperdata, + signAndVerifyNormalProcessSuperdata, + encryptAndDecryptNormalProcessNull, }; diff --git a/security/cryptoFramework/js_api_test_one/src/main/js/test/utils/asymmetric/publicAsymmetricPromise.js b/security/cryptoFramework/js_api_test_one/src/main/js/test/utils/asymmetric/publicAsymmetricPromise.js index c11a833f1..49ade96de 100644 --- a/security/cryptoFramework/js_api_test_one/src/main/js/test/utils/asymmetric/publicAsymmetricPromise.js +++ b/security/cryptoFramework/js_api_test_one/src/main/js/test/utils/asymmetric/publicAsymmetricPromise.js @@ -351,6 +351,74 @@ async function signAndVerifyNormalProcess(asyAlgoName, signVerifyAlgoName) { }); } +async function signAndVerifyNormalProcessDataException(asyAlgoName, signVerifyAlgoName, dataType) { + var globalPubKey; + var globalPriKey; + var globalSignBlob; + var globalText = "This is a sign test"; + var input; + if (dataType == "null") { + input = null; + } else { + input = { data: stringTouInt8Array(globalText) }; + }; + + return new Promise((resolve, reject) => { + var rsaGenerator = createAsyKeyGenerator(asyAlgoName); + expect(rsaGenerator != null).assertTrue(); + var signGenerator = createAsySign(signVerifyAlgoName); + expect(signGenerator != null).assertTrue(); + var verifyGenerator = createAsyVerify(signVerifyAlgoName); + expect(verifyGenerator != null).assertTrue(); + + generateAsyKeyPair(rsaGenerator) + .then((rsaKeyPair) => { + expect(rsaKeyPair != null).assertTrue(); + globalPubKey = rsaKeyPair.pubKey; + globalPriKey = rsaKeyPair.priKey; + return initSign(signGenerator, globalPriKey); + }) + .then((initData) => { + expect(initData === "init success").assertTrue(); + return updateSign(signGenerator, input); + }) + .then((updateData) => { + expect(updateData === "update success").assertTrue(); + return signForSign(signGenerator, input); + }) + .then((finalOutput) => { + expect(finalOutput != null).assertTrue(); + globalSignBlob = finalOutput; + console.log("signOutput: " + uInt8ArrayToShowStr(globalSignBlob.data)); + return initVerify(verifyGenerator, globalPubKey); + }) + .then((initData) => { + expect(initData === "init success").assertTrue(); + return updateVerify(verifyGenerator, input); + }) + .then((updateData) => { + expect(updateData === "update success").assertTrue(); + return verifyForVerify(verifyGenerator, input, globalSignBlob); + }) + .then((finalStatus) => { + expect(finalStatus).assertTrue(); + if (dataType == "null") { + reject(); + } else { + resolve(); + } + }) + .catch((err) => { + console.error("[promise] signAndVerifyNormalProcess catch err:" + err); + if (dataType =="null") { + resolve(err); + } else { + reject(err); + } + }); + }); +} + async function convertKeyEncryptAndDecryptProcess(asyAlgoName) { return new Promise((resolve, reject) => { var rsaGenerator = createAsyKeyGenerator(asyAlgoName); @@ -445,10 +513,84 @@ async function AsyPriKeyClearProcess(asyAlgoName) { }); } +async function createAsyKeyGeneratorFail(asyAlgoName) { + return new Promise((resolve, reject) => { + var rsaGenerator = createAsyKeyGenerator(asyAlgoName); + resolve(rsaGenerator); + expect(rsaGenerator == "TypeError: Cannot read property algName of null").assertTrue(); + if (rsaGenerator != "TypeError: Cannot read property algName of null") { + reject(); + } + }); +} + +async function createAsySignFail( + asyAlgoName, + signVerifyAlgoName, + signVerifyAlgoName1, + signVerifyAlgoName2, + signVerifyAlgoName3 +) { + return new Promise((resolve, reject) => { + var rsaGenerator = createAsyKeyGenerator(asyAlgoName); + expect(rsaGenerator != null).assertTrue(); + var rsaKeyPair = generateAsyKeyPair(rsaGenerator); + expect(rsaKeyPair != null).assertTrue(); + var signGenerator = createAsySign(signVerifyAlgoName); + expect(signGenerator == "TypeError: Cannot read property algName of undefined").assertTrue(); + + var signGenerator = createAsySign(signVerifyAlgoName1); + expect(signGenerator == "TypeError: Cannot read property algName of undefined").assertTrue(); + + var signGenerator = createAsySign(signVerifyAlgoName2); + expect(signGenerator == "TypeError: Cannot read property algName of undefined").assertTrue(); + + var signGenerator = createAsySign(signVerifyAlgoName3); + resolve(signGenerator); + expect(signGenerator == "TypeError: Cannot read property algName of undefined").assertTrue(); + if (signGenerator != "TypeError: Cannot read property algName of undefined") { + reject(); + } + }); +} + +async function createAsyVerifyFail( + asyAlgoName, + signVerifyAlgoName, + signVerifyAlgoName1, + signVerifyAlgoName2, + signVerifyAlgoName3 +) { + return new Promise((resolve, reject) => { + var rsaGenerator = createAsyKeyGenerator(asyAlgoName); + expect(rsaGenerator != null).assertTrue(); + var rsaKeyPair = generateAsyKeyPair(rsaGenerator); + expect(rsaKeyPair != null).assertTrue(); + var verifyGenerator = createAsyVerify(signVerifyAlgoName); + expect(verifyGenerator == "TypeError: Cannot read property algName of undefined").assertTrue(); + + var verifyGenerator = createAsyVerify(signVerifyAlgoName1); + expect(verifyGenerator == "TypeError: Cannot read property algName of undefined").assertTrue(); + + var verifyGenerator = createAsyVerify(signVerifyAlgoName2); + expect(verifyGenerator == "TypeError: Cannot read property algName of undefined").assertTrue(); + + var verifyGenerator = createAsyVerify(signVerifyAlgoName3); + resolve(verifyGenerator); + expect(verifyGenerator == "TypeError: Cannot read property algName of undefined").assertTrue(); + if (verifyGenerator != "TypeError: Cannot read property algName of undefined") { + reject(); + } + }); +} export { encryptAndDecryptNormalProcess, signAndVerifyNormalProcess, convertKeyEncryptAndDecryptProcess, keyAgreementProcess, AsyPriKeyClearProcess, + signAndVerifyNormalProcessDataException, + createAsyKeyGeneratorFail, + createAsySignFail, + createAsyVerifyFail, }; -- GitLab