提交 b99c8880 编写于 作者: Q qiaozzzh

XTS Failure Case Maintenance

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