You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

571 lines
18 KiB

  1. /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  2. * All rights reserved.
  3. *
  4. * This package is an SSL implementation written
  5. * by Eric Young (eay@cryptsoft.com).
  6. * The implementation was written so as to conform with Netscapes SSL.
  7. *
  8. * This library is free for commercial and non-commercial use as long as
  9. * the following conditions are aheared to. The following conditions
  10. * apply to all code found in this distribution, be it the RC4, RSA,
  11. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  12. * included with this distribution is covered by the same copyright terms
  13. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  14. *
  15. * Copyright remains Eric Young's, and as such any Copyright notices in
  16. * the code are not to be removed.
  17. * If this package is used in a product, Eric Young should be given attribution
  18. * as the author of the parts of the library used.
  19. * This can be in the form of a textual message at program startup or
  20. * in documentation (online or textual) provided with the package.
  21. *
  22. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions
  24. * are met:
  25. * 1. Redistributions of source code must retain the copyright
  26. * notice, this list of conditions and the following disclaimer.
  27. * 2. Redistributions in binary form must reproduce the above copyright
  28. * notice, this list of conditions and the following disclaimer in the
  29. * documentation and/or other materials provided with the distribution.
  30. * 3. All advertising materials mentioning features or use of this software
  31. * must display the following acknowledgement:
  32. * "This product includes cryptographic software written by
  33. * Eric Young (eay@cryptsoft.com)"
  34. * The word 'cryptographic' can be left out if the rouines from the library
  35. * being used are not cryptographic related :-).
  36. * 4. If you include any Windows specific code (or a derivative thereof) from
  37. * the apps directory (application code) you must include an acknowledgement:
  38. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  39. *
  40. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  41. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  42. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  43. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  44. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  45. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  46. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  47. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  48. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  49. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  50. * SUCH DAMAGE.
  51. *
  52. * The licence and distribution terms for any publically available version or
  53. * derivative of this code cannot be changed. i.e. this code cannot simply be
  54. * copied and put under another distribution licence
  55. * [including the GNU Public Licence.]
  56. */
  57. /* ====================================================================
  58. * Copyright 2005 Nokia. All rights reserved.
  59. *
  60. * The portions of the attached software ("Contribution") is developed by
  61. * Nokia Corporation and is licensed pursuant to the OpenSSL open source
  62. * license.
  63. *
  64. * The Contribution, originally written by Mika Kousa and Pasi Eronen of
  65. * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
  66. * support (see RFC 4279) to OpenSSL.
  67. *
  68. * No patent licenses or other rights except those expressly stated in
  69. * the OpenSSL open source license shall be deemed granted or received
  70. * expressly, by implication, estoppel, or otherwise.
  71. *
  72. * No assurances are provided by Nokia that the Contribution does not
  73. * infringe the patent or other intellectual property rights of any third
  74. * party or that the license provides you with all the necessary rights
  75. * to make use of the Contribution.
  76. *
  77. * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
  78. * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
  79. * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
  80. * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
  81. * OTHERWISE. */
  82. #include <assert.h>
  83. #include <stdio.h>
  84. #include <stdlib.h>
  85. #include <openssl/asn1.h>
  86. #include <openssl/asn1_mac.h>
  87. #include <openssl/err.h>
  88. #include <openssl/mem.h>
  89. #include <openssl/obj.h>
  90. #include <openssl/x509.h>
  91. #include "ssl_locl.h"
  92. OPENSSL_DECLARE_ERROR_REASON(SSL, CIPHER_CODE_WRONG_LENGTH);
  93. OPENSSL_DECLARE_ERROR_REASON(SSL, UNKNOWN_SSL_VERSION);
  94. OPENSSL_DECLARE_ERROR_REASON(SSL, BAD_LENGTH);
  95. OPENSSL_DECLARE_ERROR_FUNCTION(SSL, D2I_SSL_SESSION);
  96. typedef struct ssl_session_asn1_st
  97. {
  98. ASN1_INTEGER version;
  99. ASN1_INTEGER ssl_version;
  100. ASN1_OCTET_STRING cipher;
  101. ASN1_OCTET_STRING comp_id;
  102. ASN1_OCTET_STRING master_key;
  103. ASN1_OCTET_STRING session_id;
  104. ASN1_OCTET_STRING session_id_context;
  105. ASN1_OCTET_STRING key_arg;
  106. ASN1_INTEGER time;
  107. ASN1_INTEGER timeout;
  108. ASN1_INTEGER verify_result;
  109. ASN1_OCTET_STRING tlsext_hostname;
  110. ASN1_INTEGER tlsext_tick_lifetime;
  111. ASN1_OCTET_STRING tlsext_tick;
  112. ASN1_OCTET_STRING psk_identity_hint;
  113. ASN1_OCTET_STRING psk_identity;
  114. ASN1_OCTET_STRING peer_sha256;
  115. ASN1_OCTET_STRING original_handshake_hash;
  116. } SSL_SESSION_ASN1;
  117. int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
  118. {
  119. #define LSIZE2 (sizeof(long)*2)
  120. int v1=0,v2=0,v3=0,v4=0,v5=0,v7=0,v8=0,v13=0,v14=0;
  121. unsigned char buf[4],ibuf1[LSIZE2],ibuf2[LSIZE2];
  122. unsigned char ibuf3[LSIZE2],ibuf4[LSIZE2],ibuf5[LSIZE2];
  123. int v6=0,v9=0,v10=0;
  124. unsigned char ibuf6[LSIZE2];
  125. long l;
  126. SSL_SESSION_ASN1 a;
  127. M_ASN1_I2D_vars(in);
  128. if ((in == NULL) || ((in->cipher == NULL) && (in->cipher_id == 0)))
  129. return(0);
  130. /* Note that I cheat in the following 2 assignments. I know
  131. * that if the ASN1_INTEGER passed to ASN1_INTEGER_set
  132. * is > sizeof(long)+1, the buffer will not be re-OPENSSL_malloc()ed.
  133. * This is a bit evil but makes things simple, no dynamic allocation
  134. * to clean up :-) */
  135. a.version.length=LSIZE2;
  136. a.version.type=V_ASN1_INTEGER;
  137. a.version.data=ibuf1;
  138. ASN1_INTEGER_set(&(a.version),SSL_SESSION_ASN1_VERSION);
  139. a.ssl_version.length=LSIZE2;
  140. a.ssl_version.type=V_ASN1_INTEGER;
  141. a.ssl_version.data=ibuf2;
  142. ASN1_INTEGER_set(&(a.ssl_version),in->ssl_version);
  143. a.cipher.type=V_ASN1_OCTET_STRING;
  144. a.cipher.data=buf;
  145. if (in->cipher == NULL)
  146. l=in->cipher_id;
  147. else
  148. l=in->cipher->id;
  149. if (in->ssl_version == SSL2_VERSION)
  150. {
  151. a.cipher.length=3;
  152. buf[0]=((unsigned char)(l>>16L))&0xff;
  153. buf[1]=((unsigned char)(l>> 8L))&0xff;
  154. buf[2]=((unsigned char)(l ))&0xff;
  155. }
  156. else
  157. {
  158. a.cipher.length=2;
  159. buf[0]=((unsigned char)(l>>8L))&0xff;
  160. buf[1]=((unsigned char)(l ))&0xff;
  161. }
  162. a.master_key.length=in->master_key_length;
  163. a.master_key.type=V_ASN1_OCTET_STRING;
  164. a.master_key.data=in->master_key;
  165. a.session_id.length=in->session_id_length;
  166. a.session_id.type=V_ASN1_OCTET_STRING;
  167. a.session_id.data=in->session_id;
  168. a.session_id_context.length=in->sid_ctx_length;
  169. a.session_id_context.type=V_ASN1_OCTET_STRING;
  170. a.session_id_context.data=in->sid_ctx;
  171. a.key_arg.length=in->key_arg_length;
  172. a.key_arg.type=V_ASN1_OCTET_STRING;
  173. a.key_arg.data=in->key_arg;
  174. if (in->time != 0L)
  175. {
  176. a.time.length=LSIZE2;
  177. a.time.type=V_ASN1_INTEGER;
  178. a.time.data=ibuf3;
  179. ASN1_INTEGER_set(&(a.time),in->time);
  180. }
  181. if (in->timeout != 0L)
  182. {
  183. a.timeout.length=LSIZE2;
  184. a.timeout.type=V_ASN1_INTEGER;
  185. a.timeout.data=ibuf4;
  186. ASN1_INTEGER_set(&(a.timeout),in->timeout);
  187. }
  188. if (in->verify_result != X509_V_OK)
  189. {
  190. a.verify_result.length=LSIZE2;
  191. a.verify_result.type=V_ASN1_INTEGER;
  192. a.verify_result.data=ibuf5;
  193. ASN1_INTEGER_set(&a.verify_result,in->verify_result);
  194. }
  195. if (in->tlsext_hostname)
  196. {
  197. a.tlsext_hostname.length=strlen(in->tlsext_hostname);
  198. a.tlsext_hostname.type=V_ASN1_OCTET_STRING;
  199. a.tlsext_hostname.data=(unsigned char *)in->tlsext_hostname;
  200. }
  201. if (in->tlsext_tick)
  202. {
  203. a.tlsext_tick.length= in->tlsext_ticklen;
  204. a.tlsext_tick.type=V_ASN1_OCTET_STRING;
  205. a.tlsext_tick.data=(unsigned char *)in->tlsext_tick;
  206. }
  207. if (in->tlsext_tick_lifetime_hint > 0)
  208. {
  209. a.tlsext_tick_lifetime.length=LSIZE2;
  210. a.tlsext_tick_lifetime.type=V_ASN1_INTEGER;
  211. a.tlsext_tick_lifetime.data=ibuf6;
  212. ASN1_INTEGER_set(&a.tlsext_tick_lifetime,in->tlsext_tick_lifetime_hint);
  213. }
  214. if (in->psk_identity_hint)
  215. {
  216. a.psk_identity_hint.length=strlen(in->psk_identity_hint);
  217. a.psk_identity_hint.type=V_ASN1_OCTET_STRING;
  218. a.psk_identity_hint.data=(unsigned char *)(in->psk_identity_hint);
  219. }
  220. if (in->psk_identity)
  221. {
  222. a.psk_identity.length=strlen(in->psk_identity);
  223. a.psk_identity.type=V_ASN1_OCTET_STRING;
  224. a.psk_identity.data=(unsigned char *)(in->psk_identity);
  225. }
  226. if (in->peer_sha256_valid)
  227. {
  228. a.peer_sha256.length = sizeof(in->peer_sha256);
  229. a.peer_sha256.type = V_ASN1_OCTET_STRING;
  230. a.peer_sha256.data = in->peer_sha256;
  231. }
  232. if (in->original_handshake_hash_len > 0)
  233. {
  234. a.original_handshake_hash.length = in->original_handshake_hash_len;
  235. a.original_handshake_hash.type = V_ASN1_OCTET_STRING;
  236. a.original_handshake_hash.data = in->original_handshake_hash;
  237. }
  238. M_ASN1_I2D_len(&(a.version), i2d_ASN1_INTEGER);
  239. M_ASN1_I2D_len(&(a.ssl_version), i2d_ASN1_INTEGER);
  240. M_ASN1_I2D_len(&(a.cipher), i2d_ASN1_OCTET_STRING);
  241. M_ASN1_I2D_len(&(a.session_id), i2d_ASN1_OCTET_STRING);
  242. M_ASN1_I2D_len(&(a.master_key), i2d_ASN1_OCTET_STRING);
  243. if (in->key_arg_length > 0)
  244. M_ASN1_I2D_len_IMP_opt(&(a.key_arg),i2d_ASN1_OCTET_STRING);
  245. if (in->time != 0L)
  246. M_ASN1_I2D_len_EXP_opt(&(a.time),i2d_ASN1_INTEGER,1,v1);
  247. if (in->timeout != 0L)
  248. M_ASN1_I2D_len_EXP_opt(&(a.timeout),i2d_ASN1_INTEGER,2,v2);
  249. if (in->peer != NULL && in->peer_sha256_valid == 0)
  250. M_ASN1_I2D_len_EXP_opt(in->peer,i2d_X509,3,v3);
  251. M_ASN1_I2D_len_EXP_opt(&a.session_id_context,i2d_ASN1_OCTET_STRING,4,v4);
  252. if (in->verify_result != X509_V_OK)
  253. M_ASN1_I2D_len_EXP_opt(&(a.verify_result),i2d_ASN1_INTEGER,5,v5);
  254. if (in->tlsext_tick_lifetime_hint > 0)
  255. M_ASN1_I2D_len_EXP_opt(&a.tlsext_tick_lifetime, i2d_ASN1_INTEGER,9,v9);
  256. if (in->tlsext_tick)
  257. M_ASN1_I2D_len_EXP_opt(&(a.tlsext_tick), i2d_ASN1_OCTET_STRING,10,v10);
  258. if (in->tlsext_hostname)
  259. M_ASN1_I2D_len_EXP_opt(&(a.tlsext_hostname), i2d_ASN1_OCTET_STRING,6,v6);
  260. if (in->psk_identity_hint)
  261. M_ASN1_I2D_len_EXP_opt(&(a.psk_identity_hint), i2d_ASN1_OCTET_STRING,7,v7);
  262. if (in->psk_identity)
  263. M_ASN1_I2D_len_EXP_opt(&(a.psk_identity), i2d_ASN1_OCTET_STRING,8,v8);
  264. if (in->peer_sha256_valid)
  265. M_ASN1_I2D_len_EXP_opt(&(a.peer_sha256),i2d_ASN1_OCTET_STRING,13,v13);
  266. if (in->original_handshake_hash_len > 0)
  267. M_ASN1_I2D_len_EXP_opt(&(a.original_handshake_hash),i2d_ASN1_OCTET_STRING,14,v14);
  268. M_ASN1_I2D_seq_total();
  269. M_ASN1_I2D_put(&(a.version), i2d_ASN1_INTEGER);
  270. M_ASN1_I2D_put(&(a.ssl_version), i2d_ASN1_INTEGER);
  271. M_ASN1_I2D_put(&(a.cipher), i2d_ASN1_OCTET_STRING);
  272. M_ASN1_I2D_put(&(a.session_id), i2d_ASN1_OCTET_STRING);
  273. M_ASN1_I2D_put(&(a.master_key), i2d_ASN1_OCTET_STRING);
  274. if (in->key_arg_length > 0)
  275. M_ASN1_I2D_put_IMP_opt(&(a.key_arg),i2d_ASN1_OCTET_STRING,0);
  276. if (in->time != 0L)
  277. M_ASN1_I2D_put_EXP_opt(&(a.time),i2d_ASN1_INTEGER,1,v1);
  278. if (in->timeout != 0L)
  279. M_ASN1_I2D_put_EXP_opt(&(a.timeout),i2d_ASN1_INTEGER,2,v2);
  280. if (in->peer != NULL && in->peer_sha256_valid == 0)
  281. M_ASN1_I2D_put_EXP_opt(in->peer,i2d_X509,3,v3);
  282. M_ASN1_I2D_put_EXP_opt(&a.session_id_context,i2d_ASN1_OCTET_STRING,4,
  283. v4);
  284. if (in->verify_result != X509_V_OK)
  285. M_ASN1_I2D_put_EXP_opt(&a.verify_result,i2d_ASN1_INTEGER,5,v5);
  286. if (in->tlsext_hostname)
  287. M_ASN1_I2D_put_EXP_opt(&(a.tlsext_hostname), i2d_ASN1_OCTET_STRING,6,v6);
  288. if (in->psk_identity_hint)
  289. M_ASN1_I2D_put_EXP_opt(&(a.psk_identity_hint), i2d_ASN1_OCTET_STRING,7,v7);
  290. if (in->psk_identity)
  291. M_ASN1_I2D_put_EXP_opt(&(a.psk_identity), i2d_ASN1_OCTET_STRING,8,v8);
  292. if (in->tlsext_tick_lifetime_hint > 0)
  293. M_ASN1_I2D_put_EXP_opt(&a.tlsext_tick_lifetime, i2d_ASN1_INTEGER,9,v9);
  294. if (in->tlsext_tick)
  295. M_ASN1_I2D_put_EXP_opt(&(a.tlsext_tick), i2d_ASN1_OCTET_STRING,10,v10);
  296. if (in->peer_sha256_valid)
  297. M_ASN1_I2D_put_EXP_opt(&(a.peer_sha256),i2d_ASN1_OCTET_STRING,13,v13);
  298. if (in->original_handshake_hash_len > 0)
  299. M_ASN1_I2D_put_EXP_opt(&(a.original_handshake_hash),i2d_ASN1_OCTET_STRING,14,v14);
  300. M_ASN1_I2D_finish();
  301. }
  302. SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp,
  303. long length)
  304. {
  305. int ssl_version=0,i;
  306. long id;
  307. ASN1_INTEGER ai,*aip;
  308. ASN1_OCTET_STRING os,*osp;
  309. M_ASN1_D2I_vars(a,SSL_SESSION *,SSL_SESSION_new);
  310. aip= &ai;
  311. osp= &os;
  312. M_ASN1_D2I_Init();
  313. M_ASN1_D2I_start_sequence();
  314. ai.data=NULL; ai.length=0;
  315. M_ASN1_D2I_get_x(ASN1_INTEGER,aip,d2i_ASN1_INTEGER);
  316. if (ai.data != NULL) { OPENSSL_free(ai.data); ai.data=NULL; ai.length=0; }
  317. /* we don't care about the version right now :-) */
  318. M_ASN1_D2I_get_x(ASN1_INTEGER,aip,d2i_ASN1_INTEGER);
  319. ssl_version=(int)ASN1_INTEGER_get(aip);
  320. ret->ssl_version=ssl_version;
  321. if (ai.data != NULL) { OPENSSL_free(ai.data); ai.data=NULL; ai.length=0; }
  322. os.data=NULL; os.length=0;
  323. M_ASN1_D2I_get_x(ASN1_OCTET_STRING,osp,d2i_ASN1_OCTET_STRING);
  324. if (ssl_version == SSL2_VERSION)
  325. {
  326. if (os.length != 3)
  327. {
  328. c.error=SSL_R_CIPHER_CODE_WRONG_LENGTH;
  329. c.line=__LINE__;
  330. goto err;
  331. }
  332. id=0x02000000L|
  333. ((unsigned long)os.data[0]<<16L)|
  334. ((unsigned long)os.data[1]<< 8L)|
  335. (unsigned long)os.data[2];
  336. }
  337. else if ((ssl_version>>8) >= SSL3_VERSION_MAJOR)
  338. {
  339. if (os.length != 2)
  340. {
  341. c.error=SSL_R_CIPHER_CODE_WRONG_LENGTH;
  342. c.line=__LINE__;
  343. goto err;
  344. }
  345. id=0x03000000L|
  346. ((unsigned long)os.data[0]<<8L)|
  347. (unsigned long)os.data[1];
  348. }
  349. else
  350. {
  351. c.error=SSL_R_UNKNOWN_SSL_VERSION;
  352. c.line=__LINE__;
  353. goto err;
  354. }
  355. ret->cipher=NULL;
  356. ret->cipher_id=id;
  357. M_ASN1_D2I_get_x(ASN1_OCTET_STRING,osp,d2i_ASN1_OCTET_STRING);
  358. if ((ssl_version>>8) >= SSL3_VERSION_MAJOR)
  359. i=SSL3_MAX_SSL_SESSION_ID_LENGTH;
  360. else /* if (ssl_version>>8 == SSL2_VERSION_MAJOR) */
  361. i=SSL2_MAX_SSL_SESSION_ID_LENGTH;
  362. if (os.length > i)
  363. os.length = i;
  364. if (os.length > (int)sizeof(ret->session_id)) /* can't happen */
  365. os.length = sizeof(ret->session_id);
  366. ret->session_id_length=os.length;
  367. assert(os.length <= (int)sizeof(ret->session_id));
  368. memcpy(ret->session_id,os.data,os.length);
  369. M_ASN1_D2I_get_x(ASN1_OCTET_STRING,osp,d2i_ASN1_OCTET_STRING);
  370. if (os.length > SSL_MAX_MASTER_KEY_LENGTH)
  371. ret->master_key_length=SSL_MAX_MASTER_KEY_LENGTH;
  372. else
  373. ret->master_key_length=os.length;
  374. memcpy(ret->master_key,os.data,ret->master_key_length);
  375. os.length=0;
  376. M_ASN1_D2I_get_IMP_opt(osp,d2i_ASN1_OCTET_STRING,0,V_ASN1_OCTET_STRING);
  377. if (os.length > SSL_MAX_KEY_ARG_LENGTH)
  378. ret->key_arg_length=SSL_MAX_KEY_ARG_LENGTH;
  379. else
  380. ret->key_arg_length=os.length;
  381. memcpy(ret->key_arg,os.data,ret->key_arg_length);
  382. if (os.data != NULL) OPENSSL_free(os.data);
  383. ai.length=0;
  384. M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,1);
  385. if (ai.data != NULL)
  386. {
  387. ret->time=ASN1_INTEGER_get(aip);
  388. OPENSSL_free(ai.data); ai.data=NULL; ai.length=0;
  389. }
  390. else
  391. ret->time=(unsigned long)time(NULL);
  392. ai.length=0;
  393. M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,2);
  394. if (ai.data != NULL)
  395. {
  396. ret->timeout=ASN1_INTEGER_get(aip);
  397. OPENSSL_free(ai.data); ai.data=NULL; ai.length=0;
  398. }
  399. else
  400. ret->timeout=3;
  401. if (ret->peer != NULL)
  402. {
  403. X509_free(ret->peer);
  404. ret->peer=NULL;
  405. }
  406. M_ASN1_D2I_get_EXP_opt(ret->peer,d2i_X509,3);
  407. os.length=0;
  408. os.data=NULL;
  409. M_ASN1_D2I_get_EXP_opt(osp,d2i_ASN1_OCTET_STRING,4);
  410. if(os.data != NULL)
  411. {
  412. if (os.length > SSL_MAX_SID_CTX_LENGTH)
  413. {
  414. c.error=SSL_R_BAD_LENGTH;
  415. c.line=__LINE__;
  416. goto err;
  417. }
  418. else
  419. {
  420. ret->sid_ctx_length=os.length;
  421. memcpy(ret->sid_ctx,os.data,os.length);
  422. }
  423. OPENSSL_free(os.data); os.data=NULL; os.length=0;
  424. }
  425. else
  426. ret->sid_ctx_length=0;
  427. ai.length=0;
  428. M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,5);
  429. if (ai.data != NULL)
  430. {
  431. ret->verify_result=ASN1_INTEGER_get(aip);
  432. OPENSSL_free(ai.data); ai.data=NULL; ai.length=0;
  433. }
  434. else
  435. ret->verify_result=X509_V_OK;
  436. os.length=0;
  437. os.data=NULL;
  438. M_ASN1_D2I_get_EXP_opt(osp,d2i_ASN1_OCTET_STRING,6);
  439. if (os.data)
  440. {
  441. ret->tlsext_hostname = BUF_strndup((char *)os.data, os.length);
  442. OPENSSL_free(os.data);
  443. os.data = NULL;
  444. os.length = 0;
  445. }
  446. else
  447. ret->tlsext_hostname=NULL;
  448. os.length=0;
  449. os.data=NULL;
  450. M_ASN1_D2I_get_EXP_opt(osp,d2i_ASN1_OCTET_STRING,7);
  451. if (os.data)
  452. {
  453. ret->psk_identity_hint = BUF_strndup((char *)os.data, os.length);
  454. OPENSSL_free(os.data);
  455. os.data = NULL;
  456. os.length = 0;
  457. }
  458. else
  459. ret->psk_identity_hint=NULL;
  460. os.length=0;
  461. os.data=NULL;
  462. M_ASN1_D2I_get_EXP_opt(osp,d2i_ASN1_OCTET_STRING,8);
  463. if (os.data)
  464. {
  465. ret->psk_identity = BUF_strndup((char *)os.data, os.length);
  466. OPENSSL_free(os.data);
  467. os.data = NULL;
  468. os.length = 0;
  469. }
  470. else
  471. ret->psk_identity=NULL;
  472. ai.length=0;
  473. M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,9);
  474. if (ai.data != NULL)
  475. {
  476. ret->tlsext_tick_lifetime_hint=ASN1_INTEGER_get(aip);
  477. OPENSSL_free(ai.data); ai.data=NULL; ai.length=0;
  478. }
  479. else if (ret->tlsext_ticklen && ret->session_id_length)
  480. ret->tlsext_tick_lifetime_hint = -1;
  481. else
  482. ret->tlsext_tick_lifetime_hint=0;
  483. os.length=0;
  484. os.data=NULL;
  485. M_ASN1_D2I_get_EXP_opt(osp,d2i_ASN1_OCTET_STRING,10);
  486. if (os.data)
  487. {
  488. ret->tlsext_tick = os.data;
  489. ret->tlsext_ticklen = os.length;
  490. os.data = NULL;
  491. os.length = 0;
  492. }
  493. else
  494. ret->tlsext_tick=NULL;
  495. os.length=0;
  496. os.data=NULL;
  497. M_ASN1_D2I_get_EXP_opt(osp,d2i_ASN1_OCTET_STRING,13);
  498. if (os.data && os.length == sizeof(ret->peer_sha256))
  499. {
  500. memcpy(ret->peer_sha256, os.data, sizeof(ret->peer_sha256));
  501. ret->peer_sha256_valid = 1;
  502. OPENSSL_free(os.data);
  503. os.data = NULL;
  504. }
  505. os.length=0;
  506. os.data=NULL;
  507. M_ASN1_D2I_get_EXP_opt(osp,d2i_ASN1_OCTET_STRING,14);
  508. if (os.data && os.length < (int)sizeof(ret->original_handshake_hash))
  509. {
  510. memcpy(ret->original_handshake_hash, os.data, os.length);
  511. ret->original_handshake_hash_len = os.length;
  512. OPENSSL_free(os.data);
  513. os.data = NULL;
  514. }
  515. M_ASN1_D2I_Finish(a,SSL_SESSION_free,SSL_F_D2I_SSL_SESSION);
  516. }