OpenSSL-APIs.rst 30 KB

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