Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
9c3aceab
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
9c3aceab
编写于
6月 06, 2023
作者:
O
openharmony_ci
提交者:
Gitee
6月 06, 2023
浏览文件
操作
浏览文件
下载
差异文件
!8914 【OpenHarmony 4.0.7.2】【安全子系统】【master】XTS Failure Case Maintenance
Merge pull request !8914 from qiaozzzh/0605_1
上级
dffe1b26
c7380059
变更
10
展开全部
显示空白变更内容
内联
并排
Showing
10 changed file
with
3421 addition
and
3665 deletion
+3421
-3665
security/cryptoFramework/js_api_test_one/src/main/js/test/AsymmetricCryptography.test.js
..._test_one/src/main/js/test/AsymmetricCryptography.test.js
+625
-623
security/cryptoFramework/js_api_test_one/src/main/js/test/AsymmetricCryptographySecond.test.js
...one/src/main/js/test/AsymmetricCryptographySecond.test.js
+748
-723
security/cryptoFramework/js_api_test_one/src/main/js/test/DigestAlgorithm.test.js
.../js_api_test_one/src/main/js/test/DigestAlgorithm.test.js
+303
-283
security/cryptoFramework/js_api_test_one/src/main/js/test/List.test.js
...toFramework/js_api_test_one/src/main/js/test/List.test.js
+5
-5
security/cryptoFramework/js_api_test_one/src/main/js/test/SecurityRandom.test.js
...k/js_api_test_one/src/main/js/test/SecurityRandom.test.js
+107
-109
security/cryptoFramework/js_api_test_one/src/main/js/test/SymmetricCryptography.test.js
...i_test_one/src/main/js/test/SymmetricCryptography.test.js
+999
-997
security/cryptoFramework/js_api_test_one/src/main/js/test/utils/asymmetric/publicAsymmetricCallback.js
...main/js/test/utils/asymmetric/publicAsymmetricCallback.js
+1
-109
security/cryptoFramework/js_api_test_one/src/main/js/test/utils/asymmetric/publicAsymmetricPromise.js
.../main/js/test/utils/asymmetric/publicAsymmetricPromise.js
+428
-515
security/cryptoFramework/js_api_test_one/src/main/js/test/utils/digestalgorithm/publicDigestCallback.js
...ain/js/test/utils/digestalgorithm/publicDigestCallback.js
+205
-240
security/cryptoFramework/js_api_test_one/src/main/js/test/utils/securityrandom/publicSecurityRandomCallback.js
...test/utils/securityrandom/publicSecurityRandomCallback.js
+0
-61
未找到文件。
security/cryptoFramework/js_api_test_one/src/main/js/test/AsymmetricCryptography.test.js
浏览文件 @
9c3aceab
...
@@ -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
security/cryptoFramework/js_api_test_one/src/main/js/test/AsymmetricCryptographySecond.test.js
浏览文件 @
9c3aceab
此差异已折叠。
点击以展开。
security/cryptoFramework/js_api_test_one/src/main/js/test/DigestAlgorithm.test.js
浏览文件 @
9c3aceab
...
@@ -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
();
});
});
...
...
security/cryptoFramework/js_api_test_one/src/main/js/test/List.test.js
浏览文件 @
9c3aceab
security/cryptoFramework/js_api_test_one/src/main/js/test/SecurityRandom.test.js
浏览文件 @
9c3aceab
...
@@ -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
();
});
});
...
...
security/cryptoFramework/js_api_test_one/src/main/js/test/SymmetricCryptography.test.js
浏览文件 @
9c3aceab
...
@@ -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
...
...
security/cryptoFramework/js_api_test_one/src/main/js/test/utils/asymmetric/publicAsymmetricCallback.js
浏览文件 @
9c3aceab
...
@@ -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
};
};
security/cryptoFramework/js_api_test_one/src/main/js/test/utils/asymmetric/publicAsymmetricPromise.js
浏览文件 @
9c3aceab
...
@@ -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
,
};
};
security/cryptoFramework/js_api_test_one/src/main/js/test/utils/digestalgorithm/publicDigestCallback.js
浏览文件 @
9c3aceab
...
@@ -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
};
security/cryptoFramework/js_api_test_one/src/main/js/test/utils/securityrandom/publicSecurityRandomCallback.js
浏览文件 @
9c3aceab
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录