summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libssl/src/ssl/ssl_asn1.c173
-rw-r--r--src/lib/libssl/ssl_asn1.c173
2 files changed, 196 insertions, 150 deletions
diff --git a/src/lib/libssl/src/ssl/ssl_asn1.c b/src/lib/libssl/src/ssl/ssl_asn1.c
index 0c9b4aa6fb..33a8edf20a 100644
--- a/src/lib/libssl/src/ssl/ssl_asn1.c
+++ b/src/lib/libssl/src/ssl/ssl_asn1.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_asn1.c,v 1.30 2014/07/13 00:30:07 jsing Exp $ */ 1/* $OpenBSD: ssl_asn1.c,v 1.31 2014/07/13 16:30:50 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -116,7 +116,8 @@ i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
116 unsigned char ibuf3[LSIZE2], ibuf4[LSIZE2], ibuf5[LSIZE2]; 116 unsigned char ibuf3[LSIZE2], ibuf4[LSIZE2], ibuf5[LSIZE2];
117 unsigned char ibuf6[LSIZE2]; 117 unsigned char ibuf6[LSIZE2];
118 SSL_SESSION_ASN1 a; 118 SSL_SESSION_ASN1 a;
119 M_ASN1_I2D_vars(in); 119 unsigned char *p;
120 int len = 0, ret;
120 long l; 121 long l;
121 122
122 if ((in == NULL) || ((in->cipher == NULL) && (in->cipher_id == 0))) 123 if ((in == NULL) || ((in->cipher == NULL) && (in->cipher_id == 0)))
@@ -133,40 +134,39 @@ i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
133 a.version.type = V_ASN1_INTEGER; 134 a.version.type = V_ASN1_INTEGER;
134 a.version.data = ibuf1; 135 a.version.data = ibuf1;
135 ASN1_INTEGER_set(&(a.version), SSL_SESSION_ASN1_VERSION); 136 ASN1_INTEGER_set(&(a.version), SSL_SESSION_ASN1_VERSION);
137 len += i2d_ASN1_INTEGER(&(a.version), NULL);
136 138
137 a.ssl_version.length = LSIZE2; 139 a.ssl_version.length = LSIZE2;
138 a.ssl_version.type = V_ASN1_INTEGER; 140 a.ssl_version.type = V_ASN1_INTEGER;
139 a.ssl_version.data = ibuf2; 141 a.ssl_version.data = ibuf2;
140 ASN1_INTEGER_set(&(a.ssl_version), in->ssl_version); 142 ASN1_INTEGER_set(&(a.ssl_version), in->ssl_version);
143 len += i2d_ASN1_INTEGER(&(a.ssl_version), NULL);
141 144
145 a.cipher.length = 2;
142 a.cipher.type = V_ASN1_OCTET_STRING; 146 a.cipher.type = V_ASN1_OCTET_STRING;
147 l = (in->cipher == NULL) ? in->cipher_id : in->cipher->id;
148 buf[0] = ((unsigned char)(l >> 8L)) & 0xff;
149 buf[1] = ((unsigned char)(l)) & 0xff;
143 a.cipher.data = buf; 150 a.cipher.data = buf;
144 151 len += i2d_ASN1_OCTET_STRING(&(a.cipher), NULL);
145 if (in->cipher == NULL)
146 l = in->cipher_id;
147 else
148 l = in->cipher->id;
149 a.cipher.length = 2;
150 buf[0] = ((unsigned char)(l >> 8L))&0xff;
151 buf[1] = ((unsigned char)(l ))&0xff;
152 152
153 a.master_key.length = in->master_key_length; 153 a.master_key.length = in->master_key_length;
154 a.master_key.type = V_ASN1_OCTET_STRING; 154 a.master_key.type = V_ASN1_OCTET_STRING;
155 a.master_key.data = in->master_key; 155 a.master_key.data = in->master_key;
156 len += i2d_ASN1_OCTET_STRING(&(a.master_key), NULL);
156 157
157 a.session_id.length = in->session_id_length; 158 a.session_id.length = in->session_id_length;
158 a.session_id.type = V_ASN1_OCTET_STRING; 159 a.session_id.type = V_ASN1_OCTET_STRING;
159 a.session_id.data = in->session_id; 160 a.session_id.data = in->session_id;
160 161 len += i2d_ASN1_OCTET_STRING(&(a.session_id), NULL);
161 a.session_id_context.length = in->sid_ctx_length;
162 a.session_id_context.type = V_ASN1_OCTET_STRING;
163 a.session_id_context.data = in->sid_ctx;
164 162
165 if (in->time != 0L) { 163 if (in->time != 0L) {
166 a.time.length = LSIZE2; 164 a.time.length = LSIZE2;
167 a.time.type = V_ASN1_INTEGER; 165 a.time.type = V_ASN1_INTEGER;
168 a.time.data = ibuf3; 166 a.time.data = ibuf3;
169 ASN1_INTEGER_set(&(a.time), in->time); /* XXX 2038 */ 167 ASN1_INTEGER_set(&(a.time), in->time); /* XXX 2038 */
168 v1 = i2d_ASN1_INTEGER(&(a.time), NULL);
169 len += ASN1_object_size(1, v1, 1);
170 } 170 }
171 171
172 if (in->timeout != 0L) { 172 if (in->timeout != 0L) {
@@ -174,89 +174,112 @@ i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
174 a.timeout.type = V_ASN1_INTEGER; 174 a.timeout.type = V_ASN1_INTEGER;
175 a.timeout.data = ibuf4; 175 a.timeout.data = ibuf4;
176 ASN1_INTEGER_set(&(a.timeout), in->timeout); 176 ASN1_INTEGER_set(&(a.timeout), in->timeout);
177 v2 = i2d_ASN1_INTEGER(&(a.timeout), NULL);
178 len += ASN1_object_size(1, v2, 2);
177 } 179 }
178 180
181 if (in->peer != NULL) {
182 v3 = i2d_X509(in->peer, NULL);
183 len += ASN1_object_size(1, v3, 3);
184 }
185
186 a.session_id_context.length = in->sid_ctx_length;
187 a.session_id_context.type = V_ASN1_OCTET_STRING;
188 a.session_id_context.data = in->sid_ctx;
189 v4 = i2d_ASN1_OCTET_STRING(&(a.session_id_context), NULL);
190 len += ASN1_object_size(1, v4, 4);
191
179 if (in->verify_result != X509_V_OK) { 192 if (in->verify_result != X509_V_OK) {
180 a.verify_result.length = LSIZE2; 193 a.verify_result.length = LSIZE2;
181 a.verify_result.type = V_ASN1_INTEGER; 194 a.verify_result.type = V_ASN1_INTEGER;
182 a.verify_result.data = ibuf5; 195 a.verify_result.data = ibuf5;
183 ASN1_INTEGER_set(&a.verify_result, in->verify_result); 196 ASN1_INTEGER_set(&a.verify_result, in->verify_result);
197 v5 = i2d_ASN1_INTEGER(&(a.verify_result), NULL);
198 len += ASN1_object_size(1, v5, 5);
184 } 199 }
185 200
186 if (in->tlsext_hostname) { 201 if (in->tlsext_hostname) {
187 a.tlsext_hostname.length = strlen(in->tlsext_hostname); 202 a.tlsext_hostname.length = strlen(in->tlsext_hostname);
188 a.tlsext_hostname.type = V_ASN1_OCTET_STRING; 203 a.tlsext_hostname.type = V_ASN1_OCTET_STRING;
189 a.tlsext_hostname.data = (unsigned char *)in->tlsext_hostname; 204 a.tlsext_hostname.data = (unsigned char *)in->tlsext_hostname;
205 v6 = i2d_ASN1_OCTET_STRING(&(a.tlsext_hostname), NULL);
206 len += ASN1_object_size(1, v6, 6);
190 } 207 }
191 if (in->tlsext_tick) { 208
192 a.tlsext_tick.length = in->tlsext_ticklen; 209 /* 7 - PSK identity hint. */
193 a.tlsext_tick.type = V_ASN1_OCTET_STRING; 210 /* 8 - PSK identity. */
194 a.tlsext_tick.data = (unsigned char *)in->tlsext_tick; 211
195 }
196 if (in->tlsext_tick_lifetime_hint > 0) { 212 if (in->tlsext_tick_lifetime_hint > 0) {
197 a.tlsext_tick_lifetime.length = LSIZE2; 213 a.tlsext_tick_lifetime.length = LSIZE2;
198 a.tlsext_tick_lifetime.type = V_ASN1_INTEGER; 214 a.tlsext_tick_lifetime.type = V_ASN1_INTEGER;
199 a.tlsext_tick_lifetime.data = ibuf6; 215 a.tlsext_tick_lifetime.data = ibuf6;
200 ASN1_INTEGER_set(&a.tlsext_tick_lifetime, 216 ASN1_INTEGER_set(&a.tlsext_tick_lifetime,
201 in->tlsext_tick_lifetime_hint); 217 in->tlsext_tick_lifetime_hint);
218 v9 = i2d_ASN1_INTEGER(&(a.tlsext_tick_lifetime), NULL);
219 len += ASN1_object_size(1, v9, 9);
220 }
221
222 if (in->tlsext_tick) {
223 a.tlsext_tick.length = in->tlsext_ticklen;
224 a.tlsext_tick.type = V_ASN1_OCTET_STRING;
225 a.tlsext_tick.data = (unsigned char *)in->tlsext_tick;
226 v10 = i2d_ASN1_OCTET_STRING(&(a.tlsext_tick), NULL);
227 len += ASN1_object_size(1, v10, 10);
228 }
229
230 /* 11 - Compression method. */
231 /* 12 - SRP username. */
232
233 /* If given a NULL pointer, return the length only. */
234 ret = (ASN1_object_size(1, len, V_ASN1_SEQUENCE));
235 if (pp == NULL)
236 return (ret);
237
238 /* Burp out the ASN1. */
239 p = *pp;
240 ASN1_put_object(&p, 1, len, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
241 i2d_ASN1_INTEGER(&(a.version), &p);
242 i2d_ASN1_INTEGER(&(a.ssl_version), &p);
243 i2d_ASN1_OCTET_STRING(&(a.cipher), &p);
244 i2d_ASN1_OCTET_STRING(&(a.session_id), &p);
245 i2d_ASN1_OCTET_STRING(&(a.master_key), &p);
246 if (in->time != 0L) {
247 ASN1_put_object(&p, 1, v1, 1, V_ASN1_CONTEXT_SPECIFIC);
248 i2d_ASN1_INTEGER(&(a.time), &p);
249 }
250 if (in->timeout != 0L) {
251 ASN1_put_object(&p, 1, v2, 2, V_ASN1_CONTEXT_SPECIFIC);
252 i2d_ASN1_INTEGER(&(a.timeout), &p);
253 }
254 if (in->peer != NULL) {
255 ASN1_put_object(&p, 1, v3, 3, V_ASN1_CONTEXT_SPECIFIC);
256 i2d_X509(in->peer, &p);
257 }
258 ASN1_put_object(&p, 1, v4, 4, V_ASN1_CONTEXT_SPECIFIC);
259 i2d_ASN1_OCTET_STRING(&(a.session_id_context), &p);
260 if (in->verify_result != X509_V_OK) {
261 ASN1_put_object(&p, 1, v5, 5, V_ASN1_CONTEXT_SPECIFIC);
262 i2d_ASN1_INTEGER(&(a.verify_result), &p);
263 }
264 if (in->tlsext_hostname) {
265 ASN1_put_object(&p, 1, v6, 6, V_ASN1_CONTEXT_SPECIFIC);
266 i2d_ASN1_OCTET_STRING(&(a.tlsext_hostname), &p);
267 }
268 /* 7 - PSK identity hint. */
269 /* 8 - PSK identity. */
270 if (in->tlsext_tick_lifetime_hint > 0) {
271 ASN1_put_object(&p, 1, v9, 9, V_ASN1_CONTEXT_SPECIFIC);
272 i2d_ASN1_INTEGER(&(a.tlsext_tick_lifetime), &p);
273 }
274 if (in->tlsext_tick) {
275 ASN1_put_object(&p, 1, v10, 10, V_ASN1_CONTEXT_SPECIFIC);
276 i2d_ASN1_OCTET_STRING(&(a.tlsext_tick), &p);
202 } 277 }
278 /* 11 - Compression method. */
279 /* 12 - SRP username. */
203 280
204 M_ASN1_I2D_len(&(a.version), i2d_ASN1_INTEGER); 281 *pp = p;
205 M_ASN1_I2D_len(&(a.ssl_version), i2d_ASN1_INTEGER); 282 return (ret);
206 M_ASN1_I2D_len(&(a.cipher), i2d_ASN1_OCTET_STRING);
207 M_ASN1_I2D_len(&(a.session_id), i2d_ASN1_OCTET_STRING);
208 M_ASN1_I2D_len(&(a.master_key), i2d_ASN1_OCTET_STRING);
209
210 if (in->time != 0L)
211 M_ASN1_I2D_len_EXP_opt(&(a.time), i2d_ASN1_INTEGER, 1, v1);
212 if (in->timeout != 0L)
213 M_ASN1_I2D_len_EXP_opt(&(a.timeout), i2d_ASN1_INTEGER, 2, v2);
214 if (in->peer != NULL)
215 M_ASN1_I2D_len_EXP_opt(in->peer, i2d_X509, 3, v3);
216 M_ASN1_I2D_len_EXP_opt(&a.session_id_context,
217 i2d_ASN1_OCTET_STRING, 4, v4);
218 if (in->verify_result != X509_V_OK)
219 M_ASN1_I2D_len_EXP_opt(&(a.verify_result),
220 i2d_ASN1_INTEGER, 5, v5);
221 if (in->tlsext_tick_lifetime_hint > 0)
222 M_ASN1_I2D_len_EXP_opt(&a.tlsext_tick_lifetime,
223 i2d_ASN1_INTEGER, 9, v9);
224 if (in->tlsext_tick)
225 M_ASN1_I2D_len_EXP_opt(&(a.tlsext_tick),
226 i2d_ASN1_OCTET_STRING, 10, v10);
227 if (in->tlsext_hostname)
228 M_ASN1_I2D_len_EXP_opt(&(a.tlsext_hostname),
229 i2d_ASN1_OCTET_STRING, 6, v6);
230
231 M_ASN1_I2D_seq_total();
232
233 M_ASN1_I2D_put(&(a.version), i2d_ASN1_INTEGER);
234 M_ASN1_I2D_put(&(a.ssl_version), i2d_ASN1_INTEGER);
235 M_ASN1_I2D_put(&(a.cipher), i2d_ASN1_OCTET_STRING);
236 M_ASN1_I2D_put(&(a.session_id), i2d_ASN1_OCTET_STRING);
237 M_ASN1_I2D_put(&(a.master_key), i2d_ASN1_OCTET_STRING);
238 if (in->time != 0L)
239 M_ASN1_I2D_put_EXP_opt(&(a.time), i2d_ASN1_INTEGER, 1, v1);
240 if (in->timeout != 0L)
241 M_ASN1_I2D_put_EXP_opt(&(a.timeout), i2d_ASN1_INTEGER, 2, v2);
242 if (in->peer != NULL)
243 M_ASN1_I2D_put_EXP_opt(in->peer, i2d_X509, 3, v3);
244 M_ASN1_I2D_put_EXP_opt(&a.session_id_context,
245 i2d_ASN1_OCTET_STRING, 4, v4);
246 if (in->verify_result != X509_V_OK)
247 M_ASN1_I2D_put_EXP_opt(&a.verify_result,
248 i2d_ASN1_INTEGER, 5, v5);
249 if (in->tlsext_hostname)
250 M_ASN1_I2D_put_EXP_opt(&(a.tlsext_hostname),
251 i2d_ASN1_OCTET_STRING, 6, v6);
252 if (in->tlsext_tick_lifetime_hint > 0)
253 M_ASN1_I2D_put_EXP_opt(&a.tlsext_tick_lifetime,
254 i2d_ASN1_INTEGER, 9, v9);
255 if (in->tlsext_tick)
256 M_ASN1_I2D_put_EXP_opt(&(a.tlsext_tick),
257 i2d_ASN1_OCTET_STRING, 10, v10);
258
259 M_ASN1_I2D_finish();
260} 283}
261 284
262SSL_SESSION * 285SSL_SESSION *
diff --git a/src/lib/libssl/ssl_asn1.c b/src/lib/libssl/ssl_asn1.c
index 0c9b4aa6fb..33a8edf20a 100644
--- a/src/lib/libssl/ssl_asn1.c
+++ b/src/lib/libssl/ssl_asn1.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_asn1.c,v 1.30 2014/07/13 00:30:07 jsing Exp $ */ 1/* $OpenBSD: ssl_asn1.c,v 1.31 2014/07/13 16:30:50 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -116,7 +116,8 @@ i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
116 unsigned char ibuf3[LSIZE2], ibuf4[LSIZE2], ibuf5[LSIZE2]; 116 unsigned char ibuf3[LSIZE2], ibuf4[LSIZE2], ibuf5[LSIZE2];
117 unsigned char ibuf6[LSIZE2]; 117 unsigned char ibuf6[LSIZE2];
118 SSL_SESSION_ASN1 a; 118 SSL_SESSION_ASN1 a;
119 M_ASN1_I2D_vars(in); 119 unsigned char *p;
120 int len = 0, ret;
120 long l; 121 long l;
121 122
122 if ((in == NULL) || ((in->cipher == NULL) && (in->cipher_id == 0))) 123 if ((in == NULL) || ((in->cipher == NULL) && (in->cipher_id == 0)))
@@ -133,40 +134,39 @@ i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
133 a.version.type = V_ASN1_INTEGER; 134 a.version.type = V_ASN1_INTEGER;
134 a.version.data = ibuf1; 135 a.version.data = ibuf1;
135 ASN1_INTEGER_set(&(a.version), SSL_SESSION_ASN1_VERSION); 136 ASN1_INTEGER_set(&(a.version), SSL_SESSION_ASN1_VERSION);
137 len += i2d_ASN1_INTEGER(&(a.version), NULL);
136 138
137 a.ssl_version.length = LSIZE2; 139 a.ssl_version.length = LSIZE2;
138 a.ssl_version.type = V_ASN1_INTEGER; 140 a.ssl_version.type = V_ASN1_INTEGER;
139 a.ssl_version.data = ibuf2; 141 a.ssl_version.data = ibuf2;
140 ASN1_INTEGER_set(&(a.ssl_version), in->ssl_version); 142 ASN1_INTEGER_set(&(a.ssl_version), in->ssl_version);
143 len += i2d_ASN1_INTEGER(&(a.ssl_version), NULL);
141 144
145 a.cipher.length = 2;
142 a.cipher.type = V_ASN1_OCTET_STRING; 146 a.cipher.type = V_ASN1_OCTET_STRING;
147 l = (in->cipher == NULL) ? in->cipher_id : in->cipher->id;
148 buf[0] = ((unsigned char)(l >> 8L)) & 0xff;
149 buf[1] = ((unsigned char)(l)) & 0xff;
143 a.cipher.data = buf; 150 a.cipher.data = buf;
144 151 len += i2d_ASN1_OCTET_STRING(&(a.cipher), NULL);
145 if (in->cipher == NULL)
146 l = in->cipher_id;
147 else
148 l = in->cipher->id;
149 a.cipher.length = 2;
150 buf[0] = ((unsigned char)(l >> 8L))&0xff;
151 buf[1] = ((unsigned char)(l ))&0xff;
152 152
153 a.master_key.length = in->master_key_length; 153 a.master_key.length = in->master_key_length;
154 a.master_key.type = V_ASN1_OCTET_STRING; 154 a.master_key.type = V_ASN1_OCTET_STRING;
155 a.master_key.data = in->master_key; 155 a.master_key.data = in->master_key;
156 len += i2d_ASN1_OCTET_STRING(&(a.master_key), NULL);
156 157
157 a.session_id.length = in->session_id_length; 158 a.session_id.length = in->session_id_length;
158 a.session_id.type = V_ASN1_OCTET_STRING; 159 a.session_id.type = V_ASN1_OCTET_STRING;
159 a.session_id.data = in->session_id; 160 a.session_id.data = in->session_id;
160 161 len += i2d_ASN1_OCTET_STRING(&(a.session_id), NULL);
161 a.session_id_context.length = in->sid_ctx_length;
162 a.session_id_context.type = V_ASN1_OCTET_STRING;
163 a.session_id_context.data = in->sid_ctx;
164 162
165 if (in->time != 0L) { 163 if (in->time != 0L) {
166 a.time.length = LSIZE2; 164 a.time.length = LSIZE2;
167 a.time.type = V_ASN1_INTEGER; 165 a.time.type = V_ASN1_INTEGER;
168 a.time.data = ibuf3; 166 a.time.data = ibuf3;
169 ASN1_INTEGER_set(&(a.time), in->time); /* XXX 2038 */ 167 ASN1_INTEGER_set(&(a.time), in->time); /* XXX 2038 */
168 v1 = i2d_ASN1_INTEGER(&(a.time), NULL);
169 len += ASN1_object_size(1, v1, 1);
170 } 170 }
171 171
172 if (in->timeout != 0L) { 172 if (in->timeout != 0L) {
@@ -174,89 +174,112 @@ i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
174 a.timeout.type = V_ASN1_INTEGER; 174 a.timeout.type = V_ASN1_INTEGER;
175 a.timeout.data = ibuf4; 175 a.timeout.data = ibuf4;
176 ASN1_INTEGER_set(&(a.timeout), in->timeout); 176 ASN1_INTEGER_set(&(a.timeout), in->timeout);
177 v2 = i2d_ASN1_INTEGER(&(a.timeout), NULL);
178 len += ASN1_object_size(1, v2, 2);
177 } 179 }
178 180
181 if (in->peer != NULL) {
182 v3 = i2d_X509(in->peer, NULL);
183 len += ASN1_object_size(1, v3, 3);
184 }
185
186 a.session_id_context.length = in->sid_ctx_length;
187 a.session_id_context.type = V_ASN1_OCTET_STRING;
188 a.session_id_context.data = in->sid_ctx;
189 v4 = i2d_ASN1_OCTET_STRING(&(a.session_id_context), NULL);
190 len += ASN1_object_size(1, v4, 4);
191
179 if (in->verify_result != X509_V_OK) { 192 if (in->verify_result != X509_V_OK) {
180 a.verify_result.length = LSIZE2; 193 a.verify_result.length = LSIZE2;
181 a.verify_result.type = V_ASN1_INTEGER; 194 a.verify_result.type = V_ASN1_INTEGER;
182 a.verify_result.data = ibuf5; 195 a.verify_result.data = ibuf5;
183 ASN1_INTEGER_set(&a.verify_result, in->verify_result); 196 ASN1_INTEGER_set(&a.verify_result, in->verify_result);
197 v5 = i2d_ASN1_INTEGER(&(a.verify_result), NULL);
198 len += ASN1_object_size(1, v5, 5);
184 } 199 }
185 200
186 if (in->tlsext_hostname) { 201 if (in->tlsext_hostname) {
187 a.tlsext_hostname.length = strlen(in->tlsext_hostname); 202 a.tlsext_hostname.length = strlen(in->tlsext_hostname);
188 a.tlsext_hostname.type = V_ASN1_OCTET_STRING; 203 a.tlsext_hostname.type = V_ASN1_OCTET_STRING;
189 a.tlsext_hostname.data = (unsigned char *)in->tlsext_hostname; 204 a.tlsext_hostname.data = (unsigned char *)in->tlsext_hostname;
205 v6 = i2d_ASN1_OCTET_STRING(&(a.tlsext_hostname), NULL);
206 len += ASN1_object_size(1, v6, 6);
190 } 207 }
191 if (in->tlsext_tick) { 208
192 a.tlsext_tick.length = in->tlsext_ticklen; 209 /* 7 - PSK identity hint. */
193 a.tlsext_tick.type = V_ASN1_OCTET_STRING; 210 /* 8 - PSK identity. */
194 a.tlsext_tick.data = (unsigned char *)in->tlsext_tick; 211
195 }
196 if (in->tlsext_tick_lifetime_hint > 0) { 212 if (in->tlsext_tick_lifetime_hint > 0) {
197 a.tlsext_tick_lifetime.length = LSIZE2; 213 a.tlsext_tick_lifetime.length = LSIZE2;
198 a.tlsext_tick_lifetime.type = V_ASN1_INTEGER; 214 a.tlsext_tick_lifetime.type = V_ASN1_INTEGER;
199 a.tlsext_tick_lifetime.data = ibuf6; 215 a.tlsext_tick_lifetime.data = ibuf6;
200 ASN1_INTEGER_set(&a.tlsext_tick_lifetime, 216 ASN1_INTEGER_set(&a.tlsext_tick_lifetime,
201 in->tlsext_tick_lifetime_hint); 217 in->tlsext_tick_lifetime_hint);
218 v9 = i2d_ASN1_INTEGER(&(a.tlsext_tick_lifetime), NULL);
219 len += ASN1_object_size(1, v9, 9);
220 }
221
222 if (in->tlsext_tick) {
223 a.tlsext_tick.length = in->tlsext_ticklen;
224 a.tlsext_tick.type = V_ASN1_OCTET_STRING;
225 a.tlsext_tick.data = (unsigned char *)in->tlsext_tick;
226 v10 = i2d_ASN1_OCTET_STRING(&(a.tlsext_tick), NULL);
227 len += ASN1_object_size(1, v10, 10);
228 }
229
230 /* 11 - Compression method. */
231 /* 12 - SRP username. */
232
233 /* If given a NULL pointer, return the length only. */
234 ret = (ASN1_object_size(1, len, V_ASN1_SEQUENCE));
235 if (pp == NULL)
236 return (ret);
237
238 /* Burp out the ASN1. */
239 p = *pp;
240 ASN1_put_object(&p, 1, len, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
241 i2d_ASN1_INTEGER(&(a.version), &p);
242 i2d_ASN1_INTEGER(&(a.ssl_version), &p);
243 i2d_ASN1_OCTET_STRING(&(a.cipher), &p);
244 i2d_ASN1_OCTET_STRING(&(a.session_id), &p);
245 i2d_ASN1_OCTET_STRING(&(a.master_key), &p);
246 if (in->time != 0L) {
247 ASN1_put_object(&p, 1, v1, 1, V_ASN1_CONTEXT_SPECIFIC);
248 i2d_ASN1_INTEGER(&(a.time), &p);
249 }
250 if (in->timeout != 0L) {
251 ASN1_put_object(&p, 1, v2, 2, V_ASN1_CONTEXT_SPECIFIC);
252 i2d_ASN1_INTEGER(&(a.timeout), &p);
253 }
254 if (in->peer != NULL) {
255 ASN1_put_object(&p, 1, v3, 3, V_ASN1_CONTEXT_SPECIFIC);
256 i2d_X509(in->peer, &p);
257 }
258 ASN1_put_object(&p, 1, v4, 4, V_ASN1_CONTEXT_SPECIFIC);
259 i2d_ASN1_OCTET_STRING(&(a.session_id_context), &p);
260 if (in->verify_result != X509_V_OK) {
261 ASN1_put_object(&p, 1, v5, 5, V_ASN1_CONTEXT_SPECIFIC);
262 i2d_ASN1_INTEGER(&(a.verify_result), &p);
263 }
264 if (in->tlsext_hostname) {
265 ASN1_put_object(&p, 1, v6, 6, V_ASN1_CONTEXT_SPECIFIC);
266 i2d_ASN1_OCTET_STRING(&(a.tlsext_hostname), &p);
267 }
268 /* 7 - PSK identity hint. */
269 /* 8 - PSK identity. */
270 if (in->tlsext_tick_lifetime_hint > 0) {
271 ASN1_put_object(&p, 1, v9, 9, V_ASN1_CONTEXT_SPECIFIC);
272 i2d_ASN1_INTEGER(&(a.tlsext_tick_lifetime), &p);
273 }
274 if (in->tlsext_tick) {
275 ASN1_put_object(&p, 1, v10, 10, V_ASN1_CONTEXT_SPECIFIC);
276 i2d_ASN1_OCTET_STRING(&(a.tlsext_tick), &p);
202 } 277 }
278 /* 11 - Compression method. */
279 /* 12 - SRP username. */
203 280
204 M_ASN1_I2D_len(&(a.version), i2d_ASN1_INTEGER); 281 *pp = p;
205 M_ASN1_I2D_len(&(a.ssl_version), i2d_ASN1_INTEGER); 282 return (ret);
206 M_ASN1_I2D_len(&(a.cipher), i2d_ASN1_OCTET_STRING);
207 M_ASN1_I2D_len(&(a.session_id), i2d_ASN1_OCTET_STRING);
208 M_ASN1_I2D_len(&(a.master_key), i2d_ASN1_OCTET_STRING);
209
210 if (in->time != 0L)
211 M_ASN1_I2D_len_EXP_opt(&(a.time), i2d_ASN1_INTEGER, 1, v1);
212 if (in->timeout != 0L)
213 M_ASN1_I2D_len_EXP_opt(&(a.timeout), i2d_ASN1_INTEGER, 2, v2);
214 if (in->peer != NULL)
215 M_ASN1_I2D_len_EXP_opt(in->peer, i2d_X509, 3, v3);
216 M_ASN1_I2D_len_EXP_opt(&a.session_id_context,
217 i2d_ASN1_OCTET_STRING, 4, v4);
218 if (in->verify_result != X509_V_OK)
219 M_ASN1_I2D_len_EXP_opt(&(a.verify_result),
220 i2d_ASN1_INTEGER, 5, v5);
221 if (in->tlsext_tick_lifetime_hint > 0)
222 M_ASN1_I2D_len_EXP_opt(&a.tlsext_tick_lifetime,
223 i2d_ASN1_INTEGER, 9, v9);
224 if (in->tlsext_tick)
225 M_ASN1_I2D_len_EXP_opt(&(a.tlsext_tick),
226 i2d_ASN1_OCTET_STRING, 10, v10);
227 if (in->tlsext_hostname)
228 M_ASN1_I2D_len_EXP_opt(&(a.tlsext_hostname),
229 i2d_ASN1_OCTET_STRING, 6, v6);
230
231 M_ASN1_I2D_seq_total();
232
233 M_ASN1_I2D_put(&(a.version), i2d_ASN1_INTEGER);
234 M_ASN1_I2D_put(&(a.ssl_version), i2d_ASN1_INTEGER);
235 M_ASN1_I2D_put(&(a.cipher), i2d_ASN1_OCTET_STRING);
236 M_ASN1_I2D_put(&(a.session_id), i2d_ASN1_OCTET_STRING);
237 M_ASN1_I2D_put(&(a.master_key), i2d_ASN1_OCTET_STRING);
238 if (in->time != 0L)
239 M_ASN1_I2D_put_EXP_opt(&(a.time), i2d_ASN1_INTEGER, 1, v1);
240 if (in->timeout != 0L)
241 M_ASN1_I2D_put_EXP_opt(&(a.timeout), i2d_ASN1_INTEGER, 2, v2);
242 if (in->peer != NULL)
243 M_ASN1_I2D_put_EXP_opt(in->peer, i2d_X509, 3, v3);
244 M_ASN1_I2D_put_EXP_opt(&a.session_id_context,
245 i2d_ASN1_OCTET_STRING, 4, v4);
246 if (in->verify_result != X509_V_OK)
247 M_ASN1_I2D_put_EXP_opt(&a.verify_result,
248 i2d_ASN1_INTEGER, 5, v5);
249 if (in->tlsext_hostname)
250 M_ASN1_I2D_put_EXP_opt(&(a.tlsext_hostname),
251 i2d_ASN1_OCTET_STRING, 6, v6);
252 if (in->tlsext_tick_lifetime_hint > 0)
253 M_ASN1_I2D_put_EXP_opt(&a.tlsext_tick_lifetime,
254 i2d_ASN1_INTEGER, 9, v9);
255 if (in->tlsext_tick)
256 M_ASN1_I2D_put_EXP_opt(&(a.tlsext_tick),
257 i2d_ASN1_OCTET_STRING, 10, v10);
258
259 M_ASN1_I2D_finish();
260} 283}
261 284
262SSL_SESSION * 285SSL_SESSION *