证书算法库v1.0测试代码

Signed-off-by: haixiangw <wanghaixiang@huawei.com>
This commit is contained in:
haixiangw 2023-09-12 02:38:57 -07:00
parent 26e8fdb314
commit 0a03cde890
9 changed files with 1997 additions and 34 deletions

View File

@ -29,8 +29,10 @@ group("certificate_framework_fuzztest") {
deps = []
if (os_level == "standard") {
deps += [
"test/fuzztest/cfgetandcheck_fuzzer:fuzztest",
"test/fuzztest/cfcreate_fuzzer:fuzztest",
"test/fuzztest/cfgetandcheck_fuzzer:fuzztest",
"test/fuzztest/v1.0/x509certificate_fuzzer:fuzztest",
"test/fuzztest/v1.0/x509crl_fuzzer:fuzztest",
]
}
}

View File

@ -42,43 +42,39 @@ namespace OHOS {
static char g_testCrl[] =
"-----BEGIN X509 CRL-----\r\n"
"MIIB/DCB5QIBATANBgkqhkiG9w0BAQsFADCBjDELMAkGA1UEBhMCQ04xETAPBgNV\r\n"
"BAgMCHNoYW5naGFpMQ8wDQYDVQQHDAZodWF3ZWkxFTATBgNVBAoMDHd3dy50ZXN0\r\n"
"LmNvbTENMAsGA1UECwwEdGVzdDEVMBMGA1UEAwwMd3d3LnRlc3QuY29tMRwwGgYJ\r\n"
"KoZIhvcNAQkBFg10ZXN0QHRlc3QuY29tFw0yMjA4MjkwNzAwMTRaFw0yMjA5Mjgw\r\n"
"NzAwMTRaMBQwEgIBARcNMjIwODI5MDY1OTUzWqAOMAwwCgYDVR0UBAMCAQAwDQYJ\r\n"
"KoZIhvcNAQELBQADggEBAHpfFhhUR59OAvOSuKDQUC5tKeLEuPbY8bYdmQVI8EFd\r\n"
"xDkZTXmT3CX1aDPYKVsG/jH9KPAmCV/ODKEGiJzclb3Z4am7tT+Wy4mpXypNS1od\r\n"
"wPDcQGsMrjT6iSp6JImiB0dDDSleBTBcYR/hhtFaiGSncyqJ0mhyaXPxIkNOO6nY\r\n"
"v+rcTEPQWavViDRyNDhnTbN868I3fzFVBcidF13CA0sCJ91ZvsE9h/YmPO2+e0YE\r\n"
"IUgzn37UOiL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"i4GQKaFbmEpdNyNkvB4wHwYDVR0jBBgwFoAUIisY3oTZME72Pd/X9ALtRCKEIOgw\r\n"
"DQYJKoZIhvcNAQELBQADggEBAKVdgTE4Q8Nl5nQUQVL/uZMVCmDRcpXdJHq3cyAH\r\n"
"4BtbFW/K3MbVcZl2j1tPl6bgI5pn9Tk4kkc+SfxGUKAPR7FQ01zfgEJipSlsmAxS\r\n"
"wOZL+PGUbYUL1jzU8207PZOIZcyD67Sj8LeOV4BCNLiBIo++MjpD++x77GnP3veg\r\n"
"bDKHfDSVILdH/qnqyGSAGJ4YGJld00tehnTAqBWzmkXVIgWk0bnPTNE0dn5Tj7ZY\r\n"
"7zh6YU5JILHnrkjRGdNGmpz8SXJ+bh7u8ffHc4R9FO1q4c9/1YSsOXQj0KazyDIP\r\n"
"IArlydFj8wK8sHvYC9WhPs+hiirrRb9Y2ApFzcYX5aYn46Y=\r\n"
"-----END CERTIFICATE-----\r\n";
static void FreeCrlData()

View File

@ -17,5 +17,6 @@ group("cf_test") {
"cf_adapter_test:cf_adapter_test",
"cf_core_test:cf_core_test",
"cf_sdk_test:cf_sdk_test",
"v1.0:cf_version1_test",
]
}

View File

