18e920a95Sopenharmony_ci/*
28e920a95Sopenharmony_ci * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
38e920a95Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
48e920a95Sopenharmony_ci * you may not use this file except in compliance with the License.
58e920a95Sopenharmony_ci * You may obtain a copy of the License at
68e920a95Sopenharmony_ci *
78e920a95Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
88e920a95Sopenharmony_ci *
98e920a95Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
108e920a95Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
118e920a95Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
128e920a95Sopenharmony_ci * See the License for the specific language governing permissions and
138e920a95Sopenharmony_ci * limitations under the License.
148e920a95Sopenharmony_ci */
158e920a95Sopenharmony_ci
168e920a95Sopenharmony_ci#ifndef CODE_SIGN_OPENSSL_UTILS_H
178e920a95Sopenharmony_ci#define CODE_SIGN_OPENSSL_UTILS_H
188e920a95Sopenharmony_ci
198e920a95Sopenharmony_ci#include <string>
208e920a95Sopenharmony_ci#include <vector>
218e920a95Sopenharmony_ci#include <openssl/x509.h>
228e920a95Sopenharmony_ci#include <openssl/err.h>
238e920a95Sopenharmony_ci
248e920a95Sopenharmony_ci#include "byte_buffer.h"
258e920a95Sopenharmony_ci#include "log.h"
268e920a95Sopenharmony_ci
278e920a95Sopenharmony_cinamespace OHOS {
288e920a95Sopenharmony_cinamespace Security {
298e920a95Sopenharmony_cinamespace CodeSign {
308e920a95Sopenharmony_ciconstexpr int OPENSSL_ERR_MESSAGE_MAX_LEN = 1024;
318e920a95Sopenharmony_ci
328e920a95Sopenharmony_civoid GetOpensslErrorMessage();
338e920a95Sopenharmony_ci
348e920a95Sopenharmony_ci#define ERR_LOG_WITH_OPEN_SSL_MSG(msg) do { \
358e920a95Sopenharmony_ci    LOG_ERROR("%{public}s", msg); \
368e920a95Sopenharmony_ci    GetOpensslErrorMessage(); \
378e920a95Sopenharmony_ci} while (0)
388e920a95Sopenharmony_ci
398e920a95Sopenharmony_ciX509 *LoadCertFromBuffer(const uint8_t *buffer, const uint32_t size);
408e920a95Sopenharmony_ciSTACK_OF(X509) *MakeStackOfCerts(const std::vector<ByteBuffer> &certChain);
418e920a95Sopenharmony_ciint CreateNIDFromOID(const std::string &oid, const std::string &shortName,
428e920a95Sopenharmony_ci    const std::string &longName);
438e920a95Sopenharmony_cibool ConvertCertToPEMString(const ByteBuffer &cert, std::string &pemString);
448e920a95Sopenharmony_ci}
458e920a95Sopenharmony_ci}
468e920a95Sopenharmony_ci}
478e920a95Sopenharmony_ci#endif