openssl_apis.rst 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801
  1. OpenSSL-APIs
  2. ------------
  3. .. note:: The OpenSSL-API will be discontinued in ESP-IDF from v5.0. Please use ESP-TLS <esp_tls> instead.
  4. The code of this API (located in :component:`openssl` directory), does not contain OpenSSL itself but is intended as a wrapper for applications using the OpenSSL API.
  5. It uses mbedTLS to do the actual work, so anyone compiling openssl code needs the mbedtls library and header file.
  6. OpenSSL APIs not mentioned in this article are not open to public for the time,
  7. also do not have the corresponding function.
  8. If user calls it directly, it will always return an error or may show cannot link at compiling time.
  9. Chapter Introduction
  10. ====================
  11. - Chapter 1. SSL Context Method Create
  12. - Chapter 2. SSL Context Function
  13. - Chapter 3. SSL Function
  14. - Chapter 4. SSL X509 Certification and Private Key Function
  15. Chapter 1. SSL Context Method Create
  16. ====================================
  17. .. highlight:: none
  18. 1.1 const SSL_METHOD* ``SSLv3_client_method`` (void)
  19. Arguments::
  20. none
  21. Return::
  22. SSLV3.0 version SSL context client method point
  23. Description::
  24. create the target SSL context method
  25. Example::
  26. void example(void)
  27. {
  28. const SSL_METHOD *method = SSLv3_client_method();
  29. ...
  30. }
  31. 1.2 const SSL_METHOD* ``TLSv1_client_method`` (void)
  32. Arguments::
  33. none
  34. Return::
  35. TLSV1.0 version SSL context client method point
  36. Description::
  37. create the target SSL context method
  38. Example::
  39. void example(void)
  40. {
  41. const SSL_METHOD *method = TLSv1_client_method();
  42. ...
  43. }
  44. 1.3 const SSL_METHOD* ``TLSv1_1_client_method`` (void)
  45. Arguments::
  46. none
  47. Return::
  48. TLSV1.1 version SSL context client method point
  49. Description::
  50. create the target SSL context method
  51. Example::
  52. void example(void)
  53. {
  54. const SSL_METHOD *method = TLSv1_1_client_method();
  55. ...
  56. }
  57. 1.4 const SSL_METHOD* ``TLSv1_2_client_method`` (void)
  58. Arguments::
  59. none
  60. Return::
  61. TLSV1.2 version SSL context client method point
  62. Description::
  63. create the target SSL context method
  64. Example::
  65. void example(void)
  66. {
  67. const SSL_METHOD *method = TLSv1_2_client_method();
  68. ...
  69. }
  70. 1.5 const SSL_METHOD* ``TLS_client_method`` (void)
  71. Arguments::
  72. none
  73. Return::
  74. TLSV1.2 version SSL context client method point
  75. Description::
  76. create the default SSL context method, it's always to be TLSV1.2
  77. Example::
  78. void example(void)
  79. {
  80. const SSL_METHOD *method = TLSv1_2_client_method();
  81. ...
  82. }
  83. 1.6 const SSL_METHOD* ``SSLv3_server_method`` (void)
  84. Arguments::
  85. none
  86. Return::
  87. SSLV3.0 version SSL context server method point
  88. Description::
  89. create the target SSL context method
  90. Example::
  91. void example(void)
  92. {
  93. const SSL_METHOD *method = SSLv3_server_method();
  94. ...
  95. }
  96. 1.7 const SSL_METHOD* ``TLSv1_server_method`` (void)
  97. Arguments::
  98. none
  99. Return::
  100. TLSV1.0 version SSL context server method point
  101. Description::
  102. create the target SSL context method
  103. Example::
  104. void example(void)
  105. {
  106. const SSL_METHOD *method = TLSv1_server_method();
  107. ...
  108. }
  109. 1.8 const SSL_METHOD* ``TLSv1_1_server_method`` (void)
  110. Arguments::
  111. none
  112. Return::
  113. TLSV1.1 version SSL context server method point
  114. Description::
  115. create the target SSL context method
  116. Example::
  117. void example(void)
  118. {
  119. const SSL_METHOD *method = TLSv1_1_server_method();
  120. ...
  121. }
  122. 1.9 const SSL_METHOD* ``TLSv1_2_server_method`` (void)
  123. Arguments::
  124. none
  125. Return::
  126. TLSV1.2 version SSL context server method point
  127. Description::
  128. create the target SSL context method
  129. Example::
  130. void example(void)
  131. {
  132. const SSL_METHOD *method = TLSv1_2_server_method();
  133. ...
  134. }
  135. 1.10 const SSL_METHOD* ``TLS_server_method`` (void)
  136. Arguments::
  137. none
  138. Return::
  139. TLSV1.2 version SSL context server method point
  140. Description::
  141. create the default SSL context method, it's always to be TLSV1.2
  142. Example::
  143. void example(void)
  144. {
  145. const SSL_METHOD *method = TLSv1_2_server_method();
  146. ...
  147. }
  148. Chapter 2. SSL Context Function
  149. ===============================
  150. 2.1 SSL_CTX* ``SSL_CTX_new`` (const SSL_METHOD * method)
  151. Arguments::
  152. method - the SSL context method point
  153. Return::
  154. context point
  155. Description::
  156. create a SSL context
  157. Example::
  158. void example(void)
  159. {
  160. SSL_CTX *ctx = SSL_CTX_new(SSLv3_server_method());
  161. ...
  162. }
  163. 2.2 ``void SSL_CTX_free`` (SSL_CTX * ctx)
  164. Arguments::
  165. ctx - the SSL context point
  166. Return::
  167. none
  168. Description::
  169. free a SSL context
  170. Example::
  171. void example(void)
  172. {
  173. SSL_CTX *ctx;
  174. ... ...
  175. SSL_CTX_free(ctx);
  176. }
  177. 2.3 ``int SSL_CTX_set_ssl_version`` (SSL_CTX * ctx, const SSL_METHOD * meth)
  178. Arguments::
  179. ctx - SSL context point
  180. meth - SSL method point
  181. Return::
  182. 1 : OK
  183. 0 : failed
  184. Description::
  185. set the SSL context version
  186. Example::
  187. void example(void)
  188. {
  189. SSL_CTX *ctx;
  190. const SSL_METHOD *meth;
  191. ... ...
  192. SSL_CTX_set_ssl_version(ctx, meth);
  193. }
  194. 2.4 const SSL_METHOD* ``SSL_CTX_get_ssl_method`` (SSL_CTX * ctx)
  195. Arguments::
  196. ctx - SSL context point
  197. Return::
  198. SSL context method
  199. Description::
  200. get the SSL context method
  201. Example::
  202. void example(void)
  203. {
  204. const SSL_METHOD *method;
  205. SSL_CTX *ctx;
  206. ... ...
  207. method = SSL_CTX_get_ssl_method(ctx);
  208. }
  209. Chapter 3. SSL Function
  210. =======================
  211. 3.1 SSL* ``SSL_new`` (SSL_CTX * ctx)
  212. Arguments::
  213. ctx - SSL context point
  214. Return::
  215. SSL method
  216. Description::
  217. create a SSL
  218. Example::
  219. void example(void)
  220. {
  221. SSL *ssl;
  222. SSL_CTX *ctx;
  223. ... ...
  224. ssl = SSL_new(ctx);
  225. }
  226. 3.2 void ``SSL_free`` (SSL * ssl)
  227. Arguments::
  228. ssl - SSL point
  229. Return::
  230. none
  231. Description::
  232. free SSL
  233. Example::
  234. void example(void)
  235. {
  236. SSL *ssl;
  237. ... ...
  238. SSL_free(ssl);
  239. }
  240. 3.3 int ``SSL_do_handshake`` (SSL * ssl)
  241. Arguments::
  242. ssl - SSL point
  243. Return::
  244. 1 : OK
  245. 0 : failed, connect is close by remote
  246. -1 : a error catch
  247. Description::
  248. perform the SSL handshake
  249. Example::
  250. void example(void)
  251. {
  252. SSL *ssl;
  253. int ret;
  254. ... ...
  255. ret = SSL_do_handshake(ssl);
  256. }
  257. 3.4 int ``SSL_connect`` (SSL * ssl)
  258. Arguments::
  259. ssl - SSL point
  260. Return::
  261. 1 : OK
  262. 0 : failed, connect is close by remote
  263. -1 : a error catch
  264. Description::
  265. connect to the remote SSL server
  266. Example::
  267. void example(void)
  268. {
  269. SSL *ssl;
  270. int ret;
  271. ... ...
  272. ret = SSL_connect(ssl);
  273. }
  274. 3.5 int ``SSL_accept`` (SSL * ssl)
  275. Arguments::
  276. ssl - SSL point
  277. Return::
  278. 1 : OK
  279. 0 : failed, connect is close by remote
  280. -1 : a error catch
  281. Description::
  282. accept the remote connection
  283. Example::
  284. void example(void)
  285. {
  286. SSL *ssl;
  287. int ret;
  288. ... ...
  289. ret = SSL_accept(ssl);
  290. }
  291. 3.6 int ``SSL_shutdown`` (SSL * ssl)
  292. Arguments::
  293. ssl - SSL point
  294. Return::
  295. 1 : OK
  296. 0 : failed, connect is close by remote
  297. -1 : a error catch
  298. Description::
  299. shutdown the connection
  300. Example::
  301. void example(void)
  302. {
  303. SSL *ssl;
  304. int ret;
  305. ... ...
  306. ret = SSL_shutdown(ssl);
  307. }
  308. 3.7 int ``SSL_clear`` (SSL * ssl)
  309. Arguments::
  310. ssl - SSL point
  311. Return::
  312. 1 : OK
  313. 0 : failed
  314. Description::
  315. shutdown the connection
  316. Example::
  317. void example(void)
  318. {
  319. SSL *ssl;
  320. int ret;
  321. ... ...
  322. ret = SSL_clear(ssl);
  323. }
  324. 3.8 int ``SSL_read`` (SSL * ssl, void * buffer, int len)
  325. Arguments::
  326. ssl - point
  327. buffer - data buffer point
  328. len - data length
  329. Return::
  330. > 0 : OK, and return received data bytes
  331. = 0 : no data received or connection is closed
  332. < 0 : an error catch
  333. Description::
  334. read data from remote
  335. Example::
  336. void example(void)
  337. {
  338. SSL *ssl;
  339. char *buf;
  340. int len;
  341. int ret;
  342. ... ...
  343. ret = SSL_read(ssl, buf, len);
  344. }
  345. 3.9 int ``SSL_write`` (SSL * ssl, const void * buffer, int len)
  346. Arguments::
  347. ssl - SSL point
  348. buffer - data buffer point
  349. len - data length
  350. Return::
  351. > 0 : OK, and return received data bytes
  352. = 0 : no data sent or connection is closed
  353. < 0 : an error catch
  354. Description::
  355. send the data to remote
  356. Example::
  357. void example(void)
  358. {
  359. SSL *ssl;
  360. char *buf;
  361. int len;
  362. int ret;
  363. ... ...
  364. ret = SSL_write(ssl, buf, len);
  365. }
  366. 3.10 ``SSL_CTX *SSL_get_SSL_CTX`` (const SSL * ssl)
  367. Arguments::
  368. ssl - SSL point
  369. Return::
  370. SSL context
  371. Description::
  372. get SSL context of the SSL
  373. Example::
  374. void example(void)
  375. {
  376. SSL *ssl;
  377. SSL_CTX *ctx;
  378. ... ...
  379. ctx = SSL_get_SSL_CTX(ssl);
  380. }
  381. 3.11 int ``SSL_get_shutdown`` (const SSL * ssl)
  382. Arguments::
  383. ssl - SSL point
  384. Return::
  385. shutdown mode
  386. Description::
  387. get SSL shutdown mode
  388. Example::
  389. void example(void)
  390. {
  391. SSL *ssl;
  392. int mode;
  393. ... ...
  394. mode = SSL_get_SSL_CTX(ssl);
  395. }
  396. 3.12 void ``SSL_set_shutdown`` (SSL * ssl, int mode)
  397. Arguments::
  398. ssl - SSL point
  399. Return::
  400. shutdown mode
  401. Description::
  402. set SSL shutdown mode
  403. Example::
  404. void example(void)
  405. {
  406. SSL *ssl;
  407. int mode = 0;
  408. ... ...
  409. SSL_set_shutdown(ssl, mode);
  410. }
  411. 3.13 const SSL_METHOD* ``SSL_get_ssl_method`` (SSL * ssl)
  412. Arguments::
  413. ssl - SSL point
  414. Return::
  415. SSL method
  416. Description::
  417. set SSL shutdown mode
  418. Example::
  419. void example(void)
  420. {
  421. SSL *ssl;
  422. const SSL_METHOD *method;
  423. ... ...
  424. method = SSL_get_ssl_method(ssl);
  425. }
  426. 3.14 int ``SSL_set_ssl_method`` (SSL * ssl, const SSL_METHOD * method)
  427. Arguments::
  428. ssl - SSL point
  429. meth - SSL method point
  430. Return::
  431. 1 : OK
  432. 0 : failed
  433. Description::
  434. set the SSL method
  435. Example::
  436. void example(void)
  437. {
  438. int ret;
  439. SSL *ssl;
  440. const SSL_METHOD *method;
  441. ... ...
  442. ret = SSL_set_ssl_method(ssl, method);
  443. }
  444. 3.15 int ``SSL_pending`` (const SSL * ssl)
  445. Arguments::
  446. ssl - SSL point
  447. Return::
  448. data bytes
  449. Description::
  450. get received data bytes
  451. Example::
  452. void example(void)
  453. {
  454. int ret;
  455. SSL *ssl;
  456. ... ...
  457. ret = SSL_pending(ssl);
  458. }
  459. 3.16 int ``SSL_has_pending`` (const SSL * ssl)
  460. Arguments::
  461. ssl - SSL point
  462. Return::
  463. 1 : Yes
  464. 0 : No
  465. Description::
  466. check if data is received
  467. Example::
  468. void example(void)
  469. {
  470. int ret;
  471. SSL *ssl;
  472. ... ...
  473. ret = SSL_has_pending(ssl);
  474. }
  475. 3.17 int ``SSL_get_fd`` (const SSL * ssl)
  476. Arguments::
  477. ssl - SSL point
  478. Return::
  479. >= 0 : socket id
  480. < 0 : a error catch
  481. Description::
  482. get the socket of the SSL
  483. Example::
  484. void example(void)
  485. {
  486. int ret;
  487. SSL *ssl;
  488. ... ...
  489. ret = SSL_get_fd(ssl);
  490. }
  491. 3.18 int ``SSL_get_rfd`` (const SSL * ssl)
  492. Arguments::
  493. ssl - SSL point
  494. Return::
  495. >= 0 : socket id
  496. < 0 : a error catch
  497. Description::
  498. get the read only socket of the SSL
  499. Example::
  500. void example(void)
  501. {
  502. int ret;
  503. SSL *ssl;
  504. ... ...
  505. ret = SSL_get_rfd(ssl);
  506. }
  507. 3.19 int ``SSL_get_wfd`` (const SSL * ssl)
  508. Arguments::
  509. ssl - SSL point
  510. Return::
  511. >= 0 : socket id
  512. < 0 : a error catch
  513. Description::
  514. get the write only socket of the SSL
  515. Example::
  516. void example(void)
  517. {
  518. int ret;
  519. SSL *ssl;
  520. ... ...
  521. ret = SSL_get_wfd(ssl);
  522. }
  523. 3.20 int ``SSL_set_fd`` (SSL * ssl, int fd)
  524. Arguments::
  525. ssl - SSL point
  526. fd - socket id
  527. Return::
  528. 1 : OK
  529. 0 : failed
  530. Description::
  531. set socket to SSL
  532. Example::
  533. void example(void)
  534. {
  535. int ret;
  536. SSL *ssl;
  537. int socket;
  538. ... ...
  539. ret = SSL_set_fd(ssl, socket);
  540. }
  541. 3.21 int ``SSL_set_rfd`` (SSL * ssl, int fd)
  542. Arguments::
  543. ssl - SSL point
  544. fd - socket id
  545. Return::
  546. 1 : OK
  547. 0 : failed
  548. Description::
  549. set read only socket to SSL
  550. Example::
  551. void example(void)
  552. {
  553. int ret;
  554. SSL *ssl;
  555. int socket;
  556. ... ...
  557. ret = SSL_set_rfd(ssl, socket);
  558. }
  559. 3.22 int ``SSL_set_wfd`` (SSL * ssl, int fd)
  560. Arguments::
  561. ssl - SSL point
  562. fd - socket id
  563. Return::
  564. 1 : OK
  565. 0 : failed
  566. Description::
  567. set write only socket to SSL
  568. Example::
  569. void example(void)
  570. {
  571. int ret;
  572. SSL *ssl;
  573. int socket;
  574. ... ...
  575. ret = SSL_set_wfd(ssl, socket);
  576. }
  577. 3.23 int ``SSL_version`` (const SSL * ssl)
  578. Arguments::
  579. ssl - SSL point
  580. Return::
  581. SSL version
  582. Description::
  583. get SSL version
  584. Example::
  585. void example(void)
  586. {
  587. int version;
  588. SSL *ssl;
  589. ... ...
  590. version = SSL_version(ssl);
  591. }
  592. 3.24 const char* ``SSL_get_version`` (const SSL * ssl)
  593. Arguments::
  594. ssl - SSL point
  595. Return::
  596. SSL version string
  597. Description::
  598. get the SSL current version string
  599. Example::
  600. void example(void)
  601. {
  602. char *version;
  603. SSL *ssl;
  604. ... ...
  605. version = SSL_get_version(ssl);
  606. }
  607. 3.25 OSSL_HANDSHAKE_STATE ``SSL_get_state`` (const SSL * ssl)
  608. Arguments::
  609. ssl - SSL point
  610. Return::
  611. SSL state
  612. Description::
  613. get the SSL state
  614. Example::
  615. void example(void)
  616. {
  617. OSSL_HANDSHAKE_STATE state;
  618. SSL *ssl;
  619. ... ...
  620. state = SSL_get_state(ssl);
  621. }
  622. 3.26 const char* ``SSL_alert_desc_string`` (int value)
  623. Arguments::
  624. value - SSL description
  625. Return::
  626. alert value string
  627. Description::
  628. get alert description string
  629. Example::
  630. void example(void)
  631. {
  632. int val;
  633. char *str;
  634. ... ...
  635. str = SSL_alert_desc_string(val);
  636. }
  637. 3.27 const char* ``SSL_alert_desc_string_long`` (int value)
  638. Arguments::
  639. value - SSL description
  640. Return::
  641. alert value long string
  642. Description::
  643. get alert description long string
  644. Example::
  645. void example(void)
  646. {
  647. int val;
  648. char *str;
  649. ... ...
  650. str = SSL_alert_desc_string_long(val);
  651. }
  652. 3.28 const char* ``SSL_alert_type_string`` (int value)
  653. Arguments::
  654. value - SSL type description
  655. Return::
  656. alert type string
  657. Description::
  658. get alert type string
  659. Example::
  660. void example(void)
  661. {
  662. int val;
  663. char *str;
  664. ... ...
  665. str = SSL_alert_type_string(val);
  666. }
  667. 3.29 const char* ``SSL_alert_type_string_long`` (int value)
  668. Arguments::
  669. value - SSL type description
  670. Return::
  671. alert type long string
  672. Description::
  673. get alert type long string
  674. Example::
  675. void example(void)
  676. {
  677. int val;
  678. char *str;
  679. ... ...
  680. str = SSL_alert_type_string_long(val);
  681. }
  682. 3.30 const char* ``SSL_rstate_string`` (SSL * ssl)
  683. Arguments::
  684. ssl - SSL point
  685. Return::
  686. state string
  687. Description::
  688. get the state string where SSL is reading
  689. Example::
  690. void example(void)
  691. {
  692. SSL *ssl;
  693. char *str;
  694. ... ...
  695. str = SSL_rstate_string(ssl);
  696. }
  697. 3.31 const char* ``SSL_rstate_string_long`` (SSL * ssl)
  698. Arguments::
  699. ssl - SSL point
  700. Return::
  701. state long string
  702. Description::
  703. get the state long string where SSL is reading
  704. Example::
  705. void example(void)
  706. {
  707. SSL *ssl;
  708. char *str;
  709. ... ...
  710. str = SSL_rstate_string_long(ssl);
  711. }
  712. 3.32 const char* ``SSL_state_string`` (const SSL * ssl)
  713. Arguments::
  714. ssl - SSL point
  715. Return::
  716. state string
  717. Description::
  718. get the state string
  719. Example::
  720. void example(void)
  721. {
  722. SSL *ssl;
  723. const char *str;
  724. ... ...
  725. str = SSL_state_string(ssl);
  726. }
  727. 3.33 char* ``SSL_state_string_long`` (const SSL * ssl)
  728. Arguments::
  729. ssl - SSL point
  730. Return::
  731. state long string
  732. Description::
  733. get the state long string
  734. Example::
  735. void example(void)
  736. {
  737. SSL *ssl;
  738. char *str;
  739. ... ...
  740. str = SSL_state_string(ssl);
  741. }
  742. 3.34 int ``SSL_get_error`` (const SSL * ssl, int ret_code)
  743. Arguments::
  744. ssl - SSL point
  745. ret_code - SSL return code
  746. Return::
  747. SSL error number
  748. Description::
  749. get SSL error code
  750. Example::
  751. void example(void)
  752. {
  753. SSL *ssl;
  754. int ret;
  755. int err;
  756. ... ...
  757. err = SSL_get_error(ssl, ret);
  758. }
  759. 3.35 int ``SSL_want`` (const SSL * ssl)
  760. Arguments::
  761. ssl - SSL point
  762. Return::
  763. specifical statement
  764. Description::
  765. get the SSL specifical statement
  766. Example::
  767. void example(void)
  768. {
  769. SSL *ssl;
  770. int state;
  771. ... ...
  772. state = SSL_want(ssl);
  773. }
  774. 3.36 int ``SSL_want_nothing`` (const SSL * ssl)
  775. Arguments::
  776. ssl - SSL point
  777. Return::
  778. 0 : false
  779. 1 : true
  780. Description::
  781. check if SSL want nothing
  782. Example::
  783. void example(void)
  784. {
  785. SSL *ssl;
  786. int ret;
  787. ... ...
  788. ret = SSL_want(ssl);
  789. }
  790. 3.37 int ``SSL_want_read`` (const SSL * ssl)
  791. Arguments::
  792. ssl - SSL point
  793. Return::
  794. 0 : false
  795. 1 : true
  796. Description::
  797. check if SSL want to read
  798. Example::
  799. void example(void)
  800. {
  801. SSL *ssl;
  802. int ret;
  803. ... ...
  804. ret = SSL_want_read(ssl);
  805. }
  806. 3.38 int ``SSL_want_write`` (const SSL * ssl)
  807. Arguments::
  808. ssl - SSL point
  809. Return::
  810. 0 : false
  811. 1 : true
  812. Description::
  813. check if SSL want to write
  814. Example::
  815. void example(void)
  816. {
  817. SSL *ssl;
  818. int ret;
  819. ... ...
  820. ret = SSL_want_write(ssl);
  821. }
  822. Chapter 4. SSL X509 Certification and Private Key Function
  823. ==========================================================
  824. 4.1 X509 * ``d2i_X509`` (X509 ** cert, const unsigned char * buffer, long len)
  825. Arguments::
  826. cert - a point pointed to X509 certification
  827. buffer - a point pointed to the certification context memory point
  828. length - certification bytes
  829. Return::
  830. X509 certification object point
  831. Description::
  832. load a character certification context into system context. If '*cert' is pointed to the
  833. certification, then load certification into it. Or create a new X509 certification object
  834. Example::
  835. void example(void)
  836. {
  837. X509 *new;
  838. X509 *cert;
  839. unsigned char *buffer;
  840. long len;
  841. ... ...
  842. new = d2i_X509(&cert, buffer, len);
  843. }
  844. 4.2 int ``SSL_add_client_CA`` (SSL * ssl, X509 * x)
  845. Arguments::
  846. ssl - SSL point
  847. x - CA certification point
  848. Return::
  849. 1 : OK
  850. 0 : failed
  851. Description::
  852. add CA client certification into the SSL
  853. Example::
  854. void example(void)
  855. {
  856. int ret;
  857. SSL *ssl;
  858. X509 *new;
  859. ... ...
  860. ret = SSL_add_client_CA(ssl, new);
  861. }
  862. 4.3 int ``SSL_CTX_add_client_CA`` (SSL_CTX * ctx, X509 * x)
  863. Arguments::
  864. ctx - SSL context point
  865. x - CA certification point
  866. Return::
  867. 1 : OK
  868. 0 : failed
  869. Description::
  870. add CA client certification into the SSL context
  871. Example::
  872. void example(void)
  873. {
  874. int ret;
  875. SSL_CTX *ctx;
  876. X509 *new;
  877. ... ...
  878. ret = SSL_add_clSSL_CTX_add_client_CAient_CA(ctx, new);
  879. }
  880. 4.4 X509* ``SSL_get_certificate`` (const SSL * ssl)
  881. Arguments::
  882. ssl - SSL point
  883. Return::
  884. SSL certification point
  885. Description::
  886. get the SSL certification point
  887. Example::
  888. void example(void)
  889. {
  890. SSL *ssl;
  891. X509 *cert;
  892. ... ...
  893. cert = SSL_get_certificate(ssl);
  894. }
  895. 4.5 long ``SSL_get_verify_result`` (const SSL * ssl)
  896. Arguments::
  897. ssl - SSL point
  898. Return::
  899. the result of verifying
  900. Description::
  901. get the verifying result of the SSL certification
  902. Example::
  903. void example(void)
  904. {
  905. SSL *ssl;
  906. long ret;
  907. ... ...
  908. ret = SSL_get_verify_result(ssl);
  909. }
  910. 4.6 int ``SSL_CTX_use_certificate`` (SSL_CTX * ctx, X509 * x)
  911. Arguments::
  912. ctx - the SSL context point
  913. pkey - certification object point
  914. Return::
  915. 1 : OK
  916. 0 : failed
  917. Description::
  918. load the certification into the SSL_CTX or SSL object
  919. Example::
  920. void example(void)
  921. {
  922. int ret;
  923. SSL_CTX *ctx
  924. X509 *new;
  925. ... ...
  926. ret = SSL_CTX_use_certificate(ctx, new);
  927. }
  928. 4.7 int ``SSL_CTX_use_certificate_ASN1`` (SSL_CTX * ctx, int len, const unsigned char * d)
  929. Arguments::
  930. ctx - SSL context point
  931. len - certification length
  932. d - data point
  933. Return::
  934. 1 : OK
  935. 0 : failed
  936. Description::
  937. load the ASN1 certification into SSL context
  938. Example::
  939. void example(void)
  940. {
  941. int ret;
  942. SSL_CTX *ctx;
  943. const unsigned char *buf;
  944. int len;
  945. ... ...
  946. ret = SSL_CTX_use_certificate_ASN1(ctx, len, buf);
  947. }
  948. 4.8 int ``SSL_CTX_use_PrivateKey`` (SSL_CTX * ctx, EVP_PKEY * pkey)
  949. Arguments::
  950. ctx - SSL context point
  951. pkey - private key object point
  952. Return::
  953. 1 : OK
  954. 0 : failed
  955. Description::
  956. load the private key into the context object
  957. Example::
  958. void example(void)
  959. {
  960. int ret;
  961. SSL_CTX *ctx;
  962. EVP_PKEY *pkey;
  963. ... ...
  964. ret = SSL_CTX_use_PrivateKey(ctx, pkey);
  965. }
  966. 4.9 int ``SSL_CTX_use_PrivateKey_ASN1`` (int pk, SSL_CTX * ctx, const unsigned char * d, long len)
  967. Arguments::
  968. ctx - SSL context point
  969. d - data point
  970. len - private key length
  971. Return::
  972. 1 : OK
  973. 0 : failed
  974. Description::
  975. load the ASN1 private key into SSL context
  976. Example::
  977. void example(void)
  978. {
  979. int ret;
  980. int pk;
  981. SSL_CTX *ctx;
  982. const unsigned char *buf;
  983. long len;
  984. ... ...
  985. ret = SSL_CTX_use_PrivateKey_ASN1(pk, ctx, buf, len);
  986. }
  987. 4.10 int ``SSL_CTX_use_RSAPrivateKey_ASN1`` (SSL_CTX * ctx, const unsigned char * d, long len)
  988. Arguments::
  989. ctx - SSL context point
  990. d - data point
  991. len - private key length
  992. Return::
  993. 1 : OK
  994. 0 : failed
  995. Description::
  996. load the RSA ASN1 private key into SSL context
  997. Example::
  998. void example(void)
  999. {
  1000. int ret;
  1001. SSL_CTX *ctx;
  1002. const unsigned char *buf;
  1003. long len;
  1004. ... ...
  1005. ret = SSL_CTX_use_RSAPrivateKey_ASN1(ctx, buf, len);
  1006. }
  1007. 4.11 int ``SSL_use_certificate_ASN1`` (SSL * ssl, int len, const unsigned char * d)
  1008. Arguments::
  1009. ssl - SSL point
  1010. len - data bytes
  1011. d - data point
  1012. Return::
  1013. 1 : OK
  1014. 0 : failed
  1015. Description::
  1016. load certification into the SSL
  1017. Example::
  1018. void example(void)
  1019. {
  1020. int ret;
  1021. SSL *ssl;
  1022. const unsigned char *buf;
  1023. long len;
  1024. ... ...
  1025. ret = SSL_use_certificate_ASN1(ssl, len, buf);
  1026. }
  1027. 4.12 X509* ``SSL_get_peer_certificate`` (const SSL * ssl)
  1028. Arguments::
  1029. ssl - SSL point
  1030. Return::
  1031. peer certification
  1032. Description::
  1033. get peer certification
  1034. Example::
  1035. void example(void)
  1036. {
  1037. SSL *ssl;
  1038. X509 *peer;
  1039. ... ...
  1040. peer = SSL_get_peer_certificate(ssl);
  1041. }