@ -0,0 +1,75 @@
# Copyright (c) 2023 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("//build/test.gni")
module_output_path = "certificate_framework/certificate_framework_test"
ohos_unittest("cf_version1_test") {
testonly = true
module_out_path = module_output_path
configs = [
"../../../config/build:coverage_flag",
"../../../config/build:coverage_flag_cc",
]
include_dirs = [
"./include",
"../../../interfaces/innerkits/certificate",
"../../../interfaces/innerkits/common",
"../../../interfaces/innerkits/include",
"../../../frameworks/common/v1.0/inc",
"../../../frameworks/core/v1.0/spi",
"../../../frameworks/adapter/v1.0/inc",
"//third_party/openssl/include/",
]
sources = [
"src/crypto_x509_cert_chain_validator_test.cpp",
"src/crypto_x509_certificate_test.cpp",
"src/crypto_x509_crl_test.cpp",
]
sources += [
"../../../frameworks/core/v1.0/certificate/cert_chain_validator.c",
"../../../frameworks/core/v1.0/certificate/x509_certificate.c",
"../../../frameworks/core/v1.0/certificate/x509_crl.c",
]
sources += [
"../../../frameworks/adapter/v1.0/src/certificate_openssl_common.c",
"../../../frameworks/adapter/v1.0/src/x509_cert_chain_validator_openssl.c",
"../../../frameworks/adapter/v1.0/src/x509_certificate_openssl.c",
"../../../frameworks/adapter/v1.0/src/x509_crl_entry_openssl.c",
"../../../frameworks/adapter/v1.0/src/x509_crl_openssl.c",
]
sources += [
"../../../frameworks/common/v1.0/src/cf_blob.c",
"../../../frameworks/common/v1.0/src/cf_log.c",
"../../../frameworks/common/v1.0/src/cf_object_base.c",
"../../../frameworks/common/v1.0/src/utils.c",
"src/memory_mock.c",
]
cflags = [ "-DHILOG_ENABLE" ]
if (target_cpu == "arm") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
deps = [ "//third_party/openssl:libcrypto_shared" ]
external_deps = [
"c_utils:utils",
"crypto_framework:crypto_framework_lib",
"hilog:libhilog",
]
}

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2023 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.
*/
#ifndef MEMORY_MOCK_H
#define MEMORY_MOCK_H
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
void SetMockFlag(bool flag);
void StartRecordMallocNum(void);
void EndRecordMallocNum(void);
uint32_t GetMallocNum(void);
void ResetRecordMallocNum(void);
void SetMockMallocIndex(uint32_t index);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,665 @@
/*
* Copyright (c) 2023 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.
*/
#include <gtest/gtest.h>
#include "securec.h"
#include "string"
#include "cert_chain_validator.h"
#include "cf_blob.h"
#include "memory_mock.h"
#include "cf_object_base.h"
#include "cf_result.h"
#include "x509_cert_chain_validator_openssl.h"
using namespace std;
using namespace testing::ext;
namespace {
class CryptoX509CertChainValidatorTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
constexpr int32_t CERT_HEADER_LEN = 2;
constexpr int32_t INVALID_MAX_CERT_LEN = 8194;
static char g_caCert[] =
"-----BEGIN CERTIFICATE-----\r\n"
"MIIFwTCCA6mgAwIBAgIUBfKGru//yxvdRovc8iW9U9dzgqMwDQYJKoZIhvcNAQEL\r\n"
"BQAwbzELMAkGA1UEBhMCQ0kxCzAJBgNVBAgMAmhuMQswCQYDVQQHDAJzaDELMAkG\r\n"
"A1UECgwCaGgxCzAJBgNVBAsMAmlpMQswCQYDVQQDDAJhYjEfMB0GCSqGSIb3DQEJ\r\n"
"ARYQY3J5cHRvQGhlbGxvLmNvbTAgFw0yMjA4MjAxMjIyMzZaGA8yMDYyMDgyMDEy\r\n"
"MjIzNlowbzELMAkGA1UEBhMCQ0kxCzAJBgNVBAgMAmhuMQswCQYDVQQHDAJzaDEL\r\n"
"MAkGA1UECgwCaGgxCzAJBgNVBAsMAmlpMQsw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 0x01, 0x02, 0x02, 0x14, 0x05,
0xf2, 0x86, 0xae, 0xef, 0xff, 0xcb, 0x1b, 0xdd, 0x46, 0x8b, 0xdc, 0xf2, 0x25, 0xbd, 0x53, 0xd7,
0x73, 0x82, 0xa3, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
0x05, 0x00, 0x30, 0x6f, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x43,
0x49, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x02, 0x68, 0x6e, 0x31, 0x0b,
0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x02, 0x73, 0x68, 0x31, 0x0b, 0x30, 0x09, 0x06,
0x03, 0x55, 0x04, 0x0a, 0x0c, 0x02, 0x68, 0x68, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
0x0b, 0x0c, 0x02, 0x69, 0x69, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x02,
0x61, 0x62, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09,
0x01, 0x16, 0x10, 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x40, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e,
0x63, 0x6f, 0x6d, 0x30, 0x20, 0x17, 0x0d, 0x32, 0x32, 0x30, 0x38, 0x32, 0x30, 0x31, 0x32, 0x32,
0x32, 0x33, 0x36, 0x5a, 0x18, 0x0f, 0x32, 0x30, 0x36, 0x32, 0x30, 0x38, 0x32, 0x30, 0x31, 0x32,
0x32, 0x32, 0x33, 0x36, 0x5a, 0x30, 0x6f, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06,
0x13, 0x02, 0x43, 0x49, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x02, 0x68,
0x6e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x02, 0x73, 0x68, 0x31, 0x0b,
0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x02, 0x68, 0x68, 0x31, 0x0b, 0x30, 0x09, 0x06,
0x03, 0x55, 0x04, 0x0b, 0x0c, 0x02, 0x69, 0x69, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
0x03, 0x0c, 0x02, 0x61, 0x62, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
0x0d, 0x01, 0x09, 0x01, 0x16, 0x10, 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x40, 0x68, 0x65, 0x6c,
0x6c, 0x6f, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x82, 0x02, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,
0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x02, 0x0f, 0x00, 0x30, 0x82,
0x02, 0x0a, 0x02, 0x82, 0x02, 0x01, 0x00, 0xe5, 0xe4, 0x71, 0x7e, 0xdc, 0x1e, 0x09, 0x53, 0xc9,
0x29, 0x78, 0x5e, 0x68, 0xf0, 0x32, 0x18, 0xb2, 0xc6, 0x13, 0x10, 0x51, 0x24, 0xe7, 0x66, 0xd0,
0x32, 0x8c, 0x88, 0xae, 0x77, 0x22, 0x66, 0xaf, 0xda, 0xba, 0x0a, 0x2f, 0x0e, 0x5c, 0x64, 0xf3,
0xc8, 0xf2, 0xa6, 0xbc, 0x37, 0xa3, 0xc0, 0xa7, 0x16, 0xab, 0x06, 0x0d, 0xa5, 0x22, 0x6c,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0xd5, 0x22, 0x16,
0x16, 0x66, 0x57, 0xcb, 0xc9, 0xfc, 0x79, 0x57, 0xa6, 0x78, 0x0e, 0x1d, 0xf5, 0xf9, 0x52, 0x61,
0xa9, 0x36, 0x32, 0xfe, 0x4f, 0x3d, 0x7b, 0x6d, 0xa5, 0x23, 0x39, 0xf2, 0xbc, 0xa5, 0x23, 0x60,
0x68, 0x49, 0x32, 0x60, 0xc4, 0xdf, 0xe3, 0xd6, 0xd1, 0x35, 0x2e, 0x8f, 0x21, 0x69, 0xdc, 0x29,
0x8b, 0x98, 0x3a, 0xf0, 0x7d, 0x05, 0x77, 0x5f, 0x47, 0x38, 0xd7, 0x7e, 0x2c, 0x5c, 0x40, 0x86,
0x98, 0x09, 0xd9, 0x95, 0x09, 0x6f, 0x7a, 0xa8, 0x1b, 0x2a, 0x44, 0xcb, 0x52, 0x77, 0xdb, 0x61,
0x42, 0xab, 0xa7, 0x63, 0x22, 0xb2, 0x17, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x53, 0x30, 0x51,
0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x47, 0xd9, 0xcb, 0x06, 0xb8,
0x3f, 0xa4, 0xc2, 0x8e, 0xad, 0x53, 0x4d, 0xeb, 0x55, 0xb4, 0x79, 0x76, 0xd0, 0x61, 0x7e, 0x30,
0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x47, 0xd9, 0xcb, 0x06,
0xb8, 0x3f, 0xa4, 0xc2, 0x8e, 0xad, 0x53, 0x4d, 0xeb, 0x55, 0xb4, 0x79, 0x76, 0xd0, 0x61, 0x7e,
0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01,
0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7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 0xb9, 0xab, 0x23, 0xa4,
0x71, 0xd2, 0x18, 0x26, 0xc0, 0xea, 0xf8, 0x91, 0x57, 0xb1, 0x0d, 0xd2, 0xb2, 0x86, 0xe6, 0x70,
0x53, 0x4b, 0xb4, 0x1e, 0xa2, 0x4c, 0x25, 0x1d, 0x55, 0x8a, 0x7f, 0x77, 0x20, 0x53, 0x11, 0x13,
0xad, 0xe1, 0x8c, 0xd9, 0xe8, 0xdc, 0xd3, 0xcb, 0xed, 0xdd, 0x26, 0x96, 0x19, 0xb0, 0x8c, 0x4c,
0xb0, 0xad, 0x8d, 0x0c, 0x99, 0x76, 0x22, 0x43, 0xa6, 0xa0, 0xf2, 0x8d, 0x0f, 0x60, 0x05, 0xe0,
0x36, 0xbf, 0x0d, 0xc4, 0xe1, 0x2f, 0x05, 0x8e, 0xd9, 0x3a, 0x45, 0x9d, 0xd9, 0xd7, 0x89, 0x23,
0x20, 0x11, 0x0c, 0x47, 0x3d, 0x9c, 0xf7, 0x18, 0xe3, 0xa3, 0x22, 0xc2, 0x8c, 0x09, 0xe9, 0xb3,
0xcc, 0x54, 0xf0, 0x97, 0x60, 0x63, 0xb1, 0x49, 0xf4, 0x69, 0xbd, 0x8e, 0x52, 0x12, 0x38, 0x23,
0x96, 0x55, 0x67, 0x2b, 0x75, 0x0b, 0x20, 0xcd, 0xc0, 0x7d, 0x5a, 0x83, 0x7b, 0xb9, 0xf7, 0x1a,
0x70, 0xf8, 0xa4, 0x76, 0xc7, 0x65, 0x03, 0xcb, 0x1a, 0x9a, 0xb4, 0x6d, 0x01, 0xfd, 0x25, 0x49,
0xc2, 0xad, 0xa0, 0x7a, 0xd2
};
static uint8_t g_secCertDerFormat[] = {
0x30, 0x82, 0x05, 0xbc, 0x30, 0x82, 0x03, 0xa4, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x14, 0x64,
0x36, 0x52, 0x81, 0xa9, 0xfb, 0xb4, 0x5b, 0xe6, 0x78, 0xc9, 0x94, 0x0f, 0xcd, 0x24, 0x93, 0xea,
0x29, 0x39, 0x9c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
0x05, 0x00, 0x30, 0x6f, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x43,
0x49, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x02, 0x68, 0x6e, 0x31, 0x0b,
0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x02, 0x73, 0x68, 0x31, 0x0b, 0x30, 0x09, 0x06,
0x03, 0x55, 0x04, 0x0a, 0x0c, 0x02, 0x68, 0x68, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
0x0b, 0x0c, 0x02, 0x69, 0x69, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x02,
0x61, 0x62, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09,
0x01, 0x16, 0x10, 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x40, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e,
0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x32, 0x30, 0x38, 0x32, 0x30, 0x31, 0x32, 0x32,
0x38, 0x30, 0x38, 0x5a, 0x17, 0x0d, 0x34, 0x32, 0x30, 0x38, 0x32, 0x30, 0x31, 0x32, 0x32, 0x38,
0x30, 0x38, 0x5a, 0x30, 0x7c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
0x43, 0x4e, 0x31, 0x0e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x05, 0x48, 0x55, 0x4e,
0x41, 0x4e, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x08, 0x53, 0x48, 0x41,
0x47, 0x4e, 0x48, 0x41, 0x49, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x02,
0x68, 0x68, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x02, 0x69, 0x69, 0x31,
0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x06, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72,
0x31, 0x1f, 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16,
0x10, 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x40, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x63, 0x6f,
0x6d, 0x30, 0x82, 0x02, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x02, 0x0f, 0x00, 0x30, 0x82, 0x02, 0x0a, 0x02, 0x82, 0x02,
0x01, 0x00, 0xb9, 0x25, 0x72, 0xae, 0x5b, 0x02, 0xe6, 0x73, 0xbe, 0xeb, 0x89, 0x93, 0x60, 0x60,
0x15, 0x25, 0xbd, 0x5b, 0x75, 0x12, 0x61, 0xcf, 0xb0, 0x13, 0x33, 0x2d, 0x82, 0x13, 0x60, 0x02,
0xca, 0x8f, 0xd1, 0x02, 0x5d, 0xa9, 0xe1, 0x8a, 0x33, 0xf2, 0xe2, 0x7a, 0x53, 0x6d, 0xc8, 0xa7,
0x81, 0x7e, 0x1e, 0x60, 0x06, 0xa9, 0x79, 0xc8, 0x44, 0x67, 0xb3, 0xc1, 0xbf, 0x94, 0xd5, 0x76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0x52, 0x48, 0x06, 0x29, 0xf7, 0xf6, 0xc9, 0x6e, 0xa7, 0xd7, 0x34, 0x80, 0xcb, 0x3c, 0x9a,
0x20, 0x43, 0xc1, 0x0a, 0xb1, 0xc7, 0x0e, 0x7e, 0xcf, 0xc8, 0x88, 0xc0, 0xcf, 0xdd, 0x68, 0x2d,
0x4f, 0x7b, 0xf5, 0x0a, 0xbe, 0xfa, 0xcf, 0xe7, 0x5b, 0x06, 0x8d, 0x39, 0x7c, 0x77, 0xb0, 0xde,
0x7d, 0x98, 0xe5, 0x24, 0xc2, 0x9f, 0x19, 0xf1, 0xc6, 0xd8, 0x7f, 0x8e, 0x8e, 0x7d, 0x6c, 0xee,
0x88, 0x79, 0x48, 0x4d, 0xfa, 0x47, 0xe7, 0x9c, 0xa1, 0x80, 0xee, 0xec, 0x70, 0x3e, 0x9a, 0x64,
0xfc, 0x21, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x43, 0x30, 0x41, 0x30, 0x0c, 0x06, 0x03, 0x55,
0x1d, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x31, 0x06, 0x03, 0x55, 0x1d, 0x1f,
0x04, 0x2a, 0x30, 0x28, 0x30, 0x26, 0xa0, 0x24, 0xa0, 0x22, 0x86, 0x20, 0x68, 0x74, 0x74, 0x70,
0x73, 0x3a, 0x2f, 0x2f, 0x63, 0x61, 0x2e, 0x78, 0x69, 0x65, 0x78, 0x69, 0x61, 0x6e, 0x62, 0x69,
0x6e, 0x2e, 0x63, 0x6e, 0x2f, 0x63, 0x72, 0x6c, 0x2e, 0x70, 0x65, 0x6d, 0x30, 0x0d, 0x06, 0x09,
0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x02, 0x01, 0x00,
0x29, 0x50, 0x7b, 0x20, 0x86, 0x76, 0x58, 0x74, 0xaf, 0x44, 0xb9, 0xe4, 0x32, 0x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 0x19, 0xeb, 0x58,
0xdb, 0x61, 0x7f, 0xf2, 0xcd, 0x4d, 0xd2, 0x80, 0xbb, 0x51, 0xc9, 0xff, 0x26, 0x66, 0x54, 0x03,
0xdc, 0x63, 0x68, 0x20, 0xc4, 0x7a, 0x84, 0xc3, 0xa1, 0xe7, 0xef, 0xf3, 0xfd, 0xf3, 0x4a, 0xbd,
0xac, 0x47, 0xac, 0x11, 0xee, 0x12, 0x07, 0x82, 0xf0, 0xbd, 0x34, 0xd3, 0x93, 0xcd, 0xd4, 0x92,
0x46, 0xa7, 0x37, 0x01, 0xf5, 0x33, 0xf7, 0x49, 0x1d, 0xb0, 0x0a, 0x19, 0xa3, 0x0a, 0xa5, 0xec,
0x2a, 0xd9, 0xcb, 0xb2, 0xe2, 0xab, 0x36, 0x89, 0x33, 0x2d, 0x45, 0xfb, 0x61, 0xfc, 0x8e, 0x6c,
0xdf, 0x09, 0x5e, 0x83, 0x05, 0xa0, 0x98, 0x83, 0x39, 0x41, 0x19, 0x2f, 0xdd, 0xab, 0xf4, 0x3b,
0x03, 0xd9, 0x1b, 0x66, 0xb7, 0xc2, 0x79, 0xbf, 0xf2, 0x12, 0x0c, 0xf4, 0x87, 0x42, 0xeb, 0x5a,
0x70, 0x56, 0xc3, 0x0e, 0xeb, 0xd9, 0x3f, 0x87, 0x93, 0x82, 0xd0, 0xfe, 0x32, 0xed, 0x0b, 0x54,
};
static uint8_t g_invalidCert0[] = {
0x30, 0x82, 0x03, 0xc1, 0x30, 0x82, 0x03, 0xa9, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x14, 0x05,
};
static HcfCertChainValidator *g_validator = nullptr;
void CryptoX509CertChainValidatorTest::SetUpTestCase()
{
(void)HcfCertChainValidatorCreate("PKIX", &g_validator);
}
void CryptoX509CertChainValidatorTest::TearDownTestCase()
{
CfObjDestroy(g_validator);
}
void CryptoX509CertChainValidatorTest::SetUp()
{
}
void CryptoX509CertChainValidatorTest::TearDown()
{
}
HWTEST_F(CryptoX509CertChainValidatorTest, GetAlgorithm001, TestSize.Level0)
{
const char *algo = g_validator->getAlgorithm(g_validator);
EXPECT_NE(algo, nullptr);
if (algo == nullptr) {
CfObjDestroy(g_validator);
return;
}
string st("PKIX");
ASSERT_STREQ(algo, st.c_str());
}
HWTEST_F(CryptoX509CertChainValidatorTest, GetAlgorithm002, TestSize.Level0)
{
HcfCertChainValidator *pathValidator = nullptr;
CfResult res = HcfCertChainValidatorCreate("invalidPKIX", &pathValidator);
EXPECT_EQ(res, CF_NOT_SUPPORT);
EXPECT_EQ(pathValidator, nullptr);
}
/* valid cert chain. */
HWTEST_F(CryptoX509CertChainValidatorTest, VerifyTest001, TestSize.Level0)
{
CfResult res = CF_SUCCESS;
HcfCertChainData certsData = { 0 };
certsData.format = CF_FORMAT_PEM;
certsData.count = 2; /* level-2 cert chain. */
uint32_t caCertLen = strlen(g_caCert) + 1;
uint32_t secondCaCertLen = strlen(g_secondCaCert) + 1;
certsData.dataLen = CERT_HEADER_LEN + secondCaCertLen + CERT_HEADER_LEN + caCertLen;
certsData.data = (uint8_t *)malloc(certsData.dataLen);
if (certsData.data == nullptr) {
return;
}
if (memcpy_s(certsData.data, CERT_HEADER_LEN + secondCaCertLen + CERT_HEADER_LEN + caCertLen,
&secondCaCertLen, CERT_HEADER_LEN) != EOK) {
goto OUT;
}
if (memcpy_s(certsData.data + CERT_HEADER_LEN, secondCaCertLen + CERT_HEADER_LEN + caCertLen,
g_secondCaCert, secondCaCertLen) != EOK) {
goto OUT;
}
if (memcpy_s(certsData.data + CERT_HEADER_LEN + secondCaCertLen, CERT_HEADER_LEN + caCertLen,
&caCertLen, CERT_HEADER_LEN) != EOK) {
goto OUT;
}
if (memcpy_s(certsData.data + CERT_HEADER_LEN + secondCaCertLen + CERT_HEADER_LEN, caCertLen,
g_caCert, caCertLen) != EOK) {
goto OUT;
}
res = g_validator->validate(g_validator, &certsData);
EXPECT_EQ(res, CF_SUCCESS);
OUT:
free(certsData.data);
}
/* invalid cert chain. */
HWTEST_F(CryptoX509CertChainValidatorTest, VerifyTest002, TestSize.Level0)
{
CfResult res = CF_SUCCESS;
HcfCertChainData certsData = { 0 };
certsData.format = CF_FORMAT_PEM;
certsData.count = 3; /* level-3 cert chain. */
uint32_t caCertLen = strlen(g_caCert) + 1;
uint32_t secondCaCertLen = strlen(g_secondCaCert) + 1;
uint32_t thirdCertLen = strlen(g_invalidCaCert) + 1;
certsData.dataLen = CERT_HEADER_LEN + thirdCertLen + CERT_HEADER_LEN +
secondCaCertLen + CERT_HEADER_LEN + caCertLen;
certsData.data = (uint8_t *)malloc(certsData.dataLen);
EXPECT_NE(certsData.data, nullptr);
if (certsData.data == nullptr) {
return;
}
if (memcpy_s(certsData.data,
CERT_HEADER_LEN + thirdCertLen + CERT_HEADER_LEN + secondCaCertLen + CERT_HEADER_LEN + caCertLen,
&thirdCertLen, CERT_HEADER_LEN) != EOK) {
goto OUT;
}
if (memcpy_s(certsData.data + CERT_HEADER_LEN,
thirdCertLen + CERT_HEADER_LEN + secondCaCertLen + CERT_HEADER_LEN + caCertLen,
g_invalidCaCert, thirdCertLen) != EOK) {
return;
}
if (memcpy_s(certsData.data + CERT_HEADER_LEN + thirdCertLen,
CERT_HEADER_LEN + secondCaCertLen + CERT_HEADER_LEN + caCertLen, &secondCaCertLen, CERT_HEADER_LEN) != EOK) {
goto OUT;
}
if (memcpy_s(certsData.data + CERT_HEADER_LEN + thirdCertLen + CERT_HEADER_LEN,
secondCaCertLen + CERT_HEADER_LEN + caCertLen, g_secondCaCert, secondCaCertLen) != EOK) {
goto OUT;
}
if (memcpy_s(certsData.data + CERT_HEADER_LEN + thirdCertLen + CERT_HEADER_LEN + secondCaCertLen,
CERT_HEADER_LEN + caCertLen, &caCertLen, CERT_HEADER_LEN) != EOK) {
goto OUT;
}
if (memcpy_s(certsData.data + CERT_HEADER_LEN + thirdCertLen + CERT_HEADER_LEN + secondCaCertLen + CERT_HEADER_LEN,
caCertLen, g_caCert, caCertLen) != EOK) {
goto OUT;
}
res = g_validator->validate(g_validator, &certsData);
EXPECT_NE(res, CF_SUCCESS);
OUT:
free(certsData.data);
}
/* invalid cert chain data len. */
HWTEST_F(CryptoX509CertChainValidatorTest, VerifyTest003, TestSize.Level0)
{
HcfCertChainData certsData = { 0 };
certsData.format = CF_FORMAT_PEM;
certsData.count = 3; /* level-3 cert chain. */
certsData.dataLen = INVALID_MAX_CERT_LEN;
certsData.data = (uint8_t *)malloc(certsData.dataLen);
EXPECT_NE(certsData.data, nullptr);
if (certsData.data == nullptr) {
return;
}
CfResult res = g_validator->validate(g_validator, &certsData);
EXPECT_NE(res, CF_SUCCESS);
free(certsData.data);
}
/* invalid cert number(1). */
HWTEST_F(CryptoX509CertChainValidatorTest, VerifyTest004, TestSize.Level0)
{
CfResult res = CF_SUCCESS;
HcfCertChainData certsData = { 0 };
certsData.format = CF_FORMAT_PEM;
certsData.count = 1; /* level-3 cert chain. */
uint32_t caCertLen = strlen(g_caCert) + 1;
certsData.dataLen = CERT_HEADER_LEN + caCertLen;
certsData.data = (uint8_t *)malloc(certsData.dataLen);
EXPECT_NE(certsData.data, nullptr);
if (certsData.data == nullptr) {
return;
}
if (memcpy_s(certsData.data,
CERT_HEADER_LEN + caCertLen, &caCertLen, CERT_HEADER_LEN) != EOK) {
goto OUT;
}
if (memcpy_s(certsData.data + CERT_HEADER_LEN,
caCertLen, g_caCert, caCertLen) != EOK) {
goto OUT;
}
res = g_validator->validate(g_validator, &certsData);
EXPECT_NE(res, CF_SUCCESS);
OUT:
free(certsData.data);
}
static int32_t ConstructCertData(HcfCertChainData *certsData, uint8_t *caCert, uint32_t caCertLen,
uint8_t *secCaCert, uint32_t secCaCertLen)
{
uint32_t size = CERT_HEADER_LEN + secCaCertLen + CERT_HEADER_LEN + caCertLen;
uint8_t *tmp = (uint8_t *)malloc(size);
if (tmp == nullptr) {
return CF_ERR_MALLOC;
}
int32_t ret = CF_ERR_COPY;
do {
uint32_t offset = 0;
if (memcpy_s(tmp + offset, size - offset, &secCaCertLen, CERT_HEADER_LEN) != EOK) {
break;
}
offset += CERT_HEADER_LEN;
if (memcpy_s(tmp + offset, size - offset, secCaCert, secCaCertLen) != EOK) {
break;
}
offset += secCaCertLen;
if (memcpy_s(tmp + offset, size - offset, &caCertLen, CERT_HEADER_LEN) != EOK) {
break;
}
offset += CERT_HEADER_LEN;
if (memcpy_s(tmp + offset, size - offset, caCert, caCertLen) != EOK) {
break;
}
certsData->data = tmp;
certsData->dataLen = size;
return CF_SUCCESS;
} while (0);
free(tmp);
return ret;
}
/* valid cert chain der format. */
HWTEST_F(CryptoX509CertChainValidatorTest, VerifyTest005, TestSize.Level0)
{
HcfCertChainData certsData = { 0 };
certsData.format = CF_FORMAT_DER;
certsData.count = 2; /* level-2 cert chain. */
uint32_t caCertLen = sizeof(g_certDerFormat);
uint32_t secondCaCertLen = sizeof(g_secCertDerFormat);
int32_t ret = ConstructCertData(&certsData, g_certDerFormat, caCertLen, g_secCertDerFormat, secondCaCertLen);
ASSERT_EQ(ret, CF_SUCCESS);
ret = g_validator->validate(g_validator, &certsData);
EXPECT_EQ(ret, CF_SUCCESS);
free(certsData.data);
}
/* valid cert chain format. */
HWTEST_F(CryptoX509CertChainValidatorTest, VerifyTest006, TestSize.Level0)
{
HcfCertChainData certsData = { 0 };
certsData.format = static_cast<enum CfEncodingFormat>(CF_FORMAT_PEM + 1);
certsData.count = 2; /* level-2 cert chain. */
uint32_t caCertLen = sizeof(g_certDerFormat);
uint32_t secondCaCertLen = sizeof(g_secCertDerFormat);
int32_t ret = ConstructCertData(&certsData, g_certDerFormat, caCertLen, g_secCertDerFormat, secondCaCertLen);
ASSERT_EQ(ret, CF_SUCCESS);
ret = g_validator->validate(g_validator, &certsData);
EXPECT_NE(ret, CF_SUCCESS);
free(certsData.data);
}
/* invalid cert 0. */
HWTEST_F(CryptoX509CertChainValidatorTest, VerifyTest007, TestSize.Level0)
{
HcfCertChainData certsData = { 0 };
certsData.format = CF_FORMAT_DER;
certsData.count = 2; /* level-2 cert chain. */
uint32_t caCertLen = sizeof(g_invalidCert0);
uint32_t secondCaCertLen = sizeof(g_secCertDerFormat);
int32_t ret = ConstructCertData(&certsData, g_invalidCert0, caCertLen, g_secCertDerFormat, secondCaCertLen);
ASSERT_EQ(ret, CF_SUCCESS);
ret = g_validator->validate(g_validator, &certsData);
EXPECT_NE(ret, CF_SUCCESS);
free(certsData.data);
}
static const char *GetInvalidValidatorClass(void)
{
return "INVALID_VALIDATOR_CLASS";
}
HWTEST_F(CryptoX509CertChainValidatorTest, NullInput, TestSize.Level0)
{
CfResult res = HcfCertChainValidatorCreate("PKIX", nullptr);
EXPECT_NE(res, CF_SUCCESS);
res = g_validator->validate(g_validator, nullptr);
EXPECT_NE(res, CF_SUCCESS);
const char *algo = g_validator->getAlgorithm(nullptr);
EXPECT_EQ(algo, nullptr);
(void)g_validator->base.destroy(nullptr);
}
HWTEST_F(CryptoX509CertChainValidatorTest, InvalidClass, TestSize.Level0)
{
HcfCertChainValidator invalidValidator;
invalidValidator.base.getClass = GetInvalidValidatorClass;
HcfCertChainData certsData = { 0 };
CfResult res = g_validator->validate(&invalidValidator, &certsData);
EXPECT_NE(res, CF_SUCCESS);
const char *algo = g_validator->getAlgorithm(&invalidValidator);
EXPECT_EQ(algo, nullptr);
(void)g_validator->base.destroy(&(invalidValidator.base));
}
HWTEST_F(CryptoX509CertChainValidatorTest, NullSpiInput, TestSize.Level0)
{
HcfCertChainValidatorSpi *spiObj = nullptr;
CfResult res = HcfCertChainValidatorSpiCreate(nullptr);
EXPECT_NE(res, CF_SUCCESS);
res = HcfCertChainValidatorSpiCreate(&spiObj);
EXPECT_EQ(res, CF_SUCCESS);
res = spiObj->engineValidate(spiObj, nullptr);
EXPECT_NE(res, CF_SUCCESS);
(void)spiObj->base.destroy(nullptr);
}
HWTEST_F(CryptoX509CertChainValidatorTest, InvalidSpiClass, TestSize.Level0)
{
HcfCertChainValidatorSpi *spiObj = nullptr;
CfResult res = HcfCertChainValidatorSpiCreate(&spiObj);
HcfCertChainValidatorSpi invalidSpi;
invalidSpi.base.getClass = GetInvalidValidatorClass;
CfArray data = { 0 };
res = spiObj->engineValidate(&invalidSpi, &data);
EXPECT_NE(res, CF_SUCCESS);
(void)spiObj->base.destroy(&(invalidSpi.base));
}
HWTEST_F(CryptoX509CertChainValidatorTest, InvalidMalloc, TestSize.Level0)
{
SetMockFlag(true);
HcfCertChainValidator *pathValidator = nullptr;
CfResult res = HcfCertChainValidatorCreate("PKIX", &pathValidator);
EXPECT_EQ(res, CF_ERR_MALLOC);
HcfCertChainData certsData = { 0 };
certsData.dataLen = 1;
res = g_validator->validate(g_validator, &certsData);
EXPECT_NE(res, CF_SUCCESS);
SetMockFlag(false);
}
}

