• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OPENSSL_UTIL_H
17 #define OPENSSL_UTIL_H
18 
19 #include <vector>
20 #include <openssl/asn1.h>
21 #include "pkg_manager.h"
22 #include "pkg_stream.h"
23 
24 namespace Hpackage {
25 int32_t GetASN1OctetStringData(const ASN1_OCTET_STRING *octString, std::vector<uint8_t> &asn1Data);
26 int32_t GetX509AlgorithmNid(const X509_ALGOR *x509Algo, int32_t &algoNid);
27 X509 *GetX509CertFromPemString(const std::string &pemString);
28 X509 *GetX509CertFromPemFile(const std::string &filePath);
29 std::string GetStringFromX509Name(X509_NAME *x509Name);
30 std::string GetX509CertSubjectName(X509 *cert);
31 std::string GetX509CertIssuerName(X509 *cert);
32 bool VerifyX509CertByIssuerCert(X509 *cert, X509 *issuerCert);
33 int32_t VerifyDigestByPubKey(EVP_PKEY *pubKey, const int nid, const std::vector<uint8_t> &digestData,
34     const std::vector<uint8_t> &signature);
35 int32_t CalcSha256Digest(const Hpackage::PkgStreamPtr srcData, const size_t dataLen, std::vector<uint8_t> &result);
36 }
37 
38 #endif
39