From c33d4129abc282cd3669aa37ce2f6482e9310430 Mon Sep 17 00:00:00 2001 From: jchx Date: Wed, 10 Apr 2024 15:50:04 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=AE=97=E6=B3=95=E5=BA=93=E9=80=82?= =?UTF-8?q?=E9=85=8D=E5=B1=82=E3=80=91=E6=8F=90=E4=BE=9BPKCS8=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E7=9A=84ECC=E7=A7=81=E9=92=A5=E5=9F=BA=E4=BA=8ERFC520?= =?UTF-8?q?8=E8=A7=84=E8=8C=83=E5=92=8CRFC5915=E8=A7=84=E8=8C=83=E7=9A=84?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E8=83=BD=E5=8A=9Bissue=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/crypto_operation/mac.c | 2 +- frameworks/js/napi/crypto/inc/napi_pri_key.h | 2 +- .../js/napi/crypto/src/napi_pri_key.cpp | 2 +- frameworks/key/sym_key_generator.c | 2 +- interfaces/innerkits/key/pri_key.h | 2 +- .../common/inc/openssl_adapter.h | 2 +- .../common/src/openssl_adapter.c | 2 +- .../crypto_operation/hmac/src/mac_openssl.c | 2 +- .../src/alg_25519_asy_key_generator_openssl.c | 2 +- .../src/dh_asy_key_generator_openssl.c | 2 +- .../src/dsa_asy_key_generator_openssl.c | 2 +- .../src/ecc_asy_key_generator_openssl.c | 23 +++++++------------ .../src/rsa_asy_key_generator_openssl.c | 2 +- .../src/sm2_asy_key_generator_openssl.c | 2 +- .../src/crypto_ecc_asy_key_generator_test.cpp | 2 +- test/unittest/src/crypto_mac_test.cpp | 2 +- 16 files changed, 23 insertions(+), 30 deletions(-) diff --git a/frameworks/crypto_operation/mac.c b/frameworks/crypto_operation/mac.c index 3b1ef75..2068525 100644 --- a/frameworks/crypto_operation/mac.c +++ b/frameworks/crypto_operation/mac.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. + * Copyright (C) 2022-2024 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 diff --git a/frameworks/js/napi/crypto/inc/napi_pri_key.h b/frameworks/js/napi/crypto/inc/napi_pri_key.h index f0eacb2..8ac93c0 100644 --- a/frameworks/js/napi/crypto/inc/napi_pri_key.h +++ b/frameworks/js/napi/crypto/inc/napi_pri_key.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2022-2024 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 diff --git a/frameworks/js/napi/crypto/src/napi_pri_key.cpp b/frameworks/js/napi/crypto/src/napi_pri_key.cpp index 9a75e3c..1292c02 100644 --- a/frameworks/js/napi/crypto/src/napi_pri_key.cpp +++ b/frameworks/js/napi/crypto/src/napi_pri_key.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. + * Copyright (C) 2022-2024 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 diff --git a/frameworks/key/sym_key_generator.c b/frameworks/key/sym_key_generator.c index fff1a09..ada99b9 100644 --- a/frameworks/key/sym_key_generator.c +++ b/frameworks/key/sym_key_generator.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. + * Copyright (C) 2022-2024 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 diff --git a/interfaces/innerkits/key/pri_key.h b/interfaces/innerkits/key/pri_key.h index b1cf00f..8d42bd1 100644 --- a/interfaces/innerkits/key/pri_key.h +++ b/interfaces/innerkits/key/pri_key.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. + * Copyright (C) 2022-2024 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 diff --git a/plugin/openssl_plugin/common/inc/openssl_adapter.h b/plugin/openssl_plugin/common/inc/openssl_adapter.h index 9fc1480..23dc64d 100644 --- a/plugin/openssl_plugin/common/inc/openssl_adapter.h +++ b/plugin/openssl_plugin/common/inc/openssl_adapter.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. + * Copyright (C) 2022-2024 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 diff --git a/plugin/openssl_plugin/common/src/openssl_adapter.c b/plugin/openssl_plugin/common/src/openssl_adapter.c index 4ae8ffe..a7e647d 100644 --- a/plugin/openssl_plugin/common/src/openssl_adapter.c +++ b/plugin/openssl_plugin/common/src/openssl_adapter.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. + * Copyright (C) 2022-2024 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 diff --git a/plugin/openssl_plugin/crypto_operation/hmac/src/mac_openssl.c b/plugin/openssl_plugin/crypto_operation/hmac/src/mac_openssl.c index b8968b0..09fac6f 100644 --- a/plugin/openssl_plugin/crypto_operation/hmac/src/mac_openssl.c +++ b/plugin/openssl_plugin/crypto_operation/hmac/src/mac_openssl.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2022-2024 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 diff --git a/plugin/openssl_plugin/key/asy_key_generator/src/alg_25519_asy_key_generator_openssl.c b/plugin/openssl_plugin/key/asy_key_generator/src/alg_25519_asy_key_generator_openssl.c index 63bdab9..13934f9 100644 --- a/plugin/openssl_plugin/key/asy_key_generator/src/alg_25519_asy_key_generator_openssl.c +++ b/plugin/openssl_plugin/key/asy_key_generator/src/alg_25519_asy_key_generator_openssl.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Huawei Device Co., Ltd. + * Copyright (C) 2022-2024 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 diff --git a/plugin/openssl_plugin/key/asy_key_generator/src/dh_asy_key_generator_openssl.c b/plugin/openssl_plugin/key/asy_key_generator/src/dh_asy_key_generator_openssl.c index 479c3dd..45f505d 100644 --- a/plugin/openssl_plugin/key/asy_key_generator/src/dh_asy_key_generator_openssl.c +++ b/plugin/openssl_plugin/key/asy_key_generator/src/dh_asy_key_generator_openssl.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Huawei Device Co., Ltd. + * Copyright (C) 2022-2024 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 diff --git a/plugin/openssl_plugin/key/asy_key_generator/src/dsa_asy_key_generator_openssl.c b/plugin/openssl_plugin/key/asy_key_generator/src/dsa_asy_key_generator_openssl.c index 2f8f816..47b59be 100644 --- a/plugin/openssl_plugin/key/asy_key_generator/src/dsa_asy_key_generator_openssl.c +++ b/plugin/openssl_plugin/key/asy_key_generator/src/dsa_asy_key_generator_openssl.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Huawei Device Co., Ltd. + * Copyright (C) 2022-2024 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 diff --git a/plugin/openssl_plugin/key/asy_key_generator/src/ecc_asy_key_generator_openssl.c b/plugin/openssl_plugin/key/asy_key_generator/src/ecc_asy_key_generator_openssl.c index 4efd6a1..da008e1 100644 --- a/plugin/openssl_plugin/key/asy_key_generator/src/ecc_asy_key_generator_openssl.c +++ b/plugin/openssl_plugin/key/asy_key_generator/src/ecc_asy_key_generator_openssl.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. + * Copyright (C) 2022-2024 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 @@ -1105,7 +1105,7 @@ static HcfResult ParamCheck(const HcfPriKey *self, const char *format, HcfBlob * static HcfResult CopyMemFromBIO(BIO *bio, HcfBlob *returnBlob) { int len = BIO_pending(bio); - if (len < 0) { + if (len <= 0) { LOGE("Bio len less than 0."); return HCF_INVALID_PARAMS; } @@ -1150,7 +1150,7 @@ static HcfResult GetECPriKeyEncodedDer(const HcfPriKey *self, const char *format if (Openssl_EVP_PKEY_set1_EC_KEY(pkey, impl->ecKey) != HCF_OPENSSL_SUCCESS) { Openssl_EVP_PKEY_free(pkey); HcfPrintOpensslError(); - LOGE("Assign ec failed."); + LOGE("set ec key failed."); return HCF_ERR_CRYPTO_OPERATION; } BIO *bio = Openssl_BIO_new(Openssl_BIO_s_mem()); @@ -1166,10 +1166,9 @@ static HcfResult GetECPriKeyEncodedDer(const HcfPriKey *self, const char *format ret = HCF_ERR_CRYPTO_OPERATION; goto ERR1; } - if (CopyMemFromBIO(bio, returnBlob) != HCF_SUCCESS) { + ret = CopyMemFromBIO(bio, returnBlob); + if (ret != HCF_SUCCESS) { LOGE("Copy mem from BIO fail."); - ret = HCF_ERR_CRYPTO_OPERATION; - goto ERR1; } ERR1: Openssl_BIO_free_all(bio); @@ -1501,17 +1500,11 @@ static HcfResult ConvertEcPubKey(int32_t curveId, HcfBlob *pubKeyBlob, HcfOpenss static HcfResult ConvertPriFromEncoded(EC_KEY **eckey, HcfBlob *priKeyBlob) { - EVP_PKEY *pkey = Openssl_EVP_PKEY_new(); - if (pkey == NULL) { - HcfPrintOpensslError(); - LOGE("New pKey failed."); - return HCF_ERR_CRYPTO_OPERATION; - } const unsigned char *tmpData = (const unsigned char *)(priKeyBlob->data); - if (Openssl_d2i_PrivateKey(EVP_PKEY_EC, &pkey, &tmpData, priKeyBlob->len) == NULL) { + EVP_PKEY *pkey = Openssl_d2i_PrivateKey(EVP_PKEY_EC, NULL, &tmpData, priKeyBlob->len); + if (pkey == NULL) { HcfPrintOpensslError(); - LOGE("Assign ec key to evp key failed."); - Openssl_EVP_PKEY_free(pkey); + LOGE("d2i pri key failed."); return HCF_ERR_CRYPTO_OPERATION; } *eckey = EVP_PKEY_get1_EC_KEY(pkey); diff --git a/plugin/openssl_plugin/key/asy_key_generator/src/rsa_asy_key_generator_openssl.c b/plugin/openssl_plugin/key/asy_key_generator/src/rsa_asy_key_generator_openssl.c index 5f45ae7..bddb384 100644 --- a/plugin/openssl_plugin/key/asy_key_generator/src/rsa_asy_key_generator_openssl.c +++ b/plugin/openssl_plugin/key/asy_key_generator/src/rsa_asy_key_generator_openssl.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. + * Copyright (C) 2022-2024 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 diff --git a/plugin/openssl_plugin/key/asy_key_generator/src/sm2_asy_key_generator_openssl.c b/plugin/openssl_plugin/key/asy_key_generator/src/sm2_asy_key_generator_openssl.c index b85ee37..4bbb00d 100644 --- a/plugin/openssl_plugin/key/asy_key_generator/src/sm2_asy_key_generator_openssl.c +++ b/plugin/openssl_plugin/key/asy_key_generator/src/sm2_asy_key_generator_openssl.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Huawei Device Co., Ltd. + * Copyright (C) 2022-2024 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 diff --git a/test/unittest/src/crypto_ecc_asy_key_generator_test.cpp b/test/unittest/src/crypto_ecc_asy_key_generator_test.cpp index 334ef18..0590d7f 100644 --- a/test/unittest/src/crypto_ecc_asy_key_generator_test.cpp +++ b/test/unittest/src/crypto_ecc_asy_key_generator_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. + * Copyright (C) 2022-2024 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 diff --git a/test/unittest/src/crypto_mac_test.cpp b/test/unittest/src/crypto_mac_test.cpp index 76fb25a..53e5c40 100644 --- a/test/unittest/src/crypto_mac_test.cpp +++ b/test/unittest/src/crypto_mac_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. + * Copyright (C) 2022-2024 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 -- Gitee