1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD 2 // 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 #ifndef _SSL_X509_H_ 16 #define _SSL_X509_H_ 17 18 #ifdef __cplusplus 19 extern "C" { 20 #endif 21 22 #include "ssl_types.h" 23 #include "ssl_stack.h" 24 25 DEFINE_STACK_OF(X509_NAME) 26 27 /** 28 * @brief create a X509 certification object according to input X509 certification 29 * 30 * @param ix - input X509 certification point 31 * 32 * @return new X509 certification object point 33 */ 34 X509* __X509_new(X509 *ix); 35 36 /** 37 * @brief create a X509 certification object 38 * 39 * @param none 40 * 41 * @return X509 certification object point 42 */ 43 X509* X509_new(void); 44 45 /** 46 * @brief load a character certification context into system context. If '*cert' is pointed to the 47 * certification, then load certification into it. Or create a new X509 certification object 48 * 49 * @param cert - a point pointed to X509 certification 50 * @param buffer - a point pointed to the certification context memory point 51 * @param length - certification bytes 52 * 53 * @return X509 certification object point 54 */ 55 X509* d2i_X509(X509 **cert, const unsigned char *buffer, long len); 56 57 /** 58 * @brief free a X509 certification object 59 * 60 * @param x - X509 certification object point 61 * 62 * @return none 63 */ 64 void X509_free(X509 *x); 65 66 /** 67 * @brief set SSL context client CA certification 68 * 69 * @param ctx - SSL context point 70 * @param x - X509 certification point 71 * 72 * @return result 73 * 0 : failed 74 * 1 : OK 75 */ 76 int SSL_CTX_add_client_CA(SSL_CTX *ctx, X509 *x); 77 78 /** 79 * @brief add CA client certification into the SSL 80 * 81 * @param ssl - SSL point 82 * @param x - X509 certification point 83 * 84 * @return result 85 * 0 : failed 86 * 1 : OK 87 */ 88 int SSL_add_client_CA(SSL *ssl, X509 *x); 89 90 /** 91 * @brief load certification into the SSL 92 * 93 * @param ssl - SSL point 94 * @param len - data bytes 95 * @param d - data point 96 * 97 * @return result 98 * 0 : failed 99 * 1 : OK 100 * 101 */ 102 int SSL_use_certificate_ASN1(SSL *ssl, int len, const unsigned char *d); 103 104 105 /** 106 * @brief set SSL context client CA certification 107 * 108 * @param store - pointer to X509_STORE 109 * @param x - pointer to X509 certification point 110 * 111 * @return result 112 * 0 : failed 113 * 1 : OK 114 */ 115 int X509_STORE_add_cert(X509_STORE *store, X509 *x); 116 117 /** 118 * @brief load a character certification context into system context. 119 * 120 * If '*cert' is pointed to the certification, then load certification 121 * into it, or create a new X509 certification object. 122 * 123 * @param bp - pointer to BIO 124 * @param buffer - pointer to the certification context memory 125 * @param cb - pointer to a callback which queries pass phrase used 126 for encrypted PEM structure 127 * @param u - pointer to arbitary data passed by application to callback 128 * 129 * @return X509 certification object point 130 */ 131 X509 * PEM_read_bio_X509(BIO *bp, X509 **x, pem_password_cb cb, void *u); 132 133 /** 134 * @brief load a character certification context into system context. 135 * 136 * Current implementation directly calls PEM_read_bio_X509 137 * 138 * @param bp - pointer to BIO 139 * @param buffer - pointer to the certification context memory 140 * @param cb - pointer to the callback (not implemented) 141 * @param u - pointer to arbitrary data (not implemented) 142 * 143 * @return X509 certification object point 144 */ 145 X509 *PEM_read_bio_X509_AUX(BIO *bp, X509 **cert, pem_password_cb *cb, void *u); 146 147 148 #ifdef __cplusplus 149 } 150 #endif 151 152 #endif 153