• 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 CERT_MANAGER_X509_H
17 #define CERT_MANAGER_X509_H
18 
19 #include <stdint.h>
20 #include <stdlib.h>
21 #include <openssl/x509.h>
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #define SN_MAX_SIZE 64
27 #define TIME_FORMAT_MAX_SIZE 16
28 #define NAME_MAX_SIZE 256
29 #define FINGERPRINT_MAX_SIZE  128
30 #define NAME_DELIMITER_SIZE 2
31 #define NAME_ANS1TIME_LEN   12
32 
33 #define CM_COMMON_NAME "CN"
34 #define CM_SURNAME   "SN"
35 #define CM_COUNTRY_NAME "C"
36 #define CM_LOCALITY_NAME "L"
37 #define CM_STATE_OR_PROVINCE_NAME "ST"
38 #define CM_STREET_ADDRESS "street"
39 #define CM_ORGANIZATION_NAME "O"
40 #define CM_ORGANIZATION_UNIT_NAME  "OU"
41 
42 #define ASN1_TAG_TYPE_SEQ 0x30
43 enum CmCertFormat {
44     CM_CERT_FORMAT_PEM,
45     CM_CERT_FORMAT_DER
46 };
47 
48 struct DataTime {
49     uint32_t year;
50     uint32_t month;
51     uint32_t day;
52     uint32_t hour;
53     uint32_t min;
54     uint32_t second;
55 };
56 
57 X509 *InitCertContext(const uint8_t *certBuf, uint32_t size);
58 
59 int32_t GetX509SerialNumber(X509 *x509cert, char *outBuf, uint32_t outBufMaxSize);
60 
61 int32_t GetX509SubjectName(const X509 *x509cert, const char *subjectObjName, char* outBuf, uint32_t outBufMaxSize);
62 
63 int32_t GetX509SubjectNameLongFormat(const X509 *x509cert, char* outBuf, uint32_t outBufMaxSize);
64 int32_t GetX509IssueNameLongFormat(const X509 *x509cert, char* outBuf, uint32_t outBufMaxSize);
65 
66 int32_t GetX509NotBefore(const X509 *x509cert, char* outBuf, uint32_t outBufMaxSize);
67 int32_t GetX509NotAfter(const X509 *x509cert, char* outBuf, uint32_t outBufMaxSize);
68 
69 int32_t GetX509Fingerprint(const X509 *x509cert, char* outBuf, uint32_t outBufMaxSize);
70 
71 void FreeCertContext(X509 *x509cert);
72 #ifdef __cplusplus
73 }
74 #endif
75 #endif
76