• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This file is part of the openHiTLS project.
3  *
4  * openHiTLS is licensed under the Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *
8  *     http://license.coscl.org.cn/MulanPSL2
9  *
10  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13  * See the Mulan PSL v2 for more details.
14  */
15 
16 #ifndef HITLS_CERT_LOCAL_H
17 #define HITLS_CERT_LOCAL_H
18 
19 #include "hitls_build.h"
20 #ifdef HITLS_PKI_X509_CRT
21 #include <stdint.h>
22 #include "bsl_asn1.h"
23 #include "bsl_obj.h"
24 #include "sal_atomic.h"
25 #include "hitls_x509_local.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 typedef struct {
32     uint8_t *tbsRawData;
33     uint32_t tbsRawDataLen;
34 
35     int32_t version;
36     BSL_ASN1_Buffer serialNum;
37     HITLS_X509_Asn1AlgId signAlgId;
38 
39     BSL_ASN1_List *issuerName;
40     HITLS_X509_ValidTime validTime;
41     BSL_ASN1_List *subjectName;
42 
43     void *ealPubKey;
44     HITLS_X509_Ext ext;
45 } HITLS_X509_CertTbs;
46 
47 typedef enum {
48     HITLS_X509_CERT_STATE_NEW = 0,
49     HITLS_X509_CERT_STATE_SET,
50     HITLS_X509_CERT_STATE_SIGN,
51     HITLS_X509_CERT_STATE_GEN,
52 } HITLS_X509_CERT_STATE;
53 
54 typedef struct _HITLS_X509_Cert {
55     uint8_t flag; // Used to mark certificate parsing or generation, indicating resource release behavior.
56     uint8_t state;
57 
58     uint8_t *rawData;
59     uint32_t rawDataLen;
60     HITLS_X509_CertTbs tbs;
61     HITLS_X509_Asn1AlgId signAlgId;
62     BSL_ASN1_BitString signature;
63 
64     BSL_SAL_RefCount references;
65     CRYPT_EAL_LibCtx *libCtx;         // Provider context
66     const char *attrName;             // Provider attribute name
67 } HITLS_X509_Cert;
68 
69 #ifdef HITLS_PKI_X509_VFY
70 int32_t HITLS_X509_CheckIssued(HITLS_X509_Cert *issue, HITLS_X509_Cert *subject, bool *res);
71 bool HITLS_X509_CertIsCA(HITLS_X509_Cert *cert);
72 #endif
73 
74 #ifdef __cplusplus
75 }
76 #endif
77 
78 #endif // HITLS_PKI_X509_CRT
79 
80 #endif // HITLS_CERT_LOCAL_H