ssl.h 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904
  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. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef _SSL_H_
  14. #define _SSL_H_
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include "internal/ssl_x509.h"
  19. #include "internal/ssl_pkey.h"
  20. #include "openssl/bio.h"
  21. #include "openssl/err.h"
  22. /*
  23. {
  24. */
  25. #define SSL_CB_ALERT 0x4000
  26. #define X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT (1 << 0)
  27. #define X509_CHECK_FLAG_NO_WILDCARDS (1 << 1)
  28. #define X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS (1 << 2)
  29. #define X509_CHECK_FLAG_MULTI_LABEL_WILDCARDS (1 << 3)
  30. #define X509_CHECK_FLAG_SINGLE_LABEL_SUBDOMAINS (1 << 4)
  31. /**
  32. * @brief create a SSL context
  33. *
  34. * @param method - the SSL context method point
  35. *
  36. * @return the context point
  37. */
  38. SSL_CTX* SSL_CTX_new(const SSL_METHOD *method);
  39. /**
  40. * @brief free a SSL context
  41. *
  42. * @param method - the SSL context point
  43. *
  44. * @return none
  45. */
  46. void SSL_CTX_free(SSL_CTX *ctx);
  47. /**
  48. * @brief create a SSL
  49. *
  50. * @param ctx - the SSL context point
  51. *
  52. * @return the SSL point
  53. */
  54. SSL* SSL_new(SSL_CTX *ctx);
  55. /**
  56. * @brief free the SSL
  57. *
  58. * @param ssl - the SSL point
  59. *
  60. * @return none
  61. */
  62. void SSL_free(SSL *ssl);
  63. /**
  64. * @brief connect to the remote SSL server
  65. *
  66. * @param ssl - the SSL point
  67. *
  68. * @return result
  69. * 1 : OK
  70. * -1 : failed
  71. */
  72. int SSL_connect(SSL *ssl);
  73. /**
  74. * @brief accept the remote connection
  75. *
  76. * @param ssl - the SSL point
  77. *
  78. * @return result
  79. * 1 : OK
  80. * -1 : failed
  81. */
  82. int SSL_accept(SSL *ssl);
  83. /**
  84. * @brief read data from to remote
  85. *
  86. * @param ssl - the SSL point which has been connected
  87. * @param buffer - the received data buffer point
  88. * @param len - the received data length
  89. *
  90. * @return result
  91. * > 0 : OK, and return received data bytes
  92. * = 0 : connection is closed
  93. * < 0 : an error catch
  94. */
  95. int SSL_read(SSL *ssl, void *buffer, int len);
  96. /**
  97. * @brief send the data to remote
  98. *
  99. * @param ssl - the SSL point which has been connected
  100. * @param buffer - the send data buffer point
  101. * @param len - the send data length
  102. *
  103. * @return result
  104. * > 0 : OK, and return sent data bytes
  105. * = 0 : connection is closed
  106. * < 0 : an error catch
  107. */
  108. int SSL_write(SSL *ssl, const void *buffer, int len);
  109. /**
  110. * @brief get the verifying result of the SSL certification
  111. *
  112. * @param ssl - the SSL point
  113. *
  114. * @return the result of verifying
  115. */
  116. long SSL_get_verify_result(const SSL *ssl);
  117. /**
  118. * @brief shutdown the connection
  119. *
  120. * @param ssl - the SSL point
  121. *
  122. * @return result
  123. * 1 : OK
  124. * 0 : shutdown is not finished
  125. * -1 : an error catch
  126. */
  127. int SSL_shutdown(SSL *ssl);
  128. /**
  129. * @brief bind the socket file description into the SSL
  130. *
  131. * @param ssl - the SSL point
  132. * @param fd - socket handle
  133. *
  134. * @return result
  135. * 1 : OK
  136. * 0 : failed
  137. */
  138. int SSL_set_fd(SSL *ssl, int fd);
  139. /**
  140. * @brief Set the hostname for SNI
  141. *
  142. * @param ssl - the SSL context point
  143. * @param hostname - pointer to the hostname
  144. *
  145. * @return result
  146. * 1 : OK
  147. * 0 : failed
  148. */
  149. int SSL_set_tlsext_host_name(SSL* ssl, const char *hostname);
  150. /**
  151. * @brief These functions load the private key into the SSL_CTX or SSL object
  152. *
  153. * @param ctx - the SSL context point
  154. * @param pkey - private key object point
  155. *
  156. * @return result
  157. * 1 : OK
  158. * 0 : failed
  159. */
  160. int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
  161. /**
  162. * @brief These functions load the certification into the SSL_CTX or SSL object
  163. *
  164. * @param ctx - the SSL context point
  165. * @param pkey - certification object point
  166. *
  167. * @return result
  168. * 1 : OK
  169. * 0 : failed
  170. */
  171. int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
  172. /**
  173. * @brief create the target SSL context client method
  174. *
  175. * @param none
  176. *
  177. * @return the SSLV2.3 version SSL context client method
  178. */
  179. const SSL_METHOD* SSLv23_client_method(void);
  180. /**
  181. * @brief create the target SSL context client method
  182. *
  183. * @param none
  184. *
  185. * @return the TLSV1.0 version SSL context client method
  186. */
  187. const SSL_METHOD* TLSv1_client_method(void);
  188. /**
  189. * @brief create the target SSL context client method
  190. *
  191. * @param none
  192. *
  193. * @return the SSLV1.0 version SSL context client method
  194. */
  195. const SSL_METHOD* SSLv3_client_method(void);
  196. /**
  197. * @brief create the target SSL context client method
  198. *
  199. * @param none
  200. *
  201. * @return the TLSV1.1 version SSL context client method
  202. */
  203. const SSL_METHOD* TLSv1_1_client_method(void);
  204. /**
  205. * @brief create the target SSL context client method
  206. *
  207. * @param none
  208. *
  209. * @return the TLSV1.2 version SSL context client method
  210. */
  211. const SSL_METHOD* TLSv1_2_client_method(void);
  212. /**
  213. * @brief create the target SSL context server method
  214. *
  215. * @param none
  216. *
  217. * @return the TLS any version SSL context client method
  218. */
  219. const SSL_METHOD* TLS_client_method(void);
  220. /**
  221. * @brief create the target SSL context server method
  222. *
  223. * @param none
  224. *
  225. * @return the SSLV2.3 version SSL context server method
  226. */
  227. const SSL_METHOD* SSLv23_server_method(void);
  228. /**
  229. * @brief create the target SSL context server method
  230. *
  231. * @param none
  232. *
  233. * @return the TLSV1.1 version SSL context server method
  234. */
  235. const SSL_METHOD* TLSv1_1_server_method(void);
  236. /**
  237. * @brief create the target SSL context server method
  238. *
  239. * @param none
  240. *
  241. * @return the TLSV1.2 version SSL context server method
  242. */
  243. const SSL_METHOD* TLSv1_2_server_method(void);
  244. /**
  245. * @brief create the target SSL context server method
  246. *
  247. * @param none
  248. *
  249. * @return the TLSV1.0 version SSL context server method
  250. */
  251. const SSL_METHOD* TLSv1_server_method(void);
  252. /**
  253. * @brief create the target SSL context server method
  254. *
  255. * @param none
  256. *
  257. * @return the SSLV3.0 version SSL context server method
  258. */
  259. const SSL_METHOD* SSLv3_server_method(void);
  260. /**
  261. * @brief create the target SSL context server method
  262. *
  263. * @param none
  264. *
  265. * @return the TLS any version SSL context server method
  266. */
  267. const SSL_METHOD* TLS_server_method(void);
  268. /**
  269. * @brief create the target SSL context method
  270. *
  271. * @return the TLS any version SSL context method
  272. */
  273. const SSL_METHOD* TLS_method(void);
  274. /**
  275. * @brief create the target SSL context method
  276. *
  277. * @return the TLS1.2 version SSL context method
  278. */
  279. const SSL_METHOD* TLSv1_2_method(void);
  280. /**
  281. * @brief create the target SSL context method
  282. *
  283. * @return the TLS1.1 version SSL context method
  284. */
  285. const SSL_METHOD* TLSv1_1_method(void);
  286. /**
  287. * @brief create the target SSL context method
  288. *
  289. * @return the TLS1.0 version SSL context method
  290. */
  291. const SSL_METHOD* TLSv1_method(void);
  292. /**
  293. * @brief create the target SSL context method
  294. *
  295. * @return the SSLV3.0 version SSL context method
  296. */
  297. const SSL_METHOD* SSLv3_method(void);
  298. /**
  299. * @brief create the target SSL context method
  300. *
  301. * @param none
  302. *
  303. * @return the SSLV2.3 version SSL context method
  304. */
  305. const SSL_METHOD* SSLv23_method(void);
  306. /**
  307. * @brief Set minimum protocol version for defined context
  308. *
  309. * @param ctx SSL context
  310. *
  311. * @return 1 on success
  312. */
  313. int SSL_CTX_set_min_proto_version(SSL_CTX *ctx, int version);
  314. /**
  315. * @brief Set maximum protocol version for defined context
  316. *
  317. * @param ctx SSL context
  318. *
  319. * @return 1 on success
  320. */
  321. int SSL_CTX_set_max_proto_version(SSL_CTX *ctx, int version);
  322. /**
  323. * @brief set the SSL context ALPN select callback function
  324. *
  325. * @param ctx - SSL context point
  326. * @param cb - ALPN select callback function
  327. * @param arg - ALPN select callback function entry private data point
  328. *
  329. * @return none
  330. */
  331. void SSL_CTX_set_alpn_select_cb(SSL_CTX *ctx,
  332. int (*cb) (SSL *ssl,
  333. const unsigned char **out,
  334. unsigned char *outlen,
  335. const unsigned char *in,
  336. unsigned int inlen,
  337. void *arg),
  338. void *arg);
  339. /**
  340. * @brief set the SSL context ALPN select protocol
  341. *
  342. * @param ctx - SSL context point
  343. * @param protos - ALPN protocol name
  344. * @param protos_len - ALPN protocol name bytes
  345. *
  346. * @return result
  347. * 0 : OK
  348. * 1 : failed
  349. */
  350. int SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const unsigned char *protos, unsigned int protos_len);
  351. /**
  352. * @brief set the SSL context next ALPN select callback function
  353. *
  354. * @param ctx - SSL context point
  355. * @param cb - ALPN select callback function
  356. * @param arg - ALPN select callback function entry private data point
  357. *
  358. * @return none
  359. */
  360. void SSL_CTX_set_next_proto_select_cb(SSL_CTX *ctx,
  361. int (*cb) (SSL *ssl,
  362. unsigned char **out,
  363. unsigned char *outlen,
  364. const unsigned char *in,
  365. unsigned int inlen,
  366. void *arg),
  367. void *arg);
  368. /**
  369. * @brief initialize the SSL library
  370. *
  371. * @param none
  372. *
  373. * @return none
  374. */
  375. void SSL_library_init(void);
  376. /**
  377. * @brief generates a human-readable string representing the error code e
  378. * and store it into the "ret" point memory
  379. *
  380. * @param e - error code
  381. * @param ret - memory point to store the string
  382. *
  383. * @return the result string point
  384. */
  385. char *ERR_error_string(unsigned long e, char *ret);
  386. /**
  387. * @brief add the SSL context option
  388. *
  389. * @param ctx - SSL context point
  390. * @param opt - new SSL context option
  391. *
  392. * @return the SSL context option
  393. */
  394. unsigned long SSL_CTX_set_options(SSL_CTX *ctx, unsigned long opt);
  395. /**
  396. * @brief add the SSL context mode
  397. *
  398. * @param ctx - SSL context point
  399. * @param mod - new SSL context mod
  400. *
  401. * @return result
  402. * 1 : OK
  403. * 0 : failed
  404. */
  405. int SSL_CTX_set_mode(SSL_CTX *ctx, int mod);
  406. /*
  407. }
  408. */
  409. /**
  410. * @brief perform the SSL handshake
  411. *
  412. * @param ssl - SSL point
  413. *
  414. * @return result
  415. * 1 : OK
  416. * 0 : failed
  417. * -1 : a error catch
  418. */
  419. int SSL_do_handshake(SSL *ssl);
  420. /**
  421. * @brief get the SSL current version
  422. *
  423. * @param ssl - SSL point
  424. *
  425. * @return the version string
  426. */
  427. const char *SSL_get_version(const SSL *ssl);
  428. /**
  429. * @brief set the SSL context version
  430. *
  431. * @param ctx - SSL context point
  432. * @param meth - SSL method point
  433. *
  434. * @return result
  435. * 1 : OK
  436. * 0 : failed
  437. */
  438. int SSL_CTX_set_ssl_version(SSL_CTX *ctx, const SSL_METHOD *meth);
  439. /**
  440. * @brief get the bytes numbers which are to be read
  441. *
  442. * @param ssl - SSL point
  443. *
  444. * @return bytes number
  445. */
  446. int SSL_pending(const SSL *ssl);
  447. /**
  448. * @brief check if SSL want nothing
  449. *
  450. * @param ssl - SSL point
  451. *
  452. * @return result
  453. * 0 : false
  454. * 1 : true
  455. */
  456. int SSL_want_nothing(const SSL *ssl);
  457. /**
  458. * @brief check if SSL want to read
  459. *
  460. * @param ssl - SSL point
  461. *
  462. * @return result
  463. * 0 : false
  464. * 1 : true
  465. */
  466. int SSL_want_read(const SSL *ssl);
  467. /**
  468. * @brief check if SSL want to write
  469. *
  470. * @param ssl - SSL point
  471. *
  472. * @return result
  473. * 0 : false
  474. * 1 : true
  475. */
  476. int SSL_want_write(const SSL *ssl);
  477. /**
  478. * @brief get the SSL context current method
  479. *
  480. * @param ctx - SSL context point
  481. *
  482. * @return the SSL context current method
  483. */
  484. const SSL_METHOD *SSL_CTX_get_ssl_method(SSL_CTX *ctx);
  485. /**
  486. * @brief get the SSL current method
  487. *
  488. * @param ssl - SSL point
  489. *
  490. * @return the SSL current method
  491. */
  492. const SSL_METHOD *SSL_get_ssl_method(SSL *ssl);
  493. /**
  494. * @brief set the SSL method
  495. *
  496. * @param ssl - SSL point
  497. * @param meth - SSL method point
  498. *
  499. * @return result
  500. * 1 : OK
  501. * 0 : failed
  502. */
  503. int SSL_set_ssl_method(SSL *ssl, const SSL_METHOD *method);
  504. /**
  505. * @brief add CA client certification into the SSL
  506. *
  507. * @param ssl - SSL point
  508. * @param x - CA certification point
  509. *
  510. * @return result
  511. * 1 : OK
  512. * 0 : failed
  513. */
  514. int SSL_add_client_CA(SSL *ssl, X509 *x);
  515. /**
  516. * @brief add CA client certification into the SSL context
  517. *
  518. * @param ctx - SSL context point
  519. * @param x - CA certification point
  520. *
  521. * @return result
  522. * 1 : OK
  523. * 0 : failed
  524. */
  525. int SSL_CTX_add_client_CA(SSL_CTX *ctx, X509 *x);
  526. /**
  527. * @brief set the SSL CA certification list
  528. *
  529. * @param ssl - SSL point
  530. * @param name_list - CA certification list
  531. *
  532. * @return none
  533. */
  534. void SSL_set_client_CA_list(SSL *ssl, STACK_OF(X509_NAME) *name_list);
  535. /**
  536. * @brief set the SSL context CA certification list
  537. *
  538. * @param ctx - SSL context point
  539. * @param name_list - CA certification list
  540. *
  541. * @return none
  542. */
  543. void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *name_list);
  544. /**
  545. * @briefget the SSL CA certification list
  546. *
  547. * @param ssl - SSL point
  548. *
  549. * @return CA certification list
  550. */
  551. STACK_OF(X509_NAME) *SSL_get_client_CA_list(const SSL *ssl);
  552. /**
  553. * @brief get the SSL context CA certification list
  554. *
  555. * @param ctx - SSL context point
  556. *
  557. * @return CA certification list
  558. */
  559. STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(const SSL_CTX *ctx);
  560. /**
  561. * @brief get the SSL certification point
  562. *
  563. * @param ssl - SSL point
  564. *
  565. * @return SSL certification point
  566. */
  567. X509 *SSL_get_certificate(const SSL *ssl);
  568. /**
  569. * @brief get the SSL private key point
  570. *
  571. * @param ssl - SSL point
  572. *
  573. * @return SSL private key point
  574. */
  575. EVP_PKEY *SSL_get_privatekey(const SSL *ssl);
  576. /**
  577. * @brief set the SSL information callback function
  578. *
  579. * @param ssl - SSL point
  580. * @param cb - information callback function
  581. *
  582. * @return none
  583. */
  584. void SSL_set_info_callback(SSL *ssl, void (*cb) (const SSL *ssl, int type, int val));
  585. /**
  586. * @brief get the SSL state
  587. *
  588. * @param ssl - SSL point
  589. *
  590. * @return SSL state
  591. */
  592. OSSL_HANDSHAKE_STATE SSL_get_state(const SSL *ssl);
  593. /**
  594. * @brief set the SSL context read buffer length
  595. *
  596. * @param ctx - SSL context point
  597. * @param len - read buffer length
  598. *
  599. * @return none
  600. */
  601. void SSL_CTX_set_default_read_buffer_len(SSL_CTX *ctx, size_t len);
  602. /**
  603. * @brief set the SSL read buffer length
  604. *
  605. * @param ssl - SSL point
  606. * @param len - read buffer length
  607. *
  608. * @return none
  609. */
  610. void SSL_set_default_read_buffer_len(SSL *ssl, size_t len);
  611. /**
  612. * @brief set the SSL security level
  613. *
  614. * @param ssl - SSL point
  615. * @param level - security level
  616. *
  617. * @return none
  618. */
  619. void SSL_set_security_level(SSL *ssl, int level);
  620. /**
  621. * @brief get the SSL security level
  622. *
  623. * @param ssl - SSL point
  624. *
  625. * @return security level
  626. */
  627. int SSL_get_security_level(const SSL *ssl);
  628. /**
  629. * @brief get the SSL verifying mode of the SSL context
  630. *
  631. * @param ctx - SSL context point
  632. *
  633. * @return verifying mode
  634. */
  635. int SSL_CTX_get_verify_mode(const SSL_CTX *ctx);
  636. /**
  637. * @brief get the SSL verifying depth of the SSL context
  638. *
  639. * @param ctx - SSL context point
  640. *
  641. * @return verifying depth
  642. */
  643. int SSL_CTX_get_verify_depth(const SSL_CTX *ctx);
  644. /**
  645. * @brief set the SSL context verifying of the SSL context
  646. *
  647. * @param ctx - SSL context point
  648. * @param mode - verifying mode
  649. * @param verify_callback - verifying callback function
  650. *
  651. * @return none
  652. */
  653. void SSL_CTX_set_verify(SSL_CTX *ctx, int mode, int (*verify_callback)(int, X509_STORE_CTX *));
  654. /**
  655. * @brief set the SSL verifying of the SSL context
  656. *
  657. * @param ctx - SSL point
  658. * @param mode - verifying mode
  659. * @param verify_callback - verifying callback function
  660. *
  661. * @return none
  662. */
  663. void SSL_set_verify(SSL *s, int mode, int (*verify_callback)(int, X509_STORE_CTX *));
  664. /**
  665. * @brief set the SSL verify depth of the SSL context
  666. *
  667. * @param ctx - SSL context point
  668. * @param depth - verifying depth
  669. *
  670. * @return none
  671. */
  672. void SSL_CTX_set_verify_depth(SSL_CTX *ctx, int depth);
  673. /**
  674. * @brief certification verifying callback function
  675. *
  676. * @param preverify_ok - verifying result
  677. * @param x509_ctx - X509 certification point
  678. *
  679. * @return verifying result
  680. */
  681. int verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx);
  682. /**
  683. * @brief set the session timeout time
  684. *
  685. * @param ctx - SSL context point
  686. * @param t - new session timeout time
  687. *
  688. * @return old session timeout time
  689. */
  690. long SSL_CTX_set_timeout(SSL_CTX *ctx, long t);
  691. /**
  692. * @brief get the session timeout time
  693. *
  694. * @param ctx - SSL context point
  695. *
  696. * @return current session timeout time
  697. */
  698. long SSL_CTX_get_timeout(const SSL_CTX *ctx);
  699. /**
  700. * @brief set the SSL context cipher through the list string
  701. *
  702. * @param ctx - SSL context point
  703. * @param str - cipher controller list string
  704. *
  705. * @return result
  706. * 1 : OK
  707. * 0 : failed
  708. */
  709. int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str);
  710. /**
  711. * @brief set the SSL cipher through the list string
  712. *
  713. * @param ssl - SSL point
  714. * @param str - cipher controller list string
  715. *
  716. * @return result
  717. * 1 : OK
  718. * 0 : failed
  719. */
  720. int SSL_set_cipher_list(SSL *ssl, const char *str);
  721. /**
  722. * @brief get the SSL cipher list string
  723. *
  724. * @param ssl - SSL point
  725. *
  726. * @return cipher controller list string
  727. */
  728. const char *SSL_get_cipher_list(const SSL *ssl, int n);
  729. /**
  730. * @brief get the SSL cipher
  731. *
  732. * @param ssl - SSL point
  733. *
  734. * @return current cipher
  735. */
  736. const SSL_CIPHER *SSL_get_current_cipher(const SSL *ssl);
  737. /**
  738. * @brief get the SSL cipher string
  739. *
  740. * @param ssl - SSL point
  741. *
  742. * @return cipher string
  743. */
  744. const char *SSL_get_cipher(const SSL *ssl);
  745. /**
  746. * @brief get the SSL context object X509 certification storage
  747. *
  748. * @param ctx - SSL context point
  749. *
  750. * @return x509 certification storage
  751. */
  752. X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *ctx);
  753. /**
  754. * @brief set the SSL context object X509 certification store
  755. *
  756. * @param ctx - SSL context point
  757. * @param store - X509 certification store
  758. *
  759. * @return none
  760. */
  761. void SSL_CTX_set_cert_store(SSL_CTX *ctx, X509_STORE *store);
  762. /**
  763. * @brief get the SSL specifical statement
  764. *
  765. * @param ssl - SSL point
  766. *
  767. * @return specifical statement
  768. */
  769. int SSL_want(const SSL *ssl);
  770. /**
  771. * @brief check if the SSL is SSL_X509_LOOKUP state
  772. *
  773. * @param ssl - SSL point
  774. *
  775. * @return result
  776. * 1 : OK
  777. * 0 : failed
  778. */
  779. int SSL_want_x509_lookup(const SSL *ssl);
  780. /**
  781. * @brief reset the SSL
  782. *
  783. * @param ssl - SSL point
  784. *
  785. * @return result
  786. * 1 : OK
  787. * 0 : failed
  788. */
  789. int SSL_clear(SSL *ssl);
  790. /**
  791. * @brief get the socket handle of the SSL
  792. *
  793. * @param ssl - SSL point
  794. *
  795. * @return result
  796. * >= 0 : yes, and return socket handle
  797. * < 0 : a error catch
  798. */
  799. int SSL_get_fd(const SSL *ssl);
  800. /**
  801. * @brief get the read only socket handle of the SSL
  802. *
  803. * @param ssl - SSL point
  804. *
  805. * @return result
  806. * >= 0 : yes, and return socket handle
  807. * < 0 : a error catch
  808. */
  809. int SSL_get_rfd(const SSL *ssl);
  810. /**
  811. * @brief get the write only socket handle of the SSL
  812. *
  813. * @param ssl - SSL point
  814. *
  815. * @return result
  816. * >= 0 : yes, and return socket handle
  817. * < 0 : a error catch
  818. */
  819. int SSL_get_wfd(const SSL *ssl);
  820. /**
  821. * @brief set the SSL if we can read as many as data
  822. *
  823. * @param ssl - SSL point
  824. * @param yes - enable the function
  825. *
  826. * @return none
  827. */
  828. void SSL_set_read_ahead(SSL *s, int yes);
  829. /**
  830. * @brief set the SSL context if we can read as many as data
  831. *
  832. * @param ctx - SSL context point
  833. * @param yes - enbale the function
  834. *
  835. * @return none
  836. */
  837. void SSL_CTX_set_read_ahead(SSL_CTX *ctx, int yes);
  838. /**
  839. * @brief get the SSL ahead signal if we can read as many as data
  840. *
  841. * @param ssl - SSL point
  842. *
  843. * @return SSL context ahead signal
  844. */
  845. int SSL_get_read_ahead(const SSL *ssl);
  846. /**
  847. * @brief get the SSL context ahead signal if we can read as many as data
  848. *
  849. * @param ctx - SSL context point
  850. *
  851. * @return SSL context ahead signal
  852. */
  853. long SSL_CTX_get_read_ahead(SSL_CTX *ctx);
  854. /**
  855. * @brief check if some data can be read
  856. *
  857. * @param ssl - SSL point
  858. *
  859. * @return
  860. * 1 : there are bytes to be read
  861. * 0 : no data
  862. */
  863. int SSL_has_pending(const SSL *ssl);
  864. /**
  865. * @brief load the X509 certification into SSL context
  866. *
  867. * @param ctx - SSL context point
  868. * @param x - X509 certification point
  869. *
  870. * @return result
  871. * 1 : OK
  872. * 0 : failed
  873. */
  874. int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);//loads the certificate x into ctx
  875. /**
  876. * @brief load the ASN1 certification into SSL context
  877. *
  878. * @param ctx - SSL context point
  879. * @param len - certification length
  880. * @param d - data point
  881. *
  882. * @return result
  883. * 1 : OK
  884. * 0 : failed
  885. */
  886. int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, const unsigned char *d);
  887. /**
  888. * @brief load the certification file into SSL context
  889. *
  890. * @param ctx - SSL context point
  891. * @param file - certification file name
  892. * @param type - certification encoding type
  893. *
  894. * @return result
  895. * 1 : OK
  896. * 0 : failed
  897. */
  898. int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type);
  899. /**
  900. * @brief load the certification chain file into SSL context
  901. *
  902. * @param ctx - SSL context point
  903. * @param file - certification chain file name
  904. *
  905. * @return result
  906. * 1 : OK
  907. * 0 : failed
  908. */
  909. int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file);
  910. /**
  911. * @brief load the ASN1 private key into SSL context
  912. *
  913. * @param ctx - SSL context point
  914. * @param d - data point
  915. * @param len - private key length
  916. *
  917. * @return result
  918. * 1 : OK
  919. * 0 : failed
  920. */
  921. int SSL_CTX_use_PrivateKey_ASN1(int pk, SSL_CTX *ctx, const unsigned char *d, long len);//adds the private key of type pk stored at memory location d (length len) to ctx
  922. /**
  923. * @brief load the private key file into SSL context
  924. *
  925. * @param ctx - SSL context point
  926. * @param file - private key file name
  927. * @param type - private key encoding type
  928. *
  929. * @return result
  930. * 1 : OK
  931. * 0 : failed
  932. */
  933. int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type);
  934. /**
  935. * @brief load the RSA private key into SSL context
  936. *
  937. * @param ctx - SSL context point
  938. * @param x - RSA private key point
  939. *
  940. * @return result
  941. * 1 : OK
  942. * 0 : failed
  943. */
  944. int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa);
  945. /**
  946. * @brief load the RSA ASN1 private key into SSL context
  947. *
  948. * @param ctx - SSL context point
  949. * @param d - data point
  950. * @param len - RSA private key length
  951. *
  952. * @return result
  953. * 1 : OK
  954. * 0 : failed
  955. */
  956. int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, const unsigned char *d, long len);
  957. /**
  958. * @brief load the RSA private key file into SSL context
  959. *
  960. * @param ctx - SSL context point
  961. * @param file - RSA private key file name
  962. * @param type - private key encoding type
  963. *
  964. * @return result
  965. * 1 : OK
  966. * 0 : failed
  967. */
  968. int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type);
  969. /**
  970. * @brief check if the private key and certification is matched
  971. *
  972. * @param ctx - SSL context point
  973. *
  974. * @return result
  975. * 1 : OK
  976. * 0 : failed
  977. */
  978. int SSL_CTX_check_private_key(const SSL_CTX *ctx);
  979. /**
  980. * @brief set the SSL context server information
  981. *
  982. * @param ctx - SSL context point
  983. * @param serverinfo - server information string
  984. * @param serverinfo_length - server information length
  985. *
  986. * @return result
  987. * 1 : OK
  988. * 0 : failed
  989. */
  990. int SSL_CTX_use_serverinfo(SSL_CTX *ctx, const unsigned char *serverinfo, size_t serverinfo_length);
  991. /**
  992. * @brief load the SSL context server infomation file into SSL context
  993. *
  994. * @param ctx - SSL context point
  995. * @param file - server information file
  996. *
  997. * @return result
  998. * 1 : OK
  999. * 0 : failed
  1000. */
  1001. int SSL_CTX_use_serverinfo_file(SSL_CTX *ctx, const char *file);
  1002. /**
  1003. * @brief SSL select next function
  1004. *
  1005. * @param out - point of output data point
  1006. * @param outlen - output data length
  1007. * @param in - input data
  1008. * @param inlen - input data length
  1009. * @param client - client data point
  1010. * @param client_len -client data length
  1011. *
  1012. * @return NPN state
  1013. * OPENSSL_NPN_UNSUPPORTED : not support
  1014. * OPENSSL_NPN_NEGOTIATED : negotiated
  1015. * OPENSSL_NPN_NO_OVERLAP : no overlap
  1016. */
  1017. int SSL_select_next_proto(unsigned char **out, unsigned char *outlen,
  1018. const unsigned char *in, unsigned int inlen,
  1019. const unsigned char *client, unsigned int client_len);
  1020. /**
  1021. * @brief load the extra certification chain into the SSL context
  1022. *
  1023. * @param ctx - SSL context point
  1024. * @param x509 - X509 certification
  1025. *
  1026. * @return result
  1027. * 1 : OK
  1028. * 0 : failed
  1029. */
  1030. long SSL_CTX_add_extra_chain_cert(SSL_CTX *ctx, X509 *);
  1031. /**
  1032. * @brief control the SSL context
  1033. *
  1034. * @param ctx - SSL context point
  1035. * @param cmd - command
  1036. * @param larg - parameter length
  1037. * @param parg - parameter point
  1038. *
  1039. * @return result
  1040. * 1 : OK
  1041. * 0 : failed
  1042. */
  1043. long SSL_CTX_ctrl(SSL_CTX *ctx, int cmd, long larg, char *parg);
  1044. /**
  1045. * @brief get the SSL context cipher
  1046. *
  1047. * @param ctx - SSL context point
  1048. *
  1049. * @return SSL context cipher
  1050. */
  1051. STACK *SSL_CTX_get_ciphers(const SSL_CTX *ctx);
  1052. /**
  1053. * @brief check if the SSL context can read as many as data
  1054. *
  1055. * @param ctx - SSL context point
  1056. *
  1057. * @return result
  1058. * 1 : OK
  1059. * 0 : failed
  1060. */
  1061. long SSL_CTX_get_default_read_ahead(SSL_CTX *ctx);
  1062. /**
  1063. * @brief get the SSL context extra data
  1064. *
  1065. * @param ctx - SSL context point
  1066. * @param idx - index
  1067. *
  1068. * @return data point
  1069. */
  1070. char *SSL_CTX_get_ex_data(const SSL_CTX *ctx, int idx);
  1071. /**
  1072. * @brief get the SSL context quiet shutdown option
  1073. *
  1074. * @param ctx - SSL context point
  1075. *
  1076. * @return quiet shutdown option
  1077. */
  1078. int SSL_CTX_get_quiet_shutdown(const SSL_CTX *ctx);
  1079. /**
  1080. * @brief load the SSL context CA file
  1081. *
  1082. * @param ctx - SSL context point
  1083. * @param CAfile - CA certification file
  1084. * @param CApath - CA certification file path
  1085. *
  1086. * @return result
  1087. * 1 : OK
  1088. * 0 : failed
  1089. */
  1090. int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile, const char *CApath);
  1091. /**
  1092. * @brief add SSL context reference count by '1'
  1093. *
  1094. * @param ctx - SSL context point
  1095. *
  1096. * @return result
  1097. * 1 : OK
  1098. * 0 : failed
  1099. */
  1100. int SSL_CTX_up_ref(SSL_CTX *ctx);
  1101. /**
  1102. * @brief set SSL context application private data
  1103. *
  1104. * @param ctx - SSL context point
  1105. * @param arg - private data
  1106. *
  1107. * @return result
  1108. * 1 : OK
  1109. * 0 : failed
  1110. */
  1111. int SSL_CTX_set_app_data(SSL_CTX *ctx, void *arg);
  1112. /**
  1113. * @brief set SSL context client certification callback function
  1114. *
  1115. * @param ctx - SSL context point
  1116. * @param cb - callback function
  1117. *
  1118. * @return none
  1119. */
  1120. void SSL_CTX_set_client_cert_cb(SSL_CTX *ctx, int (*cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey));
  1121. /**
  1122. * @brief set the SSL context if we can read as many as data
  1123. *
  1124. * @param ctx - SSL context point
  1125. * @param m - enable the fuction
  1126. *
  1127. * @return none
  1128. */
  1129. void SSL_CTX_set_default_read_ahead(SSL_CTX *ctx, int m);
  1130. /**
  1131. * @brief set SSL context default verifying path
  1132. *
  1133. * @param ctx - SSL context point
  1134. *
  1135. * @return result
  1136. * 1 : OK
  1137. * 0 : failed
  1138. */
  1139. int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx);
  1140. /**
  1141. * @brief set SSL context default verifying directory
  1142. *
  1143. * @param ctx - SSL context point
  1144. *
  1145. * @return result
  1146. * 1 : OK
  1147. * 0 : failed
  1148. */
  1149. int SSL_CTX_set_default_verify_dir(SSL_CTX *ctx);
  1150. /**
  1151. * @brief set SSL context default verifying file
  1152. *
  1153. * @param ctx - SSL context point
  1154. *
  1155. * @return result
  1156. * 1 : OK
  1157. * 0 : failed
  1158. */
  1159. int SSL_CTX_set_default_verify_file(SSL_CTX *ctx);
  1160. /**
  1161. * @brief set SSL context extra data
  1162. *
  1163. * @param ctx - SSL context point
  1164. * @param idx - data index
  1165. * @param arg - data point
  1166. *
  1167. * @return result
  1168. * 1 : OK
  1169. * 0 : failed
  1170. */
  1171. int SSL_CTX_set_ex_data(SSL_CTX *s, int idx, char *arg);
  1172. /**
  1173. * @brief clear the SSL context option bit of "op"
  1174. *
  1175. * @param ctx - SSL context point
  1176. * @param op - option
  1177. *
  1178. * @return SSL context option
  1179. */
  1180. unsigned long SSL_CTX_clear_options(SSL_CTX *ctx, unsigned long op);
  1181. /**
  1182. * @brief get the SSL context option
  1183. *
  1184. * @param ctx - SSL context point
  1185. * @param op - option
  1186. *
  1187. * @return SSL context option
  1188. */
  1189. unsigned long SSL_CTX_get_options(SSL_CTX *ctx);
  1190. /**
  1191. * @brief set the SSL context quiet shutdown mode
  1192. *
  1193. * @param ctx - SSL context point
  1194. * @param mode - mode
  1195. *
  1196. * @return none
  1197. */
  1198. void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx, int mode);
  1199. /**
  1200. * @brief get the SSL context X509 certification
  1201. *
  1202. * @param ctx - SSL context point
  1203. *
  1204. * @return X509 certification
  1205. */
  1206. X509 *SSL_CTX_get0_certificate(const SSL_CTX *ctx);
  1207. /**
  1208. * @brief get the SSL context private key
  1209. *
  1210. * @param ctx - SSL context point
  1211. *
  1212. * @return private key
  1213. */
  1214. EVP_PKEY *SSL_CTX_get0_privatekey(const SSL_CTX *ctx);
  1215. /**
  1216. * @brief set SSL context PSK identity hint
  1217. *
  1218. * @param ctx - SSL context point
  1219. * @param hint - PSK identity hint
  1220. *
  1221. * @return result
  1222. * 1 : OK
  1223. * 0 : failed
  1224. */
  1225. int SSL_CTX_use_psk_identity_hint(SSL_CTX *ctx, const char *hint);
  1226. /**
  1227. * @brief set SSL context PSK server callback function
  1228. *
  1229. * @param ctx - SSL context point
  1230. * @param callback - callback function
  1231. *
  1232. * @return none
  1233. */
  1234. void SSL_CTX_set_psk_server_callback(SSL_CTX *ctx,
  1235. unsigned int (*callback)(SSL *ssl,
  1236. const char *identity,
  1237. unsigned char *psk,
  1238. int max_psk_len));
  1239. /**
  1240. * @brief get alert description string
  1241. *
  1242. * @param value - alert value
  1243. *
  1244. * @return alert description string
  1245. */
  1246. const char *SSL_alert_desc_string(int value);
  1247. /**
  1248. * @brief get alert description long string
  1249. *
  1250. * @param value - alert value
  1251. *
  1252. * @return alert description long string
  1253. */
  1254. const char *SSL_alert_desc_string_long(int value);
  1255. /**
  1256. * @brief get alert type string
  1257. *
  1258. * @param value - alert value
  1259. *
  1260. * @return alert type string
  1261. */
  1262. const char *SSL_alert_type_string(int value);
  1263. /**
  1264. * @brief get alert type long string
  1265. *
  1266. * @param value - alert value
  1267. *
  1268. * @return alert type long string
  1269. */
  1270. const char *SSL_alert_type_string_long(int value);
  1271. /**
  1272. * @brief get SSL context of the SSL
  1273. *
  1274. * @param ssl - SSL point
  1275. *
  1276. * @return SSL context
  1277. */
  1278. SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl);
  1279. /**
  1280. * @brief get SSL application data
  1281. *
  1282. * @param ssl - SSL point
  1283. *
  1284. * @return application data
  1285. */
  1286. void *SSL_get_app_data(SSL *ssl);
  1287. /**
  1288. * @brief get SSL error code
  1289. *
  1290. * @param ssl - SSL point
  1291. * @param ret_code - SSL return code
  1292. *
  1293. * @return SSL error number
  1294. */
  1295. int SSL_get_error(const SSL *ssl, int ret_code);
  1296. /**
  1297. * @brief get SSL cipher bits
  1298. *
  1299. * @param ssl - SSL point
  1300. * @param alg_bits - algorithm bits
  1301. *
  1302. * @return strength bits
  1303. */
  1304. int SSL_get_cipher_bits(const SSL *ssl, int *alg_bits);
  1305. /**
  1306. * @brief get SSL cipher name
  1307. *
  1308. * @param ssl - SSL point
  1309. *
  1310. * @return SSL cipher name
  1311. */
  1312. char *SSL_get_cipher_name(const SSL *ssl);
  1313. /**
  1314. * @brief get SSL cipher version
  1315. *
  1316. * @param ssl - SSL point
  1317. *
  1318. * @return SSL cipher version
  1319. */
  1320. char *SSL_get_cipher_version(const SSL *ssl);
  1321. /**
  1322. * @brief get SSL extra data
  1323. *
  1324. * @param ssl - SSL point
  1325. * @param idx - data index
  1326. *
  1327. * @return extra data
  1328. */
  1329. char *SSL_get_ex_data(const SSL *ssl, int idx);
  1330. /**
  1331. * @brief get index of the SSL extra data X509 storage context
  1332. *
  1333. * @param none
  1334. *
  1335. * @return data index
  1336. */
  1337. int SSL_get_ex_data_X509_STORE_CTX_idx(void);
  1338. /**
  1339. * @brief get peer certification chain
  1340. *
  1341. * @param ssl - SSL point
  1342. *
  1343. * @return certification chain
  1344. */
  1345. STACK *SSL_get_peer_cert_chain(const SSL *ssl);
  1346. /**
  1347. * @brief get peer certification
  1348. *
  1349. * @param ssl - SSL point
  1350. *
  1351. * @return certification
  1352. */
  1353. X509 *SSL_get_peer_certificate(const SSL *ssl);
  1354. /**
  1355. * @brief get SSL quiet shutdown mode
  1356. *
  1357. * @param ssl - SSL point
  1358. *
  1359. * @return quiet shutdown mode
  1360. */
  1361. int SSL_get_quiet_shutdown(const SSL *ssl);
  1362. /**
  1363. * @brief get SSL read only IO handle
  1364. *
  1365. * @param ssl - SSL point
  1366. *
  1367. * @return IO handle
  1368. */
  1369. BIO *SSL_get_rbio(const SSL *ssl);
  1370. /**
  1371. * @brief get SSL shared ciphers
  1372. *
  1373. * @param ssl - SSL point
  1374. * @param buf - buffer to store the ciphers
  1375. * @param len - buffer len
  1376. *
  1377. * @return shared ciphers
  1378. */
  1379. char *SSL_get_shared_ciphers(const SSL *ssl, char *buf, int len);
  1380. /**
  1381. * @brief get SSL shutdown mode
  1382. *
  1383. * @param ssl - SSL point
  1384. *
  1385. * @return shutdown mode
  1386. */
  1387. int SSL_get_shutdown(const SSL *ssl);
  1388. /**
  1389. * @brief get SSL session time
  1390. *
  1391. * @param ssl - SSL point
  1392. *
  1393. * @return session time
  1394. */
  1395. long SSL_get_time(const SSL *ssl);
  1396. /**
  1397. * @brief get SSL session timeout time
  1398. *
  1399. * @param ssl - SSL point
  1400. *
  1401. * @return session timeout time
  1402. */
  1403. long SSL_get_timeout(const SSL *ssl);
  1404. /**
  1405. * @brief get SSL verifying mode
  1406. *
  1407. * @param ssl - SSL point
  1408. *
  1409. * @return verifying mode
  1410. */
  1411. int SSL_get_verify_mode(const SSL *ssl);
  1412. /**
  1413. * @brief get SSL verify parameters
  1414. *
  1415. * @param ssl - SSL point
  1416. *
  1417. * @return verify parameters
  1418. */
  1419. X509_VERIFY_PARAM *SSL_get0_param(SSL *ssl);
  1420. /**
  1421. * @brief set expected hostname the peer cert CN should have
  1422. *
  1423. * @param param - verify parameters from SSL_get0_param()
  1424. *
  1425. * @param name - the expected hostname
  1426. *
  1427. * @param namelen - the length of the hostname, or 0 if NUL terminated
  1428. *
  1429. * @return verify parameters
  1430. */
  1431. int X509_VERIFY_PARAM_set1_host(X509_VERIFY_PARAM *param,
  1432. const char *name, size_t namelen);
  1433. /**
  1434. * @brief set parameters for X509 host verify action
  1435. *
  1436. * @param param -verify parameters from SSL_get0_param()
  1437. *
  1438. * @param flags - bitfield of X509_CHECK_FLAG_... parameters to set
  1439. *
  1440. * @return 1 for success, 0 for failure
  1441. */
  1442. int X509_VERIFY_PARAM_set_hostflags(X509_VERIFY_PARAM *param,
  1443. unsigned long flags);
  1444. /**
  1445. * @brief clear parameters for X509 host verify action
  1446. *
  1447. * @param param -verify parameters from SSL_get0_param()
  1448. *
  1449. * @param flags - bitfield of X509_CHECK_FLAG_... parameters to clear
  1450. *
  1451. * @return 1 for success, 0 for failure
  1452. */
  1453. int X509_VERIFY_PARAM_clear_hostflags(X509_VERIFY_PARAM *param,
  1454. unsigned long flags);
  1455. /**
  1456. * @brief get SSL write only IO handle
  1457. *
  1458. * @param ssl - SSL point
  1459. *
  1460. * @return IO handle
  1461. */
  1462. BIO *SSL_get_wbio(const SSL *ssl);
  1463. /**
  1464. * @brief load SSL client CA certification file
  1465. *
  1466. * @param file - file name
  1467. *
  1468. * @return certification loading object
  1469. */
  1470. STACK *SSL_load_client_CA_file(const char *file);
  1471. /**
  1472. * @brief add SSL reference by '1'
  1473. *
  1474. * @param ssl - SSL point
  1475. *
  1476. * @return result
  1477. * 1 : OK
  1478. * 0 : failed
  1479. */
  1480. int SSL_up_ref(SSL *ssl);
  1481. /**
  1482. * @brief read and put data into buf, but not clear the SSL low-level storage
  1483. *
  1484. * @param ssl - SSL point
  1485. * @param buf - storage buffer point
  1486. * @param num - data bytes
  1487. *
  1488. * @return result
  1489. * > 0 : OK, and return read bytes
  1490. * = 0 : connect is closed
  1491. * < 0 : a error catch
  1492. */
  1493. int SSL_peek(SSL *ssl, void *buf, int num);
  1494. /**
  1495. * @brief make SSL renegotiate
  1496. *
  1497. * @param ssl - SSL point
  1498. *
  1499. * @return result
  1500. * 1 : OK
  1501. * 0 : failed
  1502. */
  1503. int SSL_renegotiate(SSL *ssl);
  1504. /**
  1505. * @brief get the state string where SSL is reading
  1506. *
  1507. * @param ssl - SSL point
  1508. *
  1509. * @return state string
  1510. */
  1511. const char *SSL_rstate_string(SSL *ssl);
  1512. /**
  1513. * @brief get the statement long string where SSL is reading
  1514. *
  1515. * @param ssl - SSL point
  1516. *
  1517. * @return statement long string
  1518. */
  1519. const char *SSL_rstate_string_long(SSL *ssl);
  1520. /**
  1521. * @brief set SSL accept statement
  1522. *
  1523. * @param ssl - SSL point
  1524. *
  1525. * @return none
  1526. */
  1527. void SSL_set_accept_state(SSL *ssl);
  1528. /**
  1529. * @brief set SSL application data
  1530. *
  1531. * @param ssl - SSL point
  1532. * @param arg - SSL application data point
  1533. *
  1534. * @return none
  1535. */
  1536. void SSL_set_app_data(SSL *ssl, void *arg);
  1537. /**
  1538. * @brief set SSL BIO
  1539. *
  1540. * @param ssl - SSL point
  1541. * @param rbio - read only IO
  1542. * @param wbio - write only IO
  1543. *
  1544. * @return none
  1545. */
  1546. void SSL_set_bio(SSL *ssl, BIO *rbio, BIO *wbio);
  1547. /**
  1548. * @brief clear SSL option
  1549. *
  1550. * @param ssl - SSL point
  1551. * @param op - clear option
  1552. *
  1553. * @return SSL option
  1554. */
  1555. unsigned long SSL_clear_options(SSL *ssl, unsigned long op);
  1556. /**
  1557. * @brief get SSL option
  1558. *
  1559. * @param ssl - SSL point
  1560. *
  1561. * @return SSL option
  1562. */
  1563. unsigned long SSL_get_options(SSL *ssl);
  1564. /**
  1565. * @brief clear SSL option
  1566. *
  1567. * @param ssl - SSL point
  1568. * @param op - setting option
  1569. *
  1570. * @return SSL option
  1571. */
  1572. unsigned long SSL_set_options(SSL *ssl, unsigned long op);
  1573. /**
  1574. * @brief set SSL quiet shutdown mode
  1575. *
  1576. * @param ssl - SSL point
  1577. * @param mode - quiet shutdown mode
  1578. *
  1579. * @return none
  1580. */
  1581. void SSL_set_quiet_shutdown(SSL *ssl, int mode);
  1582. /**
  1583. * @brief set SSL shutdown mode
  1584. *
  1585. * @param ssl - SSL point
  1586. * @param mode - shutdown mode
  1587. *
  1588. * @return none
  1589. */
  1590. void SSL_set_shutdown(SSL *ssl, int mode);
  1591. /**
  1592. * @brief set SSL session time
  1593. *
  1594. * @param ssl - SSL point
  1595. * @param t - session time
  1596. *
  1597. * @return session time
  1598. */
  1599. void SSL_set_time(SSL *ssl, long t);
  1600. /**
  1601. * @brief set SSL session timeout time
  1602. *
  1603. * @param ssl - SSL point
  1604. * @param t - session timeout time
  1605. *
  1606. * @return session timeout time
  1607. */
  1608. void SSL_set_timeout(SSL *ssl, long t);
  1609. /**
  1610. * @brief get SSL statement string
  1611. *
  1612. * @param ssl - SSL point
  1613. *
  1614. * @return SSL statement string
  1615. */
  1616. const char *SSL_state_string(const SSL *ssl);
  1617. /**
  1618. * @brief get SSL statement long string
  1619. *
  1620. * @param ssl - SSL point
  1621. *
  1622. * @return SSL statement long string
  1623. */
  1624. char *SSL_state_string_long(const SSL *ssl);
  1625. /**
  1626. * @brief get SSL renegotiation count
  1627. *
  1628. * @param ssl - SSL point
  1629. *
  1630. * @return renegotiation count
  1631. */
  1632. long SSL_total_renegotiations(SSL *ssl);
  1633. /**
  1634. * @brief get SSL version
  1635. *
  1636. * @param ssl - SSL point
  1637. *
  1638. * @return SSL version
  1639. */
  1640. int SSL_version(const SSL *ssl);
  1641. /**
  1642. * @brief set SSL PSK identity hint
  1643. *
  1644. * @param ssl - SSL point
  1645. * @param hint - identity hint
  1646. *
  1647. * @return result
  1648. * 1 : OK
  1649. * 0 : failed
  1650. */
  1651. int SSL_use_psk_identity_hint(SSL *ssl, const char *hint);
  1652. /**
  1653. * @brief get SSL PSK identity hint
  1654. *
  1655. * @param ssl - SSL point
  1656. *
  1657. * @return identity hint
  1658. */
  1659. const char *SSL_get_psk_identity_hint(SSL *ssl);
  1660. /**
  1661. * @brief get SSL PSK identity
  1662. *
  1663. * @param ssl - SSL point
  1664. *
  1665. * @return identity
  1666. */
  1667. const char *SSL_get_psk_identity(SSL *ssl);
  1668. /**
  1669. * @brief set the SSL verify depth of the SSL
  1670. *
  1671. * @param ssl - SSL context
  1672. * @param depth - Depth level to verify
  1673. *
  1674. */
  1675. void SSL_set_verify_depth(SSL *ssl, int depth);
  1676. /**
  1677. * @brief Get default verify callback
  1678. *
  1679. * @param ctx - SSL context
  1680. * @return verify_callback - verifying callback function
  1681. *
  1682. */
  1683. openssl_verify_callback SSL_CTX_get_verify_callback(const SSL_CTX *ctx);
  1684. /**
  1685. * @brief Get default verify callback
  1686. *
  1687. * @param ctx - SSL context
  1688. * @return verify_callback - verifying callback function
  1689. *
  1690. */
  1691. openssl_verify_callback SSL_get_verify_callback(const SSL *s);
  1692. /**
  1693. * @brief Frees RSA object
  1694. *
  1695. * Current implementation calls directly EVP_PKEY free
  1696. *
  1697. * @param r RSA object
  1698. *
  1699. */
  1700. void RSA_free(RSA *r);
  1701. /**
  1702. * @brief Sets SSL mode, partially implemented
  1703. *
  1704. * @param ssl SSL context
  1705. *
  1706. * @return the new mode bitmask after adding mode
  1707. */
  1708. uint32_t SSL_set_mode(SSL *ssl, uint32_t mode);
  1709. #ifdef __cplusplus
  1710. }
  1711. #endif
  1712. #endif