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