ssl.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. /*
  2. * Copyright (c) 2007-2016, Cameron Rich
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * * Redistributions of source code must retain the above copyright notice,
  10. * this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. * * Neither the name of the axTLS project nor the names of its contributors
  15. * may be used to endorse or promote products derived from this software
  16. * without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  22. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  25. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  26. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. /**
  31. * @mainpage axTLS API
  32. *
  33. * @image html axolotl.jpg
  34. *
  35. * The axTLS library has features such as:
  36. * - The TLSv1 SSL client/server protocol
  37. * - No requirement to use any openssl libraries.
  38. * - A choice between AES block (128/256 bit) and RC4 (128 bit) stream ciphers.
  39. * - RSA encryption/decryption with variable sized keys (up to 4096 bits).
  40. * - Certificate chaining and peer authentication.
  41. * - Session resumption, session renegotiation.
  42. * - ASN.1, X.509, PKCS#8, PKCS#12 keys/certificates with DER/PEM encoding.
  43. * - Highly configurable compile time options.
  44. * - Portable across many platforms (written in ANSI C), and has language
  45. * bindings in C, C#, VB.NET, Java, Perl and Lua.
  46. * - Partial openssl API compatibility (via a wrapper).
  47. * - A very small footprint (around 50-60kB for the library in 'server-only'
  48. * mode).
  49. * - No dependencies on sockets - can use serial connections for example.
  50. * - A very simple API - ~ 20 functions/methods.
  51. *
  52. * A list of these functions/methods are described below.
  53. *
  54. * @ref c_api
  55. *
  56. * @ref bigint_api
  57. *
  58. * @ref csharp_api
  59. *
  60. * @ref java_api
  61. */
  62. #ifndef HEADER_SSL_H
  63. #define HEADER_SSL_H
  64. #ifdef __cplusplus
  65. extern "C" {
  66. #endif
  67. #include <time.h>
  68. /* need to predefine before ssl_lib.h gets to it */
  69. #define SSL_SESSION_ID_SIZE 32
  70. #ifdef SSL_STATIC_LIBRARY
  71. #define EXP_FUNC
  72. #define LIB_CALLTYPE
  73. #endif
  74. #ifdef AXTLS_LIBRARY
  75. #include "tls1.h"
  76. #else
  77. #ifdef __GNUC__
  78. #include <stdint.h>
  79. #endif
  80. typedef struct SSL_CTX SSL_CTX;
  81. typedef struct SSL SSL;
  82. typedef struct SSL_EXTENSIONS SSL_EXTENSIONS;
  83. #endif
  84. /* The optional parameters that can be given to the client/server SSL engine */
  85. #define SSL_CLIENT_AUTHENTICATION 0x00010000
  86. #define SSL_SERVER_VERIFY_LATER 0x00020000
  87. #define SSL_NO_DEFAULT_KEY 0x00040000
  88. #define SSL_DISPLAY_STATES 0x00080000
  89. #define SSL_DISPLAY_BYTES 0x00100000
  90. #define SSL_DISPLAY_CERTS 0x00200000
  91. #define SSL_DISPLAY_RSA 0x00400000
  92. #define SSL_CONNECT_IN_PARTS 0x00800000
  93. /* errors that can be generated */
  94. #define SSL_OK 0
  95. #define SSL_NOT_OK -1
  96. #define SSL_ERROR_DEAD -2
  97. #define SSL_CLOSE_NOTIFY -3
  98. #define SSL_ERROR_CONN_LOST -256
  99. #define SSL_ERROR_RECORD_OVERFLOW -257
  100. #define SSL_ERROR_SOCK_SETUP_FAILURE -258
  101. #define SSL_ERROR_INVALID_HANDSHAKE -260
  102. #define SSL_ERROR_INVALID_PROT_MSG -261
  103. #define SSL_ERROR_INVALID_HMAC -262
  104. #define SSL_ERROR_INVALID_VERSION -263
  105. #define SSL_ERROR_UNSUPPORTED_EXTENSION -264
  106. #define SSL_ERROR_INVALID_SESSION -265
  107. #define SSL_ERROR_NO_CIPHER -266
  108. #define SSL_ERROR_INVALID_CERT_HASH_ALG -267
  109. #define SSL_ERROR_BAD_CERTIFICATE -268
  110. #define SSL_ERROR_INVALID_KEY -269
  111. #define SSL_ERROR_FINISHED_INVALID -271
  112. #define SSL_ERROR_NO_CERT_DEFINED -272
  113. #define SSL_ERROR_NO_CLIENT_RENOG -273
  114. #define SSL_ERROR_NOT_SUPPORTED -274
  115. #define SSL_X509_OFFSET -512
  116. #define SSL_X509_ERROR(A) (SSL_X509_OFFSET+A)
  117. /* alert types that are recognized */
  118. #define SSL_ALERT_TYPE_WARNING 1
  119. #define SLL_ALERT_TYPE_FATAL 2
  120. /* these are all the alerts that are recognized */
  121. #define SSL_ALERT_CLOSE_NOTIFY 0
  122. #define SSL_ALERT_UNEXPECTED_MESSAGE 10
  123. #define SSL_ALERT_BAD_RECORD_MAC 20
  124. #define SSL_ALERT_RECORD_OVERFLOW 22
  125. #define SSL_ALERT_HANDSHAKE_FAILURE 40
  126. #define SSL_ALERT_BAD_CERTIFICATE 42
  127. #define SSL_ALERT_UNSUPPORTED_CERTIFICATE 43
  128. #define SSL_ALERT_CERTIFICATE_EXPIRED 45
  129. #define SSL_ALERT_CERTIFICATE_UNKNOWN 46
  130. #define SSL_ALERT_ILLEGAL_PARAMETER 47
  131. #define SSL_ALERT_UNKNOWN_CA 48
  132. #define SSL_ALERT_DECODE_ERROR 50
  133. #define SSL_ALERT_DECRYPT_ERROR 51
  134. #define SSL_ALERT_INVALID_VERSION 70
  135. #define SSL_ALERT_NO_RENEGOTIATION 100
  136. #define SSL_ALERT_UNSUPPORTED_EXTENSION 110
  137. /* The ciphers that are supported */
  138. #define SSL_AES128_SHA 0x2f
  139. #define SSL_AES256_SHA 0x35
  140. #define SSL_AES128_SHA256 0x3c
  141. #define SSL_AES256_SHA256 0x3d
  142. /* build mode ids' */
  143. #define SSL_BUILD_SKELETON_MODE 0x01
  144. #define SSL_BUILD_SERVER_ONLY 0x02
  145. #define SSL_BUILD_ENABLE_VERIFICATION 0x03
  146. #define SSL_BUILD_ENABLE_CLIENT 0x04
  147. #define SSL_BUILD_FULL_MODE 0x05
  148. /* offsets to retrieve configuration information */
  149. #define SSL_BUILD_MODE 0
  150. #define SSL_MAX_CERT_CFG_OFFSET 1
  151. #define SSL_MAX_CA_CERT_CFG_OFFSET 2
  152. #define SSL_HAS_PEM 3
  153. /* default session sizes */
  154. #define SSL_DEFAULT_SVR_SESS 5
  155. #define SSL_DEFAULT_CLNT_SESS 1
  156. /* X.509/X.520 distinguished name types */
  157. #define SSL_X509_CERT_COMMON_NAME 0
  158. #define SSL_X509_CERT_ORGANIZATION 1
  159. #define SSL_X509_CERT_ORGANIZATIONAL_NAME 2
  160. #define SSL_X509_CERT_LOCATION 3
  161. #define SSL_X509_CERT_COUNTRY 4
  162. #define SSL_X509_CERT_STATE 5
  163. #define SSL_X509_CA_CERT_COMMON_NAME 6
  164. #define SSL_X509_CA_CERT_ORGANIZATION 7
  165. #define SSL_X509_CA_CERT_ORGANIZATIONAL_NAME 8
  166. #define SSL_X509_CA_CERT_LOCATION 9
  167. #define SSL_X509_CA_CERT_COUNTRY 10
  168. #define SSL_X509_CA_CERT_STATE 11
  169. /* SSL object loader types */
  170. #define SSL_OBJ_X509_CERT 1
  171. #define SSL_OBJ_X509_CACERT 2
  172. #define SSL_OBJ_RSA_KEY 3
  173. #define SSL_OBJ_PKCS8 4
  174. #define SSL_OBJ_PKCS12 5
  175. /**
  176. * @defgroup c_api Standard C API
  177. * @brief The standard interface in C.
  178. * @{
  179. */
  180. /**
  181. * @brief Establish a new client/server context.
  182. *
  183. * This function is called before any client/server SSL connections are made.
  184. *
  185. * Each new connection will use the this context's private key and
  186. * certificate chain. If a different certificate chain is required, then a
  187. * different context needs to be be used.
  188. *
  189. * There are two threading models supported - a single thread with one
  190. * SSL_CTX can support any number of SSL connections - and multiple threads can
  191. * support one SSL_CTX object each (the default). But if a single SSL_CTX
  192. * object uses many SSL objects in individual threads, then the
  193. * CONFIG_SSL_CTX_MUTEXING option needs to be configured.
  194. *
  195. * @param options [in] Any particular options. At present the options
  196. * supported are:
  197. * - SSL_SERVER_VERIFY_LATER (client only): Don't stop a handshake if the server
  198. * authentication fails. The certificate can be authenticated later with a
  199. * call to ssl_verify_cert().
  200. * - SSL_CLIENT_AUTHENTICATION (server only): Enforce client authentication
  201. * i.e. each handshake will include a "certificate request" message from the
  202. * server. Only available if verification has been enabled.
  203. * - SSL_DISPLAY_BYTES (full mode build only): Display the byte sequences
  204. * during the handshake.
  205. * - SSL_DISPLAY_STATES (full mode build only): Display the state changes
  206. * during the handshake.
  207. * - SSL_DISPLAY_CERTS (full mode build only): Display the certificates that
  208. * are passed during a handshake.
  209. * - SSL_DISPLAY_RSA (full mode build only): Display the RSA key details that
  210. * are passed during a handshake.
  211. * - SSL_CONNECT_IN_PARTS (client only): To use a non-blocking version of
  212. * ssl_client_new().
  213. * @param num_sessions [in] The number of sessions to be used for session
  214. * caching. If this value is 0, then there is no session caching. This option
  215. * is not used in skeleton mode.
  216. * @return A client/server context.
  217. */
  218. EXP_FUNC SSL_CTX *LIB_CALLTYPE ssl_ctx_new_with_load_params(
  219. uint32_t options, int num_sessions,
  220. const char *ssl_private_key,
  221. size_t ssl_private_key_len,
  222. const char *ssl_private_key_password,
  223. const char *ssl_x509_cert,
  224. size_t ssl_x509_cert_len);
  225. EXP_FUNC SSL_CTX * LIB_CALLTYPE ssl_ctx_new(uint32_t options, int num_sessions);
  226. /**
  227. * @brief Remove a client/server context.
  228. *
  229. * Frees any used resources used by this context. Each connection will be
  230. * sent a "Close Notify" alert (if possible).
  231. * @param ssl_ctx [in] The client/server context.
  232. */
  233. EXP_FUNC void LIB_CALLTYPE ssl_ctx_free(SSL_CTX *ssl_ctx);
  234. /**
  235. * @brief (server only) Establish a new SSL connection to an SSL client.
  236. *
  237. * It is up to the application to establish the logical connection (whether it
  238. * is a socket, serial connection etc).
  239. * @param ssl_ctx [in] The server context.
  240. * @param client_fd [in] The client's file descriptor.
  241. * @return An SSL object reference.
  242. */
  243. EXP_FUNC SSL * LIB_CALLTYPE ssl_server_new(SSL_CTX *ssl_ctx, int client_fd);
  244. /**
  245. * @brief (client only) Establish a new SSL connection to an SSL server.
  246. *
  247. * It is up to the application to establish the initial logical connection
  248. * (whether it is a socket, serial connection etc).
  249. *
  250. * This is a normally a blocking call - it will finish when the handshake is
  251. * complete (or has failed). To use in non-blocking mode, set
  252. * SSL_CONNECT_IN_PARTS in ssl_ctx_new().
  253. * @param ssl_ctx [in] The client context.
  254. * @param client_fd [in] The client's file descriptor.
  255. * @param session_id [in] A 32 byte session id for session resumption. This
  256. * can be null if no session resumption is being used or required. This option
  257. * is not used in skeleton mode.
  258. * @param sess_id_size The size of the session id (max 32)
  259. * @param ssl_ext pointer to a structure with the activated SSL extensions
  260. * and their values
  261. * @return An SSL object reference. Use ssl_handshake_status() to check
  262. * if a handshake succeeded.
  263. */
  264. EXP_FUNC SSL * LIB_CALLTYPE ssl_client_new(SSL_CTX *ssl_ctx, int client_fd, const uint8_t *session_id,
  265. uint8_t sess_id_size, SSL_EXTENSIONS* ssl_ext);
  266. /**
  267. * @brief Free any used resources on this connection.
  268. * A "Close Notify" message is sent on this connection (if possible). It is up
  269. * to the application to close the socket or file descriptor.
  270. * @param ssl [in] The ssl object reference.
  271. */
  272. EXP_FUNC void LIB_CALLTYPE ssl_free(SSL *ssl);
  273. /**
  274. * @brief Read the SSL data stream.
  275. * If the socket is non-blocking and data is blocked then SSO_OK will be
  276. * returned.
  277. * @param ssl [in] An SSL object reference.
  278. * @param in_data [out] If the read was successful, a pointer to the read
  279. * buffer will be here. Do NOT ever free this memory as this buffer is used in
  280. * sucessive calls. If the call was unsuccessful, this value will be null.
  281. * @return The number of decrypted bytes:
  282. * - if > 0, then the handshaking is complete and we are returning the number
  283. * of decrypted bytes.
  284. * - SSL_OK if the handshaking stage is successful (but not yet complete).
  285. * - < 0 if an error.
  286. * @see ssl.h for the error code list.
  287. * @note Use in_data before doing any successive ssl calls.
  288. */
  289. EXP_FUNC int LIB_CALLTYPE ssl_read(SSL *ssl, uint8_t **in_data, int in_num);
  290. /**
  291. * @brief Write to the SSL data stream.
  292. * if the socket is non-blocking and data is blocked then a check is made
  293. * to ensure that all data is sent (i.e. blocked mode is forced).
  294. * @param ssl [in] An SSL obect reference.
  295. * @param out_data [in] The data to be written
  296. * @param out_len [in] The number of bytes to be written.
  297. * @return The number of bytes sent, or if < 0 if an error.
  298. * @see ssl.h for the error code list.
  299. */
  300. EXP_FUNC int LIB_CALLTYPE ssl_write(SSL *ssl, const uint8_t *out_data, int out_len);
  301. /**
  302. * @brief Find an ssl object based on a file descriptor.
  303. *
  304. * Goes through the list of SSL objects maintained in a client/server context
  305. * to look for a file descriptor match.
  306. * @param ssl_ctx [in] The client/server context.
  307. * @param client_fd [in] The file descriptor.
  308. * @return A reference to the SSL object. Returns null if the object could not
  309. * be found.
  310. */
  311. EXP_FUNC SSL * LIB_CALLTYPE ssl_find(SSL_CTX *ssl_ctx, int client_fd);
  312. /**
  313. * @brief Get the session id for a handshake.
  314. *
  315. * This will be a 32 byte sequence and is available after the first
  316. * handshaking messages are sent.
  317. * @param ssl [in] An SSL object reference.
  318. * @return The session id as a 32 byte sequence.
  319. * @note A SSLv23 handshake may have only 16 valid bytes.
  320. */
  321. EXP_FUNC const uint8_t * LIB_CALLTYPE ssl_get_session_id(const SSL *ssl);
  322. /**
  323. * @brief Get the session id size for a handshake.
  324. *
  325. * This will normally be 32 but could be 0 (no session id) or something else.
  326. * @param ssl [in] An SSL object reference.
  327. * @return The size of the session id.
  328. */
  329. EXP_FUNC uint8_t LIB_CALLTYPE ssl_get_session_id_size(const SSL *ssl);
  330. /**
  331. * @brief Return the cipher id (in the SSL form).
  332. * @param ssl [in] An SSL object reference.
  333. * @return The cipher id. This will be one of the following:
  334. * - SSL_AES128_SHA (0x2f)
  335. * - SSL_AES256_SHA (0x35)
  336. * - SSL_AES128_SHA256 (0x3c)
  337. * - SSL_AES256_SHA256 (0x3d)
  338. */
  339. EXP_FUNC uint8_t LIB_CALLTYPE ssl_get_cipher_id(const SSL *ssl);
  340. /**
  341. * @brief Return the status of the handshake.
  342. * @param ssl [in] An SSL object reference.
  343. * @return SSL_OK if the handshake is complete and ok.
  344. * @see ssl.h for the error code list.
  345. */
  346. EXP_FUNC int LIB_CALLTYPE ssl_handshake_status(const SSL *ssl);
  347. /**
  348. * @brief Retrieve various parameters about the axTLS engine.
  349. * @param offset [in] The configuration offset. It will be one of the following:
  350. * - SSL_BUILD_MODE The build mode. This will be one of the following:
  351. * - SSL_BUILD_SERVER_ONLY (basic server mode)
  352. * - SSL_BUILD_ENABLE_VERIFICATION (server can do client authentication)
  353. * - SSL_BUILD_ENABLE_CLIENT (client/server capabilties)
  354. * - SSL_BUILD_FULL_MODE (client/server with diagnostics)
  355. * - SSL_BUILD_SKELETON_MODE (skeleton mode)
  356. * - SSL_MAX_CERT_CFG_OFFSET The maximum number of certificates allowed.
  357. * - SSL_MAX_CA_CERT_CFG_OFFSET The maximum number of CA certificates allowed.
  358. * - SSL_HAS_PEM 1 if supported
  359. * @return The value of the requested parameter.
  360. */
  361. EXP_FUNC int LIB_CALLTYPE ssl_get_config(int offset);
  362. /**
  363. * @brief Display why the handshake failed.
  364. *
  365. * This call is only useful in a 'full mode' build. The output is to stdout.
  366. * @param error_code [in] An error code.
  367. * @see ssl.h for the error code list.
  368. */
  369. EXP_FUNC const char* LIB_CALLTYPE ssl_get_error(int error_code, char *buf, size_t bufsize);
  370. EXP_FUNC void LIB_CALLTYPE ssl_display_error(int error_code);
  371. /**
  372. * @brief Authenticate a received certificate.
  373. *
  374. * This call is usually made by a client after a handshake is complete and the
  375. * context is in SSL_SERVER_VERIFY_LATER mode.
  376. * @param ssl [in] An SSL object reference.
  377. * @return SSL_OK if the certificate is verified.
  378. */
  379. EXP_FUNC int LIB_CALLTYPE ssl_verify_cert(const SSL *ssl);
  380. /**
  381. * @brief Retrieve an X.509 distinguished name component.
  382. *
  383. * When a handshake is complete and a certificate has been exchanged, then the
  384. * details of the remote certificate can be retrieved.
  385. *
  386. * This will usually be used by a client to check that the server's common
  387. * name matches the URL.
  388. *
  389. * @param ssl [in] An SSL object reference.
  390. * @param component [in] one of:
  391. * - SSL_X509_CERT_COMMON_NAME
  392. * - SSL_X509_CERT_ORGANIZATION
  393. * - SSL_X509_CERT_ORGANIZATIONAL_NAME
  394. * - SSL_X509_CERT_LOCATION
  395. * - SSL_X509_CERT_COUNTRY
  396. * - SSL_X509_CERT_STATE
  397. * - SSL_X509_CA_CERT_COMMON_NAME
  398. * - SSL_X509_CA_CERT_ORGANIZATION
  399. * - SSL_X509_CA_CERT_ORGANIZATIONAL_NAME
  400. * - SSL_X509_CA_CERT_LOCATION
  401. * - SSL_X509_CA_CERT_COUNTRY
  402. * - SSL_X509_CA_CERT_STATE
  403. * @return The appropriate string (or null if not defined)
  404. * @note Verification build mode must be enabled.
  405. */
  406. EXP_FUNC const char * LIB_CALLTYPE ssl_get_cert_dn(const SSL *ssl, int component);
  407. /**
  408. * @brief Retrieve a Subject Alternative DNSName
  409. *
  410. * When a handshake is complete and a certificate has been exchanged, then the
  411. * details of the remote certificate can be retrieved.
  412. *
  413. * This will usually be used by a client to check that the server's DNS
  414. * name matches the URL.
  415. *
  416. * @param ssl [in] An SSL object reference.
  417. * @param dnsindex [in] The index of the DNS name to retrieve.
  418. * @return The appropriate string (or null if not defined)
  419. * @note Verification build mode must be enabled.
  420. */
  421. EXP_FUNC const char * LIB_CALLTYPE ssl_get_cert_subject_alt_dnsname(const SSL *ssl, int dnsindex);
  422. /**
  423. * @brief Force the client to perform its handshake again.
  424. *
  425. * For a client this involves sending another "client hello" message.
  426. * For the server is means sending a "hello request" message.
  427. *
  428. * This is a blocking call on the client (until the handshake completes).
  429. *
  430. * @param ssl [in] An SSL object reference.
  431. * @return SSL_OK if renegotiation instantiation was ok
  432. */
  433. EXP_FUNC int LIB_CALLTYPE ssl_renegotiate(SSL *ssl);
  434. /**
  435. * @brief Process a file that is in binary DER or ASCII PEM format.
  436. *
  437. * These are temporary objects that are used to load private keys,
  438. * certificates etc into memory.
  439. * @param ssl_ctx [in] The client/server context.
  440. * @param obj_type [in] The format of the file. Can be one of:
  441. * - SSL_OBJ_X509_CERT (no password required)
  442. * - SSL_OBJ_X509_CACERT (no password required)
  443. * - SSL_OBJ_RSA_KEY (AES128/AES256 PEM encryption supported)
  444. * - SSL_OBJ_PKCS8 (RC4-128 encrypted data supported)
  445. * - SSL_OBJ_PKCS12 (RC4-128 encrypted data supported)
  446. *
  447. * PEM files are automatically detected (if supported). The object type is
  448. * also detected, and so is not relevant for these types of files.
  449. * @param filename [in] The location of a file in DER/PEM format.
  450. * @param password [in] The password used. Can be null if not required.
  451. * @return SSL_OK if all ok
  452. * @note Not available in skeleton build mode.
  453. */
  454. EXP_FUNC int LIB_CALLTYPE ssl_obj_load(SSL_CTX *ssl_ctx, int obj_type, const char *filename, const char *password);
  455. /**
  456. * @brief Process binary data.
  457. *
  458. * These are temporary objects that are used to load private keys,
  459. * certificates etc into memory.
  460. * @param ssl_ctx [in] The client/server context.
  461. * @param obj_type [in] The format of the memory data.
  462. * @param data [in] The binary data to be loaded.
  463. * @param len [in] The amount of data to be loaded.
  464. * @param password [in] The password used. Can be null if not required.
  465. * @return SSL_OK if all ok
  466. * @see ssl_obj_load for more details on obj_type.
  467. */
  468. EXP_FUNC int LIB_CALLTYPE ssl_obj_memory_load(SSL_CTX *ssl_ctx, int obj_type, const uint8_t *data, int len, const char *password);
  469. #ifdef CONFIG_SSL_GENERATE_X509_CERT
  470. /**
  471. * @brief Create an X.509 certificate.
  472. *
  473. * This certificate is a self-signed v1 cert with a fixed start/stop validity
  474. * times. It is signed with an internal private key in ssl_ctx.
  475. *
  476. * @param ssl_ctx [in] The client/server context.
  477. * @param options [in] Not used yet.
  478. * @param dn [in] An array of distinguished name strings. The array is defined
  479. * by:
  480. * - SSL_X509_CERT_COMMON_NAME (0)
  481. * - If SSL_X509_CERT_COMMON_NAME is empty or not defined, then the
  482. * hostname will be used.
  483. * - SSL_X509_CERT_ORGANIZATION (1)
  484. * - If SSL_X509_CERT_ORGANIZATION is empty or not defined, then $USERNAME
  485. * will be used.
  486. * - SSL_X509_CERT_ORGANIZATIONAL_NAME (2)
  487. * - SSL_X509_CERT_ORGANIZATIONAL_NAME is optional.
  488. * @param cert_data [out] The certificate as a sequence of bytes.
  489. * @return < 0 if an error, or the size of the certificate in bytes.
  490. * @note cert_data must be freed when there is no more need for it.
  491. */
  492. EXP_FUNC int LIB_CALLTYPE ssl_x509_create(SSL_CTX *ssl_ctx, uint32_t options, const char * dn[], uint8_t **cert_data);
  493. #endif
  494. /**
  495. * @brief Return the axTLS library version as a string.
  496. */
  497. EXP_FUNC const char * LIB_CALLTYPE ssl_version(void);
  498. /** @} */
  499. #ifdef __cplusplus
  500. }
  501. #endif
  502. #endif