View File

@ -0,0 +1,988 @@
/*
* Copyright (c) 2023 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.
*/
#include <gtest/gtest.h>
#include "securec.h"
#include "x509_certificate.h"
#include "cf_blob.h"
#include "memory_mock.h"
#include "certificate_openssl_common.h"
#include "x509_certificate_openssl.h"
using namespace std;
using namespace testing::ext;
namespace {
class CryptoX509CertificateTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
static char g_deviceTestCert[] =
"-----BEGIN CERTIFICATE-----\r\n"
"MIIBLzCB1QIUO/QDVJwZLIpeJyPjyTvE43xvE5cwCgYIKoZIzj0EAwIwGjEYMBYG\r\n"
"A1UEAwwPRXhhbXBsZSBSb290IENBMB4XDTIzMDkwNDExMjAxOVoXDTI2MDUzMDEx\r\n"
"MjAxOVowGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290IEN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SiWKqR5tf1KUImIR9\r\n"
"-----END CERTIFICATE-----\r\n";
/* g_testSelfSignedCaCert
Certificate:
Data:
Version: 3 (0x2)
Serial Number: 272 (0x110)
Signature Algorithm: sha256WithRSAEncryption
Issuer: C = CN, ST = BJ, L = BJ, O = HD, OU = dev, CN = ca, emailAddress = ca@cryptoframework.com
Validity
Not Before: Aug 19 12:49:06 2022 GMT
Not After : Aug 16 12:49:06 2032 GMT
Subject: C = CN, ST = BJ, L = BJ, O = HD, OU = dev, CN = ca, emailAddress = ca@cryptoframework.com
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
RSA Public-Key: (2048 bit)
Modulus:
00:9f:29:d0:85:84:ed:6c:30:6e:d0:13:83:e0:1b:
61:08:f7:dd:63:41:06:4b:54:fb:f0:15:7f:e4:e5:
d5:a0:1a:e1:33:9e:5b:6f:d9:01:17:38:b1:dc:0b:
55:3c:5d:5c:28:a9:16:c7:ae:88:63:77:d2:1c:17:
ad:71:54:1e:b7:0c:7f:4c:36:b0:29:33:9c:95:59:
fe:b4:1c:7c:43:b9:29:bd:6f:07:3e:83:10:47:20:
21:26:04:86:1a:8e:05:f6:01:8a:de:6a:7e:9a:b9:
47:6f:b6:47:f4:e1:ff:26:d5:fa:40:6b:52:5f:86:
b2:c5:db:0c:07:ba:a1:90:b2:e7:a9:46:a6:10:ef:
98:73:14:3b:b6:b5:de:3f:92:16:64:e1:31:b2:36:
c9:ec:ae:6b:52:da:81:2a:1a:04:97:d8:d4:9f:a2:
ee:35:8f:9a:61:05:47:47:50:da:9d:04:1a:31:d3:
81:01:a1:46:8e:55:bb:00:c7:8a:93:52:bf:45:cf:
f0:e5:00:fc:f6:1b:2f:f4:81:8f:51:6a:e0:2d:e0:
b5:fb:e3:7a:cc:14:6f:35:5a:32:8a:bf:c0:2b:b2:
d6:a7:17:23:cd:19:2d:ed:f0:85:1d:b8:73:47:17:
60:53:b4:b8:68:bd:7a:03:e9:db:87:f0:ef:26:06:
aa:01
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Subject Key Identifier:
8C:A3:3B:42:63:01:B3:4D:51:F6:E4:2D:B5:83:7F:18:39:2F:B7:B5
X509v3 Authority Key Identifier:
keyid:8C:A3:3B:42:63:01:B3:4D:51:F6:E4:2D:B5:83:7F:18:39:2F:B7:B5
X509v3 Basic Constraints: critical
CA:TRUE, pathlen:2
X509v3 Key Usage:
Certificate Sign, CRL Sign
X509v3 Extended Key Usage:
TLS Web Server Authentication, TLS Web Client Authentication
X509v3 Subject Alternative Name:
email:ca@cryptoframework.com
X509v3 Issuer Alternative Name:
email:ca@cryptoframework.com
Signature Algorithm: sha256WithRSAEncryption
87:ee:11:13:a7:09:eb:6f:e0:2d:8b:2c:2e:47:3b:11:28:3b:
7b:12:b0:66:59:a2:b0:7c:81:89:cb:b2:ff:e5:da:80:e6:77:
71:36:e0:40:d5:e5:42:86:4a:6f:0f:e4:b3:f0:7f:70:89:db:
40:66:1b:a4:09:b8:ed:2b:9d:a3:e2:3f:1b:dc:63:d1:7e:e0:
40:1f:70:b5:2a:db:4a:d3:ac:e9:28:e7:2e:26:14:d3:11:5c:
16:c7:34:8f:a9:36:4a:b9:72:8b:04:50:72:34:b8:3c:e2:a2:
51:2d:02:9b:71:77:0c:71:9d:8f:9e:4f:94:19:17:c6:e7:57:
0a:ad:95:dc:9d:d5:c0:a7:f6:6d:58:d0:6f:3c:f6:f8:cf:d0:
d6:6f:8f:ec:58:41:f8:99:9e:3b:c7:9e:9a:4a:8c:43:4b:45:
31:4d:c4:33:8e:35:36:97:a3:0b:98:85:54:01:a0:a3:09:c2:
f1:2d:01:f9:fc:47:f5:d0:49:b8:73:3a:be:9c:44:5b:0d:dc:
91:91:43:65:0d:64:77:dd:58:46:0a:fb:8d:8f:1f:73:4b:ff:
4f:4b:73:1d:66:ce:11:5c:e4:94:42:01:58:bd:66:a2:6a:4b:
04:2c:1e:d3:f1:b0:f8:13:ba:d1:b7:e2:d8:ca:09:c3:cb:76:
21:c0:75:43
*/
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AMCAQYwHQYDVR0lBBYwFAYIKwYBBQUH\r\n"
"AwEGCCsGAQUFBwMCMCEGA1UdEQQaMBiBFmNhQGNyeXB0b2ZyYW1ld29yay5jb20w\r\n"
"IQYDVR0SBBowGIEWY2FAY3J5cHRvZnJhbWV3b3JrLmNvbTANBgkqhkiG9w0BAQsF\r\n"
"AAOCAQEAh+4RE6cJ62/gLYssLkc7ESg7exKwZlmisHyBicuy/+XagOZ3cTbgQNXl\r\n"
"QoZKbw/ks/B/cInbQGYbpAm47Sudo+I/G9xj0X7gQB9wtSrbStOs6SjnLiYU0xFc\r\n"
"Fsc0j6k2SrlyiwRQcjS4POKiUS0Cm3F3DHGdj55PlBkXxudXCq2V3J3VwKf2bVjQ\r\n"
"bzz2+M/Q1m+P7FhB+JmeO8eemkqMQ0tFMU3EM441NpejC5iFVAGgownC8S0B+fxH\r\n"
"9dBJuHM6vpxEWw3ckZFDZQ1kd91YRgr7jY8fc0v/T0tzHWbOEVzklEIBWL1mompL\r\n"
"BCwe0/Gw+BO60bfi2MoJw8t2IcB1Qw==\r\n"
"-----END CERTIFICATE-----\r\n";
constexpr int TEST_CERT_VERSION = 3;
constexpr int TEST_CERT_CHAIN_LEN = 2;
constexpr int TEST_CERT_SERIAL_NUMBER = 272;
static HcfX509Certificate *g_x509CertObj = nullptr;
void CryptoX509CertificateTest::SetUpTestCase()
{
CfEncodingBlob inStream = { 0 };
inStream.data = (uint8_t *)g_testSelfSignedCaCert;
inStream.encodingFormat = CF_FORMAT_PEM;
inStream.len = strlen(g_testSelfSignedCaCert) + 1;
(void)HcfX509CertificateCreate(&inStream, &g_x509CertObj);
}
void CryptoX509CertificateTest::TearDownTestCase()
{
CfObjDestroy(g_x509CertObj);
}
void CryptoX509CertificateTest::SetUp()
{
}
void CryptoX509CertificateTest::TearDown()
{
}
/**
* @tc.name: CryptoX509CertificateTest.GenerateCert001
* @tc.desc: Generate valid PEM format certificate.
* @tc.type: FUNC
* @tc.require: I5QDNN
*/
HWTEST_F(CryptoX509CertificateTest, GenerateCert001, TestSize.Level0)
{
HcfX509Certificate *x509Cert = nullptr;
CfEncodingBlob inStream = { 0 };
inStream.data = (uint8_t *)g_testSelfSignedCaCert;
inStream.encodingFormat = CF_FORMAT_PEM;
inStream.len = strlen(g_testSelfSignedCaCert) + 1;
CfResult ret = HcfX509CertificateCreate(&inStream, &x509Cert);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(x509Cert, nullptr);
CfObjDestroy(x509Cert);
}
/* Invalid input. */
HWTEST_F(CryptoX509CertificateTest, GenerateCert002, TestSize.Level0)
{
HcfX509Certificate *x509Cert = nullptr;
CfEncodingBlob inStream = { 0 };
CfResult ret = HcfX509CertificateCreate(&inStream, &x509Cert);
EXPECT_NE(ret, CF_SUCCESS);
EXPECT_EQ(x509Cert, nullptr);
CfObjDestroy(x509Cert);
}
/* Invalid PEM format. */
HWTEST_F(CryptoX509CertificateTest, GenerateCert003, TestSize.Level0)
{
HcfX509Certificate *x509Cert = nullptr;
CfEncodingBlob inStream = { 0 };
inStream.data = (uint8_t *)g_testInvalidCert;
inStream.encodingFormat = CF_FORMAT_PEM;
inStream.len = strlen(g_testInvalidCert) + 1;
CfResult ret = HcfX509CertificateCreate(&inStream, &x509Cert);
EXPECT_NE(ret, CF_SUCCESS);
EXPECT_EQ(x509Cert, nullptr);
CfObjDestroy(x509Cert);
}
/* Valid DER format. */
HWTEST_F(CryptoX509CertificateTest, GenerateCert004, TestSize.Level0)
{
CfEncodingBlob derBlob = { 0 };
CfResult ret = g_x509CertObj->base.getEncoded((HcfCertificate *)g_x509CertObj, &derBlob);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(derBlob.data, nullptr);
EXPECT_EQ(derBlob.encodingFormat, CF_FORMAT_DER);
HcfX509Certificate *certFromDerData = nullptr;
ret = HcfX509CertificateCreate(&derBlob, &certFromDerData);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(certFromDerData, nullptr);
free(derBlob.data);
CfObjDestroy(certFromDerData);
}
/* verify self signed cert. */
HWTEST_F(CryptoX509CertificateTest, Verify001, TestSize.Level0)
{
HcfPubKey *keyOut = nullptr;
CfResult ret = g_x509CertObj->base.getPublicKey((HcfCertificate *)g_x509CertObj, &keyOut);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(keyOut, nullptr);
ret = g_x509CertObj->base.verify((HcfCertificate *)g_x509CertObj, keyOut);
EXPECT_EQ(ret, CF_SUCCESS);
CfObjDestroy(keyOut);
}
/* use root ca cert's public key to verify next cert. */
HWTEST_F(CryptoX509CertificateTest, Verify002, TestSize.Level0)
{
HcfX509Certificate *rootCert = nullptr;
CfEncodingBlob root = { 0 };
root.data = (uint8_t *)g_rootCert;
root.encodingFormat = CF_FORMAT_PEM;
root.len = strlen(g_rootCert) + 1;
CfResult ret = HcfX509CertificateCreate(&root, &rootCert);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(rootCert, nullptr);
HcfPubKey *rootkeyOut = nullptr;
ret = rootCert->base.getPublicKey((HcfCertificate *)rootCert, &rootkeyOut);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(rootkeyOut, nullptr);
HcfX509Certificate *secondCert = nullptr;
CfEncodingBlob second = { 0 };
second.data = (uint8_t *)g_secondCert;
second.encodingFormat = CF_FORMAT_PEM;
second.len = strlen(g_secondCert) + 1;
ret = HcfX509CertificateCreate(&root, &secondCert);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(rootCert, nullptr);
ret = secondCert->base.verify((HcfCertificate *)secondCert, rootkeyOut);
EXPECT_EQ(ret, CF_SUCCESS);
CfObjDestroy(rootkeyOut);
CfObjDestroy(rootCert);
CfObjDestroy(secondCert);
}
/* verify cert with wrong pub key. */
HWTEST_F(CryptoX509CertificateTest, Verify003, TestSize.Level0)
{
HcfX509Certificate *rootCert = nullptr;
CfEncodingBlob root = { 0 };
root.data = (uint8_t *)g_rootCert;
root.encodingFormat = CF_FORMAT_PEM;
root.len = strlen(g_rootCert) + 1;
CfResult ret = HcfX509CertificateCreate(&root, &rootCert);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(rootCert, nullptr);
HcfPubKey *rootkeyOut = nullptr;
ret = rootCert->base.getPublicKey((HcfCertificate *)rootCert, &rootkeyOut);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(rootkeyOut, nullptr);
ret = g_x509CertObj->base.verify((HcfCertificate *)g_x509CertObj, rootkeyOut);
EXPECT_NE(ret, CF_SUCCESS);
CfObjDestroy(rootkeyOut);
CfObjDestroy(rootCert);
}
/* verify cert with invalid input pub key. */
HWTEST_F(CryptoX509CertificateTest, Verify004, TestSize.Level0)
{
CfResult ret = g_x509CertObj->base.verify((HcfCertificate *)g_x509CertObj, nullptr);
EXPECT_NE(ret, CF_SUCCESS);
}
HWTEST_F(CryptoX509CertificateTest, GetEncoded001, TestSize.Level0)
{
CfEncodingBlob encodingBlob = { 0 };
CfResult ret = g_x509CertObj->base.getEncoded((HcfCertificate *)g_x509CertObj, &encodingBlob);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(encodingBlob.data, nullptr);
EXPECT_EQ(encodingBlob.encodingFormat, CF_FORMAT_DER);
CfEncodingBlobDataFree(&encodingBlob);
}
/* Invalid input. */
HWTEST_F(CryptoX509CertificateTest, GetEncoded002, TestSize.Level0)
{
CfResult ret = g_x509CertObj->base.getEncoded((HcfCertificate *)g_x509CertObj, nullptr);
EXPECT_NE(ret, CF_SUCCESS);
}
HWTEST_F(CryptoX509CertificateTest, GetPublicKey, TestSize.Level0)
{
HcfPubKey *keyOut = nullptr;
CfResult ret = g_x509CertObj->base.getPublicKey((HcfCertificate *)g_x509CertObj, &keyOut);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(keyOut, nullptr);
CfObjDestroy(keyOut);
}
/* Input valid date. YYMMDDHHMMSSZ */
HWTEST_F(CryptoX509CertificateTest, CheckValidityWithDate001, TestSize.Level0)
{
const char *date = "231018162433Z";
// validatetime :2022/08/19 - 2032/08/16
CfResult ret = g_x509CertObj->checkValidityWithDate(g_x509CertObj, date);
EXPECT_EQ(ret, CF_SUCCESS);
}
/* Input valid date. time format: YYYYMMDDHHMMSSZ */
HWTEST_F(CryptoX509CertificateTest, CheckValidityWithDate002, TestSize.Level0)
{
const char *date = "20231018162433Z";
// validatetime :2022/08/19 - 2032/08/16
CfResult ret = g_x509CertObj->checkValidityWithDate(g_x509CertObj, date);
EXPECT_EQ(ret, CF_SUCCESS);
}
/* Input invalid date--expiered. */
HWTEST_F(CryptoX509CertificateTest, CheckValidityWithDate003, TestSize.Level0)
{
const char *date = "20991018162433Z";
// validatetime :2022/08/19 - 2032/08/16
CfResult ret = g_x509CertObj->checkValidityWithDate(g_x509CertObj, date);
EXPECT_EQ(ret, CF_ERR_CERT_HAS_EXPIRED);
}
/* Input invalid date. */
HWTEST_F(CryptoX509CertificateTest, CheckValidityWithDate004, TestSize.Level0)
{
const char *date = "20191018162433Z";
// validatetime :2022/08/19 - 2032/08/16
CfResult ret = g_x509CertObj->checkValidityWithDate(g_x509CertObj, date);
EXPECT_EQ(ret, CF_ERR_CERT_NOT_YET_VALID);
}
/* Input invalid date form. */
HWTEST_F(CryptoX509CertificateTest, CheckValidityWithDate005, TestSize.Level0)
{
const char *date = "20191018";
// validatetime :2022/08/19 - 2032/08/16
CfResult ret = g_x509CertObj->checkValidityWithDate(g_x509CertObj, date);
EXPECT_NE(ret, CF_SUCCESS);
}
HWTEST_F(CryptoX509CertificateTest, GetVersion, TestSize.Level0)
{
long ver = g_x509CertObj->getVersion(g_x509CertObj);
EXPECT_EQ(ver, TEST_CERT_VERSION);
}
HWTEST_F(CryptoX509CertificateTest, GetSerialNumber, TestSize.Level0)
{
CfBlob out = { 0, nullptr };
CfResult ret = g_x509CertObj->getSerialNumber(g_x509CertObj, &out);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(out.data, nullptr);
EXPECT_EQ(out.size, 2); /* out size: 2 bytes */
EXPECT_EQ(out.data[0] * 0x100 + out.data[1], TEST_CERT_SERIAL_NUMBER);
CfBlobDataClearAndFree(&out);
}
HWTEST_F(CryptoX509CertificateTest, GetIssuerName001, TestSize.Level0)
{
CfBlob out = { 0 };
CfResult ret = g_x509CertObj->getIssuerName(g_x509CertObj, &out);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(out.data, nullptr);
CfBlobDataClearAndFree(&out);
}
/* invalid input. */
HWTEST_F(CryptoX509CertificateTest, GetIssuerName002, TestSize.Level0)
{
CfResult ret = g_x509CertObj->getIssuerName(g_x509CertObj, nullptr);
EXPECT_NE(ret, CF_SUCCESS);
}
HWTEST_F(CryptoX509CertificateTest, GetSubjectName001, TestSize.Level0)
{
CfBlob out = { 0 };
CfResult ret = g_x509CertObj->getSubjectName(g_x509CertObj, &out);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(out.data, nullptr);
CfBlobDataClearAndFree(&out);
}
/* invalid input. */
HWTEST_F(CryptoX509CertificateTest, GetSubjectName002, TestSize.Level0)
{
CfResult ret = g_x509CertObj->getSubjectName(g_x509CertObj, nullptr);
EXPECT_NE(ret, CF_SUCCESS);
}
HWTEST_F(CryptoX509CertificateTest, GetNotBeforeTime001, TestSize.Level0)
{
CfBlob out = { 0 };
CfResult ret = g_x509CertObj->getNotBeforeTime(g_x509CertObj, &out);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(out.data, nullptr);
CfBlobDataClearAndFree(&out);
}
/* invalid input. */
HWTEST_F(CryptoX509CertificateTest, GetNotBeforeTime002, TestSize.Level0)
{
CfResult ret = g_x509CertObj->getNotBeforeTime(g_x509CertObj, nullptr);
EXPECT_NE(ret, CF_SUCCESS);
}
HWTEST_F(CryptoX509CertificateTest, GetNotAfterTime001, TestSize.Level0)
{
CfBlob out = { 0 };
CfResult ret = g_x509CertObj->getNotAfterTime(g_x509CertObj, &out);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(out.data, nullptr);
CfBlobDataClearAndFree(&out);
}
/* invalid input. */
HWTEST_F(CryptoX509CertificateTest, GetNotAfterTime002, TestSize.Level0)
{
CfResult ret = g_x509CertObj->getNotAfterTime(g_x509CertObj, nullptr);
EXPECT_NE(ret, CF_SUCCESS);
}
HWTEST_F(CryptoX509CertificateTest, GetSignature001, TestSize.Level0)
{
CfBlob sigOut = { 0 };
CfResult ret = g_x509CertObj->getSignature(g_x509CertObj, &sigOut);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(sigOut.data, nullptr);
CfBlobDataClearAndFree(&sigOut);
}
/* invalid input. */
HWTEST_F(CryptoX509CertificateTest, GetSignature002, TestSize.Level0)
{
CfResult ret = g_x509CertObj->getSignature(g_x509CertObj, nullptr);
EXPECT_NE(ret, CF_SUCCESS);
}
HWTEST_F(CryptoX509CertificateTest, GetSignatureAlgName001, TestSize.Level0)
{
CfBlob sigAlgName = { 0 };
CfResult ret = g_x509CertObj->getSignatureAlgName(g_x509CertObj, &sigAlgName);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(sigAlgName.data, nullptr);
CfBlobDataClearAndFree(&sigAlgName);
}
/* invalid input. */
HWTEST_F(CryptoX509CertificateTest, GetSignatureAlgName002, TestSize.Level0)
{
CfResult ret = g_x509CertObj->getSignatureAlgName(g_x509CertObj, nullptr);
EXPECT_NE(ret, CF_SUCCESS);
}
HWTEST_F(CryptoX509CertificateTest, GetSignatureAlgOid001, TestSize.Level0)
{
CfBlob sigAlgOid = { 0 };
CfResult ret = g_x509CertObj->getSignatureAlgOid(g_x509CertObj, &sigAlgOid);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(sigAlgOid.data, nullptr);
CfBlobDataClearAndFree(&sigAlgOid);
}
/* invalid input. */
HWTEST_F(CryptoX509CertificateTest, GetSignatureAlgOid002, TestSize.Level0)
{
CfResult ret = g_x509CertObj->getSignatureAlgOid(g_x509CertObj, nullptr);
EXPECT_NE(ret, CF_SUCCESS);
}
HWTEST_F(CryptoX509CertificateTest, GetSignatureAlgParams001, TestSize.Level0)
{
CfBlob sigAlgParamsOut = { 0 };
CfResult ret = g_x509CertObj->getSignatureAlgParams(g_x509CertObj, &sigAlgParamsOut);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(sigAlgParamsOut.data, nullptr);
CfBlobDataClearAndFree(&sigAlgParamsOut);
}
/* invalid input. */
HWTEST_F(CryptoX509CertificateTest, GetSignatureAlgParams002, TestSize.Level0)
{
CfResult ret = g_x509CertObj->getSignatureAlgParams(g_x509CertObj, nullptr);
EXPECT_NE(ret, CF_SUCCESS);
}
HWTEST_F(CryptoX509CertificateTest, GetKeyUsage, TestSize.Level0)
{
CfBlob out = { 0 };
CfResult ret = g_x509CertObj->getKeyUsage(g_x509CertObj, &out);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(out.data, nullptr);
CfBlobDataClearAndFree(&out);
}
HWTEST_F(CryptoX509CertificateTest, GetExtKeyUsage001, TestSize.Level0)
{
CfArray keyUsageOut = { 0 };
CfResult ret = g_x509CertObj->getExtKeyUsage(g_x509CertObj, &keyUsageOut);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(keyUsageOut.data, nullptr);
CfArrayDataClearAndFree(&keyUsageOut);
}
/* Cert which has no extended key usage. */
HWTEST_F(CryptoX509CertificateTest, GetExtKeyUsage002, TestSize.Level0)
{
CfArray keyUsageOut = { 0 };
HcfX509Certificate *x509Cert = nullptr;
CfEncodingBlob inStream = { 0 };
inStream.data = (uint8_t *)g_secondCert;
inStream.encodingFormat = CF_FORMAT_PEM;
inStream.len = strlen(g_secondCert) + 1;
CfResult ret = HcfX509CertificateCreate(&inStream, &x509Cert);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(x509Cert, nullptr);
ret = x509Cert->getExtKeyUsage(x509Cert, &keyUsageOut);
EXPECT_EQ(ret, CF_ERR_CRYPTO_OPERATION);
EXPECT_EQ(keyUsageOut.data, nullptr);
CfObjDestroy(x509Cert);
}
/* not a CA cert */
HWTEST_F(CryptoX509CertificateTest, GetBasicConstraints001, TestSize.Level0)
{
HcfX509Certificate *x509Cert = nullptr;
CfEncodingBlob inStream = { 0 };
inStream.data = (uint8_t *)g_deviceTestCert;
inStream.encodingFormat = CF_FORMAT_PEM;
inStream.len = strlen(g_deviceTestCert) + 1;
CfResult ret = HcfX509CertificateCreate(&inStream, &x509Cert);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(x509Cert, nullptr);
int32_t pathLen = x509Cert->getBasicConstraints(x509Cert);
EXPECT_EQ(pathLen, -1); /* cert path len is only valid for CA. */
CfObjDestroy(x509Cert);
}
/* CA cert */
HWTEST_F(CryptoX509CertificateTest, GetBasicConstraints002, TestSize.Level0)
{
int32_t pathLen = g_x509CertObj->getBasicConstraints(g_x509CertObj);
EXPECT_EQ(pathLen, TEST_CERT_CHAIN_LEN); /* g_testSelfSignedCaCert is CA and it's path len is 2. */
}
/* invalid input. */
HWTEST_F(CryptoX509CertificateTest, GetBasicConstraints003, TestSize.Level0)
{
int32_t pathLen = g_x509CertObj->getBasicConstraints(nullptr);
EXPECT_EQ(pathLen, -1);
}
HWTEST_F(CryptoX509CertificateTest, GetSubjectAltNames001, TestSize.Level0)
{
CfArray outName = { 0 };
CfResult ret = g_x509CertObj->getSubjectAltNames(g_x509CertObj, &outName);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(outName.data, nullptr);
CfArrayDataClearAndFree(&outName);
}
/* cert without subject alternative names. */
HWTEST_F(CryptoX509CertificateTest, GetSubjectAltNames002, TestSize.Level0)
{
CfArray outName = { 0 };
HcfX509Certificate *x509Cert = nullptr;
CfEncodingBlob inStream = { 0 };
inStream.data = (uint8_t *)g_secondCert;
inStream.encodingFormat = CF_FORMAT_PEM;
inStream.len = strlen(g_secondCert) + 1;
CfResult ret = HcfX509CertificateCreate(&inStream, &x509Cert);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(x509Cert, nullptr);
ret = x509Cert->getSubjectAltNames(x509Cert, &outName);
EXPECT_EQ(ret, CF_ERR_CRYPTO_OPERATION);
EXPECT_EQ(outName.data, nullptr);
CfObjDestroy(x509Cert);
}
/* invalid input. */
HWTEST_F(CryptoX509CertificateTest, GetSubjectAltNames003, TestSize.Level0)
{
HcfX509Certificate *x509Cert = nullptr;
CfEncodingBlob inStream = { 0 };
inStream.data = (uint8_t *)g_secondCert;
inStream.encodingFormat = CF_FORMAT_PEM;
inStream.len = strlen(g_secondCert) + 1;
CfResult ret = HcfX509CertificateCreate(&inStream, &x509Cert);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(x509Cert, nullptr);
ret = x509Cert->getSubjectAltNames(x509Cert, nullptr);
EXPECT_EQ(ret, CF_INVALID_PARAMS);
CfObjDestroy(x509Cert);
}
HWTEST_F(CryptoX509CertificateTest, GetIssuerAltNames001, TestSize.Level0)
{
CfArray outName = { 0 };
CfResult ret = g_x509CertObj->getIssuerAltNames(g_x509CertObj, &outName);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(outName.data, nullptr);
CfArrayDataClearAndFree(&outName);
}
/* cert without issuer alternative names. */
HWTEST_F(CryptoX509CertificateTest, GetIssuerAltNames002, TestSize.Level0)
{
CfArray outName = { 0 };
HcfX509Certificate *x509Cert = nullptr;
CfEncodingBlob inStream = { 0 };
inStream.data = (uint8_t *)g_secondCert;
inStream.encodingFormat = CF_FORMAT_PEM;
inStream.len = strlen(g_secondCert) + 1;
CfResult ret = HcfX509CertificateCreate(&inStream, &x509Cert);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(x509Cert, nullptr);
ret = x509Cert->getIssuerAltNames(x509Cert, &outName);
EXPECT_EQ(ret, CF_ERR_CRYPTO_OPERATION);
EXPECT_EQ(outName.data, nullptr);
CfObjDestroy(x509Cert);
}
/* invalid input. */
HWTEST_F(CryptoX509CertificateTest, GetIssuerAltNames003, TestSize.Level0)
{
HcfX509Certificate *x509Cert = nullptr;
CfEncodingBlob inStream = { 0 };
inStream.data = (uint8_t *)g_secondCert;
inStream.encodingFormat = CF_FORMAT_PEM;
inStream.len = strlen(g_secondCert) + 1;
CfResult ret = HcfX509CertificateCreate(&inStream, &x509Cert);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(x509Cert, nullptr);
ret = x509Cert->getIssuerAltNames(x509Cert, nullptr);
EXPECT_EQ(ret, CF_INVALID_PARAMS);
CfObjDestroy(x509Cert);
}
/* oid is nullptr */
HWTEST_F(CryptoX509CertificateTest, GetAlgorithmName001, TestSize.Level0)
{
const char *str = GetAlgorithmName(nullptr);
EXPECT_EQ(str, nullptr);
}
/* oid not found */
HWTEST_F(CryptoX509CertificateTest, GetAlgorithmName002, TestSize.Level0)
{
char oid[] = "1.2.840.113549.1.1.255";
const char *str = GetAlgorithmName(oid);
EXPECT_EQ(str, nullptr);
}
HWTEST_F(CryptoX509CertificateTest, NullInput, TestSize.Level0)
{
(void)HcfX509CertificateCreate(nullptr, nullptr);
HcfPubKey *keyOut = nullptr;
CfResult ret = g_x509CertObj->base.getPublicKey((HcfCertificate *)g_x509CertObj, &keyOut);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(keyOut, nullptr);
(void)g_x509CertObj->base.base.destroy(nullptr);
(void)keyOut->base.getAlgorithm(&(keyOut->base));
(void)keyOut->base.getEncoded(&(keyOut->base), nullptr);
(void)keyOut->base.getFormat(&(keyOut->base));
ret = g_x509CertObj->base.verify(nullptr, nullptr);
EXPECT_NE(ret, CF_SUCCESS);
ret = g_x509CertObj->base.getEncoded(nullptr, nullptr);
EXPECT_NE(ret, CF_SUCCESS);
ret = g_x509CertObj->base.getPublicKey(nullptr, nullptr);
EXPECT_NE(ret, CF_SUCCESS);
(void)g_x509CertObj->checkValidityWithDate(nullptr, nullptr);
(void)g_x509CertObj->getVersion(nullptr);
(void)g_x509CertObj->getSerialNumber(nullptr, nullptr);
(void)g_x509CertObj->getIssuerName(nullptr, nullptr);
(void)g_x509CertObj->getSubjectName(nullptr, nullptr);
(void)g_x509CertObj->getNotBeforeTime(nullptr, nullptr);
(void)g_x509CertObj->getNotAfterTime(nullptr, nullptr);
(void)g_x509CertObj->getSignature(nullptr, nullptr);
(void)g_x509CertObj->getSignatureAlgName(nullptr, nullptr);
(void)g_x509CertObj->getSignatureAlgOid(nullptr, nullptr);
(void)g_x509CertObj->getSignatureAlgParams(nullptr, nullptr);
(void)g_x509CertObj->getKeyUsage(nullptr, nullptr);
(void)g_x509CertObj->getExtKeyUsage(nullptr, nullptr);
(void)g_x509CertObj->getBasicConstraints(nullptr);
(void)g_x509CertObj->getSubjectAltNames(nullptr, nullptr);
(void)g_x509CertObj->getIssuerAltNames(nullptr, nullptr);
CfObjDestroy(keyOut);
}
HWTEST_F(CryptoX509CertificateTest, NullSpiInput, TestSize.Level0)
{
HcfX509CertificateSpi *spiObj = nullptr;
CfEncodingBlob inStream = { 0 };
inStream.data = (uint8_t *)g_testSelfSignedCaCert;
inStream.encodingFormat = CF_FORMAT_PEM;
inStream.len = strlen(g_testSelfSignedCaCert) + 1;
(void)OpensslX509CertSpiCreate(nullptr, nullptr);
CfResult ret = OpensslX509CertSpiCreate(&inStream, &spiObj);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(spiObj, nullptr);
(void)spiObj->base.destroy(nullptr);
ret = spiObj->engineVerify(nullptr, nullptr);
ret = spiObj->engineGetEncoded(nullptr, nullptr);
ret = spiObj->engineGetPublicKey(nullptr, nullptr);
EXPECT_NE(ret, CF_SUCCESS);
ret = spiObj->engineCheckValidityWithDate(nullptr, nullptr);
EXPECT_NE(ret, CF_SUCCESS);
long ver = spiObj->engineGetVersion(nullptr);
EXPECT_EQ(ver, -1);
ret = spiObj->engineGetSerialNumber(nullptr, nullptr);
ret = spiObj->engineGetIssuerName(nullptr, nullptr);
ret = spiObj->engineGetSubjectName(nullptr, nullptr);
ret = spiObj->engineGetNotBeforeTime(nullptr, nullptr);
ret = spiObj->engineGetNotAfterTime(nullptr, nullptr);
ret = spiObj->engineGetSignature(nullptr, nullptr);
ret = spiObj->engineGetSignatureAlgName(nullptr, nullptr);
ret = spiObj->engineGetSignatureAlgOid(nullptr, nullptr);
ret = spiObj->engineGetSignatureAlgParams(nullptr, nullptr);
ret = spiObj->engineGetKeyUsage(nullptr, nullptr);
ret = spiObj->engineGetExtKeyUsage(nullptr, nullptr);
EXPECT_NE(ret, CF_SUCCESS);
long basicLen = spiObj->engineGetBasicConstraints(nullptr);
EXPECT_EQ(basicLen, -1);
ret = spiObj->engineGetSubjectAltNames(nullptr, nullptr);
EXPECT_NE(ret, CF_SUCCESS);
ret = spiObj->engineGetIssuerAltNames(nullptr, nullptr);
EXPECT_NE(ret, CF_SUCCESS);
CfObjDestroy(spiObj);
}
static const char *GetInvalidCertClass(void)
{
return "INVALID_CERT_CLASS";
}
HWTEST_F(CryptoX509CertificateTest, InvalidSpiClass, TestSize.Level0)
{
HcfX509CertificateSpi *spiObj = nullptr;
HcfX509CertificateSpi invalidSpi = { {0} };
invalidSpi.base.getClass = GetInvalidCertClass;
CfBlob invalidOut = { 0 };
CfEncodingBlob inStream = { 0 };
inStream.data = (uint8_t *)g_testSelfSignedCaCert;
inStream.encodingFormat = CF_FORMAT_PEM;
inStream.len = strlen(g_testSelfSignedCaCert) + 1;
CfResult ret = OpensslX509CertSpiCreate(&inStream, &spiObj);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(spiObj, nullptr);
(void)spiObj->base.destroy(&(invalidSpi.base));
HcfPubKey pubKey;
ret = spiObj->engineVerify(&invalidSpi, &pubKey);
EXPECT_NE(ret, CF_SUCCESS);
ret = spiObj->engineGetEncoded(&invalidSpi, &inStream);
EXPECT_NE(ret, CF_SUCCESS);
HcfPubKey *pubKeyOut = nullptr;
ret = spiObj->engineGetPublicKey(&invalidSpi, &pubKeyOut);
EXPECT_NE(ret, CF_SUCCESS);
const char *date = "2020";
ret = spiObj->engineCheckValidityWithDate(&invalidSpi, date);
EXPECT_NE(ret, CF_SUCCESS);
long ver = spiObj->engineGetVersion(&invalidSpi);
EXPECT_EQ(ver, -1);
ret = spiObj->engineGetSerialNumber(&invalidSpi, &invalidOut);
ret = spiObj->engineGetIssuerName(&invalidSpi, &invalidOut);
ret = spiObj->engineGetSubjectName(&invalidSpi, &invalidOut);
ret = spiObj->engineGetNotBeforeTime(&invalidSpi, &invalidOut);
ret = spiObj->engineGetNotAfterTime(&invalidSpi, &invalidOut);
ret = spiObj->engineGetSignature(&invalidSpi, &invalidOut);
ret = spiObj->engineGetSignatureAlgName(&invalidSpi, &invalidOut);
ret = spiObj->engineGetSignatureAlgOid(&invalidSpi, &invalidOut);
ret = spiObj->engineGetSignatureAlgParams(&invalidSpi, &invalidOut);
ret = spiObj->engineGetKeyUsage(&invalidSpi, &invalidOut);
CfArray invalidArr = { 0 };
ret = spiObj->engineGetExtKeyUsage(&invalidSpi, &invalidArr);
long basicLen = spiObj->engineGetBasicConstraints(&invalidSpi);
EXPECT_EQ(basicLen, -1);
ret = spiObj->engineGetSubjectAltNames(&invalidSpi, &invalidArr);
ret = spiObj->engineGetIssuerAltNames(&invalidSpi, &invalidArr);
EXPECT_NE(ret, CF_SUCCESS);
CfObjDestroy(spiObj);
}
HWTEST_F(CryptoX509CertificateTest, InvalidCertClass, TestSize.Level0)
{
HcfX509Certificate invalidCert;
invalidCert.base.base.getClass = GetInvalidCertClass;
CfBlob invalidOut = { 0 };
CfEncodingBlob inStream = { 0 };
HcfPubKey keyOut;
g_x509CertObj->base.base.destroy(&(invalidCert.base.base));
CfResult ret = g_x509CertObj->base.verify(&(invalidCert.base), &keyOut);
EXPECT_NE(ret, CF_SUCCESS);
ret = g_x509CertObj->base.getEncoded(&(invalidCert.base), &inStream);
EXPECT_NE(ret, CF_SUCCESS);
HcfPubKey *pubKeyOut = nullptr;
ret = g_x509CertObj->base.getPublicKey(&(invalidCert.base), &pubKeyOut);
EXPECT_NE(ret, CF_SUCCESS);
const char *date = "2020";
ret = g_x509CertObj->checkValidityWithDate(&invalidCert, date);
long ver = g_x509CertObj->getVersion(&invalidCert);
EXPECT_EQ(ver, -1);
ret = g_x509CertObj->getSerialNumber(&invalidCert, &invalidOut);
ret = g_x509CertObj->getIssuerName(&invalidCert, &invalidOut);
ret = g_x509CertObj->getSubjectName(&invalidCert, &invalidOut);
ret = g_x509CertObj->getNotBeforeTime(&invalidCert, &invalidOut);
ret = g_x509CertObj->getNotAfterTime(&invalidCert, &invalidOut);
ret = g_x509CertObj->getSignature(&invalidCert, &invalidOut);
ret = g_x509CertObj->getSignatureAlgName(&invalidCert, &invalidOut);
ret = g_x509CertObj->getSignatureAlgOid(&invalidCert, &invalidOut);
ret = g_x509CertObj->getSignatureAlgParams(&invalidCert, &invalidOut);
ret = g_x509CertObj->getKeyUsage(&invalidCert, &invalidOut);
CfArray invalidArr = { 0 };
ret = g_x509CertObj->getExtKeyUsage(&invalidCert, &invalidArr);
long basicLen = g_x509CertObj->getBasicConstraints(&invalidCert);
EXPECT_EQ(basicLen, -1);
ret = g_x509CertObj->getSubjectAltNames(&invalidCert, &invalidArr);
ret = g_x509CertObj->getIssuerAltNames(&invalidCert, &invalidArr);
EXPECT_NE(ret, CF_SUCCESS);
}
HWTEST_F(CryptoX509CertificateTest, InvalidMalloc, TestSize.Level0)
{
SetMockFlag(true);
HcfX509Certificate *x509Cert = nullptr;
CfEncodingBlob inStream = { 0 };
inStream.data = (uint8_t *)g_secondCert;
inStream.encodingFormat = CF_FORMAT_PEM;
inStream.len = strlen(g_secondCert) + 1;
CfResult ret = HcfX509CertificateCreate(&inStream, &x509Cert);
EXPECT_NE(ret, CF_SUCCESS);
CfBlob out = { 0 };
CfArray arr = { 0 };
ret = g_x509CertObj->base.getEncoded(&(g_x509CertObj->base), &inStream);
EXPECT_NE(ret, CF_SUCCESS);
HcfPubKey *pubKeyOut = nullptr;
ret = g_x509CertObj->base.getPublicKey(&(g_x509CertObj->base), &pubKeyOut);
EXPECT_NE(ret, CF_SUCCESS);
const char *date = "2020";
ret = g_x509CertObj->checkValidityWithDate(g_x509CertObj, date);
ret = g_x509CertObj->getIssuerName(g_x509CertObj, &out);
ret = g_x509CertObj->getSubjectName(g_x509CertObj, &out);
ret = g_x509CertObj->getNotBeforeTime(g_x509CertObj, &out);
ret = g_x509CertObj->getNotAfterTime(g_x509CertObj, &out);
ret = g_x509CertObj->getSignature(g_x509CertObj, &out);
ret = g_x509CertObj->getSignatureAlgName(g_x509CertObj, &out);
ret = g_x509CertObj->getSignatureAlgOid(g_x509CertObj, &out);
EXPECT_NE(ret, CF_SUCCESS);
ret = g_x509CertObj->getSignatureAlgParams(g_x509CertObj, &out);
ret = g_x509CertObj->getKeyUsage(g_x509CertObj, &out);
EXPECT_NE(ret, CF_SUCCESS);
ret = g_x509CertObj->getExtKeyUsage(g_x509CertObj, &arr);
ret = g_x509CertObj->getSubjectAltNames(g_x509CertObj, &arr);
ret = g_x509CertObj->getIssuerAltNames(g_x509CertObj, &arr);
EXPECT_NE(ret, CF_SUCCESS);
SetMockFlag(false);
}
}

