提交 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";
export default function AsymmetricCryptographyJsunit() {
describe("AsymmetricCryptographyJsunit", function () {
console.info("##########start AsymmetricCryptographyJsunit##########");
beforeAll(function () {});
afterEach(function () {});
beforeAll(function () {
});
afterEach(function () {
});
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0100
......@@ -666,7 +668,7 @@ export default function AsymmetricCryptographyJsunit() {
);
});
});
}
\ No newline at end of file
......@@ -28,14 +28,17 @@ import {
testMDErrorAlgorithm,
testMDErrorAlgorithmNull,
testMDDigestCallbackLen,
testMDDigestCallbackLenNull,
} from "./utils/digestalgorithm/publicDigestCallback";
import cryptoFramework from "@ohos.security.cryptoFramework";
export default function DigestAlgorithmJsunit() {
describe("DigestAlgorithmJsunit", function () {
console.info("##########start DigestAlgorithmJsunit##########");
beforeAll(function () {});
afterEach(function () {});
beforeAll(function () {
});
afterEach(function () {
});
/**
* @tc.number Security_crypto_framework_MD_0100
......@@ -188,13 +191,30 @@ export default function DigestAlgorithmJsunit() {
* @tc.desc Use the Callback Style of Interface
*/
it("Security_crypto_framework_MD_1000", 0, async function (done) {
await testMDDigestCallbackLenNull("SHA224")
.then((data) => {
expect(data == null).assertTrue();
let mdGenerator = cryptoFramework.createMd("SHA224");
try {
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();
});
......
......@@ -13,11 +13,11 @@
* limitations under the License.
*/
import SymmetricCryptographyJsunit from "./SymmetricCryptography.test";
import AsymmetricCryptographyJsunit from "./AsymmetricCryptography.test";
import AsymmetricCryptographyJsSecondunit from "./AsymmetricCryptographySecond.test";
import DigestAlgorithmJsunit from "./DigestAlgorithm.test";
import SecurityRandomJsunit from "./SecurityRandom.test";
import SymmetricCryptographyJsunit from './SymmetricCryptography.test';
import AsymmetricCryptographyJsunit from './AsymmetricCryptography.test';
import AsymmetricCryptographyJsSecondunit from './AsymmetricCryptographySecond.test';
import DigestAlgorithmJsunit from './DigestAlgorithm.test';
import SecurityRandomJsunit from './SecurityRandom.test';
export default function testsuite() {
SymmetricCryptographyJsunit();
......
......@@ -16,18 +16,17 @@
import { describe, beforeAll, afterEach, it, expect } from "@ohos/hypium";
import { testSecurityRandomPromise } from "./utils/securityrandom/publicSecurityRandomPromise";
import {
testSecurityRandomCallback,
testSecurityRandomLengthCallback,
testSecurityRandomCallbackSeed,
} from "./utils/securityrandom/publicSecurityRandomCallback";
import { testSecurityRandomCallback } from "./utils/securityrandom/publicSecurityRandomCallback";
import { testSecurityRandomEnumCommon } from "./utils/securityrandom/publicSecurityRandomCommon";
import cryptoFramework from "@ohos.security.cryptoFramework";
export default function SecurityRandomJsunit() {
describe("SecurityRandomJsunit", function () {
console.info("##########start SecurityRandomJsunit##########");
beforeAll(function () {});
afterEach(function () {});
beforeAll(function () {
});
afterEach(function () {
});
/**
* @tc.number Security_crypto_framework_Random_0100
......@@ -63,68 +62,67 @@ export default function SecurityRandomJsunit() {
/**
* @tc.number Security_crypto_framework_Random_0300
* @tc.name Support generating safe random numbers and setting the length of random numbers
* @tc.desc use callback style of interface
* @tc.name Test generateRandom with invalid input
* @tc.desc First input 0, Second input null, Third input -1, Fourth input 2147483648
*/
it("Security_crypto_framework_Random_0300", 0, async function (done) {
await testSecurityRandomLengthCallback(0)
.then((data) => {
expect(data == null).assertTrue();
let randomGenerator = cryptoFramework.createRandom();
try {
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) => {
expect(null).assertFail();
});
await testSecurityRandomLengthCallback(-1)
.then((data) => {
expect(data == null).assertTrue();
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await randomGenerator.generateRandom(null);
} 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) => {
expect(null).assertFail();
});
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await randomGenerator.generateRandom(2147483648);
} catch (err) {
expect(err.code).assertEqual(401);
}
done();
});
/**
* @tc.number Security_crypto_framework_Random_0400
* @tc.name Support generating safe random numbers and setting random number seed exceptions
* @tc.desc use callback style of interface
* @tc.name Test setSeed with invalid input
* @tc.desc First input null, Second input 0
*/
it("Security_crypto_framework_Random_0400", 0, async function (done) {
await testSecurityRandomCallbackSeed(null)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
await testSecurityRandomCallbackSeed(0)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
await testSecurityRandomCallbackSeed(2147483647)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
let randomGenerator = cryptoFramework.createRandom();
try {
randomGenerator.setSeed(null);
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
randomGenerator.setSeed(0);
} catch (err) {
expect(err.code).assertEqual(401);
}
done();
});
......
......@@ -20,8 +20,10 @@ import * as symCallback from "./utils/symmetric/publicSymmetricCallback";
export default function SymmetricCryptographyJsunit() {
describe("SymmetricCryptographyJsunit", function () {
console.info("##########start SymmetricCryptographyJsunit##########");
beforeAll(function () {});
afterEach(function () {});
beforeAll(function () {
});
afterEach(function () {
});
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_AES_0100
......
......@@ -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) {
var globalRsaKeyPair;
......@@ -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) {
var globalCipherText;
var globalRsaKeyPair;
......@@ -714,7 +611,6 @@ async function encryptAndDecryptNormalProcessNull(asyAlgoName, cipherAlgoName) {
);
}
let decryptData = uInt8ArrayToString(finalOutput.data);
expect(decryptData == globalText).assertTrue();
reject();
})
.catch((err) => {
......@@ -730,11 +626,7 @@ export {
signAndVerifyNormalProcess,
convertKeyEncryptAndDecryptProcess,
keyAgreementProcess,
createAsyKeyAgreementFail,
keyAgreementProcessFail,
keyAgreementProcessParameterException,
createAsyKeyGeneratorFail,
encryptAndDecryptNormalProcessSuperdata,
signAndVerifyNormalProcessSuperdata,
encryptAndDecryptNormalProcessNull,
encryptAndDecryptNormalProcessNull
};
......@@ -15,11 +15,7 @@
import { expect } from "@ohos/hypium";
import cryptoFramework from "@ohos.security.cryptoFramework";
import {
stringTouInt8Array,
uInt8ArrayToShowStr,
uInt8ArrayToString,
} from "../common/publicDoString";
import { stringTouInt8Array, uInt8ArrayToShowStr, uInt8ArrayToString, } from "../common/publicDoString";
import {
createAsyKeyGenerator,
createAsyCipher,
......@@ -356,46 +352,36 @@ async function signAndVerifyNormalProcessDataException(asyAlgoName, signVerifyAl
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();
globalRsaKeyPair = rsaKeyPair;
return initSign(signGenerator, globalRsaKeyPair.priKey);
})
.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, globalRsaKeyPair.pubKey);
})
.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 {
......@@ -403,9 +389,9 @@ async function signAndVerifyNormalProcessDataException(asyAlgoName, signVerifyAl
}
})
.catch((err) => {
console.error("[promise] signAndVerifyNormalProcess catch err:" + err);
if (dataType =="null") {
resolve(err);
console.error("[promise] signAndVerifyNormalProcess catch err code:" + err.code);
if (dataType == "null") {
resolve(err.code);
} else {
reject(err);
}
......@@ -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 {
encryptAndDecryptNormalProcess,
signAndVerifyNormalProcess,
convertKeyEncryptAndDecryptProcess,
keyAgreementProcess,
AsyPriKeyClearProcess,
signAndVerifyNormalProcessDataException,
createAsyKeyGeneratorFail,
createAsySignFail,
createAsyVerifyFail,
signAndVerifyNormalProcessDataException
};
......@@ -14,11 +14,7 @@
*/
import { expect } from "@ohos/hypium";
import cryptoFramework from "@ohos.security.cryptoFramework";
import {
stringTouInt8Array,
uInt8ArrayToShowStr,
uInt8ArrayToString,
} from "../common/publicDoString";
import { stringTouInt8Array, uInt8ArrayToShowStr, uInt8ArrayToString, } from "../common/publicDoString";
async function generateSymKey(symKeyGenerator) {
return new Promise((resolve, reject) => {
......@@ -152,8 +148,8 @@ async function testMDDigestCallbackLen(MDAlgoName, DatablobLen) {
var globalMd;
var i;
var globalText;
var t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefhijklmnopqrstuvwxyz",n = t.length,s="";
for (i = 0; i < DatablobLen; i++){
var t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefhijklmnopqrstuvwxyz", n = t.length, s = "";
for (i = 0; i < DatablobLen; i++) {
globalText += t.charAt(Math.floor(Math.random() * n));
}
console.warn("Datablob = " + globalText);
......@@ -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) {
var globalMd;
......@@ -300,5 +260,10 @@ async function testHMACDigestCallback(HMACAlgoName, keyAlgoName) {
});
}
export { testMDDigestCallback, testHMACDigestCallback, testMDErrorAlgorithm,
testMDErrorAlgorithmNull, testMDDigestCallbackLen, testMDDigestCallbackLenNull };
export {
testMDDigestCallback,
testHMACDigestCallback,
testMDErrorAlgorithm,
testMDErrorAlgorithmNull,
testMDDigestCallbackLen
};
......@@ -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 {
testSecurityRandomCallback,
testSecurityRandomLengthCallback,
testSecurityRandomCallbackSeed,
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册