openHiTLS API openHiTLS 0.1.0-Alpha1
hitls_cert.h
浏览该文件的文档.
1/*---------------------------------------------------------------------------------------------
2 * This file is part of the openHiTLS project.
3 * Copyright © 2023 Huawei Technologies Co.,Ltd. All rights reserved.
4 * Licensed under the openHiTLS Software license agreement 1.0. See LICENSE in the project root
5 * for license information.
6 *---------------------------------------------------------------------------------------------
7 */
8
15#ifndef HITLS_CERT_H
16#define HITLS_CERT_H
17
18#include <stdbool.h>
19#include <stdint.h>
20#include "hitls_type.h"
21#include "hitls_cert_type.h"
22#include "hitls_cert_reg.h"
23#include "hitls_error.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
39int32_t HITLS_CFG_SetVerifyStore(HITLS_Config *config, HITLS_CERT_Store *store, bool isClone);
40
51
62int32_t HITLS_SetVerifyStore(HITLS_Ctx *ctx, HITLS_CERT_Store *store, bool isClone);
63
72
83int32_t HITLS_CFG_SetChainStore(HITLS_Config *config, HITLS_CERT_Store *store, bool isClone);
84
94
105int32_t HITLS_SetChainStore(HITLS_Ctx *ctx, HITLS_CERT_Store *store, bool isClone);
106
115
128int32_t HITLS_CFG_SetCertStore(HITLS_Config *config, HITLS_CERT_Store *store, bool isClone);
129
139
152int32_t HITLS_SetCertStore(HITLS_Ctx *ctx, HITLS_CERT_Store *store, bool isClone);
153
162
172int32_t HITLS_CFG_SetVerifyDepth(HITLS_Config *config, uint32_t depth);
173
183int32_t HITLS_CFG_GetVerifyDepth(const HITLS_Config *config, uint32_t *depth);
184
194int32_t HITLS_SetVerifyDepth(HITLS_Ctx *ctx, uint32_t depth);
195
205int32_t HITLS_GetVerifyDepth(const HITLS_Ctx *ctx, uint32_t *depth);
206
219typedef int32_t (*HITLS_PasswordCb)(char *buf, int32_t bufLen, int32_t flag, void *userdata);
220
231
240
251
260
271
280
290int32_t HITLS_SetDefaultPasswordCbUserdata(HITLS_Ctx *ctx, void *userdata);
291
300
301#ifndef HITLS_NO_TLCP11
315int32_t HITLS_CFG_SetTlcpCertificate(HITLS_Config *config, HITLS_CERT_X509 *cert, bool isClone, bool isTlcpEncCert);
316
331 bool isClone, bool isTlcpEncCertPriKey);
332#endif
333
344int32_t HITLS_CFG_SetCertificate(HITLS_Config *config, HITLS_CERT_X509 *cert, bool isClone);
345
356int32_t HITLS_CFG_LoadCertFile(HITLS_Config *config, const char *file, HITLS_ParseFormat format);
357
369int32_t HITLS_CFG_LoadCertBuffer(HITLS_Config *config, const uint8_t *buf, uint32_t bufLen, HITLS_ParseFormat format);
370
380
390int32_t HITLS_SetCertificate(HITLS_Ctx *ctx, HITLS_CERT_X509 *cert, bool isClone);
391
402int32_t HITLS_LoadCertFile(HITLS_Ctx *ctx, const char *file, HITLS_ParseFormat format);
403
415int32_t HITLS_LoadCertBuffer(HITLS_Ctx *ctx, const uint8_t *buf, uint32_t bufLen, HITLS_ParseFormat format);
416
432
442
454int32_t HITLS_CFG_SetPrivateKey(HITLS_Config *config, HITLS_CERT_Key *privateKey, bool isClone);
455
466int32_t HITLS_CFG_LoadKeyFile(HITLS_Config *config, const char *file, HITLS_ParseFormat format);
467
479int32_t HITLS_CFG_LoadKeyBuffer(HITLS_Config *config, const uint8_t *buf, uint32_t bufLen, HITLS_ParseFormat format);
480
491
501
513int32_t HITLS_SetPrivateKey(HITLS_Ctx *ctx, HITLS_CERT_Key *key, bool isClone);
514
525int32_t HITLS_LoadKeyFile(HITLS_Ctx *ctx, const char *file, HITLS_ParseFormat format);
526
538int32_t HITLS_LoadKeyBuffer(HITLS_Ctx *ctx, const uint8_t *buf, uint32_t bufLen, HITLS_ParseFormat format);
539
550
560
571int32_t HITLS_CFG_AddChainCert(HITLS_Config *config, HITLS_CERT_X509 *cert, bool isClone);
572
583int32_t HITLS_CFG_AddCertToStore(HITLS_Config *config, char *certPath, HITLS_CERT_StoreType storeType);
584
593
603
613
623
633
644typedef int (*HITLS_VerifyCb)(int32_t isPreverifyOk, HITLS_CERT_StoreCtx *storeCtx);
645
654
663
672
681
691int32_t HITLS_SetVerifyResult(HITLS_Ctx *ctx, HITLS_ERROR verifyResult);
692
702int32_t HITLS_GetVerifyResult(const HITLS_Ctx *ctx, HITLS_ERROR *verifyResult);
703
712
721
731
740
741#ifdef __cplusplus
742}
743#endif
744
745#endif /* HITLS_CERT_H */
int32_t HITLS_CFG_GetVerifyDepth(const HITLS_Config *config, uint32_t *depth)
Obtain the certificate verification depth.
int32_t HITLS_CFG_SetDefaultPasswordCb(HITLS_Config *config, HITLS_PasswordCb cb)
Set the default password callback, cb can be NULL.
int32_t HITLS_CFG_SetTlcpCertificate(HITLS_Config *config, HITLS_CERT_X509 *cert, bool isClone, bool isTlcpEncCert)
Add the device certificate by the ShangMi(SM) cipher suites. Only one certificate can be added for ea...
int(* HITLS_VerifyCb)(int32_t isPreverifyOk, HITLS_CERT_StoreCtx *storeCtx)
Certificate verification callback
Definition hitls_cert.h:644
int32_t HITLS_SetCertStore(HITLS_Ctx *ctx, HITLS_CERT_Store *store, bool isClone)
Set the cert store used by the TLS link.
int32_t HITLS_CFG_SetVerifyDepth(HITLS_Config *config, uint32_t depth)
Set the certificate verification depth.
HITLS_VerifyCb HITLS_GetVerifyCb(const HITLS_Ctx *ctx)
Obtain the certificate verification callback function.
HITLS_PasswordCb HITLS_CFG_GetDefaultPasswordCb(HITLS_Config *config)
Callback for obtaining the default password.
int32_t HITLS_CFG_SetCertStore(HITLS_Config *config, HITLS_CERT_Store *store, bool isClone)
Set the cert store used by the TLS configuration.
HITLS_CERT_Store * HITLS_CFG_GetChainStore(const HITLS_Config *config)
Obtain the chain store used by the TLS configuration.
int32_t HITLS_CFG_AddCertToStore(HITLS_Config *config, char *certPath, HITLS_CERT_StoreType storeType)
Add the certificate to the certificate store that is being used by the current config.
int32_t HITLS_LoadKeyBuffer(HITLS_Ctx *ctx, const uint8_t *buf, uint32_t bufLen, HITLS_ParseFormat format)
Read the private key of the device certificate from the buffer.
HITLS_PasswordCb HITLS_GetDefaultPasswordCb(HITLS_Ctx *ctx)
Callback for obtaining the default password
int32_t HITLS_CFG_LoadCertBuffer(HITLS_Config *config, const uint8_t *buf, uint32_t bufLen, HITLS_ParseFormat format)
Read the device certificate from the buffer.
HITLS_CERT_Store * HITLS_GetVerifyStore(const HITLS_Ctx *ctx)
Obtain the verify store used by the TLS link.
int32_t HITLS_CFG_SetVerifyStore(HITLS_Config *config, HITLS_CERT_Store *store, bool isClone)
Set the verify store used by the TLS configuration, which is used for certificate verification.
HITLS_CERT_Chain * HITLS_CFG_GetChainCerts(HITLS_Config *config)
Obtain the certificate chain that is being used by the current config.
HITLS_CERT_X509 * HITLS_GetPeerCertificate(const HITLS_Ctx *ctx)
Obtain the peer certificate.
int32_t HITLS_CFG_CheckPrivateKey(const HITLS_Config *config)
Check whether the configured certificate matches the private key.
HITLS_CERT_Store * HITLS_CFG_GetVerifyStore(const HITLS_Config *config)
Obtain the verify store used by the TLS configuration.
int32_t HITLS_SetCertificate(HITLS_Ctx *ctx, HITLS_CERT_X509 *cert, bool isClone)
Add a device certificate. Only one certificate can be added for each type.
HITLS_CERT_Key * HITLS_CFG_GetPrivateKey(const HITLS_Config *config)
Obtain the private key of the certificate in use.
HITLS_TrustedCAList * HITLS_GetClientCAList(const HITLS_Ctx *ctx)
Obtain the trusted CA list of the peer end.
int32_t(* HITLS_PasswordCb)(char *buf, int32_t bufLen, int32_t flag, void *userdata)
Password Callback
Definition hitls_cert.h:219
int32_t HITLS_CFG_RemoveCertAndKey(HITLS_Config *config)
Release all loaded certificates and private keys.
int32_t HITLS_CFG_SetCertificate(HITLS_Config *config, HITLS_CERT_X509 *cert, bool isClone)
Add a device certificate. Only one certificate of each type can be added
int32_t HITLS_SetVerifyCb(HITLS_Ctx *ctx, HITLS_VerifyCb callback)
Set the certificate verification callback function, cb can be NULL.
int32_t HITLS_RemoveCertAndKey(HITLS_Ctx *ctx)
Release all loaded certificates and private keys.
int32_t HITLS_CheckPrivateKey(const HITLS_Ctx *ctx)
Check whether the configured certificate matches the private key.
int32_t HITLS_ClearChainCerts(HITLS_Ctx *ctx)
Clear the certificate in the current certificate.
int32_t HITLS_SetVerifyStore(HITLS_Ctx *ctx, HITLS_CERT_Store *store, bool isClone)
Set the verify store used by the TLS link for certificate verification.
int32_t HITLS_SetVerifyResult(HITLS_Ctx *ctx, HITLS_ERROR verifyResult)
Set the peer certificate verification result of the current context.
int32_t HITLS_SetPrivateKey(HITLS_Ctx *ctx, HITLS_CERT_Key *key, bool isClone)
Add the private key of the device certificate.
HITLS_CERT_Key * HITLS_GetPrivateKey(HITLS_Ctx *ctx)
Obtain the private key of the certificate in use.
int32_t HITLS_CFG_SetPrivateKey(HITLS_Config *config, HITLS_CERT_Key *privateKey, bool isClone)
Add the private key of the device certificate. Only one private key can be added for each type of cer...
int32_t HITLS_LoadCertBuffer(HITLS_Ctx *ctx, const uint8_t *buf, uint32_t bufLen, HITLS_ParseFormat format)
Read the device certificate from the buffer.
HITLS_CERT_X509 * HITLS_CFG_GetCertificate(const HITLS_Config *config)
Obtain the device certificate in use.
HITLS_CERT_Store * HITLS_CFG_GetCertStore(const HITLS_Config *config)
Obtain the cert store used by the TLS configuration.
HITLS_CERT_Chain * HITLS_GetPeerCertChain(const HITLS_Ctx *ctx)
Obtain the peer certificate chain.
int32_t HITLS_GetVerifyDepth(const HITLS_Ctx *ctx, uint32_t *depth)
Obtain the certificate verification depth.
void * HITLS_CFG_GetDefaultPasswordCbUserdata(HITLS_Config *config)
Obtain the user data used by the password callback.
int32_t HITLS_LoadCertFile(HITLS_Ctx *ctx, const char *file, HITLS_ParseFormat format)
Use a file to set the device certificate.
int32_t HITLS_CFG_LoadKeyBuffer(HITLS_Config *config, const uint8_t *buf, uint32_t bufLen, HITLS_ParseFormat format)
Read the private key of the device certificate from the buffer.
int32_t HITLS_CFG_SetDefaultPasswordCbUserdata(HITLS_Config *config, void *userdata)
Set the user data used by the password callback.
int32_t HITLS_SetDefaultPasswordCb(HITLS_Ctx *ctx, HITLS_PasswordCb cb)
Set the default password callback, cb can be NULL
int32_t HITLS_LoadKeyFile(HITLS_Ctx *ctx, const char *file, HITLS_ParseFormat format)
Use the file to set the device private key.
int32_t HITLS_GetVerifyResult(const HITLS_Ctx *ctx, HITLS_ERROR *verifyResult)
Return the peer certificate verification result of the current context.
HITLS_CERT_Store * HITLS_GetChainStore(const HITLS_Ctx *ctx)
Obtain the chain store used by the TLS link.
void * HITLS_GetDefaultPasswordCbUserdata(HITLS_Ctx *ctx)
Obtain the user data used by the default password callback.
int32_t HITLS_CFG_LoadKeyFile(HITLS_Config *config, const char *file, HITLS_ParseFormat format)
Load the private key of the device certificate from the file.
int32_t HITLS_SetChainStore(HITLS_Ctx *ctx, HITLS_CERT_Store *store, bool isClone)
Set the chain store used by the TLS link to construct the certificate chain.
int32_t HITLS_CFG_ClearChainCerts(HITLS_Config *config)
Clear the certificate chain associated with the current certificate.
HITLS_CERT_Store * HITLS_GetCertStore(const HITLS_Ctx *ctx)
Obtain the cert store used by the TLS link.
int32_t HITLS_CFG_SetChainStore(HITLS_Config *config, HITLS_CERT_Store *store, bool isClone)
Set the chain store used by the TLS configuration, which is used to construct the certificate chain.
int32_t HITLS_CFG_AddExtraChainCert(HITLS_Config *config, HITLS_CERT_X509 *cert)
Add a certificate to the attached certificate chain.
int32_t HITLS_SetDefaultPasswordCbUserdata(HITLS_Ctx *ctx, void *userdata)
Set the user data used by the default password callback.
int32_t HITLS_SetVerifyDepth(HITLS_Ctx *ctx, uint32_t depth)
Set the certificate verification depth.
HITLS_CERT_X509 * HITLS_GetCertificate(const HITLS_Ctx *ctx)
Obtain the local certificate.
HITLS_VerifyCb HITLS_CFG_GetVerifyCb(const HITLS_Config *config)
Obtain the certificate verification callback function.
HITLS_CERT_Chain * HITLS_CFG_GetExtraChainCerts(HITLS_Config *config)
Obtain the attached certificate chain.
int32_t HITLS_CFG_SetTlcpPrivateKey(HITLS_Config *config, HITLS_CERT_Key *privateKey, bool isClone, bool isTlcpEncCertPriKey)
Add the private key of the device certificate by the ShangMi(SM) cipher suites. Only one private key ...
int32_t HITLS_CFG_SetVerifyCb(HITLS_Config *config, HITLS_VerifyCb callback)
Set the certificate verification callback function, cb can be NULL.
int32_t HITLS_CFG_LoadCertFile(HITLS_Config *config, const char *file, HITLS_ParseFormat format)
Load the device certificate from the file.
int32_t HITLS_CFG_AddChainCert(HITLS_Config *config, HITLS_CERT_X509 *cert, bool isClone)
Add the certificate to the certificate chain that is being used by the current config.
void HITLS_CERT_Key
Describes the certificate key
Definition hitls_cert_type.h:34
HITLS_ParseFormat
Read data format
Definition hitls_cert_type.h:105
void HITLS_CERT_StoreCtx
Describes the certificate
Definition hitls_cert_type.h:52
void HITLS_CERT_Store
Describes the certificate
Definition hitls_cert_type.h:46
void HITLS_CERT_X509
Describes the x509 certificate
Definition hitls_cert_type.h:28
HITLS_CERT_StoreType
cert store type
Definition hitls_cert_type.h:117
HITLS_ERROR
Definition hitls_error.h:74
struct TlsCtx HITLS_Ctx
HITLS context
Definition hitls_type.h:28
struct TlsConfig HITLS_Config
config context
Definition hitls_type.h:34
Definition bsl_list.h:41