View File

@ -0,0 +1,112 @@
/*
* Copyright (c) 2023 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.
*/
#include "securec.h"
#include <gtest/gtest.h>
#include <openssl/x509.h>
#include "asy_key_generator.h"
#include "cipher.h"
#include "key_pair.h"
#include "cf_memory.h"
#include "memory_mock.h"
#include "certificate_openssl_class.h"
#include "x509_crl.h"
#include "x509_crl_openssl.h"
#include "x509_crl_entry_openssl.h"
using namespace std;
using namespace testing::ext;
namespace {
HcfX509Crl *g_x509Crl = nullptr;
class CryptoX509CrlTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
static uint8_t g_crlDerData[] = {
0x30, 0x82, 0x01, 0xE3, 0x30, 0x81, 0xCC, 0x02, 0x01, 0x01, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86,
0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, 0x30, 0x2C, 0x31, 0x0B, 0x30, 0x09, 0x06,
0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x43, 0x4E, 0x31, 0x0D, 0x30, 0x0B, 0x06, 0x03, 0x55, 0x04,
0x0A, 0x0C, 0x04, 0x74, 0x65, 0x73, 0x74, 0x31, 0x0E, 0x30, 0x0C, 0x06, 0x03, 0x55, 0x04, 0x03,
0x0C, 0x05, 0x73, 0x75, 0x62, 0x63, 0x61, 0x17, 0x0D, 0x32, 0x33, 0x30, 0x39, 0x31, 0x32, 0x30,
0x36, 0x34, 0x37, 0x35, 0x30, 0x5A, 0x17, 0x0D, 0x32, 0x33, 0x31, 0x30, 0x31, 0x32, 0x30, 0x36,
0x34, 0x37, 0x35, 0x30, 0x5A, 0x30, 0x3B, 0x30, 0x13, 0x02, 0x02, 0x03, 0xE8, 0x17, 0x0D, 0x32,
0x33, 0x30, 0x39, 0x31, 0x32, 0x30, 0x36, 0x34, 0x37, 0x34, 0x39, 0x5A, 0x30, 0x24, 0x02, 0x13,
0x17, 0x5D, 0x6A, 0x9F, 0xEC, 0xA9, 0x09, 0xD7, 0x12, 0xB2, 0x48, 0x52, 0xA6, 0x3E, 0x48, 0xF6,
0x12, 0x93, 0xA9, 0x17, 0x0D, 0x32, 0x33, 0x30, 0x39, 0x31, 0x32, 0x30, 0x36, 0x34, 0x32, 0x35,
0x34, 0x5A, 0xA0, 0x2F, 0x30, 0x2D, 0x30, 0x1F, 0x06, 0x03, 0x55, 0x1D, 0x23, 0x04, 0x18, 0x30,
0x16, 0x80, 0x14, 0x22, 0x2B, 0x18, 0xDE, 0x84, 0xD9, 0x30, 0x4E,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, 0x3E, 0xE0, 0x35, 0xC9, 0x24, 0x22, 0x94, 0xD3, 0x71, 0xC4, 0x0B,
0xCE, 0x81, 0x0B, 0x14, 0x31, 0xBC, 0xFF, 0x3F, 0x9B, 0x3A, 0x70, 0x2E, 0x4A, 0x0D, 0x65, 0x64,
0x2C, 0xAF, 0xF5, 0xF3, 0xB3, 0xF6, 0x55, 0x5A, 0x7C, 0x2F, 0xAA, 0x68, 0x7A, 0x3E, 0x35, 0x6F,
0x6B, 0x74, 0x28, 0x71, 0x57, 0x5A, 0x02, 0xE5, 0x2E, 0xA3, 0x1D, 0x3B, 0xBC, 0xEF, 0xD0, 0x8E,
0x31, 0x09, 0xCB, 0xAF, 0x78, 0xC4, 0x04, 0x2B, 0x33, 0x37, 0x30, 0xE3, 0x14, 0x8E, 0xB8, 0x97,
0xA7, 0xF7, 0x25, 0x59, 0xCB, 0x65, 0xEA, 0x69, 0xE8, 0xD5, 0x35, 0x81, 0xDB, 0xA7, 0x8D, 0x02,
0xF8, 0x82, 0xD5, 0x90, 0x5D, 0x91, 0x65, 0x15, 0x5E, 0xF9, 0xC5, 0x1F, 0x1A, 0x6A, 0x17, 0x7C,
0xB1, 0xE0, 0x79, 0xA0, 0x34, 0xCF, 0x42
};
const CfEncodingBlob g_crlDerInStream = {
g_crlDerData,
sizeof(g_crlDerData),
CF_FORMAT_DER
};
void CryptoX509CrlTest::SetUpTestCase()
{
HcfX509Crl *x509Crl = nullptr;
int32_t ret = HcfX509CrlCreate(&g_crlDerInStream, &x509Crl);
ASSERT_EQ(ret, 0);
g_x509Crl = x509Crl;
}
void CryptoX509CrlTest::TearDownTestCase()
{
if (g_x509Crl != nullptr) {
CfObjDestroy(g_x509Crl);
g_x509Crl = nullptr;
}
}
void CryptoX509CrlTest::SetUp() {}
void CryptoX509CrlTest::TearDown() {}
// Test crl create DER true
HWTEST_F(CryptoX509CrlTest, X509CrlTest002, TestSize.Level0)
{
HcfX509Crl *x509Crl = nullptr;
CfResult ret = HcfX509CrlCreate(&g_crlDerInStream, &x509Crl);
EXPECT_EQ(ret, CF_SUCCESS);
EXPECT_NE(x509Crl, nullptr);
CfObjDestroy(x509Crl);
}
}

