openssl_apis.rst 30 KB

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