Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
c09d7d52
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看板
未验证
提交
c09d7d52
编写于
12月 16, 2022
作者:
O
openharmony_ci
提交者:
Gitee
12月 16, 2022
浏览文件
操作
浏览文件
下载
差异文件
!6942 【OpenHarmony 4.0.1.2】【安全子系统】【cryptoFramework】修改证书管理相关的接口
Merge pull request !6942 from Qwink2016/qwink1216
上级
0cc6c07a
539e8ddb
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
198 addition
and
281 deletion
+198
-281
security/cryptoFramework/js_api_test_two/Test.json
security/cryptoFramework/js_api_test_two/Test.json
+1
-0
security/cryptoFramework/js_api_test_two/src/main/js/test/Certificate.test.js
...work/js_api_test_two/src/main/js/test/Certificate.test.js
+3
-3
security/cryptoFramework/js_api_test_two/src/main/js/test/SecurityRandom.test.js
...k/js_api_test_two/src/main/js/test/SecurityRandom.test.js
+3
-5
security/cryptoFramework/js_api_test_two/src/main/js/test/utils/certificate/publicCertificateCallback.js
...in/js/test/utils/certificate/publicCertificateCallback.js
+62
-142
security/cryptoFramework/js_api_test_two/src/main/js/test/utils/certificate/publicCertificatePromise.js
...ain/js/test/utils/certificate/publicCertificatePromise.js
+50
-92
security/cryptoFramework/js_api_test_two/src/main/js/test/utils/securityrandom/publicSecurityRandomCallback.js
...test/utils/securityrandom/publicSecurityRandomCallback.js
+32
-14
security/cryptoFramework/js_api_test_two/src/main/js/test/utils/securityrandom/publicSecurityRandomCommon.js
...s/test/utils/securityrandom/publicSecurityRandomCommon.js
+46
-0
security/cryptoFramework/js_api_test_two/src/main/js/test/utils/securityrandom/publicSecurityRandomPromise.js
.../test/utils/securityrandom/publicSecurityRandomPromise.js
+1
-25
未找到文件。
security/cryptoFramework/js_api_test_two/Test.json
浏览文件 @
c09d7d52
...
...
@@ -4,6 +4,7 @@
"type"
:
"OHJSUnitTest"
,
"test-timeout"
:
"900000"
,
"shell-timeout"
:
"900000"
,
"testcase-timeout"
:
"60000"
,
"bundle-name"
:
"com.openharmony.cryptoFramework2"
,
"package-name"
:
"com.openharmony.cryptoFramework2"
},
...
...
security/cryptoFramework/js_api_test_two/src/main/js/test/Certificate.test.js
浏览文件 @
c09d7d52
...
...
@@ -246,7 +246,7 @@ export default function CertificateJsunit() {
await
certCallback
.
checkValidityX509CertCallback
(
"
der
"
,
"
20330830000000+0800
"
)
.
then
((
data
)
=>
{
expect
(
data
==
1
76
30004
).
assertTrue
();
expect
(
data
==
1
90
30004
).
assertTrue
();
})
.
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
...
...
@@ -264,7 +264,7 @@ export default function CertificateJsunit() {
await
certCallback
.
checkValidityX509CertCallback
(
"
der
"
,
"
NULL
"
)
.
then
((
data
)
=>
{
expect
(
data
==
1
76
30001
).
assertTrue
();
expect
(
data
==
1
90
30001
).
assertTrue
();
})
.
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
...
...
@@ -272,7 +272,7 @@ export default function CertificateJsunit() {
await
certCallback
.
checkValidityX509CertCallback
(
"
der
"
,
"
string
"
)
.
then
((
data
)
=>
{
expect
(
data
==
1
76
30001
).
assertTrue
();
expect
(
data
==
1
90
30001
).
assertTrue
();
})
.
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
...
...
security/cryptoFramework/js_api_test_two/src/main/js/test/SecurityRandom.test.js
浏览文件 @
c09d7d52
...
...
@@ -15,15 +15,13 @@
*/
import
{
describe
,
beforeAll
,
afterEach
,
it
,
expect
}
from
"
@ohos/hypium
"
;
import
{
testSecurityRandomPromise
,
testSecurityRandomEnumPromise
,
}
from
"
./utils/securityrandom/publicSecurityRandomPromise
"
;
import
{
testSecurityRandomPromise
}
from
"
./utils/securityrandom/publicSecurityRandomPromise
"
;
import
{
testSecurityRandomCallback
,
testSecurityRandomLengthCallback
,
testSecurityRandomCallbackSeed
,
}
from
"
./utils/securityrandom/publicSecurityRandomCallback
"
;
import
{
testSecurityRandomEnumCommon
}
from
"
./utils/securityrandom/publicSecurityRandomCommon
"
;
export
default
function
SecurityRandomJsunit
()
{
describe
(
"
SecurityRandomJsunit
"
,
function
()
{
...
...
@@ -136,7 +134,7 @@ export default function SecurityRandomJsunit() {
* @tc.desc cover 100% Enumerated values
*/
it
(
"
Security_crypto_framework_Random_0500
"
,
0
,
async
function
(
done
)
{
testSecurityRandomEnum
Promise
();
testSecurityRandomEnum
Common
();
done
();
});
});
...
...
security/cryptoFramework/js_api_test_two/src/main/js/test/utils/certificate/publicCertificateCallback.js
浏览文件 @
c09d7d52
...
...
@@ -15,6 +15,7 @@
import
{
expect
}
from
"
@ohos/hypium
"
;
import
cryptoFramework
from
"
@ohos.security.cryptoFramework
"
;
import
cert
from
"
@ohos.security.cert
"
;
import
{
stringTouInt8Array
,
uInt8ArrayToString
,
...
...
@@ -38,14 +39,14 @@ function createX509CertInstanceCallback(certType) {
var
encodingData
;
if
(
certType
==
"
der
"
)
{
certformat
=
c
ryptoFramework
.
EncodingFormat
.
FORMAT_DER
;
certformat
=
c
ert
.
EncodingFormat
.
FORMAT_DER
;
encodingData
=
new
Uint8Array
(
selfSignedCaCertDer
.
match
(
/
[\d
a-f
]{2}
/gi
).
map
(
function
(
h
)
{
return
parseInt
(
h
,
16
);
})
);
}
else
{
certformat
=
c
ryptoFramework
.
EncodingFormat
.
FORMAT_PEM
;
certformat
=
c
ert
.
EncodingFormat
.
FORMAT_PEM
;
encodingData
=
stringTouInt8Array
(
selfSignedCaCertPem
);
}
...
...
@@ -55,7 +56,7 @@ function createX509CertInstanceCallback(certType) {
};
return
new
Promise
((
resolve
,
reject
)
=>
{
c
ryptoFramework
.
createX509Cert
(
encodingBlob
,
(
err
,
data
)
=>
{
c
ert
.
createX509Cert
(
encodingBlob
,
(
err
,
data
)
=>
{
if
(
data
==
null
)
{
console
.
error
(
"
[callback] create X509 Cert failed! err code:
"
+
err
.
code
...
...
@@ -77,10 +78,10 @@ function createX509CertInstanceforCrlTestCallback(flag) {
var
invalidParams
=
false
;
if
(
flag
==
"
normal
"
)
{
certformat
=
c
ryptoFramework
.
EncodingFormat
.
FORMAT_PEM
;
certformat
=
c
ert
.
EncodingFormat
.
FORMAT_PEM
;
encodingData
=
stringTouInt8Array
(
testCert
);
}
else
if
(
flag
==
"
error
"
)
{
certformat
=
c
ryptoFramework
.
EncodingFormat
.
FORMAT_PEM
;
certformat
=
c
ert
.
EncodingFormat
.
FORMAT_PEM
;
encodingData
=
stringTouInt8Array
(
testErrorCert
);
}
else
{
invalidParams
=
true
;
...
...
@@ -92,7 +93,7 @@ function createX509CertInstanceforCrlTestCallback(flag) {
};
return
new
Promise
((
resolve
,
reject
)
=>
{
c
ryptoFramework
.
createX509Cert
(
encodingBlob
,
(
err
,
data
)
=>
{
c
ert
.
createX509Cert
(
encodingBlob
,
(
err
,
data
)
=>
{
if
(
data
==
null
)
{
console
.
error
(
"
[callback] create X509 Cert failed! err code:
"
+
err
.
code
...
...
@@ -112,22 +113,6 @@ function createX509CertInstanceforCrlTestCallback(flag) {
});
}
async
function
getX509CertPublicKey
(
certInstance
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
certInstance
.
getPublicKey
((
err
,
publicKey
)
=>
{
if
(
err
)
{
console
.
error
(
"
[Callback]getPublicKey failed. error is
"
+
err
);
reject
(
err
);
}
else
{
console
.
log
(
"
[Callback]getPublicKey success. publicKey is
"
+
publicKey
);
resolve
(
publicKey
);
}
});
});
}
async
function
verifyX509Cert
(
certInstance
,
pubKey
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
certInstance
.
verify
(
pubKey
,
(
err
)
=>
{
...
...
@@ -144,13 +129,12 @@ async function verifyX509Cert(certInstance, pubKey) {
async
function
verifyX509CertCallback
(
certType
,
flag
)
{
var
gInstance
;
var
pubKey
;
return
new
Promise
((
resolve
,
reject
)
=>
{
createX509CertInstanceCallback
(
certType
)
.
then
((
instance
)
=>
{
gInstance
=
instance
;
return
getX509CertPublicKey
(
gInstance
);
})
.
then
((
pubKey
)
=>
{
pubKey
=
gInstance
.
getPublicKey
();
expect
(
pubKey
!=
null
).
assertTrue
();
if
(
flag
!=
undefined
)
{
if
(
flag
==
"
wrong
"
)
{
...
...
@@ -177,31 +161,12 @@ async function verifyX509CertCallback(certType, flag) {
});
}
async
function
checkValidityWithDate
(
certInstance
,
date
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
certInstance
.
checkValidityWithDate
(
date
,
(
err
)
=>
{
if
(
err
)
{
console
.
error
(
"
[Callback]checkValidityWithDate failed. error is
"
+
err
);
reject
(
err
);
}
else
{
console
.
log
(
"
[Callback]checkValidityWithDate success!
"
);
resolve
();
}
});
});
}
async
function
checkValidityX509CertCallback
(
certType
,
date
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
createX509CertInstanceCallback
(
certType
)
.
then
((
instance
)
=>
{
return
checkValidityWithDate
(
instance
,
date
);
})
.
then
((
result
)
=>
{
console
.
warn
(
"
[callback] checkValidityX509Cert success!
"
);
resolve
(
result
);
instance
.
checkValidityWithDate
(
date
);
resolve
(
null
);
})
.
catch
((
err
)
=>
{
console
.
error
(
...
...
@@ -353,23 +318,14 @@ async function checkGetEncodedX509CertCallback(certType) {
}
async
function
checkGetPublicKeyX509CertCallback
(
certType
)
{
var
gInstance
;
var
publicKey
;
return
new
Promise
((
resolve
,
reject
)
=>
{
createX509CertInstanceCallback
(
certType
)
.
then
((
instance
)
=>
{
gInstance
=
instance
;
gInstance
.
getPublicKey
((
err
,
publicKey
)
=>
{
if
(
err
)
{
console
.
error
(
"
[callback] getPublicKey failed, err is:
"
+
err
);
reject
(
err
);
}
else
{
console
.
warn
(
"
[callback] getPublicKey success, publicKey is:
"
+
publicKey
);
expect
(
publicKey
!=
null
).
assertTrue
();
resolve
();
}
});
publicKey
=
instance
.
getPublicKey
();
console
.
warn
(
"
[callback] publicKey success, publicKey is:
"
+
publicKey
);
expect
(
publicKey
!=
null
).
assertTrue
();
resolve
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
[callback] getPublickey failed! error is:
"
+
err
);
...
...
@@ -383,14 +339,14 @@ function createX509CrlInstanceCallback(certType) {
var
encodingData
;
if
(
certType
==
"
der
"
)
{
certformat
=
c
ryptoFramework
.
EncodingFormat
.
FORMAT_DER
;
certformat
=
c
ert
.
EncodingFormat
.
FORMAT_DER
;
encodingData
=
new
Uint8Array
(
testCrlDer
.
match
(
/
[\d
a-f
]{2}
/gi
).
map
(
function
(
h
)
{
return
parseInt
(
h
,
16
);
})
);
}
else
{
certformat
=
c
ryptoFramework
.
EncodingFormat
.
FORMAT_PEM
;
certformat
=
c
ert
.
EncodingFormat
.
FORMAT_PEM
;
encodingData
=
stringTouInt8Array
(
testCrlPem
);
}
...
...
@@ -400,7 +356,7 @@ function createX509CrlInstanceCallback(certType) {
};
return
new
Promise
((
resolve
,
reject
)
=>
{
c
ryptoFramework
.
createX509Crl
(
encodingBlob
,
(
err
,
data
)
=>
{
c
ert
.
createX509Crl
(
encodingBlob
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
"
[callback] createX509Crl failed! error code is:
"
+
err
.
code
...
...
@@ -417,20 +373,13 @@ function createX509CrlInstanceCallback(certType) {
}
function
checkIsRevokedX509CrlCallback
(
crlInstance
,
flag
)
{
var
status
;
return
new
Promise
((
resolve
,
reject
)
=>
{
createX509CertInstanceforCrlTestCallback
(
flag
)
.
then
((
certInstance
)
=>
{
crlInstance
.
isRevoked
(
certInstance
,
(
err
,
status
)
=>
{
if
(
err
)
{
console
.
error
(
"
[callback] isRevoked failed! err code is:
"
+
err
.
code
);
reject
(
err
);
}
else
{
console
.
warn
(
"
[callback] isRevoked status is:
"
+
status
);
resolve
(
status
);
}
});
status
=
crlInstance
.
isRevoked
(
certInstance
);
console
.
warn
(
"
[callback] isRevoked status is:
"
+
status
);
resolve
(
status
);
})
.
catch
((
err
)
=>
{
console
.
error
(
"
[callback] isRevoked failed! err is:
"
+
err
);
...
...
@@ -512,7 +461,7 @@ function verifyX509CrlCallback(crlType, flag) {
var
globalCrlInstance
;
if
(
crlType
==
"
pem
"
||
crlType
==
"
der
"
)
{
certformat
=
c
ryptoFramework
.
EncodingFormat
.
FORMAT_DER
;
certformat
=
c
ert
.
EncodingFormat
.
FORMAT_DER
;
priKeyEncodingData
=
new
Uint8Array
(
crlVerifyPriKeyHex
.
match
(
/
[\d
a-f
]{2}
/gi
).
map
(
function
(
h
)
{
return
parseInt
(
h
,
16
);
...
...
@@ -544,7 +493,7 @@ function verifyX509CrlCallback(crlType, flag) {
var
asyKeyGenerator
=
cryptoFramework
.
createAsyKeyGenerator
(
"
RSA1024|PRIMES_3
"
);
expect
(
asyKeyGenerator
!=
null
).
assertTrue
();
c
ryptoFramework
c
ert
.
createX509Crl
(
crlEncodingBlob
)
.
then
((
crlInstance
)
=>
{
expect
(
crlInstance
!=
null
).
assertTrue
();
...
...
@@ -640,16 +589,11 @@ async function getX509CrlInfoCallback(certType, processType) {
expect
(
signatureAlgParams
!=
null
).
assertTrue
();
break
;
case
"
getTbsInfo
"
:
gInstance
.
getTbsInfo
((
err
,
tbsInfo
)
=>
{
if
(
err
)
{
console
.
error
(
"
[callback] getTbsInfo failed! error is:
"
+
err
);
reject
(
err
);
}
expect
(
tbsInfo
!=
null
).
assertTrue
();
console
.
log
(
processType
+
"
is :
"
+
uInt8ArrayToString
(
tbsInfo
.
data
)
);
});
let
tbsInfo
=
gInstance
.
getTbsInfo
();
console
.
log
(
processType
+
"
is :
"
+
uInt8ArrayToString
(
tbsInfo
.
data
)
);
expect
(
tbsInfo
!=
null
).
assertTrue
();
break
;
default
:
console
.
log
(
"
Invalid parameter !
"
);
...
...
@@ -664,32 +608,12 @@ async function getX509CrlInfoCallback(certType, processType) {
});
}
async
function
getRevokedCertWithCert
(
crlInstance
,
certInstance
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
crlInstance
.
getRevokedCertWithCert
(
certInstance
,
(
err
,
x509CrlEntry
)
=>
{
if
(
err
)
{
console
.
error
(
"
[Callback]getRevokedCertWithCert failed. error is
"
+
err
);
reject
(
err
);
}
else
{
console
.
log
(
"
[Callback]getRevokedCertWithCert success. x509CrlEntry is
"
+
x509CrlEntry
);
resolve
(
x509CrlEntry
);
}
});
});
}
function
checkGetRevokedCertWithCertX509CrlCallback
(
crlInstance
,
flag
)
{
var
x509CrlEntry
;
return
new
Promise
((
resolve
,
reject
)
=>
{
createX509CertInstanceforCrlTestCallback
(
flag
)
.
then
((
certInstance
)
=>
{
return
getRevokedCertWithCert
(
crlInstance
,
certInstance
);
})
.
then
((
x509CrlEntry
)
=>
{
x509CrlEntry
=
crlInstance
.
getRevokedCertWithCert
(
certInstance
);
expect
(
x509CrlEntry
!=
null
).
assertTrue
();
let
num
=
x509CrlEntry
.
getSerialNumber
();
console
.
warn
(
"
[num] getRevokedCertWithCert num is:
"
+
num
);
...
...
@@ -705,13 +629,12 @@ function checkGetRevokedCertWithCertX509CrlCallback(crlInstance, flag) {
}
async
function
checkGetRevokedCertsX509CrlCallback
(
certType
)
{
var
gInstance
;
var
gIndex
;
var
revocation
;
return
new
Promise
((
resolve
,
reject
)
=>
{
createX509CrlInstanceCallback
(
certType
)
.
then
((
instance
)
=>
{
gInstance
=
instance
;
gInstance
.
getRevokedCerts
((
err
,
certs
)
=>
{
instance
.
getRevokedCerts
((
err
,
certs
)
=>
{
expect
(
certs
!=
null
&&
certs
.
length
!=
0
).
assertTrue
();
console
.
warn
(
"
[callback] Crl get gevoked certs success
"
);
for
(
var
i
=
0
;
i
<
certs
.
length
;
i
++
)
{
...
...
@@ -722,20 +645,19 @@ async function checkGetRevokedCertsX509CrlCallback(certType) {
"
serialNumber is:
"
+
certs
[
gIndex
].
getSerialNumber
()
);
certs
[
gIndex
].
getRevocationDate
((
err1
,
revocation
)
=>
{
expect
(
revocation
!=
null
).
assertTrue
();
revocation
=
certs
[
gIndex
].
getRevocationDate
();
expect
(
revocation
!=
null
).
assertTrue
();
console
.
log
(
"
[callback] certs i:
"
+
gIndex
+
"
revocation date is:
"
+
revocation
);
certs
[
gIndex
].
getEncoded
((
err2
,
eData
)
=>
{
expect
(
eData
!=
null
).
assertTrue
();
console
.
log
(
"
[callback] certs i:
"
+
gIndex
+
"
revocation date is:
"
+
revocation
"
[callback] certs i:
"
+
gIndex
+
"
getEncoded is:
"
+
eData
);
certs
[
gIndex
].
getEncoded
((
err2
,
eData
)
=>
{
expect
(
eData
!=
null
).
assertTrue
();
console
.
log
(
"
[callback] certs i:
"
+
gIndex
+
"
getEncoded is:
"
+
eData
);
});
});
}
});
...
...
@@ -749,26 +671,24 @@ async function checkGetRevokedCertsX509CrlCallback(certType) {
}
async
function
checkGetRevokedCertX509CrlCallback
(
certType
)
{
var
gInstance
;
var
certIssuer
;
var
cert1
;
var
revocation
;
return
new
Promise
((
resolve
,
reject
)
=>
{
createX509CrlInstanceCallback
(
certType
)
.
then
((
instance
)
=>
{
gInstance
=
instance
;
gInstance
.
getRevokedCert
(
1
,
(
err
,
cert
)
=>
{
expect
(
cert
!=
null
).
assertTrue
();
console
.
warn
(
"
[callback] Crl get gevoked cert success
"
);
cert
.
getRevocationDate
((
err1
,
revocation
)
=>
{
expect
(
revocation
!=
null
).
assertTrue
();
console
.
log
(
"
[callback] cert revocation date is:
"
+
revocation
);
});
cert
.
getCertIssuer
((
err2
,
certIssuer
)
=>
{
expect
(
certIssuer
!=
null
).
assertTrue
();
console
.
log
(
"
[callback] cert certIssuer is:
"
+
uInt8ArrayToString
(
certIssuer
.
data
)
);
});
});
cert1
=
instance
.
getRevokedCert
(
1
);
expect
(
cert1
!=
null
).
assertTrue
();
console
.
warn
(
"
[callback] Crl get gevoked cert success
"
);
revocation
=
cert1
.
getRevocationDate
();
expect
(
revocation
!=
null
).
assertTrue
();
console
.
log
(
"
[callback] cert revocation date is:
"
+
revocation
);
certIssuer
=
cert1
.
getCertIssuer
();
expect
(
certIssuer
!=
null
).
assertTrue
();
console
.
log
(
"
[Callback] cert certIssuer is:
"
+
+
uInt8ArrayToString
(
certIssuer
.
data
)
);
resolve
();
})
.
catch
((
err
)
=>
{
...
...
@@ -781,7 +701,7 @@ async function checkGetRevokedCertX509CrlCallback(certType) {
function
checkValidateOfCertChainValidatorCallback
(
algName
,
flag
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
try
{
var
validator
=
c
ryptoFramework
.
createCertChainValidator
(
algName
);
var
validator
=
c
ert
.
createCertChainValidator
(
algName
);
var
algorithm
=
validator
.
algorithm
;
console
.
log
(
"
createCertChainValidator success! algorithm is:
"
+
algorithm
...
...
@@ -835,7 +755,7 @@ function checkValidateOfCertChainValidatorCallback(algName, flag) {
var
certChainData
=
{
data
:
dataArray
,
count
:
2
,
encodingFormat
:
c
ryptoFramework
.
EncodingFormat
.
FORMAT_PEM
,
encodingFormat
:
c
ert
.
EncodingFormat
.
FORMAT_PEM
,
};
console
.
log
(
"
certChainData.data is:
"
+
certChainData
.
data
);
validator
.
validate
(
certChainData
,
(
err
)
=>
{
...
...
security/cryptoFramework/js_api_test_two/src/main/js/test/utils/certificate/publicCertificatePromise.js
浏览文件 @
c09d7d52
...
...
@@ -15,6 +15,7 @@
import
{
expect
}
from
"
@ohos/hypium
"
;
import
cryptoFramework
from
"
@ohos.security.cryptoFramework
"
;
import
cert
from
"
@ohos.security.cert
"
;
import
{
stringTouInt8Array
,
uInt8ArrayToString
,
...
...
@@ -38,14 +39,14 @@ function createX509CertInstancePromise(certType) {
var
encodingData
;
if
(
certType
==
"
der
"
)
{
certformat
=
c
ryptoFramework
.
EncodingFormat
.
FORMAT_DER
;
certformat
=
c
ert
.
EncodingFormat
.
FORMAT_DER
;
encodingData
=
new
Uint8Array
(
selfSignedCaCertDer
.
match
(
/
[\d
a-f
]{2}
/gi
).
map
(
function
(
h
)
{
return
parseInt
(
h
,
16
);
})
);
}
else
{
certformat
=
c
ryptoFramework
.
EncodingFormat
.
FORMAT_PEM
;
certformat
=
c
ert
.
EncodingFormat
.
FORMAT_PEM
;
encodingData
=
stringTouInt8Array
(
selfSignedCaCertPem
);
}
...
...
@@ -55,7 +56,7 @@ function createX509CertInstancePromise(certType) {
};
return
new
Promise
((
resolve
,
reject
)
=>
{
c
ryptoFramework
c
ert
.
createX509Cert
(
encodingBlob
)
.
then
((
data
)
=>
{
console
.
warn
(
...
...
@@ -78,10 +79,10 @@ function createX509CertInstanceforCrlTestPromise(flag) {
var
invalidParams
=
false
;
if
(
flag
==
"
normal
"
)
{
certformat
=
c
ryptoFramework
.
EncodingFormat
.
FORMAT_PEM
;
certformat
=
c
ert
.
EncodingFormat
.
FORMAT_PEM
;
encodingData
=
stringTouInt8Array
(
testCert
);
}
else
if
(
flag
==
"
error
"
)
{
certformat
=
c
ryptoFramework
.
EncodingFormat
.
FORMAT_PEM
;
certformat
=
c
ert
.
EncodingFormat
.
FORMAT_PEM
;
encodingData
=
stringTouInt8Array
(
testErrorCert
);
}
else
{
invalidParams
=
true
;
...
...
@@ -93,7 +94,7 @@ function createX509CertInstanceforCrlTestPromise(flag) {
};
return
new
Promise
((
resolve
,
reject
)
=>
{
c
ryptoFramework
c
ert
.
createX509Cert
(
encodingBlob
)
.
then
((
data
)
=>
{
console
.
warn
(
...
...
@@ -116,13 +117,12 @@ function createX509CertInstanceforCrlTestPromise(flag) {
async
function
verifyX509CertPromise
(
certType
,
flag
)
{
var
gInstance
;
var
publicKey
;
return
new
Promise
((
resolve
,
reject
)
=>
{
createX509CertInstancePromise
(
certType
)
.
then
((
instance
)
=>
{
gInstance
=
instance
;
return
gInstance
.
getPublicKey
();
})
.
then
((
publicKey
)
=>
{
publicKey
=
gInstance
.
getPublicKey
();
expect
(
publicKey
!=
null
).
assertTrue
();
console
.
log
(
"
[promise] getPublickey success!
"
);
if
(
flag
!=
undefined
)
{
...
...
@@ -149,15 +149,11 @@ async function verifyX509CertPromise(certType, flag) {
}
async
function
checkValidityX509CertPromise
(
certType
,
date
)
{
var
gInstance
;
var
result
;
return
new
Promise
((
resolve
,
reject
)
=>
{
createX509CertInstancePromise
(
certType
)
.
then
((
instance
)
=>
{
gInstance
=
instance
;
return
gInstance
.
checkValidityWithDate
(
date
);
})
.
then
((
result
)
=>
{
console
.
warn
(
"
[promise] checkValidityX509Cert success!
"
);
result
=
instance
.
checkValidityWithDate
(
date
);
resolve
(
result
);
})
.
catch
((
err
)
=>
{
...
...
@@ -304,14 +300,11 @@ async function checkGetEncodedX509CertPromise(certType) {
}
async
function
checkGetPublicKeyX509CertPromise
(
certType
)
{
var
gInstance
;
var
publicKey
;
return
new
Promise
((
resolve
,
reject
)
=>
{
createX509CertInstancePromise
(
certType
)
.
then
((
instance
)
=>
{
gInstance
=
instance
;
return
gInstance
.
getPublicKey
();
})
.
then
((
publicKey
)
=>
{
publicKey
=
instance
.
getPublicKey
();
console
.
warn
(
"
[promise] publicKey success, publicKey is:
"
+
publicKey
);
expect
(
publicKey
!=
null
).
assertTrue
();
resolve
();
...
...
@@ -328,14 +321,14 @@ function createX509CrlInstancePromise(certType) {
var
encodingData
;
if
(
certType
==
"
der
"
)
{
certformat
=
c
ryptoFramework
.
EncodingFormat
.
FORMAT_DER
;
certformat
=
c
ert
.
EncodingFormat
.
FORMAT_DER
;
encodingData
=
new
Uint8Array
(
testCrlDer
.
match
(
/
[\d
a-f
]{2}
/gi
).
map
(
function
(
h
)
{
return
parseInt
(
h
,
16
);
})
);
}
else
{
certformat
=
c
ryptoFramework
.
EncodingFormat
.
FORMAT_PEM
;
certformat
=
c
ert
.
EncodingFormat
.
FORMAT_PEM
;
encodingData
=
stringTouInt8Array
(
testCrlPem
);
}
...
...
@@ -345,7 +338,7 @@ function createX509CrlInstancePromise(certType) {
};
return
new
Promise
((
resolve
,
reject
)
=>
{
c
ryptoFramework
c
ert
.
createX509Crl
(
encodingBlob
)
.
then
((
data
)
=>
{
console
.
warn
(
...
...
@@ -363,13 +356,11 @@ function createX509CrlInstancePromise(certType) {
}
function
checkIsRevokedX509CrlPromise
(
crlInstance
,
flag
)
{
var
status
;
return
new
Promise
((
resolve
,
reject
)
=>
{
createX509CertInstanceforCrlTestPromise
(
flag
)
.
then
((
certInstance
)
=>
{
let
status
=
crlInstance
.
isRevoked
(
certInstance
);
return
status
;
})
.
then
((
status
)
=>
{
status
=
crlInstance
.
isRevoked
(
certInstance
);
console
.
warn
(
"
[promise] isRevoked status is:
"
+
status
);
resolve
(
status
);
})
...
...
@@ -413,7 +404,7 @@ function verifyX509CrlPromise(crlType, flag) {
var
crlEncodingData
;
var
globalCrlInstance
;
if
(
crlType
==
"
pem
"
||
crlType
==
"
der
"
)
{
certFormat
=
c
ryptoFramework
.
EncodingFormat
.
FORMAT_DER
;
certFormat
=
c
ert
.
EncodingFormat
.
FORMAT_DER
;
priKeyEncodingData
=
new
Uint8Array
(
crlVerifyPriKeyHex
.
match
(
/
[\d
a-f
]{2}
/gi
).
map
(
function
(
h
)
{
return
parseInt
(
h
,
16
);
...
...
@@ -446,7 +437,7 @@ function verifyX509CrlPromise(crlType, flag) {
var
asyKeyGenerator
=
cryptoFramework
.
createAsyKeyGenerator
(
"
RSA1024|PRIMES_3
"
);
expect
(
asyKeyGenerator
!=
null
);
c
ryptoFramework
c
ert
.
createX509Crl
(
crlEncodingBlob
)
.
then
((
crlInstance
)
=>
{
expect
(
crlInstance
!=
null
).
assertTrue
();
...
...
@@ -542,18 +533,11 @@ async function getX509CrlInfoPromise(certType, processType) {
expect
(
signatureAlgParams
!=
null
).
assertTrue
();
break
;
case
"
getTbsInfo
"
:
gInstance
.
getTbsInfo
()
.
then
((
tbsInfo
)
=>
{
expect
(
tbsInfo
!=
null
).
assertTrue
();
console
.
log
(
processType
+
"
is :
"
+
uInt8ArrayToString
(
tbsInfo
.
data
)
);
})
.
catch
((
err
)
=>
{
console
.
error
(
"
[promise] getTbsInfo failed! error is:
"
+
err
);
reject
(
err
);
});
let
tbsInfo
=
gInstance
.
getTbsInfo
();
console
.
log
(
processType
+
"
is :
"
+
uInt8ArrayToString
(
tbsInfo
.
data
)
);
expect
(
tbsInfo
!=
null
).
assertTrue
();
break
;
default
:
console
.
log
(
"
Invalid parameter !
"
);
...
...
@@ -573,9 +557,6 @@ function checkGetRevokedCertWithCertX509CrlPromise(crlInstance, flag) {
createX509CertInstanceforCrlTestPromise
(
flag
)
.
then
((
certInstance
)
=>
{
let
crlEntry
=
crlInstance
.
getRevokedCertWithCert
(
certInstance
);
return
crlEntry
;
})
.
then
((
crlEntry
)
=>
{
console
.
warn
(
"
[promise] getRevokedCertWithCert is:
"
+
crlEntry
);
let
num
=
crlEntry
.
getSerialNumber
();
console
.
warn
(
"
[promise] getRevokedCertWithCert num is:
"
+
num
);
...
...
@@ -589,13 +570,12 @@ function checkGetRevokedCertWithCertX509CrlPromise(crlInstance, flag) {
}
async
function
checkGetRevokedCertsX509CrlPromise
(
certType
)
{
var
gInstance
;
var
gIndex
;
var
revocation
;
return
new
Promise
((
resolve
,
reject
)
=>
{
createX509CrlInstancePromise
(
certType
)
.
then
((
instance
)
=>
{
gInstance
=
instance
;
return
gInstance
.
getRevokedCerts
();
return
instance
.
getRevokedCerts
();
})
.
then
((
certs
)
=>
{
expect
(
certs
!=
null
&&
certs
.
length
!=
0
).
assertTrue
();
...
...
@@ -608,20 +588,14 @@ async function checkGetRevokedCertsX509CrlPromise(certType) {
"
serialNumber is:
"
+
certs
[
gIndex
].
getSerialNumber
()
);
certs
[
gIndex
]
.
getRevocationDate
()
.
then
((
revocation
)
=>
{
expect
(
revocation
!=
null
).
assertTrue
();
console
.
log
(
"
[Promise] certs i:
"
+
gIndex
+
"
revocation date is:
"
+
revocation
);
})
.
catch
((
err
)
=>
{
reject
(
err
);
});
revocation
=
certs
[
gIndex
].
getRevocationDate
();
expect
(
revocation
!=
null
).
assertTrue
();
console
.
log
(
"
[Promise] certs i:
"
+
gIndex
+
"
revocation date is:
"
+
revocation
);
certs
[
gIndex
]
.
getEncoded
()
.
then
((
eData
)
=>
{
...
...
@@ -647,39 +621,23 @@ async function checkGetRevokedCertsX509CrlPromise(certType) {
}
async
function
checkGetRevokedCertX509CrlPromise
(
certType
)
{
var
gInstance
;
var
certIssuer
;
var
revocation
;
return
new
Promise
((
resolve
,
reject
)
=>
{
createX509CrlInstancePromise
(
certType
)
.
then
((
instance
)
=>
{
gInstance
=
instance
;
return
gInstance
.
getRevokedCert
(
1
);
})
.
then
((
cert
)
=>
{
expect
(
cert
!=
null
).
assertTrue
();
let
cert1
=
instance
.
getRevokedCert
(
1
);
expect
(
cert1
!=
null
).
assertTrue
();
console
.
warn
(
"
[Promise] Crl get gevoked certs success
"
);
cert
.
getRevocationDate
()
.
then
((
revocation
)
=>
{
expect
(
revocation
!=
null
).
assertTrue
();
console
.
log
(
"
[Promise] cert revocation date is:
"
+
revocation
);
})
.
catch
((
err
)
=>
{
console
.
error
(
"
[Promise] cert revocation date is:
"
+
err
);
reject
(
err
);
});
cert
.
getCertIssuer
()
.
then
((
certIssuer
)
=>
{
expect
(
certIssuer
!=
null
).
assertTrue
();
console
.
log
(
"
[Promise] cert certIssuer is:
"
+
+
uInt8ArrayToString
(
certIssuer
.
data
)
);
})
.
catch
((
err
)
=>
{
console
.
error
(
"
[Promise] cert certIssuer is:
"
+
err
);
reject
(
err
);
});
revocation
=
cert1
.
getRevocationDate
();
expect
(
revocation
!=
null
).
assertTrue
();
console
.
log
(
"
[Promise] cert revocation date is:
"
+
revocation
);
certIssuer
=
cert1
.
getCertIssuer
();
expect
(
certIssuer
!=
null
).
assertTrue
();
console
.
log
(
"
[Promise] cert certIssuer is:
"
+
+
uInt8ArrayToString
(
certIssuer
.
data
)
);
resolve
();
})
.
catch
((
err
)
=>
{
...
...
@@ -692,7 +650,7 @@ async function checkGetRevokedCertX509CrlPromise(certType) {
function
checkValidateOfCertChainValidatorPromise
(
algName
,
flag
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
try
{
var
validator
=
c
ryptoFramework
.
createCertChainValidator
(
algName
);
var
validator
=
c
ert
.
createCertChainValidator
(
algName
);
var
algorithm
=
validator
.
algorithm
;
console
.
log
(
"
createCertChainValidator success! algorithm is:
"
+
algorithm
...
...
@@ -746,7 +704,7 @@ function checkValidateOfCertChainValidatorPromise(algName, flag) {
var
certChainData
=
{
data
:
dataArray
,
count
:
2
,
encodingFormat
:
c
ryptoFramework
.
EncodingFormat
.
FORMAT_PEM
,
encodingFormat
:
c
ert
.
EncodingFormat
.
FORMAT_PEM
,
};
console
.
log
(
"
certChainData.data is:
"
+
certChainData
.
data
);
validator
...
...
security/cryptoFramework/js_api_test_two/src/main/js/test/utils/securityrandom/publicSecurityRandomCallback.js
浏览文件 @
c09d7d52
...
...
@@ -35,13 +35,12 @@ async function testSecurityRandomCallback(length) {
console
.
log
(
"
[callback] rand result first:
"
+
uInt8ArrayToShowStr
(
randData
.
data
)
);
}
rand
.
setSeed
(
randData
,
(
err1
)
=>
{
if
(
err1
)
{
console
.
error
(
"
[callback]setSeed catch err:
"
+
err1
);
try
{
rand
.
setSeed
(
randData
);
}
catch
(
err1
)
{
reject
(
err1
);
}
}
);
}
});
rand
.
generateRandom
(
length
,
(
err
,
randData
)
=>
{
...
...
@@ -64,10 +63,15 @@ async function testSecurityRandomLengthCallback(length) {
return
new
Promise
((
resolve
,
reject
)
=>
{
rand
=
cryptoFramework
.
createRandom
();
expect
(
rand
!=
null
).
assertTrue
();
if
(
length
!=
null
)
{
if
(
length
!=
null
)
{
rand
.
generateRandom
(
length
,
(
err
,
randData
)
=>
{
if
(
err
)
{
console
.
error
(
"
[callback]generateRandom catch error:
"
+
err
+
"
[callback]: error code:
"
+
err
.
code
);
console
.
error
(
"
[callback]generateRandom catch error:
"
+
err
+
"
[callback]: error code:
"
+
err
.
code
);
expect
(
err
.
code
==
401
).
assertTrue
();
resolve
();
}
else
{
...
...
@@ -76,31 +80,45 @@ async function testSecurityRandomLengthCallback(length) {
}
});
}
else
{
try
{
try
{
rand
.
generateRandom
(
length
);
reject
();
}
catch
(
error
)
{
console
.
error
(
"
[callback]generateRandom catch err1:
"
+
error
+
"
[callback]: error code:
"
+
error
.
code
);
console
.
error
(
"
[callback]generateRandom catch err1:
"
+
error
+
"
[callback]: error code:
"
+
error
.
code
);
resolve
();
}
}
});
}
async
function
testSecurityRandomCallbackSeed
(
length
)
{
async
function
testSecurityRandomCallbackSeed
(
data
)
{
var
rand
;
return
new
Promise
((
resolve
,
reject
)
=>
{
rand
=
cryptoFramework
.
createRandom
();
expect
(
rand
!=
null
).
assertTrue
();
try
{
rand
.
setSeed
(
length
);
try
{
rand
.
setSeed
(
data
);
reject
();
}
catch
(
error
)
{
console
.
error
(
"
[callback]setSeed catch err:
"
+
error
+
"
[callback]: error code:
"
+
error
.
code
);
console
.
error
(
"
[callback]setSeed catch err:
"
+
error
+
"
[callback]: error code:
"
+
error
.
code
);
expect
(
error
.
code
==
401
).
assertTrue
();
resolve
();
}
});
}
export
{
testSecurityRandomCallback
,
testSecurityRandomLengthCallback
,
testSecurityRandomCallbackSeed
};
export
{
testSecurityRandomCallback
,
testSecurityRandomLengthCallback
,
testSecurityRandomCallbackSeed
,
};
security/cryptoFramework/js_api_test_two/src/main/js/test/utils/securityrandom/publicSecurityRandomCommon.js
0 → 100644
浏览文件 @
c09d7d52
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
{
expect
}
from
"
@ohos/hypium
"
;
import
cryptoFramework
from
"
@ohos.security.cryptoFramework
"
;
import
cert
from
"
@ohos.security.cert
"
;
function
testSecurityRandomEnumCommon
()
{
expect
(
401
).
assertEqual
(
cryptoFramework
.
Result
.
INVALID_PARAMS
);
expect
(
401
).
assertEqual
(
cert
.
CertResult
.
INVALID_PARAMS
);
expect
(
801
).
assertEqual
(
cryptoFramework
.
Result
.
NOT_SUPPORT
);
expect
(
801
).
assertEqual
(
cert
.
CertResult
.
NOT_SUPPORT
);
expect
(
17620001
).
assertEqual
(
cryptoFramework
.
Result
.
ERR_OUT_OF_MEMORY
);
expect
(
19020001
).
assertEqual
(
cert
.
CertResult
.
ERR_OUT_OF_MEMORY
);
expect
(
17620002
).
assertEqual
(
cryptoFramework
.
Result
.
ERR_RUNTIME_ERROR
);
expect
(
19020002
).
assertEqual
(
cert
.
CertResult
.
ERR_RUNTIME_ERROR
);
expect
(
17630001
).
assertEqual
(
cryptoFramework
.
Result
.
ERR_CRYPTO_OPERATION
);
expect
(
19030001
).
assertEqual
(
cert
.
CertResult
.
ERR_CRYPTO_OPERATION
);
expect
(
19030002
).
assertEqual
(
cert
.
CertResult
.
ERR_CERT_SIGNATURE_FAILURE
);
expect
(
19030003
).
assertEqual
(
cert
.
CertResult
.
ERR_CERT_NOT_YET_VALID
);
expect
(
19030004
).
assertEqual
(
cert
.
CertResult
.
ERR_CERT_HAS_EXPIRED
);
expect
(
19030005
).
assertEqual
(
cert
.
CertResult
.
ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY
);
expect
(
19030006
).
assertEqual
(
cert
.
CertResult
.
ERR_KEYUSAGE_NO_CERTSIGN
);
expect
(
19030007
).
assertEqual
(
cert
.
CertResult
.
ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE
);
expect
(
0
).
assertEqual
(
cert
.
EncodingFormat
.
FORMAT_DER
);
expect
(
1
).
assertEqual
(
cert
.
EncodingFormat
.
FORMAT_PEM
);
expect
(
0
).
assertEqual
(
cryptoFramework
.
CryptoMode
.
ENCRYPT_MODE
);
expect
(
1
).
assertEqual
(
cryptoFramework
.
CryptoMode
.
DECRYPT_MODE
);
}
export
{
testSecurityRandomEnumCommon
};
security/cryptoFramework/js_api_test_two/src/main/js/test/utils/securityrandom/publicSecurityRandomPromise.js
浏览文件 @
c09d7d52
...
...
@@ -60,28 +60,4 @@ async function testSecurityRandomPromise(length) {
});
}
function
testSecurityRandomEnumPromise
()
{
expect
(
401
).
assertEqual
(
cryptoFramework
.
Result
.
INVALID_PARAMS
);
expect
(
801
).
assertEqual
(
cryptoFramework
.
Result
.
NOT_SUPPORT
);
expect
(
17620001
).
assertEqual
(
cryptoFramework
.
Result
.
ERR_OUT_OF_MEMORY
);
expect
(
17620002
).
assertEqual
(
cryptoFramework
.
Result
.
ERR_RUNTIME_ERROR
);
expect
(
17630001
).
assertEqual
(
cryptoFramework
.
Result
.
ERR_CRYPTO_OPERATION
);
expect
(
17630002
).
assertEqual
(
cryptoFramework
.
Result
.
ERR_CERT_SIGNATURE_FAILURE
);
expect
(
17630003
).
assertEqual
(
cryptoFramework
.
Result
.
ERR_CERT_NOT_YET_VALID
);
expect
(
17630004
).
assertEqual
(
cryptoFramework
.
Result
.
ERR_CERT_HAS_EXPIRED
);
expect
(
17630005
).
assertEqual
(
cryptoFramework
.
Result
.
ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY
);
expect
(
17630006
).
assertEqual
(
cryptoFramework
.
Result
.
ERR_KEYUSAGE_NO_CERTSIGN
);
expect
(
17630007
).
assertEqual
(
cryptoFramework
.
Result
.
ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE
);
expect
(
0
).
assertEqual
(
cryptoFramework
.
EncodingFormat
.
FORMAT_DER
);
expect
(
1
).
assertEqual
(
cryptoFramework
.
EncodingFormat
.
FORMAT_PEM
);
expect
(
0
).
assertEqual
(
cryptoFramework
.
CryptoMode
.
ENCRYPT_MODE
);
expect
(
1
).
assertEqual
(
cryptoFramework
.
CryptoMode
.
DECRYPT_MODE
);
}
export
{
testSecurityRandomPromise
,
testSecurityRandomEnumPromise
};
export
{
testSecurityRandomPromise
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录