View File

@ -0,0 +1,89 @@
/*
* Copyright (c) 2023 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.
*/
#include "cf_memory.h"
#include "memory_mock.h"
#include "cf_log.h"
#include "securec.h"
static bool g_isMock = false;
static uint32_t g_mallocMockIndex = __INT32_MAX__;
static uint32_t g_mallocNum = 0;
static bool g_isRecordMallocNum = false;
void SetMockFlag(bool flag)
{
g_isMock = flag;
}
void *HcfMalloc(uint32_t size, char val)
{
if (g_isMock) {
return NULL;
}
if (g_isRecordMallocNum) {
if (g_mallocNum == g_mallocMockIndex) {
LOGI("mock malloc return NULL.");
return NULL;
}
g_mallocNum++;
}
void *addr = malloc(size);
if (addr != NULL) {
(void)memset_s(addr, size, val, size);
}
return addr;
}
void *CfMalloc(uint32_t size)
{
return HcfMalloc(size, 0);
}
void CfFree(void *addr)
{
if (addr != NULL) {
free(addr);
}
}
void StartRecordMallocNum(void)
{
ResetRecordMallocNum();
g_isRecordMallocNum = true;
}
void EndRecordMallocNum(void)
{
ResetRecordMallocNum();
g_isRecordMallocNum = false;
}
uint32_t GetMallocNum(void)
{
return g_mallocNum;
}
void ResetRecordMallocNum(void)
{
g_mallocNum = 0;
g_mallocMockIndex = __INT32_MAX__;
}
void SetMockMallocIndex(uint32_t index)
{
g_mallocMockIndex = index;
}