diff options
Diffstat (limited to 'src/lib/libssl')
62 files changed, 13147 insertions, 1452 deletions
diff --git a/src/lib/libssl/LICENSE b/src/lib/libssl/LICENSE index e6afecc724..a2c4adcbe6 100644 --- a/src/lib/libssl/LICENSE +++ b/src/lib/libssl/LICENSE | |||
| @@ -12,7 +12,7 @@ | |||
| 12 | --------------- | 12 | --------------- |
| 13 | 13 | ||
| 14 | /* ==================================================================== | 14 | /* ==================================================================== |
| 15 | * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved. | 15 | * Copyright (c) 1998-2008 The OpenSSL Project. All rights reserved. |
| 16 | * | 16 | * |
| 17 | * Redistribution and use in source and binary forms, with or without | 17 | * Redistribution and use in source and binary forms, with or without |
| 18 | * modification, are permitted provided that the following conditions | 18 | * modification, are permitted provided that the following conditions |
diff --git a/src/lib/libssl/bio_ssl.c b/src/lib/libssl/bio_ssl.c index d683ee43e1..420deb7fc9 100644 --- a/src/lib/libssl/bio_ssl.c +++ b/src/lib/libssl/bio_ssl.c | |||
| @@ -456,7 +456,7 @@ static long ssl_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
| 456 | case BIO_CTRL_SET_CALLBACK: | 456 | case BIO_CTRL_SET_CALLBACK: |
| 457 | { | 457 | { |
| 458 | #if 0 /* FIXME: Should this be used? -- Richard Levitte */ | 458 | #if 0 /* FIXME: Should this be used? -- Richard Levitte */ |
| 459 | BIOerr(SSL_F_SSL_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | 459 | SSLerr(SSL_F_SSL_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); |
| 460 | ret = -1; | 460 | ret = -1; |
| 461 | #else | 461 | #else |
| 462 | ret=0; | 462 | ret=0; |
| @@ -465,9 +465,9 @@ static long ssl_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
| 465 | break; | 465 | break; |
| 466 | case BIO_CTRL_GET_CALLBACK: | 466 | case BIO_CTRL_GET_CALLBACK: |
| 467 | { | 467 | { |
| 468 | void (**fptr)(); | 468 | void (**fptr)(const SSL *xssl,int type,int val); |
| 469 | 469 | ||
| 470 | fptr=(void (**)())ptr; | 470 | fptr=(void (**)(const SSL *xssl,int type,int val))ptr; |
| 471 | *fptr=SSL_get_info_callback(ssl); | 471 | *fptr=SSL_get_info_callback(ssl); |
| 472 | } | 472 | } |
| 473 | break; | 473 | break; |
diff --git a/src/lib/libssl/d1_both.c b/src/lib/libssl/d1_both.c new file mode 100644 index 0000000000..15a201a25c --- /dev/null +++ b/src/lib/libssl/d1_both.c | |||
| @@ -0,0 +1,1193 @@ | |||
| 1 | /* ssl/d1_both.c */ | ||
| 2 | /* | ||
| 3 | * DTLS implementation written by Nagendra Modadugu | ||
| 4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. | ||
| 5 | */ | ||
| 6 | /* ==================================================================== | ||
| 7 | * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved. | ||
| 8 | * | ||
| 9 | * Redistribution and use in source and binary forms, with or without | ||
| 10 | * modification, are permitted provided that the following conditions | ||
| 11 | * are met: | ||
| 12 | * | ||
| 13 | * 1. Redistributions of source code must retain the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer. | ||
| 15 | * | ||
| 16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 17 | * notice, this list of conditions and the following disclaimer in | ||
| 18 | * the documentation and/or other materials provided with the | ||
| 19 | * distribution. | ||
| 20 | * | ||
| 21 | * 3. All advertising materials mentioning features or use of this | ||
| 22 | * software must display the following acknowledgment: | ||
| 23 | * "This product includes software developed by the OpenSSL Project | ||
| 24 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 25 | * | ||
| 26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 27 | * endorse or promote products derived from this software without | ||
| 28 | * prior written permission. For written permission, please contact | ||
| 29 | * openssl-core@openssl.org. | ||
| 30 | * | ||
| 31 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 32 | * nor may "OpenSSL" appear in their names without prior written | ||
| 33 | * permission of the OpenSSL Project. | ||
| 34 | * | ||
| 35 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 36 | * acknowledgment: | ||
| 37 | * "This product includes software developed by the OpenSSL Project | ||
| 38 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 39 | * | ||
| 40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 51 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 52 | * ==================================================================== | ||
| 53 | * | ||
| 54 | * This product includes cryptographic software written by Eric Young | ||
| 55 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 56 | * Hudson (tjh@cryptsoft.com). | ||
| 57 | * | ||
| 58 | */ | ||
| 59 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 60 | * All rights reserved. | ||
| 61 | * | ||
| 62 | * This package is an SSL implementation written | ||
| 63 | * by Eric Young (eay@cryptsoft.com). | ||
| 64 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 65 | * | ||
| 66 | * This library is free for commercial and non-commercial use as long as | ||
| 67 | * the following conditions are aheared to. The following conditions | ||
| 68 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 69 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 70 | * included with this distribution is covered by the same copyright terms | ||
| 71 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 72 | * | ||
| 73 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 74 | * the code are not to be removed. | ||
| 75 | * If this package is used in a product, Eric Young should be given attribution | ||
| 76 | * as the author of the parts of the library used. | ||
| 77 | * This can be in the form of a textual message at program startup or | ||
| 78 | * in documentation (online or textual) provided with the package. | ||
| 79 | * | ||
| 80 | * Redistribution and use in source and binary forms, with or without | ||
| 81 | * modification, are permitted provided that the following conditions | ||
| 82 | * are met: | ||
| 83 | * 1. Redistributions of source code must retain the copyright | ||
| 84 | * notice, this list of conditions and the following disclaimer. | ||
| 85 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 86 | * notice, this list of conditions and the following disclaimer in the | ||
| 87 | * documentation and/or other materials provided with the distribution. | ||
| 88 | * 3. All advertising materials mentioning features or use of this software | ||
| 89 | * must display the following acknowledgement: | ||
| 90 | * "This product includes cryptographic software written by | ||
| 91 | * Eric Young (eay@cryptsoft.com)" | ||
| 92 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 93 | * being used are not cryptographic related :-). | ||
| 94 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 95 | * the apps directory (application code) you must include an acknowledgement: | ||
| 96 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 97 | * | ||
| 98 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 99 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 100 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 101 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 102 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 103 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 104 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 105 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 106 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 107 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 108 | * SUCH DAMAGE. | ||
| 109 | * | ||
| 110 | * The licence and distribution terms for any publically available version or | ||
| 111 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 112 | * copied and put under another distribution licence | ||
| 113 | * [including the GNU Public Licence.] | ||
| 114 | */ | ||
| 115 | |||
| 116 | #include <limits.h> | ||
| 117 | #include <string.h> | ||
| 118 | #include <stdio.h> | ||
| 119 | #include "ssl_locl.h" | ||
| 120 | #include <openssl/buffer.h> | ||
| 121 | #include <openssl/rand.h> | ||
| 122 | #include <openssl/objects.h> | ||
| 123 | #include <openssl/evp.h> | ||
| 124 | #include <openssl/x509.h> | ||
| 125 | |||
| 126 | |||
| 127 | /* XDTLS: figure out the right values */ | ||
| 128 | static unsigned int g_probable_mtu[] = {1500 - 28, 512 - 28, 256 - 28}; | ||
| 129 | |||
| 130 | static unsigned int dtls1_min_mtu(void); | ||
| 131 | static unsigned int dtls1_guess_mtu(unsigned int curr_mtu); | ||
| 132 | static void dtls1_fix_message_header(SSL *s, unsigned long frag_off, | ||
| 133 | unsigned long frag_len); | ||
| 134 | static unsigned char *dtls1_write_message_header(SSL *s, | ||
| 135 | unsigned char *p); | ||
| 136 | static void dtls1_set_message_header_int(SSL *s, unsigned char mt, | ||
| 137 | unsigned long len, unsigned short seq_num, unsigned long frag_off, | ||
| 138 | unsigned long frag_len); | ||
| 139 | static int dtls1_retransmit_buffered_messages(SSL *s); | ||
| 140 | static long dtls1_get_message_fragment(SSL *s, int st1, int stn, | ||
| 141 | long max, int *ok); | ||
| 142 | |||
| 143 | static hm_fragment * | ||
| 144 | dtls1_hm_fragment_new(unsigned long frag_len) | ||
| 145 | { | ||
| 146 | hm_fragment *frag = NULL; | ||
| 147 | unsigned char *buf = NULL; | ||
| 148 | |||
| 149 | frag = (hm_fragment *)OPENSSL_malloc(sizeof(hm_fragment)); | ||
| 150 | if ( frag == NULL) | ||
| 151 | return NULL; | ||
| 152 | |||
| 153 | if (frag_len) | ||
| 154 | { | ||
| 155 | buf = (unsigned char *)OPENSSL_malloc(frag_len); | ||
| 156 | if ( buf == NULL) | ||
| 157 | { | ||
| 158 | OPENSSL_free(frag); | ||
| 159 | return NULL; | ||
| 160 | } | ||
| 161 | } | ||
| 162 | |||
| 163 | /* zero length fragment gets zero frag->fragment */ | ||
| 164 | frag->fragment = buf; | ||
| 165 | |||
| 166 | return frag; | ||
| 167 | } | ||
| 168 | |||
| 169 | static void | ||
| 170 | dtls1_hm_fragment_free(hm_fragment *frag) | ||
| 171 | { | ||
| 172 | if (frag->fragment) OPENSSL_free(frag->fragment); | ||
| 173 | OPENSSL_free(frag); | ||
| 174 | } | ||
| 175 | |||
| 176 | /* send s->init_buf in records of type 'type' (SSL3_RT_HANDSHAKE or SSL3_RT_CHANGE_CIPHER_SPEC) */ | ||
| 177 | int dtls1_do_write(SSL *s, int type) | ||
| 178 | { | ||
| 179 | int ret; | ||
| 180 | int curr_mtu; | ||
| 181 | unsigned int len, frag_off; | ||
| 182 | |||
| 183 | /* AHA! Figure out the MTU, and stick to the right size */ | ||
| 184 | if ( ! (SSL_get_options(s) & SSL_OP_NO_QUERY_MTU)) | ||
| 185 | { | ||
| 186 | s->d1->mtu = | ||
| 187 | BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_QUERY_MTU, 0, NULL); | ||
| 188 | |||
| 189 | /* I've seen the kernel return bogus numbers when it doesn't know | ||
| 190 | * (initial write), so just make sure we have a reasonable number */ | ||
| 191 | if ( s->d1->mtu < dtls1_min_mtu()) | ||
| 192 | { | ||
| 193 | s->d1->mtu = 0; | ||
| 194 | s->d1->mtu = dtls1_guess_mtu(s->d1->mtu); | ||
| 195 | BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SET_MTU, | ||
| 196 | s->d1->mtu, NULL); | ||
| 197 | } | ||
| 198 | } | ||
| 199 | #if 0 | ||
| 200 | mtu = s->d1->mtu; | ||
| 201 | |||
| 202 | fprintf(stderr, "using MTU = %d\n", mtu); | ||
| 203 | |||
| 204 | mtu -= (DTLS1_HM_HEADER_LENGTH + DTLS1_RT_HEADER_LENGTH); | ||
| 205 | |||
| 206 | curr_mtu = mtu - BIO_wpending(SSL_get_wbio(s)); | ||
| 207 | |||
| 208 | if ( curr_mtu > 0) | ||
| 209 | mtu = curr_mtu; | ||
| 210 | else if ( ( ret = BIO_flush(SSL_get_wbio(s))) <= 0) | ||
| 211 | return ret; | ||
| 212 | |||
| 213 | if ( BIO_wpending(SSL_get_wbio(s)) + s->init_num >= mtu) | ||
| 214 | { | ||
| 215 | ret = BIO_flush(SSL_get_wbio(s)); | ||
| 216 | if ( ret <= 0) | ||
| 217 | return ret; | ||
| 218 | mtu = s->d1->mtu - (DTLS1_HM_HEADER_LENGTH + DTLS1_RT_HEADER_LENGTH); | ||
| 219 | } | ||
| 220 | |||
| 221 | OPENSSL_assert(mtu > 0); /* should have something reasonable now */ | ||
| 222 | |||
| 223 | #endif | ||
| 224 | |||
| 225 | if ( s->init_off == 0 && type == SSL3_RT_HANDSHAKE) | ||
| 226 | OPENSSL_assert(s->init_num == | ||
| 227 | (int)s->d1->w_msg_hdr.msg_len + DTLS1_HM_HEADER_LENGTH); | ||
| 228 | |||
| 229 | frag_off = 0; | ||
| 230 | while( s->init_num) | ||
| 231 | { | ||
| 232 | curr_mtu = s->d1->mtu - BIO_wpending(SSL_get_wbio(s)) - | ||
| 233 | DTLS1_RT_HEADER_LENGTH; | ||
| 234 | |||
| 235 | if ( curr_mtu <= DTLS1_HM_HEADER_LENGTH) | ||
| 236 | { | ||
| 237 | /* grr.. we could get an error if MTU picked was wrong */ | ||
| 238 | ret = BIO_flush(SSL_get_wbio(s)); | ||
| 239 | if ( ret <= 0) | ||
| 240 | return ret; | ||
| 241 | curr_mtu = s->d1->mtu - DTLS1_RT_HEADER_LENGTH; | ||
| 242 | } | ||
| 243 | |||
| 244 | if ( s->init_num > curr_mtu) | ||
| 245 | len = curr_mtu; | ||
| 246 | else | ||
| 247 | len = s->init_num; | ||
| 248 | |||
| 249 | |||
| 250 | /* XDTLS: this function is too long. split out the CCS part */ | ||
| 251 | if ( type == SSL3_RT_HANDSHAKE) | ||
| 252 | { | ||
| 253 | if ( s->init_off != 0) | ||
| 254 | { | ||
| 255 | OPENSSL_assert(s->init_off > DTLS1_HM_HEADER_LENGTH); | ||
| 256 | s->init_off -= DTLS1_HM_HEADER_LENGTH; | ||
| 257 | s->init_num += DTLS1_HM_HEADER_LENGTH; | ||
| 258 | |||
| 259 | /* write atleast DTLS1_HM_HEADER_LENGTH bytes */ | ||
| 260 | if ( len <= DTLS1_HM_HEADER_LENGTH) | ||
| 261 | len += DTLS1_HM_HEADER_LENGTH; | ||
| 262 | } | ||
| 263 | |||
| 264 | dtls1_fix_message_header(s, frag_off, | ||
| 265 | len - DTLS1_HM_HEADER_LENGTH); | ||
| 266 | |||
| 267 | dtls1_write_message_header(s, (unsigned char *)&s->init_buf->data[s->init_off]); | ||
| 268 | |||
| 269 | OPENSSL_assert(len >= DTLS1_HM_HEADER_LENGTH); | ||
| 270 | } | ||
| 271 | |||
| 272 | ret=dtls1_write_bytes(s,type,&s->init_buf->data[s->init_off], | ||
| 273 | len); | ||
| 274 | if (ret < 0) | ||
| 275 | { | ||
| 276 | /* might need to update MTU here, but we don't know | ||
| 277 | * which previous packet caused the failure -- so can't | ||
| 278 | * really retransmit anything. continue as if everything | ||
| 279 | * is fine and wait for an alert to handle the | ||
| 280 | * retransmit | ||
| 281 | */ | ||
| 282 | if ( BIO_ctrl(SSL_get_wbio(s), | ||
| 283 | BIO_CTRL_DGRAM_MTU_EXCEEDED, 0, NULL)) | ||
| 284 | s->d1->mtu = BIO_ctrl(SSL_get_wbio(s), | ||
| 285 | BIO_CTRL_DGRAM_QUERY_MTU, 0, NULL); | ||
| 286 | else | ||
| 287 | return(-1); | ||
| 288 | } | ||
| 289 | else | ||
| 290 | { | ||
| 291 | |||
| 292 | /* bad if this assert fails, only part of the handshake | ||
| 293 | * message got sent. but why would this happen? */ | ||
| 294 | OPENSSL_assert(len == (unsigned int)ret); | ||
| 295 | |||
| 296 | if (type == SSL3_RT_HANDSHAKE && ! s->d1->retransmitting) | ||
| 297 | { | ||
| 298 | /* should not be done for 'Hello Request's, but in that case | ||
| 299 | * we'll ignore the result anyway */ | ||
| 300 | unsigned char *p = (unsigned char *)&s->init_buf->data[s->init_off]; | ||
| 301 | const struct hm_header_st *msg_hdr = &s->d1->w_msg_hdr; | ||
| 302 | int xlen; | ||
| 303 | |||
| 304 | if (frag_off == 0 && s->client_version != DTLS1_BAD_VER) | ||
| 305 | { | ||
| 306 | /* reconstruct message header is if it | ||
| 307 | * is being sent in single fragment */ | ||
| 308 | *p++ = msg_hdr->type; | ||
| 309 | l2n3(msg_hdr->msg_len,p); | ||
| 310 | s2n (msg_hdr->seq,p); | ||
| 311 | l2n3(0,p); | ||
| 312 | l2n3(msg_hdr->msg_len,p); | ||
| 313 | p -= DTLS1_HM_HEADER_LENGTH; | ||
| 314 | xlen = ret; | ||
| 315 | } | ||
| 316 | else | ||
| 317 | { | ||
| 318 | p += DTLS1_HM_HEADER_LENGTH; | ||
| 319 | xlen = ret - DTLS1_HM_HEADER_LENGTH; | ||
| 320 | } | ||
| 321 | |||
| 322 | ssl3_finish_mac(s, p, xlen); | ||
| 323 | } | ||
| 324 | |||
| 325 | if (ret == s->init_num) | ||
| 326 | { | ||
| 327 | if (s->msg_callback) | ||
| 328 | s->msg_callback(1, s->version, type, s->init_buf->data, | ||
| 329 | (size_t)(s->init_off + s->init_num), s, | ||
| 330 | s->msg_callback_arg); | ||
| 331 | |||
| 332 | s->init_off = 0; /* done writing this message */ | ||
| 333 | s->init_num = 0; | ||
| 334 | |||
| 335 | return(1); | ||
| 336 | } | ||
| 337 | s->init_off+=ret; | ||
| 338 | s->init_num-=ret; | ||
| 339 | frag_off += (ret -= DTLS1_HM_HEADER_LENGTH); | ||
| 340 | } | ||
| 341 | } | ||
| 342 | return(0); | ||
| 343 | } | ||
| 344 | |||
| 345 | |||
| 346 | /* Obtain handshake message of message type 'mt' (any if mt == -1), | ||
| 347 | * maximum acceptable body length 'max'. | ||
| 348 | * Read an entire handshake message. Handshake messages arrive in | ||
| 349 | * fragments. | ||
| 350 | */ | ||
| 351 | long dtls1_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok) | ||
| 352 | { | ||
| 353 | int i, al; | ||
| 354 | struct hm_header_st *msg_hdr; | ||
| 355 | |||
| 356 | /* s3->tmp is used to store messages that are unexpected, caused | ||
| 357 | * by the absence of an optional handshake message */ | ||
| 358 | if (s->s3->tmp.reuse_message) | ||
| 359 | { | ||
| 360 | s->s3->tmp.reuse_message=0; | ||
| 361 | if ((mt >= 0) && (s->s3->tmp.message_type != mt)) | ||
| 362 | { | ||
| 363 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
| 364 | SSLerr(SSL_F_DTLS1_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE); | ||
| 365 | goto f_err; | ||
| 366 | } | ||
| 367 | *ok=1; | ||
| 368 | s->init_msg = s->init_buf->data + DTLS1_HM_HEADER_LENGTH; | ||
| 369 | s->init_num = (int)s->s3->tmp.message_size; | ||
| 370 | return s->init_num; | ||
| 371 | } | ||
| 372 | |||
| 373 | msg_hdr = &s->d1->r_msg_hdr; | ||
| 374 | do | ||
| 375 | { | ||
| 376 | if ( msg_hdr->frag_off == 0) | ||
| 377 | { | ||
| 378 | /* s->d1->r_message_header.msg_len = 0; */ | ||
| 379 | memset(msg_hdr, 0x00, sizeof(struct hm_header_st)); | ||
| 380 | } | ||
| 381 | |||
| 382 | i = dtls1_get_message_fragment(s, st1, stn, max, ok); | ||
| 383 | if ( i == DTLS1_HM_BAD_FRAGMENT || | ||
| 384 | i == DTLS1_HM_FRAGMENT_RETRY) /* bad fragment received */ | ||
| 385 | continue; | ||
| 386 | else if ( i <= 0 && !*ok) | ||
| 387 | return i; | ||
| 388 | |||
| 389 | /* Note that s->init_sum is used as a counter summing | ||
| 390 | * up fragments' lengths: as soon as they sum up to | ||
| 391 | * handshake packet length, we assume we have got all | ||
| 392 | * the fragments. Overlapping fragments would cause | ||
| 393 | * premature termination, so we don't expect overlaps. | ||
| 394 | * Well, handling overlaps would require something more | ||
| 395 | * drastic. Indeed, as it is now there is no way to | ||
| 396 | * tell if out-of-order fragment from the middle was | ||
| 397 | * the last. '>=' is the best/least we can do to control | ||
| 398 | * the potential damage caused by malformed overlaps. */ | ||
| 399 | if ((unsigned int)s->init_num >= msg_hdr->msg_len) | ||
| 400 | { | ||
| 401 | unsigned char *p = (unsigned char *)s->init_buf->data; | ||
| 402 | unsigned long msg_len = msg_hdr->msg_len; | ||
| 403 | |||
| 404 | /* reconstruct message header as if it was | ||
| 405 | * sent in single fragment */ | ||
| 406 | *(p++) = msg_hdr->type; | ||
| 407 | l2n3(msg_len,p); | ||
| 408 | s2n (msg_hdr->seq,p); | ||
| 409 | l2n3(0,p); | ||
| 410 | l2n3(msg_len,p); | ||
| 411 | if (s->client_version != DTLS1_BAD_VER) | ||
| 412 | p -= DTLS1_HM_HEADER_LENGTH, | ||
| 413 | msg_len += DTLS1_HM_HEADER_LENGTH; | ||
| 414 | |||
| 415 | ssl3_finish_mac(s, p, msg_len); | ||
| 416 | if (s->msg_callback) | ||
| 417 | s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE, | ||
| 418 | p, msg_len, | ||
| 419 | s, s->msg_callback_arg); | ||
| 420 | |||
| 421 | memset(msg_hdr, 0x00, sizeof(struct hm_header_st)); | ||
| 422 | |||
| 423 | s->d1->handshake_read_seq++; | ||
| 424 | /* we just read a handshake message from the other side: | ||
| 425 | * this means that we don't need to retransmit of the | ||
| 426 | * buffered messages. | ||
| 427 | * XDTLS: may be able clear out this | ||
| 428 | * buffer a little sooner (i.e if an out-of-order | ||
| 429 | * handshake message/record is received at the record | ||
| 430 | * layer. | ||
| 431 | * XDTLS: exception is that the server needs to | ||
| 432 | * know that change cipher spec and finished messages | ||
| 433 | * have been received by the client before clearing this | ||
| 434 | * buffer. this can simply be done by waiting for the | ||
| 435 | * first data segment, but is there a better way? */ | ||
| 436 | dtls1_clear_record_buffer(s); | ||
| 437 | |||
| 438 | s->init_msg = s->init_buf->data + DTLS1_HM_HEADER_LENGTH; | ||
| 439 | return s->init_num; | ||
| 440 | } | ||
| 441 | else | ||
| 442 | msg_hdr->frag_off = i; | ||
| 443 | } while(1) ; | ||
| 444 | |||
| 445 | f_err: | ||
| 446 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
| 447 | *ok = 0; | ||
| 448 | return -1; | ||
| 449 | } | ||
| 450 | |||
| 451 | |||
| 452 | static int dtls1_preprocess_fragment(SSL *s,struct hm_header_st *msg_hdr,int max) | ||
| 453 | { | ||
| 454 | size_t frag_off,frag_len,msg_len; | ||
| 455 | |||
| 456 | msg_len = msg_hdr->msg_len; | ||
| 457 | frag_off = msg_hdr->frag_off; | ||
| 458 | frag_len = msg_hdr->frag_len; | ||
| 459 | |||
| 460 | /* sanity checking */ | ||
| 461 | if ( (frag_off+frag_len) > msg_len) | ||
| 462 | { | ||
| 463 | SSLerr(SSL_F_DTLS1_PREPROCESS_FRAGMENT,SSL_R_EXCESSIVE_MESSAGE_SIZE); | ||
| 464 | return SSL_AD_ILLEGAL_PARAMETER; | ||
| 465 | } | ||
| 466 | |||
| 467 | if ( (frag_off+frag_len) > (unsigned long)max) | ||
| 468 | { | ||
| 469 | SSLerr(SSL_F_DTLS1_PREPROCESS_FRAGMENT,SSL_R_EXCESSIVE_MESSAGE_SIZE); | ||
| 470 | return SSL_AD_ILLEGAL_PARAMETER; | ||
| 471 | } | ||
| 472 | |||
| 473 | if ( s->d1->r_msg_hdr.frag_off == 0) /* first fragment */ | ||
| 474 | { | ||
| 475 | /* msg_len is limited to 2^24, but is effectively checked | ||
| 476 | * against max above */ | ||
| 477 | if (!BUF_MEM_grow_clean(s->init_buf,(int)msg_len+DTLS1_HM_HEADER_LENGTH)) | ||
| 478 | { | ||
| 479 | SSLerr(SSL_F_DTLS1_PREPROCESS_FRAGMENT,ERR_R_BUF_LIB); | ||
| 480 | return SSL_AD_INTERNAL_ERROR; | ||
| 481 | } | ||
| 482 | |||
| 483 | s->s3->tmp.message_size = msg_len; | ||
| 484 | s->d1->r_msg_hdr.msg_len = msg_len; | ||
| 485 | s->s3->tmp.message_type = msg_hdr->type; | ||
| 486 | s->d1->r_msg_hdr.type = msg_hdr->type; | ||
| 487 | s->d1->r_msg_hdr.seq = msg_hdr->seq; | ||
| 488 | } | ||
| 489 | else if (msg_len != s->d1->r_msg_hdr.msg_len) | ||
| 490 | { | ||
| 491 | /* They must be playing with us! BTW, failure to enforce | ||
| 492 | * upper limit would open possibility for buffer overrun. */ | ||
| 493 | SSLerr(SSL_F_DTLS1_PREPROCESS_FRAGMENT,SSL_R_EXCESSIVE_MESSAGE_SIZE); | ||
| 494 | return SSL_AD_ILLEGAL_PARAMETER; | ||
| 495 | } | ||
| 496 | |||
| 497 | return 0; /* no error */ | ||
| 498 | } | ||
| 499 | |||
| 500 | |||
| 501 | static int | ||
| 502 | dtls1_retrieve_buffered_fragment(SSL *s, long max, int *ok) | ||
| 503 | { | ||
| 504 | /* (0) check whether the desired fragment is available | ||
| 505 | * if so: | ||
| 506 | * (1) copy over the fragment to s->init_buf->data[] | ||
| 507 | * (2) update s->init_num | ||
| 508 | */ | ||
| 509 | pitem *item; | ||
| 510 | hm_fragment *frag; | ||
| 511 | int al; | ||
| 512 | |||
| 513 | *ok = 0; | ||
| 514 | item = pqueue_peek(s->d1->buffered_messages); | ||
| 515 | if ( item == NULL) | ||
| 516 | return 0; | ||
| 517 | |||
| 518 | frag = (hm_fragment *)item->data; | ||
| 519 | |||
| 520 | if ( s->d1->handshake_read_seq == frag->msg_header.seq) | ||
| 521 | { | ||
| 522 | pqueue_pop(s->d1->buffered_messages); | ||
| 523 | |||
| 524 | al=dtls1_preprocess_fragment(s,&frag->msg_header,max); | ||
| 525 | |||
| 526 | if (al==0) /* no alert */ | ||
| 527 | { | ||
| 528 | unsigned char *p = (unsigned char *)s->init_buf->data+DTLS1_HM_HEADER_LENGTH; | ||
| 529 | memcpy(&p[frag->msg_header.frag_off], | ||
| 530 | frag->fragment,frag->msg_header.frag_len); | ||
| 531 | } | ||
| 532 | |||
| 533 | dtls1_hm_fragment_free(frag); | ||
| 534 | pitem_free(item); | ||
| 535 | |||
| 536 | if (al==0) | ||
| 537 | { | ||
| 538 | *ok = 1; | ||
| 539 | return frag->msg_header.frag_len; | ||
| 540 | } | ||
| 541 | |||
| 542 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
| 543 | s->init_num = 0; | ||
| 544 | *ok = 0; | ||
| 545 | return -1; | ||
| 546 | } | ||
| 547 | else | ||
| 548 | return 0; | ||
| 549 | } | ||
| 550 | |||
| 551 | |||
| 552 | static int | ||
| 553 | dtls1_process_out_of_seq_message(SSL *s, struct hm_header_st* msg_hdr, int *ok) | ||
| 554 | { | ||
| 555 | int i=-1; | ||
| 556 | hm_fragment *frag = NULL; | ||
| 557 | pitem *item = NULL; | ||
| 558 | PQ_64BIT seq64; | ||
| 559 | unsigned long frag_len = msg_hdr->frag_len; | ||
| 560 | |||
| 561 | if ((msg_hdr->frag_off+frag_len) > msg_hdr->msg_len) | ||
| 562 | goto err; | ||
| 563 | |||
| 564 | if (msg_hdr->seq <= s->d1->handshake_read_seq) | ||
| 565 | { | ||
| 566 | unsigned char devnull [256]; | ||
| 567 | |||
| 568 | while (frag_len) | ||
| 569 | { | ||
| 570 | i = s->method->ssl_read_bytes(s,SSL3_RT_HANDSHAKE, | ||
| 571 | devnull, | ||
| 572 | frag_len>sizeof(devnull)?sizeof(devnull):frag_len,0); | ||
| 573 | if (i<=0) goto err; | ||
| 574 | frag_len -= i; | ||
| 575 | } | ||
| 576 | } | ||
| 577 | |||
| 578 | frag = dtls1_hm_fragment_new(frag_len); | ||
| 579 | if ( frag == NULL) | ||
| 580 | goto err; | ||
| 581 | |||
| 582 | memcpy(&(frag->msg_header), msg_hdr, sizeof(*msg_hdr)); | ||
| 583 | |||
| 584 | if (frag_len) | ||
| 585 | { | ||
| 586 | /* read the body of the fragment (header has already been read */ | ||
| 587 | i = s->method->ssl_read_bytes(s,SSL3_RT_HANDSHAKE, | ||
| 588 | frag->fragment,frag_len,0); | ||
| 589 | if (i<=0 || (unsigned long)i!=frag_len) | ||
| 590 | goto err; | ||
| 591 | } | ||
| 592 | |||
| 593 | pq_64bit_init(&seq64); | ||
| 594 | pq_64bit_assign_word(&seq64, msg_hdr->seq); | ||
| 595 | |||
| 596 | item = pitem_new(seq64, frag); | ||
| 597 | pq_64bit_free(&seq64); | ||
| 598 | if ( item == NULL) | ||
| 599 | goto err; | ||
| 600 | |||
| 601 | pqueue_insert(s->d1->buffered_messages, item); | ||
| 602 | return DTLS1_HM_FRAGMENT_RETRY; | ||
| 603 | |||
| 604 | err: | ||
| 605 | if ( frag != NULL) dtls1_hm_fragment_free(frag); | ||
| 606 | if ( item != NULL) OPENSSL_free(item); | ||
| 607 | *ok = 0; | ||
| 608 | return i; | ||
| 609 | } | ||
| 610 | |||
| 611 | |||
| 612 | static long | ||
| 613 | dtls1_get_message_fragment(SSL *s, int st1, int stn, long max, int *ok) | ||
| 614 | { | ||
| 615 | unsigned char wire[DTLS1_HM_HEADER_LENGTH]; | ||
| 616 | unsigned long l, frag_off, frag_len; | ||
| 617 | int i,al; | ||
| 618 | struct hm_header_st msg_hdr; | ||
| 619 | |||
| 620 | /* see if we have the required fragment already */ | ||
| 621 | if ((frag_len = dtls1_retrieve_buffered_fragment(s,max,ok)) || *ok) | ||
| 622 | { | ||
| 623 | if (*ok) s->init_num += frag_len; | ||
| 624 | return frag_len; | ||
| 625 | } | ||
| 626 | |||
| 627 | /* read handshake message header */ | ||
| 628 | i=s->method->ssl_read_bytes(s,SSL3_RT_HANDSHAKE,wire, | ||
| 629 | DTLS1_HM_HEADER_LENGTH, 0); | ||
| 630 | if (i <= 0) /* nbio, or an error */ | ||
| 631 | { | ||
| 632 | s->rwstate=SSL_READING; | ||
| 633 | *ok = 0; | ||
| 634 | return i; | ||
| 635 | } | ||
| 636 | OPENSSL_assert(i == DTLS1_HM_HEADER_LENGTH); | ||
| 637 | |||
| 638 | /* parse the message fragment header */ | ||
| 639 | dtls1_get_message_header(wire, &msg_hdr); | ||
| 640 | |||
| 641 | /* | ||
| 642 | * if this is a future (or stale) message it gets buffered | ||
| 643 | * (or dropped)--no further processing at this time | ||
| 644 | */ | ||
| 645 | if ( msg_hdr.seq != s->d1->handshake_read_seq) | ||
| 646 | return dtls1_process_out_of_seq_message(s, &msg_hdr, ok); | ||
| 647 | |||
| 648 | l = msg_hdr.msg_len; | ||
| 649 | frag_off = msg_hdr.frag_off; | ||
| 650 | frag_len = msg_hdr.frag_len; | ||
| 651 | |||
| 652 | if (!s->server && s->d1->r_msg_hdr.frag_off == 0 && | ||
| 653 | wire[0] == SSL3_MT_HELLO_REQUEST) | ||
| 654 | { | ||
| 655 | /* The server may always send 'Hello Request' messages -- | ||
| 656 | * we are doing a handshake anyway now, so ignore them | ||
| 657 | * if their format is correct. Does not count for | ||
| 658 | * 'Finished' MAC. */ | ||
| 659 | if (wire[1] == 0 && wire[2] == 0 && wire[3] == 0) | ||
| 660 | { | ||
| 661 | if (s->msg_callback) | ||
| 662 | s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE, | ||
| 663 | wire, DTLS1_HM_HEADER_LENGTH, s, | ||
| 664 | s->msg_callback_arg); | ||
| 665 | |||
| 666 | s->init_num = 0; | ||
| 667 | return dtls1_get_message_fragment(s, st1, stn, | ||
| 668 | max, ok); | ||
| 669 | } | ||
| 670 | else /* Incorrectly formated Hello request */ | ||
| 671 | { | ||
| 672 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
| 673 | SSLerr(SSL_F_DTLS1_GET_MESSAGE_FRAGMENT,SSL_R_UNEXPECTED_MESSAGE); | ||
| 674 | goto f_err; | ||
| 675 | } | ||
| 676 | } | ||
| 677 | |||
| 678 | if ((al=dtls1_preprocess_fragment(s,&msg_hdr,max))) | ||
| 679 | goto f_err; | ||
| 680 | |||
| 681 | /* XDTLS: ressurect this when restart is in place */ | ||
| 682 | s->state=stn; | ||
| 683 | |||
| 684 | if ( frag_len > 0) | ||
| 685 | { | ||
| 686 | unsigned char *p=(unsigned char *)s->init_buf->data+DTLS1_HM_HEADER_LENGTH; | ||
| 687 | |||
| 688 | i=s->method->ssl_read_bytes(s,SSL3_RT_HANDSHAKE, | ||
| 689 | &p[frag_off],frag_len,0); | ||
| 690 | /* XDTLS: fix this--message fragments cannot span multiple packets */ | ||
| 691 | if (i <= 0) | ||
| 692 | { | ||
| 693 | s->rwstate=SSL_READING; | ||
| 694 | *ok = 0; | ||
| 695 | return i; | ||
| 696 | } | ||
| 697 | } | ||
| 698 | else | ||
| 699 | i = 0; | ||
| 700 | |||
| 701 | /* XDTLS: an incorrectly formatted fragment should cause the | ||
| 702 | * handshake to fail */ | ||
| 703 | OPENSSL_assert(i == (int)frag_len); | ||
| 704 | |||
| 705 | *ok = 1; | ||
| 706 | |||
| 707 | /* Note that s->init_num is *not* used as current offset in | ||
| 708 | * s->init_buf->data, but as a counter summing up fragments' | ||
| 709 | * lengths: as soon as they sum up to handshake packet | ||
| 710 | * length, we assume we have got all the fragments. */ | ||
| 711 | s->init_num += frag_len; | ||
| 712 | return frag_len; | ||
| 713 | |||
| 714 | f_err: | ||
| 715 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
| 716 | s->init_num = 0; | ||
| 717 | |||
| 718 | *ok=0; | ||
| 719 | return(-1); | ||
| 720 | } | ||
| 721 | |||
| 722 | int dtls1_send_finished(SSL *s, int a, int b, const char *sender, int slen) | ||
| 723 | { | ||
| 724 | unsigned char *p,*d; | ||
| 725 | int i; | ||
| 726 | unsigned long l; | ||
| 727 | |||
| 728 | if (s->state == a) | ||
| 729 | { | ||
| 730 | d=(unsigned char *)s->init_buf->data; | ||
| 731 | p= &(d[DTLS1_HM_HEADER_LENGTH]); | ||
| 732 | |||
| 733 | i=s->method->ssl3_enc->final_finish_mac(s, | ||
| 734 | &(s->s3->finish_dgst1), | ||
| 735 | &(s->s3->finish_dgst2), | ||
| 736 | sender,slen,s->s3->tmp.finish_md); | ||
| 737 | s->s3->tmp.finish_md_len = i; | ||
| 738 | memcpy(p, s->s3->tmp.finish_md, i); | ||
| 739 | p+=i; | ||
| 740 | l=i; | ||
| 741 | |||
| 742 | #ifdef OPENSSL_SYS_WIN16 | ||
| 743 | /* MSVC 1.5 does not clear the top bytes of the word unless | ||
| 744 | * I do this. | ||
| 745 | */ | ||
| 746 | l&=0xffff; | ||
| 747 | #endif | ||
| 748 | |||
| 749 | d = dtls1_set_message_header(s, d, SSL3_MT_FINISHED, l, 0, l); | ||
| 750 | s->init_num=(int)l+DTLS1_HM_HEADER_LENGTH; | ||
| 751 | s->init_off=0; | ||
| 752 | |||
| 753 | /* buffer the message to handle re-xmits */ | ||
| 754 | dtls1_buffer_message(s, 0); | ||
| 755 | |||
| 756 | s->state=b; | ||
| 757 | } | ||
| 758 | |||
| 759 | /* SSL3_ST_SEND_xxxxxx_HELLO_B */ | ||
| 760 | return(dtls1_do_write(s,SSL3_RT_HANDSHAKE)); | ||
| 761 | } | ||
| 762 | |||
| 763 | /* for these 2 messages, we need to | ||
| 764 | * ssl->enc_read_ctx re-init | ||
| 765 | * ssl->s3->read_sequence zero | ||
| 766 | * ssl->s3->read_mac_secret re-init | ||
| 767 | * ssl->session->read_sym_enc assign | ||
| 768 | * ssl->session->read_compression assign | ||
| 769 | * ssl->session->read_hash assign | ||
| 770 | */ | ||
| 771 | int dtls1_send_change_cipher_spec(SSL *s, int a, int b) | ||
| 772 | { | ||
| 773 | unsigned char *p; | ||
| 774 | |||
| 775 | if (s->state == a) | ||
| 776 | { | ||
| 777 | p=(unsigned char *)s->init_buf->data; | ||
| 778 | *p++=SSL3_MT_CCS; | ||
| 779 | s->d1->handshake_write_seq = s->d1->next_handshake_write_seq; | ||
| 780 | s->init_num=DTLS1_CCS_HEADER_LENGTH; | ||
| 781 | |||
| 782 | if (s->client_version == DTLS1_BAD_VER) | ||
| 783 | { | ||
| 784 | s->d1->next_handshake_write_seq++; | ||
| 785 | s2n(s->d1->handshake_write_seq,p); | ||
| 786 | s->init_num+=2; | ||
| 787 | } | ||
| 788 | |||
| 789 | s->init_off=0; | ||
| 790 | |||
| 791 | dtls1_set_message_header_int(s, SSL3_MT_CCS, 0, | ||
| 792 | s->d1->handshake_write_seq, 0, 0); | ||
| 793 | |||
| 794 | /* buffer the message to handle re-xmits */ | ||
| 795 | dtls1_buffer_message(s, 1); | ||
| 796 | |||
| 797 | s->state=b; | ||
| 798 | } | ||
| 799 | |||
| 800 | /* SSL3_ST_CW_CHANGE_B */ | ||
| 801 | return(dtls1_do_write(s,SSL3_RT_CHANGE_CIPHER_SPEC)); | ||
| 802 | } | ||
| 803 | |||
| 804 | unsigned long dtls1_output_cert_chain(SSL *s, X509 *x) | ||
| 805 | { | ||
| 806 | unsigned char *p; | ||
| 807 | int n,i; | ||
| 808 | unsigned long l= 3 + DTLS1_HM_HEADER_LENGTH; | ||
| 809 | BUF_MEM *buf; | ||
| 810 | X509_STORE_CTX xs_ctx; | ||
| 811 | X509_OBJECT obj; | ||
| 812 | |||
| 813 | /* TLSv1 sends a chain with nothing in it, instead of an alert */ | ||
| 814 | buf=s->init_buf; | ||
| 815 | if (!BUF_MEM_grow_clean(buf,10)) | ||
| 816 | { | ||
| 817 | SSLerr(SSL_F_DTLS1_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB); | ||
| 818 | return(0); | ||
| 819 | } | ||
| 820 | if (x != NULL) | ||
| 821 | { | ||
| 822 | if(!X509_STORE_CTX_init(&xs_ctx,s->ctx->cert_store,NULL,NULL)) | ||
| 823 | { | ||
| 824 | SSLerr(SSL_F_DTLS1_OUTPUT_CERT_CHAIN,ERR_R_X509_LIB); | ||
| 825 | return(0); | ||
| 826 | } | ||
| 827 | |||
| 828 | for (;;) | ||
| 829 | { | ||
| 830 | n=i2d_X509(x,NULL); | ||
| 831 | if (!BUF_MEM_grow_clean(buf,(int)(n+l+3))) | ||
| 832 | { | ||
| 833 | SSLerr(SSL_F_DTLS1_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB); | ||
| 834 | return(0); | ||
| 835 | } | ||
| 836 | p=(unsigned char *)&(buf->data[l]); | ||
| 837 | l2n3(n,p); | ||
| 838 | i2d_X509(x,&p); | ||
| 839 | l+=n+3; | ||
| 840 | if (X509_NAME_cmp(X509_get_subject_name(x), | ||
| 841 | X509_get_issuer_name(x)) == 0) break; | ||
| 842 | |||
| 843 | i=X509_STORE_get_by_subject(&xs_ctx,X509_LU_X509, | ||
| 844 | X509_get_issuer_name(x),&obj); | ||
| 845 | if (i <= 0) break; | ||
| 846 | x=obj.data.x509; | ||
| 847 | /* Count is one too high since the X509_STORE_get uped the | ||
| 848 | * ref count */ | ||
| 849 | X509_free(x); | ||
| 850 | } | ||
| 851 | |||
| 852 | X509_STORE_CTX_cleanup(&xs_ctx); | ||
| 853 | } | ||
| 854 | |||
| 855 | /* Thawte special :-) */ | ||
| 856 | if (s->ctx->extra_certs != NULL) | ||
| 857 | for (i=0; i<sk_X509_num(s->ctx->extra_certs); i++) | ||
| 858 | { | ||
| 859 | x=sk_X509_value(s->ctx->extra_certs,i); | ||
| 860 | n=i2d_X509(x,NULL); | ||
| 861 | if (!BUF_MEM_grow_clean(buf,(int)(n+l+3))) | ||
| 862 | { | ||
| 863 | SSLerr(SSL_F_DTLS1_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB); | ||
| 864 | return(0); | ||
| 865 | } | ||
| 866 | p=(unsigned char *)&(buf->data[l]); | ||
| 867 | l2n3(n,p); | ||
| 868 | i2d_X509(x,&p); | ||
| 869 | l+=n+3; | ||
| 870 | } | ||
| 871 | |||
| 872 | l-= (3 + DTLS1_HM_HEADER_LENGTH); | ||
| 873 | |||
| 874 | p=(unsigned char *)&(buf->data[DTLS1_HM_HEADER_LENGTH]); | ||
| 875 | l2n3(l,p); | ||
| 876 | l+=3; | ||
| 877 | p=(unsigned char *)&(buf->data[0]); | ||
| 878 | p = dtls1_set_message_header(s, p, SSL3_MT_CERTIFICATE, l, 0, l); | ||
| 879 | |||
| 880 | l+=DTLS1_HM_HEADER_LENGTH; | ||
| 881 | return(l); | ||
| 882 | } | ||
| 883 | |||
| 884 | int dtls1_read_failed(SSL *s, int code) | ||
| 885 | { | ||
| 886 | DTLS1_STATE *state; | ||
| 887 | BIO *bio; | ||
| 888 | int send_alert = 0; | ||
| 889 | |||
| 890 | if ( code > 0) | ||
| 891 | { | ||
| 892 | fprintf( stderr, "invalid state reached %s:%d", __FILE__, __LINE__); | ||
| 893 | return 1; | ||
| 894 | } | ||
| 895 | |||
| 896 | bio = SSL_get_rbio(s); | ||
| 897 | if ( ! BIO_dgram_recv_timedout(bio)) | ||
| 898 | { | ||
| 899 | /* not a timeout, none of our business, | ||
| 900 | let higher layers handle this. in fact it's probably an error */ | ||
| 901 | return code; | ||
| 902 | } | ||
| 903 | |||
| 904 | if ( ! SSL_in_init(s)) /* done, no need to send a retransmit */ | ||
| 905 | { | ||
| 906 | BIO_set_flags(SSL_get_rbio(s), BIO_FLAGS_READ); | ||
| 907 | return code; | ||
| 908 | } | ||
| 909 | |||
| 910 | state = s->d1; | ||
| 911 | state->timeout.num_alerts++; | ||
| 912 | if ( state->timeout.num_alerts > DTLS1_TMO_ALERT_COUNT) | ||
| 913 | { | ||
| 914 | /* fail the connection, enough alerts have been sent */ | ||
| 915 | SSLerr(SSL_F_DTLS1_READ_FAILED,SSL_R_READ_TIMEOUT_EXPIRED); | ||
| 916 | return 0; | ||
| 917 | } | ||
| 918 | |||
| 919 | state->timeout.read_timeouts++; | ||
| 920 | if ( state->timeout.read_timeouts > DTLS1_TMO_READ_COUNT) | ||
| 921 | { | ||
| 922 | send_alert = 1; | ||
| 923 | state->timeout.read_timeouts = 1; | ||
| 924 | } | ||
| 925 | |||
| 926 | |||
| 927 | #if 0 /* for now, each alert contains only one record number */ | ||
| 928 | item = pqueue_peek(state->rcvd_records); | ||
| 929 | if ( item ) | ||
| 930 | { | ||
| 931 | /* send an alert immediately for all the missing records */ | ||
| 932 | } | ||
| 933 | else | ||
| 934 | #endif | ||
| 935 | |||
| 936 | #if 0 /* no more alert sending, just retransmit the last set of messages */ | ||
| 937 | if ( send_alert) | ||
| 938 | ssl3_send_alert(s,SSL3_AL_WARNING, | ||
| 939 | DTLS1_AD_MISSING_HANDSHAKE_MESSAGE); | ||
| 940 | #endif | ||
| 941 | |||
| 942 | return dtls1_retransmit_buffered_messages(s) ; | ||
| 943 | } | ||
| 944 | |||
| 945 | |||
| 946 | static int | ||
| 947 | dtls1_retransmit_buffered_messages(SSL *s) | ||
| 948 | { | ||
| 949 | pqueue sent = s->d1->sent_messages; | ||
| 950 | piterator iter; | ||
| 951 | pitem *item; | ||
| 952 | hm_fragment *frag; | ||
| 953 | int found = 0; | ||
| 954 | |||
| 955 | iter = pqueue_iterator(sent); | ||
| 956 | |||
| 957 | for ( item = pqueue_next(&iter); item != NULL; item = pqueue_next(&iter)) | ||
| 958 | { | ||
| 959 | frag = (hm_fragment *)item->data; | ||
| 960 | if ( dtls1_retransmit_message(s, frag->msg_header.seq, 0, &found) <= 0 && | ||
| 961 | found) | ||
| 962 | { | ||
| 963 | fprintf(stderr, "dtls1_retransmit_message() failed\n"); | ||
| 964 | return -1; | ||
| 965 | } | ||
| 966 | } | ||
| 967 | |||
| 968 | return 1; | ||
| 969 | } | ||
| 970 | |||
| 971 | int | ||
| 972 | dtls1_buffer_message(SSL *s, int is_ccs) | ||
| 973 | { | ||
| 974 | pitem *item; | ||
| 975 | hm_fragment *frag; | ||
| 976 | PQ_64BIT seq64; | ||
| 977 | unsigned int epoch = s->d1->w_epoch; | ||
| 978 | |||
| 979 | /* this function is called immediately after a message has | ||
| 980 | * been serialized */ | ||
| 981 | OPENSSL_assert(s->init_off == 0); | ||
| 982 | |||
| 983 | frag = dtls1_hm_fragment_new(s->init_num); | ||
| 984 | |||
| 985 | memcpy(frag->fragment, s->init_buf->data, s->init_num); | ||
| 986 | |||
| 987 | if ( is_ccs) | ||
| 988 | { | ||
| 989 | OPENSSL_assert(s->d1->w_msg_hdr.msg_len + | ||
| 990 | DTLS1_CCS_HEADER_LENGTH <= (unsigned int)s->init_num); | ||
| 991 | epoch++; | ||
| 992 | } | ||
| 993 | else | ||
| 994 | { | ||
| 995 | OPENSSL_assert(s->d1->w_msg_hdr.msg_len + | ||
| 996 | DTLS1_HM_HEADER_LENGTH == (unsigned int)s->init_num); | ||
| 997 | } | ||
| 998 | |||
| 999 | frag->msg_header.msg_len = s->d1->w_msg_hdr.msg_len; | ||
| 1000 | frag->msg_header.seq = s->d1->w_msg_hdr.seq; | ||
| 1001 | frag->msg_header.type = s->d1->w_msg_hdr.type; | ||
| 1002 | frag->msg_header.frag_off = 0; | ||
| 1003 | frag->msg_header.frag_len = s->d1->w_msg_hdr.msg_len; | ||
| 1004 | frag->msg_header.is_ccs = is_ccs; | ||
| 1005 | |||
| 1006 | pq_64bit_init(&seq64); | ||
| 1007 | pq_64bit_assign_word(&seq64, epoch<<16 | frag->msg_header.seq); | ||
| 1008 | |||
| 1009 | item = pitem_new(seq64, frag); | ||
| 1010 | pq_64bit_free(&seq64); | ||
| 1011 | if ( item == NULL) | ||
| 1012 | { | ||
| 1013 | dtls1_hm_fragment_free(frag); | ||
| 1014 | return 0; | ||
| 1015 | } | ||
| 1016 | |||
| 1017 | #if 0 | ||
| 1018 | fprintf( stderr, "buffered messge: \ttype = %xx\n", msg_buf->type); | ||
| 1019 | fprintf( stderr, "\t\t\t\t\tlen = %d\n", msg_buf->len); | ||
| 1020 | fprintf( stderr, "\t\t\t\t\tseq_num = %d\n", msg_buf->seq_num); | ||
| 1021 | #endif | ||
| 1022 | |||
| 1023 | pqueue_insert(s->d1->sent_messages, item); | ||
| 1024 | return 1; | ||
| 1025 | } | ||
| 1026 | |||
| 1027 | int | ||
| 1028 | dtls1_retransmit_message(SSL *s, unsigned short seq, unsigned long frag_off, | ||
| 1029 | int *found) | ||
| 1030 | { | ||
| 1031 | int ret; | ||
| 1032 | /* XDTLS: for now assuming that read/writes are blocking */ | ||
| 1033 | pitem *item; | ||
| 1034 | hm_fragment *frag ; | ||
| 1035 | unsigned long header_length; | ||
| 1036 | PQ_64BIT seq64; | ||
| 1037 | |||
| 1038 | /* | ||
| 1039 | OPENSSL_assert(s->init_num == 0); | ||
| 1040 | OPENSSL_assert(s->init_off == 0); | ||
| 1041 | */ | ||
| 1042 | |||
| 1043 | /* XDTLS: the requested message ought to be found, otherwise error */ | ||
| 1044 | pq_64bit_init(&seq64); | ||
| 1045 | pq_64bit_assign_word(&seq64, seq); | ||
| 1046 | |||
| 1047 | item = pqueue_find(s->d1->sent_messages, seq64); | ||
| 1048 | pq_64bit_free(&seq64); | ||
| 1049 | if ( item == NULL) | ||
| 1050 | { | ||
| 1051 | fprintf(stderr, "retransmit: message %d non-existant\n", seq); | ||
| 1052 | *found = 0; | ||
| 1053 | return 0; | ||
| 1054 | } | ||
| 1055 | |||
| 1056 | *found = 1; | ||
| 1057 | frag = (hm_fragment *)item->data; | ||
| 1058 | |||
| 1059 | if ( frag->msg_header.is_ccs) | ||
| 1060 | header_length = DTLS1_CCS_HEADER_LENGTH; | ||
| 1061 | else | ||
| 1062 | header_length = DTLS1_HM_HEADER_LENGTH; | ||
| 1063 | |||
| 1064 | memcpy(s->init_buf->data, frag->fragment, | ||
| 1065 | frag->msg_header.msg_len + header_length); | ||
| 1066 | s->init_num = frag->msg_header.msg_len + header_length; | ||
| 1067 | |||
| 1068 | dtls1_set_message_header_int(s, frag->msg_header.type, | ||
| 1069 | frag->msg_header.msg_len, frag->msg_header.seq, 0, | ||
| 1070 | frag->msg_header.frag_len); | ||
| 1071 | |||
| 1072 | s->d1->retransmitting = 1; | ||
| 1073 | ret = dtls1_do_write(s, frag->msg_header.is_ccs ? | ||
| 1074 | SSL3_RT_CHANGE_CIPHER_SPEC : SSL3_RT_HANDSHAKE); | ||
| 1075 | s->d1->retransmitting = 0; | ||
| 1076 | |||
| 1077 | (void)BIO_flush(SSL_get_wbio(s)); | ||
| 1078 | return ret; | ||
| 1079 | } | ||
| 1080 | |||
| 1081 | /* call this function when the buffered messages are no longer needed */ | ||
| 1082 | void | ||
| 1083 | dtls1_clear_record_buffer(SSL *s) | ||
| 1084 | { | ||
| 1085 | pitem *item; | ||
| 1086 | |||
| 1087 | for(item = pqueue_pop(s->d1->sent_messages); | ||
| 1088 | item != NULL; item = pqueue_pop(s->d1->sent_messages)) | ||
| 1089 | { | ||
| 1090 | dtls1_hm_fragment_free((hm_fragment *)item->data); | ||
| 1091 | pitem_free(item); | ||
| 1092 | } | ||
| 1093 | } | ||
| 1094 | |||
| 1095 | |||
| 1096 | unsigned char * | ||
| 1097 | dtls1_set_message_header(SSL *s, unsigned char *p, unsigned char mt, | ||
| 1098 | unsigned long len, unsigned long frag_off, unsigned long frag_len) | ||
| 1099 | { | ||
| 1100 | if ( frag_off == 0) | ||
| 1101 | { | ||
| 1102 | s->d1->handshake_write_seq = s->d1->next_handshake_write_seq; | ||
| 1103 | s->d1->next_handshake_write_seq++; | ||
| 1104 | } | ||
| 1105 | |||
| 1106 | dtls1_set_message_header_int(s, mt, len, s->d1->handshake_write_seq, | ||
| 1107 | frag_off, frag_len); | ||
| 1108 | |||
| 1109 | return p += DTLS1_HM_HEADER_LENGTH; | ||
| 1110 | } | ||
| 1111 | |||
| 1112 | |||
| 1113 | /* don't actually do the writing, wait till the MTU has been retrieved */ | ||
| 1114 | static void | ||
| 1115 | dtls1_set_message_header_int(SSL *s, unsigned char mt, | ||
| 1116 | unsigned long len, unsigned short seq_num, unsigned long frag_off, | ||
| 1117 | unsigned long frag_len) | ||
| 1118 | { | ||
| 1119 | struct hm_header_st *msg_hdr = &s->d1->w_msg_hdr; | ||
| 1120 | |||
| 1121 | msg_hdr->type = mt; | ||
| 1122 | msg_hdr->msg_len = len; | ||
| 1123 | msg_hdr->seq = seq_num; | ||
| 1124 | msg_hdr->frag_off = frag_off; | ||
| 1125 | msg_hdr->frag_len = frag_len; | ||
| 1126 | } | ||
| 1127 | |||
| 1128 | static void | ||
| 1129 | dtls1_fix_message_header(SSL *s, unsigned long frag_off, | ||
| 1130 | unsigned long frag_len) | ||
| 1131 | { | ||
| 1132 | struct hm_header_st *msg_hdr = &s->d1->w_msg_hdr; | ||
| 1133 | |||
| 1134 | msg_hdr->frag_off = frag_off; | ||
| 1135 | msg_hdr->frag_len = frag_len; | ||
| 1136 | } | ||
| 1137 | |||
| 1138 | static unsigned char * | ||
| 1139 | dtls1_write_message_header(SSL *s, unsigned char *p) | ||
| 1140 | { | ||
| 1141 | struct hm_header_st *msg_hdr = &s->d1->w_msg_hdr; | ||
| 1142 | |||
| 1143 | *p++ = msg_hdr->type; | ||
| 1144 | l2n3(msg_hdr->msg_len, p); | ||
| 1145 | |||
| 1146 | s2n(msg_hdr->seq, p); | ||
| 1147 | l2n3(msg_hdr->frag_off, p); | ||
| 1148 | l2n3(msg_hdr->frag_len, p); | ||
| 1149 | |||
| 1150 | return p; | ||
| 1151 | } | ||
| 1152 | |||
| 1153 | static unsigned int | ||
| 1154 | dtls1_min_mtu(void) | ||
| 1155 | { | ||
| 1156 | return (g_probable_mtu[(sizeof(g_probable_mtu) / | ||
| 1157 | sizeof(g_probable_mtu[0])) - 1]); | ||
| 1158 | } | ||
| 1159 | |||
| 1160 | static unsigned int | ||
| 1161 | dtls1_guess_mtu(unsigned int curr_mtu) | ||
| 1162 | { | ||
| 1163 | size_t i; | ||
| 1164 | |||
| 1165 | if ( curr_mtu == 0 ) | ||
| 1166 | return g_probable_mtu[0] ; | ||
| 1167 | |||
| 1168 | for ( i = 0; i < sizeof(g_probable_mtu)/sizeof(g_probable_mtu[0]); i++) | ||
| 1169 | if ( curr_mtu > g_probable_mtu[i]) | ||
| 1170 | return g_probable_mtu[i]; | ||
| 1171 | |||
| 1172 | return curr_mtu; | ||
| 1173 | } | ||
| 1174 | |||
| 1175 | void | ||
| 1176 | dtls1_get_message_header(unsigned char *data, struct hm_header_st *msg_hdr) | ||
| 1177 | { | ||
| 1178 | memset(msg_hdr, 0x00, sizeof(struct hm_header_st)); | ||
| 1179 | msg_hdr->type = *(data++); | ||
| 1180 | n2l3(data, msg_hdr->msg_len); | ||
| 1181 | |||
| 1182 | n2s(data, msg_hdr->seq); | ||
| 1183 | n2l3(data, msg_hdr->frag_off); | ||
| 1184 | n2l3(data, msg_hdr->frag_len); | ||
| 1185 | } | ||
| 1186 | |||
| 1187 | void | ||
| 1188 | dtls1_get_ccs_header(unsigned char *data, struct ccs_header_st *ccs_hdr) | ||
| 1189 | { | ||
| 1190 | memset(ccs_hdr, 0x00, sizeof(struct ccs_header_st)); | ||
| 1191 | |||
| 1192 | ccs_hdr->type = *(data++); | ||
| 1193 | } | ||
diff --git a/src/lib/libssl/d1_clnt.c b/src/lib/libssl/d1_clnt.c new file mode 100644 index 0000000000..5e59dc845a --- /dev/null +++ b/src/lib/libssl/d1_clnt.c | |||
| @@ -0,0 +1,1156 @@ | |||
| 1 | /* ssl/d1_clnt.c */ | ||
| 2 | /* | ||
| 3 | * DTLS implementation written by Nagendra Modadugu | ||
| 4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. | ||
| 5 | */ | ||
| 6 | /* ==================================================================== | ||
| 7 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. | ||
| 8 | * | ||
| 9 | * Redistribution and use in source and binary forms, with or without | ||
| 10 | * modification, are permitted provided that the following conditions | ||
| 11 | * are met: | ||
| 12 | * | ||
| 13 | * 1. Redistributions of source code must retain the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer. | ||
| 15 | * | ||
| 16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 17 | * notice, this list of conditions and the following disclaimer in | ||
| 18 | * the documentation and/or other materials provided with the | ||
| 19 | * distribution. | ||
| 20 | * | ||
| 21 | * 3. All advertising materials mentioning features or use of this | ||
| 22 | * software must display the following acknowledgment: | ||
| 23 | * "This product includes software developed by the OpenSSL Project | ||
| 24 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 25 | * | ||
| 26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 27 | * endorse or promote products derived from this software without | ||
| 28 | * prior written permission. For written permission, please contact | ||
| 29 | * openssl-core@OpenSSL.org. | ||
| 30 | * | ||
| 31 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 32 | * nor may "OpenSSL" appear in their names without prior written | ||
| 33 | * permission of the OpenSSL Project. | ||
| 34 | * | ||
| 35 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 36 | * acknowledgment: | ||
| 37 | * "This product includes software developed by the OpenSSL Project | ||
| 38 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 39 | * | ||
| 40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 51 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 52 | * ==================================================================== | ||
| 53 | * | ||
| 54 | * This product includes cryptographic software written by Eric Young | ||
| 55 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 56 | * Hudson (tjh@cryptsoft.com). | ||
| 57 | * | ||
| 58 | */ | ||
| 59 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 60 | * All rights reserved. | ||
| 61 | * | ||
| 62 | * This package is an SSL implementation written | ||
| 63 | * by Eric Young (eay@cryptsoft.com). | ||
| 64 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 65 | * | ||
| 66 | * This library is free for commercial and non-commercial use as long as | ||
| 67 | * the following conditions are aheared to. The following conditions | ||
| 68 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 69 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 70 | * included with this distribution is covered by the same copyright terms | ||
| 71 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 72 | * | ||
| 73 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 74 | * the code are not to be removed. | ||
| 75 | * If this package is used in a product, Eric Young should be given attribution | ||
| 76 | * as the author of the parts of the library used. | ||
| 77 | * This can be in the form of a textual message at program startup or | ||
| 78 | * in documentation (online or textual) provided with the package. | ||
| 79 | * | ||
| 80 | * Redistribution and use in source and binary forms, with or without | ||
| 81 | * modification, are permitted provided that the following conditions | ||
| 82 | * are met: | ||
| 83 | * 1. Redistributions of source code must retain the copyright | ||
| 84 | * notice, this list of conditions and the following disclaimer. | ||
| 85 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 86 | * notice, this list of conditions and the following disclaimer in the | ||
| 87 | * documentation and/or other materials provided with the distribution. | ||
| 88 | * 3. All advertising materials mentioning features or use of this software | ||
| 89 | * must display the following acknowledgement: | ||
| 90 | * "This product includes cryptographic software written by | ||
| 91 | * Eric Young (eay@cryptsoft.com)" | ||
| 92 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 93 | * being used are not cryptographic related :-). | ||
| 94 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 95 | * the apps directory (application code) you must include an acknowledgement: | ||
| 96 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 97 | * | ||
| 98 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 99 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 100 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 101 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 102 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 103 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 104 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 105 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 106 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 107 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 108 | * SUCH DAMAGE. | ||
| 109 | * | ||
| 110 | * The licence and distribution terms for any publically available version or | ||
| 111 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 112 | * copied and put under another distribution licence | ||
| 113 | * [including the GNU Public Licence.] | ||
| 114 | */ | ||
| 115 | |||
| 116 | #include <stdio.h> | ||
| 117 | #include "ssl_locl.h" | ||
| 118 | #include "kssl_lcl.h" | ||
| 119 | #include <openssl/buffer.h> | ||
| 120 | #include <openssl/rand.h> | ||
| 121 | #include <openssl/objects.h> | ||
| 122 | #include <openssl/evp.h> | ||
| 123 | #include <openssl/md5.h> | ||
| 124 | #ifndef OPENSSL_NO_DH | ||
| 125 | #include <openssl/dh.h> | ||
| 126 | #endif | ||
| 127 | |||
| 128 | static SSL_METHOD *dtls1_get_client_method(int ver); | ||
| 129 | static int dtls1_get_hello_verify(SSL *s); | ||
| 130 | |||
| 131 | static SSL_METHOD *dtls1_get_client_method(int ver) | ||
| 132 | { | ||
| 133 | if (ver == DTLS1_VERSION) | ||
| 134 | return(DTLSv1_client_method()); | ||
| 135 | else | ||
| 136 | return(NULL); | ||
| 137 | } | ||
| 138 | |||
| 139 | IMPLEMENT_dtls1_meth_func(DTLSv1_client_method, | ||
| 140 | ssl_undefined_function, | ||
| 141 | dtls1_connect, | ||
| 142 | dtls1_get_client_method) | ||
| 143 | |||
| 144 | int dtls1_connect(SSL *s) | ||
| 145 | { | ||
| 146 | BUF_MEM *buf=NULL; | ||
| 147 | unsigned long Time=(unsigned long)time(NULL),l; | ||
| 148 | long num1; | ||
| 149 | void (*cb)(const SSL *ssl,int type,int val)=NULL; | ||
| 150 | int ret= -1; | ||
| 151 | int new_state,state,skip=0;; | ||
| 152 | |||
| 153 | RAND_add(&Time,sizeof(Time),0); | ||
| 154 | ERR_clear_error(); | ||
| 155 | clear_sys_error(); | ||
| 156 | |||
| 157 | if (s->info_callback != NULL) | ||
| 158 | cb=s->info_callback; | ||
| 159 | else if (s->ctx->info_callback != NULL) | ||
| 160 | cb=s->ctx->info_callback; | ||
| 161 | |||
| 162 | s->in_handshake++; | ||
| 163 | if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s); | ||
| 164 | |||
| 165 | for (;;) | ||
| 166 | { | ||
| 167 | state=s->state; | ||
| 168 | |||
| 169 | switch(s->state) | ||
| 170 | { | ||
| 171 | case SSL_ST_RENEGOTIATE: | ||
| 172 | s->new_session=1; | ||
| 173 | s->state=SSL_ST_CONNECT; | ||
| 174 | s->ctx->stats.sess_connect_renegotiate++; | ||
| 175 | /* break */ | ||
| 176 | case SSL_ST_BEFORE: | ||
| 177 | case SSL_ST_CONNECT: | ||
| 178 | case SSL_ST_BEFORE|SSL_ST_CONNECT: | ||
| 179 | case SSL_ST_OK|SSL_ST_CONNECT: | ||
| 180 | |||
| 181 | s->server=0; | ||
| 182 | if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1); | ||
| 183 | |||
| 184 | if ((s->version & 0xff00 ) != (DTLS1_VERSION & 0xff00)) | ||
| 185 | { | ||
| 186 | SSLerr(SSL_F_DTLS1_CONNECT, ERR_R_INTERNAL_ERROR); | ||
| 187 | ret = -1; | ||
| 188 | goto end; | ||
| 189 | } | ||
| 190 | |||
| 191 | /* s->version=SSL3_VERSION; */ | ||
| 192 | s->type=SSL_ST_CONNECT; | ||
| 193 | |||
| 194 | if (s->init_buf == NULL) | ||
| 195 | { | ||
| 196 | if ((buf=BUF_MEM_new()) == NULL) | ||
| 197 | { | ||
| 198 | ret= -1; | ||
| 199 | goto end; | ||
| 200 | } | ||
| 201 | if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH)) | ||
| 202 | { | ||
| 203 | ret= -1; | ||
| 204 | goto end; | ||
| 205 | } | ||
| 206 | s->init_buf=buf; | ||
| 207 | buf=NULL; | ||
| 208 | } | ||
| 209 | |||
| 210 | if (!ssl3_setup_buffers(s)) { ret= -1; goto end; } | ||
| 211 | |||
| 212 | /* setup buffing BIO */ | ||
| 213 | if (!ssl_init_wbio_buffer(s,0)) { ret= -1; goto end; } | ||
| 214 | |||
| 215 | /* don't push the buffering BIO quite yet */ | ||
| 216 | |||
| 217 | s->state=SSL3_ST_CW_CLNT_HELLO_A; | ||
| 218 | s->ctx->stats.sess_connect++; | ||
| 219 | s->init_num=0; | ||
| 220 | /* mark client_random uninitialized */ | ||
| 221 | memset(s->s3->client_random,0,sizeof(s->s3->client_random)); | ||
| 222 | break; | ||
| 223 | |||
| 224 | case SSL3_ST_CW_CLNT_HELLO_A: | ||
| 225 | case SSL3_ST_CW_CLNT_HELLO_B: | ||
| 226 | |||
| 227 | s->shutdown=0; | ||
| 228 | |||
| 229 | /* every DTLS ClientHello resets Finished MAC */ | ||
| 230 | ssl3_init_finished_mac(s); | ||
| 231 | |||
| 232 | ret=dtls1_client_hello(s); | ||
| 233 | if (ret <= 0) goto end; | ||
| 234 | |||
| 235 | if ( s->d1->send_cookie) | ||
| 236 | { | ||
| 237 | s->state=SSL3_ST_CW_FLUSH; | ||
| 238 | s->s3->tmp.next_state=SSL3_ST_CR_SRVR_HELLO_A; | ||
| 239 | } | ||
| 240 | else | ||
| 241 | s->state=SSL3_ST_CR_SRVR_HELLO_A; | ||
| 242 | |||
| 243 | s->init_num=0; | ||
| 244 | |||
| 245 | /* turn on buffering for the next lot of output */ | ||
| 246 | if (s->bbio != s->wbio) | ||
| 247 | s->wbio=BIO_push(s->bbio,s->wbio); | ||
| 248 | |||
| 249 | break; | ||
| 250 | |||
| 251 | case SSL3_ST_CR_SRVR_HELLO_A: | ||
| 252 | case SSL3_ST_CR_SRVR_HELLO_B: | ||
| 253 | ret=ssl3_get_server_hello(s); | ||
| 254 | if (ret <= 0) goto end; | ||
| 255 | else | ||
| 256 | { | ||
| 257 | if (s->hit) | ||
| 258 | s->state=SSL3_ST_CR_FINISHED_A; | ||
| 259 | else | ||
| 260 | s->state=DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A; | ||
| 261 | } | ||
| 262 | s->init_num=0; | ||
| 263 | break; | ||
| 264 | |||
| 265 | case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A: | ||
| 266 | case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B: | ||
| 267 | |||
| 268 | ret = dtls1_get_hello_verify(s); | ||
| 269 | if ( ret <= 0) | ||
| 270 | goto end; | ||
| 271 | if ( s->d1->send_cookie) /* start again, with a cookie */ | ||
| 272 | s->state=SSL3_ST_CW_CLNT_HELLO_A; | ||
| 273 | else | ||
| 274 | s->state = SSL3_ST_CR_CERT_A; | ||
| 275 | s->init_num = 0; | ||
| 276 | break; | ||
| 277 | |||
| 278 | case SSL3_ST_CR_CERT_A: | ||
| 279 | case SSL3_ST_CR_CERT_B: | ||
| 280 | /* Check if it is anon DH */ | ||
| 281 | if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL)) | ||
| 282 | { | ||
| 283 | ret=ssl3_get_server_certificate(s); | ||
| 284 | if (ret <= 0) goto end; | ||
| 285 | } | ||
| 286 | else | ||
| 287 | skip=1; | ||
| 288 | s->state=SSL3_ST_CR_KEY_EXCH_A; | ||
| 289 | s->init_num=0; | ||
| 290 | break; | ||
| 291 | |||
| 292 | case SSL3_ST_CR_KEY_EXCH_A: | ||
| 293 | case SSL3_ST_CR_KEY_EXCH_B: | ||
| 294 | ret=ssl3_get_key_exchange(s); | ||
| 295 | if (ret <= 0) goto end; | ||
| 296 | s->state=SSL3_ST_CR_CERT_REQ_A; | ||
| 297 | s->init_num=0; | ||
| 298 | |||
| 299 | /* at this point we check that we have the | ||
| 300 | * required stuff from the server */ | ||
| 301 | if (!ssl3_check_cert_and_algorithm(s)) | ||
| 302 | { | ||
| 303 | ret= -1; | ||
| 304 | goto end; | ||
| 305 | } | ||
| 306 | break; | ||
| 307 | |||
| 308 | case SSL3_ST_CR_CERT_REQ_A: | ||
| 309 | case SSL3_ST_CR_CERT_REQ_B: | ||
| 310 | ret=ssl3_get_certificate_request(s); | ||
| 311 | if (ret <= 0) goto end; | ||
| 312 | s->state=SSL3_ST_CR_SRVR_DONE_A; | ||
| 313 | s->init_num=0; | ||
| 314 | break; | ||
| 315 | |||
| 316 | case SSL3_ST_CR_SRVR_DONE_A: | ||
| 317 | case SSL3_ST_CR_SRVR_DONE_B: | ||
| 318 | ret=ssl3_get_server_done(s); | ||
| 319 | if (ret <= 0) goto end; | ||
| 320 | if (s->s3->tmp.cert_req) | ||
| 321 | s->state=SSL3_ST_CW_CERT_A; | ||
| 322 | else | ||
| 323 | s->state=SSL3_ST_CW_KEY_EXCH_A; | ||
| 324 | s->init_num=0; | ||
| 325 | |||
| 326 | break; | ||
| 327 | |||
| 328 | case SSL3_ST_CW_CERT_A: | ||
| 329 | case SSL3_ST_CW_CERT_B: | ||
| 330 | case SSL3_ST_CW_CERT_C: | ||
| 331 | case SSL3_ST_CW_CERT_D: | ||
| 332 | ret=dtls1_send_client_certificate(s); | ||
| 333 | if (ret <= 0) goto end; | ||
| 334 | s->state=SSL3_ST_CW_KEY_EXCH_A; | ||
| 335 | s->init_num=0; | ||
| 336 | break; | ||
| 337 | |||
| 338 | case SSL3_ST_CW_KEY_EXCH_A: | ||
| 339 | case SSL3_ST_CW_KEY_EXCH_B: | ||
| 340 | ret=dtls1_send_client_key_exchange(s); | ||
| 341 | if (ret <= 0) goto end; | ||
| 342 | l=s->s3->tmp.new_cipher->algorithms; | ||
| 343 | /* EAY EAY EAY need to check for DH fix cert | ||
| 344 | * sent back */ | ||
| 345 | /* For TLS, cert_req is set to 2, so a cert chain | ||
| 346 | * of nothing is sent, but no verify packet is sent */ | ||
| 347 | if (s->s3->tmp.cert_req == 1) | ||
| 348 | { | ||
| 349 | s->state=SSL3_ST_CW_CERT_VRFY_A; | ||
| 350 | } | ||
| 351 | else | ||
| 352 | { | ||
| 353 | s->state=SSL3_ST_CW_CHANGE_A; | ||
| 354 | s->s3->change_cipher_spec=0; | ||
| 355 | } | ||
| 356 | |||
| 357 | s->init_num=0; | ||
| 358 | break; | ||
| 359 | |||
| 360 | case SSL3_ST_CW_CERT_VRFY_A: | ||
| 361 | case SSL3_ST_CW_CERT_VRFY_B: | ||
| 362 | ret=dtls1_send_client_verify(s); | ||
| 363 | if (ret <= 0) goto end; | ||
| 364 | s->state=SSL3_ST_CW_CHANGE_A; | ||
| 365 | s->init_num=0; | ||
| 366 | s->s3->change_cipher_spec=0; | ||
| 367 | break; | ||
| 368 | |||
| 369 | case SSL3_ST_CW_CHANGE_A: | ||
| 370 | case SSL3_ST_CW_CHANGE_B: | ||
| 371 | ret=dtls1_send_change_cipher_spec(s, | ||
| 372 | SSL3_ST_CW_CHANGE_A,SSL3_ST_CW_CHANGE_B); | ||
| 373 | if (ret <= 0) goto end; | ||
| 374 | s->state=SSL3_ST_CW_FINISHED_A; | ||
| 375 | s->init_num=0; | ||
| 376 | |||
| 377 | s->session->cipher=s->s3->tmp.new_cipher; | ||
| 378 | #ifdef OPENSSL_NO_COMP | ||
| 379 | s->session->compress_meth=0; | ||
| 380 | #else | ||
| 381 | if (s->s3->tmp.new_compression == NULL) | ||
| 382 | s->session->compress_meth=0; | ||
| 383 | else | ||
| 384 | s->session->compress_meth= | ||
| 385 | s->s3->tmp.new_compression->id; | ||
| 386 | #endif | ||
| 387 | if (!s->method->ssl3_enc->setup_key_block(s)) | ||
| 388 | { | ||
| 389 | ret= -1; | ||
| 390 | goto end; | ||
| 391 | } | ||
| 392 | |||
| 393 | if (!s->method->ssl3_enc->change_cipher_state(s, | ||
| 394 | SSL3_CHANGE_CIPHER_CLIENT_WRITE)) | ||
| 395 | { | ||
| 396 | ret= -1; | ||
| 397 | goto end; | ||
| 398 | } | ||
| 399 | |||
| 400 | dtls1_reset_seq_numbers(s, SSL3_CC_WRITE); | ||
| 401 | break; | ||
| 402 | |||
| 403 | case SSL3_ST_CW_FINISHED_A: | ||
| 404 | case SSL3_ST_CW_FINISHED_B: | ||
| 405 | ret=dtls1_send_finished(s, | ||
| 406 | SSL3_ST_CW_FINISHED_A,SSL3_ST_CW_FINISHED_B, | ||
| 407 | s->method->ssl3_enc->client_finished_label, | ||
| 408 | s->method->ssl3_enc->client_finished_label_len); | ||
| 409 | if (ret <= 0) goto end; | ||
| 410 | s->state=SSL3_ST_CW_FLUSH; | ||
| 411 | |||
| 412 | /* clear flags */ | ||
| 413 | s->s3->flags&= ~SSL3_FLAGS_POP_BUFFER; | ||
| 414 | if (s->hit) | ||
| 415 | { | ||
| 416 | s->s3->tmp.next_state=SSL_ST_OK; | ||
| 417 | if (s->s3->flags & SSL3_FLAGS_DELAY_CLIENT_FINISHED) | ||
| 418 | { | ||
| 419 | s->state=SSL_ST_OK; | ||
| 420 | s->s3->flags|=SSL3_FLAGS_POP_BUFFER; | ||
| 421 | s->s3->delay_buf_pop_ret=0; | ||
| 422 | } | ||
| 423 | } | ||
| 424 | else | ||
| 425 | { | ||
| 426 | s->s3->tmp.next_state=SSL3_ST_CR_FINISHED_A; | ||
| 427 | } | ||
| 428 | s->init_num=0; | ||
| 429 | /* mark client_random uninitialized */ | ||
| 430 | memset (s->s3->client_random,0,sizeof(s->s3->client_random)); | ||
| 431 | |||
| 432 | break; | ||
| 433 | |||
| 434 | case SSL3_ST_CR_FINISHED_A: | ||
| 435 | case SSL3_ST_CR_FINISHED_B: | ||
| 436 | |||
| 437 | ret=ssl3_get_finished(s,SSL3_ST_CR_FINISHED_A, | ||
| 438 | SSL3_ST_CR_FINISHED_B); | ||
| 439 | if (ret <= 0) goto end; | ||
| 440 | |||
| 441 | if (s->hit) | ||
| 442 | s->state=SSL3_ST_CW_CHANGE_A; | ||
| 443 | else | ||
| 444 | s->state=SSL_ST_OK; | ||
| 445 | s->init_num=0; | ||
| 446 | break; | ||
| 447 | |||
| 448 | case SSL3_ST_CW_FLUSH: | ||
| 449 | /* number of bytes to be flushed */ | ||
| 450 | num1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL); | ||
| 451 | if (num1 > 0) | ||
| 452 | { | ||
| 453 | s->rwstate=SSL_WRITING; | ||
| 454 | num1=BIO_flush(s->wbio); | ||
| 455 | if (num1 <= 0) { ret= -1; goto end; } | ||
| 456 | s->rwstate=SSL_NOTHING; | ||
| 457 | } | ||
| 458 | |||
| 459 | s->state=s->s3->tmp.next_state; | ||
| 460 | break; | ||
| 461 | |||
| 462 | case SSL_ST_OK: | ||
| 463 | /* clean a few things up */ | ||
| 464 | ssl3_cleanup_key_block(s); | ||
| 465 | |||
| 466 | #if 0 | ||
| 467 | if (s->init_buf != NULL) | ||
| 468 | { | ||
| 469 | BUF_MEM_free(s->init_buf); | ||
| 470 | s->init_buf=NULL; | ||
| 471 | } | ||
| 472 | #endif | ||
| 473 | |||
| 474 | /* If we are not 'joining' the last two packets, | ||
| 475 | * remove the buffering now */ | ||
| 476 | if (!(s->s3->flags & SSL3_FLAGS_POP_BUFFER)) | ||
| 477 | ssl_free_wbio_buffer(s); | ||
| 478 | /* else do it later in ssl3_write */ | ||
| 479 | |||
| 480 | s->init_num=0; | ||
| 481 | s->new_session=0; | ||
| 482 | |||
| 483 | ssl_update_cache(s,SSL_SESS_CACHE_CLIENT); | ||
| 484 | if (s->hit) s->ctx->stats.sess_hit++; | ||
| 485 | |||
| 486 | ret=1; | ||
| 487 | /* s->server=0; */ | ||
| 488 | s->handshake_func=dtls1_connect; | ||
| 489 | s->ctx->stats.sess_connect_good++; | ||
| 490 | |||
| 491 | if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1); | ||
| 492 | |||
| 493 | /* done with handshaking */ | ||
| 494 | s->d1->handshake_read_seq = 0; | ||
| 495 | goto end; | ||
| 496 | /* break; */ | ||
| 497 | |||
| 498 | default: | ||
| 499 | SSLerr(SSL_F_DTLS1_CONNECT,SSL_R_UNKNOWN_STATE); | ||
| 500 | ret= -1; | ||
| 501 | goto end; | ||
| 502 | /* break; */ | ||
| 503 | } | ||
| 504 | |||
| 505 | /* did we do anything */ | ||
| 506 | if (!s->s3->tmp.reuse_message && !skip) | ||
| 507 | { | ||
| 508 | if (s->debug) | ||
| 509 | { | ||
| 510 | if ((ret=BIO_flush(s->wbio)) <= 0) | ||
| 511 | goto end; | ||
| 512 | } | ||
| 513 | |||
| 514 | if ((cb != NULL) && (s->state != state)) | ||
| 515 | { | ||
| 516 | new_state=s->state; | ||
| 517 | s->state=state; | ||
| 518 | cb(s,SSL_CB_CONNECT_LOOP,1); | ||
| 519 | s->state=new_state; | ||
| 520 | } | ||
| 521 | } | ||
| 522 | skip=0; | ||
| 523 | } | ||
| 524 | end: | ||
| 525 | s->in_handshake--; | ||
| 526 | if (buf != NULL) | ||
| 527 | BUF_MEM_free(buf); | ||
| 528 | if (cb != NULL) | ||
| 529 | cb(s,SSL_CB_CONNECT_EXIT,ret); | ||
| 530 | return(ret); | ||
| 531 | } | ||
| 532 | |||
| 533 | int dtls1_client_hello(SSL *s) | ||
| 534 | { | ||
| 535 | unsigned char *buf; | ||
| 536 | unsigned char *p,*d; | ||
| 537 | unsigned int i,j; | ||
| 538 | unsigned long Time,l; | ||
| 539 | SSL_COMP *comp; | ||
| 540 | |||
| 541 | buf=(unsigned char *)s->init_buf->data; | ||
| 542 | if (s->state == SSL3_ST_CW_CLNT_HELLO_A) | ||
| 543 | { | ||
| 544 | if ((s->session == NULL) || | ||
| 545 | (s->session->ssl_version != s->version) || | ||
| 546 | (s->session->not_resumable)) | ||
| 547 | { | ||
| 548 | if (!ssl_get_new_session(s,0)) | ||
| 549 | goto err; | ||
| 550 | } | ||
| 551 | /* else use the pre-loaded session */ | ||
| 552 | |||
| 553 | p=s->s3->client_random; | ||
| 554 | /* if client_random is initialized, reuse it, we are | ||
| 555 | * required to use same upon reply to HelloVerify */ | ||
| 556 | for (i=0;p[i]=='\0' && i<sizeof(s->s3->client_random);i++) ; | ||
| 557 | if (i==sizeof(s->s3->client_random)) | ||
| 558 | { | ||
| 559 | Time=(unsigned long)time(NULL); /* Time */ | ||
| 560 | l2n(Time,p); | ||
| 561 | RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4); | ||
| 562 | } | ||
| 563 | |||
| 564 | /* Do the message type and length last */ | ||
| 565 | d=p= &(buf[DTLS1_HM_HEADER_LENGTH]); | ||
| 566 | |||
| 567 | *(p++)=s->version>>8; | ||
| 568 | *(p++)=s->version&0xff; | ||
| 569 | s->client_version=s->version; | ||
| 570 | |||
| 571 | /* Random stuff */ | ||
| 572 | memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE); | ||
| 573 | p+=SSL3_RANDOM_SIZE; | ||
| 574 | |||
| 575 | /* Session ID */ | ||
| 576 | if (s->new_session) | ||
| 577 | i=0; | ||
| 578 | else | ||
| 579 | i=s->session->session_id_length; | ||
| 580 | *(p++)=i; | ||
| 581 | if (i != 0) | ||
| 582 | { | ||
| 583 | if (i > sizeof s->session->session_id) | ||
| 584 | { | ||
| 585 | SSLerr(SSL_F_DTLS1_CLIENT_HELLO, ERR_R_INTERNAL_ERROR); | ||
| 586 | goto err; | ||
| 587 | } | ||
| 588 | memcpy(p,s->session->session_id,i); | ||
| 589 | p+=i; | ||
| 590 | } | ||
| 591 | |||
| 592 | /* cookie stuff */ | ||
| 593 | if ( s->d1->cookie_len > sizeof(s->d1->cookie)) | ||
| 594 | { | ||
| 595 | SSLerr(SSL_F_DTLS1_CLIENT_HELLO, ERR_R_INTERNAL_ERROR); | ||
| 596 | goto err; | ||
| 597 | } | ||
| 598 | *(p++) = s->d1->cookie_len; | ||
| 599 | memcpy(p, s->d1->cookie, s->d1->cookie_len); | ||
| 600 | p += s->d1->cookie_len; | ||
| 601 | |||
| 602 | /* Ciphers supported */ | ||
| 603 | i=ssl_cipher_list_to_bytes(s,SSL_get_ciphers(s),&(p[2]),0); | ||
| 604 | if (i == 0) | ||
| 605 | { | ||
| 606 | SSLerr(SSL_F_DTLS1_CLIENT_HELLO,SSL_R_NO_CIPHERS_AVAILABLE); | ||
| 607 | goto err; | ||
| 608 | } | ||
| 609 | s2n(i,p); | ||
| 610 | p+=i; | ||
| 611 | |||
| 612 | /* COMPRESSION */ | ||
| 613 | if (s->ctx->comp_methods == NULL) | ||
| 614 | j=0; | ||
| 615 | else | ||
| 616 | j=sk_SSL_COMP_num(s->ctx->comp_methods); | ||
| 617 | *(p++)=1+j; | ||
| 618 | for (i=0; i<j; i++) | ||
| 619 | { | ||
| 620 | comp=sk_SSL_COMP_value(s->ctx->comp_methods,i); | ||
| 621 | *(p++)=comp->id; | ||
| 622 | } | ||
| 623 | *(p++)=0; /* Add the NULL method */ | ||
| 624 | |||
| 625 | l=(p-d); | ||
| 626 | d=buf; | ||
| 627 | |||
| 628 | d = dtls1_set_message_header(s, d, SSL3_MT_CLIENT_HELLO, l, 0, l); | ||
| 629 | |||
| 630 | s->state=SSL3_ST_CW_CLNT_HELLO_B; | ||
| 631 | /* number of bytes to write */ | ||
| 632 | s->init_num=p-buf; | ||
| 633 | s->init_off=0; | ||
| 634 | |||
| 635 | /* buffer the message to handle re-xmits */ | ||
| 636 | dtls1_buffer_message(s, 0); | ||
| 637 | } | ||
| 638 | |||
| 639 | /* SSL3_ST_CW_CLNT_HELLO_B */ | ||
| 640 | return(dtls1_do_write(s,SSL3_RT_HANDSHAKE)); | ||
| 641 | err: | ||
| 642 | return(-1); | ||
| 643 | } | ||
| 644 | |||
| 645 | static int dtls1_get_hello_verify(SSL *s) | ||
| 646 | { | ||
| 647 | int n, al, ok = 0; | ||
| 648 | unsigned char *data; | ||
| 649 | unsigned int cookie_len; | ||
| 650 | |||
| 651 | n=s->method->ssl_get_message(s, | ||
| 652 | DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A, | ||
| 653 | DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B, | ||
| 654 | -1, | ||
| 655 | s->max_cert_list, | ||
| 656 | &ok); | ||
| 657 | |||
| 658 | if (!ok) return((int)n); | ||
| 659 | |||
| 660 | if (s->s3->tmp.message_type != DTLS1_MT_HELLO_VERIFY_REQUEST) | ||
| 661 | { | ||
| 662 | s->d1->send_cookie = 0; | ||
| 663 | s->s3->tmp.reuse_message=1; | ||
| 664 | return(1); | ||
| 665 | } | ||
| 666 | |||
| 667 | data = (unsigned char *)s->init_msg; | ||
| 668 | |||
| 669 | if ((data[0] != (s->version>>8)) || (data[1] != (s->version&0xff))) | ||
| 670 | { | ||
| 671 | SSLerr(SSL_F_DTLS1_GET_HELLO_VERIFY,SSL_R_WRONG_SSL_VERSION); | ||
| 672 | s->version=(s->version&0xff00)|data[1]; | ||
| 673 | al = SSL_AD_PROTOCOL_VERSION; | ||
| 674 | goto f_err; | ||
| 675 | } | ||
| 676 | data+=2; | ||
| 677 | |||
| 678 | cookie_len = *(data++); | ||
| 679 | if ( cookie_len > sizeof(s->d1->cookie)) | ||
| 680 | { | ||
| 681 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
| 682 | goto f_err; | ||
| 683 | } | ||
| 684 | |||
| 685 | memcpy(s->d1->cookie, data, cookie_len); | ||
| 686 | s->d1->cookie_len = cookie_len; | ||
| 687 | |||
| 688 | s->d1->send_cookie = 1; | ||
| 689 | return 1; | ||
| 690 | |||
| 691 | f_err: | ||
| 692 | ssl3_send_alert(s, SSL3_AL_FATAL, al); | ||
| 693 | return -1; | ||
| 694 | } | ||
| 695 | |||
| 696 | int dtls1_send_client_key_exchange(SSL *s) | ||
| 697 | { | ||
| 698 | unsigned char *p,*d; | ||
| 699 | int n; | ||
| 700 | unsigned long l; | ||
| 701 | #ifndef OPENSSL_NO_RSA | ||
| 702 | unsigned char *q; | ||
| 703 | EVP_PKEY *pkey=NULL; | ||
| 704 | #endif | ||
| 705 | #ifndef OPENSSL_NO_KRB5 | ||
| 706 | KSSL_ERR kssl_err; | ||
| 707 | #endif /* OPENSSL_NO_KRB5 */ | ||
| 708 | |||
| 709 | if (s->state == SSL3_ST_CW_KEY_EXCH_A) | ||
| 710 | { | ||
| 711 | d=(unsigned char *)s->init_buf->data; | ||
| 712 | p= &(d[DTLS1_HM_HEADER_LENGTH]); | ||
| 713 | |||
| 714 | l=s->s3->tmp.new_cipher->algorithms; | ||
| 715 | |||
| 716 | /* Fool emacs indentation */ | ||
| 717 | if (0) {} | ||
| 718 | #ifndef OPENSSL_NO_RSA | ||
| 719 | else if (l & SSL_kRSA) | ||
| 720 | { | ||
| 721 | RSA *rsa; | ||
| 722 | unsigned char tmp_buf[SSL_MAX_MASTER_KEY_LENGTH]; | ||
| 723 | |||
| 724 | if (s->session->sess_cert->peer_rsa_tmp != NULL) | ||
| 725 | rsa=s->session->sess_cert->peer_rsa_tmp; | ||
| 726 | else | ||
| 727 | { | ||
| 728 | pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509); | ||
| 729 | if ((pkey == NULL) || | ||
| 730 | (pkey->type != EVP_PKEY_RSA) || | ||
| 731 | (pkey->pkey.rsa == NULL)) | ||
| 732 | { | ||
| 733 | SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,ERR_R_INTERNAL_ERROR); | ||
| 734 | goto err; | ||
| 735 | } | ||
| 736 | rsa=pkey->pkey.rsa; | ||
| 737 | EVP_PKEY_free(pkey); | ||
| 738 | } | ||
| 739 | |||
| 740 | tmp_buf[0]=s->client_version>>8; | ||
| 741 | tmp_buf[1]=s->client_version&0xff; | ||
| 742 | if (RAND_bytes(&(tmp_buf[2]),sizeof tmp_buf-2) <= 0) | ||
| 743 | goto err; | ||
| 744 | |||
| 745 | s->session->master_key_length=sizeof tmp_buf; | ||
| 746 | |||
| 747 | q=p; | ||
| 748 | /* Fix buf for TLS and [incidentally] DTLS */ | ||
| 749 | if (s->version > SSL3_VERSION) | ||
| 750 | p+=2; | ||
| 751 | n=RSA_public_encrypt(sizeof tmp_buf, | ||
| 752 | tmp_buf,p,rsa,RSA_PKCS1_PADDING); | ||
| 753 | #ifdef PKCS1_CHECK | ||
| 754 | if (s->options & SSL_OP_PKCS1_CHECK_1) p[1]++; | ||
| 755 | if (s->options & SSL_OP_PKCS1_CHECK_2) tmp_buf[0]=0x70; | ||
| 756 | #endif | ||
| 757 | if (n <= 0) | ||
| 758 | { | ||
| 759 | SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_ENCRYPT); | ||
| 760 | goto err; | ||
| 761 | } | ||
| 762 | |||
| 763 | /* Fix buf for TLS and [incidentally] DTLS */ | ||
| 764 | if (s->version > SSL3_VERSION) | ||
| 765 | { | ||
| 766 | s2n(n,q); | ||
| 767 | n+=2; | ||
| 768 | } | ||
| 769 | |||
| 770 | s->session->master_key_length= | ||
| 771 | s->method->ssl3_enc->generate_master_secret(s, | ||
| 772 | s->session->master_key, | ||
| 773 | tmp_buf,sizeof tmp_buf); | ||
| 774 | OPENSSL_cleanse(tmp_buf,sizeof tmp_buf); | ||
| 775 | } | ||
| 776 | #endif | ||
| 777 | #ifndef OPENSSL_NO_KRB5 | ||
| 778 | else if (l & SSL_kKRB5) | ||
| 779 | { | ||
| 780 | krb5_error_code krb5rc; | ||
| 781 | KSSL_CTX *kssl_ctx = s->kssl_ctx; | ||
| 782 | /* krb5_data krb5_ap_req; */ | ||
| 783 | krb5_data *enc_ticket; | ||
| 784 | krb5_data authenticator, *authp = NULL; | ||
| 785 | EVP_CIPHER_CTX ciph_ctx; | ||
| 786 | EVP_CIPHER *enc = NULL; | ||
| 787 | unsigned char iv[EVP_MAX_IV_LENGTH]; | ||
| 788 | unsigned char tmp_buf[SSL_MAX_MASTER_KEY_LENGTH]; | ||
| 789 | unsigned char epms[SSL_MAX_MASTER_KEY_LENGTH | ||
| 790 | + EVP_MAX_IV_LENGTH]; | ||
| 791 | int padl, outl = sizeof(epms); | ||
| 792 | |||
| 793 | EVP_CIPHER_CTX_init(&ciph_ctx); | ||
| 794 | |||
| 795 | #ifdef KSSL_DEBUG | ||
| 796 | printf("ssl3_send_client_key_exchange(%lx & %lx)\n", | ||
| 797 | l, SSL_kKRB5); | ||
| 798 | #endif /* KSSL_DEBUG */ | ||
| 799 | |||
| 800 | authp = NULL; | ||
| 801 | #ifdef KRB5SENDAUTH | ||
| 802 | if (KRB5SENDAUTH) authp = &authenticator; | ||
| 803 | #endif /* KRB5SENDAUTH */ | ||
| 804 | |||
| 805 | krb5rc = kssl_cget_tkt(kssl_ctx, &enc_ticket, authp, | ||
| 806 | &kssl_err); | ||
| 807 | enc = kssl_map_enc(kssl_ctx->enctype); | ||
| 808 | if (enc == NULL) | ||
| 809 | goto err; | ||
| 810 | #ifdef KSSL_DEBUG | ||
| 811 | { | ||
| 812 | printf("kssl_cget_tkt rtn %d\n", krb5rc); | ||
| 813 | if (krb5rc && kssl_err.text) | ||
| 814 | printf("kssl_cget_tkt kssl_err=%s\n", kssl_err.text); | ||
| 815 | } | ||
| 816 | #endif /* KSSL_DEBUG */ | ||
| 817 | |||
| 818 | if (krb5rc) | ||
| 819 | { | ||
| 820 | ssl3_send_alert(s,SSL3_AL_FATAL, | ||
| 821 | SSL_AD_HANDSHAKE_FAILURE); | ||
| 822 | SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE, | ||
| 823 | kssl_err.reason); | ||
| 824 | goto err; | ||
| 825 | } | ||
| 826 | |||
| 827 | /* 20010406 VRS - Earlier versions used KRB5 AP_REQ | ||
| 828 | ** in place of RFC 2712 KerberosWrapper, as in: | ||
| 829 | ** | ||
| 830 | ** Send ticket (copy to *p, set n = length) | ||
| 831 | ** n = krb5_ap_req.length; | ||
| 832 | ** memcpy(p, krb5_ap_req.data, krb5_ap_req.length); | ||
| 833 | ** if (krb5_ap_req.data) | ||
| 834 | ** kssl_krb5_free_data_contents(NULL,&krb5_ap_req); | ||
| 835 | ** | ||
| 836 | ** Now using real RFC 2712 KerberosWrapper | ||
| 837 | ** (Thanks to Simon Wilkinson <sxw@sxw.org.uk>) | ||
| 838 | ** Note: 2712 "opaque" types are here replaced | ||
| 839 | ** with a 2-byte length followed by the value. | ||
| 840 | ** Example: | ||
| 841 | ** KerberosWrapper= xx xx asn1ticket 0 0 xx xx encpms | ||
| 842 | ** Where "xx xx" = length bytes. Shown here with | ||
| 843 | ** optional authenticator omitted. | ||
| 844 | */ | ||
| 845 | |||
| 846 | /* KerberosWrapper.Ticket */ | ||
| 847 | s2n(enc_ticket->length,p); | ||
| 848 | memcpy(p, enc_ticket->data, enc_ticket->length); | ||
| 849 | p+= enc_ticket->length; | ||
| 850 | n = enc_ticket->length + 2; | ||
| 851 | |||
| 852 | /* KerberosWrapper.Authenticator */ | ||
| 853 | if (authp && authp->length) | ||
| 854 | { | ||
| 855 | s2n(authp->length,p); | ||
| 856 | memcpy(p, authp->data, authp->length); | ||
| 857 | p+= authp->length; | ||
| 858 | n+= authp->length + 2; | ||
| 859 | |||
| 860 | free(authp->data); | ||
| 861 | authp->data = NULL; | ||
| 862 | authp->length = 0; | ||
| 863 | } | ||
| 864 | else | ||
| 865 | { | ||
| 866 | s2n(0,p);/* null authenticator length */ | ||
| 867 | n+=2; | ||
| 868 | } | ||
| 869 | |||
| 870 | if (RAND_bytes(tmp_buf,sizeof tmp_buf) <= 0) | ||
| 871 | goto err; | ||
| 872 | |||
| 873 | /* 20010420 VRS. Tried it this way; failed. | ||
| 874 | ** EVP_EncryptInit_ex(&ciph_ctx,enc, NULL,NULL); | ||
| 875 | ** EVP_CIPHER_CTX_set_key_length(&ciph_ctx, | ||
| 876 | ** kssl_ctx->length); | ||
| 877 | ** EVP_EncryptInit_ex(&ciph_ctx,NULL, key,iv); | ||
| 878 | */ | ||
| 879 | |||
| 880 | memset(iv, 0, sizeof iv); /* per RFC 1510 */ | ||
| 881 | EVP_EncryptInit_ex(&ciph_ctx,enc, NULL, | ||
| 882 | kssl_ctx->key,iv); | ||
| 883 | EVP_EncryptUpdate(&ciph_ctx,epms,&outl,tmp_buf, | ||
| 884 | sizeof tmp_buf); | ||
| 885 | EVP_EncryptFinal_ex(&ciph_ctx,&(epms[outl]),&padl); | ||
| 886 | outl += padl; | ||
| 887 | if (outl > sizeof epms) | ||
| 888 | { | ||
| 889 | SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR); | ||
| 890 | goto err; | ||
| 891 | } | ||
| 892 | EVP_CIPHER_CTX_cleanup(&ciph_ctx); | ||
| 893 | |||
| 894 | /* KerberosWrapper.EncryptedPreMasterSecret */ | ||
| 895 | s2n(outl,p); | ||
| 896 | memcpy(p, epms, outl); | ||
| 897 | p+=outl; | ||
| 898 | n+=outl + 2; | ||
| 899 | |||
| 900 | s->session->master_key_length= | ||
| 901 | s->method->ssl3_enc->generate_master_secret(s, | ||
| 902 | s->session->master_key, | ||
| 903 | tmp_buf, sizeof tmp_buf); | ||
| 904 | |||
| 905 | OPENSSL_cleanse(tmp_buf, sizeof tmp_buf); | ||
| 906 | OPENSSL_cleanse(epms, outl); | ||
| 907 | } | ||
| 908 | #endif | ||
| 909 | #ifndef OPENSSL_NO_DH | ||
| 910 | else if (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd)) | ||
| 911 | { | ||
| 912 | DH *dh_srvr,*dh_clnt; | ||
| 913 | |||
| 914 | if (s->session->sess_cert->peer_dh_tmp != NULL) | ||
| 915 | dh_srvr=s->session->sess_cert->peer_dh_tmp; | ||
| 916 | else | ||
| 917 | { | ||
| 918 | /* we get them from the cert */ | ||
| 919 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE); | ||
| 920 | SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,SSL_R_UNABLE_TO_FIND_DH_PARAMETERS); | ||
| 921 | goto err; | ||
| 922 | } | ||
| 923 | |||
| 924 | /* generate a new random key */ | ||
| 925 | if ((dh_clnt=DHparams_dup(dh_srvr)) == NULL) | ||
| 926 | { | ||
| 927 | SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
| 928 | goto err; | ||
| 929 | } | ||
| 930 | if (!DH_generate_key(dh_clnt)) | ||
| 931 | { | ||
| 932 | SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
| 933 | goto err; | ||
| 934 | } | ||
| 935 | |||
| 936 | /* use the 'p' output buffer for the DH key, but | ||
| 937 | * make sure to clear it out afterwards */ | ||
| 938 | |||
| 939 | n=DH_compute_key(p,dh_srvr->pub_key,dh_clnt); | ||
| 940 | |||
| 941 | if (n <= 0) | ||
| 942 | { | ||
| 943 | SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
| 944 | goto err; | ||
| 945 | } | ||
| 946 | |||
| 947 | /* generate master key from the result */ | ||
| 948 | s->session->master_key_length= | ||
| 949 | s->method->ssl3_enc->generate_master_secret(s, | ||
| 950 | s->session->master_key,p,n); | ||
| 951 | /* clean up */ | ||
| 952 | memset(p,0,n); | ||
| 953 | |||
| 954 | /* send off the data */ | ||
| 955 | n=BN_num_bytes(dh_clnt->pub_key); | ||
| 956 | s2n(n,p); | ||
| 957 | BN_bn2bin(dh_clnt->pub_key,p); | ||
| 958 | n+=2; | ||
| 959 | |||
| 960 | DH_free(dh_clnt); | ||
| 961 | |||
| 962 | /* perhaps clean things up a bit EAY EAY EAY EAY*/ | ||
| 963 | } | ||
| 964 | #endif | ||
| 965 | else | ||
| 966 | { | ||
| 967 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE); | ||
| 968 | SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,ERR_R_INTERNAL_ERROR); | ||
| 969 | goto err; | ||
| 970 | } | ||
| 971 | |||
| 972 | d = dtls1_set_message_header(s, d, | ||
| 973 | SSL3_MT_CLIENT_KEY_EXCHANGE, n, 0, n); | ||
| 974 | /* | ||
| 975 | *(d++)=SSL3_MT_CLIENT_KEY_EXCHANGE; | ||
| 976 | l2n3(n,d); | ||
| 977 | l2n(s->d1->handshake_write_seq,d); | ||
| 978 | s->d1->handshake_write_seq++; | ||
| 979 | */ | ||
| 980 | |||
| 981 | s->state=SSL3_ST_CW_KEY_EXCH_B; | ||
| 982 | /* number of bytes to write */ | ||
| 983 | s->init_num=n+DTLS1_HM_HEADER_LENGTH; | ||
| 984 | s->init_off=0; | ||
| 985 | |||
| 986 | /* buffer the message to handle re-xmits */ | ||
| 987 | dtls1_buffer_message(s, 0); | ||
| 988 | } | ||
| 989 | |||
| 990 | /* SSL3_ST_CW_KEY_EXCH_B */ | ||
| 991 | return(dtls1_do_write(s,SSL3_RT_HANDSHAKE)); | ||
| 992 | err: | ||
| 993 | return(-1); | ||
| 994 | } | ||
| 995 | |||
| 996 | int dtls1_send_client_verify(SSL *s) | ||
| 997 | { | ||
| 998 | unsigned char *p,*d; | ||
| 999 | unsigned char data[MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH]; | ||
| 1000 | EVP_PKEY *pkey; | ||
| 1001 | #ifndef OPENSSL_NO_RSA | ||
| 1002 | unsigned u=0; | ||
| 1003 | #endif | ||
| 1004 | unsigned long n; | ||
| 1005 | #ifndef OPENSSL_NO_DSA | ||
| 1006 | int j; | ||
| 1007 | #endif | ||
| 1008 | |||
| 1009 | if (s->state == SSL3_ST_CW_CERT_VRFY_A) | ||
| 1010 | { | ||
| 1011 | d=(unsigned char *)s->init_buf->data; | ||
| 1012 | p= &(d[DTLS1_HM_HEADER_LENGTH]); | ||
| 1013 | pkey=s->cert->key->privatekey; | ||
| 1014 | |||
| 1015 | s->method->ssl3_enc->cert_verify_mac(s,&(s->s3->finish_dgst2), | ||
| 1016 | &(data[MD5_DIGEST_LENGTH])); | ||
| 1017 | |||
| 1018 | #ifndef OPENSSL_NO_RSA | ||
| 1019 | if (pkey->type == EVP_PKEY_RSA) | ||
| 1020 | { | ||
| 1021 | s->method->ssl3_enc->cert_verify_mac(s, | ||
| 1022 | &(s->s3->finish_dgst1),&(data[0])); | ||
| 1023 | if (RSA_sign(NID_md5_sha1, data, | ||
| 1024 | MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH, | ||
| 1025 | &(p[2]), &u, pkey->pkey.rsa) <= 0 ) | ||
| 1026 | { | ||
| 1027 | SSLerr(SSL_F_DTLS1_SEND_CLIENT_VERIFY,ERR_R_RSA_LIB); | ||
| 1028 | goto err; | ||
| 1029 | } | ||
| 1030 | s2n(u,p); | ||
| 1031 | n=u+2; | ||
| 1032 | } | ||
| 1033 | else | ||
| 1034 | #endif | ||
| 1035 | #ifndef OPENSSL_NO_DSA | ||
| 1036 | if (pkey->type == EVP_PKEY_DSA) | ||
| 1037 | { | ||
| 1038 | if (!DSA_sign(pkey->save_type, | ||
| 1039 | &(data[MD5_DIGEST_LENGTH]), | ||
| 1040 | SHA_DIGEST_LENGTH,&(p[2]), | ||
| 1041 | (unsigned int *)&j,pkey->pkey.dsa)) | ||
| 1042 | { | ||
| 1043 | SSLerr(SSL_F_DTLS1_SEND_CLIENT_VERIFY,ERR_R_DSA_LIB); | ||
| 1044 | goto err; | ||
| 1045 | } | ||
| 1046 | s2n(j,p); | ||
| 1047 | n=j+2; | ||
| 1048 | } | ||
| 1049 | else | ||
| 1050 | #endif | ||
| 1051 | { | ||
| 1052 | SSLerr(SSL_F_DTLS1_SEND_CLIENT_VERIFY,ERR_R_INTERNAL_ERROR); | ||
| 1053 | goto err; | ||
| 1054 | } | ||
| 1055 | |||
| 1056 | d = dtls1_set_message_header(s, d, | ||
| 1057 | SSL3_MT_CERTIFICATE_VERIFY, n, 0, n) ; | ||
| 1058 | |||
| 1059 | s->init_num=(int)n+DTLS1_HM_HEADER_LENGTH; | ||
| 1060 | s->init_off=0; | ||
| 1061 | |||
| 1062 | /* buffer the message to handle re-xmits */ | ||
| 1063 | dtls1_buffer_message(s, 0); | ||
| 1064 | |||
| 1065 | s->state = SSL3_ST_CW_CERT_VRFY_B; | ||
| 1066 | } | ||
| 1067 | |||
| 1068 | /* s->state = SSL3_ST_CW_CERT_VRFY_B */ | ||
| 1069 | return(dtls1_do_write(s,SSL3_RT_HANDSHAKE)); | ||
| 1070 | err: | ||
| 1071 | return(-1); | ||
| 1072 | } | ||
| 1073 | |||
| 1074 | int dtls1_send_client_certificate(SSL *s) | ||
| 1075 | { | ||
| 1076 | X509 *x509=NULL; | ||
| 1077 | EVP_PKEY *pkey=NULL; | ||
| 1078 | int i; | ||
| 1079 | unsigned long l; | ||
| 1080 | |||
| 1081 | if (s->state == SSL3_ST_CW_CERT_A) | ||
| 1082 | { | ||
| 1083 | if ((s->cert == NULL) || | ||
| 1084 | (s->cert->key->x509 == NULL) || | ||
| 1085 | (s->cert->key->privatekey == NULL)) | ||
| 1086 | s->state=SSL3_ST_CW_CERT_B; | ||
| 1087 | else | ||
| 1088 | s->state=SSL3_ST_CW_CERT_C; | ||
| 1089 | } | ||
| 1090 | |||
| 1091 | /* We need to get a client cert */ | ||
| 1092 | if (s->state == SSL3_ST_CW_CERT_B) | ||
| 1093 | { | ||
| 1094 | /* If we get an error, we need to | ||
| 1095 | * ssl->rwstate=SSL_X509_LOOKUP; return(-1); | ||
| 1096 | * We then get retied later */ | ||
| 1097 | i=0; | ||
| 1098 | if (s->ctx->client_cert_cb != NULL) | ||
| 1099 | i=s->ctx->client_cert_cb(s,&(x509),&(pkey)); | ||
| 1100 | if (i < 0) | ||
| 1101 | { | ||
| 1102 | s->rwstate=SSL_X509_LOOKUP; | ||
| 1103 | return(-1); | ||
| 1104 | } | ||
| 1105 | s->rwstate=SSL_NOTHING; | ||
| 1106 | if ((i == 1) && (pkey != NULL) && (x509 != NULL)) | ||
| 1107 | { | ||
| 1108 | s->state=SSL3_ST_CW_CERT_B; | ||
| 1109 | if ( !SSL_use_certificate(s,x509) || | ||
| 1110 | !SSL_use_PrivateKey(s,pkey)) | ||
| 1111 | i=0; | ||
| 1112 | } | ||
| 1113 | else if (i == 1) | ||
| 1114 | { | ||
| 1115 | i=0; | ||
| 1116 | SSLerr(SSL_F_DTLS1_SEND_CLIENT_CERTIFICATE,SSL_R_BAD_DATA_RETURNED_BY_CALLBACK); | ||
| 1117 | } | ||
| 1118 | |||
| 1119 | if (x509 != NULL) X509_free(x509); | ||
| 1120 | if (pkey != NULL) EVP_PKEY_free(pkey); | ||
| 1121 | if (i == 0) | ||
| 1122 | { | ||
| 1123 | if (s->version == SSL3_VERSION) | ||
| 1124 | { | ||
| 1125 | s->s3->tmp.cert_req=0; | ||
| 1126 | ssl3_send_alert(s,SSL3_AL_WARNING,SSL_AD_NO_CERTIFICATE); | ||
| 1127 | return(1); | ||
| 1128 | } | ||
| 1129 | else | ||
| 1130 | { | ||
| 1131 | s->s3->tmp.cert_req=2; | ||
| 1132 | } | ||
| 1133 | } | ||
| 1134 | |||
| 1135 | /* Ok, we have a cert */ | ||
| 1136 | s->state=SSL3_ST_CW_CERT_C; | ||
| 1137 | } | ||
| 1138 | |||
| 1139 | if (s->state == SSL3_ST_CW_CERT_C) | ||
| 1140 | { | ||
| 1141 | s->state=SSL3_ST_CW_CERT_D; | ||
| 1142 | l=dtls1_output_cert_chain(s, | ||
| 1143 | (s->s3->tmp.cert_req == 2)?NULL:s->cert->key->x509); | ||
| 1144 | s->init_num=(int)l; | ||
| 1145 | s->init_off=0; | ||
| 1146 | |||
| 1147 | /* set header called by dtls1_output_cert_chain() */ | ||
| 1148 | |||
| 1149 | /* buffer the message to handle re-xmits */ | ||
| 1150 | dtls1_buffer_message(s, 0); | ||
| 1151 | } | ||
| 1152 | /* SSL3_ST_CW_CERT_D */ | ||
| 1153 | return(dtls1_do_write(s,SSL3_RT_HANDSHAKE)); | ||
| 1154 | } | ||
| 1155 | |||
| 1156 | |||
diff --git a/src/lib/libssl/d1_enc.c b/src/lib/libssl/d1_enc.c new file mode 100644 index 0000000000..cbff7495c5 --- /dev/null +++ b/src/lib/libssl/d1_enc.c | |||
| @@ -0,0 +1,281 @@ | |||
| 1 | /* ssl/d1_enc.c */ | ||
| 2 | /* | ||
| 3 | * DTLS implementation written by Nagendra Modadugu | ||
| 4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. | ||
| 5 | */ | ||
| 6 | /* ==================================================================== | ||
| 7 | * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved. | ||
| 8 | * | ||
| 9 | * Redistribution and use in source and binary forms, with or without | ||
| 10 | * modification, are permitted provided that the following conditions | ||
| 11 | * are met: | ||
| 12 | * | ||
| 13 | * 1. Redistributions of source code must retain the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer. | ||
| 15 | * | ||
| 16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 17 | * notice, this list of conditions and the following disclaimer in | ||
| 18 | * the documentation and/or other materials provided with the | ||
| 19 | * distribution. | ||
| 20 | * | ||
| 21 | * 3. All advertising materials mentioning features or use of this | ||
| 22 | * software must display the following acknowledgment: | ||
| 23 | * "This product includes software developed by the OpenSSL Project | ||
| 24 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 25 | * | ||
| 26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 27 | * endorse or promote products derived from this software without | ||
| 28 | * prior written permission. For written permission, please contact | ||
| 29 | * openssl-core@openssl.org. | ||
| 30 | * | ||
| 31 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 32 | * nor may "OpenSSL" appear in their names without prior written | ||
| 33 | * permission of the OpenSSL Project. | ||
| 34 | * | ||
| 35 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 36 | * acknowledgment: | ||
| 37 | * "This product includes software developed by the OpenSSL Project | ||
| 38 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 39 | * | ||
| 40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 51 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 52 | * ==================================================================== | ||
| 53 | * | ||
| 54 | * This product includes cryptographic software written by Eric Young | ||
| 55 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 56 | * Hudson (tjh@cryptsoft.com). | ||
| 57 | * | ||
| 58 | */ | ||
| 59 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 60 | * All rights reserved. | ||
| 61 | * | ||
| 62 | * This package is an SSL implementation written | ||
| 63 | * by Eric Young (eay@cryptsoft.com). | ||
| 64 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 65 | * | ||
| 66 | * This library is free for commercial and non-commercial use as long as | ||
| 67 | * the following conditions are aheared to. The following conditions | ||
| 68 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 69 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 70 | * included with this distribution is covered by the same copyright terms | ||
| 71 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 72 | * | ||
| 73 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 74 | * the code are not to be removed. | ||
| 75 | * If this package is used in a product, Eric Young should be given attribution | ||
| 76 | * as the author of the parts of the library used. | ||
| 77 | * This can be in the form of a textual message at program startup or | ||
| 78 | * in documentation (online or textual) provided with the package. | ||
| 79 | * | ||
| 80 | * Redistribution and use in source and binary forms, with or without | ||
| 81 | * modification, are permitted provided that the following conditions | ||
| 82 | * are met: | ||
| 83 | * 1. Redistributions of source code must retain the copyright | ||
| 84 | * notice, this list of conditions and the following disclaimer. | ||
| 85 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 86 | * notice, this list of conditions and the following disclaimer in the | ||
| 87 | * documentation and/or other materials provided with the distribution. | ||
| 88 | * 3. All advertising materials mentioning features or use of this software | ||
| 89 | * must display the following acknowledgement: | ||
| 90 | * "This product includes cryptographic software written by | ||
| 91 | * Eric Young (eay@cryptsoft.com)" | ||
| 92 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 93 | * being used are not cryptographic related :-). | ||
| 94 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 95 | * the apps directory (application code) you must include an acknowledgement: | ||
| 96 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 97 | * | ||
| 98 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 99 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 100 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 101 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 102 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 103 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 104 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 105 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 106 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 107 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 108 | * SUCH DAMAGE. | ||
| 109 | * | ||
| 110 | * The licence and distribution terms for any publically available version or | ||
| 111 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 112 | * copied and put under another distribution licence | ||
| 113 | * [including the GNU Public Licence.] | ||
| 114 | */ | ||
| 115 | |||
| 116 | #include <stdio.h> | ||
| 117 | #include "ssl_locl.h" | ||
| 118 | #include <openssl/comp.h> | ||
| 119 | #include <openssl/evp.h> | ||
| 120 | #include <openssl/hmac.h> | ||
| 121 | #include <openssl/md5.h> | ||
| 122 | #include <openssl/rand.h> | ||
| 123 | |||
| 124 | |||
| 125 | int dtls1_enc(SSL *s, int send) | ||
| 126 | { | ||
| 127 | SSL3_RECORD *rec; | ||
| 128 | EVP_CIPHER_CTX *ds; | ||
| 129 | unsigned long l; | ||
| 130 | int bs,i,ii,j,k,n=0; | ||
| 131 | const EVP_CIPHER *enc; | ||
| 132 | |||
| 133 | if (send) | ||
| 134 | { | ||
| 135 | if (s->write_hash != NULL) | ||
| 136 | n=EVP_MD_size(s->write_hash); | ||
| 137 | ds=s->enc_write_ctx; | ||
| 138 | rec= &(s->s3->wrec); | ||
| 139 | if (s->enc_write_ctx == NULL) | ||
| 140 | enc=NULL; | ||
| 141 | else | ||
| 142 | { | ||
| 143 | enc=EVP_CIPHER_CTX_cipher(s->enc_write_ctx); | ||
| 144 | if ( rec->data != rec->input) | ||
| 145 | /* we can't write into the input stream */ | ||
| 146 | fprintf(stderr, "%s:%d: rec->data != rec->input\n", | ||
| 147 | __FILE__, __LINE__); | ||
| 148 | else if ( EVP_CIPHER_block_size(ds->cipher) > 1) | ||
| 149 | { | ||
| 150 | if (!RAND_bytes(rec->input, EVP_CIPHER_block_size(ds->cipher))) | ||
| 151 | return -1; | ||
| 152 | } | ||
| 153 | } | ||
| 154 | } | ||
| 155 | else | ||
| 156 | { | ||
| 157 | if (s->read_hash != NULL) | ||
| 158 | n=EVP_MD_size(s->read_hash); | ||
| 159 | ds=s->enc_read_ctx; | ||
| 160 | rec= &(s->s3->rrec); | ||
| 161 | if (s->enc_read_ctx == NULL) | ||
| 162 | enc=NULL; | ||
| 163 | else | ||
| 164 | enc=EVP_CIPHER_CTX_cipher(s->enc_read_ctx); | ||
| 165 | } | ||
| 166 | |||
| 167 | #ifdef KSSL_DEBUG | ||
| 168 | printf("dtls1_enc(%d)\n", send); | ||
| 169 | #endif /* KSSL_DEBUG */ | ||
| 170 | |||
| 171 | if ((s->session == NULL) || (ds == NULL) || | ||
| 172 | (enc == NULL)) | ||
| 173 | { | ||
| 174 | memmove(rec->data,rec->input,rec->length); | ||
| 175 | rec->input=rec->data; | ||
| 176 | } | ||
| 177 | else | ||
| 178 | { | ||
| 179 | l=rec->length; | ||
| 180 | bs=EVP_CIPHER_block_size(ds->cipher); | ||
| 181 | |||
| 182 | if ((bs != 1) && send) | ||
| 183 | { | ||
| 184 | i=bs-((int)l%bs); | ||
| 185 | |||
| 186 | /* Add weird padding of upto 256 bytes */ | ||
| 187 | |||
| 188 | /* we need to add 'i' padding bytes of value j */ | ||
| 189 | j=i-1; | ||
| 190 | if (s->options & SSL_OP_TLS_BLOCK_PADDING_BUG) | ||
| 191 | { | ||
| 192 | if (s->s3->flags & TLS1_FLAGS_TLS_PADDING_BUG) | ||
| 193 | j++; | ||
| 194 | } | ||
| 195 | for (k=(int)l; k<(int)(l+i); k++) | ||
| 196 | rec->input[k]=j; | ||
| 197 | l+=i; | ||
| 198 | rec->length+=i; | ||
| 199 | } | ||
| 200 | |||
| 201 | #ifdef KSSL_DEBUG | ||
| 202 | { | ||
| 203 | unsigned long ui; | ||
| 204 | printf("EVP_Cipher(ds=%p,rec->data=%p,rec->input=%p,l=%ld) ==>\n", | ||
| 205 | ds,rec->data,rec->input,l); | ||
| 206 | printf("\tEVP_CIPHER_CTX: %d buf_len, %d key_len [%d %d], %d iv_len\n", | ||
| 207 | ds->buf_len, ds->cipher->key_len, | ||
| 208 | DES_KEY_SZ, DES_SCHEDULE_SZ, | ||
| 209 | ds->cipher->iv_len); | ||
| 210 | printf("\t\tIV: "); | ||
| 211 | for (i=0; i<ds->cipher->iv_len; i++) printf("%02X", ds->iv[i]); | ||
| 212 | printf("\n"); | ||
| 213 | printf("\trec->input="); | ||
| 214 | for (ui=0; ui<l; ui++) printf(" %02x", rec->input[ui]); | ||
| 215 | printf("\n"); | ||
| 216 | } | ||
| 217 | #endif /* KSSL_DEBUG */ | ||
| 218 | |||
| 219 | if (!send) | ||
| 220 | { | ||
| 221 | if (l == 0 || l%bs != 0) | ||
| 222 | { | ||
| 223 | SSLerr(SSL_F_DTLS1_ENC,SSL_R_BLOCK_CIPHER_PAD_IS_WRONG); | ||
| 224 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECRYPTION_FAILED); | ||
| 225 | return 0; | ||
| 226 | } | ||
| 227 | } | ||
| 228 | |||
| 229 | EVP_Cipher(ds,rec->data,rec->input,l); | ||
| 230 | |||
| 231 | #ifdef KSSL_DEBUG | ||
| 232 | { | ||
| 233 | unsigned long i; | ||
| 234 | printf("\trec->data="); | ||
| 235 | for (i=0; i<l; i++) | ||
| 236 | printf(" %02x", rec->data[i]); printf("\n"); | ||
| 237 | } | ||
| 238 | #endif /* KSSL_DEBUG */ | ||
| 239 | |||
| 240 | if ((bs != 1) && !send) | ||
| 241 | { | ||
| 242 | ii=i=rec->data[l-1]; /* padding_length */ | ||
| 243 | i++; | ||
| 244 | if (s->options&SSL_OP_TLS_BLOCK_PADDING_BUG) | ||
| 245 | { | ||
| 246 | /* First packet is even in size, so check */ | ||
| 247 | if ((memcmp(s->s3->read_sequence, | ||
| 248 | "\0\0\0\0\0\0\0\0",8) == 0) && !(ii & 1)) | ||
| 249 | s->s3->flags|=TLS1_FLAGS_TLS_PADDING_BUG; | ||
| 250 | if (s->s3->flags & TLS1_FLAGS_TLS_PADDING_BUG) | ||
| 251 | i--; | ||
| 252 | } | ||
| 253 | /* TLS 1.0 does not bound the number of padding bytes by the block size. | ||
| 254 | * All of them must have value 'padding_length'. */ | ||
| 255 | if (i > (int)rec->length) | ||
| 256 | { | ||
| 257 | /* Incorrect padding. SSLerr() and ssl3_alert are done | ||
| 258 | * by caller: we don't want to reveal whether this is | ||
| 259 | * a decryption error or a MAC verification failure | ||
| 260 | * (see http://www.openssl.org/~bodo/tls-cbc.txt) | ||
| 261 | */ | ||
| 262 | return -1; | ||
| 263 | } | ||
| 264 | for (j=(int)(l-i); j<(int)l; j++) | ||
| 265 | { | ||
| 266 | if (rec->data[j] != ii) | ||
| 267 | { | ||
| 268 | /* Incorrect padding */ | ||
| 269 | return -1; | ||
| 270 | } | ||
| 271 | } | ||
| 272 | rec->length-=i; | ||
| 273 | |||
| 274 | rec->data += bs; /* skip the implicit IV */ | ||
| 275 | rec->input += bs; | ||
| 276 | rec->length -= bs; | ||
| 277 | } | ||
| 278 | } | ||
| 279 | return(1); | ||
| 280 | } | ||
| 281 | |||
diff --git a/src/lib/libssl/d1_lib.c b/src/lib/libssl/d1_lib.c new file mode 100644 index 0000000000..fc088b4148 --- /dev/null +++ b/src/lib/libssl/d1_lib.c | |||
| @@ -0,0 +1,210 @@ | |||
| 1 | /* ssl/d1_lib.c */ | ||
| 2 | /* | ||
| 3 | * DTLS implementation written by Nagendra Modadugu | ||
| 4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. | ||
| 5 | */ | ||
| 6 | /* ==================================================================== | ||
| 7 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. | ||
| 8 | * | ||
| 9 | * Redistribution and use in source and binary forms, with or without | ||
| 10 | * modification, are permitted provided that the following conditions | ||
| 11 | * are met: | ||
| 12 | * | ||
| 13 | * 1. Redistributions of source code must retain the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer. | ||
| 15 | * | ||
| 16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 17 | * notice, this list of conditions and the following disclaimer in | ||
| 18 | * the documentation and/or other materials provided with the | ||
| 19 | * distribution. | ||
| 20 | * | ||
| 21 | * 3. All advertising materials mentioning features or use of this | ||
| 22 | * software must display the following acknowledgment: | ||
| 23 | * "This product includes software developed by the OpenSSL Project | ||
| 24 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 25 | * | ||
| 26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 27 | * endorse or promote products derived from this software without | ||
| 28 | * prior written permission. For written permission, please contact | ||
| 29 | * openssl-core@OpenSSL.org. | ||
| 30 | * | ||
| 31 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 32 | * nor may "OpenSSL" appear in their names without prior written | ||
| 33 | * permission of the OpenSSL Project. | ||
| 34 | * | ||
| 35 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 36 | * acknowledgment: | ||
| 37 | * "This product includes software developed by the OpenSSL Project | ||
| 38 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 39 | * | ||
| 40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 51 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 52 | * ==================================================================== | ||
| 53 | * | ||
| 54 | * This product includes cryptographic software written by Eric Young | ||
| 55 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 56 | * Hudson (tjh@cryptsoft.com). | ||
| 57 | * | ||
| 58 | */ | ||
| 59 | |||
| 60 | #include <stdio.h> | ||
| 61 | #include <openssl/objects.h> | ||
| 62 | #include "ssl_locl.h" | ||
| 63 | |||
| 64 | const char dtls1_version_str[]="DTLSv1" OPENSSL_VERSION_PTEXT; | ||
| 65 | |||
| 66 | SSL3_ENC_METHOD DTLSv1_enc_data={ | ||
| 67 | dtls1_enc, | ||
| 68 | tls1_mac, | ||
| 69 | tls1_setup_key_block, | ||
| 70 | tls1_generate_master_secret, | ||
| 71 | tls1_change_cipher_state, | ||
| 72 | tls1_final_finish_mac, | ||
| 73 | TLS1_FINISH_MAC_LENGTH, | ||
| 74 | tls1_cert_verify_mac, | ||
| 75 | TLS_MD_CLIENT_FINISH_CONST,TLS_MD_CLIENT_FINISH_CONST_SIZE, | ||
| 76 | TLS_MD_SERVER_FINISH_CONST,TLS_MD_SERVER_FINISH_CONST_SIZE, | ||
| 77 | tls1_alert_code, | ||
| 78 | }; | ||
| 79 | |||
| 80 | long dtls1_default_timeout(void) | ||
| 81 | { | ||
| 82 | /* 2 hours, the 24 hours mentioned in the DTLSv1 spec | ||
| 83 | * is way too long for http, the cache would over fill */ | ||
| 84 | return(60*60*2); | ||
| 85 | } | ||
| 86 | |||
| 87 | IMPLEMENT_dtls1_meth_func(dtlsv1_base_method, | ||
| 88 | ssl_undefined_function, | ||
| 89 | ssl_undefined_function, | ||
| 90 | ssl_bad_method) | ||
| 91 | |||
| 92 | int dtls1_new(SSL *s) | ||
| 93 | { | ||
| 94 | DTLS1_STATE *d1; | ||
| 95 | |||
| 96 | if (!ssl3_new(s)) return(0); | ||
| 97 | if ((d1=OPENSSL_malloc(sizeof *d1)) == NULL) return (0); | ||
| 98 | memset(d1,0, sizeof *d1); | ||
| 99 | |||
| 100 | /* d1->handshake_epoch=0; */ | ||
| 101 | #if defined(OPENSSL_SYS_VMS) || defined(VMS_TEST) | ||
| 102 | d1->bitmap.length=64; | ||
| 103 | #else | ||
| 104 | d1->bitmap.length=sizeof(d1->bitmap.map) * 8; | ||
| 105 | #endif | ||
| 106 | pq_64bit_init(&(d1->bitmap.map)); | ||
| 107 | pq_64bit_init(&(d1->bitmap.max_seq_num)); | ||
| 108 | |||
| 109 | pq_64bit_init(&(d1->next_bitmap.map)); | ||
| 110 | pq_64bit_init(&(d1->next_bitmap.max_seq_num)); | ||
| 111 | |||
| 112 | d1->unprocessed_rcds.q=pqueue_new(); | ||
| 113 | d1->processed_rcds.q=pqueue_new(); | ||
| 114 | d1->buffered_messages = pqueue_new(); | ||
| 115 | d1->sent_messages=pqueue_new(); | ||
| 116 | |||
| 117 | if ( s->server) | ||
| 118 | { | ||
| 119 | d1->cookie_len = sizeof(s->d1->cookie); | ||
| 120 | } | ||
| 121 | |||
| 122 | if( ! d1->unprocessed_rcds.q || ! d1->processed_rcds.q | ||
| 123 | || ! d1->buffered_messages || ! d1->sent_messages) | ||
| 124 | { | ||
| 125 | if ( d1->unprocessed_rcds.q) pqueue_free(d1->unprocessed_rcds.q); | ||
| 126 | if ( d1->processed_rcds.q) pqueue_free(d1->processed_rcds.q); | ||
| 127 | if ( d1->buffered_messages) pqueue_free(d1->buffered_messages); | ||
| 128 | if ( d1->sent_messages) pqueue_free(d1->sent_messages); | ||
| 129 | OPENSSL_free(d1); | ||
| 130 | return (0); | ||
| 131 | } | ||
| 132 | |||
| 133 | s->d1=d1; | ||
| 134 | s->method->ssl_clear(s); | ||
| 135 | return(1); | ||
| 136 | } | ||
| 137 | |||
| 138 | void dtls1_free(SSL *s) | ||
| 139 | { | ||
| 140 | pitem *item = NULL; | ||
| 141 | hm_fragment *frag = NULL; | ||
| 142 | |||
| 143 | ssl3_free(s); | ||
| 144 | |||
| 145 | while( (item = pqueue_pop(s->d1->unprocessed_rcds.q)) != NULL) | ||
| 146 | { | ||
| 147 | OPENSSL_free(item->data); | ||
| 148 | pitem_free(item); | ||
| 149 | } | ||
| 150 | pqueue_free(s->d1->unprocessed_rcds.q); | ||
| 151 | |||
| 152 | while( (item = pqueue_pop(s->d1->processed_rcds.q)) != NULL) | ||
| 153 | { | ||
| 154 | OPENSSL_free(item->data); | ||
| 155 | pitem_free(item); | ||
| 156 | } | ||
| 157 | pqueue_free(s->d1->processed_rcds.q); | ||
| 158 | |||
| 159 | while( (item = pqueue_pop(s->d1->buffered_messages)) != NULL) | ||
| 160 | { | ||
| 161 | frag = (hm_fragment *)item->data; | ||
| 162 | OPENSSL_free(frag->fragment); | ||
| 163 | OPENSSL_free(frag); | ||
| 164 | pitem_free(item); | ||
| 165 | } | ||
| 166 | pqueue_free(s->d1->buffered_messages); | ||
| 167 | |||
| 168 | while ( (item = pqueue_pop(s->d1->sent_messages)) != NULL) | ||
| 169 | { | ||
| 170 | frag = (hm_fragment *)item->data; | ||
| 171 | OPENSSL_free(frag->fragment); | ||
| 172 | OPENSSL_free(frag); | ||
| 173 | pitem_free(item); | ||
| 174 | } | ||
| 175 | pqueue_free(s->d1->sent_messages); | ||
| 176 | |||
| 177 | pq_64bit_free(&(s->d1->bitmap.map)); | ||
| 178 | pq_64bit_free(&(s->d1->bitmap.max_seq_num)); | ||
| 179 | |||
| 180 | pq_64bit_free(&(s->d1->next_bitmap.map)); | ||
| 181 | pq_64bit_free(&(s->d1->next_bitmap.max_seq_num)); | ||
| 182 | |||
| 183 | OPENSSL_free(s->d1); | ||
| 184 | } | ||
| 185 | |||
| 186 | void dtls1_clear(SSL *s) | ||
| 187 | { | ||
| 188 | ssl3_clear(s); | ||
| 189 | s->version=DTLS1_VERSION; | ||
| 190 | } | ||
| 191 | |||
| 192 | /* | ||
| 193 | * As it's impossible to use stream ciphers in "datagram" mode, this | ||
| 194 | * simple filter is designed to disengage them in DTLS. Unfortunately | ||
| 195 | * there is no universal way to identify stream SSL_CIPHER, so we have | ||
| 196 | * to explicitly list their SSL_* codes. Currently RC4 is the only one | ||
| 197 | * available, but if new ones emerge, they will have to be added... | ||
| 198 | */ | ||
| 199 | SSL_CIPHER *dtls1_get_cipher(unsigned int u) | ||
| 200 | { | ||
| 201 | SSL_CIPHER *ciph = ssl3_get_cipher(u); | ||
| 202 | |||
| 203 | if (ciph != NULL) | ||
| 204 | { | ||
| 205 | if ((ciph->algorithms&SSL_ENC_MASK) == SSL_RC4) | ||
| 206 | return NULL; | ||
| 207 | } | ||
| 208 | |||
| 209 | return ciph; | ||
| 210 | } | ||
diff --git a/src/lib/libssl/d1_meth.c b/src/lib/libssl/d1_meth.c new file mode 100644 index 0000000000..8a6cf31947 --- /dev/null +++ b/src/lib/libssl/d1_meth.c | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | /* ssl/d1_meth.h */ | ||
| 2 | /* | ||
| 3 | * DTLS implementation written by Nagendra Modadugu | ||
| 4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. | ||
| 5 | */ | ||
| 6 | /* ==================================================================== | ||
| 7 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. | ||
| 8 | * | ||
| 9 | * Redistribution and use in source and binary forms, with or without | ||
| 10 | * modification, are permitted provided that the following conditions | ||
| 11 | * are met: | ||
| 12 | * | ||
| 13 | * 1. Redistributions of source code must retain the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer. | ||
| 15 | * | ||
| 16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 17 | * notice, this list of conditions and the following disclaimer in | ||
| 18 | * the documentation and/or other materials provided with the | ||
| 19 | * distribution. | ||
| 20 | * | ||
| 21 | * 3. All advertising materials mentioning features or use of this | ||
| 22 | * software must display the following acknowledgment: | ||
| 23 | * "This product includes software developed by the OpenSSL Project | ||
| 24 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 25 | * | ||
| 26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 27 | * endorse or promote products derived from this software without | ||
| 28 | * prior written permission. For written permission, please contact | ||
| 29 | * openssl-core@OpenSSL.org. | ||
| 30 | * | ||
| 31 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 32 | * nor may "OpenSSL" appear in their names without prior written | ||
| 33 | * permission of the OpenSSL Project. | ||
| 34 | * | ||
| 35 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 36 | * acknowledgment: | ||
| 37 | * "This product includes software developed by the OpenSSL Project | ||
| 38 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 39 | * | ||
| 40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 51 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 52 | * ==================================================================== | ||
| 53 | * | ||
| 54 | * This product includes cryptographic software written by Eric Young | ||
| 55 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 56 | * Hudson (tjh@cryptsoft.com). | ||
| 57 | * | ||
| 58 | */ | ||
| 59 | |||
| 60 | #include <stdio.h> | ||
| 61 | #include <openssl/objects.h> | ||
| 62 | #include "ssl_locl.h" | ||
| 63 | |||
| 64 | static SSL_METHOD *dtls1_get_method(int ver); | ||
| 65 | static SSL_METHOD *dtls1_get_method(int ver) | ||
| 66 | { | ||
| 67 | if (ver == DTLS1_VERSION) | ||
| 68 | return(DTLSv1_method()); | ||
| 69 | else | ||
| 70 | return(NULL); | ||
| 71 | } | ||
| 72 | |||
| 73 | IMPLEMENT_dtls1_meth_func(DTLSv1_method, | ||
| 74 | dtls1_accept, | ||
| 75 | dtls1_connect, | ||
| 76 | dtls1_get_method) | ||
| 77 | |||
diff --git a/src/lib/libssl/d1_pkt.c b/src/lib/libssl/d1_pkt.c new file mode 100644 index 0000000000..377696deac --- /dev/null +++ b/src/lib/libssl/d1_pkt.c | |||
| @@ -0,0 +1,1778 @@ | |||
| 1 | /* ssl/d1_pkt.c */ | ||
| 2 | /* | ||
| 3 | * DTLS implementation written by Nagendra Modadugu | ||
| 4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. | ||
| 5 | */ | ||
| 6 | /* ==================================================================== | ||
| 7 | * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved. | ||
| 8 | * | ||
| 9 | * Redistribution and use in source and binary forms, with or without | ||
| 10 | * modification, are permitted provided that the following conditions | ||
| 11 | * are met: | ||
| 12 | * | ||
| 13 | * 1. Redistributions of source code must retain the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer. | ||
| 15 | * | ||
| 16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 17 | * notice, this list of conditions and the following disclaimer in | ||
| 18 | * the documentation and/or other materials provided with the | ||
| 19 | * distribution. | ||
| 20 | * | ||
| 21 | * 3. All advertising materials mentioning features or use of this | ||
| 22 | * software must display the following acknowledgment: | ||
| 23 | * "This product includes software developed by the OpenSSL Project | ||
| 24 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 25 | * | ||
| 26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 27 | * endorse or promote products derived from this software without | ||
| 28 | * prior written permission. For written permission, please contact | ||
| 29 | * openssl-core@openssl.org. | ||
| 30 | * | ||
| 31 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 32 | * nor may "OpenSSL" appear in their names without prior written | ||
| 33 | * permission of the OpenSSL Project. | ||
| 34 | * | ||
| 35 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 36 | * acknowledgment: | ||
| 37 | * "This product includes software developed by the OpenSSL Project | ||
| 38 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 39 | * | ||
| 40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 51 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 52 | * ==================================================================== | ||
| 53 | * | ||
| 54 | * This product includes cryptographic software written by Eric Young | ||
| 55 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 56 | * Hudson (tjh@cryptsoft.com). | ||
| 57 | * | ||
| 58 | */ | ||
| 59 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 60 | * All rights reserved. | ||
| 61 | * | ||
| 62 | * This package is an SSL implementation written | ||
| 63 | * by Eric Young (eay@cryptsoft.com). | ||
| 64 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 65 | * | ||
| 66 | * This library is free for commercial and non-commercial use as long as | ||
| 67 | * the following conditions are aheared to. The following conditions | ||
| 68 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 69 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 70 | * included with this distribution is covered by the same copyright terms | ||
| 71 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 72 | * | ||
| 73 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 74 | * the code are not to be removed. | ||
| 75 | * If this package is used in a product, Eric Young should be given attribution | ||
| 76 | * as the author of the parts of the library used. | ||
| 77 | * This can be in the form of a textual message at program startup or | ||
| 78 | * in documentation (online or textual) provided with the package. | ||
| 79 | * | ||
| 80 | * Redistribution and use in source and binary forms, with or without | ||
| 81 | * modification, are permitted provided that the following conditions | ||
| 82 | * are met: | ||
| 83 | * 1. Redistributions of source code must retain the copyright | ||
| 84 | * notice, this list of conditions and the following disclaimer. | ||
| 85 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 86 | * notice, this list of conditions and the following disclaimer in the | ||
| 87 | * documentation and/or other materials provided with the distribution. | ||
| 88 | * 3. All advertising materials mentioning features or use of this software | ||
| 89 | * must display the following acknowledgement: | ||
| 90 | * "This product includes cryptographic software written by | ||
| 91 | * Eric Young (eay@cryptsoft.com)" | ||
| 92 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 93 | * being used are not cryptographic related :-). | ||
| 94 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 95 | * the apps directory (application code) you must include an acknowledgement: | ||
| 96 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 97 | * | ||
| 98 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 99 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 100 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 101 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 102 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 103 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 104 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 105 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 106 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 107 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 108 | * SUCH DAMAGE. | ||
| 109 | * | ||
| 110 | * The licence and distribution terms for any publically available version or | ||
| 111 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 112 | * copied and put under another distribution licence | ||
| 113 | * [including the GNU Public Licence.] | ||
| 114 | */ | ||
| 115 | |||
| 116 | #include <stdio.h> | ||
| 117 | #include <errno.h> | ||
| 118 | #define USE_SOCKETS | ||
| 119 | #include "ssl_locl.h" | ||
| 120 | #include <openssl/evp.h> | ||
| 121 | #include <openssl/buffer.h> | ||
| 122 | #include <openssl/pqueue.h> | ||
| 123 | #include <openssl/rand.h> | ||
| 124 | |||
| 125 | static int have_handshake_fragment(SSL *s, int type, unsigned char *buf, | ||
| 126 | int len, int peek); | ||
| 127 | static int dtls1_record_replay_check(SSL *s, DTLS1_BITMAP *bitmap, | ||
| 128 | PQ_64BIT *seq_num); | ||
| 129 | static void dtls1_record_bitmap_update(SSL *s, DTLS1_BITMAP *bitmap); | ||
| 130 | static DTLS1_BITMAP *dtls1_get_bitmap(SSL *s, SSL3_RECORD *rr, | ||
| 131 | unsigned int *is_next_epoch); | ||
| 132 | #if 0 | ||
| 133 | static int dtls1_record_needs_buffering(SSL *s, SSL3_RECORD *rr, | ||
| 134 | unsigned short *priority, unsigned long *offset); | ||
| 135 | #endif | ||
| 136 | static int dtls1_buffer_record(SSL *s, record_pqueue *q, | ||
| 137 | PQ_64BIT priority); | ||
| 138 | static int dtls1_process_record(SSL *s); | ||
| 139 | #if PQ_64BIT_IS_INTEGER | ||
| 140 | static PQ_64BIT bytes_to_long_long(unsigned char *bytes, PQ_64BIT *num); | ||
| 141 | #endif | ||
| 142 | static void dtls1_clear_timeouts(SSL *s); | ||
| 143 | |||
| 144 | /* copy buffered record into SSL structure */ | ||
| 145 | static int | ||
| 146 | dtls1_copy_record(SSL *s, pitem *item) | ||
| 147 | { | ||
| 148 | DTLS1_RECORD_DATA *rdata; | ||
| 149 | |||
| 150 | rdata = (DTLS1_RECORD_DATA *)item->data; | ||
| 151 | |||
| 152 | if (s->s3->rbuf.buf != NULL) | ||
| 153 | OPENSSL_free(s->s3->rbuf.buf); | ||
| 154 | |||
| 155 | s->packet = rdata->packet; | ||
| 156 | s->packet_length = rdata->packet_length; | ||
| 157 | memcpy(&(s->s3->rbuf), &(rdata->rbuf), sizeof(SSL3_BUFFER)); | ||
| 158 | memcpy(&(s->s3->rrec), &(rdata->rrec), sizeof(SSL3_RECORD)); | ||
| 159 | |||
| 160 | return(1); | ||
| 161 | } | ||
| 162 | |||
| 163 | |||
| 164 | static int | ||
| 165 | dtls1_buffer_record(SSL *s, record_pqueue *queue, PQ_64BIT priority) | ||
| 166 | { | ||
| 167 | DTLS1_RECORD_DATA *rdata; | ||
| 168 | pitem *item; | ||
| 169 | |||
| 170 | rdata = OPENSSL_malloc(sizeof(DTLS1_RECORD_DATA)); | ||
| 171 | item = pitem_new(priority, rdata); | ||
| 172 | if (rdata == NULL || item == NULL) | ||
| 173 | { | ||
| 174 | if (rdata != NULL) OPENSSL_free(rdata); | ||
| 175 | if (item != NULL) pitem_free(item); | ||
| 176 | |||
| 177 | SSLerr(SSL_F_DTLS1_BUFFER_RECORD, ERR_R_INTERNAL_ERROR); | ||
| 178 | return(0); | ||
| 179 | } | ||
| 180 | |||
| 181 | rdata->packet = s->packet; | ||
| 182 | rdata->packet_length = s->packet_length; | ||
| 183 | memcpy(&(rdata->rbuf), &(s->s3->rbuf), sizeof(SSL3_BUFFER)); | ||
| 184 | memcpy(&(rdata->rrec), &(s->s3->rrec), sizeof(SSL3_RECORD)); | ||
| 185 | |||
| 186 | item->data = rdata; | ||
| 187 | |||
| 188 | /* insert should not fail, since duplicates are dropped */ | ||
| 189 | if (pqueue_insert(queue->q, item) == NULL) | ||
| 190 | { | ||
| 191 | OPENSSL_free(rdata); | ||
| 192 | pitem_free(item); | ||
| 193 | return(0); | ||
| 194 | } | ||
| 195 | |||
| 196 | s->packet = NULL; | ||
| 197 | s->packet_length = 0; | ||
| 198 | memset(&(s->s3->rbuf), 0, sizeof(SSL3_BUFFER)); | ||
| 199 | memset(&(s->s3->rrec), 0, sizeof(SSL3_RECORD)); | ||
| 200 | |||
| 201 | if (!ssl3_setup_buffers(s)) | ||
| 202 | { | ||
| 203 | SSLerr(SSL_F_DTLS1_BUFFER_RECORD, ERR_R_INTERNAL_ERROR); | ||
| 204 | OPENSSL_free(rdata); | ||
| 205 | pitem_free(item); | ||
| 206 | return(0); | ||
| 207 | } | ||
| 208 | |||
| 209 | return(1); | ||
| 210 | } | ||
| 211 | |||
| 212 | |||
| 213 | static int | ||
| 214 | dtls1_retrieve_buffered_record(SSL *s, record_pqueue *queue) | ||
| 215 | { | ||
| 216 | pitem *item; | ||
| 217 | |||
| 218 | item = pqueue_pop(queue->q); | ||
| 219 | if (item) | ||
| 220 | { | ||
| 221 | dtls1_copy_record(s, item); | ||
| 222 | |||
| 223 | OPENSSL_free(item->data); | ||
| 224 | pitem_free(item); | ||
| 225 | |||
| 226 | return(1); | ||
| 227 | } | ||
| 228 | |||
| 229 | return(0); | ||
| 230 | } | ||
| 231 | |||
| 232 | |||
| 233 | /* retrieve a buffered record that belongs to the new epoch, i.e., not processed | ||
| 234 | * yet */ | ||
| 235 | #define dtls1_get_unprocessed_record(s) \ | ||
| 236 | dtls1_retrieve_buffered_record((s), \ | ||
| 237 | &((s)->d1->unprocessed_rcds)) | ||
| 238 | |||
| 239 | /* retrieve a buffered record that belongs to the current epoch, ie, processed */ | ||
| 240 | #define dtls1_get_processed_record(s) \ | ||
| 241 | dtls1_retrieve_buffered_record((s), \ | ||
| 242 | &((s)->d1->processed_rcds)) | ||
| 243 | |||
| 244 | static int | ||
| 245 | dtls1_process_buffered_records(SSL *s) | ||
| 246 | { | ||
| 247 | pitem *item; | ||
| 248 | |||
| 249 | item = pqueue_peek(s->d1->unprocessed_rcds.q); | ||
| 250 | if (item) | ||
| 251 | { | ||
| 252 | DTLS1_RECORD_DATA *rdata; | ||
| 253 | rdata = (DTLS1_RECORD_DATA *)item->data; | ||
| 254 | |||
| 255 | /* Check if epoch is current. */ | ||
| 256 | if (s->d1->unprocessed_rcds.epoch != s->d1->r_epoch) | ||
| 257 | return(1); /* Nothing to do. */ | ||
| 258 | |||
| 259 | /* Process all the records. */ | ||
| 260 | while (pqueue_peek(s->d1->unprocessed_rcds.q)) | ||
| 261 | { | ||
| 262 | dtls1_get_unprocessed_record(s); | ||
| 263 | if ( ! dtls1_process_record(s)) | ||
| 264 | return(0); | ||
| 265 | dtls1_buffer_record(s, &(s->d1->processed_rcds), | ||
| 266 | s->s3->rrec.seq_num); | ||
| 267 | } | ||
| 268 | } | ||
| 269 | |||
| 270 | /* sync epoch numbers once all the unprocessed records | ||
| 271 | * have been processed */ | ||
| 272 | s->d1->processed_rcds.epoch = s->d1->r_epoch; | ||
| 273 | s->d1->unprocessed_rcds.epoch = s->d1->r_epoch + 1; | ||
| 274 | |||
| 275 | return(1); | ||
| 276 | } | ||
| 277 | |||
| 278 | |||
| 279 | #if 0 | ||
| 280 | |||
| 281 | static int | ||
| 282 | dtls1_get_buffered_record(SSL *s) | ||
| 283 | { | ||
| 284 | pitem *item; | ||
| 285 | PQ_64BIT priority = | ||
| 286 | (((PQ_64BIT)s->d1->handshake_read_seq) << 32) | | ||
| 287 | ((PQ_64BIT)s->d1->r_msg_hdr.frag_off); | ||
| 288 | |||
| 289 | if ( ! SSL_in_init(s)) /* if we're not (re)negotiating, | ||
| 290 | nothing buffered */ | ||
| 291 | return 0; | ||
| 292 | |||
| 293 | |||
| 294 | item = pqueue_peek(s->d1->rcvd_records); | ||
| 295 | if (item && item->priority == priority) | ||
| 296 | { | ||
| 297 | /* Check if we've received the record of interest. It must be | ||
| 298 | * a handshake record, since data records as passed up without | ||
| 299 | * buffering */ | ||
| 300 | DTLS1_RECORD_DATA *rdata; | ||
| 301 | item = pqueue_pop(s->d1->rcvd_records); | ||
| 302 | rdata = (DTLS1_RECORD_DATA *)item->data; | ||
| 303 | |||
| 304 | if (s->s3->rbuf.buf != NULL) | ||
| 305 | OPENSSL_free(s->s3->rbuf.buf); | ||
| 306 | |||
| 307 | s->packet = rdata->packet; | ||
| 308 | s->packet_length = rdata->packet_length; | ||
| 309 | memcpy(&(s->s3->rbuf), &(rdata->rbuf), sizeof(SSL3_BUFFER)); | ||
| 310 | memcpy(&(s->s3->rrec), &(rdata->rrec), sizeof(SSL3_RECORD)); | ||
| 311 | |||
| 312 | OPENSSL_free(item->data); | ||
| 313 | pitem_free(item); | ||
| 314 | |||
| 315 | /* s->d1->next_expected_seq_num++; */ | ||
| 316 | return(1); | ||
| 317 | } | ||
| 318 | |||
| 319 | return 0; | ||
| 320 | } | ||
| 321 | |||
| 322 | #endif | ||
| 323 | |||
| 324 | static int | ||
| 325 | dtls1_process_record(SSL *s) | ||
| 326 | { | ||
| 327 | int i,al; | ||
| 328 | int clear=0; | ||
| 329 | int enc_err; | ||
| 330 | SSL_SESSION *sess; | ||
| 331 | SSL3_RECORD *rr; | ||
| 332 | unsigned int mac_size; | ||
| 333 | unsigned char md[EVP_MAX_MD_SIZE]; | ||
| 334 | |||
| 335 | |||
| 336 | rr= &(s->s3->rrec); | ||
| 337 | sess = s->session; | ||
| 338 | |||
| 339 | /* At this point, s->packet_length == SSL3_RT_HEADER_LNGTH + rr->length, | ||
| 340 | * and we have that many bytes in s->packet | ||
| 341 | */ | ||
| 342 | rr->input= &(s->packet[DTLS1_RT_HEADER_LENGTH]); | ||
| 343 | |||
| 344 | /* ok, we can now read from 's->packet' data into 'rr' | ||
| 345 | * rr->input points at rr->length bytes, which | ||
| 346 | * need to be copied into rr->data by either | ||
| 347 | * the decryption or by the decompression | ||
| 348 | * When the data is 'copied' into the rr->data buffer, | ||
| 349 | * rr->input will be pointed at the new buffer */ | ||
| 350 | |||
| 351 | /* We now have - encrypted [ MAC [ compressed [ plain ] ] ] | ||
| 352 | * rr->length bytes of encrypted compressed stuff. */ | ||
| 353 | |||
| 354 | /* check is not needed I believe */ | ||
| 355 | if (rr->length > SSL3_RT_MAX_ENCRYPTED_LENGTH) | ||
| 356 | { | ||
| 357 | al=SSL_AD_RECORD_OVERFLOW; | ||
| 358 | SSLerr(SSL_F_DTLS1_PROCESS_RECORD,SSL_R_ENCRYPTED_LENGTH_TOO_LONG); | ||
| 359 | goto f_err; | ||
| 360 | } | ||
| 361 | |||
| 362 | /* decrypt in place in 'rr->input' */ | ||
| 363 | rr->data=rr->input; | ||
| 364 | |||
| 365 | enc_err = s->method->ssl3_enc->enc(s,0); | ||
| 366 | if (enc_err <= 0) | ||
| 367 | { | ||
| 368 | if (enc_err == 0) | ||
| 369 | /* SSLerr() and ssl3_send_alert() have been called */ | ||
| 370 | goto err; | ||
| 371 | |||
| 372 | /* otherwise enc_err == -1 */ | ||
| 373 | goto decryption_failed_or_bad_record_mac; | ||
| 374 | } | ||
| 375 | |||
| 376 | #ifdef TLS_DEBUG | ||
| 377 | printf("dec %d\n",rr->length); | ||
| 378 | { unsigned int z; for (z=0; z<rr->length; z++) printf("%02X%c",rr->data[z],((z+1)%16)?' ':'\n'); } | ||
| 379 | printf("\n"); | ||
| 380 | #endif | ||
| 381 | |||
| 382 | /* r->length is now the compressed data plus mac */ | ||
| 383 | if ( (sess == NULL) || | ||
| 384 | (s->enc_read_ctx == NULL) || | ||
| 385 | (s->read_hash == NULL)) | ||
| 386 | clear=1; | ||
| 387 | |||
| 388 | if (!clear) | ||
| 389 | { | ||
| 390 | mac_size=EVP_MD_size(s->read_hash); | ||
| 391 | |||
| 392 | if (rr->length > SSL3_RT_MAX_COMPRESSED_LENGTH+mac_size) | ||
| 393 | { | ||
| 394 | #if 0 /* OK only for stream ciphers (then rr->length is visible from ciphertext anyway) */ | ||
| 395 | al=SSL_AD_RECORD_OVERFLOW; | ||
| 396 | SSLerr(SSL_F_DTLS1_PROCESS_RECORD,SSL_R_PRE_MAC_LENGTH_TOO_LONG); | ||
| 397 | goto f_err; | ||
| 398 | #else | ||
| 399 | goto decryption_failed_or_bad_record_mac; | ||
| 400 | #endif | ||
| 401 | } | ||
| 402 | /* check the MAC for rr->input (it's in mac_size bytes at the tail) */ | ||
| 403 | if (rr->length < mac_size) | ||
| 404 | { | ||
| 405 | #if 0 /* OK only for stream ciphers */ | ||
| 406 | al=SSL_AD_DECODE_ERROR; | ||
| 407 | SSLerr(SSL_F_DTLS1_PROCESS_RECORD,SSL_R_LENGTH_TOO_SHORT); | ||
| 408 | goto f_err; | ||
| 409 | #else | ||
| 410 | goto decryption_failed_or_bad_record_mac; | ||
| 411 | #endif | ||
| 412 | } | ||
| 413 | rr->length-=mac_size; | ||
| 414 | i=s->method->ssl3_enc->mac(s,md,0); | ||
| 415 | if (memcmp(md,&(rr->data[rr->length]),mac_size) != 0) | ||
| 416 | { | ||
| 417 | goto decryption_failed_or_bad_record_mac; | ||
| 418 | } | ||
| 419 | } | ||
| 420 | |||
| 421 | /* r->length is now just compressed */ | ||
| 422 | if (s->expand != NULL) | ||
| 423 | { | ||
| 424 | if (rr->length > SSL3_RT_MAX_COMPRESSED_LENGTH) | ||
| 425 | { | ||
| 426 | al=SSL_AD_RECORD_OVERFLOW; | ||
| 427 | SSLerr(SSL_F_DTLS1_PROCESS_RECORD,SSL_R_COMPRESSED_LENGTH_TOO_LONG); | ||
| 428 | goto f_err; | ||
| 429 | } | ||
| 430 | if (!ssl3_do_uncompress(s)) | ||
| 431 | { | ||
| 432 | al=SSL_AD_DECOMPRESSION_FAILURE; | ||
| 433 | SSLerr(SSL_F_DTLS1_PROCESS_RECORD,SSL_R_BAD_DECOMPRESSION); | ||
| 434 | goto f_err; | ||
| 435 | } | ||
| 436 | } | ||
| 437 | |||
| 438 | if (rr->length > SSL3_RT_MAX_PLAIN_LENGTH) | ||
| 439 | { | ||
| 440 | al=SSL_AD_RECORD_OVERFLOW; | ||
| 441 | SSLerr(SSL_F_DTLS1_PROCESS_RECORD,SSL_R_DATA_LENGTH_TOO_LONG); | ||
| 442 | goto f_err; | ||
| 443 | } | ||
| 444 | |||
| 445 | rr->off=0; | ||
| 446 | /* So at this point the following is true | ||
| 447 | * ssl->s3->rrec.type is the type of record | ||
| 448 | * ssl->s3->rrec.length == number of bytes in record | ||
| 449 | * ssl->s3->rrec.off == offset to first valid byte | ||
| 450 | * ssl->s3->rrec.data == where to take bytes from, increment | ||
| 451 | * after use :-). | ||
| 452 | */ | ||
| 453 | |||
| 454 | /* we have pulled in a full packet so zero things */ | ||
| 455 | s->packet_length=0; | ||
| 456 | dtls1_record_bitmap_update(s, &(s->d1->bitmap));/* Mark receipt of record. */ | ||
| 457 | return(1); | ||
| 458 | |||
| 459 | decryption_failed_or_bad_record_mac: | ||
| 460 | /* Separate 'decryption_failed' alert was introduced with TLS 1.0, | ||
| 461 | * SSL 3.0 only has 'bad_record_mac'. But unless a decryption | ||
| 462 | * failure is directly visible from the ciphertext anyway, | ||
| 463 | * we should not reveal which kind of error occured -- this | ||
| 464 | * might become visible to an attacker (e.g. via logfile) */ | ||
| 465 | al=SSL_AD_BAD_RECORD_MAC; | ||
| 466 | SSLerr(SSL_F_DTLS1_PROCESS_RECORD,SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC); | ||
| 467 | f_err: | ||
| 468 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
| 469 | err: | ||
| 470 | return(0); | ||
| 471 | } | ||
| 472 | |||
| 473 | |||
| 474 | /* Call this to get a new input record. | ||
| 475 | * It will return <= 0 if more data is needed, normally due to an error | ||
| 476 | * or non-blocking IO. | ||
| 477 | * When it finishes, one packet has been decoded and can be found in | ||
| 478 | * ssl->s3->rrec.type - is the type of record | ||
| 479 | * ssl->s3->rrec.data, - data | ||
| 480 | * ssl->s3->rrec.length, - number of bytes | ||
| 481 | */ | ||
| 482 | /* used only by dtls1_read_bytes */ | ||
| 483 | int dtls1_get_record(SSL *s) | ||
| 484 | { | ||
| 485 | int ssl_major,ssl_minor,al; | ||
| 486 | int i,n; | ||
| 487 | SSL3_RECORD *rr; | ||
| 488 | SSL_SESSION *sess; | ||
| 489 | unsigned char *p; | ||
| 490 | unsigned short version; | ||
| 491 | DTLS1_BITMAP *bitmap; | ||
| 492 | unsigned int is_next_epoch; | ||
| 493 | |||
| 494 | rr= &(s->s3->rrec); | ||
| 495 | sess=s->session; | ||
| 496 | |||
| 497 | /* The epoch may have changed. If so, process all the | ||
| 498 | * pending records. This is a non-blocking operation. */ | ||
| 499 | if ( ! dtls1_process_buffered_records(s)) | ||
| 500 | return 0; | ||
| 501 | |||
| 502 | /* if we're renegotiating, then there may be buffered records */ | ||
| 503 | if (dtls1_get_processed_record(s)) | ||
| 504 | return 1; | ||
| 505 | |||
| 506 | /* get something from the wire */ | ||
| 507 | again: | ||
| 508 | /* check if we have the header */ | ||
| 509 | if ( (s->rstate != SSL_ST_READ_BODY) || | ||
| 510 | (s->packet_length < DTLS1_RT_HEADER_LENGTH)) | ||
| 511 | { | ||
| 512 | n=ssl3_read_n(s, DTLS1_RT_HEADER_LENGTH, s->s3->rbuf.len, 0); | ||
| 513 | /* read timeout is handled by dtls1_read_bytes */ | ||
| 514 | if (n <= 0) return(n); /* error or non-blocking */ | ||
| 515 | |||
| 516 | OPENSSL_assert(s->packet_length == DTLS1_RT_HEADER_LENGTH); | ||
| 517 | |||
| 518 | s->rstate=SSL_ST_READ_BODY; | ||
| 519 | |||
| 520 | p=s->packet; | ||
| 521 | |||
| 522 | /* Pull apart the header into the DTLS1_RECORD */ | ||
| 523 | rr->type= *(p++); | ||
| 524 | ssl_major= *(p++); | ||
| 525 | ssl_minor= *(p++); | ||
| 526 | version=(ssl_major<<8)|ssl_minor; | ||
| 527 | |||
| 528 | /* sequence number is 64 bits, with top 2 bytes = epoch */ | ||
| 529 | n2s(p,rr->epoch); | ||
| 530 | |||
| 531 | memcpy(&(s->s3->read_sequence[2]), p, 6); | ||
| 532 | p+=6; | ||
| 533 | |||
| 534 | n2s(p,rr->length); | ||
| 535 | |||
| 536 | /* Lets check version */ | ||
| 537 | if (!s->first_packet) | ||
| 538 | { | ||
| 539 | if (version != s->version && version != DTLS1_BAD_VER) | ||
| 540 | { | ||
| 541 | SSLerr(SSL_F_DTLS1_GET_RECORD,SSL_R_WRONG_VERSION_NUMBER); | ||
| 542 | /* Send back error using their | ||
| 543 | * version number :-) */ | ||
| 544 | s->version=version; | ||
| 545 | al=SSL_AD_PROTOCOL_VERSION; | ||
| 546 | goto f_err; | ||
| 547 | } | ||
| 548 | } | ||
| 549 | |||
| 550 | if ((version & 0xff00) != (DTLS1_VERSION & 0xff00) && | ||
| 551 | (version & 0xff00) != (DTLS1_BAD_VER & 0xff00)) | ||
| 552 | { | ||
| 553 | SSLerr(SSL_F_DTLS1_GET_RECORD,SSL_R_WRONG_VERSION_NUMBER); | ||
| 554 | goto err; | ||
| 555 | } | ||
| 556 | |||
| 557 | if (rr->length > SSL3_RT_MAX_ENCRYPTED_LENGTH) | ||
| 558 | { | ||
| 559 | al=SSL_AD_RECORD_OVERFLOW; | ||
| 560 | SSLerr(SSL_F_DTLS1_GET_RECORD,SSL_R_PACKET_LENGTH_TOO_LONG); | ||
| 561 | goto f_err; | ||
| 562 | } | ||
| 563 | |||
| 564 | s->client_version = version; | ||
| 565 | /* now s->rstate == SSL_ST_READ_BODY */ | ||
| 566 | } | ||
| 567 | |||
| 568 | /* s->rstate == SSL_ST_READ_BODY, get and decode the data */ | ||
| 569 | |||
| 570 | if (rr->length > s->packet_length-DTLS1_RT_HEADER_LENGTH) | ||
| 571 | { | ||
| 572 | /* now s->packet_length == DTLS1_RT_HEADER_LENGTH */ | ||
| 573 | i=rr->length; | ||
| 574 | n=ssl3_read_n(s,i,i,1); | ||
| 575 | if (n <= 0) return(n); /* error or non-blocking io */ | ||
| 576 | |||
| 577 | /* this packet contained a partial record, dump it */ | ||
| 578 | if ( n != i) | ||
| 579 | { | ||
| 580 | s->packet_length = 0; | ||
| 581 | goto again; | ||
| 582 | } | ||
| 583 | |||
| 584 | /* now n == rr->length, | ||
| 585 | * and s->packet_length == DTLS1_RT_HEADER_LENGTH + rr->length */ | ||
| 586 | } | ||
| 587 | s->rstate=SSL_ST_READ_HEADER; /* set state for later operations */ | ||
| 588 | |||
| 589 | /* match epochs. NULL means the packet is dropped on the floor */ | ||
| 590 | bitmap = dtls1_get_bitmap(s, rr, &is_next_epoch); | ||
| 591 | if ( bitmap == NULL) | ||
| 592 | { | ||
| 593 | s->packet_length = 0; /* dump this record */ | ||
| 594 | goto again; /* get another record */ | ||
| 595 | } | ||
| 596 | |||
| 597 | /* check whether this is a repeat, or aged record */ | ||
| 598 | if ( ! dtls1_record_replay_check(s, bitmap, &(rr->seq_num))) | ||
| 599 | { | ||
| 600 | s->packet_length=0; /* dump this record */ | ||
| 601 | goto again; /* get another record */ | ||
| 602 | } | ||
| 603 | |||
| 604 | /* just read a 0 length packet */ | ||
| 605 | if (rr->length == 0) goto again; | ||
| 606 | |||
| 607 | /* If this record is from the next epoch (either HM or ALERT), buffer it | ||
| 608 | * since it cannot be processed at this time. | ||
| 609 | * Records from the next epoch are marked as received even though they are | ||
| 610 | * not processed, so as to prevent any potential resource DoS attack */ | ||
| 611 | if (is_next_epoch) | ||
| 612 | { | ||
| 613 | dtls1_record_bitmap_update(s, bitmap); | ||
| 614 | dtls1_buffer_record(s, &(s->d1->unprocessed_rcds), rr->seq_num); | ||
| 615 | s->packet_length = 0; | ||
| 616 | goto again; | ||
| 617 | } | ||
| 618 | |||
| 619 | if ( ! dtls1_process_record(s)) | ||
| 620 | return(0); | ||
| 621 | |||
| 622 | dtls1_clear_timeouts(s); /* done waiting */ | ||
| 623 | return(1); | ||
| 624 | |||
| 625 | f_err: | ||
| 626 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
| 627 | err: | ||
| 628 | return(0); | ||
| 629 | } | ||
| 630 | |||
| 631 | /* Return up to 'len' payload bytes received in 'type' records. | ||
| 632 | * 'type' is one of the following: | ||
| 633 | * | ||
| 634 | * - SSL3_RT_HANDSHAKE (when ssl3_get_message calls us) | ||
| 635 | * - SSL3_RT_APPLICATION_DATA (when ssl3_read calls us) | ||
| 636 | * - 0 (during a shutdown, no data has to be returned) | ||
| 637 | * | ||
| 638 | * If we don't have stored data to work from, read a SSL/TLS record first | ||
| 639 | * (possibly multiple records if we still don't have anything to return). | ||
| 640 | * | ||
| 641 | * This function must handle any surprises the peer may have for us, such as | ||
| 642 | * Alert records (e.g. close_notify), ChangeCipherSpec records (not really | ||
| 643 | * a surprise, but handled as if it were), or renegotiation requests. | ||
| 644 | * Also if record payloads contain fragments too small to process, we store | ||
| 645 | * them until there is enough for the respective protocol (the record protocol | ||
| 646 | * may use arbitrary fragmentation and even interleaving): | ||
| 647 | * Change cipher spec protocol | ||
| 648 | * just 1 byte needed, no need for keeping anything stored | ||
| 649 | * Alert protocol | ||
| 650 | * 2 bytes needed (AlertLevel, AlertDescription) | ||
| 651 | * Handshake protocol | ||
| 652 | * 4 bytes needed (HandshakeType, uint24 length) -- we just have | ||
| 653 | * to detect unexpected Client Hello and Hello Request messages | ||
| 654 | * here, anything else is handled by higher layers | ||
| 655 | * Application data protocol | ||
| 656 | * none of our business | ||
| 657 | */ | ||
| 658 | int dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek) | ||
| 659 | { | ||
| 660 | int al,i,j,ret; | ||
| 661 | unsigned int n; | ||
| 662 | SSL3_RECORD *rr; | ||
| 663 | void (*cb)(const SSL *ssl,int type2,int val)=NULL; | ||
| 664 | |||
| 665 | if (s->s3->rbuf.buf == NULL) /* Not initialized yet */ | ||
| 666 | if (!ssl3_setup_buffers(s)) | ||
| 667 | return(-1); | ||
| 668 | |||
| 669 | /* XXX: check what the second '&& type' is about */ | ||
| 670 | if ((type && (type != SSL3_RT_APPLICATION_DATA) && | ||
| 671 | (type != SSL3_RT_HANDSHAKE) && type) || | ||
| 672 | (peek && (type != SSL3_RT_APPLICATION_DATA))) | ||
| 673 | { | ||
| 674 | SSLerr(SSL_F_DTLS1_READ_BYTES, ERR_R_INTERNAL_ERROR); | ||
| 675 | return -1; | ||
| 676 | } | ||
| 677 | |||
| 678 | /* check whether there's a handshake message (client hello?) waiting */ | ||
| 679 | if ( (ret = have_handshake_fragment(s, type, buf, len, peek))) | ||
| 680 | return ret; | ||
| 681 | |||
| 682 | /* Now s->d1->handshake_fragment_len == 0 if type == SSL3_RT_HANDSHAKE. */ | ||
| 683 | |||
| 684 | if (!s->in_handshake && SSL_in_init(s)) | ||
| 685 | { | ||
| 686 | /* type == SSL3_RT_APPLICATION_DATA */ | ||
| 687 | i=s->handshake_func(s); | ||
| 688 | if (i < 0) return(i); | ||
| 689 | if (i == 0) | ||
| 690 | { | ||
| 691 | SSLerr(SSL_F_DTLS1_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE); | ||
| 692 | return(-1); | ||
| 693 | } | ||
| 694 | } | ||
| 695 | |||
| 696 | start: | ||
| 697 | s->rwstate=SSL_NOTHING; | ||
| 698 | |||
| 699 | /* s->s3->rrec.type - is the type of record | ||
| 700 | * s->s3->rrec.data, - data | ||
| 701 | * s->s3->rrec.off, - offset into 'data' for next read | ||
| 702 | * s->s3->rrec.length, - number of bytes. */ | ||
| 703 | rr = &(s->s3->rrec); | ||
| 704 | |||
| 705 | /* get new packet if necessary */ | ||
| 706 | if ((rr->length == 0) || (s->rstate == SSL_ST_READ_BODY)) | ||
| 707 | { | ||
| 708 | ret=dtls1_get_record(s); | ||
| 709 | if (ret <= 0) | ||
| 710 | { | ||
| 711 | ret = dtls1_read_failed(s, ret); | ||
| 712 | /* anything other than a timeout is an error */ | ||
| 713 | if (ret <= 0) | ||
| 714 | return(ret); | ||
| 715 | else | ||
| 716 | goto start; | ||
| 717 | } | ||
| 718 | } | ||
| 719 | |||
| 720 | /* we now have a packet which can be read and processed */ | ||
| 721 | |||
| 722 | if (s->s3->change_cipher_spec /* set when we receive ChangeCipherSpec, | ||
| 723 | * reset by ssl3_get_finished */ | ||
| 724 | && (rr->type != SSL3_RT_HANDSHAKE)) | ||
| 725 | { | ||
| 726 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
| 727 | SSLerr(SSL_F_DTLS1_READ_BYTES,SSL_R_DATA_BETWEEN_CCS_AND_FINISHED); | ||
| 728 | goto err; | ||
| 729 | } | ||
| 730 | |||
| 731 | /* If the other end has shut down, throw anything we read away | ||
| 732 | * (even in 'peek' mode) */ | ||
| 733 | if (s->shutdown & SSL_RECEIVED_SHUTDOWN) | ||
| 734 | { | ||
| 735 | rr->length=0; | ||
| 736 | s->rwstate=SSL_NOTHING; | ||
| 737 | return(0); | ||
| 738 | } | ||
| 739 | |||
| 740 | |||
| 741 | if (type == rr->type) /* SSL3_RT_APPLICATION_DATA or SSL3_RT_HANDSHAKE */ | ||
| 742 | { | ||
| 743 | /* make sure that we are not getting application data when we | ||
| 744 | * are doing a handshake for the first time */ | ||
| 745 | if (SSL_in_init(s) && (type == SSL3_RT_APPLICATION_DATA) && | ||
| 746 | (s->enc_read_ctx == NULL)) | ||
| 747 | { | ||
| 748 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
| 749 | SSLerr(SSL_F_DTLS1_READ_BYTES,SSL_R_APP_DATA_IN_HANDSHAKE); | ||
| 750 | goto f_err; | ||
| 751 | } | ||
| 752 | |||
| 753 | if (len <= 0) return(len); | ||
| 754 | |||
| 755 | if ((unsigned int)len > rr->length) | ||
| 756 | n = rr->length; | ||
| 757 | else | ||
| 758 | n = (unsigned int)len; | ||
| 759 | |||
| 760 | memcpy(buf,&(rr->data[rr->off]),n); | ||
| 761 | if (!peek) | ||
| 762 | { | ||
| 763 | rr->length-=n; | ||
| 764 | rr->off+=n; | ||
| 765 | if (rr->length == 0) | ||
| 766 | { | ||
| 767 | s->rstate=SSL_ST_READ_HEADER; | ||
| 768 | rr->off=0; | ||
| 769 | } | ||
| 770 | } | ||
| 771 | return(n); | ||
| 772 | } | ||
| 773 | |||
| 774 | |||
| 775 | /* If we get here, then type != rr->type; if we have a handshake | ||
| 776 | * message, then it was unexpected (Hello Request or Client Hello). */ | ||
| 777 | |||
| 778 | /* In case of record types for which we have 'fragment' storage, | ||
| 779 | * fill that so that we can process the data at a fixed place. | ||
| 780 | */ | ||
| 781 | { | ||
| 782 | unsigned int k, dest_maxlen = 0; | ||
| 783 | unsigned char *dest = NULL; | ||
| 784 | unsigned int *dest_len = NULL; | ||
| 785 | |||
| 786 | if (rr->type == SSL3_RT_HANDSHAKE) | ||
| 787 | { | ||
| 788 | dest_maxlen = sizeof s->d1->handshake_fragment; | ||
| 789 | dest = s->d1->handshake_fragment; | ||
| 790 | dest_len = &s->d1->handshake_fragment_len; | ||
| 791 | } | ||
| 792 | else if (rr->type == SSL3_RT_ALERT) | ||
| 793 | { | ||
| 794 | dest_maxlen = sizeof(s->d1->alert_fragment); | ||
| 795 | dest = s->d1->alert_fragment; | ||
| 796 | dest_len = &s->d1->alert_fragment_len; | ||
| 797 | } | ||
| 798 | /* else it's a CCS message, or it's wrong */ | ||
| 799 | else if (rr->type != SSL3_RT_CHANGE_CIPHER_SPEC) | ||
| 800 | { | ||
| 801 | /* Not certain if this is the right error handling */ | ||
| 802 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
| 803 | SSLerr(SSL_F_DTLS1_READ_BYTES,SSL_R_UNEXPECTED_RECORD); | ||
| 804 | goto f_err; | ||
| 805 | } | ||
| 806 | |||
| 807 | |||
| 808 | if (dest_maxlen > 0) | ||
| 809 | { | ||
| 810 | /* XDTLS: In a pathalogical case, the Client Hello | ||
| 811 | * may be fragmented--don't always expect dest_maxlen bytes */ | ||
| 812 | if ( rr->length < dest_maxlen) | ||
| 813 | { | ||
| 814 | s->rstate=SSL_ST_READ_HEADER; | ||
| 815 | rr->length = 0; | ||
| 816 | goto start; | ||
| 817 | } | ||
| 818 | |||
| 819 | /* now move 'n' bytes: */ | ||
| 820 | for ( k = 0; k < dest_maxlen; k++) | ||
| 821 | { | ||
| 822 | dest[k] = rr->data[rr->off++]; | ||
| 823 | rr->length--; | ||
| 824 | } | ||
| 825 | *dest_len = dest_maxlen; | ||
| 826 | } | ||
| 827 | } | ||
| 828 | |||
| 829 | /* s->d1->handshake_fragment_len == 12 iff rr->type == SSL3_RT_HANDSHAKE; | ||
| 830 | * s->d1->alert_fragment_len == 7 iff rr->type == SSL3_RT_ALERT. | ||
| 831 | * (Possibly rr is 'empty' now, i.e. rr->length may be 0.) */ | ||
| 832 | |||
| 833 | /* If we are a client, check for an incoming 'Hello Request': */ | ||
| 834 | if ((!s->server) && | ||
| 835 | (s->d1->handshake_fragment_len >= DTLS1_HM_HEADER_LENGTH) && | ||
| 836 | (s->d1->handshake_fragment[0] == SSL3_MT_HELLO_REQUEST) && | ||
| 837 | (s->session != NULL) && (s->session->cipher != NULL)) | ||
| 838 | { | ||
| 839 | s->d1->handshake_fragment_len = 0; | ||
| 840 | |||
| 841 | if ((s->d1->handshake_fragment[1] != 0) || | ||
| 842 | (s->d1->handshake_fragment[2] != 0) || | ||
| 843 | (s->d1->handshake_fragment[3] != 0)) | ||
| 844 | { | ||
| 845 | al=SSL_AD_DECODE_ERROR; | ||
| 846 | SSLerr(SSL_F_DTLS1_READ_BYTES,SSL_R_BAD_HELLO_REQUEST); | ||
| 847 | goto err; | ||
| 848 | } | ||
| 849 | |||
| 850 | /* no need to check sequence number on HELLO REQUEST messages */ | ||
| 851 | |||
| 852 | if (s->msg_callback) | ||
| 853 | s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE, | ||
| 854 | s->d1->handshake_fragment, 4, s, s->msg_callback_arg); | ||
| 855 | |||
| 856 | if (SSL_is_init_finished(s) && | ||
| 857 | !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS) && | ||
| 858 | !s->s3->renegotiate) | ||
| 859 | { | ||
| 860 | ssl3_renegotiate(s); | ||
| 861 | if (ssl3_renegotiate_check(s)) | ||
| 862 | { | ||
| 863 | i=s->handshake_func(s); | ||
| 864 | if (i < 0) return(i); | ||
| 865 | if (i == 0) | ||
| 866 | { | ||
| 867 | SSLerr(SSL_F_DTLS1_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE); | ||
| 868 | return(-1); | ||
| 869 | } | ||
| 870 | |||
| 871 | if (!(s->mode & SSL_MODE_AUTO_RETRY)) | ||
| 872 | { | ||
| 873 | if (s->s3->rbuf.left == 0) /* no read-ahead left? */ | ||
| 874 | { | ||
| 875 | BIO *bio; | ||
| 876 | /* In the case where we try to read application data, | ||
| 877 | * but we trigger an SSL handshake, we return -1 with | ||
| 878 | * the retry option set. Otherwise renegotiation may | ||
| 879 | * cause nasty problems in the blocking world */ | ||
| 880 | s->rwstate=SSL_READING; | ||
| 881 | bio=SSL_get_rbio(s); | ||
| 882 | BIO_clear_retry_flags(bio); | ||
| 883 | BIO_set_retry_read(bio); | ||
| 884 | return(-1); | ||
| 885 | } | ||
| 886 | } | ||
| 887 | } | ||
| 888 | } | ||
| 889 | /* we either finished a handshake or ignored the request, | ||
| 890 | * now try again to obtain the (application) data we were asked for */ | ||
| 891 | goto start; | ||
| 892 | } | ||
| 893 | |||
| 894 | if (s->d1->alert_fragment_len >= DTLS1_AL_HEADER_LENGTH) | ||
| 895 | { | ||
| 896 | int alert_level = s->d1->alert_fragment[0]; | ||
| 897 | int alert_descr = s->d1->alert_fragment[1]; | ||
| 898 | |||
| 899 | s->d1->alert_fragment_len = 0; | ||
| 900 | |||
| 901 | if (s->msg_callback) | ||
| 902 | s->msg_callback(0, s->version, SSL3_RT_ALERT, | ||
| 903 | s->d1->alert_fragment, 2, s, s->msg_callback_arg); | ||
| 904 | |||
| 905 | if (s->info_callback != NULL) | ||
| 906 | cb=s->info_callback; | ||
| 907 | else if (s->ctx->info_callback != NULL) | ||
| 908 | cb=s->ctx->info_callback; | ||
| 909 | |||
| 910 | if (cb != NULL) | ||
| 911 | { | ||
| 912 | j = (alert_level << 8) | alert_descr; | ||
| 913 | cb(s, SSL_CB_READ_ALERT, j); | ||
| 914 | } | ||
| 915 | |||
| 916 | if (alert_level == 1) /* warning */ | ||
| 917 | { | ||
| 918 | s->s3->warn_alert = alert_descr; | ||
| 919 | if (alert_descr == SSL_AD_CLOSE_NOTIFY) | ||
| 920 | { | ||
| 921 | s->shutdown |= SSL_RECEIVED_SHUTDOWN; | ||
| 922 | return(0); | ||
| 923 | } | ||
| 924 | #if 0 | ||
| 925 | /* XXX: this is a possible improvement in the future */ | ||
| 926 | /* now check if it's a missing record */ | ||
| 927 | if (alert_descr == DTLS1_AD_MISSING_HANDSHAKE_MESSAGE) | ||
| 928 | { | ||
| 929 | unsigned short seq; | ||
| 930 | unsigned int frag_off; | ||
| 931 | unsigned char *p = &(s->d1->alert_fragment[2]); | ||
| 932 | |||
| 933 | n2s(p, seq); | ||
| 934 | n2l3(p, frag_off); | ||
| 935 | |||
| 936 | dtls1_retransmit_message(s, seq, frag_off, &found); | ||
| 937 | if ( ! found && SSL_in_init(s)) | ||
| 938 | { | ||
| 939 | /* fprintf( stderr,"in init = %d\n", SSL_in_init(s)); */ | ||
| 940 | /* requested a message not yet sent, | ||
| 941 | send an alert ourselves */ | ||
| 942 | ssl3_send_alert(s,SSL3_AL_WARNING, | ||
| 943 | DTLS1_AD_MISSING_HANDSHAKE_MESSAGE); | ||
| 944 | } | ||
| 945 | } | ||
| 946 | #endif | ||
| 947 | } | ||
| 948 | else if (alert_level == 2) /* fatal */ | ||
| 949 | { | ||
| 950 | char tmp[16]; | ||
| 951 | |||
| 952 | s->rwstate=SSL_NOTHING; | ||
| 953 | s->s3->fatal_alert = alert_descr; | ||
| 954 | SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_AD_REASON_OFFSET + alert_descr); | ||
| 955 | BIO_snprintf(tmp,sizeof tmp,"%d",alert_descr); | ||
| 956 | ERR_add_error_data(2,"SSL alert number ",tmp); | ||
| 957 | s->shutdown|=SSL_RECEIVED_SHUTDOWN; | ||
| 958 | SSL_CTX_remove_session(s->ctx,s->session); | ||
| 959 | return(0); | ||
| 960 | } | ||
| 961 | else | ||
| 962 | { | ||
| 963 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
| 964 | SSLerr(SSL_F_DTLS1_READ_BYTES,SSL_R_UNKNOWN_ALERT_TYPE); | ||
| 965 | goto f_err; | ||
| 966 | } | ||
| 967 | |||
| 968 | goto start; | ||
| 969 | } | ||
| 970 | |||
| 971 | if (s->shutdown & SSL_SENT_SHUTDOWN) /* but we have not received a shutdown */ | ||
| 972 | { | ||
| 973 | s->rwstate=SSL_NOTHING; | ||
| 974 | rr->length=0; | ||
| 975 | return(0); | ||
| 976 | } | ||
| 977 | |||
| 978 | if (rr->type == SSL3_RT_CHANGE_CIPHER_SPEC) | ||
| 979 | { | ||
| 980 | struct ccs_header_st ccs_hdr; | ||
| 981 | |||
| 982 | dtls1_get_ccs_header(rr->data, &ccs_hdr); | ||
| 983 | |||
| 984 | /* 'Change Cipher Spec' is just a single byte, so we know | ||
| 985 | * exactly what the record payload has to look like */ | ||
| 986 | /* XDTLS: check that epoch is consistent */ | ||
| 987 | if ( (s->client_version == DTLS1_BAD_VER && rr->length != 3) || | ||
| 988 | (s->client_version != DTLS1_BAD_VER && rr->length != DTLS1_CCS_HEADER_LENGTH) || | ||
| 989 | (rr->off != 0) || (rr->data[0] != SSL3_MT_CCS)) | ||
| 990 | { | ||
| 991 | i=SSL_AD_ILLEGAL_PARAMETER; | ||
| 992 | SSLerr(SSL_F_DTLS1_READ_BYTES,SSL_R_BAD_CHANGE_CIPHER_SPEC); | ||
| 993 | goto err; | ||
| 994 | } | ||
| 995 | |||
| 996 | rr->length=0; | ||
| 997 | |||
| 998 | if (s->msg_callback) | ||
| 999 | s->msg_callback(0, s->version, SSL3_RT_CHANGE_CIPHER_SPEC, | ||
| 1000 | rr->data, 1, s, s->msg_callback_arg); | ||
| 1001 | |||
| 1002 | s->s3->change_cipher_spec=1; | ||
| 1003 | if (!ssl3_do_change_cipher_spec(s)) | ||
| 1004 | goto err; | ||
| 1005 | |||
| 1006 | /* do this whenever CCS is processed */ | ||
| 1007 | dtls1_reset_seq_numbers(s, SSL3_CC_READ); | ||
| 1008 | |||
| 1009 | if (s->client_version == DTLS1_BAD_VER) | ||
| 1010 | s->d1->handshake_read_seq++; | ||
| 1011 | |||
| 1012 | goto start; | ||
| 1013 | } | ||
| 1014 | |||
| 1015 | /* Unexpected handshake message (Client Hello, or protocol violation) */ | ||
| 1016 | if ((s->d1->handshake_fragment_len >= DTLS1_HM_HEADER_LENGTH) && | ||
| 1017 | !s->in_handshake) | ||
| 1018 | { | ||
| 1019 | struct hm_header_st msg_hdr; | ||
| 1020 | |||
| 1021 | /* this may just be a stale retransmit */ | ||
| 1022 | dtls1_get_message_header(rr->data, &msg_hdr); | ||
| 1023 | if( rr->epoch != s->d1->r_epoch) | ||
| 1024 | { | ||
| 1025 | rr->length = 0; | ||
| 1026 | goto start; | ||
| 1027 | } | ||
| 1028 | |||
| 1029 | if (((s->state&SSL_ST_MASK) == SSL_ST_OK) && | ||
| 1030 | !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS)) | ||
| 1031 | { | ||
| 1032 | #if 0 /* worked only because C operator preferences are not as expected (and | ||
| 1033 | * because this is not really needed for clients except for detecting | ||
| 1034 | * protocol violations): */ | ||
| 1035 | s->state=SSL_ST_BEFORE|(s->server) | ||
| 1036 | ?SSL_ST_ACCEPT | ||
| 1037 | :SSL_ST_CONNECT; | ||
| 1038 | #else | ||
| 1039 | s->state = s->server ? SSL_ST_ACCEPT : SSL_ST_CONNECT; | ||
| 1040 | #endif | ||
| 1041 | s->new_session=1; | ||
| 1042 | } | ||
| 1043 | i=s->handshake_func(s); | ||
| 1044 | if (i < 0) return(i); | ||
| 1045 | if (i == 0) | ||
| 1046 | { | ||
| 1047 | SSLerr(SSL_F_DTLS1_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE); | ||
| 1048 | return(-1); | ||
| 1049 | } | ||
| 1050 | |||
| 1051 | if (!(s->mode & SSL_MODE_AUTO_RETRY)) | ||
| 1052 | { | ||
| 1053 | if (s->s3->rbuf.left == 0) /* no read-ahead left? */ | ||
| 1054 | { | ||
| 1055 | BIO *bio; | ||
| 1056 | /* In the case where we try to read application data, | ||
| 1057 | * but we trigger an SSL handshake, we return -1 with | ||
| 1058 | * the retry option set. Otherwise renegotiation may | ||
| 1059 | * cause nasty problems in the blocking world */ | ||
| 1060 | s->rwstate=SSL_READING; | ||
| 1061 | bio=SSL_get_rbio(s); | ||
| 1062 | BIO_clear_retry_flags(bio); | ||
| 1063 | BIO_set_retry_read(bio); | ||
| 1064 | return(-1); | ||
| 1065 | } | ||
| 1066 | } | ||
| 1067 | goto start; | ||
| 1068 | } | ||
| 1069 | |||
| 1070 | switch (rr->type) | ||
| 1071 | { | ||
| 1072 | default: | ||
| 1073 | #ifndef OPENSSL_NO_TLS | ||
| 1074 | /* TLS just ignores unknown message types */ | ||
| 1075 | if (s->version == TLS1_VERSION) | ||
| 1076 | { | ||
| 1077 | rr->length = 0; | ||
| 1078 | goto start; | ||
| 1079 | } | ||
| 1080 | #endif | ||
| 1081 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
| 1082 | SSLerr(SSL_F_DTLS1_READ_BYTES,SSL_R_UNEXPECTED_RECORD); | ||
| 1083 | goto f_err; | ||
| 1084 | case SSL3_RT_CHANGE_CIPHER_SPEC: | ||
| 1085 | case SSL3_RT_ALERT: | ||
| 1086 | case SSL3_RT_HANDSHAKE: | ||
| 1087 | /* we already handled all of these, with the possible exception | ||
| 1088 | * of SSL3_RT_HANDSHAKE when s->in_handshake is set, but that | ||
| 1089 | * should not happen when type != rr->type */ | ||
| 1090 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
| 1091 | SSLerr(SSL_F_DTLS1_READ_BYTES,ERR_R_INTERNAL_ERROR); | ||
| 1092 | goto f_err; | ||
| 1093 | case SSL3_RT_APPLICATION_DATA: | ||
| 1094 | /* At this point, we were expecting handshake data, | ||
| 1095 | * but have application data. If the library was | ||
| 1096 | * running inside ssl3_read() (i.e. in_read_app_data | ||
| 1097 | * is set) and it makes sense to read application data | ||
| 1098 | * at this point (session renegotiation not yet started), | ||
| 1099 | * we will indulge it. | ||
| 1100 | */ | ||
| 1101 | if (s->s3->in_read_app_data && | ||
| 1102 | (s->s3->total_renegotiations != 0) && | ||
| 1103 | (( | ||
| 1104 | (s->state & SSL_ST_CONNECT) && | ||
| 1105 | (s->state >= SSL3_ST_CW_CLNT_HELLO_A) && | ||
| 1106 | (s->state <= SSL3_ST_CR_SRVR_HELLO_A) | ||
| 1107 | ) || ( | ||
| 1108 | (s->state & SSL_ST_ACCEPT) && | ||
| 1109 | (s->state <= SSL3_ST_SW_HELLO_REQ_A) && | ||
| 1110 | (s->state >= SSL3_ST_SR_CLNT_HELLO_A) | ||
| 1111 | ) | ||
| 1112 | )) | ||
| 1113 | { | ||
| 1114 | s->s3->in_read_app_data=2; | ||
| 1115 | return(-1); | ||
| 1116 | } | ||
| 1117 | else | ||
| 1118 | { | ||
| 1119 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
| 1120 | SSLerr(SSL_F_DTLS1_READ_BYTES,SSL_R_UNEXPECTED_RECORD); | ||
| 1121 | goto f_err; | ||
| 1122 | } | ||
| 1123 | } | ||
| 1124 | /* not reached */ | ||
| 1125 | |||
| 1126 | f_err: | ||
| 1127 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
| 1128 | err: | ||
| 1129 | return(-1); | ||
| 1130 | } | ||
| 1131 | |||
| 1132 | int | ||
| 1133 | dtls1_write_app_data_bytes(SSL *s, int type, const void *buf_, int len) | ||
| 1134 | { | ||
| 1135 | unsigned int n,tot; | ||
| 1136 | int i; | ||
| 1137 | |||
| 1138 | if (SSL_in_init(s) && !s->in_handshake) | ||
| 1139 | { | ||
| 1140 | i=s->handshake_func(s); | ||
| 1141 | if (i < 0) return(i); | ||
| 1142 | if (i == 0) | ||
| 1143 | { | ||
| 1144 | SSLerr(SSL_F_DTLS1_WRITE_APP_DATA_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE); | ||
| 1145 | return -1; | ||
| 1146 | } | ||
| 1147 | } | ||
| 1148 | |||
| 1149 | tot = s->s3->wnum; | ||
| 1150 | n = len - tot; | ||
| 1151 | |||
| 1152 | while( n) | ||
| 1153 | { | ||
| 1154 | /* dtls1_write_bytes sends one record at a time, sized according to | ||
| 1155 | * the currently known MTU */ | ||
| 1156 | i = dtls1_write_bytes(s, type, buf_, len); | ||
| 1157 | if (i <= 0) return i; | ||
| 1158 | |||
| 1159 | if ((i == (int)n) || | ||
| 1160 | (type == SSL3_RT_APPLICATION_DATA && | ||
| 1161 | (s->mode & SSL_MODE_ENABLE_PARTIAL_WRITE))) | ||
| 1162 | { | ||
| 1163 | /* next chunk of data should get another prepended empty fragment | ||
| 1164 | * in ciphersuites with known-IV weakness: */ | ||
| 1165 | s->s3->empty_fragment_done = 0; | ||
| 1166 | return tot+i; | ||
| 1167 | } | ||
| 1168 | |||
| 1169 | tot += i; | ||
| 1170 | n-=i; | ||
| 1171 | } | ||
| 1172 | |||
| 1173 | return tot; | ||
| 1174 | } | ||
| 1175 | |||
| 1176 | |||
| 1177 | /* this only happens when a client hello is received and a handshake | ||
| 1178 | * is started. */ | ||
| 1179 | static int | ||
| 1180 | have_handshake_fragment(SSL *s, int type, unsigned char *buf, | ||
| 1181 | int len, int peek) | ||
| 1182 | { | ||
| 1183 | |||
| 1184 | if ((type == SSL3_RT_HANDSHAKE) && (s->d1->handshake_fragment_len > 0)) | ||
| 1185 | /* (partially) satisfy request from storage */ | ||
| 1186 | { | ||
| 1187 | unsigned char *src = s->d1->handshake_fragment; | ||
| 1188 | unsigned char *dst = buf; | ||
| 1189 | unsigned int k,n; | ||
| 1190 | |||
| 1191 | /* peek == 0 */ | ||
| 1192 | n = 0; | ||
| 1193 | while ((len > 0) && (s->d1->handshake_fragment_len > 0)) | ||
| 1194 | { | ||
| 1195 | *dst++ = *src++; | ||
| 1196 | len--; s->d1->handshake_fragment_len--; | ||
| 1197 | n++; | ||
| 1198 | } | ||
| 1199 | /* move any remaining fragment bytes: */ | ||
| 1200 | for (k = 0; k < s->d1->handshake_fragment_len; k++) | ||
| 1201 | s->d1->handshake_fragment[k] = *src++; | ||
| 1202 | return n; | ||
| 1203 | } | ||
| 1204 | |||
| 1205 | return 0; | ||
| 1206 | } | ||
| 1207 | |||
| 1208 | |||
| 1209 | |||
| 1210 | |||
| 1211 | /* Call this to write data in records of type 'type' | ||
| 1212 | * It will return <= 0 if not all data has been sent or non-blocking IO. | ||
| 1213 | */ | ||
| 1214 | int dtls1_write_bytes(SSL *s, int type, const void *buf_, int len) | ||
| 1215 | { | ||
| 1216 | const unsigned char *buf=buf_; | ||
| 1217 | unsigned int tot,n,nw; | ||
| 1218 | int i; | ||
| 1219 | unsigned int mtu; | ||
| 1220 | |||
| 1221 | s->rwstate=SSL_NOTHING; | ||
| 1222 | tot=s->s3->wnum; | ||
| 1223 | |||
| 1224 | n=(len-tot); | ||
| 1225 | |||
| 1226 | /* handshake layer figures out MTU for itself, but data records | ||
| 1227 | * are also sent through this interface, so need to figure out MTU */ | ||
| 1228 | #if 0 | ||
| 1229 | mtu = BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_GET_MTU, 0, NULL); | ||
| 1230 | mtu += DTLS1_HM_HEADER_LENGTH; /* HM already inserted */ | ||
| 1231 | #endif | ||
| 1232 | mtu = s->d1->mtu; | ||
| 1233 | |||
| 1234 | if (mtu > SSL3_RT_MAX_PLAIN_LENGTH) | ||
| 1235 | mtu = SSL3_RT_MAX_PLAIN_LENGTH; | ||
| 1236 | |||
| 1237 | if (n > mtu) | ||
| 1238 | nw=mtu; | ||
| 1239 | else | ||
| 1240 | nw=n; | ||
| 1241 | |||
| 1242 | i=do_dtls1_write(s, type, &(buf[tot]), nw, 0); | ||
| 1243 | if (i <= 0) | ||
| 1244 | { | ||
| 1245 | s->s3->wnum=tot; | ||
| 1246 | return i; | ||
| 1247 | } | ||
| 1248 | |||
| 1249 | if ( (int)s->s3->wnum + i == len) | ||
| 1250 | s->s3->wnum = 0; | ||
| 1251 | else | ||
| 1252 | s->s3->wnum += i; | ||
| 1253 | |||
| 1254 | return tot + i; | ||
| 1255 | } | ||
| 1256 | |||
| 1257 | int do_dtls1_write(SSL *s, int type, const unsigned char *buf, unsigned int len, int create_empty_fragment) | ||
| 1258 | { | ||
| 1259 | unsigned char *p,*pseq; | ||
| 1260 | int i,mac_size,clear=0; | ||
| 1261 | int prefix_len = 0; | ||
| 1262 | SSL3_RECORD *wr; | ||
| 1263 | SSL3_BUFFER *wb; | ||
| 1264 | SSL_SESSION *sess; | ||
| 1265 | int bs; | ||
| 1266 | |||
| 1267 | /* first check if there is a SSL3_BUFFER still being written | ||
| 1268 | * out. This will happen with non blocking IO */ | ||
| 1269 | if (s->s3->wbuf.left != 0) | ||
| 1270 | { | ||
| 1271 | OPENSSL_assert(0); /* XDTLS: want to see if we ever get here */ | ||
| 1272 | return(ssl3_write_pending(s,type,buf,len)); | ||
| 1273 | } | ||
| 1274 | |||
| 1275 | /* If we have an alert to send, lets send it */ | ||
| 1276 | if (s->s3->alert_dispatch) | ||
| 1277 | { | ||
| 1278 | i=s->method->ssl_dispatch_alert(s); | ||
| 1279 | if (i <= 0) | ||
| 1280 | return(i); | ||
| 1281 | /* if it went, fall through and send more stuff */ | ||
| 1282 | } | ||
| 1283 | |||
| 1284 | if (len == 0 && !create_empty_fragment) | ||
| 1285 | return 0; | ||
| 1286 | |||
| 1287 | wr= &(s->s3->wrec); | ||
| 1288 | wb= &(s->s3->wbuf); | ||
| 1289 | sess=s->session; | ||
| 1290 | |||
| 1291 | if ( (sess == NULL) || | ||
| 1292 | (s->enc_write_ctx == NULL) || | ||
| 1293 | (s->write_hash == NULL)) | ||
| 1294 | clear=1; | ||
| 1295 | |||
| 1296 | if (clear) | ||
| 1297 | mac_size=0; | ||
| 1298 | else | ||
| 1299 | mac_size=EVP_MD_size(s->write_hash); | ||
| 1300 | |||
| 1301 | /* DTLS implements explicit IV, so no need for empty fragments */ | ||
| 1302 | #if 0 | ||
| 1303 | /* 'create_empty_fragment' is true only when this function calls itself */ | ||
| 1304 | if (!clear && !create_empty_fragment && !s->s3->empty_fragment_done | ||
| 1305 | && SSL_version(s) != DTLS1_VERSION) | ||
| 1306 | { | ||
| 1307 | /* countermeasure against known-IV weakness in CBC ciphersuites | ||
| 1308 | * (see http://www.openssl.org/~bodo/tls-cbc.txt) | ||
| 1309 | */ | ||
| 1310 | |||
| 1311 | if (s->s3->need_empty_fragments && type == SSL3_RT_APPLICATION_DATA) | ||
| 1312 | { | ||
| 1313 | /* recursive function call with 'create_empty_fragment' set; | ||
| 1314 | * this prepares and buffers the data for an empty fragment | ||
| 1315 | * (these 'prefix_len' bytes are sent out later | ||
| 1316 | * together with the actual payload) */ | ||
| 1317 | prefix_len = s->method->do_ssl_write(s, type, buf, 0, 1); | ||
| 1318 | if (prefix_len <= 0) | ||
| 1319 | goto err; | ||
| 1320 | |||
| 1321 | if (s->s3->wbuf.len < (size_t)prefix_len + SSL3_RT_MAX_PACKET_SIZE) | ||
| 1322 | { | ||
| 1323 | /* insufficient space */ | ||
| 1324 | SSLerr(SSL_F_DO_DTLS1_WRITE, ERR_R_INTERNAL_ERROR); | ||
| 1325 | goto err; | ||
| 1326 | } | ||
| 1327 | } | ||
| 1328 | |||
| 1329 | s->s3->empty_fragment_done = 1; | ||
| 1330 | } | ||
| 1331 | #endif | ||
| 1332 | |||
| 1333 | p = wb->buf + prefix_len; | ||
| 1334 | |||
| 1335 | /* write the header */ | ||
| 1336 | |||
| 1337 | *(p++)=type&0xff; | ||
| 1338 | wr->type=type; | ||
| 1339 | |||
| 1340 | if (s->client_version == DTLS1_BAD_VER) | ||
| 1341 | *(p++) = DTLS1_BAD_VER>>8, | ||
| 1342 | *(p++) = DTLS1_BAD_VER&0xff; | ||
| 1343 | else | ||
| 1344 | *(p++)=(s->version>>8), | ||
| 1345 | *(p++)=s->version&0xff; | ||
| 1346 | |||
| 1347 | /* field where we are to write out packet epoch, seq num and len */ | ||
| 1348 | pseq=p; | ||
| 1349 | p+=10; | ||
| 1350 | |||
| 1351 | /* lets setup the record stuff. */ | ||
| 1352 | |||
| 1353 | /* Make space for the explicit IV in case of CBC. | ||
| 1354 | * (this is a bit of a boundary violation, but what the heck). | ||
| 1355 | */ | ||
| 1356 | if ( s->enc_write_ctx && | ||
| 1357 | (EVP_CIPHER_mode( s->enc_write_ctx->cipher ) & EVP_CIPH_CBC_MODE)) | ||
| 1358 | bs = EVP_CIPHER_block_size(s->enc_write_ctx->cipher); | ||
| 1359 | else | ||
| 1360 | bs = 0; | ||
| 1361 | |||
| 1362 | wr->data=p + bs; /* make room for IV in case of CBC */ | ||
| 1363 | wr->length=(int)len; | ||
| 1364 | wr->input=(unsigned char *)buf; | ||
| 1365 | |||
| 1366 | /* we now 'read' from wr->input, wr->length bytes into | ||
| 1367 | * wr->data */ | ||
| 1368 | |||
| 1369 | /* first we compress */ | ||
| 1370 | if (s->compress != NULL) | ||
| 1371 | { | ||
| 1372 | if (!ssl3_do_compress(s)) | ||
| 1373 | { | ||
| 1374 | SSLerr(SSL_F_DO_DTLS1_WRITE,SSL_R_COMPRESSION_FAILURE); | ||
| 1375 | goto err; | ||
| 1376 | } | ||
| 1377 | } | ||
| 1378 | else | ||
| 1379 | { | ||
| 1380 | memcpy(wr->data,wr->input,wr->length); | ||
| 1381 | wr->input=wr->data; | ||
| 1382 | } | ||
| 1383 | |||
| 1384 | /* we should still have the output to wr->data and the input | ||
| 1385 | * from wr->input. Length should be wr->length. | ||
| 1386 | * wr->data still points in the wb->buf */ | ||
| 1387 | |||
| 1388 | if (mac_size != 0) | ||
| 1389 | { | ||
| 1390 | s->method->ssl3_enc->mac(s,&(p[wr->length + bs]),1); | ||
| 1391 | wr->length+=mac_size; | ||
| 1392 | } | ||
| 1393 | |||
| 1394 | /* this is true regardless of mac size */ | ||
| 1395 | wr->input=p; | ||
| 1396 | wr->data=p; | ||
| 1397 | |||
| 1398 | |||
| 1399 | /* ssl3_enc can only have an error on read */ | ||
| 1400 | if (bs) /* bs != 0 in case of CBC */ | ||
| 1401 | { | ||
| 1402 | RAND_pseudo_bytes(p,bs); | ||
| 1403 | /* master IV and last CBC residue stand for | ||
| 1404 | * the rest of randomness */ | ||
| 1405 | wr->length += bs; | ||
| 1406 | } | ||
| 1407 | |||
| 1408 | s->method->ssl3_enc->enc(s,1); | ||
| 1409 | |||
| 1410 | /* record length after mac and block padding */ | ||
| 1411 | /* if (type == SSL3_RT_APPLICATION_DATA || | ||
| 1412 | (type == SSL3_RT_ALERT && ! SSL_in_init(s))) */ | ||
| 1413 | |||
| 1414 | /* there's only one epoch between handshake and app data */ | ||
| 1415 | |||
| 1416 | s2n(s->d1->w_epoch, pseq); | ||
| 1417 | |||
| 1418 | /* XDTLS: ?? */ | ||
| 1419 | /* else | ||
| 1420 | s2n(s->d1->handshake_epoch, pseq); */ | ||
| 1421 | |||
| 1422 | memcpy(pseq, &(s->s3->write_sequence[2]), 6); | ||
| 1423 | pseq+=6; | ||
| 1424 | s2n(wr->length,pseq); | ||
| 1425 | |||
| 1426 | /* we should now have | ||
| 1427 | * wr->data pointing to the encrypted data, which is | ||
| 1428 | * wr->length long */ | ||
| 1429 | wr->type=type; /* not needed but helps for debugging */ | ||
| 1430 | wr->length+=DTLS1_RT_HEADER_LENGTH; | ||
| 1431 | |||
| 1432 | #if 0 /* this is now done at the message layer */ | ||
| 1433 | /* buffer the record, making it easy to handle retransmits */ | ||
| 1434 | if ( type == SSL3_RT_HANDSHAKE || type == SSL3_RT_CHANGE_CIPHER_SPEC) | ||
| 1435 | dtls1_buffer_record(s, wr->data, wr->length, | ||
| 1436 | *((PQ_64BIT *)&(s->s3->write_sequence[0]))); | ||
| 1437 | #endif | ||
| 1438 | |||
| 1439 | ssl3_record_sequence_update(&(s->s3->write_sequence[0])); | ||
| 1440 | |||
| 1441 | if (create_empty_fragment) | ||
| 1442 | { | ||
| 1443 | /* we are in a recursive call; | ||
| 1444 | * just return the length, don't write out anything here | ||
| 1445 | */ | ||
| 1446 | return wr->length; | ||
| 1447 | } | ||
| 1448 | |||
| 1449 | /* now let's set up wb */ | ||
| 1450 | wb->left = prefix_len + wr->length; | ||
| 1451 | wb->offset = 0; | ||
| 1452 | |||
| 1453 | /* memorize arguments so that ssl3_write_pending can detect bad write retries later */ | ||
| 1454 | s->s3->wpend_tot=len; | ||
| 1455 | s->s3->wpend_buf=buf; | ||
| 1456 | s->s3->wpend_type=type; | ||
| 1457 | s->s3->wpend_ret=len; | ||
| 1458 | |||
| 1459 | /* we now just need to write the buffer */ | ||
| 1460 | return ssl3_write_pending(s,type,buf,len); | ||
| 1461 | err: | ||
| 1462 | return -1; | ||
| 1463 | } | ||
| 1464 | |||
| 1465 | |||
| 1466 | |||
| 1467 | static int dtls1_record_replay_check(SSL *s, DTLS1_BITMAP *bitmap, | ||
| 1468 | PQ_64BIT *seq_num) | ||
| 1469 | { | ||
| 1470 | #if PQ_64BIT_IS_INTEGER | ||
| 1471 | PQ_64BIT mask = 0x0000000000000001L; | ||
| 1472 | #endif | ||
| 1473 | PQ_64BIT rcd_num, tmp; | ||
| 1474 | |||
| 1475 | pq_64bit_init(&rcd_num); | ||
| 1476 | pq_64bit_init(&tmp); | ||
| 1477 | |||
| 1478 | /* this is the sequence number for the record just read */ | ||
| 1479 | pq_64bit_bin2num(&rcd_num, s->s3->read_sequence, 8); | ||
| 1480 | |||
| 1481 | |||
| 1482 | if (pq_64bit_gt(&rcd_num, &(bitmap->max_seq_num)) || | ||
| 1483 | pq_64bit_eq(&rcd_num, &(bitmap->max_seq_num))) | ||
| 1484 | { | ||
| 1485 | pq_64bit_assign(seq_num, &rcd_num); | ||
| 1486 | pq_64bit_free(&rcd_num); | ||
| 1487 | pq_64bit_free(&tmp); | ||
| 1488 | return 1; /* this record is new */ | ||
| 1489 | } | ||
| 1490 | |||
| 1491 | pq_64bit_sub(&tmp, &(bitmap->max_seq_num), &rcd_num); | ||
| 1492 | |||
| 1493 | if ( pq_64bit_get_word(&tmp) > bitmap->length) | ||
| 1494 | { | ||
| 1495 | pq_64bit_free(&rcd_num); | ||
| 1496 | pq_64bit_free(&tmp); | ||
| 1497 | return 0; /* stale, outside the window */ | ||
| 1498 | } | ||
| 1499 | |||
| 1500 | #if PQ_64BIT_IS_BIGNUM | ||
| 1501 | { | ||
| 1502 | int offset; | ||
| 1503 | pq_64bit_sub(&tmp, &(bitmap->max_seq_num), &rcd_num); | ||
| 1504 | pq_64bit_sub_word(&tmp, 1); | ||
| 1505 | offset = pq_64bit_get_word(&tmp); | ||
| 1506 | if ( pq_64bit_is_bit_set(&(bitmap->map), offset)) | ||
| 1507 | { | ||
| 1508 | pq_64bit_free(&rcd_num); | ||
| 1509 | pq_64bit_free(&tmp); | ||
| 1510 | return 0; | ||
| 1511 | } | ||
| 1512 | } | ||
| 1513 | #else | ||
| 1514 | mask <<= (bitmap->max_seq_num - rcd_num - 1); | ||
| 1515 | if (bitmap->map & mask) | ||
| 1516 | return 0; /* record previously received */ | ||
| 1517 | #endif | ||
| 1518 | |||
| 1519 | pq_64bit_assign(seq_num, &rcd_num); | ||
| 1520 | pq_64bit_free(&rcd_num); | ||
| 1521 | pq_64bit_free(&tmp); | ||
| 1522 | return 1; | ||
| 1523 | } | ||
| 1524 | |||
| 1525 | |||
| 1526 | static void dtls1_record_bitmap_update(SSL *s, DTLS1_BITMAP *bitmap) | ||
| 1527 | { | ||
| 1528 | unsigned int shift; | ||
| 1529 | PQ_64BIT rcd_num; | ||
| 1530 | PQ_64BIT tmp; | ||
| 1531 | PQ_64BIT_CTX *ctx; | ||
| 1532 | |||
| 1533 | pq_64bit_init(&rcd_num); | ||
| 1534 | pq_64bit_init(&tmp); | ||
| 1535 | |||
| 1536 | pq_64bit_bin2num(&rcd_num, s->s3->read_sequence, 8); | ||
| 1537 | |||
| 1538 | /* unfortunate code complexity due to 64-bit manipulation support | ||
| 1539 | * on 32-bit machines */ | ||
| 1540 | if ( pq_64bit_gt(&rcd_num, &(bitmap->max_seq_num)) || | ||
| 1541 | pq_64bit_eq(&rcd_num, &(bitmap->max_seq_num))) | ||
| 1542 | { | ||
| 1543 | pq_64bit_sub(&tmp, &rcd_num, &(bitmap->max_seq_num)); | ||
| 1544 | pq_64bit_add_word(&tmp, 1); | ||
| 1545 | |||
| 1546 | shift = (unsigned int)pq_64bit_get_word(&tmp); | ||
| 1547 | |||
| 1548 | pq_64bit_lshift(&(tmp), &(bitmap->map), shift); | ||
| 1549 | pq_64bit_assign(&(bitmap->map), &tmp); | ||
| 1550 | |||
| 1551 | pq_64bit_set_bit(&(bitmap->map), 0); | ||
| 1552 | pq_64bit_add_word(&rcd_num, 1); | ||
| 1553 | pq_64bit_assign(&(bitmap->max_seq_num), &rcd_num); | ||
| 1554 | |||
| 1555 | pq_64bit_assign_word(&tmp, 1); | ||
| 1556 | pq_64bit_lshift(&tmp, &tmp, bitmap->length); | ||
| 1557 | ctx = pq_64bit_ctx_new(&ctx); | ||
| 1558 | pq_64bit_mod(&(bitmap->map), &(bitmap->map), &tmp, ctx); | ||
| 1559 | pq_64bit_ctx_free(ctx); | ||
| 1560 | } | ||
| 1561 | else | ||
| 1562 | { | ||
| 1563 | pq_64bit_sub(&tmp, &(bitmap->max_seq_num), &rcd_num); | ||
| 1564 | pq_64bit_sub_word(&tmp, 1); | ||
| 1565 | shift = (unsigned int)pq_64bit_get_word(&tmp); | ||
| 1566 | |||
| 1567 | pq_64bit_set_bit(&(bitmap->map), shift); | ||
| 1568 | } | ||
| 1569 | |||
| 1570 | pq_64bit_free(&rcd_num); | ||
| 1571 | pq_64bit_free(&tmp); | ||
| 1572 | } | ||
| 1573 | |||
| 1574 | |||
| 1575 | int dtls1_dispatch_alert(SSL *s) | ||
| 1576 | { | ||
| 1577 | int i,j; | ||
| 1578 | void (*cb)(const SSL *ssl,int type,int val)=NULL; | ||
| 1579 | unsigned char buf[2 + 2 + 3]; /* alert level + alert desc + message seq +frag_off */ | ||
| 1580 | unsigned char *ptr = &buf[0]; | ||
| 1581 | |||
| 1582 | s->s3->alert_dispatch=0; | ||
| 1583 | |||
| 1584 | memset(buf, 0x00, sizeof(buf)); | ||
| 1585 | *ptr++ = s->s3->send_alert[0]; | ||
| 1586 | *ptr++ = s->s3->send_alert[1]; | ||
| 1587 | |||
| 1588 | if (s->s3->send_alert[1] == DTLS1_AD_MISSING_HANDSHAKE_MESSAGE) | ||
| 1589 | { | ||
| 1590 | s2n(s->d1->handshake_read_seq, ptr); | ||
| 1591 | #if 0 | ||
| 1592 | if ( s->d1->r_msg_hdr.frag_off == 0) /* waiting for a new msg */ | ||
| 1593 | |||
| 1594 | else | ||
| 1595 | s2n(s->d1->r_msg_hdr.seq, ptr); /* partial msg read */ | ||
| 1596 | #endif | ||
| 1597 | |||
| 1598 | #if 0 | ||
| 1599 | fprintf(stderr, "s->d1->handshake_read_seq = %d, s->d1->r_msg_hdr.seq = %d\n",s->d1->handshake_read_seq,s->d1->r_msg_hdr.seq); | ||
| 1600 | #endif | ||
| 1601 | l2n3(s->d1->r_msg_hdr.frag_off, ptr); | ||
| 1602 | } | ||
| 1603 | |||
| 1604 | i = do_dtls1_write(s, SSL3_RT_ALERT, &buf[0], sizeof(buf), 0); | ||
| 1605 | if (i <= 0) | ||
| 1606 | { | ||
| 1607 | s->s3->alert_dispatch=1; | ||
| 1608 | /* fprintf( stderr, "not done with alert\n" ); */ | ||
| 1609 | } | ||
| 1610 | else | ||
| 1611 | { | ||
| 1612 | if ( s->s3->send_alert[0] == SSL3_AL_FATAL || | ||
| 1613 | s->s3->send_alert[1] == DTLS1_AD_MISSING_HANDSHAKE_MESSAGE) | ||
| 1614 | (void)BIO_flush(s->wbio); | ||
| 1615 | |||
| 1616 | if (s->msg_callback) | ||
| 1617 | s->msg_callback(1, s->version, SSL3_RT_ALERT, s->s3->send_alert, | ||
| 1618 | 2, s, s->msg_callback_arg); | ||
| 1619 | |||
| 1620 | if (s->info_callback != NULL) | ||
| 1621 | cb=s->info_callback; | ||
| 1622 | else if (s->ctx->info_callback != NULL) | ||
| 1623 | cb=s->ctx->info_callback; | ||
| 1624 | |||
| 1625 | if (cb != NULL) | ||
| 1626 | { | ||
| 1627 | j=(s->s3->send_alert[0]<<8)|s->s3->send_alert[1]; | ||
| 1628 | cb(s,SSL_CB_WRITE_ALERT,j); | ||
| 1629 | } | ||
| 1630 | } | ||
| 1631 | return(i); | ||
| 1632 | } | ||
| 1633 | |||
| 1634 | |||
| 1635 | static DTLS1_BITMAP * | ||
| 1636 | dtls1_get_bitmap(SSL *s, SSL3_RECORD *rr, unsigned int *is_next_epoch) | ||
| 1637 | { | ||
| 1638 | |||
| 1639 | *is_next_epoch = 0; | ||
| 1640 | |||
| 1641 | /* In current epoch, accept HM, CCS, DATA, & ALERT */ | ||
| 1642 | if (rr->epoch == s->d1->r_epoch) | ||
| 1643 | return &s->d1->bitmap; | ||
| 1644 | |||
| 1645 | /* Only HM and ALERT messages can be from the next epoch */ | ||
| 1646 | else if (rr->epoch == (unsigned long)(s->d1->r_epoch + 1) && | ||
| 1647 | (rr->type == SSL3_RT_HANDSHAKE || | ||
| 1648 | rr->type == SSL3_RT_ALERT)) | ||
| 1649 | { | ||
| 1650 | *is_next_epoch = 1; | ||
| 1651 | return &s->d1->next_bitmap; | ||
| 1652 | } | ||
| 1653 | |||
| 1654 | return NULL; | ||
| 1655 | } | ||
| 1656 | |||
| 1657 | #if 0 | ||
| 1658 | static int | ||
| 1659 | dtls1_record_needs_buffering(SSL *s, SSL3_RECORD *rr, unsigned short *priority, | ||
| 1660 | unsigned long *offset) | ||
| 1661 | { | ||
| 1662 | |||
| 1663 | /* alerts are passed up immediately */ | ||
| 1664 | if ( rr->type == SSL3_RT_APPLICATION_DATA || | ||
| 1665 | rr->type == SSL3_RT_ALERT) | ||
| 1666 | return 0; | ||
| 1667 | |||
| 1668 | /* Only need to buffer if a handshake is underway. | ||
| 1669 | * (this implies that Hello Request and Client Hello are passed up | ||
| 1670 | * immediately) */ | ||
| 1671 | if ( SSL_in_init(s)) | ||
| 1672 | { | ||
| 1673 | unsigned char *data = rr->data; | ||
| 1674 | /* need to extract the HM/CCS sequence number here */ | ||
| 1675 | if ( rr->type == SSL3_RT_HANDSHAKE || | ||
| 1676 | rr->type == SSL3_RT_CHANGE_CIPHER_SPEC) | ||
| 1677 | { | ||
| 1678 | unsigned short seq_num; | ||
| 1679 | struct hm_header_st msg_hdr; | ||
| 1680 | struct ccs_header_st ccs_hdr; | ||
| 1681 | |||
| 1682 | if ( rr->type == SSL3_RT_HANDSHAKE) | ||
| 1683 | { | ||
| 1684 | dtls1_get_message_header(data, &msg_hdr); | ||
| 1685 | seq_num = msg_hdr.seq; | ||
| 1686 | *offset = msg_hdr.frag_off; | ||
| 1687 | } | ||
| 1688 | else | ||
| 1689 | { | ||
| 1690 | dtls1_get_ccs_header(data, &ccs_hdr); | ||
| 1691 | seq_num = ccs_hdr.seq; | ||
| 1692 | *offset = 0; | ||
| 1693 | } | ||
| 1694 | |||
| 1695 | /* this is either a record we're waiting for, or a | ||
| 1696 | * retransmit of something we happened to previously | ||
| 1697 | * receive (higher layers will drop the repeat silently */ | ||
| 1698 | if ( seq_num < s->d1->handshake_read_seq) | ||
| 1699 | return 0; | ||
| 1700 | if (rr->type == SSL3_RT_HANDSHAKE && | ||
| 1701 | seq_num == s->d1->handshake_read_seq && | ||
| 1702 | msg_hdr.frag_off < s->d1->r_msg_hdr.frag_off) | ||
| 1703 | return 0; | ||
| 1704 | else if ( seq_num == s->d1->handshake_read_seq && | ||
| 1705 | (rr->type == SSL3_RT_CHANGE_CIPHER_SPEC || | ||
| 1706 | msg_hdr.frag_off == s->d1->r_msg_hdr.frag_off)) | ||
| 1707 | return 0; | ||
| 1708 | else | ||
| 1709 | { | ||
| 1710 | *priority = seq_num; | ||
| 1711 | return 1; | ||
| 1712 | } | ||
| 1713 | } | ||
| 1714 | else /* unknown record type */ | ||
| 1715 | return 0; | ||
| 1716 | } | ||
| 1717 | |||
| 1718 | return 0; | ||
| 1719 | } | ||
| 1720 | #endif | ||
| 1721 | |||
| 1722 | void | ||
| 1723 | dtls1_reset_seq_numbers(SSL *s, int rw) | ||
| 1724 | { | ||
| 1725 | unsigned char *seq; | ||
| 1726 | unsigned int seq_bytes = sizeof(s->s3->read_sequence); | ||
| 1727 | |||
| 1728 | if ( rw & SSL3_CC_READ) | ||
| 1729 | { | ||
| 1730 | seq = s->s3->read_sequence; | ||
| 1731 | s->d1->r_epoch++; | ||
| 1732 | |||
| 1733 | pq_64bit_assign(&(s->d1->bitmap.map), &(s->d1->next_bitmap.map)); | ||
| 1734 | s->d1->bitmap.length = s->d1->next_bitmap.length; | ||
| 1735 | pq_64bit_assign(&(s->d1->bitmap.max_seq_num), | ||
| 1736 | &(s->d1->next_bitmap.max_seq_num)); | ||
| 1737 | |||
| 1738 | pq_64bit_free(&(s->d1->next_bitmap.map)); | ||
| 1739 | pq_64bit_free(&(s->d1->next_bitmap.max_seq_num)); | ||
| 1740 | memset(&(s->d1->next_bitmap), 0x00, sizeof(DTLS1_BITMAP)); | ||
| 1741 | pq_64bit_init(&(s->d1->next_bitmap.map)); | ||
| 1742 | pq_64bit_init(&(s->d1->next_bitmap.max_seq_num)); | ||
| 1743 | } | ||
| 1744 | else | ||
| 1745 | { | ||
| 1746 | seq = s->s3->write_sequence; | ||
| 1747 | s->d1->w_epoch++; | ||
| 1748 | } | ||
| 1749 | |||
| 1750 | memset(seq, 0x00, seq_bytes); | ||
| 1751 | } | ||
| 1752 | |||
| 1753 | #if PQ_64BIT_IS_INTEGER | ||
| 1754 | static PQ_64BIT | ||
| 1755 | bytes_to_long_long(unsigned char *bytes, PQ_64BIT *num) | ||
| 1756 | { | ||
| 1757 | PQ_64BIT _num; | ||
| 1758 | |||
| 1759 | _num = (((PQ_64BIT)bytes[0]) << 56) | | ||
| 1760 | (((PQ_64BIT)bytes[1]) << 48) | | ||
| 1761 | (((PQ_64BIT)bytes[2]) << 40) | | ||
| 1762 | (((PQ_64BIT)bytes[3]) << 32) | | ||
| 1763 | (((PQ_64BIT)bytes[4]) << 24) | | ||
| 1764 | (((PQ_64BIT)bytes[5]) << 16) | | ||
| 1765 | (((PQ_64BIT)bytes[6]) << 8) | | ||
| 1766 | (((PQ_64BIT)bytes[7]) ); | ||
| 1767 | |||
| 1768 | *num = _num ; | ||
| 1769 | return _num; | ||
| 1770 | } | ||
| 1771 | #endif | ||
| 1772 | |||
| 1773 | |||
| 1774 | static void | ||
| 1775 | dtls1_clear_timeouts(SSL *s) | ||
| 1776 | { | ||
| 1777 | memset(&(s->d1->timeout), 0x00, sizeof(struct dtls1_timeout_st)); | ||
| 1778 | } | ||
diff --git a/src/lib/libssl/d1_srvr.c b/src/lib/libssl/d1_srvr.c new file mode 100644 index 0000000000..927b01f3c4 --- /dev/null +++ b/src/lib/libssl/d1_srvr.c | |||
| @@ -0,0 +1,1147 @@ | |||
| 1 | /* ssl/d1_srvr.c */ | ||
| 2 | /* | ||
| 3 | * DTLS implementation written by Nagendra Modadugu | ||
| 4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. | ||
| 5 | */ | ||
| 6 | /* ==================================================================== | ||
| 7 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. | ||
| 8 | * | ||
| 9 | * Redistribution and use in source and binary forms, with or without | ||
| 10 | * modification, are permitted provided that the following conditions | ||
| 11 | * are met: | ||
| 12 | * | ||
| 13 | * 1. Redistributions of source code must retain the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer. | ||
| 15 | * | ||
| 16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 17 | * notice, this list of conditions and the following disclaimer in | ||
| 18 | * the documentation and/or other materials provided with the | ||
| 19 | * distribution. | ||
| 20 | * | ||
| 21 | * 3. All advertising materials mentioning features or use of this | ||
| 22 | * software must display the following acknowledgment: | ||
| 23 | * "This product includes software developed by the OpenSSL Project | ||
| 24 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 25 | * | ||
| 26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 27 | * endorse or promote products derived from this software without | ||
| 28 | * prior written permission. For written permission, please contact | ||
| 29 | * openssl-core@OpenSSL.org. | ||
| 30 | * | ||
| 31 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 32 | * nor may "OpenSSL" appear in their names without prior written | ||
| 33 | * permission of the OpenSSL Project. | ||
| 34 | * | ||
| 35 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 36 | * acknowledgment: | ||
| 37 | * "This product includes software developed by the OpenSSL Project | ||
| 38 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 39 | * | ||
| 40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 51 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 52 | * ==================================================================== | ||
| 53 | * | ||
| 54 | * This product includes cryptographic software written by Eric Young | ||
| 55 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 56 | * Hudson (tjh@cryptsoft.com). | ||
| 57 | * | ||
| 58 | */ | ||
| 59 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 60 | * All rights reserved. | ||
| 61 | * | ||
| 62 | * This package is an SSL implementation written | ||
| 63 | * by Eric Young (eay@cryptsoft.com). | ||
| 64 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 65 | * | ||
| 66 | * This library is free for commercial and non-commercial use as long as | ||
| 67 | * the following conditions are aheared to. The following conditions | ||
| 68 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 69 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 70 | * included with this distribution is covered by the same copyright terms | ||
| 71 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 72 | * | ||
| 73 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 74 | * the code are not to be removed. | ||
| 75 | * If this package is used in a product, Eric Young should be given attribution | ||
| 76 | * as the author of the parts of the library used. | ||
| 77 | * This can be in the form of a textual message at program startup or | ||
| 78 | * in documentation (online or textual) provided with the package. | ||
| 79 | * | ||
| 80 | * Redistribution and use in source and binary forms, with or without | ||
| 81 | * modification, are permitted provided that the following conditions | ||
| 82 | * are met: | ||
| 83 | * 1. Redistributions of source code must retain the copyright | ||
| 84 | * notice, this list of conditions and the following disclaimer. | ||
| 85 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 86 | * notice, this list of conditions and the following disclaimer in the | ||
| 87 | * documentation and/or other materials provided with the distribution. | ||
| 88 | * 3. All advertising materials mentioning features or use of this software | ||
| 89 | * must display the following acknowledgement: | ||
| 90 | * "This product includes cryptographic software written by | ||
| 91 | * Eric Young (eay@cryptsoft.com)" | ||
| 92 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 93 | * being used are not cryptographic related :-). | ||
| 94 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 95 | * the apps directory (application code) you must include an acknowledgement: | ||
| 96 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 97 | * | ||
| 98 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 99 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 100 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 101 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 102 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 103 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 104 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 105 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 106 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 107 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 108 | * SUCH DAMAGE. | ||
| 109 | * | ||
| 110 | * The licence and distribution terms for any publically available version or | ||
| 111 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 112 | * copied and put under another distribution licence | ||
| 113 | * [including the GNU Public Licence.] | ||
| 114 | */ | ||
| 115 | |||
| 116 | #include <stdio.h> | ||
| 117 | #include "ssl_locl.h" | ||
| 118 | #include <openssl/buffer.h> | ||
| 119 | #include <openssl/rand.h> | ||
| 120 | #include <openssl/objects.h> | ||
| 121 | #include <openssl/evp.h> | ||
| 122 | #include <openssl/x509.h> | ||
| 123 | #include <openssl/md5.h> | ||
| 124 | #ifndef OPENSSL_NO_DH | ||
| 125 | #include <openssl/dh.h> | ||
| 126 | #endif | ||
| 127 | |||
| 128 | static SSL_METHOD *dtls1_get_server_method(int ver); | ||
| 129 | static int dtls1_send_hello_verify_request(SSL *s); | ||
| 130 | |||
| 131 | static SSL_METHOD *dtls1_get_server_method(int ver) | ||
| 132 | { | ||
| 133 | if (ver == DTLS1_VERSION) | ||
| 134 | return(DTLSv1_server_method()); | ||
| 135 | else | ||
| 136 | return(NULL); | ||
| 137 | } | ||
| 138 | |||
| 139 | IMPLEMENT_dtls1_meth_func(DTLSv1_server_method, | ||
| 140 | dtls1_accept, | ||
| 141 | ssl_undefined_function, | ||
| 142 | dtls1_get_server_method) | ||
| 143 | |||
| 144 | int dtls1_accept(SSL *s) | ||
| 145 | { | ||
| 146 | BUF_MEM *buf; | ||
| 147 | unsigned long l,Time=(unsigned long)time(NULL); | ||
| 148 | void (*cb)(const SSL *ssl,int type,int val)=NULL; | ||
| 149 | long num1; | ||
| 150 | int ret= -1; | ||
| 151 | int new_state,state,skip=0; | ||
| 152 | |||
| 153 | RAND_add(&Time,sizeof(Time),0); | ||
| 154 | ERR_clear_error(); | ||
| 155 | clear_sys_error(); | ||
| 156 | |||
| 157 | if (s->info_callback != NULL) | ||
| 158 | cb=s->info_callback; | ||
| 159 | else if (s->ctx->info_callback != NULL) | ||
| 160 | cb=s->ctx->info_callback; | ||
| 161 | |||
| 162 | /* init things to blank */ | ||
| 163 | s->in_handshake++; | ||
| 164 | if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s); | ||
| 165 | |||
| 166 | if (s->cert == NULL) | ||
| 167 | { | ||
| 168 | SSLerr(SSL_F_DTLS1_ACCEPT,SSL_R_NO_CERTIFICATE_SET); | ||
| 169 | return(-1); | ||
| 170 | } | ||
| 171 | |||
| 172 | for (;;) | ||
| 173 | { | ||
| 174 | state=s->state; | ||
| 175 | |||
| 176 | switch (s->state) | ||
| 177 | { | ||
| 178 | case SSL_ST_RENEGOTIATE: | ||
| 179 | s->new_session=1; | ||
| 180 | /* s->state=SSL_ST_ACCEPT; */ | ||
| 181 | |||
| 182 | case SSL_ST_BEFORE: | ||
| 183 | case SSL_ST_ACCEPT: | ||
| 184 | case SSL_ST_BEFORE|SSL_ST_ACCEPT: | ||
| 185 | case SSL_ST_OK|SSL_ST_ACCEPT: | ||
| 186 | |||
| 187 | s->server=1; | ||
| 188 | if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1); | ||
| 189 | |||
| 190 | if ((s->version & 0xff00) != (DTLS1_VERSION & 0xff00)) | ||
| 191 | { | ||
| 192 | SSLerr(SSL_F_DTLS1_ACCEPT, ERR_R_INTERNAL_ERROR); | ||
| 193 | return -1; | ||
| 194 | } | ||
| 195 | s->type=SSL_ST_ACCEPT; | ||
| 196 | |||
| 197 | if (s->init_buf == NULL) | ||
| 198 | { | ||
| 199 | if ((buf=BUF_MEM_new()) == NULL) | ||
| 200 | { | ||
| 201 | ret= -1; | ||
| 202 | goto end; | ||
| 203 | } | ||
| 204 | if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH)) | ||
| 205 | { | ||
| 206 | ret= -1; | ||
| 207 | goto end; | ||
| 208 | } | ||
| 209 | s->init_buf=buf; | ||
| 210 | } | ||
| 211 | |||
| 212 | if (!ssl3_setup_buffers(s)) | ||
| 213 | { | ||
| 214 | ret= -1; | ||
| 215 | goto end; | ||
| 216 | } | ||
| 217 | |||
| 218 | s->init_num=0; | ||
| 219 | |||
| 220 | if (s->state != SSL_ST_RENEGOTIATE) | ||
| 221 | { | ||
| 222 | /* Ok, we now need to push on a buffering BIO so that | ||
| 223 | * the output is sent in a way that TCP likes :-) | ||
| 224 | */ | ||
| 225 | if (!ssl_init_wbio_buffer(s,1)) { ret= -1; goto end; } | ||
| 226 | |||
| 227 | ssl3_init_finished_mac(s); | ||
| 228 | s->state=SSL3_ST_SR_CLNT_HELLO_A; | ||
| 229 | s->ctx->stats.sess_accept++; | ||
| 230 | } | ||
| 231 | else | ||
| 232 | { | ||
| 233 | /* s->state == SSL_ST_RENEGOTIATE, | ||
| 234 | * we will just send a HelloRequest */ | ||
| 235 | s->ctx->stats.sess_accept_renegotiate++; | ||
| 236 | s->state=SSL3_ST_SW_HELLO_REQ_A; | ||
| 237 | } | ||
| 238 | |||
| 239 | if ( (SSL_get_options(s) & SSL_OP_COOKIE_EXCHANGE)) | ||
| 240 | s->d1->send_cookie = 1; | ||
| 241 | else | ||
| 242 | s->d1->send_cookie = 0; | ||
| 243 | |||
| 244 | break; | ||
| 245 | |||
| 246 | case SSL3_ST_SW_HELLO_REQ_A: | ||
| 247 | case SSL3_ST_SW_HELLO_REQ_B: | ||
| 248 | |||
| 249 | s->shutdown=0; | ||
| 250 | ret=dtls1_send_hello_request(s); | ||
| 251 | if (ret <= 0) goto end; | ||
| 252 | s->s3->tmp.next_state=SSL3_ST_SW_HELLO_REQ_C; | ||
| 253 | s->state=SSL3_ST_SW_FLUSH; | ||
| 254 | s->init_num=0; | ||
| 255 | |||
| 256 | ssl3_init_finished_mac(s); | ||
| 257 | break; | ||
| 258 | |||
| 259 | case SSL3_ST_SW_HELLO_REQ_C: | ||
| 260 | s->state=SSL_ST_OK; | ||
| 261 | break; | ||
| 262 | |||
| 263 | case SSL3_ST_SR_CLNT_HELLO_A: | ||
| 264 | case SSL3_ST_SR_CLNT_HELLO_B: | ||
| 265 | case SSL3_ST_SR_CLNT_HELLO_C: | ||
| 266 | |||
| 267 | s->shutdown=0; | ||
| 268 | ret=ssl3_get_client_hello(s); | ||
| 269 | if (ret <= 0) goto end; | ||
| 270 | s->new_session = 2; | ||
| 271 | |||
| 272 | if ( s->d1->send_cookie) | ||
| 273 | s->state = DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A; | ||
| 274 | else | ||
| 275 | s->state = SSL3_ST_SW_SRVR_HELLO_A; | ||
| 276 | |||
| 277 | s->init_num=0; | ||
| 278 | break; | ||
| 279 | |||
| 280 | case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A: | ||
| 281 | case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B: | ||
| 282 | |||
| 283 | ret = dtls1_send_hello_verify_request(s); | ||
| 284 | if ( ret <= 0) goto end; | ||
| 285 | s->d1->send_cookie = 0; | ||
| 286 | s->state=SSL3_ST_SW_FLUSH; | ||
| 287 | s->s3->tmp.next_state=SSL3_ST_SR_CLNT_HELLO_A; | ||
| 288 | |||
| 289 | /* HelloVerifyRequests resets Finished MAC */ | ||
| 290 | if (s->client_version != DTLS1_BAD_VER) | ||
| 291 | ssl3_init_finished_mac(s); | ||
| 292 | break; | ||
| 293 | |||
| 294 | case SSL3_ST_SW_SRVR_HELLO_A: | ||
| 295 | case SSL3_ST_SW_SRVR_HELLO_B: | ||
| 296 | ret=dtls1_send_server_hello(s); | ||
| 297 | if (ret <= 0) goto end; | ||
| 298 | |||
| 299 | if (s->hit) | ||
| 300 | s->state=SSL3_ST_SW_CHANGE_A; | ||
| 301 | else | ||
| 302 | s->state=SSL3_ST_SW_CERT_A; | ||
| 303 | s->init_num=0; | ||
| 304 | break; | ||
| 305 | |||
| 306 | case SSL3_ST_SW_CERT_A: | ||
| 307 | case SSL3_ST_SW_CERT_B: | ||
| 308 | /* Check if it is anon DH */ | ||
| 309 | if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL)) | ||
| 310 | { | ||
| 311 | ret=dtls1_send_server_certificate(s); | ||
| 312 | if (ret <= 0) goto end; | ||
| 313 | } | ||
| 314 | else | ||
| 315 | skip=1; | ||
| 316 | s->state=SSL3_ST_SW_KEY_EXCH_A; | ||
| 317 | s->init_num=0; | ||
| 318 | break; | ||
| 319 | |||
| 320 | case SSL3_ST_SW_KEY_EXCH_A: | ||
| 321 | case SSL3_ST_SW_KEY_EXCH_B: | ||
| 322 | l=s->s3->tmp.new_cipher->algorithms; | ||
| 323 | |||
| 324 | /* clear this, it may get reset by | ||
| 325 | * send_server_key_exchange */ | ||
| 326 | if ((s->options & SSL_OP_EPHEMERAL_RSA) | ||
| 327 | #ifndef OPENSSL_NO_KRB5 | ||
| 328 | && !(l & SSL_KRB5) | ||
| 329 | #endif /* OPENSSL_NO_KRB5 */ | ||
| 330 | ) | ||
| 331 | /* option SSL_OP_EPHEMERAL_RSA sends temporary RSA key | ||
| 332 | * even when forbidden by protocol specs | ||
| 333 | * (handshake may fail as clients are not required to | ||
| 334 | * be able to handle this) */ | ||
| 335 | s->s3->tmp.use_rsa_tmp=1; | ||
| 336 | else | ||
| 337 | s->s3->tmp.use_rsa_tmp=0; | ||
| 338 | |||
| 339 | /* only send if a DH key exchange, fortezza or | ||
| 340 | * RSA but we have a sign only certificate */ | ||
| 341 | if (s->s3->tmp.use_rsa_tmp | ||
| 342 | || (l & (SSL_DH|SSL_kFZA)) | ||
| 343 | || ((l & SSL_kRSA) | ||
| 344 | && (s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL | ||
| 345 | || (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) | ||
| 346 | && EVP_PKEY_size(s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey)*8 > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher) | ||
| 347 | ) | ||
| 348 | ) | ||
| 349 | ) | ||
| 350 | ) | ||
| 351 | { | ||
| 352 | ret=dtls1_send_server_key_exchange(s); | ||
| 353 | if (ret <= 0) goto end; | ||
| 354 | } | ||
| 355 | else | ||
| 356 | skip=1; | ||
| 357 | |||
| 358 | s->state=SSL3_ST_SW_CERT_REQ_A; | ||
| 359 | s->init_num=0; | ||
| 360 | break; | ||
| 361 | |||
| 362 | case SSL3_ST_SW_CERT_REQ_A: | ||
| 363 | case SSL3_ST_SW_CERT_REQ_B: | ||
| 364 | if (/* don't request cert unless asked for it: */ | ||
| 365 | !(s->verify_mode & SSL_VERIFY_PEER) || | ||
| 366 | /* if SSL_VERIFY_CLIENT_ONCE is set, | ||
| 367 | * don't request cert during re-negotiation: */ | ||
| 368 | ((s->session->peer != NULL) && | ||
| 369 | (s->verify_mode & SSL_VERIFY_CLIENT_ONCE)) || | ||
| 370 | /* never request cert in anonymous ciphersuites | ||
| 371 | * (see section "Certificate request" in SSL 3 drafts | ||
| 372 | * and in RFC 2246): */ | ||
| 373 | ((s->s3->tmp.new_cipher->algorithms & SSL_aNULL) && | ||
| 374 | /* ... except when the application insists on verification | ||
| 375 | * (against the specs, but s3_clnt.c accepts this for SSL 3) */ | ||
| 376 | !(s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)) || | ||
| 377 | /* never request cert in Kerberos ciphersuites */ | ||
| 378 | (s->s3->tmp.new_cipher->algorithms & SSL_aKRB5)) | ||
| 379 | { | ||
| 380 | /* no cert request */ | ||
| 381 | skip=1; | ||
| 382 | s->s3->tmp.cert_request=0; | ||
| 383 | s->state=SSL3_ST_SW_SRVR_DONE_A; | ||
| 384 | } | ||
| 385 | else | ||
| 386 | { | ||
| 387 | s->s3->tmp.cert_request=1; | ||
| 388 | ret=dtls1_send_certificate_request(s); | ||
| 389 | if (ret <= 0) goto end; | ||
| 390 | #ifndef NETSCAPE_HANG_BUG | ||
| 391 | s->state=SSL3_ST_SW_SRVR_DONE_A; | ||
| 392 | #else | ||
| 393 | s->state=SSL3_ST_SW_FLUSH; | ||
| 394 | s->s3->tmp.next_state=SSL3_ST_SR_CERT_A; | ||
| 395 | #endif | ||
| 396 | s->init_num=0; | ||
| 397 | } | ||
| 398 | break; | ||
| 399 | |||
| 400 | case SSL3_ST_SW_SRVR_DONE_A: | ||
| 401 | case SSL3_ST_SW_SRVR_DONE_B: | ||
| 402 | ret=dtls1_send_server_done(s); | ||
| 403 | if (ret <= 0) goto end; | ||
| 404 | s->s3->tmp.next_state=SSL3_ST_SR_CERT_A; | ||
| 405 | s->state=SSL3_ST_SW_FLUSH; | ||
| 406 | s->init_num=0; | ||
| 407 | break; | ||
| 408 | |||
| 409 | case SSL3_ST_SW_FLUSH: | ||
| 410 | /* number of bytes to be flushed */ | ||
| 411 | num1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL); | ||
| 412 | if (num1 > 0) | ||
| 413 | { | ||
| 414 | s->rwstate=SSL_WRITING; | ||
| 415 | num1=BIO_flush(s->wbio); | ||
| 416 | if (num1 <= 0) { ret= -1; goto end; } | ||
| 417 | s->rwstate=SSL_NOTHING; | ||
| 418 | } | ||
| 419 | |||
| 420 | s->state=s->s3->tmp.next_state; | ||
| 421 | break; | ||
| 422 | |||
| 423 | case SSL3_ST_SR_CERT_A: | ||
| 424 | case SSL3_ST_SR_CERT_B: | ||
| 425 | /* Check for second client hello (MS SGC) */ | ||
| 426 | ret = ssl3_check_client_hello(s); | ||
| 427 | if (ret <= 0) | ||
| 428 | goto end; | ||
| 429 | if (ret == 2) | ||
| 430 | s->state = SSL3_ST_SR_CLNT_HELLO_C; | ||
| 431 | else { | ||
| 432 | /* could be sent for a DH cert, even if we | ||
| 433 | * have not asked for it :-) */ | ||
| 434 | ret=ssl3_get_client_certificate(s); | ||
| 435 | if (ret <= 0) goto end; | ||
| 436 | s->init_num=0; | ||
| 437 | s->state=SSL3_ST_SR_KEY_EXCH_A; | ||
| 438 | } | ||
| 439 | break; | ||
| 440 | |||
| 441 | case SSL3_ST_SR_KEY_EXCH_A: | ||
| 442 | case SSL3_ST_SR_KEY_EXCH_B: | ||
| 443 | ret=ssl3_get_client_key_exchange(s); | ||
| 444 | if (ret <= 0) goto end; | ||
| 445 | s->state=SSL3_ST_SR_CERT_VRFY_A; | ||
| 446 | s->init_num=0; | ||
| 447 | |||
| 448 | /* We need to get hashes here so if there is | ||
| 449 | * a client cert, it can be verified */ | ||
| 450 | s->method->ssl3_enc->cert_verify_mac(s, | ||
| 451 | &(s->s3->finish_dgst1), | ||
| 452 | &(s->s3->tmp.cert_verify_md[0])); | ||
| 453 | s->method->ssl3_enc->cert_verify_mac(s, | ||
| 454 | &(s->s3->finish_dgst2), | ||
| 455 | &(s->s3->tmp.cert_verify_md[MD5_DIGEST_LENGTH])); | ||
| 456 | |||
| 457 | break; | ||
| 458 | |||
| 459 | case SSL3_ST_SR_CERT_VRFY_A: | ||
| 460 | case SSL3_ST_SR_CERT_VRFY_B: | ||
| 461 | |||
| 462 | /* we should decide if we expected this one */ | ||
| 463 | ret=ssl3_get_cert_verify(s); | ||
| 464 | if (ret <= 0) goto end; | ||
| 465 | |||
| 466 | s->state=SSL3_ST_SR_FINISHED_A; | ||
| 467 | s->init_num=0; | ||
| 468 | break; | ||
| 469 | |||
| 470 | case SSL3_ST_SR_FINISHED_A: | ||
| 471 | case SSL3_ST_SR_FINISHED_B: | ||
| 472 | ret=ssl3_get_finished(s,SSL3_ST_SR_FINISHED_A, | ||
| 473 | SSL3_ST_SR_FINISHED_B); | ||
| 474 | if (ret <= 0) goto end; | ||
| 475 | if (s->hit) | ||
| 476 | s->state=SSL_ST_OK; | ||
| 477 | else | ||
| 478 | s->state=SSL3_ST_SW_CHANGE_A; | ||
| 479 | s->init_num=0; | ||
| 480 | break; | ||
| 481 | |||
| 482 | case SSL3_ST_SW_CHANGE_A: | ||
| 483 | case SSL3_ST_SW_CHANGE_B: | ||
| 484 | |||
| 485 | s->session->cipher=s->s3->tmp.new_cipher; | ||
| 486 | if (!s->method->ssl3_enc->setup_key_block(s)) | ||
| 487 | { ret= -1; goto end; } | ||
| 488 | |||
| 489 | ret=dtls1_send_change_cipher_spec(s, | ||
| 490 | SSL3_ST_SW_CHANGE_A,SSL3_ST_SW_CHANGE_B); | ||
| 491 | |||
| 492 | if (ret <= 0) goto end; | ||
| 493 | s->state=SSL3_ST_SW_FINISHED_A; | ||
| 494 | s->init_num=0; | ||
| 495 | |||
| 496 | if (!s->method->ssl3_enc->change_cipher_state(s, | ||
| 497 | SSL3_CHANGE_CIPHER_SERVER_WRITE)) | ||
| 498 | { | ||
| 499 | ret= -1; | ||
| 500 | goto end; | ||
| 501 | } | ||
| 502 | |||
| 503 | dtls1_reset_seq_numbers(s, SSL3_CC_WRITE); | ||
| 504 | break; | ||
| 505 | |||
| 506 | case SSL3_ST_SW_FINISHED_A: | ||
| 507 | case SSL3_ST_SW_FINISHED_B: | ||
| 508 | ret=dtls1_send_finished(s, | ||
| 509 | SSL3_ST_SW_FINISHED_A,SSL3_ST_SW_FINISHED_B, | ||
| 510 | s->method->ssl3_enc->server_finished_label, | ||
| 511 | s->method->ssl3_enc->server_finished_label_len); | ||
| 512 | if (ret <= 0) goto end; | ||
| 513 | s->state=SSL3_ST_SW_FLUSH; | ||
| 514 | if (s->hit) | ||
| 515 | s->s3->tmp.next_state=SSL3_ST_SR_FINISHED_A; | ||
| 516 | else | ||
| 517 | s->s3->tmp.next_state=SSL_ST_OK; | ||
| 518 | s->init_num=0; | ||
| 519 | break; | ||
| 520 | |||
| 521 | case SSL_ST_OK: | ||
| 522 | /* clean a few things up */ | ||
| 523 | ssl3_cleanup_key_block(s); | ||
| 524 | |||
| 525 | #if 0 | ||
| 526 | BUF_MEM_free(s->init_buf); | ||
| 527 | s->init_buf=NULL; | ||
| 528 | #endif | ||
| 529 | |||
| 530 | /* remove buffering on output */ | ||
| 531 | ssl_free_wbio_buffer(s); | ||
| 532 | |||
| 533 | s->init_num=0; | ||
| 534 | |||
| 535 | if (s->new_session == 2) /* skipped if we just sent a HelloRequest */ | ||
| 536 | { | ||
| 537 | /* actually not necessarily a 'new' session unless | ||
| 538 | * SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION is set */ | ||
| 539 | |||
| 540 | s->new_session=0; | ||
| 541 | |||
| 542 | ssl_update_cache(s,SSL_SESS_CACHE_SERVER); | ||
| 543 | |||
| 544 | s->ctx->stats.sess_accept_good++; | ||
| 545 | /* s->server=1; */ | ||
| 546 | s->handshake_func=dtls1_accept; | ||
| 547 | |||
| 548 | if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1); | ||
| 549 | } | ||
| 550 | |||
| 551 | ret = 1; | ||
| 552 | |||
| 553 | /* done handshaking, next message is client hello */ | ||
| 554 | s->d1->handshake_read_seq = 0; | ||
| 555 | /* next message is server hello */ | ||
| 556 | s->d1->handshake_write_seq = 0; | ||
| 557 | goto end; | ||
| 558 | /* break; */ | ||
| 559 | |||
| 560 | default: | ||
| 561 | SSLerr(SSL_F_DTLS1_ACCEPT,SSL_R_UNKNOWN_STATE); | ||
| 562 | ret= -1; | ||
| 563 | goto end; | ||
| 564 | /* break; */ | ||
| 565 | } | ||
| 566 | |||
| 567 | if (!s->s3->tmp.reuse_message && !skip) | ||
| 568 | { | ||
| 569 | if (s->debug) | ||
| 570 | { | ||
| 571 | if ((ret=BIO_flush(s->wbio)) <= 0) | ||
| 572 | goto end; | ||
| 573 | } | ||
| 574 | |||
| 575 | |||
| 576 | if ((cb != NULL) && (s->state != state)) | ||
| 577 | { | ||
| 578 | new_state=s->state; | ||
| 579 | s->state=state; | ||
| 580 | cb(s,SSL_CB_ACCEPT_LOOP,1); | ||
| 581 | s->state=new_state; | ||
| 582 | } | ||
| 583 | } | ||
| 584 | skip=0; | ||
| 585 | } | ||
| 586 | end: | ||
| 587 | /* BIO_flush(s->wbio); */ | ||
| 588 | |||
| 589 | s->in_handshake--; | ||
| 590 | if (cb != NULL) | ||
| 591 | cb(s,SSL_CB_ACCEPT_EXIT,ret); | ||
| 592 | return(ret); | ||
| 593 | } | ||
| 594 | |||
| 595 | int dtls1_send_hello_request(SSL *s) | ||
| 596 | { | ||
| 597 | unsigned char *p; | ||
| 598 | |||
| 599 | if (s->state == SSL3_ST_SW_HELLO_REQ_A) | ||
| 600 | { | ||
| 601 | p=(unsigned char *)s->init_buf->data; | ||
| 602 | p = dtls1_set_message_header(s, p, SSL3_MT_HELLO_REQUEST, 0, 0, 0); | ||
| 603 | |||
| 604 | s->state=SSL3_ST_SW_HELLO_REQ_B; | ||
| 605 | /* number of bytes to write */ | ||
| 606 | s->init_num=DTLS1_HM_HEADER_LENGTH; | ||
| 607 | s->init_off=0; | ||
| 608 | |||
| 609 | /* no need to buffer this message, since there are no retransmit | ||
| 610 | * requests for it */ | ||
| 611 | } | ||
| 612 | |||
| 613 | /* SSL3_ST_SW_HELLO_REQ_B */ | ||
| 614 | return(dtls1_do_write(s,SSL3_RT_HANDSHAKE)); | ||
| 615 | } | ||
| 616 | |||
| 617 | int dtls1_send_hello_verify_request(SSL *s) | ||
| 618 | { | ||
| 619 | unsigned int msg_len; | ||
| 620 | unsigned char *msg, *buf, *p; | ||
| 621 | |||
| 622 | if (s->state == DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A) | ||
| 623 | { | ||
| 624 | buf = (unsigned char *)s->init_buf->data; | ||
| 625 | |||
| 626 | msg = p = &(buf[DTLS1_HM_HEADER_LENGTH]); | ||
| 627 | if (s->client_version == DTLS1_BAD_VER) | ||
| 628 | *(p++) = DTLS1_BAD_VER>>8, | ||
| 629 | *(p++) = DTLS1_BAD_VER&0xff; | ||
| 630 | else | ||
| 631 | *(p++) = s->version >> 8, | ||
| 632 | *(p++) = s->version & 0xFF; | ||
| 633 | |||
| 634 | if (s->ctx->app_gen_cookie_cb != NULL && | ||
| 635 | s->ctx->app_gen_cookie_cb(s, s->d1->cookie, | ||
| 636 | &(s->d1->cookie_len)) == 0) | ||
| 637 | { | ||
| 638 | SSLerr(SSL_F_DTLS1_SEND_HELLO_VERIFY_REQUEST,ERR_R_INTERNAL_ERROR); | ||
| 639 | return 0; | ||
| 640 | } | ||
| 641 | /* else the cookie is assumed to have | ||
| 642 | * been initialized by the application */ | ||
| 643 | |||
| 644 | *(p++) = (unsigned char) s->d1->cookie_len; | ||
| 645 | memcpy(p, s->d1->cookie, s->d1->cookie_len); | ||
| 646 | p += s->d1->cookie_len; | ||
| 647 | msg_len = p - msg; | ||
| 648 | |||
| 649 | dtls1_set_message_header(s, buf, | ||
| 650 | DTLS1_MT_HELLO_VERIFY_REQUEST, msg_len, 0, msg_len); | ||
| 651 | |||
| 652 | s->state=DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B; | ||
| 653 | /* number of bytes to write */ | ||
| 654 | s->init_num=p-buf; | ||
| 655 | s->init_off=0; | ||
| 656 | |||
| 657 | /* buffer the message to handle re-xmits */ | ||
| 658 | dtls1_buffer_message(s, 0); | ||
| 659 | } | ||
| 660 | |||
| 661 | /* s->state = DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B */ | ||
| 662 | return(dtls1_do_write(s,SSL3_RT_HANDSHAKE)); | ||
| 663 | } | ||
| 664 | |||
| 665 | int dtls1_send_server_hello(SSL *s) | ||
| 666 | { | ||
| 667 | unsigned char *buf; | ||
| 668 | unsigned char *p,*d; | ||
| 669 | int i; | ||
| 670 | unsigned int sl; | ||
| 671 | unsigned long l,Time; | ||
| 672 | |||
| 673 | if (s->state == SSL3_ST_SW_SRVR_HELLO_A) | ||
| 674 | { | ||
| 675 | buf=(unsigned char *)s->init_buf->data; | ||
| 676 | p=s->s3->server_random; | ||
| 677 | Time=(unsigned long)time(NULL); /* Time */ | ||
| 678 | l2n(Time,p); | ||
| 679 | RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-sizeof(Time)); | ||
| 680 | /* Do the message type and length last */ | ||
| 681 | d=p= &(buf[DTLS1_HM_HEADER_LENGTH]); | ||
| 682 | |||
| 683 | if (s->client_version == DTLS1_BAD_VER) | ||
| 684 | *(p++)=DTLS1_BAD_VER>>8, | ||
| 685 | *(p++)=DTLS1_BAD_VER&0xff; | ||
| 686 | else | ||
| 687 | *(p++)=s->version>>8, | ||
| 688 | *(p++)=s->version&0xff; | ||
| 689 | |||
| 690 | /* Random stuff */ | ||
| 691 | memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE); | ||
| 692 | p+=SSL3_RANDOM_SIZE; | ||
| 693 | |||
| 694 | /* now in theory we have 3 options to sending back the | ||
| 695 | * session id. If it is a re-use, we send back the | ||
| 696 | * old session-id, if it is a new session, we send | ||
| 697 | * back the new session-id or we send back a 0 length | ||
| 698 | * session-id if we want it to be single use. | ||
| 699 | * Currently I will not implement the '0' length session-id | ||
| 700 | * 12-Jan-98 - I'll now support the '0' length stuff. | ||
| 701 | */ | ||
| 702 | if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_SERVER)) | ||
| 703 | s->session->session_id_length=0; | ||
| 704 | |||
| 705 | sl=s->session->session_id_length; | ||
| 706 | if (sl > sizeof s->session->session_id) | ||
| 707 | { | ||
| 708 | SSLerr(SSL_F_DTLS1_SEND_SERVER_HELLO, ERR_R_INTERNAL_ERROR); | ||
| 709 | return -1; | ||
| 710 | } | ||
| 711 | *(p++)=sl; | ||
| 712 | memcpy(p,s->session->session_id,sl); | ||
| 713 | p+=sl; | ||
| 714 | |||
| 715 | /* put the cipher */ | ||
| 716 | i=ssl3_put_cipher_by_char(s->s3->tmp.new_cipher,p); | ||
| 717 | p+=i; | ||
| 718 | |||
| 719 | /* put the compression method */ | ||
| 720 | #ifdef OPENSSL_NO_COMP | ||
| 721 | *(p++)=0; | ||
| 722 | #else | ||
| 723 | if (s->s3->tmp.new_compression == NULL) | ||
| 724 | *(p++)=0; | ||
| 725 | else | ||
| 726 | *(p++)=s->s3->tmp.new_compression->id; | ||
| 727 | #endif | ||
| 728 | |||
| 729 | /* do the header */ | ||
| 730 | l=(p-d); | ||
| 731 | d=buf; | ||
| 732 | |||
| 733 | d = dtls1_set_message_header(s, d, SSL3_MT_SERVER_HELLO, l, 0, l); | ||
| 734 | |||
| 735 | s->state=SSL3_ST_CW_CLNT_HELLO_B; | ||
| 736 | /* number of bytes to write */ | ||
| 737 | s->init_num=p-buf; | ||
| 738 | s->init_off=0; | ||
| 739 | |||
| 740 | /* buffer the message to handle re-xmits */ | ||
| 741 | dtls1_buffer_message(s, 0); | ||
| 742 | } | ||
| 743 | |||
| 744 | /* SSL3_ST_CW_CLNT_HELLO_B */ | ||
| 745 | return(dtls1_do_write(s,SSL3_RT_HANDSHAKE)); | ||
| 746 | } | ||
| 747 | |||
| 748 | int dtls1_send_server_done(SSL *s) | ||
| 749 | { | ||
| 750 | unsigned char *p; | ||
| 751 | |||
| 752 | if (s->state == SSL3_ST_SW_SRVR_DONE_A) | ||
| 753 | { | ||
| 754 | p=(unsigned char *)s->init_buf->data; | ||
| 755 | |||
| 756 | /* do the header */ | ||
| 757 | p = dtls1_set_message_header(s, p, SSL3_MT_SERVER_DONE, 0, 0, 0); | ||
| 758 | |||
| 759 | s->state=SSL3_ST_SW_SRVR_DONE_B; | ||
| 760 | /* number of bytes to write */ | ||
| 761 | s->init_num=DTLS1_HM_HEADER_LENGTH; | ||
| 762 | s->init_off=0; | ||
| 763 | |||
| 764 | /* buffer the message to handle re-xmits */ | ||
| 765 | dtls1_buffer_message(s, 0); | ||
| 766 | } | ||
| 767 | |||
| 768 | /* SSL3_ST_CW_CLNT_HELLO_B */ | ||
| 769 | return(dtls1_do_write(s,SSL3_RT_HANDSHAKE)); | ||
| 770 | } | ||
| 771 | |||
| 772 | int dtls1_send_server_key_exchange(SSL *s) | ||
| 773 | { | ||
| 774 | #ifndef OPENSSL_NO_RSA | ||
| 775 | unsigned char *q; | ||
| 776 | int j,num; | ||
| 777 | RSA *rsa; | ||
| 778 | unsigned char md_buf[MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH]; | ||
| 779 | unsigned int u; | ||
| 780 | #endif | ||
| 781 | #ifndef OPENSSL_NO_DH | ||
| 782 | DH *dh=NULL,*dhp; | ||
| 783 | #endif | ||
| 784 | EVP_PKEY *pkey; | ||
| 785 | unsigned char *p,*d; | ||
| 786 | int al,i; | ||
| 787 | unsigned long type; | ||
| 788 | int n; | ||
| 789 | CERT *cert; | ||
| 790 | BIGNUM *r[4]; | ||
| 791 | int nr[4],kn; | ||
| 792 | BUF_MEM *buf; | ||
| 793 | EVP_MD_CTX md_ctx; | ||
| 794 | |||
| 795 | EVP_MD_CTX_init(&md_ctx); | ||
| 796 | if (s->state == SSL3_ST_SW_KEY_EXCH_A) | ||
| 797 | { | ||
| 798 | type=s->s3->tmp.new_cipher->algorithms & SSL_MKEY_MASK; | ||
| 799 | cert=s->cert; | ||
| 800 | |||
| 801 | buf=s->init_buf; | ||
| 802 | |||
| 803 | r[0]=r[1]=r[2]=r[3]=NULL; | ||
| 804 | n=0; | ||
| 805 | #ifndef OPENSSL_NO_RSA | ||
| 806 | if (type & SSL_kRSA) | ||
| 807 | { | ||
| 808 | rsa=cert->rsa_tmp; | ||
| 809 | if ((rsa == NULL) && (s->cert->rsa_tmp_cb != NULL)) | ||
| 810 | { | ||
| 811 | rsa=s->cert->rsa_tmp_cb(s, | ||
| 812 | SSL_C_IS_EXPORT(s->s3->tmp.new_cipher), | ||
| 813 | SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)); | ||
| 814 | if(rsa == NULL) | ||
| 815 | { | ||
| 816 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
| 817 | SSLerr(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE,SSL_R_ERROR_GENERATING_TMP_RSA_KEY); | ||
| 818 | goto f_err; | ||
| 819 | } | ||
| 820 | RSA_up_ref(rsa); | ||
| 821 | cert->rsa_tmp=rsa; | ||
| 822 | } | ||
| 823 | if (rsa == NULL) | ||
| 824 | { | ||
| 825 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
| 826 | SSLerr(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE,SSL_R_MISSING_TMP_RSA_KEY); | ||
| 827 | goto f_err; | ||
| 828 | } | ||
| 829 | r[0]=rsa->n; | ||
| 830 | r[1]=rsa->e; | ||
| 831 | s->s3->tmp.use_rsa_tmp=1; | ||
| 832 | } | ||
| 833 | else | ||
| 834 | #endif | ||
| 835 | #ifndef OPENSSL_NO_DH | ||
| 836 | if (type & SSL_kEDH) | ||
| 837 | { | ||
| 838 | dhp=cert->dh_tmp; | ||
| 839 | if ((dhp == NULL) && (s->cert->dh_tmp_cb != NULL)) | ||
| 840 | dhp=s->cert->dh_tmp_cb(s, | ||
| 841 | SSL_C_IS_EXPORT(s->s3->tmp.new_cipher), | ||
| 842 | SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)); | ||
| 843 | if (dhp == NULL) | ||
| 844 | { | ||
| 845 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
| 846 | SSLerr(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE,SSL_R_MISSING_TMP_DH_KEY); | ||
| 847 | goto f_err; | ||
| 848 | } | ||
| 849 | |||
| 850 | if (s->s3->tmp.dh != NULL) | ||
| 851 | { | ||
| 852 | DH_free(dh); | ||
| 853 | SSLerr(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR); | ||
| 854 | goto err; | ||
| 855 | } | ||
| 856 | |||
| 857 | if ((dh=DHparams_dup(dhp)) == NULL) | ||
| 858 | { | ||
| 859 | SSLerr(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
| 860 | goto err; | ||
| 861 | } | ||
| 862 | |||
| 863 | s->s3->tmp.dh=dh; | ||
| 864 | if ((dhp->pub_key == NULL || | ||
| 865 | dhp->priv_key == NULL || | ||
| 866 | (s->options & SSL_OP_SINGLE_DH_USE))) | ||
| 867 | { | ||
| 868 | if(!DH_generate_key(dh)) | ||
| 869 | { | ||
| 870 | SSLerr(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE, | ||
| 871 | ERR_R_DH_LIB); | ||
| 872 | goto err; | ||
| 873 | } | ||
| 874 | } | ||
| 875 | else | ||
| 876 | { | ||
| 877 | dh->pub_key=BN_dup(dhp->pub_key); | ||
| 878 | dh->priv_key=BN_dup(dhp->priv_key); | ||
| 879 | if ((dh->pub_key == NULL) || | ||
| 880 | (dh->priv_key == NULL)) | ||
| 881 | { | ||
| 882 | SSLerr(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
| 883 | goto err; | ||
| 884 | } | ||
| 885 | } | ||
| 886 | r[0]=dh->p; | ||
| 887 | r[1]=dh->g; | ||
| 888 | r[2]=dh->pub_key; | ||
| 889 | } | ||
| 890 | else | ||
| 891 | #endif | ||
| 892 | { | ||
| 893 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
| 894 | SSLerr(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE); | ||
| 895 | goto f_err; | ||
| 896 | } | ||
| 897 | for (i=0; r[i] != NULL; i++) | ||
| 898 | { | ||
| 899 | nr[i]=BN_num_bytes(r[i]); | ||
| 900 | n+=2+nr[i]; | ||
| 901 | } | ||
| 902 | |||
| 903 | if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL)) | ||
| 904 | { | ||
| 905 | if ((pkey=ssl_get_sign_pkey(s,s->s3->tmp.new_cipher)) | ||
| 906 | == NULL) | ||
| 907 | { | ||
| 908 | al=SSL_AD_DECODE_ERROR; | ||
| 909 | goto f_err; | ||
| 910 | } | ||
| 911 | kn=EVP_PKEY_size(pkey); | ||
| 912 | } | ||
| 913 | else | ||
| 914 | { | ||
| 915 | pkey=NULL; | ||
| 916 | kn=0; | ||
| 917 | } | ||
| 918 | |||
| 919 | if (!BUF_MEM_grow_clean(buf,n+DTLS1_HM_HEADER_LENGTH+kn)) | ||
| 920 | { | ||
| 921 | SSLerr(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_BUF); | ||
| 922 | goto err; | ||
| 923 | } | ||
| 924 | d=(unsigned char *)s->init_buf->data; | ||
| 925 | p= &(d[DTLS1_HM_HEADER_LENGTH]); | ||
| 926 | |||
| 927 | for (i=0; r[i] != NULL; i++) | ||
| 928 | { | ||
| 929 | s2n(nr[i],p); | ||
| 930 | BN_bn2bin(r[i],p); | ||
| 931 | p+=nr[i]; | ||
| 932 | } | ||
| 933 | |||
| 934 | /* not anonymous */ | ||
| 935 | if (pkey != NULL) | ||
| 936 | { | ||
| 937 | /* n is the length of the params, they start at | ||
| 938 | * &(d[DTLS1_HM_HEADER_LENGTH]) and p points to the space | ||
| 939 | * at the end. */ | ||
| 940 | #ifndef OPENSSL_NO_RSA | ||
| 941 | if (pkey->type == EVP_PKEY_RSA) | ||
| 942 | { | ||
| 943 | q=md_buf; | ||
| 944 | j=0; | ||
| 945 | for (num=2; num > 0; num--) | ||
| 946 | { | ||
| 947 | EVP_DigestInit_ex(&md_ctx,(num == 2) | ||
| 948 | ?s->ctx->md5:s->ctx->sha1, NULL); | ||
| 949 | EVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE); | ||
| 950 | EVP_DigestUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE); | ||
| 951 | EVP_DigestUpdate(&md_ctx,&(d[DTLS1_HM_HEADER_LENGTH]),n); | ||
| 952 | EVP_DigestFinal_ex(&md_ctx,q, | ||
| 953 | (unsigned int *)&i); | ||
| 954 | q+=i; | ||
| 955 | j+=i; | ||
| 956 | } | ||
| 957 | if (RSA_sign(NID_md5_sha1, md_buf, j, | ||
| 958 | &(p[2]), &u, pkey->pkey.rsa) <= 0) | ||
| 959 | { | ||
| 960 | SSLerr(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_RSA); | ||
| 961 | goto err; | ||
| 962 | } | ||
| 963 | s2n(u,p); | ||
| 964 | n+=u+2; | ||
| 965 | } | ||
| 966 | else | ||
| 967 | #endif | ||
| 968 | #if !defined(OPENSSL_NO_DSA) | ||
| 969 | if (pkey->type == EVP_PKEY_DSA) | ||
| 970 | { | ||
| 971 | /* lets do DSS */ | ||
| 972 | EVP_SignInit_ex(&md_ctx,EVP_dss1(), NULL); | ||
| 973 | EVP_SignUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE); | ||
| 974 | EVP_SignUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE); | ||
| 975 | EVP_SignUpdate(&md_ctx,&(d[DTLS1_HM_HEADER_LENGTH]),n); | ||
| 976 | if (!EVP_SignFinal(&md_ctx,&(p[2]), | ||
| 977 | (unsigned int *)&i,pkey)) | ||
| 978 | { | ||
| 979 | SSLerr(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_DSA); | ||
| 980 | goto err; | ||
| 981 | } | ||
| 982 | s2n(i,p); | ||
| 983 | n+=i+2; | ||
| 984 | } | ||
| 985 | else | ||
| 986 | #endif | ||
| 987 | { | ||
| 988 | /* Is this error check actually needed? */ | ||
| 989 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
| 990 | SSLerr(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNKNOWN_PKEY_TYPE); | ||
| 991 | goto f_err; | ||
| 992 | } | ||
| 993 | } | ||
| 994 | |||
| 995 | d = dtls1_set_message_header(s, d, | ||
| 996 | SSL3_MT_SERVER_KEY_EXCHANGE, n, 0, n); | ||
| 997 | |||
| 998 | /* we should now have things packed up, so lets send | ||
| 999 | * it off */ | ||
| 1000 | s->init_num=n+DTLS1_HM_HEADER_LENGTH; | ||
| 1001 | s->init_off=0; | ||
| 1002 | |||
| 1003 | /* buffer the message to handle re-xmits */ | ||
| 1004 | dtls1_buffer_message(s, 0); | ||
| 1005 | } | ||
| 1006 | |||
| 1007 | s->state = SSL3_ST_SW_KEY_EXCH_B; | ||
| 1008 | EVP_MD_CTX_cleanup(&md_ctx); | ||
| 1009 | return(dtls1_do_write(s,SSL3_RT_HANDSHAKE)); | ||
| 1010 | f_err: | ||
| 1011 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
| 1012 | err: | ||
| 1013 | EVP_MD_CTX_cleanup(&md_ctx); | ||
| 1014 | return(-1); | ||
| 1015 | } | ||
| 1016 | |||
| 1017 | int dtls1_send_certificate_request(SSL *s) | ||
| 1018 | { | ||
| 1019 | unsigned char *p,*d; | ||
| 1020 | int i,j,nl,off,n; | ||
| 1021 | STACK_OF(X509_NAME) *sk=NULL; | ||
| 1022 | X509_NAME *name; | ||
| 1023 | BUF_MEM *buf; | ||
| 1024 | unsigned int msg_len; | ||
| 1025 | |||
| 1026 | if (s->state == SSL3_ST_SW_CERT_REQ_A) | ||
| 1027 | { | ||
| 1028 | buf=s->init_buf; | ||
| 1029 | |||
| 1030 | d=p=(unsigned char *)&(buf->data[DTLS1_HM_HEADER_LENGTH]); | ||
| 1031 | |||
| 1032 | /* get the list of acceptable cert types */ | ||
| 1033 | p++; | ||
| 1034 | n=ssl3_get_req_cert_type(s,p); | ||
| 1035 | d[0]=n; | ||
| 1036 | p+=n; | ||
| 1037 | n++; | ||
| 1038 | |||
| 1039 | off=n; | ||
| 1040 | p+=2; | ||
| 1041 | n+=2; | ||
| 1042 | |||
| 1043 | sk=SSL_get_client_CA_list(s); | ||
| 1044 | nl=0; | ||
| 1045 | if (sk != NULL) | ||
| 1046 | { | ||
| 1047 | for (i=0; i<sk_X509_NAME_num(sk); i++) | ||
| 1048 | { | ||
| 1049 | name=sk_X509_NAME_value(sk,i); | ||
| 1050 | j=i2d_X509_NAME(name,NULL); | ||
| 1051 | if (!BUF_MEM_grow_clean(buf,DTLS1_HM_HEADER_LENGTH+n+j+2)) | ||
| 1052 | { | ||
| 1053 | SSLerr(SSL_F_DTLS1_SEND_CERTIFICATE_REQUEST,ERR_R_BUF_LIB); | ||
| 1054 | goto err; | ||
| 1055 | } | ||
| 1056 | p=(unsigned char *)&(buf->data[DTLS1_HM_HEADER_LENGTH+n]); | ||
| 1057 | if (!(s->options & SSL_OP_NETSCAPE_CA_DN_BUG)) | ||
| 1058 | { | ||
| 1059 | s2n(j,p); | ||
| 1060 | i2d_X509_NAME(name,&p); | ||
| 1061 | n+=2+j; | ||
| 1062 | nl+=2+j; | ||
| 1063 | } | ||
| 1064 | else | ||
| 1065 | { | ||
| 1066 | d=p; | ||
| 1067 | i2d_X509_NAME(name,&p); | ||
| 1068 | j-=2; s2n(j,d); j+=2; | ||
| 1069 | n+=j; | ||
| 1070 | nl+=j; | ||
| 1071 | } | ||
| 1072 | } | ||
| 1073 | } | ||
| 1074 | /* else no CA names */ | ||
| 1075 | p=(unsigned char *)&(buf->data[DTLS1_HM_HEADER_LENGTH+off]); | ||
| 1076 | s2n(nl,p); | ||
| 1077 | |||
| 1078 | d=(unsigned char *)buf->data; | ||
| 1079 | *(d++)=SSL3_MT_CERTIFICATE_REQUEST; | ||
| 1080 | l2n3(n,d); | ||
| 1081 | s2n(s->d1->handshake_write_seq,d); | ||
| 1082 | s->d1->handshake_write_seq++; | ||
| 1083 | |||
| 1084 | /* we should now have things packed up, so lets send | ||
| 1085 | * it off */ | ||
| 1086 | |||
| 1087 | s->init_num=n+DTLS1_HM_HEADER_LENGTH; | ||
| 1088 | s->init_off=0; | ||
| 1089 | #ifdef NETSCAPE_HANG_BUG | ||
| 1090 | /* XXX: what to do about this? */ | ||
| 1091 | p=(unsigned char *)s->init_buf->data + s->init_num; | ||
| 1092 | |||
| 1093 | /* do the header */ | ||
| 1094 | *(p++)=SSL3_MT_SERVER_DONE; | ||
| 1095 | *(p++)=0; | ||
| 1096 | *(p++)=0; | ||
| 1097 | *(p++)=0; | ||
| 1098 | s->init_num += 4; | ||
| 1099 | #endif | ||
| 1100 | |||
| 1101 | /* XDTLS: set message header ? */ | ||
| 1102 | msg_len = s->init_num - DTLS1_HM_HEADER_LENGTH; | ||
| 1103 | dtls1_set_message_header(s, (void *)s->init_buf->data, | ||
| 1104 | SSL3_MT_CERTIFICATE_REQUEST, msg_len, 0, msg_len); | ||
| 1105 | |||
| 1106 | /* buffer the message to handle re-xmits */ | ||
| 1107 | dtls1_buffer_message(s, 0); | ||
| 1108 | |||
| 1109 | s->state = SSL3_ST_SW_CERT_REQ_B; | ||
| 1110 | } | ||
| 1111 | |||
| 1112 | /* SSL3_ST_SW_CERT_REQ_B */ | ||
| 1113 | return(dtls1_do_write(s,SSL3_RT_HANDSHAKE)); | ||
| 1114 | err: | ||
| 1115 | return(-1); | ||
| 1116 | } | ||
| 1117 | |||
| 1118 | int dtls1_send_server_certificate(SSL *s) | ||
| 1119 | { | ||
| 1120 | unsigned long l; | ||
| 1121 | X509 *x; | ||
| 1122 | |||
| 1123 | if (s->state == SSL3_ST_SW_CERT_A) | ||
| 1124 | { | ||
| 1125 | x=ssl_get_server_send_cert(s); | ||
| 1126 | if (x == NULL && | ||
| 1127 | /* VRS: allow null cert if auth == KRB5 */ | ||
| 1128 | (s->s3->tmp.new_cipher->algorithms | ||
| 1129 | & (SSL_MKEY_MASK|SSL_AUTH_MASK)) | ||
| 1130 | != (SSL_aKRB5|SSL_kKRB5)) | ||
| 1131 | { | ||
| 1132 | SSLerr(SSL_F_DTLS1_SEND_SERVER_CERTIFICATE,ERR_R_INTERNAL_ERROR); | ||
| 1133 | return(0); | ||
| 1134 | } | ||
| 1135 | |||
| 1136 | l=dtls1_output_cert_chain(s,x); | ||
| 1137 | s->state=SSL3_ST_SW_CERT_B; | ||
| 1138 | s->init_num=(int)l; | ||
| 1139 | s->init_off=0; | ||
| 1140 | |||
| 1141 | /* buffer the message to handle re-xmits */ | ||
| 1142 | dtls1_buffer_message(s, 0); | ||
| 1143 | } | ||
| 1144 | |||
| 1145 | /* SSL3_ST_SW_CERT_B */ | ||
| 1146 | return(dtls1_do_write(s,SSL3_RT_HANDSHAKE)); | ||
| 1147 | } | ||
diff --git a/src/lib/libssl/doc/openssl.cnf b/src/lib/libssl/doc/openssl.cnf index 4c1d595b0a..9e59020c17 100644 --- a/src/lib/libssl/doc/openssl.cnf +++ b/src/lib/libssl/doc/openssl.cnf | |||
| @@ -44,8 +44,8 @@ new_certs_dir = $dir/newcerts # default place for new certs. | |||
| 44 | 44 | ||
| 45 | certificate = $dir/cacert.pem # The CA certificate | 45 | certificate = $dir/cacert.pem # The CA certificate |
| 46 | serial = $dir/serial # The current serial number | 46 | serial = $dir/serial # The current serial number |
| 47 | #crlnumber = $dir/crlnumber # the current crl number must be | 47 | crlnumber = $dir/crlnumber # the current crl number |
| 48 | # commented out to leave a V1 CRL | 48 | # must be commented out to leave a V1 CRL |
| 49 | crl = $dir/crl.pem # The current CRL | 49 | crl = $dir/crl.pem # The current CRL |
| 50 | private_key = $dir/private/cakey.pem# The private key | 50 | private_key = $dir/private/cakey.pem# The private key |
| 51 | RANDFILE = $dir/private/.rand # private random number file | 51 | RANDFILE = $dir/private/.rand # private random number file |
| @@ -67,7 +67,7 @@ cert_opt = ca_default # Certificate field options | |||
| 67 | 67 | ||
| 68 | default_days = 365 # how long to certify for | 68 | default_days = 365 # how long to certify for |
| 69 | default_crl_days= 30 # how long before next CRL | 69 | default_crl_days= 30 # how long before next CRL |
| 70 | default_md = md5 # which md to use. | 70 | default_md = sha1 # which md to use. |
| 71 | preserve = no # keep passed DN ordering | 71 | preserve = no # keep passed DN ordering |
| 72 | 72 | ||
| 73 | # A few difference way of specifying how similar the request should look | 73 | # A few difference way of specifying how similar the request should look |
| @@ -188,7 +188,7 @@ nsComment = "OpenSSL Generated Certificate" | |||
| 188 | 188 | ||
| 189 | # PKIX recommendations harmless if included in all certificates. | 189 | # PKIX recommendations harmless if included in all certificates. |
| 190 | subjectKeyIdentifier=hash | 190 | subjectKeyIdentifier=hash |
| 191 | authorityKeyIdentifier=keyid,issuer:always | 191 | authorityKeyIdentifier=keyid,issuer |
| 192 | 192 | ||
| 193 | # This stuff is for subjectAltName and issuerAltname. | 193 | # This stuff is for subjectAltName and issuerAltname. |
| 194 | # Import the email address. | 194 | # Import the email address. |
diff --git a/src/lib/libssl/doc/openssl.txt b/src/lib/libssl/doc/openssl.txt index 432a17b66c..f8817b0a71 100644 --- a/src/lib/libssl/doc/openssl.txt +++ b/src/lib/libssl/doc/openssl.txt | |||
| @@ -154,8 +154,22 @@ for example contain data in multiple sections. The correct syntax to | |||
| 154 | use is defined by the extension code itself: check out the certificate | 154 | use is defined by the extension code itself: check out the certificate |
| 155 | policies extension for an example. | 155 | policies extension for an example. |
| 156 | 156 | ||
| 157 | In addition it is also possible to use the word DER to include arbitrary | 157 | There are two ways to encode arbitrary extensions. |
| 158 | data in any extension. | 158 | |
| 159 | The first way is to use the word ASN1 followed by the extension content | ||
| 160 | using the same syntax as ASN1_generate_nconf(). For example: | ||
| 161 | |||
| 162 | 1.2.3.4=critical,ASN1:UTF8String:Some random data | ||
| 163 | |||
| 164 | 1.2.3.4=ASN1:SEQUENCE:seq_sect | ||
| 165 | |||
| 166 | [seq_sect] | ||
| 167 | |||
| 168 | field1 = UTF8:field1 | ||
| 169 | field2 = UTF8:field2 | ||
| 170 | |||
| 171 | It is also possible to use the word DER to include arbitrary data in any | ||
| 172 | extension. | ||
| 159 | 173 | ||
| 160 | 1.2.3.4=critical,DER:01:02:03:04 | 174 | 1.2.3.4=critical,DER:01:02:03:04 |
| 161 | 1.2.3.4=DER:01020304 | 175 | 1.2.3.4=DER:01020304 |
| @@ -336,16 +350,21 @@ Subject Alternative Name. | |||
| 336 | The subject alternative name extension allows various literal values to be | 350 | The subject alternative name extension allows various literal values to be |
| 337 | included in the configuration file. These include "email" (an email address) | 351 | included in the configuration file. These include "email" (an email address) |
| 338 | "URI" a uniform resource indicator, "DNS" (a DNS domain name), RID (a | 352 | "URI" a uniform resource indicator, "DNS" (a DNS domain name), RID (a |
| 339 | registered ID: OBJECT IDENTIFIER) and IP (and IP address). | 353 | registered ID: OBJECT IDENTIFIER), IP (and IP address) and otherName. |
| 340 | 354 | ||
| 341 | Also the email option include a special 'copy' value. This will automatically | 355 | Also the email option include a special 'copy' value. This will automatically |
| 342 | include and email addresses contained in the certificate subject name in | 356 | include and email addresses contained in the certificate subject name in |
| 343 | the extension. | 357 | the extension. |
| 344 | 358 | ||
| 359 | otherName can include arbitrary data associated with an OID: the value | ||
| 360 | should be the OID followed by a semicolon and the content in standard | ||
| 361 | ASN1_generate_nconf() format. | ||
| 362 | |||
| 345 | Examples: | 363 | Examples: |
| 346 | 364 | ||
| 347 | subjectAltName=email:copy,email:my@other.address,URI:http://my.url.here/ | 365 | subjectAltName=email:copy,email:my@other.address,URI:http://my.url.here/ |
| 348 | subjectAltName=email:my@other.address,RID:1.2.3.4 | 366 | subjectAltName=email:my@other.address,RID:1.2.3.4 |
| 367 | subjectAltName=otherName:1.2.3.4;UTF8:some other identifier | ||
| 349 | 368 | ||
| 350 | Issuer Alternative Name. | 369 | Issuer Alternative Name. |
| 351 | 370 | ||
| @@ -759,7 +778,7 @@ called. | |||
| 759 | 778 | ||
| 760 | The X509V3_EXT_METHOD structure is described below. | 779 | The X509V3_EXT_METHOD structure is described below. |
| 761 | 780 | ||
| 762 | strut { | 781 | struct { |
| 763 | int ext_nid; | 782 | int ext_nid; |
| 764 | int ext_flags; | 783 | int ext_flags; |
| 765 | X509V3_EXT_NEW ext_new; | 784 | X509V3_EXT_NEW ext_new; |
diff --git a/src/lib/libssl/doc/standards.txt b/src/lib/libssl/doc/standards.txt index f6675b574b..a5ce778f8e 100644 --- a/src/lib/libssl/doc/standards.txt +++ b/src/lib/libssl/doc/standards.txt | |||
| @@ -88,10 +88,26 @@ PKCS#12: Personal Information Exchange Syntax Standard, version 1.0. | |||
| 88 | (Format: TXT=143173 bytes) (Obsoletes RFC2437) (Status: | 88 | (Format: TXT=143173 bytes) (Obsoletes RFC2437) (Status: |
| 89 | INFORMATIONAL) | 89 | INFORMATIONAL) |
| 90 | 90 | ||
| 91 | 3713 A Description of the Camellia Encryption Algorithm. M. Matsui, | ||
| 92 | J. Nakajima, S. Moriai. April 2004. (Format: TXT=25031 bytes) | ||
| 93 | (Status: INFORMATIONAL) | ||
| 94 | |||
| 91 | 3820 Internet X.509 Public Key Infrastructure (PKI) Proxy Certificate | 95 | 3820 Internet X.509 Public Key Infrastructure (PKI) Proxy Certificate |
| 92 | Profile. S. Tuecke, V. Welch, D. Engert, L. Pearlman, M. Thompson. | 96 | Profile. S. Tuecke, V. Welch, D. Engert, L. Pearlman, M. Thompson. |
| 93 | June 2004. (Format: TXT=86374 bytes) (Status: PROPOSED STANDARD) | 97 | June 2004. (Format: TXT=86374 bytes) (Status: PROPOSED STANDARD) |
| 94 | 98 | ||
| 99 | 4132 Addition of Camellia Cipher Suites to Transport Layer Security | ||
| 100 | (TLS). S. Moriai, A. Kato, M. Kanda. July 2005. (Format: TXT=13590 | ||
| 101 | bytes) (Status: PROPOSED STANDARD) | ||
| 102 | |||
| 103 | 4162 Addition of SEED Cipher Suites to Transport Layer Security (TLS). | ||
| 104 | H.J. Lee, J.H. Yoon, J.I. Lee. August 2005. (Format: TXT=10578 bytes) | ||
| 105 | (Status: PROPOSED STANDARD) | ||
| 106 | |||
| 107 | 4269 The SEED Encryption Algorithm. H.J. Lee, S.J. Lee, J.H. Yoon, | ||
| 108 | D.H. Cheon, J.I. Lee. December 2005. (Format: TXT=34390 bytes) | ||
| 109 | (Obsoletes RFC4009) (Status: INFORMATIONAL) | ||
| 110 | |||
| 95 | 111 | ||
| 96 | Related: | 112 | Related: |
| 97 | -------- | 113 | -------- |
| @@ -250,7 +266,11 @@ STARTTLS documents. | |||
| 250 | Protocol. A. Jungmaier, E. Rescorla, M. Tuexen. December 2002. | 266 | Protocol. A. Jungmaier, E. Rescorla, M. Tuexen. December 2002. |
| 251 | (Format: TXT=16333 bytes) (Status: PROPOSED STANDARD) | 267 | (Format: TXT=16333 bytes) (Status: PROPOSED STANDARD) |
| 252 | 268 | ||
| 253 | "Securing FTP with TLS", 01/27/2000, <draft-murray-auth-ftp-ssl-05.txt> | 269 | 3657 Use of the Camellia Encryption Algorithm in Cryptographic |
| 270 | Message Syntax (CMS). S. Moriai, A. Kato. January 2004. | ||
| 271 | (Format: TXT=26282 bytes) (Status: PROPOSED STANDARD) | ||
| 272 | |||
| 273 | "Securing FTP with TLS", 01/27/2000, <draft-murray-auth-ftp-ssl-05.txt> | ||
| 254 | 274 | ||
| 255 | 275 | ||
| 256 | To be implemented: | 276 | To be implemented: |
diff --git a/src/lib/libssl/dtls1.h b/src/lib/libssl/dtls1.h new file mode 100644 index 0000000000..a663cf85f2 --- /dev/null +++ b/src/lib/libssl/dtls1.h | |||
| @@ -0,0 +1,211 @@ | |||
| 1 | /* ssl/dtls1.h */ | ||
| 2 | /* | ||
| 3 | * DTLS implementation written by Nagendra Modadugu | ||
| 4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. | ||
| 5 | */ | ||
| 6 | /* ==================================================================== | ||
| 7 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. | ||
| 8 | * | ||
| 9 | * Redistribution and use in source and binary forms, with or without | ||
| 10 | * modification, are permitted provided that the following conditions | ||
| 11 | * are met: | ||
| 12 | * | ||
| 13 | * 1. Redistributions of source code must retain the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer. | ||
| 15 | * | ||
| 16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 17 | * notice, this list of conditions and the following disclaimer in | ||
| 18 | * the documentation and/or other materials provided with the | ||
| 19 | * distribution. | ||
| 20 | * | ||
| 21 | * 3. All advertising materials mentioning features or use of this | ||
| 22 | * software must display the following acknowledgment: | ||
| 23 | * "This product includes software developed by the OpenSSL Project | ||
| 24 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 25 | * | ||
| 26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 27 | * endorse or promote products derived from this software without | ||
| 28 | * prior written permission. For written permission, please contact | ||
| 29 | * openssl-core@OpenSSL.org. | ||
| 30 | * | ||
| 31 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 32 | * nor may "OpenSSL" appear in their names without prior written | ||
| 33 | * permission of the OpenSSL Project. | ||
| 34 | * | ||
| 35 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 36 | * acknowledgment: | ||
| 37 | * "This product includes software developed by the OpenSSL Project | ||
| 38 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 39 | * | ||
| 40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 51 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 52 | * ==================================================================== | ||
| 53 | * | ||
| 54 | * This product includes cryptographic software written by Eric Young | ||
| 55 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 56 | * Hudson (tjh@cryptsoft.com). | ||
| 57 | * | ||
| 58 | */ | ||
| 59 | |||
| 60 | #ifndef HEADER_DTLS1_H | ||
| 61 | #define HEADER_DTLS1_H | ||
| 62 | |||
| 63 | #include <openssl/buffer.h> | ||
| 64 | #include <openssl/pqueue.h> | ||
| 65 | |||
| 66 | #ifdef __cplusplus | ||
| 67 | extern "C" { | ||
| 68 | #endif | ||
| 69 | |||
| 70 | #define DTLS1_VERSION 0xFEFF | ||
| 71 | #define DTLS1_BAD_VER 0x0100 | ||
| 72 | |||
| 73 | #define DTLS1_AD_MISSING_HANDSHAKE_MESSAGE 110 | ||
| 74 | |||
| 75 | /* lengths of messages */ | ||
| 76 | #define DTLS1_COOKIE_LENGTH 32 | ||
| 77 | |||
| 78 | #define DTLS1_RT_HEADER_LENGTH 13 | ||
| 79 | |||
| 80 | #define DTLS1_HM_HEADER_LENGTH 12 | ||
| 81 | |||
| 82 | #define DTLS1_HM_BAD_FRAGMENT -2 | ||
| 83 | #define DTLS1_HM_FRAGMENT_RETRY -3 | ||
| 84 | |||
| 85 | #define DTLS1_CCS_HEADER_LENGTH 1 | ||
| 86 | |||
| 87 | #define DTLS1_AL_HEADER_LENGTH 7 | ||
| 88 | |||
| 89 | |||
| 90 | typedef struct dtls1_bitmap_st | ||
| 91 | { | ||
| 92 | PQ_64BIT map; | ||
| 93 | unsigned long length; /* sizeof the bitmap in bits */ | ||
| 94 | PQ_64BIT max_seq_num; /* max record number seen so far */ | ||
| 95 | } DTLS1_BITMAP; | ||
| 96 | |||
| 97 | struct hm_header_st | ||
| 98 | { | ||
| 99 | unsigned char type; | ||
| 100 | unsigned long msg_len; | ||
| 101 | unsigned short seq; | ||
| 102 | unsigned long frag_off; | ||
| 103 | unsigned long frag_len; | ||
| 104 | unsigned int is_ccs; | ||
| 105 | }; | ||
| 106 | |||
| 107 | struct ccs_header_st | ||
| 108 | { | ||
| 109 | unsigned char type; | ||
| 110 | unsigned short seq; | ||
| 111 | }; | ||
| 112 | |||
| 113 | struct dtls1_timeout_st | ||
| 114 | { | ||
| 115 | /* Number of read timeouts so far */ | ||
| 116 | unsigned int read_timeouts; | ||
| 117 | |||
| 118 | /* Number of write timeouts so far */ | ||
| 119 | unsigned int write_timeouts; | ||
| 120 | |||
| 121 | /* Number of alerts received so far */ | ||
| 122 | unsigned int num_alerts; | ||
| 123 | }; | ||
| 124 | |||
| 125 | typedef struct record_pqueue_st | ||
| 126 | { | ||
| 127 | unsigned short epoch; | ||
| 128 | pqueue q; | ||
| 129 | } record_pqueue; | ||
| 130 | |||
| 131 | typedef struct hm_fragment_st | ||
| 132 | { | ||
| 133 | struct hm_header_st msg_header; | ||
| 134 | unsigned char *fragment; | ||
| 135 | } hm_fragment; | ||
| 136 | |||
| 137 | typedef struct dtls1_state_st | ||
| 138 | { | ||
| 139 | unsigned int send_cookie; | ||
| 140 | unsigned char cookie[DTLS1_COOKIE_LENGTH]; | ||
| 141 | unsigned char rcvd_cookie[DTLS1_COOKIE_LENGTH]; | ||
| 142 | unsigned int cookie_len; | ||
| 143 | |||
| 144 | /* | ||
| 145 | * The current data and handshake epoch. This is initially | ||
| 146 | * undefined, and starts at zero once the initial handshake is | ||
| 147 | * completed | ||
| 148 | */ | ||
| 149 | unsigned short r_epoch; | ||
| 150 | unsigned short w_epoch; | ||
| 151 | |||
| 152 | /* records being received in the current epoch */ | ||
| 153 | DTLS1_BITMAP bitmap; | ||
| 154 | |||
| 155 | /* renegotiation starts a new set of sequence numbers */ | ||
| 156 | DTLS1_BITMAP next_bitmap; | ||
| 157 | |||
| 158 | /* handshake message numbers */ | ||
| 159 | unsigned short handshake_write_seq; | ||
| 160 | unsigned short next_handshake_write_seq; | ||
| 161 | |||
| 162 | unsigned short handshake_read_seq; | ||
| 163 | |||
| 164 | /* Received handshake records (processed and unprocessed) */ | ||
| 165 | record_pqueue unprocessed_rcds; | ||
| 166 | record_pqueue processed_rcds; | ||
| 167 | |||
| 168 | /* Buffered handshake messages */ | ||
| 169 | pqueue buffered_messages; | ||
| 170 | |||
| 171 | /* Buffered (sent) handshake records */ | ||
| 172 | pqueue sent_messages; | ||
| 173 | |||
| 174 | unsigned int mtu; /* max wire packet size */ | ||
| 175 | |||
| 176 | struct hm_header_st w_msg_hdr; | ||
| 177 | struct hm_header_st r_msg_hdr; | ||
| 178 | |||
| 179 | struct dtls1_timeout_st timeout; | ||
| 180 | |||
| 181 | /* storage for Alert/Handshake protocol data received but not | ||
| 182 | * yet processed by ssl3_read_bytes: */ | ||
| 183 | unsigned char alert_fragment[DTLS1_AL_HEADER_LENGTH]; | ||
| 184 | unsigned int alert_fragment_len; | ||
| 185 | unsigned char handshake_fragment[DTLS1_HM_HEADER_LENGTH]; | ||
| 186 | unsigned int handshake_fragment_len; | ||
| 187 | |||
| 188 | unsigned int retransmitting; | ||
| 189 | |||
| 190 | } DTLS1_STATE; | ||
| 191 | |||
| 192 | typedef struct dtls1_record_data_st | ||
| 193 | { | ||
| 194 | unsigned char *packet; | ||
| 195 | unsigned int packet_length; | ||
| 196 | SSL3_BUFFER rbuf; | ||
| 197 | SSL3_RECORD rrec; | ||
| 198 | } DTLS1_RECORD_DATA; | ||
| 199 | |||
| 200 | |||
| 201 | /* Timeout multipliers (timeout slice is defined in apps/timeouts.h */ | ||
| 202 | #define DTLS1_TMO_READ_COUNT 2 | ||
| 203 | #define DTLS1_TMO_WRITE_COUNT 2 | ||
| 204 | |||
| 205 | #define DTLS1_TMO_ALERT_COUNT 12 | ||
| 206 | |||
| 207 | #ifdef __cplusplus | ||
| 208 | } | ||
| 209 | #endif | ||
| 210 | #endif | ||
| 211 | |||
diff --git a/src/lib/libssl/s23_clnt.c b/src/lib/libssl/s23_clnt.c index 86356731ea..c45a8e0a04 100644 --- a/src/lib/libssl/s23_clnt.c +++ b/src/lib/libssl/s23_clnt.c | |||
| @@ -80,28 +80,10 @@ static SSL_METHOD *ssl23_get_client_method(int ver) | |||
| 80 | return(NULL); | 80 | return(NULL); |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | SSL_METHOD *SSLv23_client_method(void) | 83 | IMPLEMENT_ssl23_meth_func(SSLv23_client_method, |
| 84 | { | 84 | ssl_undefined_function, |
| 85 | static int init=1; | 85 | ssl23_connect, |
| 86 | static SSL_METHOD SSLv23_client_data; | 86 | ssl23_get_client_method) |
| 87 | |||
| 88 | if (init) | ||
| 89 | { | ||
| 90 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD); | ||
| 91 | |||
| 92 | if (init) | ||
| 93 | { | ||
| 94 | memcpy((char *)&SSLv23_client_data, | ||
| 95 | (char *)sslv23_base_method(),sizeof(SSL_METHOD)); | ||
| 96 | SSLv23_client_data.ssl_connect=ssl23_connect; | ||
| 97 | SSLv23_client_data.get_ssl_method=ssl23_get_client_method; | ||
| 98 | init=0; | ||
| 99 | } | ||
| 100 | |||
| 101 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD); | ||
| 102 | } | ||
| 103 | return(&SSLv23_client_data); | ||
| 104 | } | ||
| 105 | 87 | ||
| 106 | int ssl23_connect(SSL *s) | 88 | int ssl23_connect(SSL *s) |
| 107 | { | 89 | { |
| @@ -241,6 +223,17 @@ static int ssl23_client_hello(SSL *s) | |||
| 241 | { | 223 | { |
| 242 | version = SSL2_VERSION; | 224 | version = SSL2_VERSION; |
| 243 | } | 225 | } |
| 226 | #ifndef OPENSSL_NO_TLSEXT | ||
| 227 | if (version != SSL2_VERSION) | ||
| 228 | { | ||
| 229 | /* have to disable SSL 2.0 compatibility if we need TLS extensions */ | ||
| 230 | |||
| 231 | if (s->tlsext_hostname != NULL) | ||
| 232 | ssl2_compat = 0; | ||
| 233 | if (s->tlsext_status_type != -1) | ||
| 234 | ssl2_compat = 0; | ||
| 235 | } | ||
| 236 | #endif | ||
| 244 | 237 | ||
| 245 | buf=(unsigned char *)s->init_buf->data; | 238 | buf=(unsigned char *)s->init_buf->data; |
| 246 | if (s->state == SSL23_ST_CW_CLNT_HELLO_A) | 239 | if (s->state == SSL23_ST_CW_CLNT_HELLO_A) |
| @@ -254,7 +247,7 @@ static int ssl23_client_hello(SSL *s) | |||
| 254 | #endif | 247 | #endif |
| 255 | 248 | ||
| 256 | p=s->s3->client_random; | 249 | p=s->s3->client_random; |
| 257 | Time=(unsigned long)time(NULL); /* Time */ | 250 | Time=(unsigned long)time(NULL); /* Time */ |
| 258 | l2n(Time,p); | 251 | l2n(Time,p); |
| 259 | if (RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4) <= 0) | 252 | if (RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4) <= 0) |
| 260 | return -1; | 253 | return -1; |
| @@ -264,14 +257,6 @@ static int ssl23_client_hello(SSL *s) | |||
| 264 | version_major = TLS1_VERSION_MAJOR; | 257 | version_major = TLS1_VERSION_MAJOR; |
| 265 | version_minor = TLS1_VERSION_MINOR; | 258 | version_minor = TLS1_VERSION_MINOR; |
| 266 | } | 259 | } |
| 267 | #ifdef OPENSSL_FIPS | ||
| 268 | else if(FIPS_mode()) | ||
| 269 | { | ||
| 270 | SSLerr(SSL_F_SSL23_CLIENT_HELLO, | ||
| 271 | SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE); | ||
| 272 | return -1; | ||
| 273 | } | ||
| 274 | #endif | ||
| 275 | else if (version == SSL3_VERSION) | 260 | else if (version == SSL3_VERSION) |
| 276 | { | 261 | { |
| 277 | version_major = SSL3_VERSION_MAJOR; | 262 | version_major = SSL3_VERSION_MAJOR; |
| @@ -386,6 +371,13 @@ static int ssl23_client_hello(SSL *s) | |||
| 386 | *(p++)=comp->id; | 371 | *(p++)=comp->id; |
| 387 | } | 372 | } |
| 388 | *(p++)=0; /* Add the NULL method */ | 373 | *(p++)=0; /* Add the NULL method */ |
| 374 | #ifndef OPENSSL_NO_TLSEXT | ||
| 375 | if ((p = ssl_add_clienthello_tlsext(s, p, buf+SSL3_RT_MAX_PLAIN_LENGTH)) == NULL) | ||
| 376 | { | ||
| 377 | SSLerr(SSL_F_SSL23_CLIENT_HELLO,ERR_R_INTERNAL_ERROR); | ||
| 378 | return -1; | ||
| 379 | } | ||
| 380 | #endif | ||
| 389 | 381 | ||
| 390 | l = p-d; | 382 | l = p-d; |
| 391 | *p = 42; | 383 | *p = 42; |
| @@ -544,14 +536,6 @@ static int ssl23_get_server_hello(SSL *s) | |||
| 544 | if ((p[2] == SSL3_VERSION_MINOR) && | 536 | if ((p[2] == SSL3_VERSION_MINOR) && |
| 545 | !(s->options & SSL_OP_NO_SSLv3)) | 537 | !(s->options & SSL_OP_NO_SSLv3)) |
| 546 | { | 538 | { |
| 547 | #ifdef OPENSSL_FIPS | ||
| 548 | if(FIPS_mode()) | ||
| 549 | { | ||
| 550 | SSLerr(SSL_F_SSL23_GET_SERVER_HELLO, | ||
| 551 | SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE); | ||
| 552 | goto err; | ||
| 553 | } | ||
| 554 | #endif | ||
| 555 | s->version=SSL3_VERSION; | 539 | s->version=SSL3_VERSION; |
| 556 | s->method=SSLv3_client_method(); | 540 | s->method=SSLv3_client_method(); |
| 557 | } | 541 | } |
| @@ -608,7 +592,6 @@ static int ssl23_get_server_hello(SSL *s) | |||
| 608 | if (!ssl_get_new_session(s,0)) | 592 | if (!ssl_get_new_session(s,0)) |
| 609 | goto err; | 593 | goto err; |
| 610 | 594 | ||
| 611 | s->first_packet=1; | ||
| 612 | return(SSL_connect(s)); | 595 | return(SSL_connect(s)); |
| 613 | err: | 596 | err: |
| 614 | return(-1); | 597 | return(-1); |
diff --git a/src/lib/libssl/s23_lib.c b/src/lib/libssl/s23_lib.c index 8d7dbcf569..fc2981308d 100644 --- a/src/lib/libssl/s23_lib.c +++ b/src/lib/libssl/s23_lib.c | |||
| @@ -60,55 +60,17 @@ | |||
| 60 | #include <openssl/objects.h> | 60 | #include <openssl/objects.h> |
| 61 | #include "ssl_locl.h" | 61 | #include "ssl_locl.h" |
| 62 | 62 | ||
| 63 | static int ssl23_num_ciphers(void ); | 63 | long ssl23_default_timeout(void) |
| 64 | static SSL_CIPHER *ssl23_get_cipher(unsigned int u); | ||
| 65 | static int ssl23_read(SSL *s, void *buf, int len); | ||
| 66 | static int ssl23_peek(SSL *s, void *buf, int len); | ||
| 67 | static int ssl23_write(SSL *s, const void *buf, int len); | ||
| 68 | static long ssl23_default_timeout(void ); | ||
| 69 | static int ssl23_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p); | ||
| 70 | static SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p); | ||
| 71 | const char *SSL23_version_str="SSLv2/3 compatibility" OPENSSL_VERSION_PTEXT; | ||
| 72 | |||
| 73 | static SSL_METHOD SSLv23_data= { | ||
| 74 | TLS1_VERSION, | ||
| 75 | tls1_new, | ||
| 76 | tls1_clear, | ||
| 77 | tls1_free, | ||
| 78 | ssl_undefined_function, | ||
| 79 | ssl_undefined_function, | ||
| 80 | ssl23_read, | ||
| 81 | ssl23_peek, | ||
| 82 | ssl23_write, | ||
| 83 | ssl_undefined_function, | ||
| 84 | ssl_undefined_function, | ||
| 85 | ssl_ok, | ||
| 86 | ssl3_ctrl, | ||
| 87 | ssl3_ctx_ctrl, | ||
| 88 | ssl23_get_cipher_by_char, | ||
| 89 | ssl23_put_cipher_by_char, | ||
| 90 | ssl_undefined_const_function, | ||
| 91 | ssl23_num_ciphers, | ||
| 92 | ssl23_get_cipher, | ||
| 93 | ssl_bad_method, | ||
| 94 | ssl23_default_timeout, | ||
| 95 | &ssl3_undef_enc_method, | ||
| 96 | ssl_undefined_function, | ||
| 97 | ssl3_callback_ctrl, | ||
| 98 | ssl3_ctx_callback_ctrl, | ||
| 99 | }; | ||
| 100 | |||
| 101 | static long ssl23_default_timeout(void) | ||
| 102 | { | 64 | { |
| 103 | return(300); | 65 | return(300); |
| 104 | } | 66 | } |
| 105 | 67 | ||
| 106 | SSL_METHOD *sslv23_base_method(void) | 68 | IMPLEMENT_ssl23_meth_func(sslv23_base_method, |
| 107 | { | 69 | ssl_undefined_function, |
| 108 | return(&SSLv23_data); | 70 | ssl_undefined_function, |
| 109 | } | 71 | ssl_bad_method) |
| 110 | 72 | ||
| 111 | static int ssl23_num_ciphers(void) | 73 | int ssl23_num_ciphers(void) |
| 112 | { | 74 | { |
| 113 | return(ssl3_num_ciphers() | 75 | return(ssl3_num_ciphers() |
| 114 | #ifndef OPENSSL_NO_SSL2 | 76 | #ifndef OPENSSL_NO_SSL2 |
| @@ -117,7 +79,7 @@ static int ssl23_num_ciphers(void) | |||
| 117 | ); | 79 | ); |
| 118 | } | 80 | } |
| 119 | 81 | ||
| 120 | static SSL_CIPHER *ssl23_get_cipher(unsigned int u) | 82 | SSL_CIPHER *ssl23_get_cipher(unsigned int u) |
| 121 | { | 83 | { |
| 122 | unsigned int uu=ssl3_num_ciphers(); | 84 | unsigned int uu=ssl3_num_ciphers(); |
| 123 | 85 | ||
| @@ -133,7 +95,7 @@ static SSL_CIPHER *ssl23_get_cipher(unsigned int u) | |||
| 133 | 95 | ||
| 134 | /* This function needs to check if the ciphers required are actually | 96 | /* This function needs to check if the ciphers required are actually |
| 135 | * available */ | 97 | * available */ |
| 136 | static SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p) | 98 | SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p) |
| 137 | { | 99 | { |
| 138 | SSL_CIPHER c,*cp; | 100 | SSL_CIPHER c,*cp; |
| 139 | unsigned long id; | 101 | unsigned long id; |
| @@ -151,7 +113,7 @@ static SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p) | |||
| 151 | return(cp); | 113 | return(cp); |
| 152 | } | 114 | } |
| 153 | 115 | ||
| 154 | static int ssl23_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p) | 116 | int ssl23_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p) |
| 155 | { | 117 | { |
| 156 | long l; | 118 | long l; |
| 157 | 119 | ||
| @@ -166,7 +128,7 @@ static int ssl23_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p) | |||
| 166 | return(3); | 128 | return(3); |
| 167 | } | 129 | } |
| 168 | 130 | ||
| 169 | static int ssl23_read(SSL *s, void *buf, int len) | 131 | int ssl23_read(SSL *s, void *buf, int len) |
| 170 | { | 132 | { |
| 171 | int n; | 133 | int n; |
| 172 | 134 | ||
| @@ -189,7 +151,7 @@ static int ssl23_read(SSL *s, void *buf, int len) | |||
| 189 | } | 151 | } |
| 190 | } | 152 | } |
| 191 | 153 | ||
| 192 | static int ssl23_peek(SSL *s, void *buf, int len) | 154 | int ssl23_peek(SSL *s, void *buf, int len) |
| 193 | { | 155 | { |
| 194 | int n; | 156 | int n; |
| 195 | 157 | ||
| @@ -212,7 +174,7 @@ static int ssl23_peek(SSL *s, void *buf, int len) | |||
| 212 | } | 174 | } |
| 213 | } | 175 | } |
| 214 | 176 | ||
| 215 | static int ssl23_write(SSL *s, const void *buf, int len) | 177 | int ssl23_write(SSL *s, const void *buf, int len) |
| 216 | { | 178 | { |
| 217 | int n; | 179 | int n; |
| 218 | 180 | ||
diff --git a/src/lib/libssl/s23_srvr.c b/src/lib/libssl/s23_srvr.c index b73abc448f..6637bb9549 100644 --- a/src/lib/libssl/s23_srvr.c +++ b/src/lib/libssl/s23_srvr.c | |||
| @@ -132,28 +132,10 @@ static SSL_METHOD *ssl23_get_server_method(int ver) | |||
| 132 | return(NULL); | 132 | return(NULL); |
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | SSL_METHOD *SSLv23_server_method(void) | 135 | IMPLEMENT_ssl23_meth_func(SSLv23_server_method, |
| 136 | { | 136 | ssl23_accept, |
| 137 | static int init=1; | 137 | ssl_undefined_function, |
| 138 | static SSL_METHOD SSLv23_server_data; | 138 | ssl23_get_server_method) |
| 139 | |||
| 140 | if (init) | ||
| 141 | { | ||
| 142 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD); | ||
| 143 | |||
| 144 | if (init) | ||
| 145 | { | ||
| 146 | memcpy((char *)&SSLv23_server_data, | ||
| 147 | (char *)sslv23_base_method(),sizeof(SSL_METHOD)); | ||
| 148 | SSLv23_server_data.ssl_accept=ssl23_accept; | ||
| 149 | SSLv23_server_data.get_ssl_method=ssl23_get_server_method; | ||
| 150 | init=0; | ||
| 151 | } | ||
| 152 | |||
| 153 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD); | ||
| 154 | } | ||
| 155 | return(&SSLv23_server_data); | ||
| 156 | } | ||
| 157 | 139 | ||
| 158 | int ssl23_accept(SSL *s) | 140 | int ssl23_accept(SSL *s) |
| 159 | { | 141 | { |
| @@ -404,15 +386,6 @@ int ssl23_get_client_hello(SSL *s) | |||
| 404 | } | 386 | } |
| 405 | } | 387 | } |
| 406 | 388 | ||
| 407 | #ifdef OPENSSL_FIPS | ||
| 408 | if (FIPS_mode() && (s->version < TLS1_VERSION)) | ||
| 409 | { | ||
| 410 | SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO, | ||
| 411 | SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE); | ||
| 412 | goto err; | ||
| 413 | } | ||
| 414 | #endif | ||
| 415 | |||
| 416 | if (s->state == SSL23_ST_SR_CLNT_HELLO_B) | 389 | if (s->state == SSL23_ST_SR_CLNT_HELLO_B) |
| 417 | { | 390 | { |
| 418 | /* we have SSLv3/TLSv1 in an SSLv2 header | 391 | /* we have SSLv3/TLSv1 in an SSLv2 header |
| @@ -592,7 +565,6 @@ int ssl23_get_client_hello(SSL *s) | |||
| 592 | s->init_num=0; | 565 | s->init_num=0; |
| 593 | 566 | ||
| 594 | if (buf != buf_space) OPENSSL_free(buf); | 567 | if (buf != buf_space) OPENSSL_free(buf); |
| 595 | s->first_packet=1; | ||
| 596 | return(SSL_accept(s)); | 568 | return(SSL_accept(s)); |
| 597 | err: | 569 | err: |
| 598 | if (buf != buf_space) OPENSSL_free(buf); | 570 | if (buf != buf_space) OPENSSL_free(buf); |
diff --git a/src/lib/libssl/s3_both.c b/src/lib/libssl/s3_both.c index 64d317b7ac..2ecfbb77cb 100644 --- a/src/lib/libssl/s3_both.c +++ b/src/lib/libssl/s3_both.c | |||
| @@ -108,6 +108,11 @@ | |||
| 108 | * Hudson (tjh@cryptsoft.com). | 108 | * Hudson (tjh@cryptsoft.com). |
| 109 | * | 109 | * |
| 110 | */ | 110 | */ |
| 111 | /* ==================================================================== | ||
| 112 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
| 113 | * ECC cipher suite support in OpenSSL originally developed by | ||
| 114 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. | ||
| 115 | */ | ||
| 111 | 116 | ||
| 112 | #include <limits.h> | 117 | #include <limits.h> |
| 113 | #include <string.h> | 118 | #include <string.h> |
| @@ -192,7 +197,7 @@ int ssl3_get_finished(SSL *s, int a, int b) | |||
| 192 | * change cipher spec message and is in s->s3->tmp.peer_finish_md | 197 | * change cipher spec message and is in s->s3->tmp.peer_finish_md |
| 193 | */ | 198 | */ |
| 194 | 199 | ||
| 195 | n=ssl3_get_message(s, | 200 | n=s->method->ssl_get_message(s, |
| 196 | a, | 201 | a, |
| 197 | b, | 202 | b, |
| 198 | SSL3_MT_FINISHED, | 203 | SSL3_MT_FINISHED, |
| @@ -386,8 +391,8 @@ long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok) | |||
| 386 | { | 391 | { |
| 387 | while (s->init_num < 4) | 392 | while (s->init_num < 4) |
| 388 | { | 393 | { |
| 389 | i=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num], | 394 | i=s->method->ssl_read_bytes(s,SSL3_RT_HANDSHAKE, |
| 390 | 4 - s->init_num, 0); | 395 | &p[s->init_num],4 - s->init_num, 0); |
| 391 | if (i <= 0) | 396 | if (i <= 0) |
| 392 | { | 397 | { |
| 393 | s->rwstate=SSL_READING; | 398 | s->rwstate=SSL_READING; |
| @@ -467,7 +472,7 @@ long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok) | |||
| 467 | n = s->s3->tmp.message_size - s->init_num; | 472 | n = s->s3->tmp.message_size - s->init_num; |
| 468 | while (n > 0) | 473 | while (n > 0) |
| 469 | { | 474 | { |
| 470 | i=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],n,0); | 475 | i=s->method->ssl_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],n,0); |
| 471 | if (i <= 0) | 476 | if (i <= 0) |
| 472 | { | 477 | { |
| 473 | s->rwstate=SSL_READING; | 478 | s->rwstate=SSL_READING; |
| @@ -492,7 +497,7 @@ err: | |||
| 492 | int ssl_cert_type(X509 *x, EVP_PKEY *pkey) | 497 | int ssl_cert_type(X509 *x, EVP_PKEY *pkey) |
| 493 | { | 498 | { |
| 494 | EVP_PKEY *pk; | 499 | EVP_PKEY *pk; |
| 495 | int ret= -1,i,j; | 500 | int ret= -1,i; |
| 496 | 501 | ||
| 497 | if (pkey == NULL) | 502 | if (pkey == NULL) |
| 498 | pk=X509_get_pubkey(x); | 503 | pk=X509_get_pubkey(x); |
| @@ -504,35 +509,17 @@ int ssl_cert_type(X509 *x, EVP_PKEY *pkey) | |||
| 504 | if (i == EVP_PKEY_RSA) | 509 | if (i == EVP_PKEY_RSA) |
| 505 | { | 510 | { |
| 506 | ret=SSL_PKEY_RSA_ENC; | 511 | ret=SSL_PKEY_RSA_ENC; |
| 507 | if (x != NULL) | ||
| 508 | { | ||
| 509 | j=X509_get_ext_count(x); | ||
| 510 | /* check to see if this is a signing only certificate */ | ||
| 511 | /* EAY EAY EAY EAY */ | ||
| 512 | } | ||
| 513 | } | 512 | } |
| 514 | else if (i == EVP_PKEY_DSA) | 513 | else if (i == EVP_PKEY_DSA) |
| 515 | { | 514 | { |
| 516 | ret=SSL_PKEY_DSA_SIGN; | 515 | ret=SSL_PKEY_DSA_SIGN; |
| 517 | } | 516 | } |
| 518 | else if (i == EVP_PKEY_DH) | 517 | #ifndef OPENSSL_NO_EC |
| 518 | else if (i == EVP_PKEY_EC) | ||
| 519 | { | 519 | { |
| 520 | /* if we just have a key, we needs to be guess */ | 520 | ret = SSL_PKEY_ECC; |
| 521 | |||
| 522 | if (x == NULL) | ||
| 523 | ret=SSL_PKEY_DH_DSA; | ||
| 524 | else | ||
| 525 | { | ||
| 526 | j=X509_get_signature_type(x); | ||
| 527 | if (j == EVP_PKEY_RSA) | ||
| 528 | ret=SSL_PKEY_DH_RSA; | ||
| 529 | else if (j== EVP_PKEY_DSA) | ||
| 530 | ret=SSL_PKEY_DH_DSA; | ||
| 531 | else ret= -1; | ||
| 532 | } | ||
| 533 | } | 521 | } |
| 534 | else | 522 | #endif |
| 535 | ret= -1; | ||
| 536 | 523 | ||
| 537 | err: | 524 | err: |
| 538 | if(!pkey) EVP_PKEY_free(pk); | 525 | if(!pkey) EVP_PKEY_free(pk); |
diff --git a/src/lib/libssl/s3_clnt.c b/src/lib/libssl/s3_clnt.c index 05194fdb31..f6864cdc50 100644 --- a/src/lib/libssl/s3_clnt.c +++ b/src/lib/libssl/s3_clnt.c | |||
| @@ -56,7 +56,7 @@ | |||
| 56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
| 57 | */ | 57 | */ |
| 58 | /* ==================================================================== | 58 | /* ==================================================================== |
| 59 | * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. | 59 | * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved. |
| 60 | * | 60 | * |
| 61 | * Redistribution and use in source and binary forms, with or without | 61 | * Redistribution and use in source and binary forms, with or without |
| 62 | * modification, are permitted provided that the following conditions | 62 | * modification, are permitted provided that the following conditions |
| @@ -108,6 +108,19 @@ | |||
| 108 | * Hudson (tjh@cryptsoft.com). | 108 | * Hudson (tjh@cryptsoft.com). |
| 109 | * | 109 | * |
| 110 | */ | 110 | */ |
| 111 | /* ==================================================================== | ||
| 112 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
| 113 | * | ||
| 114 | * Portions of the attached software ("Contribution") are developed by | ||
| 115 | * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. | ||
| 116 | * | ||
| 117 | * The Contribution is licensed pursuant to the OpenSSL open source | ||
| 118 | * license provided above. | ||
| 119 | * | ||
| 120 | * ECC cipher suite support in OpenSSL originally written by | ||
| 121 | * Vipul Gupta and Sumit Gupta of Sun Microsystems Laboratories. | ||
| 122 | * | ||
| 123 | */ | ||
| 111 | 124 | ||
| 112 | #include <stdio.h> | 125 | #include <stdio.h> |
| 113 | #include "ssl_locl.h" | 126 | #include "ssl_locl.h" |
| @@ -117,20 +130,22 @@ | |||
| 117 | #include <openssl/objects.h> | 130 | #include <openssl/objects.h> |
| 118 | #include <openssl/evp.h> | 131 | #include <openssl/evp.h> |
| 119 | #include <openssl/md5.h> | 132 | #include <openssl/md5.h> |
| 120 | #include <openssl/fips.h> | 133 | #ifndef OPENSSL_NO_DH |
| 134 | #include <openssl/dh.h> | ||
| 135 | #endif | ||
| 136 | #include <openssl/bn.h> | ||
| 121 | 137 | ||
| 122 | static SSL_METHOD *ssl3_get_client_method(int ver); | 138 | static SSL_METHOD *ssl3_get_client_method(int ver); |
| 123 | static int ssl3_client_hello(SSL *s); | ||
| 124 | static int ssl3_get_server_hello(SSL *s); | ||
| 125 | static int ssl3_get_certificate_request(SSL *s); | ||
| 126 | static int ca_dn_cmp(const X509_NAME * const *a,const X509_NAME * const *b); | 139 | static int ca_dn_cmp(const X509_NAME * const *a,const X509_NAME * const *b); |
| 127 | static int ssl3_get_server_done(SSL *s); | 140 | #ifndef OPENSSL_NO_TLSEXT |
| 128 | static int ssl3_send_client_verify(SSL *s); | 141 | static int ssl3_check_finished(SSL *s); |
| 129 | static int ssl3_send_client_certificate(SSL *s); | 142 | #endif |
| 130 | static int ssl3_send_client_key_exchange(SSL *s); | 143 | |
| 131 | static int ssl3_get_key_exchange(SSL *s); | 144 | #ifndef OPENSSL_NO_ECDH |
| 132 | static int ssl3_get_server_certificate(SSL *s); | 145 | static int curve_id2nid(int curve_id); |
| 133 | static int ssl3_check_cert_and_algorithm(SSL *s); | 146 | int check_srvr_ecc_cert_and_alg(X509 *x, SSL_CIPHER *cs); |
| 147 | #endif | ||
| 148 | |||
| 134 | static SSL_METHOD *ssl3_get_client_method(int ver) | 149 | static SSL_METHOD *ssl3_get_client_method(int ver) |
| 135 | { | 150 | { |
| 136 | if (ver == SSL3_VERSION) | 151 | if (ver == SSL3_VERSION) |
| @@ -139,28 +154,10 @@ static SSL_METHOD *ssl3_get_client_method(int ver) | |||
| 139 | return(NULL); | 154 | return(NULL); |
| 140 | } | 155 | } |
| 141 | 156 | ||
| 142 | SSL_METHOD *SSLv3_client_method(void) | 157 | IMPLEMENT_ssl3_meth_func(SSLv3_client_method, |
| 143 | { | 158 | ssl_undefined_function, |
| 144 | static int init=1; | 159 | ssl3_connect, |
| 145 | static SSL_METHOD SSLv3_client_data; | 160 | ssl3_get_client_method) |
| 146 | |||
| 147 | if (init) | ||
| 148 | { | ||
| 149 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD); | ||
| 150 | |||
| 151 | if (init) | ||
| 152 | { | ||
| 153 | memcpy((char *)&SSLv3_client_data,(char *)sslv3_base_method(), | ||
| 154 | sizeof(SSL_METHOD)); | ||
| 155 | SSLv3_client_data.ssl_connect=ssl3_connect; | ||
| 156 | SSLv3_client_data.get_ssl_method=ssl3_get_client_method; | ||
| 157 | init=0; | ||
| 158 | } | ||
| 159 | |||
| 160 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD); | ||
| 161 | } | ||
| 162 | return(&SSLv3_client_data); | ||
| 163 | } | ||
| 164 | 161 | ||
| 165 | int ssl3_connect(SSL *s) | 162 | int ssl3_connect(SSL *s) |
| 166 | { | 163 | { |
| @@ -270,15 +267,43 @@ int ssl3_connect(SSL *s) | |||
| 270 | 267 | ||
| 271 | case SSL3_ST_CR_CERT_A: | 268 | case SSL3_ST_CR_CERT_A: |
| 272 | case SSL3_ST_CR_CERT_B: | 269 | case SSL3_ST_CR_CERT_B: |
| 273 | /* Check if it is anon DH */ | 270 | #ifndef OPENSSL_NO_TLSEXT |
| 271 | ret=ssl3_check_finished(s); | ||
| 272 | if (ret <= 0) goto end; | ||
| 273 | if (ret == 2) | ||
| 274 | { | ||
| 275 | s->hit = 1; | ||
| 276 | if (s->tlsext_ticket_expected) | ||
| 277 | s->state=SSL3_ST_CR_SESSION_TICKET_A; | ||
| 278 | else | ||
| 279 | s->state=SSL3_ST_CR_FINISHED_A; | ||
| 280 | s->init_num=0; | ||
| 281 | break; | ||
| 282 | } | ||
| 283 | #endif | ||
| 284 | /* Check if it is anon DH/ECDH */ | ||
| 274 | if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL)) | 285 | if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL)) |
| 275 | { | 286 | { |
| 276 | ret=ssl3_get_server_certificate(s); | 287 | ret=ssl3_get_server_certificate(s); |
| 277 | if (ret <= 0) goto end; | 288 | if (ret <= 0) goto end; |
| 289 | #ifndef OPENSSL_NO_TLSEXT | ||
| 290 | if (s->tlsext_status_expected) | ||
| 291 | s->state=SSL3_ST_CR_CERT_STATUS_A; | ||
| 292 | else | ||
| 293 | s->state=SSL3_ST_CR_KEY_EXCH_A; | ||
| 294 | } | ||
| 295 | else | ||
| 296 | { | ||
| 297 | skip = 1; | ||
| 298 | s->state=SSL3_ST_CR_KEY_EXCH_A; | ||
| 299 | } | ||
| 300 | #else | ||
| 278 | } | 301 | } |
| 279 | else | 302 | else |
| 280 | skip=1; | 303 | skip=1; |
| 304 | |||
| 281 | s->state=SSL3_ST_CR_KEY_EXCH_A; | 305 | s->state=SSL3_ST_CR_KEY_EXCH_A; |
| 306 | #endif | ||
| 282 | s->init_num=0; | 307 | s->init_num=0; |
| 283 | break; | 308 | break; |
| 284 | 309 | ||
| @@ -337,6 +362,13 @@ int ssl3_connect(SSL *s) | |||
| 337 | * sent back */ | 362 | * sent back */ |
| 338 | /* For TLS, cert_req is set to 2, so a cert chain | 363 | /* For TLS, cert_req is set to 2, so a cert chain |
| 339 | * of nothing is sent, but no verify packet is sent */ | 364 | * of nothing is sent, but no verify packet is sent */ |
| 365 | /* XXX: For now, we do not support client | ||
| 366 | * authentication in ECDH cipher suites with | ||
| 367 | * ECDH (rather than ECDSA) certificates. | ||
| 368 | * We need to skip the certificate verify | ||
| 369 | * message when client's ECDH public key is sent | ||
| 370 | * inside the client certificate. | ||
| 371 | */ | ||
| 340 | if (s->s3->tmp.cert_req == 1) | 372 | if (s->s3->tmp.cert_req == 1) |
| 341 | { | 373 | { |
| 342 | s->state=SSL3_ST_CW_CERT_VRFY_A; | 374 | s->state=SSL3_ST_CW_CERT_VRFY_A; |
| @@ -368,11 +400,15 @@ int ssl3_connect(SSL *s) | |||
| 368 | s->init_num=0; | 400 | s->init_num=0; |
| 369 | 401 | ||
| 370 | s->session->cipher=s->s3->tmp.new_cipher; | 402 | s->session->cipher=s->s3->tmp.new_cipher; |
| 403 | #ifdef OPENSSL_NO_COMP | ||
| 404 | s->session->compress_meth=0; | ||
| 405 | #else | ||
| 371 | if (s->s3->tmp.new_compression == NULL) | 406 | if (s->s3->tmp.new_compression == NULL) |
| 372 | s->session->compress_meth=0; | 407 | s->session->compress_meth=0; |
| 373 | else | 408 | else |
| 374 | s->session->compress_meth= | 409 | s->session->compress_meth= |
| 375 | s->s3->tmp.new_compression->id; | 410 | s->s3->tmp.new_compression->id; |
| 411 | #endif | ||
| 376 | if (!s->method->ssl3_enc->setup_key_block(s)) | 412 | if (!s->method->ssl3_enc->setup_key_block(s)) |
| 377 | { | 413 | { |
| 378 | ret= -1; | 414 | ret= -1; |
| @@ -411,11 +447,36 @@ int ssl3_connect(SSL *s) | |||
| 411 | } | 447 | } |
| 412 | else | 448 | else |
| 413 | { | 449 | { |
| 450 | #ifndef OPENSSL_NO_TLSEXT | ||
| 451 | /* Allow NewSessionTicket if ticket expected */ | ||
| 452 | if (s->tlsext_ticket_expected) | ||
| 453 | s->s3->tmp.next_state=SSL3_ST_CR_SESSION_TICKET_A; | ||
| 454 | else | ||
| 455 | #endif | ||
| 456 | |||
| 414 | s->s3->tmp.next_state=SSL3_ST_CR_FINISHED_A; | 457 | s->s3->tmp.next_state=SSL3_ST_CR_FINISHED_A; |
| 415 | } | 458 | } |
| 416 | s->init_num=0; | 459 | s->init_num=0; |
| 417 | break; | 460 | break; |
| 418 | 461 | ||
| 462 | #ifndef OPENSSL_NO_TLSEXT | ||
| 463 | case SSL3_ST_CR_SESSION_TICKET_A: | ||
| 464 | case SSL3_ST_CR_SESSION_TICKET_B: | ||
| 465 | ret=ssl3_get_new_session_ticket(s); | ||
| 466 | if (ret <= 0) goto end; | ||
| 467 | s->state=SSL3_ST_CR_FINISHED_A; | ||
| 468 | s->init_num=0; | ||
| 469 | break; | ||
| 470 | |||
| 471 | case SSL3_ST_CR_CERT_STATUS_A: | ||
| 472 | case SSL3_ST_CR_CERT_STATUS_B: | ||
| 473 | ret=ssl3_get_cert_status(s); | ||
| 474 | if (ret <= 0) goto end; | ||
| 475 | s->state=SSL3_ST_CR_KEY_EXCH_A; | ||
| 476 | s->init_num=0; | ||
| 477 | break; | ||
| 478 | #endif | ||
| 479 | |||
| 419 | case SSL3_ST_CR_FINISHED_A: | 480 | case SSL3_ST_CR_FINISHED_A: |
| 420 | case SSL3_ST_CR_FINISHED_B: | 481 | case SSL3_ST_CR_FINISHED_B: |
| 421 | 482 | ||
| @@ -512,13 +573,16 @@ end: | |||
| 512 | } | 573 | } |
| 513 | 574 | ||
| 514 | 575 | ||
| 515 | static int ssl3_client_hello(SSL *s) | 576 | int ssl3_client_hello(SSL *s) |
| 516 | { | 577 | { |
| 517 | unsigned char *buf; | 578 | unsigned char *buf; |
| 518 | unsigned char *p,*d; | 579 | unsigned char *p,*d; |
| 519 | int i,j; | 580 | int i; |
| 520 | unsigned long Time,l; | 581 | unsigned long Time,l; |
| 582 | #ifndef OPENSSL_NO_COMP | ||
| 583 | int j; | ||
| 521 | SSL_COMP *comp; | 584 | SSL_COMP *comp; |
| 585 | #endif | ||
| 522 | 586 | ||
| 523 | buf=(unsigned char *)s->init_buf->data; | 587 | buf=(unsigned char *)s->init_buf->data; |
| 524 | if (s->state == SSL3_ST_CW_CLNT_HELLO_A) | 588 | if (s->state == SSL3_ST_CW_CLNT_HELLO_A) |
| @@ -535,8 +599,8 @@ static int ssl3_client_hello(SSL *s) | |||
| 535 | p=s->s3->client_random; | 599 | p=s->s3->client_random; |
| 536 | Time=(unsigned long)time(NULL); /* Time */ | 600 | Time=(unsigned long)time(NULL); /* Time */ |
| 537 | l2n(Time,p); | 601 | l2n(Time,p); |
| 538 | if(RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4) <= 0) | 602 | if (RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4) <= 0) |
| 539 | goto err; | 603 | goto err; |
| 540 | 604 | ||
| 541 | /* Do the message type and length last */ | 605 | /* Do the message type and length last */ |
| 542 | d=p= &(buf[4]); | 606 | d=p= &(buf[4]); |
| @@ -557,7 +621,7 @@ static int ssl3_client_hello(SSL *s) | |||
| 557 | *(p++)=i; | 621 | *(p++)=i; |
| 558 | if (i != 0) | 622 | if (i != 0) |
| 559 | { | 623 | { |
| 560 | if (i > sizeof s->session->session_id) | 624 | if (i > (int)sizeof(s->session->session_id)) |
| 561 | { | 625 | { |
| 562 | SSLerr(SSL_F_SSL3_CLIENT_HELLO, ERR_R_INTERNAL_ERROR); | 626 | SSLerr(SSL_F_SSL3_CLIENT_HELLO, ERR_R_INTERNAL_ERROR); |
| 563 | goto err; | 627 | goto err; |
| @@ -577,6 +641,9 @@ static int ssl3_client_hello(SSL *s) | |||
| 577 | p+=i; | 641 | p+=i; |
| 578 | 642 | ||
| 579 | /* COMPRESSION */ | 643 | /* COMPRESSION */ |
| 644 | #ifdef OPENSSL_NO_COMP | ||
| 645 | *(p++)=1; | ||
| 646 | #else | ||
| 580 | if (s->ctx->comp_methods == NULL) | 647 | if (s->ctx->comp_methods == NULL) |
| 581 | j=0; | 648 | j=0; |
| 582 | else | 649 | else |
| @@ -587,8 +654,15 @@ static int ssl3_client_hello(SSL *s) | |||
| 587 | comp=sk_SSL_COMP_value(s->ctx->comp_methods,i); | 654 | comp=sk_SSL_COMP_value(s->ctx->comp_methods,i); |
| 588 | *(p++)=comp->id; | 655 | *(p++)=comp->id; |
| 589 | } | 656 | } |
| 657 | #endif | ||
| 590 | *(p++)=0; /* Add the NULL method */ | 658 | *(p++)=0; /* Add the NULL method */ |
| 591 | 659 | #ifndef OPENSSL_NO_TLSEXT | |
| 660 | if ((p = ssl_add_clienthello_tlsext(s, p, buf+SSL3_RT_MAX_PLAIN_LENGTH)) == NULL) | ||
| 661 | { | ||
| 662 | SSLerr(SSL_F_SSL3_CLIENT_HELLO,ERR_R_INTERNAL_ERROR); | ||
| 663 | goto err; | ||
| 664 | } | ||
| 665 | #endif | ||
| 592 | l=(p-d); | 666 | l=(p-d); |
| 593 | d=buf; | 667 | d=buf; |
| 594 | *(d++)=SSL3_MT_CLIENT_HELLO; | 668 | *(d++)=SSL3_MT_CLIENT_HELLO; |
| @@ -606,7 +680,7 @@ err: | |||
| 606 | return(-1); | 680 | return(-1); |
| 607 | } | 681 | } |
| 608 | 682 | ||
| 609 | static int ssl3_get_server_hello(SSL *s) | 683 | int ssl3_get_server_hello(SSL *s) |
| 610 | { | 684 | { |
| 611 | STACK_OF(SSL_CIPHER) *sk; | 685 | STACK_OF(SSL_CIPHER) *sk; |
| 612 | SSL_CIPHER *c; | 686 | SSL_CIPHER *c; |
| @@ -614,16 +688,44 @@ static int ssl3_get_server_hello(SSL *s) | |||
| 614 | int i,al,ok; | 688 | int i,al,ok; |
| 615 | unsigned int j; | 689 | unsigned int j; |
| 616 | long n; | 690 | long n; |
| 691 | #ifndef OPENSSL_NO_COMP | ||
| 617 | SSL_COMP *comp; | 692 | SSL_COMP *comp; |
| 693 | #endif | ||
| 618 | 694 | ||
| 619 | n=ssl3_get_message(s, | 695 | n=s->method->ssl_get_message(s, |
| 620 | SSL3_ST_CR_SRVR_HELLO_A, | 696 | SSL3_ST_CR_SRVR_HELLO_A, |
| 621 | SSL3_ST_CR_SRVR_HELLO_B, | 697 | SSL3_ST_CR_SRVR_HELLO_B, |
| 622 | SSL3_MT_SERVER_HELLO, | 698 | -1, |
| 623 | 300, /* ?? */ | 699 | 20000, /* ?? */ |
| 624 | &ok); | 700 | &ok); |
| 625 | 701 | ||
| 626 | if (!ok) return((int)n); | 702 | if (!ok) return((int)n); |
| 703 | |||
| 704 | if ( SSL_version(s) == DTLS1_VERSION) | ||
| 705 | { | ||
| 706 | if ( s->s3->tmp.message_type == DTLS1_MT_HELLO_VERIFY_REQUEST) | ||
| 707 | { | ||
| 708 | if ( s->d1->send_cookie == 0) | ||
| 709 | { | ||
| 710 | s->s3->tmp.reuse_message = 1; | ||
| 711 | return 1; | ||
| 712 | } | ||
| 713 | else /* already sent a cookie */ | ||
| 714 | { | ||
| 715 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
| 716 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_BAD_MESSAGE_TYPE); | ||
| 717 | goto f_err; | ||
| 718 | } | ||
| 719 | } | ||
| 720 | } | ||
| 721 | |||
| 722 | if ( s->s3->tmp.message_type != SSL3_MT_SERVER_HELLO) | ||
| 723 | { | ||
| 724 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
| 725 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_BAD_MESSAGE_TYPE); | ||
| 726 | goto f_err; | ||
| 727 | } | ||
| 728 | |||
| 627 | d=p=(unsigned char *)s->init_msg; | 729 | d=p=(unsigned char *)s->init_msg; |
| 628 | 730 | ||
| 629 | if ((p[0] != (s->version>>8)) || (p[1] != (s->version&0xff))) | 731 | if ((p[0] != (s->version>>8)) || (p[1] != (s->version&0xff))) |
| @@ -719,6 +821,14 @@ static int ssl3_get_server_hello(SSL *s) | |||
| 719 | 821 | ||
| 720 | /* lets get the compression algorithm */ | 822 | /* lets get the compression algorithm */ |
| 721 | /* COMPRESSION */ | 823 | /* COMPRESSION */ |
| 824 | #ifdef OPENSSL_NO_COMP | ||
| 825 | if (*(p++) != 0) | ||
| 826 | { | ||
| 827 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
| 828 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM); | ||
| 829 | goto f_err; | ||
| 830 | } | ||
| 831 | #else | ||
| 722 | j= *(p++); | 832 | j= *(p++); |
| 723 | if (j == 0) | 833 | if (j == 0) |
| 724 | comp=NULL; | 834 | comp=NULL; |
| @@ -735,6 +845,25 @@ static int ssl3_get_server_hello(SSL *s) | |||
| 735 | { | 845 | { |
| 736 | s->s3->tmp.new_compression=comp; | 846 | s->s3->tmp.new_compression=comp; |
| 737 | } | 847 | } |
| 848 | #endif | ||
| 849 | #ifndef OPENSSL_NO_TLSEXT | ||
| 850 | /* TLS extensions*/ | ||
| 851 | if (s->version > SSL3_VERSION) | ||
| 852 | { | ||
| 853 | if (!ssl_parse_serverhello_tlsext(s,&p,d,n, &al)) | ||
| 854 | { | ||
| 855 | /* 'al' set by ssl_parse_serverhello_tlsext */ | ||
| 856 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_PARSE_TLSEXT); | ||
| 857 | goto f_err; | ||
| 858 | } | ||
| 859 | if (ssl_check_serverhello_tlsext(s) <= 0) | ||
| 860 | { | ||
| 861 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_SERVERHELLO_TLSEXT); | ||
| 862 | goto err; | ||
| 863 | } | ||
| 864 | } | ||
| 865 | #endif | ||
| 866 | |||
| 738 | 867 | ||
| 739 | if (p != (d+n)) | 868 | if (p != (d+n)) |
| 740 | { | 869 | { |
| @@ -751,18 +880,19 @@ err: | |||
| 751 | return(-1); | 880 | return(-1); |
| 752 | } | 881 | } |
| 753 | 882 | ||
| 754 | static int ssl3_get_server_certificate(SSL *s) | 883 | int ssl3_get_server_certificate(SSL *s) |
| 755 | { | 884 | { |
| 756 | int al,i,ok,ret= -1; | 885 | int al,i,ok,ret= -1; |
| 757 | unsigned long n,nc,llen,l; | 886 | unsigned long n,nc,llen,l; |
| 758 | X509 *x=NULL; | 887 | X509 *x=NULL; |
| 759 | unsigned char *p,*d,*q; | 888 | const unsigned char *q,*p; |
| 889 | unsigned char *d; | ||
| 760 | STACK_OF(X509) *sk=NULL; | 890 | STACK_OF(X509) *sk=NULL; |
| 761 | SESS_CERT *sc; | 891 | SESS_CERT *sc; |
| 762 | EVP_PKEY *pkey=NULL; | 892 | EVP_PKEY *pkey=NULL; |
| 763 | int need_cert = 1; /* VRS: 0=> will allow null cert if auth == KRB5 */ | 893 | int need_cert = 1; /* VRS: 0=> will allow null cert if auth == KRB5 */ |
| 764 | 894 | ||
| 765 | n=ssl3_get_message(s, | 895 | n=s->method->ssl_get_message(s, |
| 766 | SSL3_ST_CR_CERT_A, | 896 | SSL3_ST_CR_CERT_A, |
| 767 | SSL3_ST_CR_CERT_B, | 897 | SSL3_ST_CR_CERT_B, |
| 768 | -1, | 898 | -1, |
| @@ -771,7 +901,9 @@ static int ssl3_get_server_certificate(SSL *s) | |||
| 771 | 901 | ||
| 772 | if (!ok) return((int)n); | 902 | if (!ok) return((int)n); |
| 773 | 903 | ||
| 774 | if (s->s3->tmp.message_type == SSL3_MT_SERVER_KEY_EXCHANGE) | 904 | if ((s->s3->tmp.message_type == SSL3_MT_SERVER_KEY_EXCHANGE) || |
| 905 | ((s->s3->tmp.new_cipher->algorithms & SSL_aKRB5) && | ||
| 906 | (s->s3->tmp.message_type == SSL3_MT_SERVER_DONE))) | ||
| 775 | { | 907 | { |
| 776 | s->s3->tmp.reuse_message=1; | 908 | s->s3->tmp.reuse_message=1; |
| 777 | return(1); | 909 | return(1); |
| @@ -783,7 +915,7 @@ static int ssl3_get_server_certificate(SSL *s) | |||
| 783 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_BAD_MESSAGE_TYPE); | 915 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_BAD_MESSAGE_TYPE); |
| 784 | goto f_err; | 916 | goto f_err; |
| 785 | } | 917 | } |
| 786 | d=p=(unsigned char *)s->init_msg; | 918 | p=d=(unsigned char *)s->init_msg; |
| 787 | 919 | ||
| 788 | if ((sk=sk_X509_new_null()) == NULL) | 920 | if ((sk=sk_X509_new_null()) == NULL) |
| 789 | { | 921 | { |
| @@ -835,10 +967,10 @@ static int ssl3_get_server_certificate(SSL *s) | |||
| 835 | i=ssl_verify_cert_chain(s,sk); | 967 | i=ssl_verify_cert_chain(s,sk); |
| 836 | if ((s->verify_mode != SSL_VERIFY_NONE) && (!i) | 968 | if ((s->verify_mode != SSL_VERIFY_NONE) && (!i) |
| 837 | #ifndef OPENSSL_NO_KRB5 | 969 | #ifndef OPENSSL_NO_KRB5 |
| 838 | && (s->s3->tmp.new_cipher->algorithms & (SSL_MKEY_MASK|SSL_AUTH_MASK)) | 970 | && (s->s3->tmp.new_cipher->algorithms & (SSL_MKEY_MASK|SSL_AUTH_MASK)) |
| 839 | != (SSL_aKRB5|SSL_kKRB5) | 971 | != (SSL_aKRB5|SSL_kKRB5) |
| 840 | #endif /* OPENSSL_NO_KRB5 */ | 972 | #endif /* OPENSSL_NO_KRB5 */ |
| 841 | ) | 973 | ) |
| 842 | { | 974 | { |
| 843 | al=ssl_verify_alarm_type(s->verify_result); | 975 | al=ssl_verify_alarm_type(s->verify_result); |
| 844 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERTIFICATE_VERIFY_FAILED); | 976 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERTIFICATE_VERIFY_FAILED); |
| @@ -861,16 +993,16 @@ static int ssl3_get_server_certificate(SSL *s) | |||
| 861 | 993 | ||
| 862 | pkey=X509_get_pubkey(x); | 994 | pkey=X509_get_pubkey(x); |
| 863 | 995 | ||
| 864 | /* VRS: allow null cert if auth == KRB5 */ | 996 | /* VRS: allow null cert if auth == KRB5 */ |
| 865 | need_cert = ((s->s3->tmp.new_cipher->algorithms | 997 | need_cert = ((s->s3->tmp.new_cipher->algorithms |
| 866 | & (SSL_MKEY_MASK|SSL_AUTH_MASK)) | 998 | & (SSL_MKEY_MASK|SSL_AUTH_MASK)) |
| 867 | == (SSL_aKRB5|SSL_kKRB5))? 0: 1; | 999 | == (SSL_aKRB5|SSL_kKRB5))? 0: 1; |
| 868 | 1000 | ||
| 869 | #ifdef KSSL_DEBUG | 1001 | #ifdef KSSL_DEBUG |
| 870 | printf("pkey,x = %p, %p\n", pkey,x); | 1002 | printf("pkey,x = %p, %p\n", pkey,x); |
| 871 | printf("ssl_cert_type(x,pkey) = %d\n", ssl_cert_type(x,pkey)); | 1003 | printf("ssl_cert_type(x,pkey) = %d\n", ssl_cert_type(x,pkey)); |
| 872 | printf("cipher, alg, nc = %s, %lx, %d\n", s->s3->tmp.new_cipher->name, | 1004 | printf("cipher, alg, nc = %s, %lx, %d\n", s->s3->tmp.new_cipher->name, |
| 873 | s->s3->tmp.new_cipher->algorithms, need_cert); | 1005 | s->s3->tmp.new_cipher->algorithms, need_cert); |
| 874 | #endif /* KSSL_DEBUG */ | 1006 | #endif /* KSSL_DEBUG */ |
| 875 | 1007 | ||
| 876 | if (need_cert && ((pkey == NULL) || EVP_PKEY_missing_parameters(pkey))) | 1008 | if (need_cert && ((pkey == NULL) || EVP_PKEY_missing_parameters(pkey))) |
| @@ -892,31 +1024,31 @@ static int ssl3_get_server_certificate(SSL *s) | |||
| 892 | goto f_err; | 1024 | goto f_err; |
| 893 | } | 1025 | } |
| 894 | 1026 | ||
| 895 | if (need_cert) | 1027 | if (need_cert) |
| 896 | { | 1028 | { |
| 897 | sc->peer_cert_type=i; | 1029 | sc->peer_cert_type=i; |
| 898 | CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509); | 1030 | CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509); |
| 899 | /* Why would the following ever happen? | 1031 | /* Why would the following ever happen? |
| 900 | * We just created sc a couple of lines ago. */ | 1032 | * We just created sc a couple of lines ago. */ |
| 901 | if (sc->peer_pkeys[i].x509 != NULL) | 1033 | if (sc->peer_pkeys[i].x509 != NULL) |
| 902 | X509_free(sc->peer_pkeys[i].x509); | 1034 | X509_free(sc->peer_pkeys[i].x509); |
| 903 | sc->peer_pkeys[i].x509=x; | 1035 | sc->peer_pkeys[i].x509=x; |
| 904 | sc->peer_key= &(sc->peer_pkeys[i]); | 1036 | sc->peer_key= &(sc->peer_pkeys[i]); |
| 905 | 1037 | ||
| 906 | if (s->session->peer != NULL) | 1038 | if (s->session->peer != NULL) |
| 907 | X509_free(s->session->peer); | 1039 | X509_free(s->session->peer); |
| 908 | CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509); | 1040 | CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509); |
| 909 | s->session->peer=x; | 1041 | s->session->peer=x; |
| 910 | } | 1042 | } |
| 911 | else | 1043 | else |
| 912 | { | 1044 | { |
| 913 | sc->peer_cert_type=i; | 1045 | sc->peer_cert_type=i; |
| 914 | sc->peer_key= NULL; | 1046 | sc->peer_key= NULL; |
| 915 | 1047 | ||
| 916 | if (s->session->peer != NULL) | 1048 | if (s->session->peer != NULL) |
| 917 | X509_free(s->session->peer); | 1049 | X509_free(s->session->peer); |
| 918 | s->session->peer=NULL; | 1050 | s->session->peer=NULL; |
| 919 | } | 1051 | } |
| 920 | s->session->verify_result = s->verify_result; | 1052 | s->session->verify_result = s->verify_result; |
| 921 | 1053 | ||
| 922 | x=NULL; | 1054 | x=NULL; |
| @@ -934,7 +1066,7 @@ err: | |||
| 934 | return(ret); | 1066 | return(ret); |
| 935 | } | 1067 | } |
| 936 | 1068 | ||
| 937 | static int ssl3_get_key_exchange(SSL *s) | 1069 | int ssl3_get_key_exchange(SSL *s) |
| 938 | { | 1070 | { |
| 939 | #ifndef OPENSSL_NO_RSA | 1071 | #ifndef OPENSSL_NO_RSA |
| 940 | unsigned char *q,md_buf[EVP_MAX_MD_SIZE*2]; | 1072 | unsigned char *q,md_buf[EVP_MAX_MD_SIZE*2]; |
| @@ -950,10 +1082,17 @@ static int ssl3_get_key_exchange(SSL *s) | |||
| 950 | #ifndef OPENSSL_NO_DH | 1082 | #ifndef OPENSSL_NO_DH |
| 951 | DH *dh=NULL; | 1083 | DH *dh=NULL; |
| 952 | #endif | 1084 | #endif |
| 1085 | #ifndef OPENSSL_NO_ECDH | ||
| 1086 | EC_KEY *ecdh = NULL; | ||
| 1087 | BN_CTX *bn_ctx = NULL; | ||
| 1088 | EC_POINT *srvr_ecpoint = NULL; | ||
| 1089 | int curve_nid = 0; | ||
| 1090 | int encoded_pt_len = 0; | ||
| 1091 | #endif | ||
| 953 | 1092 | ||
| 954 | /* use same message size as in ssl3_get_certificate_request() | 1093 | /* use same message size as in ssl3_get_certificate_request() |
| 955 | * as ServerKeyExchange message may be skipped */ | 1094 | * as ServerKeyExchange message may be skipped */ |
| 956 | n=ssl3_get_message(s, | 1095 | n=s->method->ssl_get_message(s, |
| 957 | SSL3_ST_CR_KEY_EXCH_A, | 1096 | SSL3_ST_CR_KEY_EXCH_A, |
| 958 | SSL3_ST_CR_KEY_EXCH_B, | 1097 | SSL3_ST_CR_KEY_EXCH_B, |
| 959 | -1, | 1098 | -1, |
| @@ -986,6 +1125,13 @@ static int ssl3_get_key_exchange(SSL *s) | |||
| 986 | s->session->sess_cert->peer_dh_tmp=NULL; | 1125 | s->session->sess_cert->peer_dh_tmp=NULL; |
| 987 | } | 1126 | } |
| 988 | #endif | 1127 | #endif |
| 1128 | #ifndef OPENSSL_NO_ECDH | ||
| 1129 | if (s->session->sess_cert->peer_ecdh_tmp) | ||
| 1130 | { | ||
| 1131 | EC_KEY_free(s->session->sess_cert->peer_ecdh_tmp); | ||
| 1132 | s->session->sess_cert->peer_ecdh_tmp=NULL; | ||
| 1133 | } | ||
| 1134 | #endif | ||
| 989 | } | 1135 | } |
| 990 | else | 1136 | else |
| 991 | { | 1137 | { |
| @@ -1127,6 +1273,114 @@ static int ssl3_get_key_exchange(SSL *s) | |||
| 1127 | goto f_err; | 1273 | goto f_err; |
| 1128 | } | 1274 | } |
| 1129 | #endif /* !OPENSSL_NO_DH */ | 1275 | #endif /* !OPENSSL_NO_DH */ |
| 1276 | |||
| 1277 | #ifndef OPENSSL_NO_ECDH | ||
| 1278 | else if (alg & SSL_kECDHE) | ||
| 1279 | { | ||
| 1280 | EC_GROUP *ngroup; | ||
| 1281 | const EC_GROUP *group; | ||
| 1282 | |||
| 1283 | if ((ecdh=EC_KEY_new()) == NULL) | ||
| 1284 | { | ||
| 1285 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE); | ||
| 1286 | goto err; | ||
| 1287 | } | ||
| 1288 | |||
| 1289 | /* Extract elliptic curve parameters and the | ||
| 1290 | * server's ephemeral ECDH public key. | ||
| 1291 | * Keep accumulating lengths of various components in | ||
| 1292 | * param_len and make sure it never exceeds n. | ||
| 1293 | */ | ||
| 1294 | |||
| 1295 | /* XXX: For now we only support named (not generic) curves | ||
| 1296 | * and the ECParameters in this case is just three bytes. | ||
| 1297 | */ | ||
| 1298 | param_len=3; | ||
| 1299 | if ((param_len > n) || | ||
| 1300 | (*p != NAMED_CURVE_TYPE) || | ||
| 1301 | ((curve_nid = curve_id2nid(*(p + 2))) == 0)) | ||
| 1302 | { | ||
| 1303 | al=SSL_AD_INTERNAL_ERROR; | ||
| 1304 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_UNABLE_TO_FIND_ECDH_PARAMETERS); | ||
| 1305 | goto f_err; | ||
| 1306 | } | ||
| 1307 | |||
| 1308 | ngroup = EC_GROUP_new_by_curve_name(curve_nid); | ||
| 1309 | if (ngroup == NULL) | ||
| 1310 | { | ||
| 1311 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_EC_LIB); | ||
| 1312 | goto err; | ||
| 1313 | } | ||
| 1314 | if (EC_KEY_set_group(ecdh, ngroup) == 0) | ||
| 1315 | { | ||
| 1316 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_EC_LIB); | ||
| 1317 | goto err; | ||
| 1318 | } | ||
| 1319 | EC_GROUP_free(ngroup); | ||
| 1320 | |||
| 1321 | group = EC_KEY_get0_group(ecdh); | ||
| 1322 | |||
| 1323 | if (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && | ||
| 1324 | (EC_GROUP_get_degree(group) > 163)) | ||
| 1325 | { | ||
| 1326 | al=SSL_AD_EXPORT_RESTRICTION; | ||
| 1327 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_ECGROUP_TOO_LARGE_FOR_CIPHER); | ||
| 1328 | goto f_err; | ||
| 1329 | } | ||
| 1330 | |||
| 1331 | p+=3; | ||
| 1332 | |||
| 1333 | /* Next, get the encoded ECPoint */ | ||
| 1334 | if (((srvr_ecpoint = EC_POINT_new(group)) == NULL) || | ||
| 1335 | ((bn_ctx = BN_CTX_new()) == NULL)) | ||
| 1336 | { | ||
| 1337 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE); | ||
| 1338 | goto err; | ||
| 1339 | } | ||
| 1340 | |||
| 1341 | encoded_pt_len = *p; /* length of encoded point */ | ||
| 1342 | p+=1; | ||
| 1343 | param_len += (1 + encoded_pt_len); | ||
| 1344 | if ((param_len > n) || | ||
| 1345 | (EC_POINT_oct2point(group, srvr_ecpoint, | ||
| 1346 | p, encoded_pt_len, bn_ctx) == 0)) | ||
| 1347 | { | ||
| 1348 | al=SSL_AD_DECODE_ERROR; | ||
| 1349 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_ECPOINT); | ||
| 1350 | goto f_err; | ||
| 1351 | } | ||
| 1352 | |||
| 1353 | n-=param_len; | ||
| 1354 | p+=encoded_pt_len; | ||
| 1355 | |||
| 1356 | /* The ECC/TLS specification does not mention | ||
| 1357 | * the use of DSA to sign ECParameters in the server | ||
| 1358 | * key exchange message. We do support RSA and ECDSA. | ||
| 1359 | */ | ||
| 1360 | if (0) ; | ||
| 1361 | #ifndef OPENSSL_NO_RSA | ||
| 1362 | else if (alg & SSL_aRSA) | ||
| 1363 | pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509); | ||
| 1364 | #endif | ||
| 1365 | #ifndef OPENSSL_NO_ECDSA | ||
| 1366 | else if (alg & SSL_aECDSA) | ||
| 1367 | pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_ECC].x509); | ||
| 1368 | #endif | ||
| 1369 | /* else anonymous ECDH, so no certificate or pkey. */ | ||
| 1370 | EC_KEY_set_public_key(ecdh, srvr_ecpoint); | ||
| 1371 | s->session->sess_cert->peer_ecdh_tmp=ecdh; | ||
| 1372 | ecdh=NULL; | ||
| 1373 | BN_CTX_free(bn_ctx); | ||
| 1374 | EC_POINT_free(srvr_ecpoint); | ||
| 1375 | srvr_ecpoint = NULL; | ||
| 1376 | } | ||
| 1377 | else if (alg & SSL_kECDH) | ||
| 1378 | { | ||
| 1379 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
| 1380 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_UNEXPECTED_MESSAGE); | ||
| 1381 | goto f_err; | ||
| 1382 | } | ||
| 1383 | #endif /* !OPENSSL_NO_ECDH */ | ||
| 1130 | if (alg & SSL_aFZA) | 1384 | if (alg & SSL_aFZA) |
| 1131 | { | 1385 | { |
| 1132 | al=SSL_AD_HANDSHAKE_FAILURE; | 1386 | al=SSL_AD_HANDSHAKE_FAILURE; |
| @@ -1137,7 +1391,6 @@ static int ssl3_get_key_exchange(SSL *s) | |||
| 1137 | 1391 | ||
| 1138 | /* p points to the next byte, there are 'n' bytes left */ | 1392 | /* p points to the next byte, there are 'n' bytes left */ |
| 1139 | 1393 | ||
| 1140 | |||
| 1141 | /* if it was signed, check the signature */ | 1394 | /* if it was signed, check the signature */ |
| 1142 | if (pkey != NULL) | 1395 | if (pkey != NULL) |
| 1143 | { | 1396 | { |
| @@ -1162,14 +1415,11 @@ static int ssl3_get_key_exchange(SSL *s) | |||
| 1162 | q=md_buf; | 1415 | q=md_buf; |
| 1163 | for (num=2; num > 0; num--) | 1416 | for (num=2; num > 0; num--) |
| 1164 | { | 1417 | { |
| 1165 | EVP_MD_CTX_set_flags(&md_ctx, | ||
| 1166 | EVP_MD_CTX_FLAG_NON_FIPS_ALLOW); | ||
| 1167 | EVP_DigestInit_ex(&md_ctx,(num == 2) | 1418 | EVP_DigestInit_ex(&md_ctx,(num == 2) |
| 1168 | ?s->ctx->md5:s->ctx->sha1, NULL); | 1419 | ?s->ctx->md5:s->ctx->sha1, NULL); |
| 1169 | EVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE); | 1420 | EVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE); |
| 1170 | EVP_DigestUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE); | 1421 | EVP_DigestUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE); |
| 1171 | EVP_DigestUpdate(&md_ctx,param,param_len); | 1422 | EVP_DigestUpdate(&md_ctx,param,param_len); |
| 1172 | |||
| 1173 | EVP_DigestFinal_ex(&md_ctx,q,(unsigned int *)&i); | 1423 | EVP_DigestFinal_ex(&md_ctx,q,(unsigned int *)&i); |
| 1174 | q+=i; | 1424 | q+=i; |
| 1175 | j+=i; | 1425 | j+=i; |
| @@ -1210,6 +1460,24 @@ static int ssl3_get_key_exchange(SSL *s) | |||
| 1210 | } | 1460 | } |
| 1211 | else | 1461 | else |
| 1212 | #endif | 1462 | #endif |
| 1463 | #ifndef OPENSSL_NO_ECDSA | ||
| 1464 | if (pkey->type == EVP_PKEY_EC) | ||
| 1465 | { | ||
| 1466 | /* let's do ECDSA */ | ||
| 1467 | EVP_VerifyInit_ex(&md_ctx,EVP_ecdsa(), NULL); | ||
| 1468 | EVP_VerifyUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE); | ||
| 1469 | EVP_VerifyUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE); | ||
| 1470 | EVP_VerifyUpdate(&md_ctx,param,param_len); | ||
| 1471 | if (!EVP_VerifyFinal(&md_ctx,p,(int)n,pkey)) | ||
| 1472 | { | ||
| 1473 | /* bad signature */ | ||
| 1474 | al=SSL_AD_DECRYPT_ERROR; | ||
| 1475 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_SIGNATURE); | ||
| 1476 | goto f_err; | ||
| 1477 | } | ||
| 1478 | } | ||
| 1479 | else | ||
| 1480 | #endif | ||
| 1213 | { | 1481 | { |
| 1214 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_INTERNAL_ERROR); | 1482 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_INTERNAL_ERROR); |
| 1215 | goto err; | 1483 | goto err; |
| @@ -1245,20 +1513,27 @@ err: | |||
| 1245 | if (dh != NULL) | 1513 | if (dh != NULL) |
| 1246 | DH_free(dh); | 1514 | DH_free(dh); |
| 1247 | #endif | 1515 | #endif |
| 1516 | #ifndef OPENSSL_NO_ECDH | ||
| 1517 | BN_CTX_free(bn_ctx); | ||
| 1518 | EC_POINT_free(srvr_ecpoint); | ||
| 1519 | if (ecdh != NULL) | ||
| 1520 | EC_KEY_free(ecdh); | ||
| 1521 | #endif | ||
| 1248 | EVP_MD_CTX_cleanup(&md_ctx); | 1522 | EVP_MD_CTX_cleanup(&md_ctx); |
| 1249 | return(-1); | 1523 | return(-1); |
| 1250 | } | 1524 | } |
| 1251 | 1525 | ||
| 1252 | static int ssl3_get_certificate_request(SSL *s) | 1526 | int ssl3_get_certificate_request(SSL *s) |
| 1253 | { | 1527 | { |
| 1254 | int ok,ret=0; | 1528 | int ok,ret=0; |
| 1255 | unsigned long n,nc,l; | 1529 | unsigned long n,nc,l; |
| 1256 | unsigned int llen,ctype_num,i; | 1530 | unsigned int llen,ctype_num,i; |
| 1257 | X509_NAME *xn=NULL; | 1531 | X509_NAME *xn=NULL; |
| 1258 | unsigned char *p,*d,*q; | 1532 | const unsigned char *p,*q; |
| 1533 | unsigned char *d; | ||
| 1259 | STACK_OF(X509_NAME) *ca_sk=NULL; | 1534 | STACK_OF(X509_NAME) *ca_sk=NULL; |
| 1260 | 1535 | ||
| 1261 | n=ssl3_get_message(s, | 1536 | n=s->method->ssl_get_message(s, |
| 1262 | SSL3_ST_CR_CERT_REQ_A, | 1537 | SSL3_ST_CR_CERT_REQ_A, |
| 1263 | SSL3_ST_CR_CERT_REQ_B, | 1538 | SSL3_ST_CR_CERT_REQ_B, |
| 1264 | -1, | 1539 | -1, |
| @@ -1294,7 +1569,7 @@ static int ssl3_get_certificate_request(SSL *s) | |||
| 1294 | } | 1569 | } |
| 1295 | } | 1570 | } |
| 1296 | 1571 | ||
| 1297 | d=p=(unsigned char *)s->init_msg; | 1572 | p=d=(unsigned char *)s->init_msg; |
| 1298 | 1573 | ||
| 1299 | if ((ca_sk=sk_X509_NAME_new(ca_dn_cmp)) == NULL) | 1574 | if ((ca_sk=sk_X509_NAME_new(ca_dn_cmp)) == NULL) |
| 1300 | { | 1575 | { |
| @@ -1395,13 +1670,150 @@ static int ca_dn_cmp(const X509_NAME * const *a, const X509_NAME * const *b) | |||
| 1395 | { | 1670 | { |
| 1396 | return(X509_NAME_cmp(*a,*b)); | 1671 | return(X509_NAME_cmp(*a,*b)); |
| 1397 | } | 1672 | } |
| 1673 | #ifndef OPENSSL_NO_TLSEXT | ||
| 1674 | int ssl3_get_new_session_ticket(SSL *s) | ||
| 1675 | { | ||
| 1676 | int ok,al,ret=0, ticklen; | ||
| 1677 | long n; | ||
| 1678 | const unsigned char *p; | ||
| 1679 | unsigned char *d; | ||
| 1398 | 1680 | ||
| 1399 | static int ssl3_get_server_done(SSL *s) | 1681 | n=s->method->ssl_get_message(s, |
| 1682 | SSL3_ST_CR_SESSION_TICKET_A, | ||
| 1683 | SSL3_ST_CR_SESSION_TICKET_B, | ||
| 1684 | -1, | ||
| 1685 | 16384, | ||
| 1686 | &ok); | ||
| 1687 | |||
| 1688 | if (!ok) | ||
| 1689 | return((int)n); | ||
| 1690 | |||
| 1691 | if (s->s3->tmp.message_type == SSL3_MT_FINISHED) | ||
| 1692 | { | ||
| 1693 | s->s3->tmp.reuse_message=1; | ||
| 1694 | return(1); | ||
| 1695 | } | ||
| 1696 | if (s->s3->tmp.message_type != SSL3_MT_NEWSESSION_TICKET) | ||
| 1697 | { | ||
| 1698 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
| 1699 | SSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET,SSL_R_BAD_MESSAGE_TYPE); | ||
| 1700 | goto f_err; | ||
| 1701 | } | ||
| 1702 | if (n < 6) | ||
| 1703 | { | ||
| 1704 | /* need at least ticket_lifetime_hint + ticket length */ | ||
| 1705 | al = SSL3_AL_FATAL,SSL_AD_DECODE_ERROR; | ||
| 1706 | SSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET,SSL_R_LENGTH_MISMATCH); | ||
| 1707 | goto f_err; | ||
| 1708 | } | ||
| 1709 | p=d=(unsigned char *)s->init_msg; | ||
| 1710 | n2l(p, s->session->tlsext_tick_lifetime_hint); | ||
| 1711 | n2s(p, ticklen); | ||
| 1712 | /* ticket_lifetime_hint + ticket_length + ticket */ | ||
| 1713 | if (ticklen + 6 != n) | ||
| 1714 | { | ||
| 1715 | al = SSL3_AL_FATAL,SSL_AD_DECODE_ERROR; | ||
| 1716 | SSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET,SSL_R_LENGTH_MISMATCH); | ||
| 1717 | goto f_err; | ||
| 1718 | } | ||
| 1719 | if (s->session->tlsext_tick) | ||
| 1720 | { | ||
| 1721 | OPENSSL_free(s->session->tlsext_tick); | ||
| 1722 | s->session->tlsext_ticklen = 0; | ||
| 1723 | } | ||
| 1724 | s->session->tlsext_tick = OPENSSL_malloc(ticklen); | ||
| 1725 | if (!s->session->tlsext_tick) | ||
| 1726 | { | ||
| 1727 | SSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET,ERR_R_MALLOC_FAILURE); | ||
| 1728 | goto err; | ||
| 1729 | } | ||
| 1730 | memcpy(s->session->tlsext_tick, p, ticklen); | ||
| 1731 | s->session->tlsext_ticklen = ticklen; | ||
| 1732 | |||
| 1733 | ret=1; | ||
| 1734 | return(ret); | ||
| 1735 | f_err: | ||
| 1736 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
| 1737 | err: | ||
| 1738 | return(-1); | ||
| 1739 | } | ||
| 1740 | |||
| 1741 | int ssl3_get_cert_status(SSL *s) | ||
| 1742 | { | ||
| 1743 | int ok, al; | ||
| 1744 | unsigned long resplen; | ||
| 1745 | long n; | ||
| 1746 | const unsigned char *p; | ||
| 1747 | |||
| 1748 | n=s->method->ssl_get_message(s, | ||
| 1749 | SSL3_ST_CR_CERT_STATUS_A, | ||
| 1750 | SSL3_ST_CR_CERT_STATUS_B, | ||
| 1751 | SSL3_MT_CERTIFICATE_STATUS, | ||
| 1752 | 16384, | ||
| 1753 | &ok); | ||
| 1754 | |||
| 1755 | if (!ok) return((int)n); | ||
| 1756 | if (n < 4) | ||
| 1757 | { | ||
| 1758 | /* need at least status type + length */ | ||
| 1759 | al = SSL_AD_DECODE_ERROR; | ||
| 1760 | SSLerr(SSL_F_SSL3_GET_CERT_STATUS,SSL_R_LENGTH_MISMATCH); | ||
| 1761 | goto f_err; | ||
| 1762 | } | ||
| 1763 | p = (unsigned char *)s->init_msg; | ||
| 1764 | if (*p++ != TLSEXT_STATUSTYPE_ocsp) | ||
| 1765 | { | ||
| 1766 | al = SSL_AD_DECODE_ERROR; | ||
| 1767 | SSLerr(SSL_F_SSL3_GET_CERT_STATUS,SSL_R_UNSUPPORTED_STATUS_TYPE); | ||
| 1768 | goto f_err; | ||
| 1769 | } | ||
| 1770 | n2l3(p, resplen); | ||
| 1771 | if (resplen + 4 != n) | ||
| 1772 | { | ||
| 1773 | al = SSL_AD_DECODE_ERROR; | ||
| 1774 | SSLerr(SSL_F_SSL3_GET_CERT_STATUS,SSL_R_LENGTH_MISMATCH); | ||
| 1775 | goto f_err; | ||
| 1776 | } | ||
| 1777 | if (s->tlsext_ocsp_resp) | ||
| 1778 | OPENSSL_free(s->tlsext_ocsp_resp); | ||
| 1779 | s->tlsext_ocsp_resp = BUF_memdup(p, resplen); | ||
| 1780 | if (!s->tlsext_ocsp_resp) | ||
| 1781 | { | ||
| 1782 | al = SSL_AD_INTERNAL_ERROR; | ||
| 1783 | SSLerr(SSL_F_SSL3_GET_CERT_STATUS,ERR_R_MALLOC_FAILURE); | ||
| 1784 | goto f_err; | ||
| 1785 | } | ||
| 1786 | s->tlsext_ocsp_resplen = resplen; | ||
| 1787 | if (s->ctx->tlsext_status_cb) | ||
| 1788 | { | ||
| 1789 | int ret; | ||
| 1790 | ret = s->ctx->tlsext_status_cb(s, s->ctx->tlsext_status_arg); | ||
| 1791 | if (ret == 0) | ||
| 1792 | { | ||
| 1793 | al = SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE; | ||
| 1794 | SSLerr(SSL_F_SSL3_GET_CERT_STATUS,SSL_R_INVALID_STATUS_RESPONSE); | ||
| 1795 | goto f_err; | ||
| 1796 | } | ||
| 1797 | if (ret < 0) | ||
| 1798 | { | ||
| 1799 | al = SSL_AD_INTERNAL_ERROR; | ||
| 1800 | SSLerr(SSL_F_SSL3_GET_CERT_STATUS,ERR_R_MALLOC_FAILURE); | ||
| 1801 | goto f_err; | ||
| 1802 | } | ||
| 1803 | } | ||
| 1804 | return 1; | ||
| 1805 | f_err: | ||
| 1806 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
| 1807 | return(-1); | ||
| 1808 | } | ||
| 1809 | #endif | ||
| 1810 | |||
| 1811 | int ssl3_get_server_done(SSL *s) | ||
| 1400 | { | 1812 | { |
| 1401 | int ok,ret=0; | 1813 | int ok,ret=0; |
| 1402 | long n; | 1814 | long n; |
| 1403 | 1815 | ||
| 1404 | n=ssl3_get_message(s, | 1816 | n=s->method->ssl_get_message(s, |
| 1405 | SSL3_ST_CR_SRVR_DONE_A, | 1817 | SSL3_ST_CR_SRVR_DONE_A, |
| 1406 | SSL3_ST_CR_SRVR_DONE_B, | 1818 | SSL3_ST_CR_SRVR_DONE_B, |
| 1407 | SSL3_MT_SERVER_DONE, | 1819 | SSL3_MT_SERVER_DONE, |
| @@ -1420,7 +1832,8 @@ static int ssl3_get_server_done(SSL *s) | |||
| 1420 | return(ret); | 1832 | return(ret); |
| 1421 | } | 1833 | } |
| 1422 | 1834 | ||
| 1423 | static int ssl3_send_client_key_exchange(SSL *s) | 1835 | |
| 1836 | int ssl3_send_client_key_exchange(SSL *s) | ||
| 1424 | { | 1837 | { |
| 1425 | unsigned char *p,*d; | 1838 | unsigned char *p,*d; |
| 1426 | int n; | 1839 | int n; |
| @@ -1430,8 +1843,16 @@ static int ssl3_send_client_key_exchange(SSL *s) | |||
| 1430 | EVP_PKEY *pkey=NULL; | 1843 | EVP_PKEY *pkey=NULL; |
| 1431 | #endif | 1844 | #endif |
| 1432 | #ifndef OPENSSL_NO_KRB5 | 1845 | #ifndef OPENSSL_NO_KRB5 |
| 1433 | KSSL_ERR kssl_err; | 1846 | KSSL_ERR kssl_err; |
| 1434 | #endif /* OPENSSL_NO_KRB5 */ | 1847 | #endif /* OPENSSL_NO_KRB5 */ |
| 1848 | #ifndef OPENSSL_NO_ECDH | ||
| 1849 | EC_KEY *clnt_ecdh = NULL; | ||
| 1850 | const EC_POINT *srvr_ecpoint = NULL; | ||
| 1851 | EVP_PKEY *srvr_pub_pkey = NULL; | ||
| 1852 | unsigned char *encodedPoint = NULL; | ||
| 1853 | int encoded_pt_len = 0; | ||
| 1854 | BN_CTX * bn_ctx = NULL; | ||
| 1855 | #endif | ||
| 1435 | 1856 | ||
| 1436 | if (s->state == SSL3_ST_CW_KEY_EXCH_A) | 1857 | if (s->state == SSL3_ST_CW_KEY_EXCH_A) |
| 1437 | { | 1858 | { |
| @@ -1440,8 +1861,8 @@ static int ssl3_send_client_key_exchange(SSL *s) | |||
| 1440 | 1861 | ||
| 1441 | l=s->s3->tmp.new_cipher->algorithms; | 1862 | l=s->s3->tmp.new_cipher->algorithms; |
| 1442 | 1863 | ||
| 1443 | /* Fool emacs indentation */ | 1864 | /* Fool emacs indentation */ |
| 1444 | if (0) {} | 1865 | if (0) {} |
| 1445 | #ifndef OPENSSL_NO_RSA | 1866 | #ifndef OPENSSL_NO_RSA |
| 1446 | else if (l & SSL_kRSA) | 1867 | else if (l & SSL_kRSA) |
| 1447 | { | 1868 | { |
| @@ -1503,12 +1924,12 @@ static int ssl3_send_client_key_exchange(SSL *s) | |||
| 1503 | #endif | 1924 | #endif |
| 1504 | #ifndef OPENSSL_NO_KRB5 | 1925 | #ifndef OPENSSL_NO_KRB5 |
| 1505 | else if (l & SSL_kKRB5) | 1926 | else if (l & SSL_kKRB5) |
| 1506 | { | 1927 | { |
| 1507 | krb5_error_code krb5rc; | 1928 | krb5_error_code krb5rc; |
| 1508 | KSSL_CTX *kssl_ctx = s->kssl_ctx; | 1929 | KSSL_CTX *kssl_ctx = s->kssl_ctx; |
| 1509 | /* krb5_data krb5_ap_req; */ | 1930 | /* krb5_data krb5_ap_req; */ |
| 1510 | krb5_data *enc_ticket; | 1931 | krb5_data *enc_ticket; |
| 1511 | krb5_data authenticator, *authp = NULL; | 1932 | krb5_data authenticator, *authp = NULL; |
| 1512 | EVP_CIPHER_CTX ciph_ctx; | 1933 | EVP_CIPHER_CTX ciph_ctx; |
| 1513 | EVP_CIPHER *enc = NULL; | 1934 | EVP_CIPHER *enc = NULL; |
| 1514 | unsigned char iv[EVP_MAX_IV_LENGTH]; | 1935 | unsigned char iv[EVP_MAX_IV_LENGTH]; |
| @@ -1520,8 +1941,8 @@ static int ssl3_send_client_key_exchange(SSL *s) | |||
| 1520 | EVP_CIPHER_CTX_init(&ciph_ctx); | 1941 | EVP_CIPHER_CTX_init(&ciph_ctx); |
| 1521 | 1942 | ||
| 1522 | #ifdef KSSL_DEBUG | 1943 | #ifdef KSSL_DEBUG |
| 1523 | printf("ssl3_send_client_key_exchange(%lx & %lx)\n", | 1944 | printf("ssl3_send_client_key_exchange(%lx & %lx)\n", |
| 1524 | l, SSL_kKRB5); | 1945 | l, SSL_kKRB5); |
| 1525 | #endif /* KSSL_DEBUG */ | 1946 | #endif /* KSSL_DEBUG */ |
| 1526 | 1947 | ||
| 1527 | authp = NULL; | 1948 | authp = NULL; |
| @@ -1529,37 +1950,37 @@ static int ssl3_send_client_key_exchange(SSL *s) | |||
| 1529 | if (KRB5SENDAUTH) authp = &authenticator; | 1950 | if (KRB5SENDAUTH) authp = &authenticator; |
| 1530 | #endif /* KRB5SENDAUTH */ | 1951 | #endif /* KRB5SENDAUTH */ |
| 1531 | 1952 | ||
| 1532 | krb5rc = kssl_cget_tkt(kssl_ctx, &enc_ticket, authp, | 1953 | krb5rc = kssl_cget_tkt(kssl_ctx, &enc_ticket, authp, |
| 1533 | &kssl_err); | 1954 | &kssl_err); |
| 1534 | enc = kssl_map_enc(kssl_ctx->enctype); | 1955 | enc = kssl_map_enc(kssl_ctx->enctype); |
| 1535 | if (enc == NULL) | 1956 | if (enc == NULL) |
| 1536 | goto err; | 1957 | goto err; |
| 1537 | #ifdef KSSL_DEBUG | 1958 | #ifdef KSSL_DEBUG |
| 1538 | { | 1959 | { |
| 1539 | printf("kssl_cget_tkt rtn %d\n", krb5rc); | 1960 | printf("kssl_cget_tkt rtn %d\n", krb5rc); |
| 1540 | if (krb5rc && kssl_err.text) | 1961 | if (krb5rc && kssl_err.text) |
| 1541 | printf("kssl_cget_tkt kssl_err=%s\n", kssl_err.text); | 1962 | printf("kssl_cget_tkt kssl_err=%s\n", kssl_err.text); |
| 1542 | } | 1963 | } |
| 1543 | #endif /* KSSL_DEBUG */ | 1964 | #endif /* KSSL_DEBUG */ |
| 1544 | 1965 | ||
| 1545 | if (krb5rc) | 1966 | if (krb5rc) |
| 1546 | { | 1967 | { |
| 1547 | ssl3_send_alert(s,SSL3_AL_FATAL, | 1968 | ssl3_send_alert(s,SSL3_AL_FATAL, |
| 1548 | SSL_AD_HANDSHAKE_FAILURE); | 1969 | SSL_AD_HANDSHAKE_FAILURE); |
| 1549 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE, | 1970 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE, |
| 1550 | kssl_err.reason); | 1971 | kssl_err.reason); |
| 1551 | goto err; | 1972 | goto err; |
| 1552 | } | 1973 | } |
| 1553 | 1974 | ||
| 1554 | /* 20010406 VRS - Earlier versions used KRB5 AP_REQ | 1975 | /* 20010406 VRS - Earlier versions used KRB5 AP_REQ |
| 1555 | ** in place of RFC 2712 KerberosWrapper, as in: | 1976 | ** in place of RFC 2712 KerberosWrapper, as in: |
| 1556 | ** | 1977 | ** |
| 1557 | ** Send ticket (copy to *p, set n = length) | 1978 | ** Send ticket (copy to *p, set n = length) |
| 1558 | ** n = krb5_ap_req.length; | 1979 | ** n = krb5_ap_req.length; |
| 1559 | ** memcpy(p, krb5_ap_req.data, krb5_ap_req.length); | 1980 | ** memcpy(p, krb5_ap_req.data, krb5_ap_req.length); |
| 1560 | ** if (krb5_ap_req.data) | 1981 | ** if (krb5_ap_req.data) |
| 1561 | ** kssl_krb5_free_data_contents(NULL,&krb5_ap_req); | 1982 | ** kssl_krb5_free_data_contents(NULL,&krb5_ap_req); |
| 1562 | ** | 1983 | ** |
| 1563 | ** Now using real RFC 2712 KerberosWrapper | 1984 | ** Now using real RFC 2712 KerberosWrapper |
| 1564 | ** (Thanks to Simon Wilkinson <sxw@sxw.org.uk>) | 1985 | ** (Thanks to Simon Wilkinson <sxw@sxw.org.uk>) |
| 1565 | ** Note: 2712 "opaque" types are here replaced | 1986 | ** Note: 2712 "opaque" types are here replaced |
| @@ -1594,8 +2015,10 @@ static int ssl3_send_client_key_exchange(SSL *s) | |||
| 1594 | n+=2; | 2015 | n+=2; |
| 1595 | } | 2016 | } |
| 1596 | 2017 | ||
| 1597 | if (RAND_bytes(tmp_buf,sizeof tmp_buf) <= 0) | 2018 | tmp_buf[0]=s->client_version>>8; |
| 1598 | goto err; | 2019 | tmp_buf[1]=s->client_version&0xff; |
| 2020 | if (RAND_bytes(&(tmp_buf[2]),sizeof tmp_buf-2) <= 0) | ||
| 2021 | goto err; | ||
| 1599 | 2022 | ||
| 1600 | /* 20010420 VRS. Tried it this way; failed. | 2023 | /* 20010420 VRS. Tried it this way; failed. |
| 1601 | ** EVP_EncryptInit_ex(&ciph_ctx,enc, NULL,NULL); | 2024 | ** EVP_EncryptInit_ex(&ciph_ctx,enc, NULL,NULL); |
| @@ -1624,20 +2047,27 @@ static int ssl3_send_client_key_exchange(SSL *s) | |||
| 1624 | p+=outl; | 2047 | p+=outl; |
| 1625 | n+=outl + 2; | 2048 | n+=outl + 2; |
| 1626 | 2049 | ||
| 1627 | s->session->master_key_length= | 2050 | s->session->master_key_length= |
| 1628 | s->method->ssl3_enc->generate_master_secret(s, | 2051 | s->method->ssl3_enc->generate_master_secret(s, |
| 1629 | s->session->master_key, | 2052 | s->session->master_key, |
| 1630 | tmp_buf, sizeof tmp_buf); | 2053 | tmp_buf, sizeof tmp_buf); |
| 1631 | 2054 | ||
| 1632 | OPENSSL_cleanse(tmp_buf, sizeof tmp_buf); | 2055 | OPENSSL_cleanse(tmp_buf, sizeof tmp_buf); |
| 1633 | OPENSSL_cleanse(epms, outl); | 2056 | OPENSSL_cleanse(epms, outl); |
| 1634 | } | 2057 | } |
| 1635 | #endif | 2058 | #endif |
| 1636 | #ifndef OPENSSL_NO_DH | 2059 | #ifndef OPENSSL_NO_DH |
| 1637 | else if (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd)) | 2060 | else if (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd)) |
| 1638 | { | 2061 | { |
| 1639 | DH *dh_srvr,*dh_clnt; | 2062 | DH *dh_srvr,*dh_clnt; |
| 1640 | 2063 | ||
| 2064 | if (s->session->sess_cert == NULL) | ||
| 2065 | { | ||
| 2066 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE); | ||
| 2067 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_UNEXPECTED_MESSAGE); | ||
| 2068 | goto err; | ||
| 2069 | } | ||
| 2070 | |||
| 1641 | if (s->session->sess_cert->peer_dh_tmp != NULL) | 2071 | if (s->session->sess_cert->peer_dh_tmp != NULL) |
| 1642 | dh_srvr=s->session->sess_cert->peer_dh_tmp; | 2072 | dh_srvr=s->session->sess_cert->peer_dh_tmp; |
| 1643 | else | 2073 | else |
| @@ -1689,10 +2119,198 @@ static int ssl3_send_client_key_exchange(SSL *s) | |||
| 1689 | /* perhaps clean things up a bit EAY EAY EAY EAY*/ | 2119 | /* perhaps clean things up a bit EAY EAY EAY EAY*/ |
| 1690 | } | 2120 | } |
| 1691 | #endif | 2121 | #endif |
| 2122 | |||
| 2123 | #ifndef OPENSSL_NO_ECDH | ||
| 2124 | else if ((l & SSL_kECDH) || (l & SSL_kECDHE)) | ||
| 2125 | { | ||
| 2126 | const EC_GROUP *srvr_group = NULL; | ||
| 2127 | EC_KEY *tkey; | ||
| 2128 | int ecdh_clnt_cert = 0; | ||
| 2129 | int field_size = 0; | ||
| 2130 | |||
| 2131 | /* Did we send out the client's | ||
| 2132 | * ECDH share for use in premaster | ||
| 2133 | * computation as part of client certificate? | ||
| 2134 | * If so, set ecdh_clnt_cert to 1. | ||
| 2135 | */ | ||
| 2136 | if ((l & SSL_kECDH) && (s->cert != NULL)) | ||
| 2137 | { | ||
| 2138 | /* XXX: For now, we do not support client | ||
| 2139 | * authentication using ECDH certificates. | ||
| 2140 | * To add such support, one needs to add | ||
| 2141 | * code that checks for appropriate | ||
| 2142 | * conditions and sets ecdh_clnt_cert to 1. | ||
| 2143 | * For example, the cert have an ECC | ||
| 2144 | * key on the same curve as the server's | ||
| 2145 | * and the key should be authorized for | ||
| 2146 | * key agreement. | ||
| 2147 | * | ||
| 2148 | * One also needs to add code in ssl3_connect | ||
| 2149 | * to skip sending the certificate verify | ||
| 2150 | * message. | ||
| 2151 | * | ||
| 2152 | * if ((s->cert->key->privatekey != NULL) && | ||
| 2153 | * (s->cert->key->privatekey->type == | ||
| 2154 | * EVP_PKEY_EC) && ...) | ||
| 2155 | * ecdh_clnt_cert = 1; | ||
| 2156 | */ | ||
| 2157 | } | ||
| 2158 | |||
| 2159 | if (s->session->sess_cert->peer_ecdh_tmp != NULL) | ||
| 2160 | { | ||
| 2161 | tkey = s->session->sess_cert->peer_ecdh_tmp; | ||
| 2162 | } | ||
| 2163 | else | ||
| 2164 | { | ||
| 2165 | /* Get the Server Public Key from Cert */ | ||
| 2166 | srvr_pub_pkey = X509_get_pubkey(s->session-> \ | ||
| 2167 | sess_cert->peer_pkeys[SSL_PKEY_ECC].x509); | ||
| 2168 | if ((srvr_pub_pkey == NULL) || | ||
| 2169 | (srvr_pub_pkey->type != EVP_PKEY_EC) || | ||
| 2170 | (srvr_pub_pkey->pkey.ec == NULL)) | ||
| 2171 | { | ||
| 2172 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE, | ||
| 2173 | ERR_R_INTERNAL_ERROR); | ||
| 2174 | goto err; | ||
| 2175 | } | ||
| 2176 | |||
| 2177 | tkey = srvr_pub_pkey->pkey.ec; | ||
| 2178 | } | ||
| 2179 | |||
| 2180 | srvr_group = EC_KEY_get0_group(tkey); | ||
| 2181 | srvr_ecpoint = EC_KEY_get0_public_key(tkey); | ||
| 2182 | |||
| 2183 | if ((srvr_group == NULL) || (srvr_ecpoint == NULL)) | ||
| 2184 | { | ||
| 2185 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE, | ||
| 2186 | ERR_R_INTERNAL_ERROR); | ||
| 2187 | goto err; | ||
| 2188 | } | ||
| 2189 | |||
| 2190 | if ((clnt_ecdh=EC_KEY_new()) == NULL) | ||
| 2191 | { | ||
| 2192 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE); | ||
| 2193 | goto err; | ||
| 2194 | } | ||
| 2195 | |||
| 2196 | if (!EC_KEY_set_group(clnt_ecdh, srvr_group)) | ||
| 2197 | { | ||
| 2198 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_EC_LIB); | ||
| 2199 | goto err; | ||
| 2200 | } | ||
| 2201 | if (ecdh_clnt_cert) | ||
| 2202 | { | ||
| 2203 | /* Reuse key info from our certificate | ||
| 2204 | * We only need our private key to perform | ||
| 2205 | * the ECDH computation. | ||
| 2206 | */ | ||
| 2207 | const BIGNUM *priv_key; | ||
| 2208 | tkey = s->cert->key->privatekey->pkey.ec; | ||
| 2209 | priv_key = EC_KEY_get0_private_key(tkey); | ||
| 2210 | if (priv_key == NULL) | ||
| 2211 | { | ||
| 2212 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE); | ||
| 2213 | goto err; | ||
| 2214 | } | ||
| 2215 | if (!EC_KEY_set_private_key(clnt_ecdh, priv_key)) | ||
| 2216 | { | ||
| 2217 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_EC_LIB); | ||
| 2218 | goto err; | ||
| 2219 | } | ||
| 2220 | } | ||
| 2221 | else | ||
| 2222 | { | ||
| 2223 | /* Generate a new ECDH key pair */ | ||
| 2224 | if (!(EC_KEY_generate_key(clnt_ecdh))) | ||
| 2225 | { | ||
| 2226 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE, ERR_R_ECDH_LIB); | ||
| 2227 | goto err; | ||
| 2228 | } | ||
| 2229 | } | ||
| 2230 | |||
| 2231 | /* use the 'p' output buffer for the ECDH key, but | ||
| 2232 | * make sure to clear it out afterwards | ||
| 2233 | */ | ||
| 2234 | |||
| 2235 | field_size = EC_GROUP_get_degree(srvr_group); | ||
| 2236 | if (field_size <= 0) | ||
| 2237 | { | ||
| 2238 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE, | ||
| 2239 | ERR_R_ECDH_LIB); | ||
| 2240 | goto err; | ||
| 2241 | } | ||
| 2242 | n=ECDH_compute_key(p, (field_size+7)/8, srvr_ecpoint, clnt_ecdh, NULL); | ||
| 2243 | if (n <= 0) | ||
| 2244 | { | ||
| 2245 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE, | ||
| 2246 | ERR_R_ECDH_LIB); | ||
| 2247 | goto err; | ||
| 2248 | } | ||
| 2249 | |||
| 2250 | /* generate master key from the result */ | ||
| 2251 | s->session->master_key_length = s->method->ssl3_enc \ | ||
| 2252 | -> generate_master_secret(s, | ||
| 2253 | s->session->master_key, | ||
| 2254 | p, n); | ||
| 2255 | |||
| 2256 | memset(p, 0, n); /* clean up */ | ||
| 2257 | |||
| 2258 | if (ecdh_clnt_cert) | ||
| 2259 | { | ||
| 2260 | /* Send empty client key exch message */ | ||
| 2261 | n = 0; | ||
| 2262 | } | ||
| 2263 | else | ||
| 2264 | { | ||
| 2265 | /* First check the size of encoding and | ||
| 2266 | * allocate memory accordingly. | ||
| 2267 | */ | ||
| 2268 | encoded_pt_len = | ||
| 2269 | EC_POINT_point2oct(srvr_group, | ||
| 2270 | EC_KEY_get0_public_key(clnt_ecdh), | ||
| 2271 | POINT_CONVERSION_UNCOMPRESSED, | ||
| 2272 | NULL, 0, NULL); | ||
| 2273 | |||
| 2274 | encodedPoint = (unsigned char *) | ||
| 2275 | OPENSSL_malloc(encoded_pt_len * | ||
| 2276 | sizeof(unsigned char)); | ||
| 2277 | bn_ctx = BN_CTX_new(); | ||
| 2278 | if ((encodedPoint == NULL) || | ||
| 2279 | (bn_ctx == NULL)) | ||
| 2280 | { | ||
| 2281 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE); | ||
| 2282 | goto err; | ||
| 2283 | } | ||
| 2284 | |||
| 2285 | /* Encode the public key */ | ||
| 2286 | n = EC_POINT_point2oct(srvr_group, | ||
| 2287 | EC_KEY_get0_public_key(clnt_ecdh), | ||
| 2288 | POINT_CONVERSION_UNCOMPRESSED, | ||
| 2289 | encodedPoint, encoded_pt_len, bn_ctx); | ||
| 2290 | |||
| 2291 | *p = n; /* length of encoded point */ | ||
| 2292 | /* Encoded point will be copied here */ | ||
| 2293 | p += 1; | ||
| 2294 | /* copy the point */ | ||
| 2295 | memcpy((unsigned char *)p, encodedPoint, n); | ||
| 2296 | /* increment n to account for length field */ | ||
| 2297 | n += 1; | ||
| 2298 | } | ||
| 2299 | |||
| 2300 | /* Free allocated memory */ | ||
| 2301 | BN_CTX_free(bn_ctx); | ||
| 2302 | if (encodedPoint != NULL) OPENSSL_free(encodedPoint); | ||
| 2303 | if (clnt_ecdh != NULL) | ||
| 2304 | EC_KEY_free(clnt_ecdh); | ||
| 2305 | EVP_PKEY_free(srvr_pub_pkey); | ||
| 2306 | } | ||
| 2307 | #endif /* !OPENSSL_NO_ECDH */ | ||
| 1692 | else | 2308 | else |
| 1693 | { | 2309 | { |
| 1694 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE); | 2310 | ssl3_send_alert(s, SSL3_AL_FATAL, |
| 1695 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_INTERNAL_ERROR); | 2311 | SSL_AD_HANDSHAKE_FAILURE); |
| 2312 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE, | ||
| 2313 | ERR_R_INTERNAL_ERROR); | ||
| 1696 | goto err; | 2314 | goto err; |
| 1697 | } | 2315 | } |
| 1698 | 2316 | ||
| @@ -1708,10 +2326,17 @@ static int ssl3_send_client_key_exchange(SSL *s) | |||
| 1708 | /* SSL3_ST_CW_KEY_EXCH_B */ | 2326 | /* SSL3_ST_CW_KEY_EXCH_B */ |
| 1709 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | 2327 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); |
| 1710 | err: | 2328 | err: |
| 2329 | #ifndef OPENSSL_NO_ECDH | ||
| 2330 | BN_CTX_free(bn_ctx); | ||
| 2331 | if (encodedPoint != NULL) OPENSSL_free(encodedPoint); | ||
| 2332 | if (clnt_ecdh != NULL) | ||
| 2333 | EC_KEY_free(clnt_ecdh); | ||
| 2334 | EVP_PKEY_free(srvr_pub_pkey); | ||
| 2335 | #endif | ||
| 1711 | return(-1); | 2336 | return(-1); |
| 1712 | } | 2337 | } |
| 1713 | 2338 | ||
| 1714 | static int ssl3_send_client_verify(SSL *s) | 2339 | int ssl3_send_client_verify(SSL *s) |
| 1715 | { | 2340 | { |
| 1716 | unsigned char *p,*d; | 2341 | unsigned char *p,*d; |
| 1717 | unsigned char data[MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH]; | 2342 | unsigned char data[MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH]; |
| @@ -1720,7 +2345,7 @@ static int ssl3_send_client_verify(SSL *s) | |||
| 1720 | unsigned u=0; | 2345 | unsigned u=0; |
| 1721 | #endif | 2346 | #endif |
| 1722 | unsigned long n; | 2347 | unsigned long n; |
| 1723 | #ifndef OPENSSL_NO_DSA | 2348 | #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_ECDSA) |
| 1724 | int j; | 2349 | int j; |
| 1725 | #endif | 2350 | #endif |
| 1726 | 2351 | ||
| @@ -1766,6 +2391,23 @@ static int ssl3_send_client_verify(SSL *s) | |||
| 1766 | } | 2391 | } |
| 1767 | else | 2392 | else |
| 1768 | #endif | 2393 | #endif |
| 2394 | #ifndef OPENSSL_NO_ECDSA | ||
| 2395 | if (pkey->type == EVP_PKEY_EC) | ||
| 2396 | { | ||
| 2397 | if (!ECDSA_sign(pkey->save_type, | ||
| 2398 | &(data[MD5_DIGEST_LENGTH]), | ||
| 2399 | SHA_DIGEST_LENGTH,&(p[2]), | ||
| 2400 | (unsigned int *)&j,pkey->pkey.ec)) | ||
| 2401 | { | ||
| 2402 | SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY, | ||
| 2403 | ERR_R_ECDSA_LIB); | ||
| 2404 | goto err; | ||
| 2405 | } | ||
| 2406 | s2n(j,p); | ||
| 2407 | n=j+2; | ||
| 2408 | } | ||
| 2409 | else | ||
| 2410 | #endif | ||
| 1769 | { | 2411 | { |
| 1770 | SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,ERR_R_INTERNAL_ERROR); | 2412 | SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,ERR_R_INTERNAL_ERROR); |
| 1771 | goto err; | 2413 | goto err; |
| @@ -1782,7 +2424,7 @@ err: | |||
| 1782 | return(-1); | 2424 | return(-1); |
| 1783 | } | 2425 | } |
| 1784 | 2426 | ||
| 1785 | static int ssl3_send_client_certificate(SSL *s) | 2427 | int ssl3_send_client_certificate(SSL *s) |
| 1786 | { | 2428 | { |
| 1787 | X509 *x509=NULL; | 2429 | X509 *x509=NULL; |
| 1788 | EVP_PKEY *pkey=NULL; | 2430 | EVP_PKEY *pkey=NULL; |
| @@ -1861,7 +2503,7 @@ static int ssl3_send_client_certificate(SSL *s) | |||
| 1861 | 2503 | ||
| 1862 | #define has_bits(i,m) (((i)&(m)) == (m)) | 2504 | #define has_bits(i,m) (((i)&(m)) == (m)) |
| 1863 | 2505 | ||
| 1864 | static int ssl3_check_cert_and_algorithm(SSL *s) | 2506 | int ssl3_check_cert_and_algorithm(SSL *s) |
| 1865 | { | 2507 | { |
| 1866 | int i,idx; | 2508 | int i,idx; |
| 1867 | long algs; | 2509 | long algs; |
| @@ -1876,18 +2518,18 @@ static int ssl3_check_cert_and_algorithm(SSL *s) | |||
| 1876 | 2518 | ||
| 1877 | sc=s->session->sess_cert; | 2519 | sc=s->session->sess_cert; |
| 1878 | 2520 | ||
| 1879 | if (sc == NULL) | ||
| 1880 | { | ||
| 1881 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,ERR_R_INTERNAL_ERROR); | ||
| 1882 | goto err; | ||
| 1883 | } | ||
| 1884 | |||
| 1885 | algs=s->s3->tmp.new_cipher->algorithms; | 2521 | algs=s->s3->tmp.new_cipher->algorithms; |
| 1886 | 2522 | ||
| 1887 | /* we don't have a certificate */ | 2523 | /* we don't have a certificate */ |
| 1888 | if (algs & (SSL_aDH|SSL_aNULL|SSL_aKRB5)) | 2524 | if (algs & (SSL_aDH|SSL_aNULL|SSL_aKRB5)) |
| 1889 | return(1); | 2525 | return(1); |
| 1890 | 2526 | ||
| 2527 | if (sc == NULL) | ||
| 2528 | { | ||
| 2529 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,ERR_R_INTERNAL_ERROR); | ||
| 2530 | goto err; | ||
| 2531 | } | ||
| 2532 | |||
| 1891 | #ifndef OPENSSL_NO_RSA | 2533 | #ifndef OPENSSL_NO_RSA |
| 1892 | rsa=s->session->sess_cert->peer_rsa_tmp; | 2534 | rsa=s->session->sess_cert->peer_rsa_tmp; |
| 1893 | #endif | 2535 | #endif |
| @@ -1898,6 +2540,21 @@ static int ssl3_check_cert_and_algorithm(SSL *s) | |||
| 1898 | /* This is the passed certificate */ | 2540 | /* This is the passed certificate */ |
| 1899 | 2541 | ||
| 1900 | idx=sc->peer_cert_type; | 2542 | idx=sc->peer_cert_type; |
| 2543 | #ifndef OPENSSL_NO_ECDH | ||
| 2544 | if (idx == SSL_PKEY_ECC) | ||
| 2545 | { | ||
| 2546 | if (check_srvr_ecc_cert_and_alg(sc->peer_pkeys[idx].x509, | ||
| 2547 | s->s3->tmp.new_cipher) == 0) | ||
| 2548 | { /* check failed */ | ||
| 2549 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_BAD_ECC_CERT); | ||
| 2550 | goto f_err; | ||
| 2551 | } | ||
| 2552 | else | ||
| 2553 | { | ||
| 2554 | return 1; | ||
| 2555 | } | ||
| 2556 | } | ||
| 2557 | #endif | ||
| 1901 | pkey=X509_get_pubkey(sc->peer_pkeys[idx].x509); | 2558 | pkey=X509_get_pubkey(sc->peer_pkeys[idx].x509); |
| 1902 | i=X509_certificate_type(sc->peer_pkeys[idx].x509,pkey); | 2559 | i=X509_certificate_type(sc->peer_pkeys[idx].x509,pkey); |
| 1903 | EVP_PKEY_free(pkey); | 2560 | EVP_PKEY_free(pkey); |
| @@ -1983,3 +2640,79 @@ err: | |||
| 1983 | return(0); | 2640 | return(0); |
| 1984 | } | 2641 | } |
| 1985 | 2642 | ||
| 2643 | |||
| 2644 | #ifndef OPENSSL_NO_ECDH | ||
| 2645 | /* This is the complement of nid2curve_id in s3_srvr.c. */ | ||
| 2646 | static int curve_id2nid(int curve_id) | ||
| 2647 | { | ||
| 2648 | /* ECC curves from draft-ietf-tls-ecc-01.txt (Mar 15, 2001) | ||
| 2649 | * (no changes in draft-ietf-tls-ecc-03.txt [June 2003]) */ | ||
| 2650 | static int nid_list[26] = | ||
| 2651 | { | ||
| 2652 | 0, | ||
| 2653 | NID_sect163k1, /* sect163k1 (1) */ | ||
| 2654 | NID_sect163r1, /* sect163r1 (2) */ | ||
| 2655 | NID_sect163r2, /* sect163r2 (3) */ | ||
| 2656 | NID_sect193r1, /* sect193r1 (4) */ | ||
| 2657 | NID_sect193r2, /* sect193r2 (5) */ | ||
| 2658 | NID_sect233k1, /* sect233k1 (6) */ | ||
| 2659 | NID_sect233r1, /* sect233r1 (7) */ | ||
| 2660 | NID_sect239k1, /* sect239k1 (8) */ | ||
| 2661 | NID_sect283k1, /* sect283k1 (9) */ | ||
| 2662 | NID_sect283r1, /* sect283r1 (10) */ | ||
| 2663 | NID_sect409k1, /* sect409k1 (11) */ | ||
| 2664 | NID_sect409r1, /* sect409r1 (12) */ | ||
| 2665 | NID_sect571k1, /* sect571k1 (13) */ | ||
| 2666 | NID_sect571r1, /* sect571r1 (14) */ | ||
| 2667 | NID_secp160k1, /* secp160k1 (15) */ | ||
| 2668 | NID_secp160r1, /* secp160r1 (16) */ | ||
| 2669 | NID_secp160r2, /* secp160r2 (17) */ | ||
| 2670 | NID_secp192k1, /* secp192k1 (18) */ | ||
| 2671 | NID_X9_62_prime192v1, /* secp192r1 (19) */ | ||
| 2672 | NID_secp224k1, /* secp224k1 (20) */ | ||
| 2673 | NID_secp224r1, /* secp224r1 (21) */ | ||
| 2674 | NID_secp256k1, /* secp256k1 (22) */ | ||
| 2675 | NID_X9_62_prime256v1, /* secp256r1 (23) */ | ||
| 2676 | NID_secp384r1, /* secp384r1 (24) */ | ||
| 2677 | NID_secp521r1 /* secp521r1 (25) */ | ||
| 2678 | }; | ||
| 2679 | |||
| 2680 | if ((curve_id < 1) || (curve_id > 25)) return 0; | ||
| 2681 | |||
| 2682 | return nid_list[curve_id]; | ||
| 2683 | } | ||
| 2684 | #endif | ||
| 2685 | |||
| 2686 | /* Check to see if handshake is full or resumed. Usually this is just a | ||
| 2687 | * case of checking to see if a cache hit has occurred. In the case of | ||
| 2688 | * session tickets we have to check the next message to be sure. | ||
| 2689 | */ | ||
| 2690 | |||
| 2691 | #ifndef OPENSSL_NO_TLSEXT | ||
| 2692 | static int ssl3_check_finished(SSL *s) | ||
| 2693 | { | ||
| 2694 | int ok; | ||
| 2695 | long n; | ||
| 2696 | /* If we have no ticket or session ID is non-zero length (a match of | ||
| 2697 | * a non-zero session length would never reach here) it cannot be a | ||
| 2698 | * resumed session. | ||
| 2699 | */ | ||
| 2700 | if (!s->session->tlsext_tick || s->session->session_id_length) | ||
| 2701 | return 1; | ||
| 2702 | /* this function is called when we really expect a Certificate | ||
| 2703 | * message, so permit appropriate message length */ | ||
| 2704 | n=s->method->ssl_get_message(s, | ||
| 2705 | SSL3_ST_CR_CERT_A, | ||
| 2706 | SSL3_ST_CR_CERT_B, | ||
| 2707 | -1, | ||
| 2708 | s->max_cert_list, | ||
| 2709 | &ok); | ||
| 2710 | if (!ok) return((int)n); | ||
| 2711 | s->s3->tmp.reuse_message = 1; | ||
| 2712 | if ((s->s3->tmp.message_type == SSL3_MT_FINISHED) | ||
| 2713 | || (s->s3->tmp.message_type == SSL3_MT_NEWSESSION_TICKET)) | ||
| 2714 | return 2; | ||
| 2715 | |||
| 2716 | return 1; | ||
| 2717 | } | ||
| 2718 | #endif | ||
diff --git a/src/lib/libssl/s3_lib.c b/src/lib/libssl/s3_lib.c index a77588e725..bdbcd44f27 100644 --- a/src/lib/libssl/s3_lib.c +++ b/src/lib/libssl/s3_lib.c | |||
| @@ -56,7 +56,7 @@ | |||
| 56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
| 57 | */ | 57 | */ |
| 58 | /* ==================================================================== | 58 | /* ==================================================================== |
| 59 | * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. | 59 | * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved. |
| 60 | * | 60 | * |
| 61 | * Redistribution and use in source and binary forms, with or without | 61 | * Redistribution and use in source and binary forms, with or without |
| 62 | * modification, are permitted provided that the following conditions | 62 | * modification, are permitted provided that the following conditions |
| @@ -108,19 +108,35 @@ | |||
| 108 | * Hudson (tjh@cryptsoft.com). | 108 | * Hudson (tjh@cryptsoft.com). |
| 109 | * | 109 | * |
| 110 | */ | 110 | */ |
| 111 | /* ==================================================================== | ||
| 112 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
| 113 | * | ||
| 114 | * Portions of the attached software ("Contribution") are developed by | ||
| 115 | * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. | ||
| 116 | * | ||
| 117 | * The Contribution is licensed pursuant to the OpenSSL open source | ||
| 118 | * license provided above. | ||
| 119 | * | ||
| 120 | * ECC cipher suite support in OpenSSL originally written by | ||
| 121 | * Vipul Gupta and Sumit Gupta of Sun Microsystems Laboratories. | ||
| 122 | * | ||
| 123 | */ | ||
| 111 | 124 | ||
| 112 | #include <stdio.h> | 125 | #include <stdio.h> |
| 113 | #include <openssl/objects.h> | 126 | #include <openssl/objects.h> |
| 114 | #include "ssl_locl.h" | 127 | #include "ssl_locl.h" |
| 115 | #include "kssl_lcl.h" | 128 | #include "kssl_lcl.h" |
| 116 | #include <openssl/md5.h> | 129 | #include <openssl/md5.h> |
| 130 | #ifndef OPENSSL_NO_DH | ||
| 131 | #include <openssl/dh.h> | ||
| 132 | #endif | ||
| 133 | #include <openssl/pq_compat.h> | ||
| 117 | 134 | ||
| 118 | const char *ssl3_version_str="SSLv3" OPENSSL_VERSION_PTEXT; | 135 | const char ssl3_version_str[]="SSLv3" OPENSSL_VERSION_PTEXT; |
| 119 | 136 | ||
| 120 | #define SSL3_NUM_CIPHERS (sizeof(ssl3_ciphers)/sizeof(SSL_CIPHER)) | 137 | #define SSL3_NUM_CIPHERS (sizeof(ssl3_ciphers)/sizeof(SSL_CIPHER)) |
| 121 | 138 | ||
| 122 | static long ssl3_default_timeout(void ); | 139 | /* list of available SSLv3 ciphers (sorted by id) */ |
| 123 | |||
| 124 | OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | 140 | OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ |
| 125 | /* The RSA ciphers */ | 141 | /* The RSA ciphers */ |
| 126 | /* Cipher 01 */ | 142 | /* Cipher 01 */ |
| @@ -142,82 +158,13 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 142 | SSL3_TXT_RSA_NULL_SHA, | 158 | SSL3_TXT_RSA_NULL_SHA, |
| 143 | SSL3_CK_RSA_NULL_SHA, | 159 | SSL3_CK_RSA_NULL_SHA, |
| 144 | SSL_kRSA|SSL_aRSA|SSL_eNULL |SSL_SHA1|SSL_SSLV3, | 160 | SSL_kRSA|SSL_aRSA|SSL_eNULL |SSL_SHA1|SSL_SSLV3, |
| 145 | SSL_NOT_EXP|SSL_STRONG_NONE|SSL_FIPS, | 161 | SSL_NOT_EXP|SSL_STRONG_NONE, |
| 146 | 0, | ||
| 147 | 0, | ||
| 148 | 0, | ||
| 149 | SSL_ALL_CIPHERS, | ||
| 150 | SSL_ALL_STRENGTHS, | ||
| 151 | }, | ||
| 152 | |||
| 153 | /* anon DH */ | ||
| 154 | /* Cipher 17 */ | ||
| 155 | { | ||
| 156 | 1, | ||
| 157 | SSL3_TXT_ADH_RC4_40_MD5, | ||
| 158 | SSL3_CK_ADH_RC4_40_MD5, | ||
| 159 | SSL_kEDH |SSL_aNULL|SSL_RC4 |SSL_MD5 |SSL_SSLV3, | ||
| 160 | SSL_EXPORT|SSL_EXP40, | ||
| 161 | 0, | ||
| 162 | 40, | ||
| 163 | 128, | ||
| 164 | SSL_ALL_CIPHERS, | ||
| 165 | SSL_ALL_STRENGTHS, | ||
| 166 | }, | ||
| 167 | /* Cipher 18 */ | ||
| 168 | { | ||
| 169 | 1, | ||
| 170 | SSL3_TXT_ADH_RC4_128_MD5, | ||
| 171 | SSL3_CK_ADH_RC4_128_MD5, | ||
| 172 | SSL_kEDH |SSL_aNULL|SSL_RC4 |SSL_MD5 |SSL_SSLV3, | ||
| 173 | SSL_NOT_EXP|SSL_MEDIUM, | ||
| 174 | 0, | ||
| 175 | 128, | ||
| 176 | 128, | ||
| 177 | SSL_ALL_CIPHERS, | ||
| 178 | SSL_ALL_STRENGTHS, | ||
| 179 | }, | ||
| 180 | /* Cipher 19 */ | ||
| 181 | { | ||
| 182 | 1, | ||
| 183 | SSL3_TXT_ADH_DES_40_CBC_SHA, | ||
| 184 | SSL3_CK_ADH_DES_40_CBC_SHA, | ||
| 185 | SSL_kEDH |SSL_aNULL|SSL_DES|SSL_SHA1|SSL_SSLV3, | ||
| 186 | SSL_EXPORT|SSL_EXP40|SSL_FIPS, | ||
| 187 | 0, | 162 | 0, |
| 188 | 40, | ||
| 189 | 128, | ||
| 190 | SSL_ALL_CIPHERS, | ||
| 191 | SSL_ALL_STRENGTHS, | ||
| 192 | }, | ||
| 193 | /* Cipher 1A */ | ||
| 194 | { | ||
| 195 | 1, | ||
| 196 | SSL3_TXT_ADH_DES_64_CBC_SHA, | ||
| 197 | SSL3_CK_ADH_DES_64_CBC_SHA, | ||
| 198 | SSL_kEDH |SSL_aNULL|SSL_DES |SSL_SHA1|SSL_SSLV3, | ||
| 199 | SSL_NOT_EXP|SSL_LOW|SSL_FIPS, | ||
| 200 | 0, | 163 | 0, |
| 201 | 56, | ||
| 202 | 56, | ||
| 203 | SSL_ALL_CIPHERS, | ||
| 204 | SSL_ALL_STRENGTHS, | ||
| 205 | }, | ||
| 206 | /* Cipher 1B */ | ||
| 207 | { | ||
| 208 | 1, | ||
| 209 | SSL3_TXT_ADH_DES_192_CBC_SHA, | ||
| 210 | SSL3_CK_ADH_DES_192_CBC_SHA, | ||
| 211 | SSL_kEDH |SSL_aNULL|SSL_3DES |SSL_SHA1|SSL_SSLV3, | ||
| 212 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | ||
| 213 | 0, | 164 | 0, |
| 214 | 168, | ||
| 215 | 168, | ||
| 216 | SSL_ALL_CIPHERS, | 165 | SSL_ALL_CIPHERS, |
| 217 | SSL_ALL_STRENGTHS, | 166 | SSL_ALL_STRENGTHS, |
| 218 | }, | 167 | }, |
| 219 | |||
| 220 | /* RSA again */ | ||
| 221 | /* Cipher 03 */ | 168 | /* Cipher 03 */ |
| 222 | { | 169 | { |
| 223 | 1, | 170 | 1, |
| @@ -291,7 +238,7 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 291 | SSL3_TXT_RSA_DES_40_CBC_SHA, | 238 | SSL3_TXT_RSA_DES_40_CBC_SHA, |
| 292 | SSL3_CK_RSA_DES_40_CBC_SHA, | 239 | SSL3_CK_RSA_DES_40_CBC_SHA, |
| 293 | SSL_kRSA|SSL_aRSA|SSL_DES|SSL_SHA1|SSL_SSLV3, | 240 | SSL_kRSA|SSL_aRSA|SSL_DES|SSL_SHA1|SSL_SSLV3, |
| 294 | SSL_EXPORT|SSL_EXP40|SSL_FIPS, | 241 | SSL_EXPORT|SSL_EXP40, |
| 295 | 0, | 242 | 0, |
| 296 | 40, | 243 | 40, |
| 297 | 56, | 244 | 56, |
| @@ -304,7 +251,7 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 304 | SSL3_TXT_RSA_DES_64_CBC_SHA, | 251 | SSL3_TXT_RSA_DES_64_CBC_SHA, |
| 305 | SSL3_CK_RSA_DES_64_CBC_SHA, | 252 | SSL3_CK_RSA_DES_64_CBC_SHA, |
| 306 | SSL_kRSA|SSL_aRSA|SSL_DES |SSL_SHA1|SSL_SSLV3, | 253 | SSL_kRSA|SSL_aRSA|SSL_DES |SSL_SHA1|SSL_SSLV3, |
| 307 | SSL_NOT_EXP|SSL_LOW|SSL_FIPS, | 254 | SSL_NOT_EXP|SSL_LOW, |
| 308 | 0, | 255 | 0, |
| 309 | 56, | 256 | 56, |
| 310 | 56, | 257 | 56, |
| @@ -317,22 +264,21 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 317 | SSL3_TXT_RSA_DES_192_CBC3_SHA, | 264 | SSL3_TXT_RSA_DES_192_CBC3_SHA, |
| 318 | SSL3_CK_RSA_DES_192_CBC3_SHA, | 265 | SSL3_CK_RSA_DES_192_CBC3_SHA, |
| 319 | SSL_kRSA|SSL_aRSA|SSL_3DES |SSL_SHA1|SSL_SSLV3, | 266 | SSL_kRSA|SSL_aRSA|SSL_3DES |SSL_SHA1|SSL_SSLV3, |
| 320 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | 267 | SSL_NOT_EXP|SSL_HIGH, |
| 321 | 0, | 268 | 0, |
| 322 | 168, | 269 | 168, |
| 323 | 168, | 270 | 168, |
| 324 | SSL_ALL_CIPHERS, | 271 | SSL_ALL_CIPHERS, |
| 325 | SSL_ALL_STRENGTHS, | 272 | SSL_ALL_STRENGTHS, |
| 326 | }, | 273 | }, |
| 327 | 274 | /* The DH ciphers */ | |
| 328 | /* The DH ciphers */ | ||
| 329 | /* Cipher 0B */ | 275 | /* Cipher 0B */ |
| 330 | { | 276 | { |
| 331 | 0, | 277 | 0, |
| 332 | SSL3_TXT_DH_DSS_DES_40_CBC_SHA, | 278 | SSL3_TXT_DH_DSS_DES_40_CBC_SHA, |
| 333 | SSL3_CK_DH_DSS_DES_40_CBC_SHA, | 279 | SSL3_CK_DH_DSS_DES_40_CBC_SHA, |
| 334 | SSL_kDHd |SSL_aDH|SSL_DES|SSL_SHA1|SSL_SSLV3, | 280 | SSL_kDHd |SSL_aDH|SSL_DES|SSL_SHA1|SSL_SSLV3, |
| 335 | SSL_EXPORT|SSL_EXP40|SSL_FIPS, | 281 | SSL_EXPORT|SSL_EXP40, |
| 336 | 0, | 282 | 0, |
| 337 | 40, | 283 | 40, |
| 338 | 56, | 284 | 56, |
| @@ -345,7 +291,7 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 345 | SSL3_TXT_DH_DSS_DES_64_CBC_SHA, | 291 | SSL3_TXT_DH_DSS_DES_64_CBC_SHA, |
| 346 | SSL3_CK_DH_DSS_DES_64_CBC_SHA, | 292 | SSL3_CK_DH_DSS_DES_64_CBC_SHA, |
| 347 | SSL_kDHd |SSL_aDH|SSL_DES |SSL_SHA1|SSL_SSLV3, | 293 | SSL_kDHd |SSL_aDH|SSL_DES |SSL_SHA1|SSL_SSLV3, |
| 348 | SSL_NOT_EXP|SSL_LOW|SSL_FIPS, | 294 | SSL_NOT_EXP|SSL_LOW, |
| 349 | 0, | 295 | 0, |
| 350 | 56, | 296 | 56, |
| 351 | 56, | 297 | 56, |
| @@ -358,7 +304,7 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 358 | SSL3_TXT_DH_DSS_DES_192_CBC3_SHA, | 304 | SSL3_TXT_DH_DSS_DES_192_CBC3_SHA, |
| 359 | SSL3_CK_DH_DSS_DES_192_CBC3_SHA, | 305 | SSL3_CK_DH_DSS_DES_192_CBC3_SHA, |
| 360 | SSL_kDHd |SSL_aDH|SSL_3DES |SSL_SHA1|SSL_SSLV3, | 306 | SSL_kDHd |SSL_aDH|SSL_3DES |SSL_SHA1|SSL_SSLV3, |
| 361 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | 307 | SSL_NOT_EXP|SSL_HIGH, |
| 362 | 0, | 308 | 0, |
| 363 | 168, | 309 | 168, |
| 364 | 168, | 310 | 168, |
| @@ -371,7 +317,7 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 371 | SSL3_TXT_DH_RSA_DES_40_CBC_SHA, | 317 | SSL3_TXT_DH_RSA_DES_40_CBC_SHA, |
| 372 | SSL3_CK_DH_RSA_DES_40_CBC_SHA, | 318 | SSL3_CK_DH_RSA_DES_40_CBC_SHA, |
| 373 | SSL_kDHr |SSL_aDH|SSL_DES|SSL_SHA1|SSL_SSLV3, | 319 | SSL_kDHr |SSL_aDH|SSL_DES|SSL_SHA1|SSL_SSLV3, |
| 374 | SSL_EXPORT|SSL_EXP40|SSL_FIPS, | 320 | SSL_EXPORT|SSL_EXP40, |
| 375 | 0, | 321 | 0, |
| 376 | 40, | 322 | 40, |
| 377 | 56, | 323 | 56, |
| @@ -384,7 +330,7 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 384 | SSL3_TXT_DH_RSA_DES_64_CBC_SHA, | 330 | SSL3_TXT_DH_RSA_DES_64_CBC_SHA, |
| 385 | SSL3_CK_DH_RSA_DES_64_CBC_SHA, | 331 | SSL3_CK_DH_RSA_DES_64_CBC_SHA, |
| 386 | SSL_kDHr |SSL_aDH|SSL_DES |SSL_SHA1|SSL_SSLV3, | 332 | SSL_kDHr |SSL_aDH|SSL_DES |SSL_SHA1|SSL_SSLV3, |
| 387 | SSL_NOT_EXP|SSL_LOW|SSL_FIPS, | 333 | SSL_NOT_EXP|SSL_LOW, |
| 388 | 0, | 334 | 0, |
| 389 | 56, | 335 | 56, |
| 390 | 56, | 336 | 56, |
| @@ -397,7 +343,7 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 397 | SSL3_TXT_DH_RSA_DES_192_CBC3_SHA, | 343 | SSL3_TXT_DH_RSA_DES_192_CBC3_SHA, |
| 398 | SSL3_CK_DH_RSA_DES_192_CBC3_SHA, | 344 | SSL3_CK_DH_RSA_DES_192_CBC3_SHA, |
| 399 | SSL_kDHr |SSL_aDH|SSL_3DES |SSL_SHA1|SSL_SSLV3, | 345 | SSL_kDHr |SSL_aDH|SSL_3DES |SSL_SHA1|SSL_SSLV3, |
| 400 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | 346 | SSL_NOT_EXP|SSL_HIGH, |
| 401 | 0, | 347 | 0, |
| 402 | 168, | 348 | 168, |
| 403 | 168, | 349 | 168, |
| @@ -412,7 +358,7 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 412 | SSL3_TXT_EDH_DSS_DES_40_CBC_SHA, | 358 | SSL3_TXT_EDH_DSS_DES_40_CBC_SHA, |
| 413 | SSL3_CK_EDH_DSS_DES_40_CBC_SHA, | 359 | SSL3_CK_EDH_DSS_DES_40_CBC_SHA, |
| 414 | SSL_kEDH|SSL_aDSS|SSL_DES|SSL_SHA1|SSL_SSLV3, | 360 | SSL_kEDH|SSL_aDSS|SSL_DES|SSL_SHA1|SSL_SSLV3, |
| 415 | SSL_EXPORT|SSL_EXP40|SSL_FIPS, | 361 | SSL_EXPORT|SSL_EXP40, |
| 416 | 0, | 362 | 0, |
| 417 | 40, | 363 | 40, |
| 418 | 56, | 364 | 56, |
| @@ -425,7 +371,7 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 425 | SSL3_TXT_EDH_DSS_DES_64_CBC_SHA, | 371 | SSL3_TXT_EDH_DSS_DES_64_CBC_SHA, |
| 426 | SSL3_CK_EDH_DSS_DES_64_CBC_SHA, | 372 | SSL3_CK_EDH_DSS_DES_64_CBC_SHA, |
| 427 | SSL_kEDH|SSL_aDSS|SSL_DES |SSL_SHA1|SSL_SSLV3, | 373 | SSL_kEDH|SSL_aDSS|SSL_DES |SSL_SHA1|SSL_SSLV3, |
| 428 | SSL_NOT_EXP|SSL_LOW|SSL_FIPS, | 374 | SSL_NOT_EXP|SSL_LOW, |
| 429 | 0, | 375 | 0, |
| 430 | 56, | 376 | 56, |
| 431 | 56, | 377 | 56, |
| @@ -438,7 +384,7 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 438 | SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA, | 384 | SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA, |
| 439 | SSL3_CK_EDH_DSS_DES_192_CBC3_SHA, | 385 | SSL3_CK_EDH_DSS_DES_192_CBC3_SHA, |
| 440 | SSL_kEDH|SSL_aDSS|SSL_3DES |SSL_SHA1|SSL_SSLV3, | 386 | SSL_kEDH|SSL_aDSS|SSL_3DES |SSL_SHA1|SSL_SSLV3, |
| 441 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | 387 | SSL_NOT_EXP|SSL_HIGH, |
| 442 | 0, | 388 | 0, |
| 443 | 168, | 389 | 168, |
| 444 | 168, | 390 | 168, |
| @@ -451,7 +397,7 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 451 | SSL3_TXT_EDH_RSA_DES_40_CBC_SHA, | 397 | SSL3_TXT_EDH_RSA_DES_40_CBC_SHA, |
| 452 | SSL3_CK_EDH_RSA_DES_40_CBC_SHA, | 398 | SSL3_CK_EDH_RSA_DES_40_CBC_SHA, |
| 453 | SSL_kEDH|SSL_aRSA|SSL_DES|SSL_SHA1|SSL_SSLV3, | 399 | SSL_kEDH|SSL_aRSA|SSL_DES|SSL_SHA1|SSL_SSLV3, |
| 454 | SSL_EXPORT|SSL_EXP40|SSL_FIPS, | 400 | SSL_EXPORT|SSL_EXP40, |
| 455 | 0, | 401 | 0, |
| 456 | 40, | 402 | 40, |
| 457 | 56, | 403 | 56, |
| @@ -464,7 +410,7 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 464 | SSL3_TXT_EDH_RSA_DES_64_CBC_SHA, | 410 | SSL3_TXT_EDH_RSA_DES_64_CBC_SHA, |
| 465 | SSL3_CK_EDH_RSA_DES_64_CBC_SHA, | 411 | SSL3_CK_EDH_RSA_DES_64_CBC_SHA, |
| 466 | SSL_kEDH|SSL_aRSA|SSL_DES |SSL_SHA1|SSL_SSLV3, | 412 | SSL_kEDH|SSL_aRSA|SSL_DES |SSL_SHA1|SSL_SSLV3, |
| 467 | SSL_NOT_EXP|SSL_LOW|SSL_FIPS, | 413 | SSL_NOT_EXP|SSL_LOW, |
| 468 | 0, | 414 | 0, |
| 469 | 56, | 415 | 56, |
| 470 | 56, | 416 | 56, |
| @@ -477,7 +423,72 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 477 | SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA, | 423 | SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA, |
| 478 | SSL3_CK_EDH_RSA_DES_192_CBC3_SHA, | 424 | SSL3_CK_EDH_RSA_DES_192_CBC3_SHA, |
| 479 | SSL_kEDH|SSL_aRSA|SSL_3DES |SSL_SHA1|SSL_SSLV3, | 425 | SSL_kEDH|SSL_aRSA|SSL_3DES |SSL_SHA1|SSL_SSLV3, |
| 480 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | 426 | SSL_NOT_EXP|SSL_HIGH, |
| 427 | 0, | ||
| 428 | 168, | ||
| 429 | 168, | ||
| 430 | SSL_ALL_CIPHERS, | ||
| 431 | SSL_ALL_STRENGTHS, | ||
| 432 | }, | ||
| 433 | /* Cipher 17 */ | ||
| 434 | { | ||
| 435 | 1, | ||
| 436 | SSL3_TXT_ADH_RC4_40_MD5, | ||
| 437 | SSL3_CK_ADH_RC4_40_MD5, | ||
| 438 | SSL_kEDH |SSL_aNULL|SSL_RC4 |SSL_MD5 |SSL_SSLV3, | ||
| 439 | SSL_EXPORT|SSL_EXP40, | ||
| 440 | 0, | ||
| 441 | 40, | ||
| 442 | 128, | ||
| 443 | SSL_ALL_CIPHERS, | ||
| 444 | SSL_ALL_STRENGTHS, | ||
| 445 | }, | ||
| 446 | /* Cipher 18 */ | ||
| 447 | { | ||
| 448 | 1, | ||
| 449 | SSL3_TXT_ADH_RC4_128_MD5, | ||
| 450 | SSL3_CK_ADH_RC4_128_MD5, | ||
| 451 | SSL_kEDH |SSL_aNULL|SSL_RC4 |SSL_MD5 |SSL_SSLV3, | ||
| 452 | SSL_NOT_EXP|SSL_MEDIUM, | ||
| 453 | 0, | ||
| 454 | 128, | ||
| 455 | 128, | ||
| 456 | SSL_ALL_CIPHERS, | ||
| 457 | SSL_ALL_STRENGTHS, | ||
| 458 | }, | ||
| 459 | /* Cipher 19 */ | ||
| 460 | { | ||
| 461 | 1, | ||
| 462 | SSL3_TXT_ADH_DES_40_CBC_SHA, | ||
| 463 | SSL3_CK_ADH_DES_40_CBC_SHA, | ||
| 464 | SSL_kEDH |SSL_aNULL|SSL_DES|SSL_SHA1|SSL_SSLV3, | ||
| 465 | SSL_EXPORT|SSL_EXP40, | ||
| 466 | 0, | ||
| 467 | 40, | ||
| 468 | 128, | ||
| 469 | SSL_ALL_CIPHERS, | ||
| 470 | SSL_ALL_STRENGTHS, | ||
| 471 | }, | ||
| 472 | /* Cipher 1A */ | ||
| 473 | { | ||
| 474 | 1, | ||
| 475 | SSL3_TXT_ADH_DES_64_CBC_SHA, | ||
| 476 | SSL3_CK_ADH_DES_64_CBC_SHA, | ||
| 477 | SSL_kEDH |SSL_aNULL|SSL_DES |SSL_SHA1|SSL_SSLV3, | ||
| 478 | SSL_NOT_EXP|SSL_LOW, | ||
| 479 | 0, | ||
| 480 | 56, | ||
| 481 | 56, | ||
| 482 | SSL_ALL_CIPHERS, | ||
| 483 | SSL_ALL_STRENGTHS, | ||
| 484 | }, | ||
| 485 | /* Cipher 1B */ | ||
| 486 | { | ||
| 487 | 1, | ||
| 488 | SSL3_TXT_ADH_DES_192_CBC_SHA, | ||
| 489 | SSL3_CK_ADH_DES_192_CBC_SHA, | ||
| 490 | SSL_kEDH |SSL_aNULL|SSL_3DES |SSL_SHA1|SSL_SSLV3, | ||
| 491 | SSL_NOT_EXP|SSL_HIGH, | ||
| 481 | 0, | 492 | 0, |
| 482 | 168, | 493 | 168, |
| 483 | 168, | 494 | 168, |
| @@ -531,17 +542,14 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 531 | #endif | 542 | #endif |
| 532 | 543 | ||
| 533 | #ifndef OPENSSL_NO_KRB5 | 544 | #ifndef OPENSSL_NO_KRB5 |
| 534 | /* The Kerberos ciphers | 545 | /* The Kerberos ciphers */ |
| 535 | ** 20000107 VRS: And the first shall be last, | 546 | /* Cipher 1E */ |
| 536 | ** in hopes of avoiding the lynx ssl renegotiation problem. | ||
| 537 | */ | ||
| 538 | /* Cipher 1E VRS */ | ||
| 539 | { | 547 | { |
| 540 | 1, | 548 | 1, |
| 541 | SSL3_TXT_KRB5_DES_64_CBC_SHA, | 549 | SSL3_TXT_KRB5_DES_64_CBC_SHA, |
| 542 | SSL3_CK_KRB5_DES_64_CBC_SHA, | 550 | SSL3_CK_KRB5_DES_64_CBC_SHA, |
| 543 | SSL_kKRB5|SSL_aKRB5| SSL_DES|SSL_SHA1 |SSL_SSLV3, | 551 | SSL_kKRB5|SSL_aKRB5| SSL_DES|SSL_SHA1 |SSL_SSLV3, |
| 544 | SSL_NOT_EXP|SSL_LOW|SSL_FIPS, | 552 | SSL_NOT_EXP|SSL_LOW, |
| 545 | 0, | 553 | 0, |
| 546 | 56, | 554 | 56, |
| 547 | 56, | 555 | 56, |
| @@ -549,21 +557,21 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 549 | SSL_ALL_STRENGTHS, | 557 | SSL_ALL_STRENGTHS, |
| 550 | }, | 558 | }, |
| 551 | 559 | ||
| 552 | /* Cipher 1F VRS */ | 560 | /* Cipher 1F */ |
| 553 | { | 561 | { |
| 554 | 1, | 562 | 1, |
| 555 | SSL3_TXT_KRB5_DES_192_CBC3_SHA, | 563 | SSL3_TXT_KRB5_DES_192_CBC3_SHA, |
| 556 | SSL3_CK_KRB5_DES_192_CBC3_SHA, | 564 | SSL3_CK_KRB5_DES_192_CBC3_SHA, |
| 557 | SSL_kKRB5|SSL_aKRB5| SSL_3DES|SSL_SHA1 |SSL_SSLV3, | 565 | SSL_kKRB5|SSL_aKRB5| SSL_3DES|SSL_SHA1 |SSL_SSLV3, |
| 558 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | 566 | SSL_NOT_EXP|SSL_HIGH, |
| 559 | 0, | 567 | 0, |
| 560 | 112, | 568 | 168, |
| 561 | 168, | 569 | 168, |
| 562 | SSL_ALL_CIPHERS, | 570 | SSL_ALL_CIPHERS, |
| 563 | SSL_ALL_STRENGTHS, | 571 | SSL_ALL_STRENGTHS, |
| 564 | }, | 572 | }, |
| 565 | 573 | ||
| 566 | /* Cipher 20 VRS */ | 574 | /* Cipher 20 */ |
| 567 | { | 575 | { |
| 568 | 1, | 576 | 1, |
| 569 | SSL3_TXT_KRB5_RC4_128_SHA, | 577 | SSL3_TXT_KRB5_RC4_128_SHA, |
| @@ -577,7 +585,7 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 577 | SSL_ALL_STRENGTHS, | 585 | SSL_ALL_STRENGTHS, |
| 578 | }, | 586 | }, |
| 579 | 587 | ||
| 580 | /* Cipher 21 VRS */ | 588 | /* Cipher 21 */ |
| 581 | { | 589 | { |
| 582 | 1, | 590 | 1, |
| 583 | SSL3_TXT_KRB5_IDEA_128_CBC_SHA, | 591 | SSL3_TXT_KRB5_IDEA_128_CBC_SHA, |
| @@ -591,7 +599,7 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 591 | SSL_ALL_STRENGTHS, | 599 | SSL_ALL_STRENGTHS, |
| 592 | }, | 600 | }, |
| 593 | 601 | ||
| 594 | /* Cipher 22 VRS */ | 602 | /* Cipher 22 */ |
| 595 | { | 603 | { |
| 596 | 1, | 604 | 1, |
| 597 | SSL3_TXT_KRB5_DES_64_CBC_MD5, | 605 | SSL3_TXT_KRB5_DES_64_CBC_MD5, |
| @@ -605,7 +613,7 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 605 | SSL_ALL_STRENGTHS, | 613 | SSL_ALL_STRENGTHS, |
| 606 | }, | 614 | }, |
| 607 | 615 | ||
| 608 | /* Cipher 23 VRS */ | 616 | /* Cipher 23 */ |
| 609 | { | 617 | { |
| 610 | 1, | 618 | 1, |
| 611 | SSL3_TXT_KRB5_DES_192_CBC3_MD5, | 619 | SSL3_TXT_KRB5_DES_192_CBC3_MD5, |
| @@ -613,13 +621,13 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 613 | SSL_kKRB5|SSL_aKRB5| SSL_3DES|SSL_MD5 |SSL_SSLV3, | 621 | SSL_kKRB5|SSL_aKRB5| SSL_3DES|SSL_MD5 |SSL_SSLV3, |
| 614 | SSL_NOT_EXP|SSL_HIGH, | 622 | SSL_NOT_EXP|SSL_HIGH, |
| 615 | 0, | 623 | 0, |
| 616 | 112, | 624 | 168, |
| 617 | 168, | 625 | 168, |
| 618 | SSL_ALL_CIPHERS, | 626 | SSL_ALL_CIPHERS, |
| 619 | SSL_ALL_STRENGTHS, | 627 | SSL_ALL_STRENGTHS, |
| 620 | }, | 628 | }, |
| 621 | 629 | ||
| 622 | /* Cipher 24 VRS */ | 630 | /* Cipher 24 */ |
| 623 | { | 631 | { |
| 624 | 1, | 632 | 1, |
| 625 | SSL3_TXT_KRB5_RC4_128_MD5, | 633 | SSL3_TXT_KRB5_RC4_128_MD5, |
| @@ -633,7 +641,7 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 633 | SSL_ALL_STRENGTHS, | 641 | SSL_ALL_STRENGTHS, |
| 634 | }, | 642 | }, |
| 635 | 643 | ||
| 636 | /* Cipher 25 VRS */ | 644 | /* Cipher 25 */ |
| 637 | { | 645 | { |
| 638 | 1, | 646 | 1, |
| 639 | SSL3_TXT_KRB5_IDEA_128_CBC_MD5, | 647 | SSL3_TXT_KRB5_IDEA_128_CBC_MD5, |
| @@ -647,13 +655,13 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 647 | SSL_ALL_STRENGTHS, | 655 | SSL_ALL_STRENGTHS, |
| 648 | }, | 656 | }, |
| 649 | 657 | ||
| 650 | /* Cipher 26 VRS */ | 658 | /* Cipher 26 */ |
| 651 | { | 659 | { |
| 652 | 1, | 660 | 1, |
| 653 | SSL3_TXT_KRB5_DES_40_CBC_SHA, | 661 | SSL3_TXT_KRB5_DES_40_CBC_SHA, |
| 654 | SSL3_CK_KRB5_DES_40_CBC_SHA, | 662 | SSL3_CK_KRB5_DES_40_CBC_SHA, |
| 655 | SSL_kKRB5|SSL_aKRB5| SSL_DES|SSL_SHA1 |SSL_SSLV3, | 663 | SSL_kKRB5|SSL_aKRB5| SSL_DES|SSL_SHA1 |SSL_SSLV3, |
| 656 | SSL_EXPORT|SSL_EXP40|SSL_FIPS, | 664 | SSL_EXPORT|SSL_EXP40, |
| 657 | 0, | 665 | 0, |
| 658 | 40, | 666 | 40, |
| 659 | 56, | 667 | 56, |
| @@ -661,7 +669,7 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 661 | SSL_ALL_STRENGTHS, | 669 | SSL_ALL_STRENGTHS, |
| 662 | }, | 670 | }, |
| 663 | 671 | ||
| 664 | /* Cipher 27 VRS */ | 672 | /* Cipher 27 */ |
| 665 | { | 673 | { |
| 666 | 1, | 674 | 1, |
| 667 | SSL3_TXT_KRB5_RC2_40_CBC_SHA, | 675 | SSL3_TXT_KRB5_RC2_40_CBC_SHA, |
| @@ -675,7 +683,7 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 675 | SSL_ALL_STRENGTHS, | 683 | SSL_ALL_STRENGTHS, |
| 676 | }, | 684 | }, |
| 677 | 685 | ||
| 678 | /* Cipher 28 VRS */ | 686 | /* Cipher 28 */ |
| 679 | { | 687 | { |
| 680 | 1, | 688 | 1, |
| 681 | SSL3_TXT_KRB5_RC4_40_SHA, | 689 | SSL3_TXT_KRB5_RC4_40_SHA, |
| @@ -683,13 +691,13 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 683 | SSL_kKRB5|SSL_aKRB5| SSL_RC4|SSL_SHA1 |SSL_SSLV3, | 691 | SSL_kKRB5|SSL_aKRB5| SSL_RC4|SSL_SHA1 |SSL_SSLV3, |
| 684 | SSL_EXPORT|SSL_EXP40, | 692 | SSL_EXPORT|SSL_EXP40, |
| 685 | 0, | 693 | 0, |
| 686 | 128, | 694 | 40, |
| 687 | 128, | 695 | 128, |
| 688 | SSL_ALL_CIPHERS, | 696 | SSL_ALL_CIPHERS, |
| 689 | SSL_ALL_STRENGTHS, | 697 | SSL_ALL_STRENGTHS, |
| 690 | }, | 698 | }, |
| 691 | 699 | ||
| 692 | /* Cipher 29 VRS */ | 700 | /* Cipher 29 */ |
| 693 | { | 701 | { |
| 694 | 1, | 702 | 1, |
| 695 | SSL3_TXT_KRB5_DES_40_CBC_MD5, | 703 | SSL3_TXT_KRB5_DES_40_CBC_MD5, |
| @@ -703,7 +711,7 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 703 | SSL_ALL_STRENGTHS, | 711 | SSL_ALL_STRENGTHS, |
| 704 | }, | 712 | }, |
| 705 | 713 | ||
| 706 | /* Cipher 2A VRS */ | 714 | /* Cipher 2A */ |
| 707 | { | 715 | { |
| 708 | 1, | 716 | 1, |
| 709 | SSL3_TXT_KRB5_RC2_40_CBC_MD5, | 717 | SSL3_TXT_KRB5_RC2_40_CBC_MD5, |
| @@ -717,7 +725,7 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 717 | SSL_ALL_STRENGTHS, | 725 | SSL_ALL_STRENGTHS, |
| 718 | }, | 726 | }, |
| 719 | 727 | ||
| 720 | /* Cipher 2B VRS */ | 728 | /* Cipher 2B */ |
| 721 | { | 729 | { |
| 722 | 1, | 730 | 1, |
| 723 | SSL3_TXT_KRB5_RC4_40_MD5, | 731 | SSL3_TXT_KRB5_RC4_40_MD5, |
| @@ -725,16 +733,258 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 725 | SSL_kKRB5|SSL_aKRB5| SSL_RC4|SSL_MD5 |SSL_SSLV3, | 733 | SSL_kKRB5|SSL_aKRB5| SSL_RC4|SSL_MD5 |SSL_SSLV3, |
| 726 | SSL_EXPORT|SSL_EXP40, | 734 | SSL_EXPORT|SSL_EXP40, |
| 727 | 0, | 735 | 0, |
| 728 | 128, | 736 | 40, |
| 729 | 128, | 737 | 128, |
| 730 | SSL_ALL_CIPHERS, | 738 | SSL_ALL_CIPHERS, |
| 731 | SSL_ALL_STRENGTHS, | 739 | SSL_ALL_STRENGTHS, |
| 732 | }, | 740 | }, |
| 733 | #endif /* OPENSSL_NO_KRB5 */ | 741 | #endif /* OPENSSL_NO_KRB5 */ |
| 734 | 742 | ||
| 743 | /* New AES ciphersuites */ | ||
| 744 | /* Cipher 2F */ | ||
| 745 | { | ||
| 746 | 1, | ||
| 747 | TLS1_TXT_RSA_WITH_AES_128_SHA, | ||
| 748 | TLS1_CK_RSA_WITH_AES_128_SHA, | ||
| 749 | SSL_kRSA|SSL_aRSA|SSL_AES|SSL_SHA |SSL_TLSV1, | ||
| 750 | SSL_NOT_EXP|SSL_HIGH, | ||
| 751 | 0, | ||
| 752 | 128, | ||
| 753 | 128, | ||
| 754 | SSL_ALL_CIPHERS, | ||
| 755 | SSL_ALL_STRENGTHS, | ||
| 756 | }, | ||
| 757 | /* Cipher 30 */ | ||
| 758 | { | ||
| 759 | 0, | ||
| 760 | TLS1_TXT_DH_DSS_WITH_AES_128_SHA, | ||
| 761 | TLS1_CK_DH_DSS_WITH_AES_128_SHA, | ||
| 762 | SSL_kDHd|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1, | ||
| 763 | SSL_NOT_EXP|SSL_HIGH, | ||
| 764 | 0, | ||
| 765 | 128, | ||
| 766 | 128, | ||
| 767 | SSL_ALL_CIPHERS, | ||
| 768 | SSL_ALL_STRENGTHS, | ||
| 769 | }, | ||
| 770 | /* Cipher 31 */ | ||
| 771 | { | ||
| 772 | 0, | ||
| 773 | TLS1_TXT_DH_RSA_WITH_AES_128_SHA, | ||
| 774 | TLS1_CK_DH_RSA_WITH_AES_128_SHA, | ||
| 775 | SSL_kDHr|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1, | ||
| 776 | SSL_NOT_EXP|SSL_HIGH, | ||
| 777 | 0, | ||
| 778 | 128, | ||
| 779 | 128, | ||
| 780 | SSL_ALL_CIPHERS, | ||
| 781 | SSL_ALL_STRENGTHS, | ||
| 782 | }, | ||
| 783 | /* Cipher 32 */ | ||
| 784 | { | ||
| 785 | 1, | ||
| 786 | TLS1_TXT_DHE_DSS_WITH_AES_128_SHA, | ||
| 787 | TLS1_CK_DHE_DSS_WITH_AES_128_SHA, | ||
| 788 | SSL_kEDH|SSL_aDSS|SSL_AES|SSL_SHA|SSL_TLSV1, | ||
| 789 | SSL_NOT_EXP|SSL_HIGH, | ||
| 790 | 0, | ||
| 791 | 128, | ||
| 792 | 128, | ||
| 793 | SSL_ALL_CIPHERS, | ||
| 794 | SSL_ALL_STRENGTHS, | ||
| 795 | }, | ||
| 796 | /* Cipher 33 */ | ||
| 797 | { | ||
| 798 | 1, | ||
| 799 | TLS1_TXT_DHE_RSA_WITH_AES_128_SHA, | ||
| 800 | TLS1_CK_DHE_RSA_WITH_AES_128_SHA, | ||
| 801 | SSL_kEDH|SSL_aRSA|SSL_AES|SSL_SHA|SSL_TLSV1, | ||
| 802 | SSL_NOT_EXP|SSL_HIGH, | ||
| 803 | 0, | ||
| 804 | 128, | ||
| 805 | 128, | ||
| 806 | SSL_ALL_CIPHERS, | ||
| 807 | SSL_ALL_STRENGTHS, | ||
| 808 | }, | ||
| 809 | /* Cipher 34 */ | ||
| 810 | { | ||
| 811 | 1, | ||
| 812 | TLS1_TXT_ADH_WITH_AES_128_SHA, | ||
| 813 | TLS1_CK_ADH_WITH_AES_128_SHA, | ||
| 814 | SSL_kEDH|SSL_aNULL|SSL_AES|SSL_SHA|SSL_TLSV1, | ||
| 815 | SSL_NOT_EXP|SSL_HIGH, | ||
| 816 | 0, | ||
| 817 | 128, | ||
| 818 | 128, | ||
| 819 | SSL_ALL_CIPHERS, | ||
| 820 | SSL_ALL_STRENGTHS, | ||
| 821 | }, | ||
| 822 | |||
| 823 | /* Cipher 35 */ | ||
| 824 | { | ||
| 825 | 1, | ||
| 826 | TLS1_TXT_RSA_WITH_AES_256_SHA, | ||
| 827 | TLS1_CK_RSA_WITH_AES_256_SHA, | ||
| 828 | SSL_kRSA|SSL_aRSA|SSL_AES|SSL_SHA |SSL_TLSV1, | ||
| 829 | SSL_NOT_EXP|SSL_HIGH, | ||
| 830 | 0, | ||
| 831 | 256, | ||
| 832 | 256, | ||
| 833 | SSL_ALL_CIPHERS, | ||
| 834 | SSL_ALL_STRENGTHS, | ||
| 835 | }, | ||
| 836 | /* Cipher 36 */ | ||
| 837 | { | ||
| 838 | 0, | ||
| 839 | TLS1_TXT_DH_DSS_WITH_AES_256_SHA, | ||
| 840 | TLS1_CK_DH_DSS_WITH_AES_256_SHA, | ||
| 841 | SSL_kDHd|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1, | ||
| 842 | SSL_NOT_EXP|SSL_HIGH, | ||
| 843 | 0, | ||
| 844 | 256, | ||
| 845 | 256, | ||
| 846 | SSL_ALL_CIPHERS, | ||
| 847 | SSL_ALL_STRENGTHS, | ||
| 848 | }, | ||
| 849 | /* Cipher 37 */ | ||
| 850 | { | ||
| 851 | 0, | ||
| 852 | TLS1_TXT_DH_RSA_WITH_AES_256_SHA, | ||
| 853 | TLS1_CK_DH_RSA_WITH_AES_256_SHA, | ||
| 854 | SSL_kDHr|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1, | ||
| 855 | SSL_NOT_EXP|SSL_HIGH, | ||
| 856 | 0, | ||
| 857 | 256, | ||
| 858 | 256, | ||
| 859 | SSL_ALL_CIPHERS, | ||
| 860 | SSL_ALL_STRENGTHS, | ||
| 861 | }, | ||
| 862 | /* Cipher 38 */ | ||
| 863 | { | ||
| 864 | 1, | ||
| 865 | TLS1_TXT_DHE_DSS_WITH_AES_256_SHA, | ||
| 866 | TLS1_CK_DHE_DSS_WITH_AES_256_SHA, | ||
| 867 | SSL_kEDH|SSL_aDSS|SSL_AES|SSL_SHA|SSL_TLSV1, | ||
| 868 | SSL_NOT_EXP|SSL_HIGH, | ||
| 869 | 0, | ||
| 870 | 256, | ||
| 871 | 256, | ||
| 872 | SSL_ALL_CIPHERS, | ||
| 873 | SSL_ALL_STRENGTHS, | ||
| 874 | }, | ||
| 875 | /* Cipher 39 */ | ||
| 876 | { | ||
| 877 | 1, | ||
| 878 | TLS1_TXT_DHE_RSA_WITH_AES_256_SHA, | ||
| 879 | TLS1_CK_DHE_RSA_WITH_AES_256_SHA, | ||
| 880 | SSL_kEDH|SSL_aRSA|SSL_AES|SSL_SHA|SSL_TLSV1, | ||
| 881 | SSL_NOT_EXP|SSL_HIGH, | ||
| 882 | 0, | ||
| 883 | 256, | ||
| 884 | 256, | ||
| 885 | SSL_ALL_CIPHERS, | ||
| 886 | SSL_ALL_STRENGTHS, | ||
| 887 | }, | ||
| 888 | /* Cipher 3A */ | ||
| 889 | { | ||
| 890 | 1, | ||
| 891 | TLS1_TXT_ADH_WITH_AES_256_SHA, | ||
| 892 | TLS1_CK_ADH_WITH_AES_256_SHA, | ||
| 893 | SSL_kEDH|SSL_aNULL|SSL_AES|SSL_SHA|SSL_TLSV1, | ||
| 894 | SSL_NOT_EXP|SSL_HIGH, | ||
| 895 | 0, | ||
| 896 | 256, | ||
| 897 | 256, | ||
| 898 | SSL_ALL_CIPHERS, | ||
| 899 | SSL_ALL_STRENGTHS, | ||
| 900 | }, | ||
| 901 | |||
| 902 | #ifndef OPENSSL_NO_CAMELLIA | ||
| 903 | /* Camellia ciphersuites from RFC4132 (128-bit portion) */ | ||
| 904 | |||
| 905 | /* Cipher 41 */ | ||
| 906 | { | ||
| 907 | 1, | ||
| 908 | TLS1_TXT_RSA_WITH_CAMELLIA_128_CBC_SHA, | ||
| 909 | TLS1_CK_RSA_WITH_CAMELLIA_128_CBC_SHA, | ||
| 910 | SSL_kRSA|SSL_aRSA|SSL_CAMELLIA|SSL_SHA|SSL_TLSV1, | ||
| 911 | SSL_NOT_EXP|SSL_HIGH, | ||
| 912 | 0, | ||
| 913 | 128, | ||
| 914 | 128, | ||
| 915 | SSL_ALL_CIPHERS, | ||
| 916 | SSL_ALL_STRENGTHS | ||
| 917 | }, | ||
| 918 | /* Cipher 42 */ | ||
| 919 | { | ||
| 920 | 0, /* not implemented (non-ephemeral DH) */ | ||
| 921 | TLS1_TXT_DH_DSS_WITH_CAMELLIA_128_CBC_SHA, | ||
| 922 | TLS1_CK_DH_DSS_WITH_CAMELLIA_128_CBC_SHA, | ||
| 923 | SSL_kDHd|SSL_aDH|SSL_CAMELLIA|SSL_SHA|SSL_TLSV1, | ||
| 924 | SSL_NOT_EXP|SSL_HIGH, | ||
| 925 | 0, | ||
| 926 | 128, | ||
| 927 | 128, | ||
| 928 | SSL_ALL_CIPHERS, | ||
| 929 | SSL_ALL_STRENGTHS | ||
| 930 | }, | ||
| 931 | /* Cipher 43 */ | ||
| 932 | { | ||
| 933 | 0, /* not implemented (non-ephemeral DH) */ | ||
| 934 | TLS1_TXT_DH_RSA_WITH_CAMELLIA_128_CBC_SHA, | ||
| 935 | TLS1_CK_DH_RSA_WITH_CAMELLIA_128_CBC_SHA, | ||
| 936 | SSL_kDHr|SSL_aDH|SSL_CAMELLIA|SSL_SHA|SSL_TLSV1, | ||
| 937 | SSL_NOT_EXP|SSL_HIGH, | ||
| 938 | 0, | ||
| 939 | 128, | ||
| 940 | 128, | ||
| 941 | SSL_ALL_CIPHERS, | ||
| 942 | SSL_ALL_STRENGTHS | ||
| 943 | }, | ||
| 944 | /* Cipher 44 */ | ||
| 945 | { | ||
| 946 | 1, | ||
| 947 | TLS1_TXT_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA, | ||
| 948 | TLS1_CK_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA, | ||
| 949 | SSL_kEDH|SSL_aDSS|SSL_CAMELLIA|SSL_SHA|SSL_TLSV1, | ||
| 950 | SSL_NOT_EXP|SSL_HIGH, | ||
| 951 | 0, | ||
| 952 | 128, | ||
| 953 | 128, | ||
| 954 | SSL_ALL_CIPHERS, | ||
| 955 | SSL_ALL_STRENGTHS | ||
| 956 | }, | ||
| 957 | /* Cipher 45 */ | ||
| 958 | { | ||
| 959 | 1, | ||
| 960 | TLS1_TXT_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA, | ||
| 961 | TLS1_CK_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA, | ||
| 962 | SSL_kEDH|SSL_aRSA|SSL_CAMELLIA|SSL_SHA|SSL_TLSV1, | ||
| 963 | SSL_NOT_EXP|SSL_HIGH, | ||
| 964 | 0, | ||
| 965 | 128, | ||
| 966 | 128, | ||
| 967 | SSL_ALL_CIPHERS, | ||
| 968 | SSL_ALL_STRENGTHS | ||
| 969 | }, | ||
| 970 | /* Cipher 46 */ | ||
| 971 | { | ||
| 972 | 1, | ||
| 973 | TLS1_TXT_ADH_WITH_CAMELLIA_128_CBC_SHA, | ||
| 974 | TLS1_CK_ADH_WITH_CAMELLIA_128_CBC_SHA, | ||
| 975 | SSL_kEDH|SSL_aNULL|SSL_CAMELLIA|SSL_SHA|SSL_TLSV1, | ||
| 976 | SSL_NOT_EXP|SSL_HIGH, | ||
| 977 | 0, | ||
| 978 | 128, | ||
| 979 | 128, | ||
| 980 | SSL_ALL_CIPHERS, | ||
| 981 | SSL_ALL_STRENGTHS | ||
| 982 | }, | ||
| 983 | #endif /* OPENSSL_NO_CAMELLIA */ | ||
| 735 | 984 | ||
| 736 | #if TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES | 985 | #if TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES |
| 737 | /* New TLS Export CipherSuites */ | 986 | /* New TLS Export CipherSuites from expired ID */ |
| 987 | #if 0 | ||
| 738 | /* Cipher 60 */ | 988 | /* Cipher 60 */ |
| 739 | { | 989 | { |
| 740 | 1, | 990 | 1, |
| @@ -761,13 +1011,14 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 761 | SSL_ALL_CIPHERS, | 1011 | SSL_ALL_CIPHERS, |
| 762 | SSL_ALL_STRENGTHS, | 1012 | SSL_ALL_STRENGTHS, |
| 763 | }, | 1013 | }, |
| 1014 | #endif | ||
| 764 | /* Cipher 62 */ | 1015 | /* Cipher 62 */ |
| 765 | { | 1016 | { |
| 766 | 1, | 1017 | 1, |
| 767 | TLS1_TXT_RSA_EXPORT1024_WITH_DES_CBC_SHA, | 1018 | TLS1_TXT_RSA_EXPORT1024_WITH_DES_CBC_SHA, |
| 768 | TLS1_CK_RSA_EXPORT1024_WITH_DES_CBC_SHA, | 1019 | TLS1_CK_RSA_EXPORT1024_WITH_DES_CBC_SHA, |
| 769 | SSL_kRSA|SSL_aRSA|SSL_DES|SSL_SHA|SSL_TLSV1, | 1020 | SSL_kRSA|SSL_aRSA|SSL_DES|SSL_SHA|SSL_TLSV1, |
| 770 | SSL_EXPORT|SSL_EXP56|SSL_FIPS, | 1021 | SSL_EXPORT|SSL_EXP56, |
| 771 | 0, | 1022 | 0, |
| 772 | 56, | 1023 | 56, |
| 773 | 56, | 1024 | 56, |
| @@ -780,7 +1031,7 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 780 | TLS1_TXT_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA, | 1031 | TLS1_TXT_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA, |
| 781 | TLS1_CK_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA, | 1032 | TLS1_CK_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA, |
| 782 | SSL_kEDH|SSL_aDSS|SSL_DES|SSL_SHA|SSL_TLSV1, | 1033 | SSL_kEDH|SSL_aDSS|SSL_DES|SSL_SHA|SSL_TLSV1, |
| 783 | SSL_EXPORT|SSL_EXP56|SSL_FIPS, | 1034 | SSL_EXPORT|SSL_EXP56, |
| 784 | 0, | 1035 | 0, |
| 785 | 56, | 1036 | 56, |
| 786 | 56, | 1037 | 56, |
| @@ -827,170 +1078,536 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
| 827 | SSL_ALL_STRENGTHS | 1078 | SSL_ALL_STRENGTHS |
| 828 | }, | 1079 | }, |
| 829 | #endif | 1080 | #endif |
| 830 | /* New AES ciphersuites */ | ||
| 831 | 1081 | ||
| 832 | /* Cipher 2F */ | 1082 | #ifndef OPENSSL_NO_CAMELLIA |
| 1083 | /* Camellia ciphersuites from RFC4132 (256-bit portion) */ | ||
| 1084 | |||
| 1085 | /* Cipher 84 */ | ||
| 1086 | { | ||
| 1087 | 1, | ||
| 1088 | TLS1_TXT_RSA_WITH_CAMELLIA_256_CBC_SHA, | ||
| 1089 | TLS1_CK_RSA_WITH_CAMELLIA_256_CBC_SHA, | ||
| 1090 | SSL_kRSA|SSL_aRSA|SSL_CAMELLIA|SSL_SHA|SSL_TLSV1, | ||
| 1091 | SSL_NOT_EXP|SSL_HIGH, | ||
| 1092 | 0, | ||
| 1093 | 256, | ||
| 1094 | 256, | ||
| 1095 | SSL_ALL_CIPHERS, | ||
| 1096 | SSL_ALL_STRENGTHS | ||
| 1097 | }, | ||
| 1098 | /* Cipher 85 */ | ||
| 1099 | { | ||
| 1100 | 0, /* not implemented (non-ephemeral DH) */ | ||
| 1101 | TLS1_TXT_DH_DSS_WITH_CAMELLIA_256_CBC_SHA, | ||
| 1102 | TLS1_CK_DH_DSS_WITH_CAMELLIA_256_CBC_SHA, | ||
| 1103 | SSL_kDHd|SSL_aDH|SSL_CAMELLIA|SSL_SHA|SSL_TLSV1, | ||
| 1104 | SSL_NOT_EXP|SSL_HIGH, | ||
| 1105 | 0, | ||
| 1106 | 256, | ||
| 1107 | 256, | ||
| 1108 | SSL_ALL_CIPHERS, | ||
| 1109 | SSL_ALL_STRENGTHS | ||
| 1110 | }, | ||
| 1111 | /* Cipher 86 */ | ||
| 1112 | { | ||
| 1113 | 0, /* not implemented (non-ephemeral DH) */ | ||
| 1114 | TLS1_TXT_DH_RSA_WITH_CAMELLIA_256_CBC_SHA, | ||
| 1115 | TLS1_CK_DH_RSA_WITH_CAMELLIA_256_CBC_SHA, | ||
| 1116 | SSL_kDHr|SSL_aDH|SSL_CAMELLIA|SSL_SHA|SSL_TLSV1, | ||
| 1117 | SSL_NOT_EXP|SSL_HIGH, | ||
| 1118 | 0, | ||
| 1119 | 256, | ||
| 1120 | 256, | ||
| 1121 | SSL_ALL_CIPHERS, | ||
| 1122 | SSL_ALL_STRENGTHS | ||
| 1123 | }, | ||
| 1124 | /* Cipher 87 */ | ||
| 1125 | { | ||
| 1126 | 1, | ||
| 1127 | TLS1_TXT_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA, | ||
| 1128 | TLS1_CK_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA, | ||
| 1129 | SSL_kEDH|SSL_aDSS|SSL_CAMELLIA|SSL_SHA|SSL_TLSV1, | ||
| 1130 | SSL_NOT_EXP|SSL_HIGH, | ||
| 1131 | 0, | ||
| 1132 | 256, | ||
| 1133 | 256, | ||
| 1134 | SSL_ALL_CIPHERS, | ||
| 1135 | SSL_ALL_STRENGTHS | ||
| 1136 | }, | ||
| 1137 | /* Cipher 88 */ | ||
| 1138 | { | ||
| 1139 | 1, | ||
| 1140 | TLS1_TXT_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA, | ||
| 1141 | TLS1_CK_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA, | ||
| 1142 | SSL_kEDH|SSL_aRSA|SSL_CAMELLIA|SSL_SHA|SSL_TLSV1, | ||
| 1143 | SSL_NOT_EXP|SSL_HIGH, | ||
| 1144 | 0, | ||
| 1145 | 256, | ||
| 1146 | 256, | ||
| 1147 | SSL_ALL_CIPHERS, | ||
| 1148 | SSL_ALL_STRENGTHS | ||
| 1149 | }, | ||
| 1150 | /* Cipher 89 */ | ||
| 1151 | { | ||
| 1152 | 1, | ||
| 1153 | TLS1_TXT_ADH_WITH_CAMELLIA_256_CBC_SHA, | ||
| 1154 | TLS1_CK_ADH_WITH_CAMELLIA_256_CBC_SHA, | ||
| 1155 | SSL_kEDH|SSL_aNULL|SSL_CAMELLIA|SSL_SHA|SSL_TLSV1, | ||
| 1156 | SSL_NOT_EXP|SSL_HIGH, | ||
| 1157 | 0, | ||
| 1158 | 256, | ||
| 1159 | 256, | ||
| 1160 | SSL_ALL_CIPHERS, | ||
| 1161 | SSL_ALL_STRENGTHS | ||
| 1162 | }, | ||
| 1163 | #endif /* OPENSSL_NO_CAMELLIA */ | ||
| 1164 | |||
| 1165 | #ifndef OPENSSL_NO_SEED | ||
| 1166 | /* SEED ciphersuites from RFC4162 */ | ||
| 1167 | |||
| 1168 | /* Cipher 96 */ | ||
| 1169 | { | ||
| 1170 | 1, | ||
| 1171 | TLS1_TXT_RSA_WITH_SEED_SHA, | ||
| 1172 | TLS1_CK_RSA_WITH_SEED_SHA, | ||
| 1173 | SSL_kRSA|SSL_aRSA|SSL_SEED|SSL_SHA1|SSL_TLSV1, | ||
| 1174 | SSL_NOT_EXP|SSL_MEDIUM, | ||
| 1175 | 0, | ||
| 1176 | 128, | ||
| 1177 | 128, | ||
| 1178 | SSL_ALL_CIPHERS, | ||
| 1179 | SSL_ALL_STRENGTHS, | ||
| 1180 | }, | ||
| 1181 | |||
| 1182 | /* Cipher 97 */ | ||
| 1183 | { | ||
| 1184 | 0, /* not implemented (non-ephemeral DH) */ | ||
| 1185 | TLS1_TXT_DH_DSS_WITH_SEED_SHA, | ||
| 1186 | TLS1_CK_DH_DSS_WITH_SEED_SHA, | ||
| 1187 | SSL_kDHd|SSL_aDH|SSL_SEED|SSL_SHA1|SSL_TLSV1, | ||
| 1188 | SSL_NOT_EXP|SSL_MEDIUM, | ||
| 1189 | 0, | ||
| 1190 | 128, | ||
| 1191 | 128, | ||
| 1192 | SSL_ALL_CIPHERS, | ||
| 1193 | SSL_ALL_STRENGTHS, | ||
| 1194 | }, | ||
| 1195 | |||
| 1196 | /* Cipher 98 */ | ||
| 1197 | { | ||
| 1198 | 0, /* not implemented (non-ephemeral DH) */ | ||
| 1199 | TLS1_TXT_DH_RSA_WITH_SEED_SHA, | ||
| 1200 | TLS1_CK_DH_RSA_WITH_SEED_SHA, | ||
| 1201 | SSL_kDHr|SSL_aDH|SSL_SEED|SSL_SHA1|SSL_TLSV1, | ||
| 1202 | SSL_NOT_EXP|SSL_MEDIUM, | ||
| 1203 | 0, | ||
| 1204 | 128, | ||
| 1205 | 128, | ||
| 1206 | SSL_ALL_CIPHERS, | ||
| 1207 | SSL_ALL_STRENGTHS, | ||
| 1208 | }, | ||
| 1209 | |||
| 1210 | /* Cipher 99 */ | ||
| 1211 | { | ||
| 1212 | 1, | ||
| 1213 | TLS1_TXT_DHE_DSS_WITH_SEED_SHA, | ||
| 1214 | TLS1_CK_DHE_DSS_WITH_SEED_SHA, | ||
| 1215 | SSL_kEDH|SSL_aDSS|SSL_SEED|SSL_SHA1|SSL_TLSV1, | ||
| 1216 | SSL_NOT_EXP|SSL_MEDIUM, | ||
| 1217 | 0, | ||
| 1218 | 128, | ||
| 1219 | 128, | ||
| 1220 | SSL_ALL_CIPHERS, | ||
| 1221 | SSL_ALL_STRENGTHS, | ||
| 1222 | }, | ||
| 1223 | |||
| 1224 | /* Cipher 9A */ | ||
| 1225 | { | ||
| 1226 | 1, | ||
| 1227 | TLS1_TXT_DHE_RSA_WITH_SEED_SHA, | ||
| 1228 | TLS1_CK_DHE_RSA_WITH_SEED_SHA, | ||
| 1229 | SSL_kEDH|SSL_aRSA|SSL_SEED|SSL_SHA1|SSL_TLSV1, | ||
| 1230 | SSL_NOT_EXP|SSL_MEDIUM, | ||
| 1231 | 0, | ||
| 1232 | 128, | ||
| 1233 | 128, | ||
| 1234 | SSL_ALL_CIPHERS, | ||
| 1235 | SSL_ALL_STRENGTHS, | ||
| 1236 | }, | ||
| 1237 | |||
| 1238 | /* Cipher 9B */ | ||
| 1239 | { | ||
| 1240 | 1, | ||
| 1241 | TLS1_TXT_ADH_WITH_SEED_SHA, | ||
| 1242 | TLS1_CK_ADH_WITH_SEED_SHA, | ||
| 1243 | SSL_kEDH|SSL_aNULL|SSL_SEED|SSL_SHA1|SSL_TLSV1, | ||
| 1244 | SSL_NOT_EXP|SSL_MEDIUM, | ||
| 1245 | 0, | ||
| 1246 | 128, | ||
| 1247 | 128, | ||
| 1248 | SSL_ALL_CIPHERS, | ||
| 1249 | SSL_ALL_STRENGTHS, | ||
| 1250 | }, | ||
| 1251 | |||
| 1252 | #endif /* OPENSSL_NO_SEED */ | ||
| 1253 | |||
| 1254 | #ifndef OPENSSL_NO_ECDH | ||
| 1255 | /* Cipher C001 */ | ||
| 833 | { | 1256 | { |
| 834 | 1, | 1257 | 1, |
| 835 | TLS1_TXT_RSA_WITH_AES_128_SHA, | 1258 | TLS1_TXT_ECDH_ECDSA_WITH_NULL_SHA, |
| 836 | TLS1_CK_RSA_WITH_AES_128_SHA, | 1259 | TLS1_CK_ECDH_ECDSA_WITH_NULL_SHA, |
| 837 | SSL_kRSA|SSL_aRSA|SSL_AES|SSL_SHA |SSL_TLSV1, | 1260 | SSL_kECDH|SSL_aECDSA|SSL_eNULL|SSL_SHA|SSL_TLSV1, |
| 838 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | 1261 | SSL_NOT_EXP, |
| 839 | 0, | 1262 | 0, |
| 840 | 128, | 1263 | 0, |
| 841 | 128, | 1264 | 0, |
| 842 | SSL_ALL_CIPHERS, | 1265 | SSL_ALL_CIPHERS, |
| 843 | SSL_ALL_STRENGTHS, | 1266 | SSL_ALL_STRENGTHS, |
| 844 | }, | 1267 | }, |
| 845 | /* Cipher 30 */ | 1268 | |
| 1269 | /* Cipher C002 */ | ||
| 846 | { | 1270 | { |
| 847 | 0, | 1271 | 1, |
| 848 | TLS1_TXT_DH_DSS_WITH_AES_128_SHA, | 1272 | TLS1_TXT_ECDH_ECDSA_WITH_RC4_128_SHA, |
| 849 | TLS1_CK_DH_DSS_WITH_AES_128_SHA, | 1273 | TLS1_CK_ECDH_ECDSA_WITH_RC4_128_SHA, |
| 850 | SSL_kDHd|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1, | 1274 | SSL_kECDH|SSL_aECDSA|SSL_RC4|SSL_SHA|SSL_TLSV1, |
| 851 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | 1275 | SSL_NOT_EXP, |
| 852 | 0, | 1276 | 0, |
| 853 | 128, | 1277 | 128, |
| 854 | 128, | 1278 | 128, |
| 855 | SSL_ALL_CIPHERS, | 1279 | SSL_ALL_CIPHERS, |
| 856 | SSL_ALL_STRENGTHS, | 1280 | SSL_ALL_STRENGTHS, |
| 857 | }, | 1281 | }, |
| 858 | /* Cipher 31 */ | 1282 | |
| 1283 | /* Cipher C003 */ | ||
| 859 | { | 1284 | { |
| 860 | 0, | 1285 | 1, |
| 861 | TLS1_TXT_DH_RSA_WITH_AES_128_SHA, | 1286 | TLS1_TXT_ECDH_ECDSA_WITH_DES_192_CBC3_SHA, |
| 862 | TLS1_CK_DH_RSA_WITH_AES_128_SHA, | 1287 | TLS1_CK_ECDH_ECDSA_WITH_DES_192_CBC3_SHA, |
| 863 | SSL_kDHr|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1, | 1288 | SSL_kECDH|SSL_aECDSA|SSL_3DES|SSL_SHA|SSL_TLSV1, |
| 864 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | 1289 | SSL_NOT_EXP|SSL_HIGH, |
| 865 | 0, | 1290 | 0, |
| 866 | 128, | 1291 | 168, |
| 867 | 128, | 1292 | 168, |
| 868 | SSL_ALL_CIPHERS, | 1293 | SSL_ALL_CIPHERS, |
| 869 | SSL_ALL_STRENGTHS, | 1294 | SSL_ALL_STRENGTHS, |
| 870 | }, | 1295 | }, |
| 871 | /* Cipher 32 */ | 1296 | |
| 1297 | /* Cipher C004 */ | ||
| 872 | { | 1298 | { |
| 873 | 1, | 1299 | 1, |
| 874 | TLS1_TXT_DHE_DSS_WITH_AES_128_SHA, | 1300 | TLS1_TXT_ECDH_ECDSA_WITH_AES_128_CBC_SHA, |
| 875 | TLS1_CK_DHE_DSS_WITH_AES_128_SHA, | 1301 | TLS1_CK_ECDH_ECDSA_WITH_AES_128_CBC_SHA, |
| 876 | SSL_kEDH|SSL_aDSS|SSL_AES|SSL_SHA|SSL_TLSV1, | 1302 | SSL_kECDH|SSL_aECDSA|SSL_AES|SSL_SHA|SSL_TLSV1, |
| 877 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | 1303 | SSL_NOT_EXP|SSL_HIGH, |
| 878 | 0, | 1304 | 0, |
| 879 | 128, | 1305 | 128, |
| 880 | 128, | 1306 | 128, |
| 881 | SSL_ALL_CIPHERS, | 1307 | SSL_ALL_CIPHERS, |
| 882 | SSL_ALL_STRENGTHS, | 1308 | SSL_ALL_STRENGTHS, |
| 883 | }, | 1309 | }, |
| 884 | /* Cipher 33 */ | 1310 | |
| 1311 | /* Cipher C005 */ | ||
| 885 | { | 1312 | { |
| 886 | 1, | 1313 | 1, |
| 887 | TLS1_TXT_DHE_RSA_WITH_AES_128_SHA, | 1314 | TLS1_TXT_ECDH_ECDSA_WITH_AES_256_CBC_SHA, |
| 888 | TLS1_CK_DHE_RSA_WITH_AES_128_SHA, | 1315 | TLS1_CK_ECDH_ECDSA_WITH_AES_256_CBC_SHA, |
| 889 | SSL_kEDH|SSL_aRSA|SSL_AES|SSL_SHA|SSL_TLSV1, | 1316 | SSL_kECDH|SSL_aECDSA|SSL_AES|SSL_SHA|SSL_TLSV1, |
| 890 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | 1317 | SSL_NOT_EXP|SSL_HIGH, |
| 891 | 0, | 1318 | 0, |
| 892 | 128, | 1319 | 256, |
| 893 | 128, | 1320 | 256, |
| 894 | SSL_ALL_CIPHERS, | 1321 | SSL_ALL_CIPHERS, |
| 895 | SSL_ALL_STRENGTHS, | 1322 | SSL_ALL_STRENGTHS, |
| 896 | }, | 1323 | }, |
| 897 | /* Cipher 34 */ | 1324 | |
| 1325 | /* Cipher C006 */ | ||
| 898 | { | 1326 | { |
| 899 | 1, | 1327 | 1, |
| 900 | TLS1_TXT_ADH_WITH_AES_128_SHA, | 1328 | TLS1_TXT_ECDHE_ECDSA_WITH_NULL_SHA, |
| 901 | TLS1_CK_ADH_WITH_AES_128_SHA, | 1329 | TLS1_CK_ECDHE_ECDSA_WITH_NULL_SHA, |
| 902 | SSL_kEDH|SSL_aNULL|SSL_AES|SSL_SHA|SSL_TLSV1, | 1330 | SSL_kECDHE|SSL_aECDSA|SSL_eNULL|SSL_SHA|SSL_TLSV1, |
| 903 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | 1331 | SSL_NOT_EXP, |
| 904 | 0, | 1332 | 0, |
| 905 | 128, | 1333 | 0, |
| 906 | 128, | 1334 | 0, |
| 907 | SSL_ALL_CIPHERS, | 1335 | SSL_ALL_CIPHERS, |
| 908 | SSL_ALL_STRENGTHS, | 1336 | SSL_ALL_STRENGTHS, |
| 909 | }, | 1337 | }, |
| 910 | 1338 | ||
| 911 | /* Cipher 35 */ | 1339 | /* Cipher C007 */ |
| 912 | { | 1340 | { |
| 913 | 1, | 1341 | 1, |
| 914 | TLS1_TXT_RSA_WITH_AES_256_SHA, | 1342 | TLS1_TXT_ECDHE_ECDSA_WITH_RC4_128_SHA, |
| 915 | TLS1_CK_RSA_WITH_AES_256_SHA, | 1343 | TLS1_CK_ECDHE_ECDSA_WITH_RC4_128_SHA, |
| 916 | SSL_kRSA|SSL_aRSA|SSL_AES|SSL_SHA |SSL_TLSV1, | 1344 | SSL_kECDHE|SSL_aECDSA|SSL_RC4|SSL_SHA|SSL_TLSV1, |
| 917 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | 1345 | SSL_NOT_EXP, |
| 918 | 0, | 1346 | 0, |
| 919 | 256, | 1347 | 128, |
| 920 | 256, | 1348 | 128, |
| 921 | SSL_ALL_CIPHERS, | 1349 | SSL_ALL_CIPHERS, |
| 922 | SSL_ALL_STRENGTHS, | 1350 | SSL_ALL_STRENGTHS, |
| 923 | }, | 1351 | }, |
| 924 | /* Cipher 36 */ | 1352 | |
| 1353 | /* Cipher C008 */ | ||
| 925 | { | 1354 | { |
| 926 | 0, | 1355 | 1, |
| 927 | TLS1_TXT_DH_DSS_WITH_AES_256_SHA, | 1356 | TLS1_TXT_ECDHE_ECDSA_WITH_DES_192_CBC3_SHA, |
| 928 | TLS1_CK_DH_DSS_WITH_AES_256_SHA, | 1357 | TLS1_CK_ECDHE_ECDSA_WITH_DES_192_CBC3_SHA, |
| 929 | SSL_kDHd|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1, | 1358 | SSL_kECDHE|SSL_aECDSA|SSL_3DES|SSL_SHA|SSL_TLSV1, |
| 930 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | 1359 | SSL_NOT_EXP|SSL_HIGH, |
| 931 | 0, | 1360 | 0, |
| 932 | 256, | 1361 | 168, |
| 933 | 256, | 1362 | 168, |
| 934 | SSL_ALL_CIPHERS, | 1363 | SSL_ALL_CIPHERS, |
| 935 | SSL_ALL_STRENGTHS, | 1364 | SSL_ALL_STRENGTHS, |
| 936 | }, | 1365 | }, |
| 937 | /* Cipher 37 */ | 1366 | |
| 1367 | /* Cipher C009 */ | ||
| 938 | { | 1368 | { |
| 939 | 0, | 1369 | 1, |
| 940 | TLS1_TXT_DH_RSA_WITH_AES_256_SHA, | 1370 | TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, |
| 941 | TLS1_CK_DH_RSA_WITH_AES_256_SHA, | 1371 | TLS1_CK_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, |
| 942 | SSL_kDHr|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1, | 1372 | SSL_kECDHE|SSL_aECDSA|SSL_AES|SSL_SHA|SSL_TLSV1, |
| 943 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | 1373 | SSL_NOT_EXP|SSL_HIGH, |
| 944 | 0, | 1374 | 0, |
| 945 | 256, | 1375 | 128, |
| 946 | 256, | 1376 | 128, |
| 947 | SSL_ALL_CIPHERS, | 1377 | SSL_ALL_CIPHERS, |
| 948 | SSL_ALL_STRENGTHS, | 1378 | SSL_ALL_STRENGTHS, |
| 949 | }, | 1379 | }, |
| 950 | /* Cipher 38 */ | 1380 | |
| 1381 | /* Cipher C00A */ | ||
| 951 | { | 1382 | { |
| 952 | 1, | 1383 | 1, |
| 953 | TLS1_TXT_DHE_DSS_WITH_AES_256_SHA, | 1384 | TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, |
| 954 | TLS1_CK_DHE_DSS_WITH_AES_256_SHA, | 1385 | TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, |
| 955 | SSL_kEDH|SSL_aDSS|SSL_AES|SSL_SHA|SSL_TLSV1, | 1386 | SSL_kECDHE|SSL_aECDSA|SSL_AES|SSL_SHA|SSL_TLSV1, |
| 956 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | 1387 | SSL_NOT_EXP|SSL_HIGH, |
| 957 | 0, | 1388 | 0, |
| 958 | 256, | 1389 | 256, |
| 959 | 256, | 1390 | 256, |
| 960 | SSL_ALL_CIPHERS, | 1391 | SSL_ALL_CIPHERS, |
| 961 | SSL_ALL_STRENGTHS, | 1392 | SSL_ALL_STRENGTHS, |
| 962 | }, | 1393 | }, |
| 963 | /* Cipher 39 */ | 1394 | |
| 1395 | /* Cipher C00B */ | ||
| 964 | { | 1396 | { |
| 965 | 1, | 1397 | 1, |
| 966 | TLS1_TXT_DHE_RSA_WITH_AES_256_SHA, | 1398 | TLS1_TXT_ECDH_RSA_WITH_NULL_SHA, |
| 967 | TLS1_CK_DHE_RSA_WITH_AES_256_SHA, | 1399 | TLS1_CK_ECDH_RSA_WITH_NULL_SHA, |
| 968 | SSL_kEDH|SSL_aRSA|SSL_AES|SSL_SHA|SSL_TLSV1, | 1400 | SSL_kECDH|SSL_aRSA|SSL_eNULL|SSL_SHA|SSL_TLSV1, |
| 969 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | 1401 | SSL_NOT_EXP, |
| 970 | 0, | 1402 | 0, |
| 971 | 256, | 1403 | 0, |
| 972 | 256, | 1404 | 0, |
| 973 | SSL_ALL_CIPHERS, | 1405 | SSL_ALL_CIPHERS, |
| 974 | SSL_ALL_STRENGTHS, | 1406 | SSL_ALL_STRENGTHS, |
| 975 | }, | 1407 | }, |
| 976 | /* Cipher 3A */ | 1408 | |
| 1409 | /* Cipher C00C */ | ||
| 977 | { | 1410 | { |
| 978 | 1, | 1411 | 1, |
| 979 | TLS1_TXT_ADH_WITH_AES_256_SHA, | 1412 | TLS1_TXT_ECDH_RSA_WITH_RC4_128_SHA, |
| 980 | TLS1_CK_ADH_WITH_AES_256_SHA, | 1413 | TLS1_CK_ECDH_RSA_WITH_RC4_128_SHA, |
| 981 | SSL_kEDH|SSL_aNULL|SSL_AES|SSL_SHA|SSL_TLSV1, | 1414 | SSL_kECDH|SSL_aRSA|SSL_RC4|SSL_SHA|SSL_TLSV1, |
| 982 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | 1415 | SSL_NOT_EXP, |
| 983 | 0, | 1416 | 0, |
| 984 | 256, | 1417 | 128, |
| 985 | 256, | 1418 | 128, |
| 986 | SSL_ALL_CIPHERS, | 1419 | SSL_ALL_CIPHERS, |
| 987 | SSL_ALL_STRENGTHS, | 1420 | SSL_ALL_STRENGTHS, |
| 1421 | }, | ||
| 1422 | |||
| 1423 | /* Cipher C00D */ | ||
| 1424 | { | ||
| 1425 | 1, | ||
| 1426 | TLS1_TXT_ECDH_RSA_WITH_DES_192_CBC3_SHA, | ||
| 1427 | TLS1_CK_ECDH_RSA_WITH_DES_192_CBC3_SHA, | ||
| 1428 | SSL_kECDH|SSL_aRSA|SSL_3DES|SSL_SHA|SSL_TLSV1, | ||
| 1429 | SSL_NOT_EXP|SSL_HIGH, | ||
| 1430 | 0, | ||
| 1431 | 168, | ||
| 1432 | 168, | ||
| 1433 | SSL_ALL_CIPHERS, | ||
| 1434 | SSL_ALL_STRENGTHS, | ||
| 1435 | }, | ||
| 1436 | |||
| 1437 | /* Cipher C00E */ | ||
| 1438 | { | ||
| 1439 | 1, | ||
| 1440 | TLS1_TXT_ECDH_RSA_WITH_AES_128_CBC_SHA, | ||
| 1441 | TLS1_CK_ECDH_RSA_WITH_AES_128_CBC_SHA, | ||
| 1442 | SSL_kECDH|SSL_aRSA|SSL_AES|SSL_SHA|SSL_TLSV1, | ||
| 1443 | SSL_NOT_EXP|SSL_HIGH, | ||
| 1444 | 0, | ||
| 1445 | 128, | ||
| 1446 | 128, | ||
| 1447 | SSL_ALL_CIPHERS, | ||
| 1448 | SSL_ALL_STRENGTHS, | ||
| 1449 | }, | ||
| 1450 | |||
| 1451 | /* Cipher C00F */ | ||
| 1452 | { | ||
| 1453 | 1, | ||
| 1454 | TLS1_TXT_ECDH_RSA_WITH_AES_256_CBC_SHA, | ||
| 1455 | TLS1_CK_ECDH_RSA_WITH_AES_256_CBC_SHA, | ||
| 1456 | SSL_kECDH|SSL_aRSA|SSL_AES|SSL_SHA|SSL_TLSV1, | ||
| 1457 | SSL_NOT_EXP|SSL_HIGH, | ||
| 1458 | 0, | ||
| 1459 | 256, | ||
| 1460 | 256, | ||
| 1461 | SSL_ALL_CIPHERS, | ||
| 1462 | SSL_ALL_STRENGTHS, | ||
| 1463 | }, | ||
| 1464 | |||
| 1465 | /* Cipher C010 */ | ||
| 1466 | { | ||
| 1467 | 1, | ||
| 1468 | TLS1_TXT_ECDHE_RSA_WITH_NULL_SHA, | ||
| 1469 | TLS1_CK_ECDHE_RSA_WITH_NULL_SHA, | ||
| 1470 | SSL_kECDHE|SSL_aRSA|SSL_eNULL|SSL_SHA|SSL_TLSV1, | ||
| 1471 | SSL_NOT_EXP, | ||
| 1472 | 0, | ||
| 1473 | 0, | ||
| 1474 | 0, | ||
| 1475 | SSL_ALL_CIPHERS, | ||
| 1476 | SSL_ALL_STRENGTHS, | ||
| 1477 | }, | ||
| 1478 | |||
| 1479 | /* Cipher C011 */ | ||
| 1480 | { | ||
| 1481 | 1, | ||
| 1482 | TLS1_TXT_ECDHE_RSA_WITH_RC4_128_SHA, | ||
| 1483 | TLS1_CK_ECDHE_RSA_WITH_RC4_128_SHA, | ||
| 1484 | SSL_kECDHE|SSL_aRSA|SSL_RC4|SSL_SHA|SSL_TLSV1, | ||
| 1485 | SSL_NOT_EXP, | ||
| 1486 | 0, | ||
| 1487 | 128, | ||
| 1488 | 128, | ||
| 1489 | SSL_ALL_CIPHERS, | ||
| 1490 | SSL_ALL_STRENGTHS, | ||
| 1491 | }, | ||
| 1492 | |||
| 1493 | /* Cipher C012 */ | ||
| 1494 | { | ||
| 1495 | 1, | ||
| 1496 | TLS1_TXT_ECDHE_RSA_WITH_DES_192_CBC3_SHA, | ||
| 1497 | TLS1_CK_ECDHE_RSA_WITH_DES_192_CBC3_SHA, | ||
| 1498 | SSL_kECDHE|SSL_aRSA|SSL_3DES|SSL_SHA|SSL_TLSV1, | ||
| 1499 | SSL_NOT_EXP|SSL_HIGH, | ||
| 1500 | 0, | ||
| 1501 | 168, | ||
| 1502 | 168, | ||
| 1503 | SSL_ALL_CIPHERS, | ||
| 1504 | SSL_ALL_STRENGTHS, | ||
| 1505 | }, | ||
| 1506 | |||
| 1507 | /* Cipher C013 */ | ||
| 1508 | { | ||
| 1509 | 1, | ||
| 1510 | TLS1_TXT_ECDHE_RSA_WITH_AES_128_CBC_SHA, | ||
| 1511 | TLS1_CK_ECDHE_RSA_WITH_AES_128_CBC_SHA, | ||
| 1512 | SSL_kECDHE|SSL_aRSA|SSL_AES|SSL_SHA|SSL_TLSV1, | ||
| 1513 | SSL_NOT_EXP|SSL_HIGH, | ||
| 1514 | 0, | ||
| 1515 | 128, | ||
| 1516 | 128, | ||
| 1517 | SSL_ALL_CIPHERS, | ||
| 1518 | SSL_ALL_STRENGTHS, | ||
| 1519 | }, | ||
| 1520 | |||
| 1521 | /* Cipher C014 */ | ||
| 1522 | { | ||
| 1523 | 1, | ||
| 1524 | TLS1_TXT_ECDHE_RSA_WITH_AES_256_CBC_SHA, | ||
| 1525 | TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA, | ||
| 1526 | SSL_kECDHE|SSL_aRSA|SSL_AES|SSL_SHA|SSL_TLSV1, | ||
| 1527 | SSL_NOT_EXP|SSL_HIGH, | ||
| 1528 | 0, | ||
| 1529 | 256, | ||
| 1530 | 256, | ||
| 1531 | SSL_ALL_CIPHERS, | ||
| 1532 | SSL_ALL_STRENGTHS, | ||
| 1533 | }, | ||
| 1534 | |||
| 1535 | /* Cipher C015 */ | ||
| 1536 | { | ||
| 1537 | 1, | ||
| 1538 | TLS1_TXT_ECDH_anon_WITH_NULL_SHA, | ||
| 1539 | TLS1_CK_ECDH_anon_WITH_NULL_SHA, | ||
| 1540 | SSL_kECDHE|SSL_aNULL|SSL_eNULL|SSL_SHA|SSL_TLSV1, | ||
| 1541 | SSL_NOT_EXP, | ||
| 1542 | 0, | ||
| 1543 | 0, | ||
| 1544 | 0, | ||
| 1545 | SSL_ALL_CIPHERS, | ||
| 1546 | SSL_ALL_STRENGTHS, | ||
| 988 | }, | 1547 | }, |
| 989 | 1548 | ||
| 1549 | /* Cipher C016 */ | ||
| 1550 | { | ||
| 1551 | 1, | ||
| 1552 | TLS1_TXT_ECDH_anon_WITH_RC4_128_SHA, | ||
| 1553 | TLS1_CK_ECDH_anon_WITH_RC4_128_SHA, | ||
| 1554 | SSL_kECDHE|SSL_aNULL|SSL_RC4|SSL_SHA|SSL_TLSV1, | ||
| 1555 | SSL_NOT_EXP, | ||
| 1556 | 0, | ||
| 1557 | 128, | ||
| 1558 | 128, | ||
| 1559 | SSL_ALL_CIPHERS, | ||
| 1560 | SSL_ALL_STRENGTHS, | ||
| 1561 | }, | ||
| 1562 | |||
| 1563 | /* Cipher C017 */ | ||
| 1564 | { | ||
| 1565 | 1, | ||
| 1566 | TLS1_TXT_ECDH_anon_WITH_DES_192_CBC3_SHA, | ||
| 1567 | TLS1_CK_ECDH_anon_WITH_DES_192_CBC3_SHA, | ||
| 1568 | SSL_kECDHE|SSL_aNULL|SSL_3DES|SSL_SHA|SSL_TLSV1, | ||
| 1569 | SSL_NOT_EXP|SSL_HIGH, | ||
| 1570 | 0, | ||
| 1571 | 168, | ||
| 1572 | 168, | ||
| 1573 | SSL_ALL_CIPHERS, | ||
| 1574 | SSL_ALL_STRENGTHS, | ||
| 1575 | }, | ||
| 1576 | |||
| 1577 | /* Cipher C018 */ | ||
| 1578 | { | ||
| 1579 | 1, | ||
| 1580 | TLS1_TXT_ECDH_anon_WITH_AES_128_CBC_SHA, | ||
| 1581 | TLS1_CK_ECDH_anon_WITH_AES_128_CBC_SHA, | ||
| 1582 | SSL_kECDHE|SSL_aNULL|SSL_AES|SSL_SHA|SSL_TLSV1, | ||
| 1583 | SSL_NOT_EXP|SSL_HIGH, | ||
| 1584 | 0, | ||
| 1585 | 128, | ||
| 1586 | 128, | ||
| 1587 | SSL_ALL_CIPHERS, | ||
| 1588 | SSL_ALL_STRENGTHS, | ||
| 1589 | }, | ||
| 1590 | |||
| 1591 | /* Cipher C019 */ | ||
| 1592 | { | ||
| 1593 | 1, | ||
| 1594 | TLS1_TXT_ECDH_anon_WITH_AES_256_CBC_SHA, | ||
| 1595 | TLS1_CK_ECDH_anon_WITH_AES_256_CBC_SHA, | ||
| 1596 | SSL_kECDHE|SSL_aNULL|SSL_AES|SSL_SHA|SSL_TLSV1, | ||
| 1597 | SSL_NOT_EXP|SSL_HIGH, | ||
| 1598 | 0, | ||
| 1599 | 256, | ||
| 1600 | 256, | ||
| 1601 | SSL_ALL_CIPHERS, | ||
| 1602 | SSL_ALL_STRENGTHS, | ||
| 1603 | }, | ||
| 1604 | #endif /* OPENSSL_NO_ECDH */ | ||
| 1605 | |||
| 1606 | |||
| 990 | /* end of list */ | 1607 | /* end of list */ |
| 991 | }; | 1608 | }; |
| 992 | 1609 | ||
| 993 | static SSL3_ENC_METHOD SSLv3_enc_data={ | 1610 | SSL3_ENC_METHOD SSLv3_enc_data={ |
| 994 | ssl3_enc, | 1611 | ssl3_enc, |
| 995 | ssl3_mac, | 1612 | ssl3_mac, |
| 996 | ssl3_setup_key_block, | 1613 | ssl3_setup_key_block, |
| @@ -1004,45 +1621,17 @@ static SSL3_ENC_METHOD SSLv3_enc_data={ | |||
| 1004 | ssl3_alert_code, | 1621 | ssl3_alert_code, |
| 1005 | }; | 1622 | }; |
| 1006 | 1623 | ||
| 1007 | static SSL_METHOD SSLv3_data= { | 1624 | long ssl3_default_timeout(void) |
| 1008 | SSL3_VERSION, | ||
| 1009 | ssl3_new, | ||
| 1010 | ssl3_clear, | ||
| 1011 | ssl3_free, | ||
| 1012 | ssl_undefined_function, | ||
| 1013 | ssl_undefined_function, | ||
| 1014 | ssl3_read, | ||
| 1015 | ssl3_peek, | ||
| 1016 | ssl3_write, | ||
| 1017 | ssl3_shutdown, | ||
| 1018 | ssl3_renegotiate, | ||
| 1019 | ssl3_renegotiate_check, | ||
| 1020 | ssl3_ctrl, | ||
| 1021 | ssl3_ctx_ctrl, | ||
| 1022 | ssl3_get_cipher_by_char, | ||
| 1023 | ssl3_put_cipher_by_char, | ||
| 1024 | ssl3_pending, | ||
| 1025 | ssl3_num_ciphers, | ||
| 1026 | ssl3_get_cipher, | ||
| 1027 | ssl_bad_method, | ||
| 1028 | ssl3_default_timeout, | ||
| 1029 | &SSLv3_enc_data, | ||
| 1030 | ssl_undefined_function, | ||
| 1031 | ssl3_callback_ctrl, | ||
| 1032 | ssl3_ctx_callback_ctrl, | ||
| 1033 | }; | ||
| 1034 | |||
| 1035 | static long ssl3_default_timeout(void) | ||
| 1036 | { | 1625 | { |
| 1037 | /* 2 hours, the 24 hours mentioned in the SSLv3 spec | 1626 | /* 2 hours, the 24 hours mentioned in the SSLv3 spec |
| 1038 | * is way too long for http, the cache would over fill */ | 1627 | * is way too long for http, the cache would over fill */ |
| 1039 | return(60*60*2); | 1628 | return(60*60*2); |
| 1040 | } | 1629 | } |
| 1041 | 1630 | ||
| 1042 | SSL_METHOD *sslv3_base_method(void) | 1631 | IMPLEMENT_ssl3_meth_func(sslv3_base_method, |
| 1043 | { | 1632 | ssl_undefined_function, |
| 1044 | return(&SSLv3_data); | 1633 | ssl_undefined_function, |
| 1045 | } | 1634 | ssl_bad_method) |
| 1046 | 1635 | ||
| 1047 | int ssl3_num_ciphers(void) | 1636 | int ssl3_num_ciphers(void) |
| 1048 | { | 1637 | { |
| @@ -1073,6 +1662,8 @@ int ssl3_new(SSL *s) | |||
| 1073 | memset(s3,0,sizeof *s3); | 1662 | memset(s3,0,sizeof *s3); |
| 1074 | EVP_MD_CTX_init(&s3->finish_dgst1); | 1663 | EVP_MD_CTX_init(&s3->finish_dgst1); |
| 1075 | EVP_MD_CTX_init(&s3->finish_dgst2); | 1664 | EVP_MD_CTX_init(&s3->finish_dgst2); |
| 1665 | pq_64bit_init(&(s3->rrec.seq_num)); | ||
| 1666 | pq_64bit_init(&(s3->wrec.seq_num)); | ||
| 1076 | 1667 | ||
| 1077 | s->s3=s3; | 1668 | s->s3=s3; |
| 1078 | 1669 | ||
| @@ -1098,10 +1689,18 @@ void ssl3_free(SSL *s) | |||
| 1098 | if (s->s3->tmp.dh != NULL) | 1689 | if (s->s3->tmp.dh != NULL) |
| 1099 | DH_free(s->s3->tmp.dh); | 1690 | DH_free(s->s3->tmp.dh); |
| 1100 | #endif | 1691 | #endif |
| 1692 | #ifndef OPENSSL_NO_ECDH | ||
| 1693 | if (s->s3->tmp.ecdh != NULL) | ||
| 1694 | EC_KEY_free(s->s3->tmp.ecdh); | ||
| 1695 | #endif | ||
| 1696 | |||
| 1101 | if (s->s3->tmp.ca_names != NULL) | 1697 | if (s->s3->tmp.ca_names != NULL) |
| 1102 | sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free); | 1698 | sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free); |
| 1103 | EVP_MD_CTX_cleanup(&s->s3->finish_dgst1); | 1699 | EVP_MD_CTX_cleanup(&s->s3->finish_dgst1); |
| 1104 | EVP_MD_CTX_cleanup(&s->s3->finish_dgst2); | 1700 | EVP_MD_CTX_cleanup(&s->s3->finish_dgst2); |
| 1701 | pq_64bit_free(&(s->s3->rrec.seq_num)); | ||
| 1702 | pq_64bit_free(&(s->s3->wrec.seq_num)); | ||
| 1703 | |||
| 1105 | OPENSSL_cleanse(s->s3,sizeof *s->s3); | 1704 | OPENSSL_cleanse(s->s3,sizeof *s->s3); |
| 1106 | OPENSSL_free(s->s3); | 1705 | OPENSSL_free(s->s3); |
| 1107 | s->s3=NULL; | 1706 | s->s3=NULL; |
| @@ -1125,6 +1724,10 @@ void ssl3_clear(SSL *s) | |||
| 1125 | if (s->s3->tmp.dh != NULL) | 1724 | if (s->s3->tmp.dh != NULL) |
| 1126 | DH_free(s->s3->tmp.dh); | 1725 | DH_free(s->s3->tmp.dh); |
| 1127 | #endif | 1726 | #endif |
| 1727 | #ifndef OPENSSL_NO_ECDH | ||
| 1728 | if (s->s3->tmp.ecdh != NULL) | ||
| 1729 | EC_KEY_free(s->s3->tmp.ecdh); | ||
| 1730 | #endif | ||
| 1128 | 1731 | ||
| 1129 | rp = s->s3->rbuf.buf; | 1732 | rp = s->s3->rbuf.buf; |
| 1130 | wp = s->s3->wbuf.buf; | 1733 | wp = s->s3->wbuf.buf; |
| @@ -1263,13 +1866,122 @@ long ssl3_ctrl(SSL *s, int cmd, long larg, void *parg) | |||
| 1263 | } | 1866 | } |
| 1264 | break; | 1867 | break; |
| 1265 | #endif | 1868 | #endif |
| 1869 | #ifndef OPENSSL_NO_ECDH | ||
| 1870 | case SSL_CTRL_SET_TMP_ECDH: | ||
| 1871 | { | ||
| 1872 | EC_KEY *ecdh = NULL; | ||
| 1873 | |||
| 1874 | if (parg == NULL) | ||
| 1875 | { | ||
| 1876 | SSLerr(SSL_F_SSL3_CTRL, ERR_R_PASSED_NULL_PARAMETER); | ||
| 1877 | return(ret); | ||
| 1878 | } | ||
| 1879 | if (!EC_KEY_up_ref((EC_KEY *)parg)) | ||
| 1880 | { | ||
| 1881 | SSLerr(SSL_F_SSL3_CTRL,ERR_R_ECDH_LIB); | ||
| 1882 | return(ret); | ||
| 1883 | } | ||
| 1884 | ecdh = (EC_KEY *)parg; | ||
| 1885 | if (!(s->options & SSL_OP_SINGLE_ECDH_USE)) | ||
| 1886 | { | ||
| 1887 | if (!EC_KEY_generate_key(ecdh)) | ||
| 1888 | { | ||
| 1889 | EC_KEY_free(ecdh); | ||
| 1890 | SSLerr(SSL_F_SSL3_CTRL,ERR_R_ECDH_LIB); | ||
| 1891 | return(ret); | ||
| 1892 | } | ||
| 1893 | } | ||
| 1894 | if (s->cert->ecdh_tmp != NULL) | ||
| 1895 | EC_KEY_free(s->cert->ecdh_tmp); | ||
| 1896 | s->cert->ecdh_tmp = ecdh; | ||
| 1897 | ret = 1; | ||
| 1898 | } | ||
| 1899 | break; | ||
| 1900 | case SSL_CTRL_SET_TMP_ECDH_CB: | ||
| 1901 | { | ||
| 1902 | SSLerr(SSL_F_SSL3_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
| 1903 | return(ret); | ||
| 1904 | } | ||
| 1905 | break; | ||
| 1906 | #endif /* !OPENSSL_NO_ECDH */ | ||
| 1907 | #ifndef OPENSSL_NO_TLSEXT | ||
| 1908 | case SSL_CTRL_SET_TLSEXT_HOSTNAME: | ||
| 1909 | if (larg == TLSEXT_NAMETYPE_host_name) | ||
| 1910 | { | ||
| 1911 | if (s->tlsext_hostname != NULL) | ||
| 1912 | OPENSSL_free(s->tlsext_hostname); | ||
| 1913 | s->tlsext_hostname = NULL; | ||
| 1914 | |||
| 1915 | ret = 1; | ||
| 1916 | if (parg == NULL) | ||
| 1917 | break; | ||
| 1918 | if (strlen((char *)parg) > TLSEXT_MAXLEN_host_name) | ||
| 1919 | { | ||
| 1920 | SSLerr(SSL_F_SSL3_CTRL, SSL_R_SSL3_EXT_INVALID_SERVERNAME); | ||
| 1921 | return 0; | ||
| 1922 | } | ||
| 1923 | if ((s->tlsext_hostname = BUF_strdup((char *)parg)) == NULL) | ||
| 1924 | { | ||
| 1925 | SSLerr(SSL_F_SSL3_CTRL, ERR_R_INTERNAL_ERROR); | ||
| 1926 | return 0; | ||
| 1927 | } | ||
| 1928 | } | ||
| 1929 | else | ||
| 1930 | { | ||
| 1931 | SSLerr(SSL_F_SSL3_CTRL, SSL_R_SSL3_EXT_INVALID_SERVERNAME_TYPE); | ||
| 1932 | return 0; | ||
| 1933 | } | ||
| 1934 | break; | ||
| 1935 | case SSL_CTRL_SET_TLSEXT_DEBUG_ARG: | ||
| 1936 | s->tlsext_debug_arg=parg; | ||
| 1937 | ret = 1; | ||
| 1938 | break; | ||
| 1939 | |||
| 1940 | case SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE: | ||
| 1941 | s->tlsext_status_type=larg; | ||
| 1942 | ret = 1; | ||
| 1943 | break; | ||
| 1944 | |||
| 1945 | case SSL_CTRL_GET_TLSEXT_STATUS_REQ_EXTS: | ||
| 1946 | *(STACK_OF(X509_EXTENSION) **)parg = s->tlsext_ocsp_exts; | ||
| 1947 | ret = 1; | ||
| 1948 | break; | ||
| 1949 | |||
| 1950 | case SSL_CTRL_SET_TLSEXT_STATUS_REQ_EXTS: | ||
| 1951 | s->tlsext_ocsp_exts = parg; | ||
| 1952 | ret = 1; | ||
| 1953 | break; | ||
| 1954 | |||
| 1955 | case SSL_CTRL_GET_TLSEXT_STATUS_REQ_IDS: | ||
| 1956 | *(STACK_OF(OCSP_RESPID) **)parg = s->tlsext_ocsp_ids; | ||
| 1957 | ret = 1; | ||
| 1958 | break; | ||
| 1959 | |||
| 1960 | case SSL_CTRL_SET_TLSEXT_STATUS_REQ_IDS: | ||
| 1961 | s->tlsext_ocsp_ids = parg; | ||
| 1962 | ret = 1; | ||
| 1963 | break; | ||
| 1964 | |||
| 1965 | case SSL_CTRL_GET_TLSEXT_STATUS_REQ_OCSP_RESP: | ||
| 1966 | *(unsigned char **)parg = s->tlsext_ocsp_resp; | ||
| 1967 | return s->tlsext_ocsp_resplen; | ||
| 1968 | |||
| 1969 | case SSL_CTRL_SET_TLSEXT_STATUS_REQ_OCSP_RESP: | ||
| 1970 | if (s->tlsext_ocsp_resp) | ||
| 1971 | OPENSSL_free(s->tlsext_ocsp_resp); | ||
| 1972 | s->tlsext_ocsp_resp = parg; | ||
| 1973 | s->tlsext_ocsp_resplen = larg; | ||
| 1974 | ret = 1; | ||
| 1975 | break; | ||
| 1976 | |||
| 1977 | #endif /* !OPENSSL_NO_TLSEXT */ | ||
| 1266 | default: | 1978 | default: |
| 1267 | break; | 1979 | break; |
| 1268 | } | 1980 | } |
| 1269 | return(ret); | 1981 | return(ret); |
| 1270 | } | 1982 | } |
| 1271 | 1983 | ||
| 1272 | long ssl3_callback_ctrl(SSL *s, int cmd, void (*fp)()) | 1984 | long ssl3_callback_ctrl(SSL *s, int cmd, void (*fp)(void)) |
| 1273 | { | 1985 | { |
| 1274 | int ret=0; | 1986 | int ret=0; |
| 1275 | 1987 | ||
| @@ -1307,6 +2019,19 @@ long ssl3_callback_ctrl(SSL *s, int cmd, void (*fp)()) | |||
| 1307 | } | 2019 | } |
| 1308 | break; | 2020 | break; |
| 1309 | #endif | 2021 | #endif |
| 2022 | #ifndef OPENSSL_NO_ECDH | ||
| 2023 | case SSL_CTRL_SET_TMP_ECDH_CB: | ||
| 2024 | { | ||
| 2025 | s->cert->ecdh_tmp_cb = (EC_KEY *(*)(SSL *, int, int))fp; | ||
| 2026 | } | ||
| 2027 | break; | ||
| 2028 | #endif | ||
| 2029 | #ifndef OPENSSL_NO_TLSEXT | ||
| 2030 | case SSL_CTRL_SET_TLSEXT_DEBUG_CB: | ||
| 2031 | s->tlsext_debug_cb=(void (*)(SSL *,int ,int, | ||
| 2032 | unsigned char *, int, void *))fp; | ||
| 2033 | break; | ||
| 2034 | #endif | ||
| 1310 | default: | 2035 | default: |
| 1311 | break; | 2036 | break; |
| 1312 | } | 2037 | } |
| @@ -1399,6 +2124,83 @@ long ssl3_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg) | |||
| 1399 | } | 2124 | } |
| 1400 | break; | 2125 | break; |
| 1401 | #endif | 2126 | #endif |
| 2127 | #ifndef OPENSSL_NO_ECDH | ||
| 2128 | case SSL_CTRL_SET_TMP_ECDH: | ||
| 2129 | { | ||
| 2130 | EC_KEY *ecdh = NULL; | ||
| 2131 | |||
| 2132 | if (parg == NULL) | ||
| 2133 | { | ||
| 2134 | SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_ECDH_LIB); | ||
| 2135 | return 0; | ||
| 2136 | } | ||
| 2137 | ecdh = EC_KEY_dup((EC_KEY *)parg); | ||
| 2138 | if (ecdh == NULL) | ||
| 2139 | { | ||
| 2140 | SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_EC_LIB); | ||
| 2141 | return 0; | ||
| 2142 | } | ||
| 2143 | if (!(ctx->options & SSL_OP_SINGLE_ECDH_USE)) | ||
| 2144 | { | ||
| 2145 | if (!EC_KEY_generate_key(ecdh)) | ||
| 2146 | { | ||
| 2147 | EC_KEY_free(ecdh); | ||
| 2148 | SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_ECDH_LIB); | ||
| 2149 | return 0; | ||
| 2150 | } | ||
| 2151 | } | ||
| 2152 | |||
| 2153 | if (cert->ecdh_tmp != NULL) | ||
| 2154 | { | ||
| 2155 | EC_KEY_free(cert->ecdh_tmp); | ||
| 2156 | } | ||
| 2157 | cert->ecdh_tmp = ecdh; | ||
| 2158 | return 1; | ||
| 2159 | } | ||
| 2160 | /* break; */ | ||
| 2161 | case SSL_CTRL_SET_TMP_ECDH_CB: | ||
| 2162 | { | ||
| 2163 | SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
| 2164 | return(0); | ||
| 2165 | } | ||
| 2166 | break; | ||
| 2167 | #endif /* !OPENSSL_NO_ECDH */ | ||
| 2168 | #ifndef OPENSSL_NO_TLSEXT | ||
| 2169 | case SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG: | ||
| 2170 | ctx->tlsext_servername_arg=parg; | ||
| 2171 | break; | ||
| 2172 | case SSL_CTRL_SET_TLSEXT_TICKET_KEYS: | ||
| 2173 | case SSL_CTRL_GET_TLSEXT_TICKET_KEYS: | ||
| 2174 | { | ||
| 2175 | unsigned char *keys = parg; | ||
| 2176 | if (!keys) | ||
| 2177 | return 48; | ||
| 2178 | if (larg != 48) | ||
| 2179 | { | ||
| 2180 | SSLerr(SSL_F_SSL3_CTX_CTRL, SSL_R_INVALID_TICKET_KEYS_LENGTH); | ||
| 2181 | return 0; | ||
| 2182 | } | ||
| 2183 | if (cmd == SSL_CTRL_SET_TLSEXT_TICKET_KEYS) | ||
| 2184 | { | ||
| 2185 | memcpy(ctx->tlsext_tick_key_name, keys, 16); | ||
| 2186 | memcpy(ctx->tlsext_tick_hmac_key, keys + 16, 16); | ||
| 2187 | memcpy(ctx->tlsext_tick_aes_key, keys + 32, 16); | ||
| 2188 | } | ||
| 2189 | else | ||
| 2190 | { | ||
| 2191 | memcpy(keys, ctx->tlsext_tick_key_name, 16); | ||
| 2192 | memcpy(keys + 16, ctx->tlsext_tick_hmac_key, 16); | ||
| 2193 | memcpy(keys + 32, ctx->tlsext_tick_aes_key, 16); | ||
| 2194 | } | ||
| 2195 | return 1; | ||
| 2196 | } | ||
| 2197 | |||
| 2198 | case SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG: | ||
| 2199 | ctx->tlsext_status_arg=parg; | ||
| 2200 | return 1; | ||
| 2201 | break; | ||
| 2202 | |||
| 2203 | #endif /* !OPENSSL_NO_TLSEXT */ | ||
| 1402 | /* A Thawte special :-) */ | 2204 | /* A Thawte special :-) */ |
| 1403 | case SSL_CTRL_EXTRA_CHAIN_CERT: | 2205 | case SSL_CTRL_EXTRA_CHAIN_CERT: |
| 1404 | if (ctx->extra_certs == NULL) | 2206 | if (ctx->extra_certs == NULL) |
| @@ -1415,7 +2217,7 @@ long ssl3_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg) | |||
| 1415 | return(1); | 2217 | return(1); |
| 1416 | } | 2218 | } |
| 1417 | 2219 | ||
| 1418 | long ssl3_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)()) | 2220 | long ssl3_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)(void)) |
| 1419 | { | 2221 | { |
| 1420 | CERT *cert; | 2222 | CERT *cert; |
| 1421 | 2223 | ||
| @@ -1437,6 +2239,30 @@ long ssl3_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)()) | |||
| 1437 | } | 2239 | } |
| 1438 | break; | 2240 | break; |
| 1439 | #endif | 2241 | #endif |
| 2242 | #ifndef OPENSSL_NO_ECDH | ||
| 2243 | case SSL_CTRL_SET_TMP_ECDH_CB: | ||
| 2244 | { | ||
| 2245 | cert->ecdh_tmp_cb = (EC_KEY *(*)(SSL *, int, int))fp; | ||
| 2246 | } | ||
| 2247 | break; | ||
| 2248 | #endif | ||
| 2249 | #ifndef OPENSSL_NO_TLSEXT | ||
| 2250 | case SSL_CTRL_SET_TLSEXT_SERVERNAME_CB: | ||
| 2251 | ctx->tlsext_servername_callback=(int (*)(SSL *,int *,void *))fp; | ||
| 2252 | break; | ||
| 2253 | |||
| 2254 | case SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB: | ||
| 2255 | ctx->tlsext_status_cb=(int (*)(SSL *,void *))fp; | ||
| 2256 | break; | ||
| 2257 | |||
| 2258 | case SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB: | ||
| 2259 | ctx->tlsext_ticket_key_cb=(int (*)(SSL *,unsigned char *, | ||
| 2260 | unsigned char *, | ||
| 2261 | EVP_CIPHER_CTX *, | ||
| 2262 | HMAC_CTX *, int))fp; | ||
| 2263 | break; | ||
| 2264 | |||
| 2265 | #endif | ||
| 1440 | default: | 2266 | default: |
| 1441 | return(0); | 2267 | return(0); |
| 1442 | } | 2268 | } |
| @@ -1447,41 +2273,19 @@ long ssl3_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)()) | |||
| 1447 | * available */ | 2273 | * available */ |
| 1448 | SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p) | 2274 | SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p) |
| 1449 | { | 2275 | { |
| 1450 | static int init=1; | 2276 | SSL_CIPHER c,*cp; |
| 1451 | static SSL_CIPHER *sorted[SSL3_NUM_CIPHERS]; | ||
| 1452 | SSL_CIPHER c,*cp= &c,**cpp; | ||
| 1453 | unsigned long id; | 2277 | unsigned long id; |
| 1454 | int i; | ||
| 1455 | |||
| 1456 | if (init) | ||
| 1457 | { | ||
| 1458 | CRYPTO_w_lock(CRYPTO_LOCK_SSL); | ||
| 1459 | |||
| 1460 | if (init) | ||
| 1461 | { | ||
| 1462 | for (i=0; i<SSL3_NUM_CIPHERS; i++) | ||
| 1463 | sorted[i]= &(ssl3_ciphers[i]); | ||
| 1464 | |||
| 1465 | qsort(sorted, | ||
| 1466 | SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER *), | ||
| 1467 | FP_ICC ssl_cipher_ptr_id_cmp); | ||
| 1468 | |||
| 1469 | init=0; | ||
| 1470 | } | ||
| 1471 | |||
| 1472 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL); | ||
| 1473 | } | ||
| 1474 | 2278 | ||
| 1475 | id=0x03000000L|((unsigned long)p[0]<<8L)|(unsigned long)p[1]; | 2279 | id=0x03000000L|((unsigned long)p[0]<<8L)|(unsigned long)p[1]; |
| 1476 | c.id=id; | 2280 | c.id=id; |
| 1477 | cpp=(SSL_CIPHER **)OBJ_bsearch((char *)&cp, | 2281 | cp = (SSL_CIPHER *)OBJ_bsearch((char *)&c, |
| 1478 | (char *)sorted, | 2282 | (char *)ssl3_ciphers, |
| 1479 | SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER *), | 2283 | SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER), |
| 1480 | FP_ICC ssl_cipher_ptr_id_cmp); | 2284 | FP_ICC ssl_cipher_id_cmp); |
| 1481 | if ((cpp == NULL) || !(*cpp)->valid) | 2285 | if (cp == NULL || cp->valid == 0) |
| 1482 | return(NULL); | 2286 | return NULL; |
| 1483 | else | 2287 | else |
| 1484 | return(*cpp); | 2288 | return cp; |
| 1485 | } | 2289 | } |
| 1486 | 2290 | ||
| 1487 | int ssl3_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p) | 2291 | int ssl3_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p) |
| @@ -1504,6 +2308,7 @@ SSL_CIPHER *ssl3_choose_cipher(SSL *s, STACK_OF(SSL_CIPHER) *clnt, | |||
| 1504 | SSL_CIPHER *c,*ret=NULL; | 2308 | SSL_CIPHER *c,*ret=NULL; |
| 1505 | STACK_OF(SSL_CIPHER) *prio, *allow; | 2309 | STACK_OF(SSL_CIPHER) *prio, *allow; |
| 1506 | int i,j,ok; | 2310 | int i,j,ok; |
| 2311 | |||
| 1507 | CERT *cert; | 2312 | CERT *cert; |
| 1508 | unsigned long alg,mask,emask; | 2313 | unsigned long alg,mask,emask; |
| 1509 | 2314 | ||
| @@ -1584,7 +2389,6 @@ SSL_CIPHER *ssl3_choose_cipher(SSL *s, STACK_OF(SSL_CIPHER) *clnt, | |||
| 1584 | } | 2389 | } |
| 1585 | 2390 | ||
| 1586 | if (!ok) continue; | 2391 | if (!ok) continue; |
| 1587 | |||
| 1588 | j=sk_SSL_CIPHER_find(allow,c); | 2392 | j=sk_SSL_CIPHER_find(allow,c); |
| 1589 | if (j >= 0) | 2393 | if (j >= 0) |
| 1590 | { | 2394 | { |
| @@ -1629,6 +2433,26 @@ int ssl3_get_req_cert_type(SSL *s, unsigned char *p) | |||
| 1629 | #ifndef OPENSSL_NO_DSA | 2433 | #ifndef OPENSSL_NO_DSA |
| 1630 | p[ret++]=SSL3_CT_DSS_SIGN; | 2434 | p[ret++]=SSL3_CT_DSS_SIGN; |
| 1631 | #endif | 2435 | #endif |
| 2436 | #ifndef OPENSSL_NO_ECDH | ||
| 2437 | /* We should ask for fixed ECDH certificates only | ||
| 2438 | * for SSL_kECDH (and not SSL_kECDHE) | ||
| 2439 | */ | ||
| 2440 | if ((alg & SSL_kECDH) && (s->version >= TLS1_VERSION)) | ||
| 2441 | { | ||
| 2442 | p[ret++]=TLS_CT_RSA_FIXED_ECDH; | ||
| 2443 | p[ret++]=TLS_CT_ECDSA_FIXED_ECDH; | ||
| 2444 | } | ||
| 2445 | #endif | ||
| 2446 | |||
| 2447 | #ifndef OPENSSL_NO_ECDSA | ||
| 2448 | /* ECDSA certs can be used with RSA cipher suites as well | ||
| 2449 | * so we don't need to check for SSL_kECDH or SSL_kECDHE | ||
| 2450 | */ | ||
| 2451 | if (s->version >= TLS1_VERSION) | ||
| 2452 | { | ||
| 2453 | p[ret++]=TLS_CT_ECDSA_SIGN; | ||
| 2454 | } | ||
| 2455 | #endif | ||
| 1632 | return(ret); | 2456 | return(ret); |
| 1633 | } | 2457 | } |
| 1634 | 2458 | ||
| @@ -1656,13 +2480,13 @@ int ssl3_shutdown(SSL *s) | |||
| 1656 | { | 2480 | { |
| 1657 | /* resend it if not sent */ | 2481 | /* resend it if not sent */ |
| 1658 | #if 1 | 2482 | #if 1 |
| 1659 | ssl3_dispatch_alert(s); | 2483 | s->method->ssl_dispatch_alert(s); |
| 1660 | #endif | 2484 | #endif |
| 1661 | } | 2485 | } |
| 1662 | else if (!(s->shutdown & SSL_RECEIVED_SHUTDOWN)) | 2486 | else if (!(s->shutdown & SSL_RECEIVED_SHUTDOWN)) |
| 1663 | { | 2487 | { |
| 1664 | /* If we are waiting for a close from our peer, we are closed */ | 2488 | /* If we are waiting for a close from our peer, we are closed */ |
| 1665 | ssl3_read_bytes(s,0,NULL,0,0); | 2489 | s->method->ssl_read_bytes(s,0,NULL,0,0); |
| 1666 | } | 2490 | } |
| 1667 | 2491 | ||
| 1668 | if ((s->shutdown == (SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN)) && | 2492 | if ((s->shutdown == (SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN)) && |
| @@ -1717,8 +2541,8 @@ int ssl3_write(SSL *s, const void *buf, int len) | |||
| 1717 | } | 2541 | } |
| 1718 | else | 2542 | else |
| 1719 | { | 2543 | { |
| 1720 | ret=ssl3_write_bytes(s,SSL3_RT_APPLICATION_DATA, | 2544 | ret=s->method->ssl_write_bytes(s,SSL3_RT_APPLICATION_DATA, |
| 1721 | buf,len); | 2545 | buf,len); |
| 1722 | if (ret <= 0) return(ret); | 2546 | if (ret <= 0) return(ret); |
| 1723 | } | 2547 | } |
| 1724 | 2548 | ||
| @@ -1732,7 +2556,7 @@ static int ssl3_read_internal(SSL *s, void *buf, int len, int peek) | |||
| 1732 | clear_sys_error(); | 2556 | clear_sys_error(); |
| 1733 | if (s->s3->renegotiate) ssl3_renegotiate_check(s); | 2557 | if (s->s3->renegotiate) ssl3_renegotiate_check(s); |
| 1734 | s->s3->in_read_app_data=1; | 2558 | s->s3->in_read_app_data=1; |
| 1735 | ret=ssl3_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len,peek); | 2559 | ret=s->method->ssl_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len,peek); |
| 1736 | if ((ret == -1) && (s->s3->in_read_app_data == 2)) | 2560 | if ((ret == -1) && (s->s3->in_read_app_data == 2)) |
| 1737 | { | 2561 | { |
| 1738 | /* ssl3_read_bytes decided to call s->handshake_func, which | 2562 | /* ssl3_read_bytes decided to call s->handshake_func, which |
| @@ -1741,7 +2565,7 @@ static int ssl3_read_internal(SSL *s, void *buf, int len, int peek) | |||
| 1741 | * and thinks that application data makes sense here; so disable | 2565 | * and thinks that application data makes sense here; so disable |
| 1742 | * handshake processing and try to read application data again. */ | 2566 | * handshake processing and try to read application data again. */ |
| 1743 | s->in_handshake++; | 2567 | s->in_handshake++; |
| 1744 | ret=ssl3_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len,peek); | 2568 | ret=s->method->ssl_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len,peek); |
| 1745 | s->in_handshake--; | 2569 | s->in_handshake--; |
| 1746 | } | 2570 | } |
| 1747 | else | 2571 | else |
diff --git a/src/lib/libssl/s3_pkt.c b/src/lib/libssl/s3_pkt.c index cb0b12b400..44c7c143fe 100644 --- a/src/lib/libssl/s3_pkt.c +++ b/src/lib/libssl/s3_pkt.c | |||
| @@ -118,15 +118,9 @@ | |||
| 118 | 118 | ||
| 119 | static int do_ssl3_write(SSL *s, int type, const unsigned char *buf, | 119 | static int do_ssl3_write(SSL *s, int type, const unsigned char *buf, |
| 120 | unsigned int len, int create_empty_fragment); | 120 | unsigned int len, int create_empty_fragment); |
| 121 | static int ssl3_write_pending(SSL *s, int type, const unsigned char *buf, | ||
| 122 | unsigned int len); | ||
| 123 | static int ssl3_get_record(SSL *s); | 121 | static int ssl3_get_record(SSL *s); |
| 124 | static int do_compress(SSL *ssl); | ||
| 125 | static int do_uncompress(SSL *ssl); | ||
| 126 | static int do_change_cipher_spec(SSL *ssl); | ||
| 127 | 122 | ||
| 128 | /* used only by ssl3_get_record */ | 123 | int ssl3_read_n(SSL *s, int n, int max, int extend) |
| 129 | static int ssl3_read_n(SSL *s, int n, int max, int extend) | ||
| 130 | { | 124 | { |
| 131 | /* If extend == 0, obtain new n-byte packet; if extend == 1, increase | 125 | /* If extend == 0, obtain new n-byte packet; if extend == 1, increase |
| 132 | * packet by another n bytes. | 126 | * packet by another n bytes. |
| @@ -147,6 +141,14 @@ static int ssl3_read_n(SSL *s, int n, int max, int extend) | |||
| 147 | /* ... now we can act as if 'extend' was set */ | 141 | /* ... now we can act as if 'extend' was set */ |
| 148 | } | 142 | } |
| 149 | 143 | ||
| 144 | /* extend reads should not span multiple packets for DTLS */ | ||
| 145 | if ( SSL_version(s) == DTLS1_VERSION && | ||
| 146 | extend) | ||
| 147 | { | ||
| 148 | if ( s->s3->rbuf.left > 0 && n > s->s3->rbuf.left) | ||
| 149 | n = s->s3->rbuf.left; | ||
| 150 | } | ||
| 151 | |||
| 150 | /* if there is enough in the buffer from a previous read, take some */ | 152 | /* if there is enough in the buffer from a previous read, take some */ |
| 151 | if (s->s3->rbuf.left >= (int)n) | 153 | if (s->s3->rbuf.left >= (int)n) |
| 152 | { | 154 | { |
| @@ -275,11 +277,7 @@ again: | |||
| 275 | n2s(p,rr->length); | 277 | n2s(p,rr->length); |
| 276 | 278 | ||
| 277 | /* Lets check version */ | 279 | /* Lets check version */ |
| 278 | if (s->first_packet) | 280 | if (!s->first_packet) |
| 279 | { | ||
| 280 | s->first_packet=0; | ||
| 281 | } | ||
| 282 | else | ||
| 283 | { | 281 | { |
| 284 | if (version != s->version) | 282 | if (version != s->version) |
| 285 | { | 283 | { |
| @@ -434,7 +432,7 @@ printf("\n"); | |||
| 434 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_COMPRESSED_LENGTH_TOO_LONG); | 432 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_COMPRESSED_LENGTH_TOO_LONG); |
| 435 | goto f_err; | 433 | goto f_err; |
| 436 | } | 434 | } |
| 437 | if (!do_uncompress(s)) | 435 | if (!ssl3_do_uncompress(s)) |
| 438 | { | 436 | { |
| 439 | al=SSL_AD_DECOMPRESSION_FAILURE; | 437 | al=SSL_AD_DECOMPRESSION_FAILURE; |
| 440 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_BAD_DECOMPRESSION); | 438 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_BAD_DECOMPRESSION); |
| @@ -472,8 +470,9 @@ err: | |||
| 472 | return(ret); | 470 | return(ret); |
| 473 | } | 471 | } |
| 474 | 472 | ||
| 475 | static int do_uncompress(SSL *ssl) | 473 | int ssl3_do_uncompress(SSL *ssl) |
| 476 | { | 474 | { |
| 475 | #ifndef OPENSSL_NO_COMP | ||
| 477 | int i; | 476 | int i; |
| 478 | SSL3_RECORD *rr; | 477 | SSL3_RECORD *rr; |
| 479 | 478 | ||
| @@ -485,12 +484,13 @@ static int do_uncompress(SSL *ssl) | |||
| 485 | else | 484 | else |
| 486 | rr->length=i; | 485 | rr->length=i; |
| 487 | rr->data=rr->comp; | 486 | rr->data=rr->comp; |
| 488 | 487 | #endif | |
| 489 | return(1); | 488 | return(1); |
| 490 | } | 489 | } |
| 491 | 490 | ||
| 492 | static int do_compress(SSL *ssl) | 491 | int ssl3_do_compress(SSL *ssl) |
| 493 | { | 492 | { |
| 493 | #ifndef OPENSSL_NO_COMP | ||
| 494 | int i; | 494 | int i; |
| 495 | SSL3_RECORD *wr; | 495 | SSL3_RECORD *wr; |
| 496 | 496 | ||
| @@ -504,6 +504,7 @@ static int do_compress(SSL *ssl) | |||
| 504 | wr->length=i; | 504 | wr->length=i; |
| 505 | 505 | ||
| 506 | wr->input=wr->data; | 506 | wr->input=wr->data; |
| 507 | #endif | ||
| 507 | return(1); | 508 | return(1); |
| 508 | } | 509 | } |
| 509 | 510 | ||
| @@ -580,7 +581,7 @@ static int do_ssl3_write(SSL *s, int type, const unsigned char *buf, | |||
| 580 | /* If we have an alert to send, lets send it */ | 581 | /* If we have an alert to send, lets send it */ |
| 581 | if (s->s3->alert_dispatch) | 582 | if (s->s3->alert_dispatch) |
| 582 | { | 583 | { |
| 583 | i=ssl3_dispatch_alert(s); | 584 | i=s->method->ssl_dispatch_alert(s); |
| 584 | if (i <= 0) | 585 | if (i <= 0) |
| 585 | return(i); | 586 | return(i); |
| 586 | /* if it went, fall through and send more stuff */ | 587 | /* if it went, fall through and send more stuff */ |
| @@ -655,7 +656,7 @@ static int do_ssl3_write(SSL *s, int type, const unsigned char *buf, | |||
| 655 | /* first we compress */ | 656 | /* first we compress */ |
| 656 | if (s->compress != NULL) | 657 | if (s->compress != NULL) |
| 657 | { | 658 | { |
| 658 | if (!do_compress(s)) | 659 | if (!ssl3_do_compress(s)) |
| 659 | { | 660 | { |
| 660 | SSLerr(SSL_F_DO_SSL3_WRITE,SSL_R_COMPRESSION_FAILURE); | 661 | SSLerr(SSL_F_DO_SSL3_WRITE,SSL_R_COMPRESSION_FAILURE); |
| 661 | goto err; | 662 | goto err; |
| @@ -716,8 +717,8 @@ err: | |||
| 716 | } | 717 | } |
| 717 | 718 | ||
| 718 | /* if s->s3->wbuf.left != 0, we need to call this */ | 719 | /* if s->s3->wbuf.left != 0, we need to call this */ |
| 719 | static int ssl3_write_pending(SSL *s, int type, const unsigned char *buf, | 720 | int ssl3_write_pending(SSL *s, int type, const unsigned char *buf, |
| 720 | unsigned int len) | 721 | unsigned int len) |
| 721 | { | 722 | { |
| 722 | int i; | 723 | int i; |
| 723 | 724 | ||
| @@ -1089,7 +1090,7 @@ start: | |||
| 1089 | if (s->s3->tmp.new_cipher == NULL) | 1090 | if (s->s3->tmp.new_cipher == NULL) |
| 1090 | { | 1091 | { |
| 1091 | al=SSL_AD_UNEXPECTED_MESSAGE; | 1092 | al=SSL_AD_UNEXPECTED_MESSAGE; |
| 1092 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_CCS_RECEIVED_EARLY); | 1093 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_CCS_RECEIVED_EARLY); |
| 1093 | goto f_err; | 1094 | goto f_err; |
| 1094 | } | 1095 | } |
| 1095 | 1096 | ||
| @@ -1099,7 +1100,7 @@ start: | |||
| 1099 | s->msg_callback(0, s->version, SSL3_RT_CHANGE_CIPHER_SPEC, rr->data, 1, s, s->msg_callback_arg); | 1100 | s->msg_callback(0, s->version, SSL3_RT_CHANGE_CIPHER_SPEC, rr->data, 1, s, s->msg_callback_arg); |
| 1100 | 1101 | ||
| 1101 | s->s3->change_cipher_spec=1; | 1102 | s->s3->change_cipher_spec=1; |
| 1102 | if (!do_change_cipher_spec(s)) | 1103 | if (!ssl3_do_change_cipher_spec(s)) |
| 1103 | goto err; | 1104 | goto err; |
| 1104 | else | 1105 | else |
| 1105 | goto start; | 1106 | goto start; |
| @@ -1211,7 +1212,7 @@ err: | |||
| 1211 | return(-1); | 1212 | return(-1); |
| 1212 | } | 1213 | } |
| 1213 | 1214 | ||
| 1214 | static int do_change_cipher_spec(SSL *s) | 1215 | int ssl3_do_change_cipher_spec(SSL *s) |
| 1215 | { | 1216 | { |
| 1216 | int i; | 1217 | int i; |
| 1217 | const char *sender; | 1218 | const char *sender; |
| @@ -1268,7 +1269,7 @@ void ssl3_send_alert(SSL *s, int level, int desc) | |||
| 1268 | s->s3->send_alert[0]=level; | 1269 | s->s3->send_alert[0]=level; |
| 1269 | s->s3->send_alert[1]=desc; | 1270 | s->s3->send_alert[1]=desc; |
| 1270 | if (s->s3->wbuf.left == 0) /* data still being written out? */ | 1271 | if (s->s3->wbuf.left == 0) /* data still being written out? */ |
| 1271 | ssl3_dispatch_alert(s); | 1272 | s->method->ssl_dispatch_alert(s); |
| 1272 | /* else data is still being written out, we will get written | 1273 | /* else data is still being written out, we will get written |
| 1273 | * some time in the future */ | 1274 | * some time in the future */ |
| 1274 | } | 1275 | } |
diff --git a/src/lib/libssl/s3_srvr.c b/src/lib/libssl/s3_srvr.c index 36fc39d7f8..903522ab59 100644 --- a/src/lib/libssl/s3_srvr.c +++ b/src/lib/libssl/s3_srvr.c | |||
| @@ -56,7 +56,7 @@ | |||
| 56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
| 57 | */ | 57 | */ |
| 58 | /* ==================================================================== | 58 | /* ==================================================================== |
| 59 | * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. | 59 | * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved. |
| 60 | * | 60 | * |
| 61 | * Redistribution and use in source and binary forms, with or without | 61 | * Redistribution and use in source and binary forms, with or without |
| 62 | * modification, are permitted provided that the following conditions | 62 | * modification, are permitted provided that the following conditions |
| @@ -108,11 +108,23 @@ | |||
| 108 | * Hudson (tjh@cryptsoft.com). | 108 | * Hudson (tjh@cryptsoft.com). |
| 109 | * | 109 | * |
| 110 | */ | 110 | */ |
| 111 | /* ==================================================================== | ||
| 112 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
| 113 | * | ||
| 114 | * Portions of the attached software ("Contribution") are developed by | ||
| 115 | * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. | ||
| 116 | * | ||
| 117 | * The Contribution is licensed pursuant to the OpenSSL open source | ||
| 118 | * license provided above. | ||
| 119 | * | ||
| 120 | * ECC cipher suite support in OpenSSL originally written by | ||
| 121 | * Vipul Gupta and Sumit Gupta of Sun Microsystems Laboratories. | ||
| 122 | * | ||
| 123 | */ | ||
| 111 | 124 | ||
| 112 | #define REUSE_CIPHER_BUG | 125 | #define REUSE_CIPHER_BUG |
| 113 | #define NETSCAPE_HANG_BUG | 126 | #define NETSCAPE_HANG_BUG |
| 114 | 127 | ||
| 115 | |||
| 116 | #include <stdio.h> | 128 | #include <stdio.h> |
| 117 | #include "ssl_locl.h" | 129 | #include "ssl_locl.h" |
| 118 | #include "kssl_lcl.h" | 130 | #include "kssl_lcl.h" |
| @@ -120,24 +132,21 @@ | |||
| 120 | #include <openssl/rand.h> | 132 | #include <openssl/rand.h> |
| 121 | #include <openssl/objects.h> | 133 | #include <openssl/objects.h> |
| 122 | #include <openssl/evp.h> | 134 | #include <openssl/evp.h> |
| 135 | #include <openssl/hmac.h> | ||
| 123 | #include <openssl/x509.h> | 136 | #include <openssl/x509.h> |
| 137 | #ifndef OPENSSL_NO_DH | ||
| 138 | #include <openssl/dh.h> | ||
| 139 | #endif | ||
| 140 | #include <openssl/bn.h> | ||
| 124 | #ifndef OPENSSL_NO_KRB5 | 141 | #ifndef OPENSSL_NO_KRB5 |
| 125 | #include <openssl/krb5_asn.h> | 142 | #include <openssl/krb5_asn.h> |
| 126 | #endif | 143 | #endif |
| 127 | #include <openssl/md5.h> | 144 | #include <openssl/md5.h> |
| 128 | #include <openssl/fips.h> | ||
| 129 | 145 | ||
| 130 | static SSL_METHOD *ssl3_get_server_method(int ver); | 146 | static SSL_METHOD *ssl3_get_server_method(int ver); |
| 131 | static int ssl3_get_client_hello(SSL *s); | 147 | #ifndef OPENSSL_NO_ECDH |
| 132 | static int ssl3_check_client_hello(SSL *s); | 148 | static int nid2curve_id(int nid); |
| 133 | static int ssl3_send_server_hello(SSL *s); | 149 | #endif |
| 134 | static int ssl3_send_server_key_exchange(SSL *s); | ||
| 135 | static int ssl3_send_certificate_request(SSL *s); | ||
| 136 | static int ssl3_send_server_done(SSL *s); | ||
| 137 | static int ssl3_get_client_key_exchange(SSL *s); | ||
| 138 | static int ssl3_get_client_certificate(SSL *s); | ||
| 139 | static int ssl3_get_cert_verify(SSL *s); | ||
| 140 | static int ssl3_send_hello_request(SSL *s); | ||
| 141 | 150 | ||
| 142 | static SSL_METHOD *ssl3_get_server_method(int ver) | 151 | static SSL_METHOD *ssl3_get_server_method(int ver) |
| 143 | { | 152 | { |
| @@ -147,28 +156,10 @@ static SSL_METHOD *ssl3_get_server_method(int ver) | |||
| 147 | return(NULL); | 156 | return(NULL); |
| 148 | } | 157 | } |
| 149 | 158 | ||
| 150 | SSL_METHOD *SSLv3_server_method(void) | 159 | IMPLEMENT_ssl3_meth_func(SSLv3_server_method, |
| 151 | { | 160 | ssl3_accept, |
| 152 | static int init=1; | 161 | ssl_undefined_function, |
| 153 | static SSL_METHOD SSLv3_server_data; | 162 | ssl3_get_server_method) |
| 154 | |||
| 155 | if (init) | ||
| 156 | { | ||
| 157 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD); | ||
| 158 | |||
| 159 | if (init) | ||
| 160 | { | ||
| 161 | memcpy((char *)&SSLv3_server_data,(char *)sslv3_base_method(), | ||
| 162 | sizeof(SSL_METHOD)); | ||
| 163 | SSLv3_server_data.ssl_accept=ssl3_accept; | ||
| 164 | SSLv3_server_data.get_ssl_method=ssl3_get_server_method; | ||
| 165 | init=0; | ||
| 166 | } | ||
| 167 | |||
| 168 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD); | ||
| 169 | } | ||
| 170 | return(&SSLv3_server_data); | ||
| 171 | } | ||
| 172 | 163 | ||
| 173 | int ssl3_accept(SSL *s) | 164 | int ssl3_accept(SSL *s) |
| 174 | { | 165 | { |
| @@ -299,9 +290,18 @@ int ssl3_accept(SSL *s) | |||
| 299 | case SSL3_ST_SW_SRVR_HELLO_B: | 290 | case SSL3_ST_SW_SRVR_HELLO_B: |
| 300 | ret=ssl3_send_server_hello(s); | 291 | ret=ssl3_send_server_hello(s); |
| 301 | if (ret <= 0) goto end; | 292 | if (ret <= 0) goto end; |
| 302 | 293 | #ifndef OPENSSL_NO_TLSEXT | |
| 303 | if (s->hit) | 294 | if (s->hit) |
| 304 | s->state=SSL3_ST_SW_CHANGE_A; | 295 | { |
| 296 | if (s->tlsext_ticket_expected) | ||
| 297 | s->state=SSL3_ST_SW_SESSION_TICKET_A; | ||
| 298 | else | ||
| 299 | s->state=SSL3_ST_SW_CHANGE_A; | ||
| 300 | } | ||
| 301 | #else | ||
| 302 | if (s->hit) | ||
| 303 | s->state=SSL3_ST_SW_CHANGE_A; | ||
| 304 | #endif | ||
| 305 | else | 305 | else |
| 306 | s->state=SSL3_ST_SW_CERT_A; | 306 | s->state=SSL3_ST_SW_CERT_A; |
| 307 | s->init_num=0; | 307 | s->init_num=0; |
| @@ -309,15 +309,30 @@ int ssl3_accept(SSL *s) | |||
| 309 | 309 | ||
| 310 | case SSL3_ST_SW_CERT_A: | 310 | case SSL3_ST_SW_CERT_A: |
| 311 | case SSL3_ST_SW_CERT_B: | 311 | case SSL3_ST_SW_CERT_B: |
| 312 | /* Check if it is anon DH */ | 312 | /* Check if it is anon DH or anon ECDH or KRB5 */ |
| 313 | if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL)) | 313 | if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL) |
| 314 | && !(s->s3->tmp.new_cipher->algorithms & SSL_aKRB5)) | ||
| 314 | { | 315 | { |
| 315 | ret=ssl3_send_server_certificate(s); | 316 | ret=ssl3_send_server_certificate(s); |
| 316 | if (ret <= 0) goto end; | 317 | if (ret <= 0) goto end; |
| 318 | #ifndef OPENSSL_NO_TLSEXT | ||
| 319 | if (s->tlsext_status_expected) | ||
| 320 | s->state=SSL3_ST_SW_CERT_STATUS_A; | ||
| 321 | else | ||
| 322 | s->state=SSL3_ST_SW_KEY_EXCH_A; | ||
| 323 | } | ||
| 324 | else | ||
| 325 | { | ||
| 326 | skip = 1; | ||
| 327 | s->state=SSL3_ST_SW_KEY_EXCH_A; | ||
| 328 | } | ||
| 329 | #else | ||
| 317 | } | 330 | } |
| 318 | else | 331 | else |
| 319 | skip=1; | 332 | skip=1; |
| 333 | |||
| 320 | s->state=SSL3_ST_SW_KEY_EXCH_A; | 334 | s->state=SSL3_ST_SW_KEY_EXCH_A; |
| 335 | #endif | ||
| 321 | s->init_num=0; | 336 | s->init_num=0; |
| 322 | break; | 337 | break; |
| 323 | 338 | ||
| @@ -340,9 +355,18 @@ int ssl3_accept(SSL *s) | |||
| 340 | else | 355 | else |
| 341 | s->s3->tmp.use_rsa_tmp=0; | 356 | s->s3->tmp.use_rsa_tmp=0; |
| 342 | 357 | ||
| 358 | |||
| 343 | /* only send if a DH key exchange, fortezza or | 359 | /* only send if a DH key exchange, fortezza or |
| 344 | * RSA but we have a sign only certificate */ | 360 | * RSA but we have a sign only certificate |
| 361 | * | ||
| 362 | * For ECC ciphersuites, we send a serverKeyExchange | ||
| 363 | * message only if the cipher suite is either | ||
| 364 | * ECDH-anon or ECDHE. In other cases, the | ||
| 365 | * server certificate contains the server's | ||
| 366 | * public key for key exchange. | ||
| 367 | */ | ||
| 345 | if (s->s3->tmp.use_rsa_tmp | 368 | if (s->s3->tmp.use_rsa_tmp |
| 369 | || (l & SSL_kECDHE) | ||
| 346 | || (l & (SSL_DH|SSL_kFZA)) | 370 | || (l & (SSL_DH|SSL_kFZA)) |
| 347 | || ((l & SSL_kRSA) | 371 | || ((l & SSL_kRSA) |
| 348 | && (s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL | 372 | && (s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL |
| @@ -446,19 +470,33 @@ int ssl3_accept(SSL *s) | |||
| 446 | case SSL3_ST_SR_KEY_EXCH_A: | 470 | case SSL3_ST_SR_KEY_EXCH_A: |
| 447 | case SSL3_ST_SR_KEY_EXCH_B: | 471 | case SSL3_ST_SR_KEY_EXCH_B: |
| 448 | ret=ssl3_get_client_key_exchange(s); | 472 | ret=ssl3_get_client_key_exchange(s); |
| 449 | if (ret <= 0) goto end; | 473 | if (ret <= 0) |
| 450 | s->state=SSL3_ST_SR_CERT_VRFY_A; | 474 | goto end; |
| 451 | s->init_num=0; | 475 | if (ret == 2) |
| 452 | 476 | { | |
| 453 | /* We need to get hashes here so if there is | 477 | /* For the ECDH ciphersuites when |
| 454 | * a client cert, it can be verified */ | 478 | * the client sends its ECDH pub key in |
| 455 | s->method->ssl3_enc->cert_verify_mac(s, | 479 | * a certificate, the CertificateVerify |
| 456 | &(s->s3->finish_dgst1), | 480 | * message is not sent. |
| 457 | &(s->s3->tmp.cert_verify_md[0])); | 481 | */ |
| 458 | s->method->ssl3_enc->cert_verify_mac(s, | 482 | s->state=SSL3_ST_SR_FINISHED_A; |
| 459 | &(s->s3->finish_dgst2), | 483 | s->init_num = 0; |
| 460 | &(s->s3->tmp.cert_verify_md[MD5_DIGEST_LENGTH])); | 484 | } |
| 485 | else | ||
| 486 | { | ||
| 487 | s->state=SSL3_ST_SR_CERT_VRFY_A; | ||
| 488 | s->init_num=0; | ||
| 461 | 489 | ||
| 490 | /* We need to get hashes here so if there is | ||
| 491 | * a client cert, it can be verified | ||
| 492 | */ | ||
| 493 | s->method->ssl3_enc->cert_verify_mac(s, | ||
| 494 | &(s->s3->finish_dgst1), | ||
| 495 | &(s->s3->tmp.cert_verify_md[0])); | ||
| 496 | s->method->ssl3_enc->cert_verify_mac(s, | ||
| 497 | &(s->s3->finish_dgst2), | ||
| 498 | &(s->s3->tmp.cert_verify_md[MD5_DIGEST_LENGTH])); | ||
| 499 | } | ||
| 462 | break; | 500 | break; |
| 463 | 501 | ||
| 464 | case SSL3_ST_SR_CERT_VRFY_A: | 502 | case SSL3_ST_SR_CERT_VRFY_A: |
| @@ -479,11 +517,34 @@ int ssl3_accept(SSL *s) | |||
| 479 | if (ret <= 0) goto end; | 517 | if (ret <= 0) goto end; |
| 480 | if (s->hit) | 518 | if (s->hit) |
| 481 | s->state=SSL_ST_OK; | 519 | s->state=SSL_ST_OK; |
| 520 | #ifndef OPENSSL_NO_TLSEXT | ||
| 521 | else if (s->tlsext_ticket_expected) | ||
| 522 | s->state=SSL3_ST_SW_SESSION_TICKET_A; | ||
| 523 | #endif | ||
| 482 | else | 524 | else |
| 483 | s->state=SSL3_ST_SW_CHANGE_A; | 525 | s->state=SSL3_ST_SW_CHANGE_A; |
| 484 | s->init_num=0; | 526 | s->init_num=0; |
| 485 | break; | 527 | break; |
| 486 | 528 | ||
| 529 | #ifndef OPENSSL_NO_TLSEXT | ||
| 530 | case SSL3_ST_SW_SESSION_TICKET_A: | ||
| 531 | case SSL3_ST_SW_SESSION_TICKET_B: | ||
| 532 | ret=ssl3_send_newsession_ticket(s); | ||
| 533 | if (ret <= 0) goto end; | ||
| 534 | s->state=SSL3_ST_SW_CHANGE_A; | ||
| 535 | s->init_num=0; | ||
| 536 | break; | ||
| 537 | |||
| 538 | case SSL3_ST_SW_CERT_STATUS_A: | ||
| 539 | case SSL3_ST_SW_CERT_STATUS_B: | ||
| 540 | ret=ssl3_send_cert_status(s); | ||
| 541 | if (ret <= 0) goto end; | ||
| 542 | s->state=SSL3_ST_SW_KEY_EXCH_A; | ||
| 543 | s->init_num=0; | ||
| 544 | break; | ||
| 545 | |||
| 546 | #endif | ||
| 547 | |||
| 487 | case SSL3_ST_SW_CHANGE_A: | 548 | case SSL3_ST_SW_CHANGE_A: |
| 488 | case SSL3_ST_SW_CHANGE_B: | 549 | case SSL3_ST_SW_CHANGE_B: |
| 489 | 550 | ||
| @@ -589,7 +650,7 @@ end: | |||
| 589 | return(ret); | 650 | return(ret); |
| 590 | } | 651 | } |
| 591 | 652 | ||
| 592 | static int ssl3_send_hello_request(SSL *s) | 653 | int ssl3_send_hello_request(SSL *s) |
| 593 | { | 654 | { |
| 594 | unsigned char *p; | 655 | unsigned char *p; |
| 595 | 656 | ||
| @@ -611,14 +672,14 @@ static int ssl3_send_hello_request(SSL *s) | |||
| 611 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | 672 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); |
| 612 | } | 673 | } |
| 613 | 674 | ||
| 614 | static int ssl3_check_client_hello(SSL *s) | 675 | int ssl3_check_client_hello(SSL *s) |
| 615 | { | 676 | { |
| 616 | int ok; | 677 | int ok; |
| 617 | long n; | 678 | long n; |
| 618 | 679 | ||
| 619 | /* this function is called when we really expect a Certificate message, | 680 | /* this function is called when we really expect a Certificate message, |
| 620 | * so permit appropriate message length */ | 681 | * so permit appropriate message length */ |
| 621 | n=ssl3_get_message(s, | 682 | n=s->method->ssl_get_message(s, |
| 622 | SSL3_ST_SR_CERT_A, | 683 | SSL3_ST_SR_CERT_A, |
| 623 | SSL3_ST_SR_CERT_B, | 684 | SSL3_ST_SR_CERT_B, |
| 624 | -1, | 685 | -1, |
| @@ -644,14 +705,17 @@ static int ssl3_check_client_hello(SSL *s) | |||
| 644 | return 1; | 705 | return 1; |
| 645 | } | 706 | } |
| 646 | 707 | ||
| 647 | static int ssl3_get_client_hello(SSL *s) | 708 | int ssl3_get_client_hello(SSL *s) |
| 648 | { | 709 | { |
| 649 | int i,j,ok,al,ret= -1; | 710 | int i,j,ok,al,ret= -1; |
| 711 | unsigned int cookie_len; | ||
| 650 | long n; | 712 | long n; |
| 651 | unsigned long id; | 713 | unsigned long id; |
| 652 | unsigned char *p,*d,*q; | 714 | unsigned char *p,*d,*q; |
| 653 | SSL_CIPHER *c; | 715 | SSL_CIPHER *c; |
| 716 | #ifndef OPENSSL_NO_COMP | ||
| 654 | SSL_COMP *comp=NULL; | 717 | SSL_COMP *comp=NULL; |
| 718 | #endif | ||
| 655 | STACK_OF(SSL_CIPHER) *ciphers=NULL; | 719 | STACK_OF(SSL_CIPHER) *ciphers=NULL; |
| 656 | 720 | ||
| 657 | /* We do this so that we will respond with our native type. | 721 | /* We do this so that we will respond with our native type. |
| @@ -662,10 +726,10 @@ static int ssl3_get_client_hello(SSL *s) | |||
| 662 | */ | 726 | */ |
| 663 | if (s->state == SSL3_ST_SR_CLNT_HELLO_A) | 727 | if (s->state == SSL3_ST_SR_CLNT_HELLO_A) |
| 664 | { | 728 | { |
| 665 | s->first_packet=1; | ||
| 666 | s->state=SSL3_ST_SR_CLNT_HELLO_B; | 729 | s->state=SSL3_ST_SR_CLNT_HELLO_B; |
| 667 | } | 730 | } |
| 668 | n=ssl3_get_message(s, | 731 | s->first_packet=1; |
| 732 | n=s->method->ssl_get_message(s, | ||
| 669 | SSL3_ST_SR_CLNT_HELLO_B, | 733 | SSL3_ST_SR_CLNT_HELLO_B, |
| 670 | SSL3_ST_SR_CLNT_HELLO_C, | 734 | SSL3_ST_SR_CLNT_HELLO_C, |
| 671 | SSL3_MT_CLIENT_HELLO, | 735 | SSL3_MT_CLIENT_HELLO, |
| @@ -673,6 +737,7 @@ static int ssl3_get_client_hello(SSL *s) | |||
| 673 | &ok); | 737 | &ok); |
| 674 | 738 | ||
| 675 | if (!ok) return((int)n); | 739 | if (!ok) return((int)n); |
| 740 | s->first_packet=0; | ||
| 676 | d=p=(unsigned char *)s->init_msg; | 741 | d=p=(unsigned char *)s->init_msg; |
| 677 | 742 | ||
| 678 | /* use version from inside client hello, not from record header | 743 | /* use version from inside client hello, not from record header |
| @@ -680,7 +745,8 @@ static int ssl3_get_client_hello(SSL *s) | |||
| 680 | s->client_version=(((int)p[0])<<8)|(int)p[1]; | 745 | s->client_version=(((int)p[0])<<8)|(int)p[1]; |
| 681 | p+=2; | 746 | p+=2; |
| 682 | 747 | ||
| 683 | if (s->client_version < s->version) | 748 | if ((s->version == DTLS1_VERSION && s->client_version > s->version) || |
| 749 | (s->version != DTLS1_VERSION && s->client_version < s->version)) | ||
| 684 | { | 750 | { |
| 685 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_WRONG_VERSION_NUMBER); | 751 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_WRONG_VERSION_NUMBER); |
| 686 | if ((s->client_version>>8) == SSL3_VERSION_MAJOR) | 752 | if ((s->client_version>>8) == SSL3_VERSION_MAJOR) |
| @@ -708,14 +774,14 @@ static int ssl3_get_client_hello(SSL *s) | |||
| 708 | * might be written that become totally unsecure when compiled with | 774 | * might be written that become totally unsecure when compiled with |
| 709 | * an earlier library version) | 775 | * an earlier library version) |
| 710 | */ | 776 | */ |
| 711 | if (j == 0 || (s->new_session && (s->options & SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION))) | 777 | if ((s->new_session && (s->options & SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION))) |
| 712 | { | 778 | { |
| 713 | if (!ssl_get_new_session(s,1)) | 779 | if (!ssl_get_new_session(s,1)) |
| 714 | goto err; | 780 | goto err; |
| 715 | } | 781 | } |
| 716 | else | 782 | else |
| 717 | { | 783 | { |
| 718 | i=ssl_get_prev_session(s,p,j); | 784 | i=ssl_get_prev_session(s, p, j, d + n); |
| 719 | if (i == 1) | 785 | if (i == 1) |
| 720 | { /* previous session */ | 786 | { /* previous session */ |
| 721 | s->hit=1; | 787 | s->hit=1; |
| @@ -730,6 +796,68 @@ static int ssl3_get_client_hello(SSL *s) | |||
| 730 | } | 796 | } |
| 731 | 797 | ||
| 732 | p+=j; | 798 | p+=j; |
| 799 | |||
| 800 | if (s->version == DTLS1_VERSION) | ||
| 801 | { | ||
| 802 | /* cookie stuff */ | ||
| 803 | cookie_len = *(p++); | ||
| 804 | |||
| 805 | if ( (SSL_get_options(s) & SSL_OP_COOKIE_EXCHANGE) && | ||
| 806 | s->d1->send_cookie == 0) | ||
| 807 | { | ||
| 808 | /* HelloVerifyMessage has already been sent */ | ||
| 809 | if ( cookie_len != s->d1->cookie_len) | ||
| 810 | { | ||
| 811 | al = SSL_AD_HANDSHAKE_FAILURE; | ||
| 812 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_COOKIE_MISMATCH); | ||
| 813 | goto f_err; | ||
| 814 | } | ||
| 815 | } | ||
| 816 | |||
| 817 | /* | ||
| 818 | * The ClientHello may contain a cookie even if the | ||
| 819 | * HelloVerify message has not been sent--make sure that it | ||
| 820 | * does not cause an overflow. | ||
| 821 | */ | ||
| 822 | if ( cookie_len > sizeof(s->d1->rcvd_cookie)) | ||
| 823 | { | ||
| 824 | /* too much data */ | ||
| 825 | al = SSL_AD_DECODE_ERROR; | ||
| 826 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_COOKIE_MISMATCH); | ||
| 827 | goto f_err; | ||
| 828 | } | ||
| 829 | |||
| 830 | /* verify the cookie if appropriate option is set. */ | ||
| 831 | if ( (SSL_get_options(s) & SSL_OP_COOKIE_EXCHANGE) && | ||
| 832 | cookie_len > 0) | ||
| 833 | { | ||
| 834 | memcpy(s->d1->rcvd_cookie, p, cookie_len); | ||
| 835 | |||
| 836 | if ( s->ctx->app_verify_cookie_cb != NULL) | ||
| 837 | { | ||
| 838 | if ( s->ctx->app_verify_cookie_cb(s, s->d1->rcvd_cookie, | ||
| 839 | cookie_len) == 0) | ||
| 840 | { | ||
| 841 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
| 842 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, | ||
| 843 | SSL_R_COOKIE_MISMATCH); | ||
| 844 | goto f_err; | ||
| 845 | } | ||
| 846 | /* else cookie verification succeeded */ | ||
| 847 | } | ||
| 848 | else if ( memcmp(s->d1->rcvd_cookie, s->d1->cookie, | ||
| 849 | s->d1->cookie_len) != 0) /* default verification */ | ||
| 850 | { | ||
| 851 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
| 852 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, | ||
| 853 | SSL_R_COOKIE_MISMATCH); | ||
| 854 | goto f_err; | ||
| 855 | } | ||
| 856 | } | ||
| 857 | |||
| 858 | p += cookie_len; | ||
| 859 | } | ||
| 860 | |||
| 733 | n2s(p,i); | 861 | n2s(p,i); |
| 734 | if ((i == 0) && (j != 0)) | 862 | if ((i == 0) && (j != 0)) |
| 735 | { | 863 | { |
| @@ -779,8 +907,7 @@ static int ssl3_get_client_hello(SSL *s) | |||
| 779 | if ((s->options & SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG) && (sk_SSL_CIPHER_num(ciphers) == 1)) | 907 | if ((s->options & SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG) && (sk_SSL_CIPHER_num(ciphers) == 1)) |
| 780 | { | 908 | { |
| 781 | /* Very bad for multi-threading.... */ | 909 | /* Very bad for multi-threading.... */ |
| 782 | s->session->cipher=sk_SSL_CIPHER_value(ciphers, | 910 | s->session->cipher=sk_SSL_CIPHER_value(ciphers, 0); |
| 783 | 0); | ||
| 784 | } | 911 | } |
| 785 | else | 912 | else |
| 786 | { | 913 | { |
| @@ -817,10 +944,27 @@ static int ssl3_get_client_hello(SSL *s) | |||
| 817 | goto f_err; | 944 | goto f_err; |
| 818 | } | 945 | } |
| 819 | 946 | ||
| 947 | #ifndef OPENSSL_NO_TLSEXT | ||
| 948 | /* TLS extensions*/ | ||
| 949 | if (s->version > SSL3_VERSION) | ||
| 950 | { | ||
| 951 | if (!ssl_parse_clienthello_tlsext(s,&p,d,n, &al)) | ||
| 952 | { | ||
| 953 | /* 'al' set by ssl_parse_clienthello_tlsext */ | ||
| 954 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_PARSE_TLSEXT); | ||
| 955 | goto f_err; | ||
| 956 | } | ||
| 957 | } | ||
| 958 | if (ssl_check_clienthello_tlsext(s) <= 0) { | ||
| 959 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_CLIENTHELLO_TLSEXT); | ||
| 960 | goto err; | ||
| 961 | } | ||
| 962 | #endif | ||
| 820 | /* Worst case, we will use the NULL compression, but if we have other | 963 | /* Worst case, we will use the NULL compression, but if we have other |
| 821 | * options, we will now look for them. We have i-1 compression | 964 | * options, we will now look for them. We have i-1 compression |
| 822 | * algorithms from the client, starting at q. */ | 965 | * algorithms from the client, starting at q. */ |
| 823 | s->s3->tmp.new_compression=NULL; | 966 | s->s3->tmp.new_compression=NULL; |
| 967 | #ifndef OPENSSL_NO_COMP | ||
| 824 | if (s->ctx->comp_methods != NULL) | 968 | if (s->ctx->comp_methods != NULL) |
| 825 | { /* See if we have a match */ | 969 | { /* See if we have a match */ |
| 826 | int m,nn,o,v,done=0; | 970 | int m,nn,o,v,done=0; |
| @@ -845,6 +989,7 @@ static int ssl3_get_client_hello(SSL *s) | |||
| 845 | else | 989 | else |
| 846 | comp=NULL; | 990 | comp=NULL; |
| 847 | } | 991 | } |
| 992 | #endif | ||
| 848 | 993 | ||
| 849 | /* TLS does not mind if there is extra stuff */ | 994 | /* TLS does not mind if there is extra stuff */ |
| 850 | #if 0 /* SSL 3.0 does not mind either, so we should disable this test | 995 | #if 0 /* SSL 3.0 does not mind either, so we should disable this test |
| @@ -868,7 +1013,11 @@ static int ssl3_get_client_hello(SSL *s) | |||
| 868 | 1013 | ||
| 869 | if (!s->hit) | 1014 | if (!s->hit) |
| 870 | { | 1015 | { |
| 1016 | #ifdef OPENSSL_NO_COMP | ||
| 1017 | s->session->compress_meth=0; | ||
| 1018 | #else | ||
| 871 | s->session->compress_meth=(comp == NULL)?0:comp->id; | 1019 | s->session->compress_meth=(comp == NULL)?0:comp->id; |
| 1020 | #endif | ||
| 872 | if (s->session->ciphers != NULL) | 1021 | if (s->session->ciphers != NULL) |
| 873 | sk_SSL_CIPHER_free(s->session->ciphers); | 1022 | sk_SSL_CIPHER_free(s->session->ciphers); |
| 874 | s->session->ciphers=ciphers; | 1023 | s->session->ciphers=ciphers; |
| @@ -943,7 +1092,7 @@ err: | |||
| 943 | return(ret); | 1092 | return(ret); |
| 944 | } | 1093 | } |
| 945 | 1094 | ||
| 946 | static int ssl3_send_server_hello(SSL *s) | 1095 | int ssl3_send_server_hello(SSL *s) |
| 947 | { | 1096 | { |
| 948 | unsigned char *buf; | 1097 | unsigned char *buf; |
| 949 | unsigned char *p,*d; | 1098 | unsigned char *p,*d; |
| @@ -956,7 +1105,7 @@ static int ssl3_send_server_hello(SSL *s) | |||
| 956 | p=s->s3->server_random; | 1105 | p=s->s3->server_random; |
| 957 | Time=(unsigned long)time(NULL); /* Time */ | 1106 | Time=(unsigned long)time(NULL); /* Time */ |
| 958 | l2n(Time,p); | 1107 | l2n(Time,p); |
| 959 | if(RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4) <= 0) | 1108 | if (RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4) <= 0) |
| 960 | return -1; | 1109 | return -1; |
| 961 | /* Do the message type and length last */ | 1110 | /* Do the message type and length last */ |
| 962 | d=p= &(buf[4]); | 1111 | d=p= &(buf[4]); |
| @@ -975,12 +1124,20 @@ static int ssl3_send_server_hello(SSL *s) | |||
| 975 | * session-id if we want it to be single use. | 1124 | * session-id if we want it to be single use. |
| 976 | * Currently I will not implement the '0' length session-id | 1125 | * Currently I will not implement the '0' length session-id |
| 977 | * 12-Jan-98 - I'll now support the '0' length stuff. | 1126 | * 12-Jan-98 - I'll now support the '0' length stuff. |
| 1127 | * | ||
| 1128 | * We also have an additional case where stateless session | ||
| 1129 | * resumption is successful: we always send back the old | ||
| 1130 | * session id. In this case s->hit is non zero: this can | ||
| 1131 | * only happen if stateless session resumption is succesful | ||
| 1132 | * if session caching is disabled so existing functionality | ||
| 1133 | * is unaffected. | ||
| 978 | */ | 1134 | */ |
| 979 | if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_SERVER)) | 1135 | if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_SERVER) |
| 1136 | && !s->hit) | ||
| 980 | s->session->session_id_length=0; | 1137 | s->session->session_id_length=0; |
| 981 | 1138 | ||
| 982 | sl=s->session->session_id_length; | 1139 | sl=s->session->session_id_length; |
| 983 | if (sl > sizeof s->session->session_id) | 1140 | if (sl > (int)sizeof(s->session->session_id)) |
| 984 | { | 1141 | { |
| 985 | SSLerr(SSL_F_SSL3_SEND_SERVER_HELLO, ERR_R_INTERNAL_ERROR); | 1142 | SSLerr(SSL_F_SSL3_SEND_SERVER_HELLO, ERR_R_INTERNAL_ERROR); |
| 986 | return -1; | 1143 | return -1; |
| @@ -994,11 +1151,21 @@ static int ssl3_send_server_hello(SSL *s) | |||
| 994 | p+=i; | 1151 | p+=i; |
| 995 | 1152 | ||
| 996 | /* put the compression method */ | 1153 | /* put the compression method */ |
| 1154 | #ifdef OPENSSL_NO_COMP | ||
| 1155 | *(p++)=0; | ||
| 1156 | #else | ||
| 997 | if (s->s3->tmp.new_compression == NULL) | 1157 | if (s->s3->tmp.new_compression == NULL) |
| 998 | *(p++)=0; | 1158 | *(p++)=0; |
| 999 | else | 1159 | else |
| 1000 | *(p++)=s->s3->tmp.new_compression->id; | 1160 | *(p++)=s->s3->tmp.new_compression->id; |
| 1001 | 1161 | #endif | |
| 1162 | #ifndef OPENSSL_NO_TLSEXT | ||
| 1163 | if ((p = ssl_add_serverhello_tlsext(s, p, buf+SSL3_RT_MAX_PLAIN_LENGTH)) == NULL) | ||
| 1164 | { | ||
| 1165 | SSLerr(SSL_F_SSL3_SEND_SERVER_HELLO,ERR_R_INTERNAL_ERROR); | ||
| 1166 | return -1; | ||
| 1167 | } | ||
| 1168 | #endif | ||
| 1002 | /* do the header */ | 1169 | /* do the header */ |
| 1003 | l=(p-d); | 1170 | l=(p-d); |
| 1004 | d=buf; | 1171 | d=buf; |
| @@ -1015,7 +1182,7 @@ static int ssl3_send_server_hello(SSL *s) | |||
| 1015 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | 1182 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); |
| 1016 | } | 1183 | } |
| 1017 | 1184 | ||
| 1018 | static int ssl3_send_server_done(SSL *s) | 1185 | int ssl3_send_server_done(SSL *s) |
| 1019 | { | 1186 | { |
| 1020 | unsigned char *p; | 1187 | unsigned char *p; |
| 1021 | 1188 | ||
| @@ -1039,7 +1206,7 @@ static int ssl3_send_server_done(SSL *s) | |||
| 1039 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | 1206 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); |
| 1040 | } | 1207 | } |
| 1041 | 1208 | ||
| 1042 | static int ssl3_send_server_key_exchange(SSL *s) | 1209 | int ssl3_send_server_key_exchange(SSL *s) |
| 1043 | { | 1210 | { |
| 1044 | #ifndef OPENSSL_NO_RSA | 1211 | #ifndef OPENSSL_NO_RSA |
| 1045 | unsigned char *q; | 1212 | unsigned char *q; |
| @@ -1051,6 +1218,13 @@ static int ssl3_send_server_key_exchange(SSL *s) | |||
| 1051 | #ifndef OPENSSL_NO_DH | 1218 | #ifndef OPENSSL_NO_DH |
| 1052 | DH *dh=NULL,*dhp; | 1219 | DH *dh=NULL,*dhp; |
| 1053 | #endif | 1220 | #endif |
| 1221 | #ifndef OPENSSL_NO_ECDH | ||
| 1222 | EC_KEY *ecdh=NULL, *ecdhp; | ||
| 1223 | unsigned char *encodedPoint = NULL; | ||
| 1224 | int encodedlen = 0; | ||
| 1225 | int curve_id = 0; | ||
| 1226 | BN_CTX *bn_ctx = NULL; | ||
| 1227 | #endif | ||
| 1054 | EVP_PKEY *pkey; | 1228 | EVP_PKEY *pkey; |
| 1055 | unsigned char *p,*d; | 1229 | unsigned char *p,*d; |
| 1056 | int al,i; | 1230 | int al,i; |
| @@ -1159,6 +1333,134 @@ static int ssl3_send_server_key_exchange(SSL *s) | |||
| 1159 | } | 1333 | } |
| 1160 | else | 1334 | else |
| 1161 | #endif | 1335 | #endif |
| 1336 | #ifndef OPENSSL_NO_ECDH | ||
| 1337 | if (type & SSL_kECDHE) | ||
| 1338 | { | ||
| 1339 | const EC_GROUP *group; | ||
| 1340 | |||
| 1341 | ecdhp=cert->ecdh_tmp; | ||
| 1342 | if ((ecdhp == NULL) && (s->cert->ecdh_tmp_cb != NULL)) | ||
| 1343 | { | ||
| 1344 | ecdhp=s->cert->ecdh_tmp_cb(s, | ||
| 1345 | SSL_C_IS_EXPORT(s->s3->tmp.new_cipher), | ||
| 1346 | SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)); | ||
| 1347 | } | ||
| 1348 | if (ecdhp == NULL) | ||
| 1349 | { | ||
| 1350 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
| 1351 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_MISSING_TMP_ECDH_KEY); | ||
| 1352 | goto f_err; | ||
| 1353 | } | ||
| 1354 | |||
| 1355 | if (s->s3->tmp.ecdh != NULL) | ||
| 1356 | { | ||
| 1357 | EC_KEY_free(s->s3->tmp.ecdh); | ||
| 1358 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR); | ||
| 1359 | goto err; | ||
| 1360 | } | ||
| 1361 | |||
| 1362 | /* Duplicate the ECDH structure. */ | ||
| 1363 | if (ecdhp == NULL) | ||
| 1364 | { | ||
| 1365 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_ECDH_LIB); | ||
| 1366 | goto err; | ||
| 1367 | } | ||
| 1368 | if (!EC_KEY_up_ref(ecdhp)) | ||
| 1369 | { | ||
| 1370 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_ECDH_LIB); | ||
| 1371 | goto err; | ||
| 1372 | } | ||
| 1373 | ecdh = ecdhp; | ||
| 1374 | |||
| 1375 | s->s3->tmp.ecdh=ecdh; | ||
| 1376 | if ((EC_KEY_get0_public_key(ecdh) == NULL) || | ||
| 1377 | (EC_KEY_get0_private_key(ecdh) == NULL) || | ||
| 1378 | (s->options & SSL_OP_SINGLE_ECDH_USE)) | ||
| 1379 | { | ||
| 1380 | if(!EC_KEY_generate_key(ecdh)) | ||
| 1381 | { | ||
| 1382 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_ECDH_LIB); | ||
| 1383 | goto err; | ||
| 1384 | } | ||
| 1385 | } | ||
| 1386 | |||
| 1387 | if (((group = EC_KEY_get0_group(ecdh)) == NULL) || | ||
| 1388 | (EC_KEY_get0_public_key(ecdh) == NULL) || | ||
| 1389 | (EC_KEY_get0_private_key(ecdh) == NULL)) | ||
| 1390 | { | ||
| 1391 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_ECDH_LIB); | ||
| 1392 | goto err; | ||
| 1393 | } | ||
| 1394 | |||
| 1395 | if (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && | ||
| 1396 | (EC_GROUP_get_degree(group) > 163)) | ||
| 1397 | { | ||
| 1398 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_ECGROUP_TOO_LARGE_FOR_CIPHER); | ||
| 1399 | goto err; | ||
| 1400 | } | ||
| 1401 | |||
| 1402 | /* XXX: For now, we only support ephemeral ECDH | ||
| 1403 | * keys over named (not generic) curves. For | ||
| 1404 | * supported named curves, curve_id is non-zero. | ||
| 1405 | */ | ||
| 1406 | if ((curve_id = | ||
| 1407 | nid2curve_id(EC_GROUP_get_curve_name(group))) | ||
| 1408 | == 0) | ||
| 1409 | { | ||
| 1410 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNSUPPORTED_ELLIPTIC_CURVE); | ||
| 1411 | goto err; | ||
| 1412 | } | ||
| 1413 | |||
| 1414 | /* Encode the public key. | ||
| 1415 | * First check the size of encoding and | ||
| 1416 | * allocate memory accordingly. | ||
| 1417 | */ | ||
| 1418 | encodedlen = EC_POINT_point2oct(group, | ||
| 1419 | EC_KEY_get0_public_key(ecdh), | ||
| 1420 | POINT_CONVERSION_UNCOMPRESSED, | ||
| 1421 | NULL, 0, NULL); | ||
| 1422 | |||
| 1423 | encodedPoint = (unsigned char *) | ||
| 1424 | OPENSSL_malloc(encodedlen*sizeof(unsigned char)); | ||
| 1425 | bn_ctx = BN_CTX_new(); | ||
| 1426 | if ((encodedPoint == NULL) || (bn_ctx == NULL)) | ||
| 1427 | { | ||
| 1428 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE); | ||
| 1429 | goto err; | ||
| 1430 | } | ||
| 1431 | |||
| 1432 | |||
| 1433 | encodedlen = EC_POINT_point2oct(group, | ||
| 1434 | EC_KEY_get0_public_key(ecdh), | ||
| 1435 | POINT_CONVERSION_UNCOMPRESSED, | ||
| 1436 | encodedPoint, encodedlen, bn_ctx); | ||
| 1437 | |||
| 1438 | if (encodedlen == 0) | ||
| 1439 | { | ||
| 1440 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_ECDH_LIB); | ||
| 1441 | goto err; | ||
| 1442 | } | ||
| 1443 | |||
| 1444 | BN_CTX_free(bn_ctx); bn_ctx=NULL; | ||
| 1445 | |||
| 1446 | /* XXX: For now, we only support named (not | ||
| 1447 | * generic) curves in ECDH ephemeral key exchanges. | ||
| 1448 | * In this situation, we need four additional bytes | ||
| 1449 | * to encode the entire ServerECDHParams | ||
| 1450 | * structure. | ||
| 1451 | */ | ||
| 1452 | n = 4 + encodedlen; | ||
| 1453 | |||
| 1454 | /* We'll generate the serverKeyExchange message | ||
| 1455 | * explicitly so we can set these to NULLs | ||
| 1456 | */ | ||
| 1457 | r[0]=NULL; | ||
| 1458 | r[1]=NULL; | ||
| 1459 | r[2]=NULL; | ||
| 1460 | r[3]=NULL; | ||
| 1461 | } | ||
| 1462 | else | ||
| 1463 | #endif /* !OPENSSL_NO_ECDH */ | ||
| 1162 | { | 1464 | { |
| 1163 | al=SSL_AD_HANDSHAKE_FAILURE; | 1465 | al=SSL_AD_HANDSHAKE_FAILURE; |
| 1164 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE); | 1466 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE); |
| @@ -1201,6 +1503,31 @@ static int ssl3_send_server_key_exchange(SSL *s) | |||
| 1201 | p+=nr[i]; | 1503 | p+=nr[i]; |
| 1202 | } | 1504 | } |
| 1203 | 1505 | ||
| 1506 | #ifndef OPENSSL_NO_ECDH | ||
| 1507 | if (type & SSL_kECDHE) | ||
| 1508 | { | ||
| 1509 | /* XXX: For now, we only support named (not generic) curves. | ||
| 1510 | * In this situation, the serverKeyExchange message has: | ||
| 1511 | * [1 byte CurveType], [2 byte CurveName] | ||
| 1512 | * [1 byte length of encoded point], followed by | ||
| 1513 | * the actual encoded point itself | ||
| 1514 | */ | ||
| 1515 | *p = NAMED_CURVE_TYPE; | ||
| 1516 | p += 1; | ||
| 1517 | *p = 0; | ||
| 1518 | p += 1; | ||
| 1519 | *p = curve_id; | ||
| 1520 | p += 1; | ||
| 1521 | *p = encodedlen; | ||
| 1522 | p += 1; | ||
| 1523 | memcpy((unsigned char*)p, | ||
| 1524 | (unsigned char *)encodedPoint, | ||
| 1525 | encodedlen); | ||
| 1526 | OPENSSL_free(encodedPoint); | ||
| 1527 | p += encodedlen; | ||
| 1528 | } | ||
| 1529 | #endif | ||
| 1530 | |||
| 1204 | /* not anonymous */ | 1531 | /* not anonymous */ |
| 1205 | if (pkey != NULL) | 1532 | if (pkey != NULL) |
| 1206 | { | 1533 | { |
| @@ -1213,8 +1540,6 @@ static int ssl3_send_server_key_exchange(SSL *s) | |||
| 1213 | j=0; | 1540 | j=0; |
| 1214 | for (num=2; num > 0; num--) | 1541 | for (num=2; num > 0; num--) |
| 1215 | { | 1542 | { |
| 1216 | EVP_MD_CTX_set_flags(&md_ctx, | ||
| 1217 | EVP_MD_CTX_FLAG_NON_FIPS_ALLOW); | ||
| 1218 | EVP_DigestInit_ex(&md_ctx,(num == 2) | 1543 | EVP_DigestInit_ex(&md_ctx,(num == 2) |
| 1219 | ?s->ctx->md5:s->ctx->sha1, NULL); | 1544 | ?s->ctx->md5:s->ctx->sha1, NULL); |
| 1220 | EVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE); | 1545 | EVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE); |
| @@ -1255,6 +1580,25 @@ static int ssl3_send_server_key_exchange(SSL *s) | |||
| 1255 | } | 1580 | } |
| 1256 | else | 1581 | else |
| 1257 | #endif | 1582 | #endif |
| 1583 | #if !defined(OPENSSL_NO_ECDSA) | ||
| 1584 | if (pkey->type == EVP_PKEY_EC) | ||
| 1585 | { | ||
| 1586 | /* let's do ECDSA */ | ||
| 1587 | EVP_SignInit_ex(&md_ctx,EVP_ecdsa(), NULL); | ||
| 1588 | EVP_SignUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE); | ||
| 1589 | EVP_SignUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE); | ||
| 1590 | EVP_SignUpdate(&md_ctx,&(d[4]),n); | ||
| 1591 | if (!EVP_SignFinal(&md_ctx,&(p[2]), | ||
| 1592 | (unsigned int *)&i,pkey)) | ||
| 1593 | { | ||
| 1594 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_ECDSA); | ||
| 1595 | goto err; | ||
| 1596 | } | ||
| 1597 | s2n(i,p); | ||
| 1598 | n+=i+2; | ||
| 1599 | } | ||
| 1600 | else | ||
| 1601 | #endif | ||
| 1258 | { | 1602 | { |
| 1259 | /* Is this error check actually needed? */ | 1603 | /* Is this error check actually needed? */ |
| 1260 | al=SSL_AD_HANDSHAKE_FAILURE; | 1604 | al=SSL_AD_HANDSHAKE_FAILURE; |
| @@ -1278,11 +1622,15 @@ static int ssl3_send_server_key_exchange(SSL *s) | |||
| 1278 | f_err: | 1622 | f_err: |
| 1279 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | 1623 | ssl3_send_alert(s,SSL3_AL_FATAL,al); |
| 1280 | err: | 1624 | err: |
| 1625 | #ifndef OPENSSL_NO_ECDH | ||
| 1626 | if (encodedPoint != NULL) OPENSSL_free(encodedPoint); | ||
| 1627 | BN_CTX_free(bn_ctx); | ||
| 1628 | #endif | ||
| 1281 | EVP_MD_CTX_cleanup(&md_ctx); | 1629 | EVP_MD_CTX_cleanup(&md_ctx); |
| 1282 | return(-1); | 1630 | return(-1); |
| 1283 | } | 1631 | } |
| 1284 | 1632 | ||
| 1285 | static int ssl3_send_certificate_request(SSL *s) | 1633 | int ssl3_send_certificate_request(SSL *s) |
| 1286 | { | 1634 | { |
| 1287 | unsigned char *p,*d; | 1635 | unsigned char *p,*d; |
| 1288 | int i,j,nl,off,n; | 1636 | int i,j,nl,off,n; |
| @@ -1371,7 +1719,7 @@ err: | |||
| 1371 | return(-1); | 1719 | return(-1); |
| 1372 | } | 1720 | } |
| 1373 | 1721 | ||
| 1374 | static int ssl3_get_client_key_exchange(SSL *s) | 1722 | int ssl3_get_client_key_exchange(SSL *s) |
| 1375 | { | 1723 | { |
| 1376 | int i,al,ok; | 1724 | int i,al,ok; |
| 1377 | long n; | 1725 | long n; |
| @@ -1389,7 +1737,14 @@ static int ssl3_get_client_key_exchange(SSL *s) | |||
| 1389 | KSSL_ERR kssl_err; | 1737 | KSSL_ERR kssl_err; |
| 1390 | #endif /* OPENSSL_NO_KRB5 */ | 1738 | #endif /* OPENSSL_NO_KRB5 */ |
| 1391 | 1739 | ||
| 1392 | n=ssl3_get_message(s, | 1740 | #ifndef OPENSSL_NO_ECDH |
| 1741 | EC_KEY *srvr_ecdh = NULL; | ||
| 1742 | EVP_PKEY *clnt_pub_pkey = NULL; | ||
| 1743 | EC_POINT *clnt_ecpoint = NULL; | ||
| 1744 | BN_CTX *bn_ctx = NULL; | ||
| 1745 | #endif | ||
| 1746 | |||
| 1747 | n=s->method->ssl_get_message(s, | ||
| 1393 | SSL3_ST_SR_KEY_EXCH_A, | 1748 | SSL3_ST_SR_KEY_EXCH_A, |
| 1394 | SSL3_ST_SR_KEY_EXCH_B, | 1749 | SSL3_ST_SR_KEY_EXCH_B, |
| 1395 | SSL3_MT_CLIENT_KEY_EXCHANGE, | 1750 | SSL3_MT_CLIENT_KEY_EXCHANGE, |
| @@ -1433,8 +1788,9 @@ static int ssl3_get_client_key_exchange(SSL *s) | |||
| 1433 | rsa=pkey->pkey.rsa; | 1788 | rsa=pkey->pkey.rsa; |
| 1434 | } | 1789 | } |
| 1435 | 1790 | ||
| 1436 | /* TLS */ | 1791 | /* TLS and [incidentally] DTLS, including pre-0.9.8f */ |
| 1437 | if (s->version > SSL3_VERSION) | 1792 | if (s->version > SSL3_VERSION && |
| 1793 | s->client_version != DTLS1_BAD_VER) | ||
| 1438 | { | 1794 | { |
| 1439 | n2s(p,i); | 1795 | n2s(p,i); |
| 1440 | if (n != i+2) | 1796 | if (n != i+2) |
| @@ -1495,7 +1851,7 @@ static int ssl3_get_client_key_exchange(SSL *s) | |||
| 1495 | i = SSL_MAX_MASTER_KEY_LENGTH; | 1851 | i = SSL_MAX_MASTER_KEY_LENGTH; |
| 1496 | p[0] = s->client_version >> 8; | 1852 | p[0] = s->client_version >> 8; |
| 1497 | p[1] = s->client_version & 0xff; | 1853 | p[1] = s->client_version & 0xff; |
| 1498 | if(RAND_pseudo_bytes(p+2, i-2) <= 0) /* should be RAND_bytes, but we cannot work around a failure */ | 1854 | if (RAND_pseudo_bytes(p+2, i-2) <= 0) /* should be RAND_bytes, but we cannot work around a failure */ |
| 1499 | goto err; | 1855 | goto err; |
| 1500 | } | 1856 | } |
| 1501 | 1857 | ||
| @@ -1594,7 +1950,7 @@ static int ssl3_get_client_key_exchange(SSL *s) | |||
| 1594 | n2s(p,i); | 1950 | n2s(p,i); |
| 1595 | enc_ticket.length = i; | 1951 | enc_ticket.length = i; |
| 1596 | 1952 | ||
| 1597 | if (n < (long)enc_ticket.length + 6) | 1953 | if (n < (int)enc_ticket.length + 6) |
| 1598 | { | 1954 | { |
| 1599 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, | 1955 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, |
| 1600 | SSL_R_DATA_LENGTH_TOO_LONG); | 1956 | SSL_R_DATA_LENGTH_TOO_LONG); |
| @@ -1607,7 +1963,7 @@ static int ssl3_get_client_key_exchange(SSL *s) | |||
| 1607 | n2s(p,i); | 1963 | n2s(p,i); |
| 1608 | authenticator.length = i; | 1964 | authenticator.length = i; |
| 1609 | 1965 | ||
| 1610 | if (n < (long)(enc_ticket.length + authenticator.length + 6)) | 1966 | if (n < (int)(enc_ticket.length + authenticator.length) + 6) |
| 1611 | { | 1967 | { |
| 1612 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, | 1968 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, |
| 1613 | SSL_R_DATA_LENGTH_TOO_LONG); | 1969 | SSL_R_DATA_LENGTH_TOO_LONG); |
| @@ -1649,7 +2005,7 @@ static int ssl3_get_client_key_exchange(SSL *s) | |||
| 1649 | if (kssl_err.text) | 2005 | if (kssl_err.text) |
| 1650 | printf("kssl_err text= %s\n", kssl_err.text); | 2006 | printf("kssl_err text= %s\n", kssl_err.text); |
| 1651 | #endif /* KSSL_DEBUG */ | 2007 | #endif /* KSSL_DEBUG */ |
| 1652 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE, | 2008 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, |
| 1653 | kssl_err.reason); | 2009 | kssl_err.reason); |
| 1654 | goto err; | 2010 | goto err; |
| 1655 | } | 2011 | } |
| @@ -1666,14 +2022,14 @@ static int ssl3_get_client_key_exchange(SSL *s) | |||
| 1666 | if (kssl_err.text) | 2022 | if (kssl_err.text) |
| 1667 | printf("kssl_err text= %s\n", kssl_err.text); | 2023 | printf("kssl_err text= %s\n", kssl_err.text); |
| 1668 | #endif /* KSSL_DEBUG */ | 2024 | #endif /* KSSL_DEBUG */ |
| 1669 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE, | 2025 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, |
| 1670 | kssl_err.reason); | 2026 | kssl_err.reason); |
| 1671 | goto err; | 2027 | goto err; |
| 1672 | } | 2028 | } |
| 1673 | 2029 | ||
| 1674 | if ((krb5rc = kssl_validate_times(authtime, &ttimes)) != 0) | 2030 | if ((krb5rc = kssl_validate_times(authtime, &ttimes)) != 0) |
| 1675 | { | 2031 | { |
| 1676 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE, krb5rc); | 2032 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, krb5rc); |
| 1677 | goto err; | 2033 | goto err; |
| 1678 | } | 2034 | } |
| 1679 | 2035 | ||
| @@ -1719,6 +2075,24 @@ static int ssl3_get_client_key_exchange(SSL *s) | |||
| 1719 | SSL_R_DATA_LENGTH_TOO_LONG); | 2075 | SSL_R_DATA_LENGTH_TOO_LONG); |
| 1720 | goto err; | 2076 | goto err; |
| 1721 | } | 2077 | } |
| 2078 | if (!((pms[0] == (s->client_version>>8)) && (pms[1] == (s->client_version & 0xff)))) | ||
| 2079 | { | ||
| 2080 | /* The premaster secret must contain the same version number as the | ||
| 2081 | * ClientHello to detect version rollback attacks (strangely, the | ||
| 2082 | * protocol does not offer such protection for DH ciphersuites). | ||
| 2083 | * However, buggy clients exist that send random bytes instead of | ||
| 2084 | * the protocol version. | ||
| 2085 | * If SSL_OP_TLS_ROLLBACK_BUG is set, tolerate such clients. | ||
| 2086 | * (Perhaps we should have a separate BUG value for the Kerberos cipher) | ||
| 2087 | */ | ||
| 2088 | if (!(s->options & SSL_OP_TLS_ROLLBACK_BUG)) | ||
| 2089 | { | ||
| 2090 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, | ||
| 2091 | SSL_AD_DECODE_ERROR); | ||
| 2092 | goto err; | ||
| 2093 | } | ||
| 2094 | } | ||
| 2095 | |||
| 1722 | EVP_CIPHER_CTX_cleanup(&ciph_ctx); | 2096 | EVP_CIPHER_CTX_cleanup(&ciph_ctx); |
| 1723 | 2097 | ||
| 1724 | s->session->master_key_length= | 2098 | s->session->master_key_length= |
| @@ -1727,7 +2101,7 @@ static int ssl3_get_client_key_exchange(SSL *s) | |||
| 1727 | 2101 | ||
| 1728 | if (kssl_ctx->client_princ) | 2102 | if (kssl_ctx->client_princ) |
| 1729 | { | 2103 | { |
| 1730 | int len = strlen(kssl_ctx->client_princ); | 2104 | size_t len = strlen(kssl_ctx->client_princ); |
| 1731 | if ( len < SSL_MAX_KRB5_PRINCIPAL_LENGTH ) | 2105 | if ( len < SSL_MAX_KRB5_PRINCIPAL_LENGTH ) |
| 1732 | { | 2106 | { |
| 1733 | s->session->krb5_client_princ_len = len; | 2107 | s->session->krb5_client_princ_len = len; |
| @@ -1744,6 +2118,156 @@ static int ssl3_get_client_key_exchange(SSL *s) | |||
| 1744 | } | 2118 | } |
| 1745 | else | 2119 | else |
| 1746 | #endif /* OPENSSL_NO_KRB5 */ | 2120 | #endif /* OPENSSL_NO_KRB5 */ |
| 2121 | |||
| 2122 | #ifndef OPENSSL_NO_ECDH | ||
| 2123 | if ((l & SSL_kECDH) || (l & SSL_kECDHE)) | ||
| 2124 | { | ||
| 2125 | int ret = 1; | ||
| 2126 | int field_size = 0; | ||
| 2127 | const EC_KEY *tkey; | ||
| 2128 | const EC_GROUP *group; | ||
| 2129 | const BIGNUM *priv_key; | ||
| 2130 | |||
| 2131 | /* initialize structures for server's ECDH key pair */ | ||
| 2132 | if ((srvr_ecdh = EC_KEY_new()) == NULL) | ||
| 2133 | { | ||
| 2134 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, | ||
| 2135 | ERR_R_MALLOC_FAILURE); | ||
| 2136 | goto err; | ||
| 2137 | } | ||
| 2138 | |||
| 2139 | /* Let's get server private key and group information */ | ||
| 2140 | if (l & SSL_kECDH) | ||
| 2141 | { | ||
| 2142 | /* use the certificate */ | ||
| 2143 | tkey = s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec; | ||
| 2144 | } | ||
| 2145 | else | ||
| 2146 | { | ||
| 2147 | /* use the ephermeral values we saved when | ||
| 2148 | * generating the ServerKeyExchange msg. | ||
| 2149 | */ | ||
| 2150 | tkey = s->s3->tmp.ecdh; | ||
| 2151 | } | ||
| 2152 | |||
| 2153 | group = EC_KEY_get0_group(tkey); | ||
| 2154 | priv_key = EC_KEY_get0_private_key(tkey); | ||
| 2155 | |||
| 2156 | if (!EC_KEY_set_group(srvr_ecdh, group) || | ||
| 2157 | !EC_KEY_set_private_key(srvr_ecdh, priv_key)) | ||
| 2158 | { | ||
| 2159 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, | ||
| 2160 | ERR_R_EC_LIB); | ||
| 2161 | goto err; | ||
| 2162 | } | ||
| 2163 | |||
| 2164 | /* Let's get client's public key */ | ||
| 2165 | if ((clnt_ecpoint = EC_POINT_new(group)) == NULL) | ||
| 2166 | { | ||
| 2167 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, | ||
| 2168 | ERR_R_MALLOC_FAILURE); | ||
| 2169 | goto err; | ||
| 2170 | } | ||
| 2171 | |||
| 2172 | if (n == 0L) | ||
| 2173 | { | ||
| 2174 | /* Client Publickey was in Client Certificate */ | ||
| 2175 | |||
| 2176 | if (l & SSL_kECDHE) | ||
| 2177 | { | ||
| 2178 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
| 2179 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_ECDH_KEY); | ||
| 2180 | goto f_err; | ||
| 2181 | } | ||
| 2182 | if (((clnt_pub_pkey=X509_get_pubkey(s->session->peer)) | ||
| 2183 | == NULL) || | ||
| 2184 | (clnt_pub_pkey->type != EVP_PKEY_EC)) | ||
| 2185 | { | ||
| 2186 | /* XXX: For now, we do not support client | ||
| 2187 | * authentication using ECDH certificates | ||
| 2188 | * so this branch (n == 0L) of the code is | ||
| 2189 | * never executed. When that support is | ||
| 2190 | * added, we ought to ensure the key | ||
| 2191 | * received in the certificate is | ||
| 2192 | * authorized for key agreement. | ||
| 2193 | * ECDH_compute_key implicitly checks that | ||
| 2194 | * the two ECDH shares are for the same | ||
| 2195 | * group. | ||
| 2196 | */ | ||
| 2197 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
| 2198 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, | ||
| 2199 | SSL_R_UNABLE_TO_DECODE_ECDH_CERTS); | ||
| 2200 | goto f_err; | ||
| 2201 | } | ||
| 2202 | |||
| 2203 | if (EC_POINT_copy(clnt_ecpoint, | ||
| 2204 | EC_KEY_get0_public_key(clnt_pub_pkey->pkey.ec)) == 0) | ||
| 2205 | { | ||
| 2206 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, | ||
| 2207 | ERR_R_EC_LIB); | ||
| 2208 | goto err; | ||
| 2209 | } | ||
| 2210 | ret = 2; /* Skip certificate verify processing */ | ||
| 2211 | } | ||
| 2212 | else | ||
| 2213 | { | ||
| 2214 | /* Get client's public key from encoded point | ||
| 2215 | * in the ClientKeyExchange message. | ||
| 2216 | */ | ||
| 2217 | if ((bn_ctx = BN_CTX_new()) == NULL) | ||
| 2218 | { | ||
| 2219 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, | ||
| 2220 | ERR_R_MALLOC_FAILURE); | ||
| 2221 | goto err; | ||
| 2222 | } | ||
| 2223 | |||
| 2224 | /* Get encoded point length */ | ||
| 2225 | i = *p; | ||
| 2226 | p += 1; | ||
| 2227 | if (EC_POINT_oct2point(group, | ||
| 2228 | clnt_ecpoint, p, i, bn_ctx) == 0) | ||
| 2229 | { | ||
| 2230 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, | ||
| 2231 | ERR_R_EC_LIB); | ||
| 2232 | goto err; | ||
| 2233 | } | ||
| 2234 | /* p is pointing to somewhere in the buffer | ||
| 2235 | * currently, so set it to the start | ||
| 2236 | */ | ||
| 2237 | p=(unsigned char *)s->init_buf->data; | ||
| 2238 | } | ||
| 2239 | |||
| 2240 | /* Compute the shared pre-master secret */ | ||
| 2241 | field_size = EC_GROUP_get_degree(group); | ||
| 2242 | if (field_size <= 0) | ||
| 2243 | { | ||
| 2244 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, | ||
| 2245 | ERR_R_ECDH_LIB); | ||
| 2246 | goto err; | ||
| 2247 | } | ||
| 2248 | i = ECDH_compute_key(p, (field_size+7)/8, clnt_ecpoint, srvr_ecdh, NULL); | ||
| 2249 | if (i <= 0) | ||
| 2250 | { | ||
| 2251 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, | ||
| 2252 | ERR_R_ECDH_LIB); | ||
| 2253 | goto err; | ||
| 2254 | } | ||
| 2255 | |||
| 2256 | EVP_PKEY_free(clnt_pub_pkey); | ||
| 2257 | EC_POINT_free(clnt_ecpoint); | ||
| 2258 | if (srvr_ecdh != NULL) | ||
| 2259 | EC_KEY_free(srvr_ecdh); | ||
| 2260 | BN_CTX_free(bn_ctx); | ||
| 2261 | |||
| 2262 | /* Compute the master secret */ | ||
| 2263 | s->session->master_key_length = s->method->ssl3_enc-> \ | ||
| 2264 | generate_master_secret(s, s->session->master_key, p, i); | ||
| 2265 | |||
| 2266 | OPENSSL_cleanse(p, i); | ||
| 2267 | return (ret); | ||
| 2268 | } | ||
| 2269 | else | ||
| 2270 | #endif | ||
| 1747 | { | 2271 | { |
| 1748 | al=SSL_AD_HANDSHAKE_FAILURE; | 2272 | al=SSL_AD_HANDSHAKE_FAILURE; |
| 1749 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, | 2273 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, |
| @@ -1754,13 +2278,20 @@ static int ssl3_get_client_key_exchange(SSL *s) | |||
| 1754 | return(1); | 2278 | return(1); |
| 1755 | f_err: | 2279 | f_err: |
| 1756 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | 2280 | ssl3_send_alert(s,SSL3_AL_FATAL,al); |
| 1757 | #if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_RSA) | 2281 | #if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_ECDH) |
| 1758 | err: | 2282 | err: |
| 1759 | #endif | 2283 | #endif |
| 2284 | #ifndef OPENSSL_NO_ECDH | ||
| 2285 | EVP_PKEY_free(clnt_pub_pkey); | ||
| 2286 | EC_POINT_free(clnt_ecpoint); | ||
| 2287 | if (srvr_ecdh != NULL) | ||
| 2288 | EC_KEY_free(srvr_ecdh); | ||
| 2289 | BN_CTX_free(bn_ctx); | ||
| 2290 | #endif | ||
| 1760 | return(-1); | 2291 | return(-1); |
| 1761 | } | 2292 | } |
| 1762 | 2293 | ||
| 1763 | static int ssl3_get_cert_verify(SSL *s) | 2294 | int ssl3_get_cert_verify(SSL *s) |
| 1764 | { | 2295 | { |
| 1765 | EVP_PKEY *pkey=NULL; | 2296 | EVP_PKEY *pkey=NULL; |
| 1766 | unsigned char *p; | 2297 | unsigned char *p; |
| @@ -1769,7 +2300,7 @@ static int ssl3_get_cert_verify(SSL *s) | |||
| 1769 | int type=0,i,j; | 2300 | int type=0,i,j; |
| 1770 | X509 *peer; | 2301 | X509 *peer; |
| 1771 | 2302 | ||
| 1772 | n=ssl3_get_message(s, | 2303 | n=s->method->ssl_get_message(s, |
| 1773 | SSL3_ST_SR_CERT_VRFY_A, | 2304 | SSL3_ST_SR_CERT_VRFY_A, |
| 1774 | SSL3_ST_SR_CERT_VRFY_B, | 2305 | SSL3_ST_SR_CERT_VRFY_B, |
| 1775 | -1, | 2306 | -1, |
| @@ -1880,6 +2411,23 @@ static int ssl3_get_cert_verify(SSL *s) | |||
| 1880 | } | 2411 | } |
| 1881 | else | 2412 | else |
| 1882 | #endif | 2413 | #endif |
| 2414 | #ifndef OPENSSL_NO_ECDSA | ||
| 2415 | if (pkey->type == EVP_PKEY_EC) | ||
| 2416 | { | ||
| 2417 | j=ECDSA_verify(pkey->save_type, | ||
| 2418 | &(s->s3->tmp.cert_verify_md[MD5_DIGEST_LENGTH]), | ||
| 2419 | SHA_DIGEST_LENGTH,p,i,pkey->pkey.ec); | ||
| 2420 | if (j <= 0) | ||
| 2421 | { | ||
| 2422 | /* bad signature */ | ||
| 2423 | al=SSL_AD_DECRYPT_ERROR; | ||
| 2424 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY, | ||
| 2425 | SSL_R_BAD_ECDSA_SIGNATURE); | ||
| 2426 | goto f_err; | ||
| 2427 | } | ||
| 2428 | } | ||
| 2429 | else | ||
| 2430 | #endif | ||
| 1883 | { | 2431 | { |
| 1884 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,ERR_R_INTERNAL_ERROR); | 2432 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,ERR_R_INTERNAL_ERROR); |
| 1885 | al=SSL_AD_UNSUPPORTED_CERTIFICATE; | 2433 | al=SSL_AD_UNSUPPORTED_CERTIFICATE; |
| @@ -1898,15 +2446,16 @@ end: | |||
| 1898 | return(ret); | 2446 | return(ret); |
| 1899 | } | 2447 | } |
| 1900 | 2448 | ||
| 1901 | static int ssl3_get_client_certificate(SSL *s) | 2449 | int ssl3_get_client_certificate(SSL *s) |
| 1902 | { | 2450 | { |
| 1903 | int i,ok,al,ret= -1; | 2451 | int i,ok,al,ret= -1; |
| 1904 | X509 *x=NULL; | 2452 | X509 *x=NULL; |
| 1905 | unsigned long l,nc,llen,n; | 2453 | unsigned long l,nc,llen,n; |
| 1906 | unsigned char *p,*d,*q; | 2454 | const unsigned char *p,*q; |
| 2455 | unsigned char *d; | ||
| 1907 | STACK_OF(X509) *sk=NULL; | 2456 | STACK_OF(X509) *sk=NULL; |
| 1908 | 2457 | ||
| 1909 | n=ssl3_get_message(s, | 2458 | n=s->method->ssl_get_message(s, |
| 1910 | SSL3_ST_SR_CERT_A, | 2459 | SSL3_ST_SR_CERT_A, |
| 1911 | SSL3_ST_SR_CERT_B, | 2460 | SSL3_ST_SR_CERT_B, |
| 1912 | -1, | 2461 | -1, |
| @@ -1941,7 +2490,7 @@ static int ssl3_get_client_certificate(SSL *s) | |||
| 1941 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_WRONG_MESSAGE_TYPE); | 2490 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_WRONG_MESSAGE_TYPE); |
| 1942 | goto f_err; | 2491 | goto f_err; |
| 1943 | } | 2492 | } |
| 1944 | d=p=(unsigned char *)s->init_msg; | 2493 | p=d=(unsigned char *)s->init_msg; |
| 1945 | 2494 | ||
| 1946 | if ((sk=sk_X509_new_null()) == NULL) | 2495 | if ((sk=sk_X509_new_null()) == NULL) |
| 1947 | { | 2496 | { |
| @@ -2080,3 +2629,209 @@ int ssl3_send_server_certificate(SSL *s) | |||
| 2080 | /* SSL3_ST_SW_CERT_B */ | 2629 | /* SSL3_ST_SW_CERT_B */ |
| 2081 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | 2630 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); |
| 2082 | } | 2631 | } |
| 2632 | |||
| 2633 | |||
| 2634 | #ifndef OPENSSL_NO_ECDH | ||
| 2635 | /* This is the complement of curve_id2nid in s3_clnt.c. */ | ||
| 2636 | static int nid2curve_id(int nid) | ||
| 2637 | { | ||
| 2638 | /* ECC curves from draft-ietf-tls-ecc-01.txt (Mar 15, 2001) | ||
| 2639 | * (no changes in draft-ietf-tls-ecc-03.txt [June 2003]) */ | ||
| 2640 | switch (nid) { | ||
| 2641 | case NID_sect163k1: /* sect163k1 (1) */ | ||
| 2642 | return 1; | ||
| 2643 | case NID_sect163r1: /* sect163r1 (2) */ | ||
| 2644 | return 2; | ||
| 2645 | case NID_sect163r2: /* sect163r2 (3) */ | ||
| 2646 | return 3; | ||
| 2647 | case NID_sect193r1: /* sect193r1 (4) */ | ||
| 2648 | return 4; | ||
| 2649 | case NID_sect193r2: /* sect193r2 (5) */ | ||
| 2650 | return 5; | ||
| 2651 | case NID_sect233k1: /* sect233k1 (6) */ | ||
| 2652 | return 6; | ||
| 2653 | case NID_sect233r1: /* sect233r1 (7) */ | ||
| 2654 | return 7; | ||
| 2655 | case NID_sect239k1: /* sect239k1 (8) */ | ||
| 2656 | return 8; | ||
| 2657 | case NID_sect283k1: /* sect283k1 (9) */ | ||
| 2658 | return 9; | ||
| 2659 | case NID_sect283r1: /* sect283r1 (10) */ | ||
| 2660 | return 10; | ||
| 2661 | case NID_sect409k1: /* sect409k1 (11) */ | ||
| 2662 | return 11; | ||
| 2663 | case NID_sect409r1: /* sect409r1 (12) */ | ||
| 2664 | return 12; | ||
| 2665 | case NID_sect571k1: /* sect571k1 (13) */ | ||
| 2666 | return 13; | ||
| 2667 | case NID_sect571r1: /* sect571r1 (14) */ | ||
| 2668 | return 14; | ||
| 2669 | case NID_secp160k1: /* secp160k1 (15) */ | ||
| 2670 | return 15; | ||
| 2671 | case NID_secp160r1: /* secp160r1 (16) */ | ||
| 2672 | return 16; | ||
| 2673 | case NID_secp160r2: /* secp160r2 (17) */ | ||
| 2674 | return 17; | ||
| 2675 | case NID_secp192k1: /* secp192k1 (18) */ | ||
| 2676 | return 18; | ||
| 2677 | case NID_X9_62_prime192v1: /* secp192r1 (19) */ | ||
| 2678 | return 19; | ||
| 2679 | case NID_secp224k1: /* secp224k1 (20) */ | ||
| 2680 | return 20; | ||
| 2681 | case NID_secp224r1: /* secp224r1 (21) */ | ||
| 2682 | return 21; | ||
| 2683 | case NID_secp256k1: /* secp256k1 (22) */ | ||
| 2684 | return 22; | ||
| 2685 | case NID_X9_62_prime256v1: /* secp256r1 (23) */ | ||
| 2686 | return 23; | ||
| 2687 | case NID_secp384r1: /* secp384r1 (24) */ | ||
| 2688 | return 24; | ||
| 2689 | case NID_secp521r1: /* secp521r1 (25) */ | ||
| 2690 | return 25; | ||
| 2691 | default: | ||
| 2692 | return 0; | ||
| 2693 | } | ||
| 2694 | } | ||
| 2695 | #endif | ||
| 2696 | #ifndef OPENSSL_NO_TLSEXT | ||
| 2697 | int ssl3_send_newsession_ticket(SSL *s) | ||
| 2698 | { | ||
| 2699 | if (s->state == SSL3_ST_SW_SESSION_TICKET_A) | ||
| 2700 | { | ||
| 2701 | unsigned char *p, *senc, *macstart; | ||
| 2702 | int len, slen; | ||
| 2703 | unsigned int hlen; | ||
| 2704 | EVP_CIPHER_CTX ctx; | ||
| 2705 | HMAC_CTX hctx; | ||
| 2706 | unsigned char iv[EVP_MAX_IV_LENGTH]; | ||
| 2707 | unsigned char key_name[16]; | ||
| 2708 | |||
| 2709 | /* get session encoding length */ | ||
| 2710 | slen = i2d_SSL_SESSION(s->session, NULL); | ||
| 2711 | /* Some length values are 16 bits, so forget it if session is | ||
| 2712 | * too long | ||
| 2713 | */ | ||
| 2714 | if (slen > 0xFF00) | ||
| 2715 | return -1; | ||
| 2716 | /* Grow buffer if need be: the length calculation is as | ||
| 2717 | * follows 1 (size of message name) + 3 (message length | ||
| 2718 | * bytes) + 4 (ticket lifetime hint) + 2 (ticket length) + | ||
| 2719 | * 16 (key name) + max_iv_len (iv length) + | ||
| 2720 | * session_length + max_enc_block_size (max encrypted session | ||
| 2721 | * length) + max_md_size (HMAC). | ||
| 2722 | */ | ||
| 2723 | if (!BUF_MEM_grow(s->init_buf, | ||
| 2724 | 26 + EVP_MAX_IV_LENGTH + EVP_MAX_BLOCK_LENGTH + | ||
| 2725 | EVP_MAX_MD_SIZE + slen)) | ||
| 2726 | return -1; | ||
| 2727 | senc = OPENSSL_malloc(slen); | ||
| 2728 | if (!senc) | ||
| 2729 | return -1; | ||
| 2730 | p = senc; | ||
| 2731 | i2d_SSL_SESSION(s->session, &p); | ||
| 2732 | |||
| 2733 | p=(unsigned char *)s->init_buf->data; | ||
| 2734 | /* do the header */ | ||
| 2735 | *(p++)=SSL3_MT_NEWSESSION_TICKET; | ||
| 2736 | /* Skip message length for now */ | ||
| 2737 | p += 3; | ||
| 2738 | EVP_CIPHER_CTX_init(&ctx); | ||
| 2739 | HMAC_CTX_init(&hctx); | ||
| 2740 | /* Initialize HMAC and cipher contexts. If callback present | ||
| 2741 | * it does all the work otherwise use generated values | ||
| 2742 | * from parent ctx. | ||
| 2743 | */ | ||
| 2744 | if (s->ctx->tlsext_ticket_key_cb) | ||
| 2745 | { | ||
| 2746 | if (s->ctx->tlsext_ticket_key_cb(s, key_name, iv, &ctx, | ||
| 2747 | &hctx, 1) < 0) | ||
| 2748 | { | ||
| 2749 | OPENSSL_free(senc); | ||
| 2750 | return -1; | ||
| 2751 | } | ||
| 2752 | } | ||
| 2753 | else | ||
| 2754 | { | ||
| 2755 | RAND_pseudo_bytes(iv, 16); | ||
| 2756 | EVP_EncryptInit_ex(&ctx, EVP_aes_128_cbc(), NULL, | ||
| 2757 | s->ctx->tlsext_tick_aes_key, iv); | ||
| 2758 | HMAC_Init_ex(&hctx, s->ctx->tlsext_tick_hmac_key, 16, | ||
| 2759 | tlsext_tick_md(), NULL); | ||
| 2760 | memcpy(key_name, s->ctx->tlsext_tick_key_name, 16); | ||
| 2761 | } | ||
| 2762 | l2n(s->session->tlsext_tick_lifetime_hint, p); | ||
| 2763 | /* Skip ticket length for now */ | ||
| 2764 | p += 2; | ||
| 2765 | /* Output key name */ | ||
| 2766 | macstart = p; | ||
| 2767 | memcpy(p, key_name, 16); | ||
| 2768 | p += 16; | ||
| 2769 | /* output IV */ | ||
| 2770 | memcpy(p, iv, EVP_CIPHER_CTX_iv_length(&ctx)); | ||
| 2771 | p += EVP_CIPHER_CTX_iv_length(&ctx); | ||
| 2772 | /* Encrypt session data */ | ||
| 2773 | EVP_EncryptUpdate(&ctx, p, &len, senc, slen); | ||
| 2774 | p += len; | ||
| 2775 | EVP_EncryptFinal(&ctx, p, &len); | ||
| 2776 | p += len; | ||
| 2777 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
| 2778 | |||
| 2779 | HMAC_Update(&hctx, macstart, p - macstart); | ||
| 2780 | HMAC_Final(&hctx, p, &hlen); | ||
| 2781 | HMAC_CTX_cleanup(&hctx); | ||
| 2782 | |||
| 2783 | p += hlen; | ||
| 2784 | /* Now write out lengths: p points to end of data written */ | ||
| 2785 | /* Total length */ | ||
| 2786 | len = p - (unsigned char *)s->init_buf->data; | ||
| 2787 | p=(unsigned char *)s->init_buf->data + 1; | ||
| 2788 | l2n3(len - 4, p); /* Message length */ | ||
| 2789 | p += 4; | ||
| 2790 | s2n(len - 10, p); /* Ticket length */ | ||
| 2791 | |||
| 2792 | /* number of bytes to write */ | ||
| 2793 | s->init_num= len; | ||
| 2794 | s->state=SSL3_ST_SW_SESSION_TICKET_B; | ||
| 2795 | s->init_off=0; | ||
| 2796 | OPENSSL_free(senc); | ||
| 2797 | } | ||
| 2798 | |||
| 2799 | /* SSL3_ST_SW_SESSION_TICKET_B */ | ||
| 2800 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
| 2801 | } | ||
| 2802 | |||
| 2803 | int ssl3_send_cert_status(SSL *s) | ||
| 2804 | { | ||
| 2805 | if (s->state == SSL3_ST_SW_CERT_STATUS_A) | ||
| 2806 | { | ||
| 2807 | unsigned char *p; | ||
| 2808 | /* Grow buffer if need be: the length calculation is as | ||
| 2809 | * follows 1 (message type) + 3 (message length) + | ||
| 2810 | * 1 (ocsp response type) + 3 (ocsp response length) | ||
| 2811 | * + (ocsp response) | ||
| 2812 | */ | ||
| 2813 | if (!BUF_MEM_grow(s->init_buf, 8 + s->tlsext_ocsp_resplen)) | ||
| 2814 | return -1; | ||
| 2815 | |||
| 2816 | p=(unsigned char *)s->init_buf->data; | ||
| 2817 | |||
| 2818 | /* do the header */ | ||
| 2819 | *(p++)=SSL3_MT_CERTIFICATE_STATUS; | ||
| 2820 | /* message length */ | ||
| 2821 | l2n3(s->tlsext_ocsp_resplen + 4, p); | ||
| 2822 | /* status type */ | ||
| 2823 | *(p++)= s->tlsext_status_type; | ||
| 2824 | /* length of OCSP response */ | ||
| 2825 | l2n3(s->tlsext_ocsp_resplen, p); | ||
| 2826 | /* actual response */ | ||
| 2827 | memcpy(p, s->tlsext_ocsp_resp, s->tlsext_ocsp_resplen); | ||
| 2828 | /* number of bytes to write */ | ||
| 2829 | s->init_num = 8 + s->tlsext_ocsp_resplen; | ||
| 2830 | s->state=SSL3_ST_SW_CERT_STATUS_B; | ||
| 2831 | s->init_off = 0; | ||
| 2832 | } | ||
| 2833 | |||
| 2834 | /* SSL3_ST_SW_CERT_STATUS_B */ | ||
| 2835 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
| 2836 | } | ||
| 2837 | #endif | ||
diff --git a/src/lib/libssl/ssl.h b/src/lib/libssl/ssl.h index 99e188086b..6df921f3c1 100644 --- a/src/lib/libssl/ssl.h +++ b/src/lib/libssl/ssl.h | |||
| @@ -109,7 +109,7 @@ | |||
| 109 | * | 109 | * |
| 110 | */ | 110 | */ |
| 111 | /* ==================================================================== | 111 | /* ==================================================================== |
| 112 | * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. | 112 | * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved. |
| 113 | * | 113 | * |
| 114 | * Redistribution and use in source and binary forms, with or without | 114 | * Redistribution and use in source and binary forms, with or without |
| 115 | * modification, are permitted provided that the following conditions | 115 | * modification, are permitted provided that the following conditions |
| @@ -161,6 +161,11 @@ | |||
| 161 | * Hudson (tjh@cryptsoft.com). | 161 | * Hudson (tjh@cryptsoft.com). |
| 162 | * | 162 | * |
| 163 | */ | 163 | */ |
| 164 | /* ==================================================================== | ||
| 165 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
| 166 | * ECC cipher suite support in OpenSSL originally developed by | ||
| 167 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. | ||
| 168 | */ | ||
| 164 | 169 | ||
| 165 | #ifndef HEADER_SSL_H | 170 | #ifndef HEADER_SSL_H |
| 166 | #define HEADER_SSL_H | 171 | #define HEADER_SSL_H |
| @@ -173,9 +178,17 @@ | |||
| 173 | #ifndef OPENSSL_NO_BIO | 178 | #ifndef OPENSSL_NO_BIO |
| 174 | #include <openssl/bio.h> | 179 | #include <openssl/bio.h> |
| 175 | #endif | 180 | #endif |
| 181 | #ifndef OPENSSL_NO_DEPRECATED | ||
| 176 | #ifndef OPENSSL_NO_X509 | 182 | #ifndef OPENSSL_NO_X509 |
| 177 | #include <openssl/x509.h> | 183 | #include <openssl/x509.h> |
| 178 | #endif | 184 | #endif |
| 185 | #include <openssl/crypto.h> | ||
| 186 | #include <openssl/lhash.h> | ||
| 187 | #include <openssl/buffer.h> | ||
| 188 | #endif | ||
| 189 | #include <openssl/pem.h> | ||
| 190 | #include <openssl/hmac.h> | ||
| 191 | |||
| 179 | #include <openssl/kssl.h> | 192 | #include <openssl/kssl.h> |
| 180 | #include <openssl/safestack.h> | 193 | #include <openssl/safestack.h> |
| 181 | #include <openssl/symhacks.h> | 194 | #include <openssl/symhacks.h> |
| @@ -239,7 +252,6 @@ extern "C" { | |||
| 239 | #define SSL_TXT_LOW "LOW" | 252 | #define SSL_TXT_LOW "LOW" |
| 240 | #define SSL_TXT_MEDIUM "MEDIUM" | 253 | #define SSL_TXT_MEDIUM "MEDIUM" |
| 241 | #define SSL_TXT_HIGH "HIGH" | 254 | #define SSL_TXT_HIGH "HIGH" |
| 242 | #define SSL_TXT_FIPS "FIPS" | ||
| 243 | #define SSL_TXT_kFZA "kFZA" | 255 | #define SSL_TXT_kFZA "kFZA" |
| 244 | #define SSL_TXT_aFZA "aFZA" | 256 | #define SSL_TXT_aFZA "aFZA" |
| 245 | #define SSL_TXT_eFZA "eFZA" | 257 | #define SSL_TXT_eFZA "eFZA" |
| @@ -270,7 +282,9 @@ extern "C" { | |||
| 270 | #define SSL_TXT_RC4 "RC4" | 282 | #define SSL_TXT_RC4 "RC4" |
| 271 | #define SSL_TXT_RC2 "RC2" | 283 | #define SSL_TXT_RC2 "RC2" |
| 272 | #define SSL_TXT_IDEA "IDEA" | 284 | #define SSL_TXT_IDEA "IDEA" |
| 285 | #define SSL_TXT_SEED "SEED" | ||
| 273 | #define SSL_TXT_AES "AES" | 286 | #define SSL_TXT_AES "AES" |
| 287 | #define SSL_TXT_CAMELLIA "CAMELLIA" | ||
| 274 | #define SSL_TXT_MD5 "MD5" | 288 | #define SSL_TXT_MD5 "MD5" |
| 275 | #define SSL_TXT_SHA1 "SHA1" | 289 | #define SSL_TXT_SHA1 "SHA1" |
| 276 | #define SSL_TXT_SHA "SHA" | 290 | #define SSL_TXT_SHA "SHA" |
| @@ -282,6 +296,7 @@ extern "C" { | |||
| 282 | #define SSL_TXT_SSLV3 "SSLv3" | 296 | #define SSL_TXT_SSLV3 "SSLv3" |
| 283 | #define SSL_TXT_TLSV1 "TLSv1" | 297 | #define SSL_TXT_TLSV1 "TLSv1" |
| 284 | #define SSL_TXT_ALL "ALL" | 298 | #define SSL_TXT_ALL "ALL" |
| 299 | #define SSL_TXT_ECC "ECCdraft" /* ECC ciphersuites are not yet official */ | ||
| 285 | 300 | ||
| 286 | /* | 301 | /* |
| 287 | * COMPLEMENTOF* definitions. These identifiers are used to (de-select) | 302 | * COMPLEMENTOF* definitions. These identifiers are used to (de-select) |
| @@ -303,7 +318,7 @@ extern "C" { | |||
| 303 | /* The following cipher list is used by default. | 318 | /* The following cipher list is used by default. |
| 304 | * It also is substituted when an application-defined cipher list string | 319 | * It also is substituted when an application-defined cipher list string |
| 305 | * starts with 'DEFAULT'. */ | 320 | * starts with 'DEFAULT'. */ |
| 306 | #define SSL_DEFAULT_CIPHER_LIST "ALL:!ADH:+RC4:@STRENGTH" /* low priority for RC4 */ | 321 | #define SSL_DEFAULT_CIPHER_LIST "AES:ALL:!aNULL:!eNULL:+RC4:@STRENGTH" /* low priority for RC4 */ |
| 307 | 322 | ||
| 308 | /* Used in SSL_set_shutdown()/SSL_get_shutdown(); */ | 323 | /* Used in SSL_set_shutdown()/SSL_get_shutdown(); */ |
| 309 | #define SSL_SENT_SHUTDOWN 1 | 324 | #define SSL_SENT_SHUTDOWN 1 |
| @@ -313,11 +328,6 @@ extern "C" { | |||
| 313 | } | 328 | } |
| 314 | #endif | 329 | #endif |
| 315 | 330 | ||
| 316 | #include <openssl/crypto.h> | ||
| 317 | #include <openssl/lhash.h> | ||
| 318 | #include <openssl/buffer.h> | ||
| 319 | #include <openssl/pem.h> | ||
| 320 | |||
| 321 | #ifdef __cplusplus | 331 | #ifdef __cplusplus |
| 322 | extern "C" { | 332 | extern "C" { |
| 323 | #endif | 333 | #endif |
| @@ -369,6 +379,12 @@ typedef struct ssl_method_st | |||
| 369 | int (*ssl_shutdown)(SSL *s); | 379 | int (*ssl_shutdown)(SSL *s); |
| 370 | int (*ssl_renegotiate)(SSL *s); | 380 | int (*ssl_renegotiate)(SSL *s); |
| 371 | int (*ssl_renegotiate_check)(SSL *s); | 381 | int (*ssl_renegotiate_check)(SSL *s); |
| 382 | long (*ssl_get_message)(SSL *s, int st1, int stn, int mt, long | ||
| 383 | max, int *ok); | ||
| 384 | int (*ssl_read_bytes)(SSL *s, int type, unsigned char *buf, int len, | ||
| 385 | int peek); | ||
| 386 | int (*ssl_write_bytes)(SSL *s, int type, const void *buf_, int len); | ||
| 387 | int (*ssl_dispatch_alert)(SSL *s); | ||
| 372 | long (*ssl_ctrl)(SSL *s,int cmd,long larg,void *parg); | 388 | long (*ssl_ctrl)(SSL *s,int cmd,long larg,void *parg); |
| 373 | long (*ssl_ctx_ctrl)(SSL_CTX *ctx,int cmd,long larg,void *parg); | 389 | long (*ssl_ctx_ctrl)(SSL_CTX *ctx,int cmd,long larg,void *parg); |
| 374 | SSL_CIPHER *(*get_cipher_by_char)(const unsigned char *ptr); | 390 | SSL_CIPHER *(*get_cipher_by_char)(const unsigned char *ptr); |
| @@ -379,9 +395,9 @@ typedef struct ssl_method_st | |||
| 379 | struct ssl_method_st *(*get_ssl_method)(int version); | 395 | struct ssl_method_st *(*get_ssl_method)(int version); |
| 380 | long (*get_timeout)(void); | 396 | long (*get_timeout)(void); |
| 381 | struct ssl3_enc_method *ssl3_enc; /* Extra SSLv3/TLS stuff */ | 397 | struct ssl3_enc_method *ssl3_enc; /* Extra SSLv3/TLS stuff */ |
| 382 | int (*ssl_version)(); | 398 | int (*ssl_version)(void); |
| 383 | long (*ssl_callback_ctrl)(SSL *s, int cb_id, void (*fp)()); | 399 | long (*ssl_callback_ctrl)(SSL *s, int cb_id, void (*fp)(void)); |
| 384 | long (*ssl_ctx_callback_ctrl)(SSL_CTX *s, int cb_id, void (*fp)()); | 400 | long (*ssl_ctx_callback_ctrl)(SSL_CTX *s, int cb_id, void (*fp)(void)); |
| 385 | } SSL_METHOD; | 401 | } SSL_METHOD; |
| 386 | 402 | ||
| 387 | /* Lets make this into an ASN.1 type structure as follows | 403 | /* Lets make this into an ASN.1 type structure as follows |
| @@ -459,6 +475,13 @@ typedef struct ssl_session_st | |||
| 459 | /* These are used to make removal of session-ids more | 475 | /* These are used to make removal of session-ids more |
| 460 | * efficient and to implement a maximum cache size. */ | 476 | * efficient and to implement a maximum cache size. */ |
| 461 | struct ssl_session_st *prev,*next; | 477 | struct ssl_session_st *prev,*next; |
| 478 | #ifndef OPENSSL_NO_TLSEXT | ||
| 479 | char *tlsext_hostname; | ||
| 480 | /* RFC4507 info */ | ||
| 481 | unsigned char *tlsext_tick; /* Session ticket */ | ||
| 482 | size_t tlsext_ticklen; /* Session ticket length */ | ||
| 483 | long tlsext_tick_lifetime_hint; /* Session lifetime hint in seconds */ | ||
| 484 | #endif | ||
| 462 | } SSL_SESSION; | 485 | } SSL_SESSION; |
| 463 | 486 | ||
| 464 | 487 | ||
| @@ -483,8 +506,17 @@ typedef struct ssl_session_st | |||
| 483 | * This used to be 0x000FFFFFL before 0.9.7. */ | 506 | * This used to be 0x000FFFFFL before 0.9.7. */ |
| 484 | #define SSL_OP_ALL 0x00000FFFL | 507 | #define SSL_OP_ALL 0x00000FFFL |
| 485 | 508 | ||
| 509 | /* DTLS options */ | ||
| 510 | #define SSL_OP_NO_QUERY_MTU 0x00001000L | ||
| 511 | /* Turn on Cookie Exchange (on relevant for servers) */ | ||
| 512 | #define SSL_OP_COOKIE_EXCHANGE 0x00002000L | ||
| 513 | /* Don't use RFC4507 ticket extension */ | ||
| 514 | #define SSL_OP_NO_TICKET 0x00004000L | ||
| 515 | |||
| 486 | /* As server, disallow session resumption on renegotiation */ | 516 | /* As server, disallow session resumption on renegotiation */ |
| 487 | #define SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION 0x00010000L | 517 | #define SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION 0x00010000L |
| 518 | /* If set, always create a new key when using tmp_ecdh parameters */ | ||
| 519 | #define SSL_OP_SINGLE_ECDH_USE 0x00080000L | ||
| 488 | /* If set, always create a new key when using tmp_dh parameters */ | 520 | /* If set, always create a new key when using tmp_dh parameters */ |
| 489 | #define SSL_OP_SINGLE_DH_USE 0x00100000L | 521 | #define SSL_OP_SINGLE_DH_USE 0x00100000L |
| 490 | /* Set to always use the tmp_rsa key when doing RSA operations, | 522 | /* Set to always use the tmp_rsa key when doing RSA operations, |
| @@ -546,6 +578,8 @@ typedef struct ssl_session_st | |||
| 546 | SSL_ctrl((ssl),SSL_CTRL_MODE,(op),NULL) | 578 | SSL_ctrl((ssl),SSL_CTRL_MODE,(op),NULL) |
| 547 | #define SSL_get_mode(ssl) \ | 579 | #define SSL_get_mode(ssl) \ |
| 548 | SSL_ctrl((ssl),SSL_CTRL_MODE,0,NULL) | 580 | SSL_ctrl((ssl),SSL_CTRL_MODE,0,NULL) |
| 581 | #define SSL_set_mtu(ssl, mtu) \ | ||
| 582 | SSL_ctrl((ssl),SSL_CTRL_SET_MTU,(mtu),NULL) | ||
| 549 | 583 | ||
| 550 | 584 | ||
| 551 | void SSL_CTX_set_msg_callback(SSL_CTX *ctx, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg)); | 585 | void SSL_CTX_set_msg_callback(SSL_CTX *ctx, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg)); |
| @@ -582,7 +616,7 @@ typedef int (*GEN_SESSION_CB)(const SSL *ssl, unsigned char *id, | |||
| 582 | typedef struct ssl_comp_st | 616 | typedef struct ssl_comp_st |
| 583 | { | 617 | { |
| 584 | int id; | 618 | int id; |
| 585 | char *name; | 619 | const char *name; |
| 586 | #ifndef OPENSSL_NO_COMP | 620 | #ifndef OPENSSL_NO_COMP |
| 587 | COMP_METHOD *method; | 621 | COMP_METHOD *method; |
| 588 | #else | 622 | #else |
| @@ -670,6 +704,14 @@ struct ssl_ctx_st | |||
| 670 | /* get client cert callback */ | 704 | /* get client cert callback */ |
| 671 | int (*client_cert_cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey); | 705 | int (*client_cert_cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey); |
| 672 | 706 | ||
| 707 | /* cookie generate callback */ | ||
| 708 | int (*app_gen_cookie_cb)(SSL *ssl, unsigned char *cookie, | ||
| 709 | unsigned int *cookie_len); | ||
| 710 | |||
| 711 | /* verify cookie callback */ | ||
| 712 | int (*app_verify_cookie_cb)(SSL *ssl, unsigned char *cookie, | ||
| 713 | unsigned int cookie_len); | ||
| 714 | |||
| 673 | CRYPTO_EX_DATA ex_data; | 715 | CRYPTO_EX_DATA ex_data; |
| 674 | 716 | ||
| 675 | const EVP_MD *rsa_md5;/* For SSLv2 - name is 'ssl2-md5' */ | 717 | const EVP_MD *rsa_md5;/* For SSLv2 - name is 'ssl2-md5' */ |
| @@ -702,7 +744,6 @@ struct ssl_ctx_st | |||
| 702 | void *msg_callback_arg; | 744 | void *msg_callback_arg; |
| 703 | 745 | ||
| 704 | int verify_mode; | 746 | int verify_mode; |
| 705 | int verify_depth; | ||
| 706 | unsigned int sid_ctx_length; | 747 | unsigned int sid_ctx_length; |
| 707 | unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH]; | 748 | unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH]; |
| 708 | int (*default_verify_callback)(int ok,X509_STORE_CTX *ctx); /* called 'verify_callback' in the SSL */ | 749 | int (*default_verify_callback)(int ok,X509_STORE_CTX *ctx); /* called 'verify_callback' in the SSL */ |
| @@ -710,10 +751,35 @@ struct ssl_ctx_st | |||
| 710 | /* Default generate session ID callback. */ | 751 | /* Default generate session ID callback. */ |
| 711 | GEN_SESSION_CB generate_session_id; | 752 | GEN_SESSION_CB generate_session_id; |
| 712 | 753 | ||
| 754 | X509_VERIFY_PARAM *param; | ||
| 755 | |||
| 756 | #if 0 | ||
| 713 | int purpose; /* Purpose setting */ | 757 | int purpose; /* Purpose setting */ |
| 714 | int trust; /* Trust setting */ | 758 | int trust; /* Trust setting */ |
| 759 | #endif | ||
| 715 | 760 | ||
| 716 | int quiet_shutdown; | 761 | int quiet_shutdown; |
| 762 | |||
| 763 | #ifndef OPENSSL_NO_TLSEXT | ||
| 764 | /* TLS extensions servername callback */ | ||
| 765 | int (*tlsext_servername_callback)(SSL*, int *, void *); | ||
| 766 | void *tlsext_servername_arg; | ||
| 767 | /* RFC 4507 session ticket keys */ | ||
| 768 | unsigned char tlsext_tick_key_name[16]; | ||
| 769 | unsigned char tlsext_tick_hmac_key[16]; | ||
| 770 | unsigned char tlsext_tick_aes_key[16]; | ||
| 771 | /* Callback to support customisation of ticket key setting */ | ||
| 772 | int (*tlsext_ticket_key_cb)(SSL *ssl, | ||
| 773 | unsigned char *name, unsigned char *iv, | ||
| 774 | EVP_CIPHER_CTX *ectx, | ||
| 775 | HMAC_CTX *hctx, int enc); | ||
| 776 | |||
| 777 | /* certificate status request info */ | ||
| 778 | /* Callback for status request */ | ||
| 779 | int (*tlsext_status_cb)(SSL *ssl, void *arg); | ||
| 780 | void *tlsext_status_arg; | ||
| 781 | #endif | ||
| 782 | |||
| 717 | }; | 783 | }; |
| 718 | 784 | ||
| 719 | #define SSL_SESS_CACHE_OFF 0x0000 | 785 | #define SSL_SESS_CACHE_OFF 0x0000 |
| @@ -753,16 +819,18 @@ struct ssl_ctx_st | |||
| 753 | #define SSL_CTX_sess_cache_full(ctx) \ | 819 | #define SSL_CTX_sess_cache_full(ctx) \ |
| 754 | SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CACHE_FULL,0,NULL) | 820 | SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CACHE_FULL,0,NULL) |
| 755 | 821 | ||
| 756 | #define SSL_CTX_sess_set_new_cb(ctx,cb) ((ctx)->new_session_cb=(cb)) | 822 | void SSL_CTX_sess_set_new_cb(SSL_CTX *ctx, int (*new_session_cb)(struct ssl_st *ssl,SSL_SESSION *sess)); |
| 757 | #define SSL_CTX_sess_get_new_cb(ctx) ((ctx)->new_session_cb) | 823 | int (*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx))(struct ssl_st *ssl, SSL_SESSION *sess); |
| 758 | #define SSL_CTX_sess_set_remove_cb(ctx,cb) ((ctx)->remove_session_cb=(cb)) | 824 | void SSL_CTX_sess_set_remove_cb(SSL_CTX *ctx, void (*remove_session_cb)(struct ssl_ctx_st *ctx,SSL_SESSION *sess)); |
| 759 | #define SSL_CTX_sess_get_remove_cb(ctx) ((ctx)->remove_session_cb) | 825 | void (*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx))(struct ssl_ctx_st *ctx, SSL_SESSION *sess); |
| 760 | #define SSL_CTX_sess_set_get_cb(ctx,cb) ((ctx)->get_session_cb=(cb)) | 826 | void SSL_CTX_sess_set_get_cb(SSL_CTX *ctx, SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl, unsigned char *data,int len,int *copy)); |
| 761 | #define SSL_CTX_sess_get_get_cb(ctx) ((ctx)->get_session_cb) | 827 | SSL_SESSION *(*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx))(struct ssl_st *ssl, unsigned char *Data, int len, int *copy); |
| 762 | #define SSL_CTX_set_info_callback(ctx,cb) ((ctx)->info_callback=(cb)) | 828 | void SSL_CTX_set_info_callback(SSL_CTX *ctx, void (*cb)(const SSL *ssl,int type,int val)); |
| 763 | #define SSL_CTX_get_info_callback(ctx) ((ctx)->info_callback) | 829 | void (*SSL_CTX_get_info_callback(SSL_CTX *ctx))(const SSL *ssl,int type,int val); |
| 764 | #define SSL_CTX_set_client_cert_cb(ctx,cb) ((ctx)->client_cert_cb=(cb)) | 830 | void SSL_CTX_set_client_cert_cb(SSL_CTX *ctx, int (*client_cert_cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey)); |
| 765 | #define SSL_CTX_get_client_cert_cb(ctx) ((ctx)->client_cert_cb) | 831 | int (*SSL_CTX_get_client_cert_cb(SSL_CTX *ctx))(SSL *ssl, X509 **x509, EVP_PKEY **pkey); |
| 832 | void SSL_CTX_set_cookie_generate_cb(SSL_CTX *ctx, int (*app_gen_cookie_cb)(SSL *ssl, unsigned char *cookie, unsigned int *cookie_len)); | ||
| 833 | void SSL_CTX_set_cookie_verify_cb(SSL_CTX *ctx, int (*app_verify_cookie_cb)(SSL *ssl, unsigned char *cookie, unsigned int cookie_len)); | ||
| 766 | 834 | ||
| 767 | #define SSL_NOTHING 1 | 835 | #define SSL_NOTHING 1 |
| 768 | #define SSL_WRITING 2 | 836 | #define SSL_WRITING 2 |
| @@ -778,7 +846,7 @@ struct ssl_ctx_st | |||
| 778 | struct ssl_st | 846 | struct ssl_st |
| 779 | { | 847 | { |
| 780 | /* protocol version | 848 | /* protocol version |
| 781 | * (one of SSL2_VERSION, SSL3_VERSION, TLS1_VERSION) | 849 | * (one of SSL2_VERSION, SSL3_VERSION, TLS1_VERSION, DTLS1_VERSION) |
| 782 | */ | 850 | */ |
| 783 | int version; | 851 | int version; |
| 784 | int type; /* SSL_ST_CONNECT or SSL_ST_ACCEPT */ | 852 | int type; /* SSL_ST_CONNECT or SSL_ST_ACCEPT */ |
| @@ -807,7 +875,7 @@ struct ssl_st | |||
| 807 | 875 | ||
| 808 | /* true when we are actually in SSL_accept() or SSL_connect() */ | 876 | /* true when we are actually in SSL_accept() or SSL_connect() */ |
| 809 | int in_handshake; | 877 | int in_handshake; |
| 810 | int (*handshake_func)(); | 878 | int (*handshake_func)(SSL *); |
| 811 | 879 | ||
| 812 | /* Imagine that here's a boolean member "init" that is | 880 | /* Imagine that here's a boolean member "init" that is |
| 813 | * switched as soon as SSL_set_{accept/connect}_state | 881 | * switched as soon as SSL_set_{accept/connect}_state |
| @@ -842,6 +910,7 @@ struct ssl_st | |||
| 842 | 910 | ||
| 843 | struct ssl2_state_st *s2; /* SSLv2 variables */ | 911 | struct ssl2_state_st *s2; /* SSLv2 variables */ |
| 844 | struct ssl3_state_st *s3; /* SSLv3 variables */ | 912 | struct ssl3_state_st *s3; /* SSLv3 variables */ |
| 913 | struct dtls1_state_st *d1; /* DTLSv1 variables */ | ||
| 845 | 914 | ||
| 846 | int read_ahead; /* Read as many input bytes as possible | 915 | int read_ahead; /* Read as many input bytes as possible |
| 847 | * (for non-blocking reads) */ | 916 | * (for non-blocking reads) */ |
| @@ -852,8 +921,12 @@ struct ssl_st | |||
| 852 | 921 | ||
| 853 | int hit; /* reusing a previous session */ | 922 | int hit; /* reusing a previous session */ |
| 854 | 923 | ||
| 924 | X509_VERIFY_PARAM *param; | ||
| 925 | |||
| 926 | #if 0 | ||
| 855 | int purpose; /* Purpose setting */ | 927 | int purpose; /* Purpose setting */ |
| 856 | int trust; /* Trust setting */ | 928 | int trust; /* Trust setting */ |
| 929 | #endif | ||
| 857 | 930 | ||
| 858 | /* crypto */ | 931 | /* crypto */ |
| 859 | STACK_OF(SSL_CIPHER) *cipher_list; | 932 | STACK_OF(SSL_CIPHER) *cipher_list; |
| @@ -898,7 +971,6 @@ struct ssl_st | |||
| 898 | /* Used in SSL2 and SSL3 */ | 971 | /* Used in SSL2 and SSL3 */ |
| 899 | int verify_mode; /* 0 don't care about verify failure. | 972 | int verify_mode; /* 0 don't care about verify failure. |
| 900 | * 1 fail if verify fails */ | 973 | * 1 fail if verify fails */ |
| 901 | int verify_depth; | ||
| 902 | int (*verify_callback)(int ok,X509_STORE_CTX *ctx); /* fail if callback returns 0 */ | 974 | int (*verify_callback)(int ok,X509_STORE_CTX *ctx); /* fail if callback returns 0 */ |
| 903 | 975 | ||
| 904 | void (*info_callback)(const SSL *ssl,int type,int val); /* optional informational callback */ | 976 | void (*info_callback)(const SSL *ssl,int type,int val); /* optional informational callback */ |
| @@ -929,6 +1001,37 @@ struct ssl_st | |||
| 929 | int first_packet; | 1001 | int first_packet; |
| 930 | int client_version; /* what was passed, used for | 1002 | int client_version; /* what was passed, used for |
| 931 | * SSLv3/TLS rollback check */ | 1003 | * SSLv3/TLS rollback check */ |
| 1004 | #ifndef OPENSSL_NO_TLSEXT | ||
| 1005 | /* TLS extension debug callback */ | ||
| 1006 | void (*tlsext_debug_cb)(SSL *s, int client_server, int type, | ||
| 1007 | unsigned char *data, int len, | ||
| 1008 | void *arg); | ||
| 1009 | void *tlsext_debug_arg; | ||
| 1010 | char *tlsext_hostname; | ||
| 1011 | int servername_done; /* no further mod of servername | ||
| 1012 | 0 : call the servername extension callback. | ||
| 1013 | 1 : prepare 2, allow last ack just after in server callback. | ||
| 1014 | 2 : don't call servername callback, no ack in server hello | ||
| 1015 | */ | ||
| 1016 | /* certificate status request info */ | ||
| 1017 | /* Status type or -1 if no status type */ | ||
| 1018 | int tlsext_status_type; | ||
| 1019 | /* Expect OCSP CertificateStatus message */ | ||
| 1020 | int tlsext_status_expected; | ||
| 1021 | /* OCSP status request only */ | ||
| 1022 | STACK_OF(OCSP_RESPID) *tlsext_ocsp_ids; | ||
| 1023 | X509_EXTENSIONS *tlsext_ocsp_exts; | ||
| 1024 | /* OCSP response received or to be sent */ | ||
| 1025 | unsigned char *tlsext_ocsp_resp; | ||
| 1026 | int tlsext_ocsp_resplen; | ||
| 1027 | |||
| 1028 | /* RFC4507 session ticket expected to be received or sent */ | ||
| 1029 | int tlsext_ticket_expected; | ||
| 1030 | SSL_CTX * initial_ctx; /* initial ctx, used to store sessions */ | ||
| 1031 | #define session_ctx initial_ctx | ||
| 1032 | #else | ||
| 1033 | #define session_ctx ctx | ||
| 1034 | #endif | ||
| 932 | }; | 1035 | }; |
| 933 | 1036 | ||
| 934 | #ifdef __cplusplus | 1037 | #ifdef __cplusplus |
| @@ -938,6 +1041,7 @@ struct ssl_st | |||
| 938 | #include <openssl/ssl2.h> | 1041 | #include <openssl/ssl2.h> |
| 939 | #include <openssl/ssl3.h> | 1042 | #include <openssl/ssl3.h> |
| 940 | #include <openssl/tls1.h> /* This is mostly sslv3 with a few tweaks */ | 1043 | #include <openssl/tls1.h> /* This is mostly sslv3 with a few tweaks */ |
| 1044 | #include <openssl/dtls1.h> /* Datagram TLS */ | ||
| 941 | #include <openssl/ssl23.h> | 1045 | #include <openssl/ssl23.h> |
| 942 | 1046 | ||
| 943 | #ifdef __cplusplus | 1047 | #ifdef __cplusplus |
| @@ -1035,21 +1139,16 @@ size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count); | |||
| 1035 | #define SSL_set_timeout(a,b) SSL_SESSION_set_timeout((a),(b)) | 1139 | #define SSL_set_timeout(a,b) SSL_SESSION_set_timeout((a),(b)) |
| 1036 | 1140 | ||
| 1037 | #if 1 /*SSLEAY_MACROS*/ | 1141 | #if 1 /*SSLEAY_MACROS*/ |
| 1038 | #define d2i_SSL_SESSION_bio(bp,s_id) (SSL_SESSION *)ASN1_d2i_bio( \ | 1142 | #define d2i_SSL_SESSION_bio(bp,s_id) ASN1_d2i_bio_of(SSL_SESSION,SSL_SESSION_new,d2i_SSL_SESSION,bp,s_id) |
| 1039 | (char *(*)())SSL_SESSION_new,(char *(*)())d2i_SSL_SESSION, \ | 1143 | #define i2d_SSL_SESSION_bio(bp,s_id) ASN1_i2d_bio_of(SSL_SESSION,i2d_SSL_SESSION,bp,s_id) |
| 1040 | (bp),(unsigned char **)(s_id)) | ||
| 1041 | #define i2d_SSL_SESSION_bio(bp,s_id) ASN1_i2d_bio(i2d_SSL_SESSION, \ | ||
| 1042 | bp,(unsigned char *)s_id) | ||
| 1043 | #define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \ | 1144 | #define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \ |
| 1044 | (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u) | 1145 | (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u) |
| 1045 | #define PEM_read_bio_SSL_SESSION(bp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read_bio( \ | 1146 | #define PEM_read_bio_SSL_SESSION(bp,x,cb,u) PEM_ASN1_read_bio_of(SSL_SESSION,d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,x,cb,u) |
| 1046 | (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb,u) | ||
| 1047 | #define PEM_write_SSL_SESSION(fp,x) \ | 1147 | #define PEM_write_SSL_SESSION(fp,x) \ |
| 1048 | PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \ | 1148 | PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \ |
| 1049 | PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL) | 1149 | PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL) |
| 1050 | #define PEM_write_bio_SSL_SESSION(bp,x) \ | 1150 | #define PEM_write_bio_SSL_SESSION(bp,x) \ |
| 1051 | PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \ | 1151 | PEM_ASN1_write_bio_of(SSL_SESSION,i2d_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,x,NULL,NULL,0,NULL,NULL) |
| 1052 | PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL,NULL) | ||
| 1053 | #endif | 1152 | #endif |
| 1054 | 1153 | ||
| 1055 | #define SSL_AD_REASON_OFFSET 1000 | 1154 | #define SSL_AD_REASON_OFFSET 1000 |
| @@ -1078,6 +1177,10 @@ size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count); | |||
| 1078 | #define SSL_AD_INTERNAL_ERROR TLS1_AD_INTERNAL_ERROR /* fatal */ | 1177 | #define SSL_AD_INTERNAL_ERROR TLS1_AD_INTERNAL_ERROR /* fatal */ |
| 1079 | #define SSL_AD_USER_CANCELLED TLS1_AD_USER_CANCELLED | 1178 | #define SSL_AD_USER_CANCELLED TLS1_AD_USER_CANCELLED |
| 1080 | #define SSL_AD_NO_RENEGOTIATION TLS1_AD_NO_RENEGOTIATION | 1179 | #define SSL_AD_NO_RENEGOTIATION TLS1_AD_NO_RENEGOTIATION |
| 1180 | #define SSL_AD_UNSUPPORTED_EXTENSION TLS1_AD_UNSUPPORTED_EXTENSION | ||
| 1181 | #define SSL_AD_CERTIFICATE_UNOBTAINABLE TLS1_AD_CERTIFICATE_UNOBTAINABLE | ||
| 1182 | #define SSL_AD_UNRECOGNIZED_NAME TLS1_AD_UNRECOGNIZED_NAME | ||
| 1183 | #define SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE | ||
| 1081 | 1184 | ||
| 1082 | #define SSL_ERROR_NONE 0 | 1185 | #define SSL_ERROR_NONE 0 |
| 1083 | #define SSL_ERROR_SSL 1 | 1186 | #define SSL_ERROR_SSL 1 |
| @@ -1092,20 +1195,24 @@ size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count); | |||
| 1092 | #define SSL_CTRL_NEED_TMP_RSA 1 | 1195 | #define SSL_CTRL_NEED_TMP_RSA 1 |
| 1093 | #define SSL_CTRL_SET_TMP_RSA 2 | 1196 | #define SSL_CTRL_SET_TMP_RSA 2 |
| 1094 | #define SSL_CTRL_SET_TMP_DH 3 | 1197 | #define SSL_CTRL_SET_TMP_DH 3 |
| 1095 | #define SSL_CTRL_SET_TMP_RSA_CB 4 | 1198 | #define SSL_CTRL_SET_TMP_ECDH 4 |
| 1096 | #define SSL_CTRL_SET_TMP_DH_CB 5 | 1199 | #define SSL_CTRL_SET_TMP_RSA_CB 5 |
| 1097 | 1200 | #define SSL_CTRL_SET_TMP_DH_CB 6 | |
| 1098 | #define SSL_CTRL_GET_SESSION_REUSED 6 | 1201 | #define SSL_CTRL_SET_TMP_ECDH_CB 7 |
| 1099 | #define SSL_CTRL_GET_CLIENT_CERT_REQUEST 7 | 1202 | |
| 1100 | #define SSL_CTRL_GET_NUM_RENEGOTIATIONS 8 | 1203 | #define SSL_CTRL_GET_SESSION_REUSED 8 |
| 1101 | #define SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS 9 | 1204 | #define SSL_CTRL_GET_CLIENT_CERT_REQUEST 9 |
| 1102 | #define SSL_CTRL_GET_TOTAL_RENEGOTIATIONS 10 | 1205 | #define SSL_CTRL_GET_NUM_RENEGOTIATIONS 10 |
| 1103 | #define SSL_CTRL_GET_FLAGS 11 | 1206 | #define SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS 11 |
| 1104 | #define SSL_CTRL_EXTRA_CHAIN_CERT 12 | 1207 | #define SSL_CTRL_GET_TOTAL_RENEGOTIATIONS 12 |
| 1105 | 1208 | #define SSL_CTRL_GET_FLAGS 13 | |
| 1106 | #define SSL_CTRL_SET_MSG_CALLBACK 13 | 1209 | #define SSL_CTRL_EXTRA_CHAIN_CERT 14 |
| 1107 | #define SSL_CTRL_SET_MSG_CALLBACK_ARG 14 | 1210 | |
| 1108 | 1211 | #define SSL_CTRL_SET_MSG_CALLBACK 15 | |
| 1212 | #define SSL_CTRL_SET_MSG_CALLBACK_ARG 16 | ||
| 1213 | |||
| 1214 | /* only applies to datagram connections */ | ||
| 1215 | #define SSL_CTRL_SET_MTU 17 | ||
| 1109 | /* Stats */ | 1216 | /* Stats */ |
| 1110 | #define SSL_CTRL_SESS_NUMBER 20 | 1217 | #define SSL_CTRL_SESS_NUMBER 20 |
| 1111 | #define SSL_CTRL_SESS_CONNECT 21 | 1218 | #define SSL_CTRL_SESS_CONNECT 21 |
| @@ -1132,6 +1239,29 @@ size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count); | |||
| 1132 | #define SSL_CTRL_GET_MAX_CERT_LIST 50 | 1239 | #define SSL_CTRL_GET_MAX_CERT_LIST 50 |
| 1133 | #define SSL_CTRL_SET_MAX_CERT_LIST 51 | 1240 | #define SSL_CTRL_SET_MAX_CERT_LIST 51 |
| 1134 | 1241 | ||
| 1242 | /* see tls1.h for macros based on these */ | ||
| 1243 | #ifndef OPENSSL_NO_TLSEXT | ||
| 1244 | #define SSL_CTRL_SET_TLSEXT_SERVERNAME_CB 53 | ||
| 1245 | #define SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG 54 | ||
| 1246 | #define SSL_CTRL_SET_TLSEXT_HOSTNAME 55 | ||
| 1247 | #define SSL_CTRL_SET_TLSEXT_DEBUG_CB 56 | ||
| 1248 | #define SSL_CTRL_SET_TLSEXT_DEBUG_ARG 57 | ||
| 1249 | #define SSL_CTRL_GET_TLSEXT_TICKET_KEYS 58 | ||
| 1250 | #define SSL_CTRL_SET_TLSEXT_TICKET_KEYS 59 | ||
| 1251 | |||
| 1252 | #define SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB 63 | ||
| 1253 | #define SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG 64 | ||
| 1254 | #define SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE 65 | ||
| 1255 | #define SSL_CTRL_GET_TLSEXT_STATUS_REQ_EXTS 66 | ||
| 1256 | #define SSL_CTRL_SET_TLSEXT_STATUS_REQ_EXTS 67 | ||
| 1257 | #define SSL_CTRL_GET_TLSEXT_STATUS_REQ_IDS 68 | ||
| 1258 | #define SSL_CTRL_SET_TLSEXT_STATUS_REQ_IDS 69 | ||
| 1259 | #define SSL_CTRL_GET_TLSEXT_STATUS_REQ_OCSP_RESP 70 | ||
| 1260 | #define SSL_CTRL_SET_TLSEXT_STATUS_REQ_OCSP_RESP 71 | ||
| 1261 | |||
| 1262 | #define SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB 72 | ||
| 1263 | #endif | ||
| 1264 | |||
| 1135 | #define SSL_session_reused(ssl) \ | 1265 | #define SSL_session_reused(ssl) \ |
| 1136 | SSL_ctrl((ssl),SSL_CTRL_GET_SESSION_REUSED,0,NULL) | 1266 | SSL_ctrl((ssl),SSL_CTRL_GET_SESSION_REUSED,0,NULL) |
| 1137 | #define SSL_num_renegotiations(ssl) \ | 1267 | #define SSL_num_renegotiations(ssl) \ |
| @@ -1147,6 +1277,8 @@ size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count); | |||
| 1147 | SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa) | 1277 | SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa) |
| 1148 | #define SSL_CTX_set_tmp_dh(ctx,dh) \ | 1278 | #define SSL_CTX_set_tmp_dh(ctx,dh) \ |
| 1149 | SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH,0,(char *)dh) | 1279 | SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH,0,(char *)dh) |
| 1280 | #define SSL_CTX_set_tmp_ecdh(ctx,ecdh) \ | ||
| 1281 | SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_ECDH,0,(char *)ecdh) | ||
| 1150 | 1282 | ||
| 1151 | #define SSL_need_tmp_RSA(ssl) \ | 1283 | #define SSL_need_tmp_RSA(ssl) \ |
| 1152 | SSL_ctrl(ssl,SSL_CTRL_NEED_TMP_RSA,0,NULL) | 1284 | SSL_ctrl(ssl,SSL_CTRL_NEED_TMP_RSA,0,NULL) |
| @@ -1154,6 +1286,8 @@ size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count); | |||
| 1154 | SSL_ctrl(ssl,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa) | 1286 | SSL_ctrl(ssl,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa) |
| 1155 | #define SSL_set_tmp_dh(ssl,dh) \ | 1287 | #define SSL_set_tmp_dh(ssl,dh) \ |
| 1156 | SSL_ctrl(ssl,SSL_CTRL_SET_TMP_DH,0,(char *)dh) | 1288 | SSL_ctrl(ssl,SSL_CTRL_SET_TMP_DH,0,(char *)dh) |
| 1289 | #define SSL_set_tmp_ecdh(ssl,ecdh) \ | ||
| 1290 | SSL_ctrl(ssl,SSL_CTRL_SET_TMP_ECDH,0,(char *)ecdh) | ||
| 1157 | 1291 | ||
| 1158 | #define SSL_CTX_add_extra_chain_cert(ctx,x509) \ | 1292 | #define SSL_CTX_add_extra_chain_cert(ctx,x509) \ |
| 1159 | SSL_CTX_ctrl(ctx,SSL_CTRL_EXTRA_CHAIN_CERT,0,(char *)x509) | 1293 | SSL_CTX_ctrl(ctx,SSL_CTRL_EXTRA_CHAIN_CERT,0,(char *)x509) |
| @@ -1215,9 +1349,9 @@ int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa); | |||
| 1215 | #endif | 1349 | #endif |
| 1216 | int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len); | 1350 | int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len); |
| 1217 | int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey); | 1351 | int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey); |
| 1218 | int SSL_use_PrivateKey_ASN1(int pk,SSL *ssl, unsigned char *d, long len); | 1352 | int SSL_use_PrivateKey_ASN1(int pk,SSL *ssl, const unsigned char *d, long len); |
| 1219 | int SSL_use_certificate(SSL *ssl, X509 *x); | 1353 | int SSL_use_certificate(SSL *ssl, X509 *x); |
| 1220 | int SSL_use_certificate_ASN1(SSL *ssl, unsigned char *d, int len); | 1354 | int SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len); |
| 1221 | 1355 | ||
| 1222 | #ifndef OPENSSL_NO_STDIO | 1356 | #ifndef OPENSSL_NO_STDIO |
| 1223 | int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type); | 1357 | int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type); |
| @@ -1253,6 +1387,7 @@ void SSL_copy_session_id(SSL *to,const SSL *from); | |||
| 1253 | SSL_SESSION *SSL_SESSION_new(void); | 1387 | SSL_SESSION *SSL_SESSION_new(void); |
| 1254 | unsigned long SSL_SESSION_hash(const SSL_SESSION *a); | 1388 | unsigned long SSL_SESSION_hash(const SSL_SESSION *a); |
| 1255 | int SSL_SESSION_cmp(const SSL_SESSION *a,const SSL_SESSION *b); | 1389 | int SSL_SESSION_cmp(const SSL_SESSION *a,const SSL_SESSION *b); |
| 1390 | const unsigned char *SSL_SESSION_get_id(const SSL_SESSION *s, unsigned int *len); | ||
| 1256 | #ifndef OPENSSL_NO_FP_API | 1391 | #ifndef OPENSSL_NO_FP_API |
| 1257 | int SSL_SESSION_print_fp(FILE *fp,const SSL_SESSION *ses); | 1392 | int SSL_SESSION_print_fp(FILE *fp,const SSL_SESSION *ses); |
| 1258 | #endif | 1393 | #endif |
| @@ -1268,7 +1403,7 @@ int SSL_CTX_set_generate_session_id(SSL_CTX *, GEN_SESSION_CB); | |||
| 1268 | int SSL_set_generate_session_id(SSL *, GEN_SESSION_CB); | 1403 | int SSL_set_generate_session_id(SSL *, GEN_SESSION_CB); |
| 1269 | int SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id, | 1404 | int SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id, |
| 1270 | unsigned int id_len); | 1405 | unsigned int id_len); |
| 1271 | SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a,const unsigned char * const *pp, | 1406 | SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a,const unsigned char **pp, |
| 1272 | long length); | 1407 | long length); |
| 1273 | 1408 | ||
| 1274 | #ifdef HEADER_X509_H | 1409 | #ifdef HEADER_X509_H |
| @@ -1287,12 +1422,12 @@ void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx, int (*cb)(X509_STORE_CTX *,v | |||
| 1287 | #ifndef OPENSSL_NO_RSA | 1422 | #ifndef OPENSSL_NO_RSA |
| 1288 | int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa); | 1423 | int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa); |
| 1289 | #endif | 1424 | #endif |
| 1290 | int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, unsigned char *d, long len); | 1425 | int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, const unsigned char *d, long len); |
| 1291 | int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey); | 1426 | int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey); |
| 1292 | int SSL_CTX_use_PrivateKey_ASN1(int pk,SSL_CTX *ctx, | 1427 | int SSL_CTX_use_PrivateKey_ASN1(int pk,SSL_CTX *ctx, |
| 1293 | unsigned char *d, long len); | 1428 | const unsigned char *d, long len); |
| 1294 | int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x); | 1429 | int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x); |
| 1295 | int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, unsigned char *d); | 1430 | int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, const unsigned char *d); |
| 1296 | 1431 | ||
| 1297 | void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb); | 1432 | void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb); |
| 1298 | void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u); | 1433 | void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u); |
| @@ -1319,9 +1454,9 @@ int SSL_read(SSL *ssl,void *buf,int num); | |||
| 1319 | int SSL_peek(SSL *ssl,void *buf,int num); | 1454 | int SSL_peek(SSL *ssl,void *buf,int num); |
| 1320 | int SSL_write(SSL *ssl,const void *buf,int num); | 1455 | int SSL_write(SSL *ssl,const void *buf,int num); |
| 1321 | long SSL_ctrl(SSL *ssl,int cmd, long larg, void *parg); | 1456 | long SSL_ctrl(SSL *ssl,int cmd, long larg, void *parg); |
| 1322 | long SSL_callback_ctrl(SSL *, int, void (*)()); | 1457 | long SSL_callback_ctrl(SSL *, int, void (*)(void)); |
| 1323 | long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd, long larg, void *parg); | 1458 | long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd, long larg, void *parg); |
| 1324 | long SSL_CTX_callback_ctrl(SSL_CTX *, int, void (*)()); | 1459 | long SSL_CTX_callback_ctrl(SSL_CTX *, int, void (*)(void)); |
| 1325 | 1460 | ||
| 1326 | int SSL_get_error(const SSL *s,int ret_code); | 1461 | int SSL_get_error(const SSL *s,int ret_code); |
| 1327 | const char *SSL_get_version(const SSL *s); | 1462 | const char *SSL_get_version(const SSL *s); |
| @@ -1345,6 +1480,10 @@ SSL_METHOD *TLSv1_method(void); /* TLSv1.0 */ | |||
| 1345 | SSL_METHOD *TLSv1_server_method(void); /* TLSv1.0 */ | 1480 | SSL_METHOD *TLSv1_server_method(void); /* TLSv1.0 */ |
| 1346 | SSL_METHOD *TLSv1_client_method(void); /* TLSv1.0 */ | 1481 | SSL_METHOD *TLSv1_client_method(void); /* TLSv1.0 */ |
| 1347 | 1482 | ||
| 1483 | SSL_METHOD *DTLSv1_method(void); /* DTLSv1.0 */ | ||
| 1484 | SSL_METHOD *DTLSv1_server_method(void); /* DTLSv1.0 */ | ||
| 1485 | SSL_METHOD *DTLSv1_client_method(void); /* DTLSv1.0 */ | ||
| 1486 | |||
| 1348 | STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL *s); | 1487 | STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL *s); |
| 1349 | 1488 | ||
| 1350 | int SSL_do_handshake(SSL *s); | 1489 | int SSL_do_handshake(SSL *s); |
| @@ -1395,6 +1534,7 @@ int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile, | |||
| 1395 | SSL_SESSION *SSL_get_session(const SSL *ssl); | 1534 | SSL_SESSION *SSL_get_session(const SSL *ssl); |
| 1396 | SSL_SESSION *SSL_get1_session(SSL *ssl); /* obtain a reference count */ | 1535 | SSL_SESSION *SSL_get1_session(SSL *ssl); /* obtain a reference count */ |
| 1397 | SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl); | 1536 | SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl); |
| 1537 | SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX* ctx); | ||
| 1398 | void SSL_set_info_callback(SSL *ssl, | 1538 | void SSL_set_info_callback(SSL *ssl, |
| 1399 | void (*cb)(const SSL *ssl,int type,int val)); | 1539 | void (*cb)(const SSL *ssl,int type,int val)); |
| 1400 | void (*SSL_get_info_callback(const SSL *ssl))(const SSL *ssl,int type,int val); | 1540 | void (*SSL_get_info_callback(const SSL *ssl))(const SSL *ssl,int type,int val); |
| @@ -1462,11 +1602,27 @@ void SSL_set_tmp_dh_callback(SSL *ssl, | |||
| 1462 | DH *(*dh)(SSL *ssl,int is_export, | 1602 | DH *(*dh)(SSL *ssl,int is_export, |
| 1463 | int keylength)); | 1603 | int keylength)); |
| 1464 | #endif | 1604 | #endif |
| 1605 | #ifndef OPENSSL_NO_ECDH | ||
| 1606 | void SSL_CTX_set_tmp_ecdh_callback(SSL_CTX *ctx, | ||
| 1607 | EC_KEY *(*ecdh)(SSL *ssl,int is_export, | ||
| 1608 | int keylength)); | ||
| 1609 | void SSL_set_tmp_ecdh_callback(SSL *ssl, | ||
| 1610 | EC_KEY *(*ecdh)(SSL *ssl,int is_export, | ||
| 1611 | int keylength)); | ||
| 1612 | #endif | ||
| 1465 | 1613 | ||
| 1466 | #ifndef OPENSSL_NO_COMP | 1614 | #ifndef OPENSSL_NO_COMP |
| 1615 | const COMP_METHOD *SSL_get_current_compression(SSL *s); | ||
| 1616 | const COMP_METHOD *SSL_get_current_expansion(SSL *s); | ||
| 1617 | const char *SSL_COMP_get_name(const COMP_METHOD *comp); | ||
| 1618 | STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void); | ||
| 1467 | int SSL_COMP_add_compression_method(int id,COMP_METHOD *cm); | 1619 | int SSL_COMP_add_compression_method(int id,COMP_METHOD *cm); |
| 1468 | #else | 1620 | #else |
| 1469 | int SSL_COMP_add_compression_method(int id,char *cm); | 1621 | const void *SSL_get_current_compression(SSL *s); |
| 1622 | const void *SSL_get_current_expansion(SSL *s); | ||
| 1623 | const char *SSL_COMP_get_name(const void *comp); | ||
| 1624 | void *SSL_COMP_get_compression_methods(void); | ||
| 1625 | int SSL_COMP_add_compression_method(int id,void *cm); | ||
| 1470 | #endif | 1626 | #endif |
| 1471 | 1627 | ||
| 1472 | /* BEGIN ERROR CODES */ | 1628 | /* BEGIN ERROR CODES */ |
| @@ -1479,11 +1635,36 @@ void ERR_load_SSL_strings(void); | |||
| 1479 | 1635 | ||
| 1480 | /* Function codes. */ | 1636 | /* Function codes. */ |
| 1481 | #define SSL_F_CLIENT_CERTIFICATE 100 | 1637 | #define SSL_F_CLIENT_CERTIFICATE 100 |
| 1482 | #define SSL_F_CLIENT_FINISHED 238 | 1638 | #define SSL_F_CLIENT_FINISHED 167 |
| 1483 | #define SSL_F_CLIENT_HELLO 101 | 1639 | #define SSL_F_CLIENT_HELLO 101 |
| 1484 | #define SSL_F_CLIENT_MASTER_KEY 102 | 1640 | #define SSL_F_CLIENT_MASTER_KEY 102 |
| 1485 | #define SSL_F_D2I_SSL_SESSION 103 | 1641 | #define SSL_F_D2I_SSL_SESSION 103 |
| 1642 | #define SSL_F_DO_DTLS1_WRITE 245 | ||
| 1486 | #define SSL_F_DO_SSL3_WRITE 104 | 1643 | #define SSL_F_DO_SSL3_WRITE 104 |
| 1644 | #define SSL_F_DTLS1_ACCEPT 246 | ||
| 1645 | #define SSL_F_DTLS1_BUFFER_RECORD 247 | ||
| 1646 | #define SSL_F_DTLS1_CLIENT_HELLO 248 | ||
| 1647 | #define SSL_F_DTLS1_CONNECT 249 | ||
| 1648 | #define SSL_F_DTLS1_ENC 250 | ||
| 1649 | #define SSL_F_DTLS1_GET_HELLO_VERIFY 251 | ||
| 1650 | #define SSL_F_DTLS1_GET_MESSAGE 252 | ||
| 1651 | #define SSL_F_DTLS1_GET_MESSAGE_FRAGMENT 253 | ||
| 1652 | #define SSL_F_DTLS1_GET_RECORD 254 | ||
| 1653 | #define SSL_F_DTLS1_OUTPUT_CERT_CHAIN 255 | ||
| 1654 | #define SSL_F_DTLS1_PREPROCESS_FRAGMENT 277 | ||
| 1655 | #define SSL_F_DTLS1_PROCESS_OUT_OF_SEQ_MESSAGE 256 | ||
| 1656 | #define SSL_F_DTLS1_PROCESS_RECORD 257 | ||
| 1657 | #define SSL_F_DTLS1_READ_BYTES 258 | ||
| 1658 | #define SSL_F_DTLS1_READ_FAILED 259 | ||
| 1659 | #define SSL_F_DTLS1_SEND_CERTIFICATE_REQUEST 260 | ||
| 1660 | #define SSL_F_DTLS1_SEND_CLIENT_CERTIFICATE 261 | ||
| 1661 | #define SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE 262 | ||
| 1662 | #define SSL_F_DTLS1_SEND_CLIENT_VERIFY 263 | ||
| 1663 | #define SSL_F_DTLS1_SEND_HELLO_VERIFY_REQUEST 264 | ||
| 1664 | #define SSL_F_DTLS1_SEND_SERVER_CERTIFICATE 265 | ||
| 1665 | #define SSL_F_DTLS1_SEND_SERVER_HELLO 266 | ||
| 1666 | #define SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE 267 | ||
| 1667 | #define SSL_F_DTLS1_WRITE_APP_DATA_BYTES 268 | ||
| 1487 | #define SSL_F_GET_CLIENT_FINISHED 105 | 1668 | #define SSL_F_GET_CLIENT_FINISHED 105 |
| 1488 | #define SSL_F_GET_CLIENT_HELLO 106 | 1669 | #define SSL_F_GET_CLIENT_HELLO 106 |
| 1489 | #define SSL_F_GET_CLIENT_MASTER_KEY 107 | 1670 | #define SSL_F_GET_CLIENT_MASTER_KEY 107 |
| @@ -1524,6 +1705,7 @@ void ERR_load_SSL_strings(void); | |||
| 1524 | #define SSL_F_SSL3_ENC 134 | 1705 | #define SSL_F_SSL3_ENC 134 |
| 1525 | #define SSL_F_SSL3_GENERATE_KEY_BLOCK 238 | 1706 | #define SSL_F_SSL3_GENERATE_KEY_BLOCK 238 |
| 1526 | #define SSL_F_SSL3_GET_CERTIFICATE_REQUEST 135 | 1707 | #define SSL_F_SSL3_GET_CERTIFICATE_REQUEST 135 |
| 1708 | #define SSL_F_SSL3_GET_CERT_STATUS 288 | ||
| 1527 | #define SSL_F_SSL3_GET_CERT_VERIFY 136 | 1709 | #define SSL_F_SSL3_GET_CERT_VERIFY 136 |
| 1528 | #define SSL_F_SSL3_GET_CLIENT_CERTIFICATE 137 | 1710 | #define SSL_F_SSL3_GET_CLIENT_CERTIFICATE 137 |
| 1529 | #define SSL_F_SSL3_GET_CLIENT_HELLO 138 | 1711 | #define SSL_F_SSL3_GET_CLIENT_HELLO 138 |
| @@ -1531,10 +1713,12 @@ void ERR_load_SSL_strings(void); | |||
| 1531 | #define SSL_F_SSL3_GET_FINISHED 140 | 1713 | #define SSL_F_SSL3_GET_FINISHED 140 |
| 1532 | #define SSL_F_SSL3_GET_KEY_EXCHANGE 141 | 1714 | #define SSL_F_SSL3_GET_KEY_EXCHANGE 141 |
| 1533 | #define SSL_F_SSL3_GET_MESSAGE 142 | 1715 | #define SSL_F_SSL3_GET_MESSAGE 142 |
| 1716 | #define SSL_F_SSL3_GET_NEW_SESSION_TICKET 283 | ||
| 1534 | #define SSL_F_SSL3_GET_RECORD 143 | 1717 | #define SSL_F_SSL3_GET_RECORD 143 |
| 1535 | #define SSL_F_SSL3_GET_SERVER_CERTIFICATE 144 | 1718 | #define SSL_F_SSL3_GET_SERVER_CERTIFICATE 144 |
| 1536 | #define SSL_F_SSL3_GET_SERVER_DONE 145 | 1719 | #define SSL_F_SSL3_GET_SERVER_DONE 145 |
| 1537 | #define SSL_F_SSL3_GET_SERVER_HELLO 146 | 1720 | #define SSL_F_SSL3_GET_SERVER_HELLO 146 |
| 1721 | #define SSL_F_SSL3_NEW_SESSION_TICKET 284 | ||
| 1538 | #define SSL_F_SSL3_OUTPUT_CERT_CHAIN 147 | 1722 | #define SSL_F_SSL3_OUTPUT_CERT_CHAIN 147 |
| 1539 | #define SSL_F_SSL3_PEEK 235 | 1723 | #define SSL_F_SSL3_PEEK 235 |
| 1540 | #define SSL_F_SSL3_READ_BYTES 148 | 1724 | #define SSL_F_SSL3_READ_BYTES 148 |
| @@ -1550,8 +1734,10 @@ void ERR_load_SSL_strings(void); | |||
| 1550 | #define SSL_F_SSL3_SETUP_KEY_BLOCK 157 | 1734 | #define SSL_F_SSL3_SETUP_KEY_BLOCK 157 |
| 1551 | #define SSL_F_SSL3_WRITE_BYTES 158 | 1735 | #define SSL_F_SSL3_WRITE_BYTES 158 |
| 1552 | #define SSL_F_SSL3_WRITE_PENDING 159 | 1736 | #define SSL_F_SSL3_WRITE_PENDING 159 |
| 1737 | #define SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT 272 | ||
| 1553 | #define SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK 215 | 1738 | #define SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK 215 |
| 1554 | #define SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK 216 | 1739 | #define SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK 216 |
| 1740 | #define SSL_F_SSL_ADD_SERVERHELLO_TLSEXT 273 | ||
| 1555 | #define SSL_F_SSL_BAD_METHOD 160 | 1741 | #define SSL_F_SSL_BAD_METHOD 160 |
| 1556 | #define SSL_F_SSL_BYTES_TO_CIPHER_LIST 161 | 1742 | #define SSL_F_SSL_BYTES_TO_CIPHER_LIST 161 |
| 1557 | #define SSL_F_SSL_CERT_DUP 221 | 1743 | #define SSL_F_SSL_CERT_DUP 221 |
| @@ -1559,6 +1745,7 @@ void ERR_load_SSL_strings(void); | |||
| 1559 | #define SSL_F_SSL_CERT_INSTANTIATE 214 | 1745 | #define SSL_F_SSL_CERT_INSTANTIATE 214 |
| 1560 | #define SSL_F_SSL_CERT_NEW 162 | 1746 | #define SSL_F_SSL_CERT_NEW 162 |
| 1561 | #define SSL_F_SSL_CHECK_PRIVATE_KEY 163 | 1747 | #define SSL_F_SSL_CHECK_PRIVATE_KEY 163 |
| 1748 | #define SSL_F_SSL_CHECK_SERVERHELLO_TLSEXT 274 | ||
| 1562 | #define SSL_F_SSL_CIPHER_PROCESS_RULESTR 230 | 1749 | #define SSL_F_SSL_CIPHER_PROCESS_RULESTR 230 |
| 1563 | #define SSL_F_SSL_CIPHER_STRENGTH_SORT 231 | 1750 | #define SSL_F_SSL_CIPHER_STRENGTH_SORT 231 |
| 1564 | #define SSL_F_SSL_CLEAR 164 | 1751 | #define SSL_F_SSL_CLEAR 164 |
| @@ -1590,6 +1777,9 @@ void ERR_load_SSL_strings(void); | |||
| 1590 | #define SSL_F_SSL_INIT_WBIO_BUFFER 184 | 1777 | #define SSL_F_SSL_INIT_WBIO_BUFFER 184 |
| 1591 | #define SSL_F_SSL_LOAD_CLIENT_CA_FILE 185 | 1778 | #define SSL_F_SSL_LOAD_CLIENT_CA_FILE 185 |
| 1592 | #define SSL_F_SSL_NEW 186 | 1779 | #define SSL_F_SSL_NEW 186 |
| 1780 | #define SSL_F_SSL_PEEK 270 | ||
| 1781 | #define SSL_F_SSL_PREPARE_CLIENTHELLO_TLSEXT 275 | ||
| 1782 | #define SSL_F_SSL_PREPARE_SERVERHELLO_TLSEXT 276 | ||
| 1593 | #define SSL_F_SSL_READ 223 | 1783 | #define SSL_F_SSL_READ 223 |
| 1594 | #define SSL_F_SSL_RSA_PRIVATE_DECRYPT 187 | 1784 | #define SSL_F_SSL_RSA_PRIVATE_DECRYPT 187 |
| 1595 | #define SSL_F_SSL_RSA_PUBLIC_ENCRYPT 188 | 1785 | #define SSL_F_SSL_RSA_PUBLIC_ENCRYPT 188 |
| @@ -1609,6 +1799,7 @@ void ERR_load_SSL_strings(void); | |||
| 1609 | #define SSL_F_SSL_SHUTDOWN 224 | 1799 | #define SSL_F_SSL_SHUTDOWN 224 |
| 1610 | #define SSL_F_SSL_UNDEFINED_CONST_FUNCTION 243 | 1800 | #define SSL_F_SSL_UNDEFINED_CONST_FUNCTION 243 |
| 1611 | #define SSL_F_SSL_UNDEFINED_FUNCTION 197 | 1801 | #define SSL_F_SSL_UNDEFINED_FUNCTION 197 |
| 1802 | #define SSL_F_SSL_UNDEFINED_VOID_FUNCTION 244 | ||
| 1612 | #define SSL_F_SSL_USE_CERTIFICATE 198 | 1803 | #define SSL_F_SSL_USE_CERTIFICATE 198 |
| 1613 | #define SSL_F_SSL_USE_CERTIFICATE_ASN1 199 | 1804 | #define SSL_F_SSL_USE_CERTIFICATE_ASN1 199 |
| 1614 | #define SSL_F_SSL_USE_CERTIFICATE_FILE 200 | 1805 | #define SSL_F_SSL_USE_CERTIFICATE_FILE 200 |
| @@ -1639,6 +1830,9 @@ void ERR_load_SSL_strings(void); | |||
| 1639 | #define SSL_R_BAD_DH_P_LENGTH 110 | 1830 | #define SSL_R_BAD_DH_P_LENGTH 110 |
| 1640 | #define SSL_R_BAD_DIGEST_LENGTH 111 | 1831 | #define SSL_R_BAD_DIGEST_LENGTH 111 |
| 1641 | #define SSL_R_BAD_DSA_SIGNATURE 112 | 1832 | #define SSL_R_BAD_DSA_SIGNATURE 112 |
| 1833 | #define SSL_R_BAD_ECC_CERT 304 | ||
| 1834 | #define SSL_R_BAD_ECDSA_SIGNATURE 305 | ||
| 1835 | #define SSL_R_BAD_ECPOINT 306 | ||
| 1642 | #define SSL_R_BAD_HELLO_REQUEST 105 | 1836 | #define SSL_R_BAD_HELLO_REQUEST 105 |
| 1643 | #define SSL_R_BAD_LENGTH 271 | 1837 | #define SSL_R_BAD_LENGTH 271 |
| 1644 | #define SSL_R_BAD_MAC_DECODE 113 | 1838 | #define SSL_R_BAD_MAC_DECODE 113 |
| @@ -1668,17 +1862,22 @@ void ERR_load_SSL_strings(void); | |||
| 1668 | #define SSL_R_CIPHER_CODE_WRONG_LENGTH 137 | 1862 | #define SSL_R_CIPHER_CODE_WRONG_LENGTH 137 |
| 1669 | #define SSL_R_CIPHER_OR_HASH_UNAVAILABLE 138 | 1863 | #define SSL_R_CIPHER_OR_HASH_UNAVAILABLE 138 |
| 1670 | #define SSL_R_CIPHER_TABLE_SRC_ERROR 139 | 1864 | #define SSL_R_CIPHER_TABLE_SRC_ERROR 139 |
| 1865 | #define SSL_R_CLIENTHELLO_TLSEXT 157 | ||
| 1671 | #define SSL_R_COMPRESSED_LENGTH_TOO_LONG 140 | 1866 | #define SSL_R_COMPRESSED_LENGTH_TOO_LONG 140 |
| 1672 | #define SSL_R_COMPRESSION_FAILURE 141 | 1867 | #define SSL_R_COMPRESSION_FAILURE 141 |
| 1868 | #define SSL_R_COMPRESSION_ID_NOT_WITHIN_PRIVATE_RANGE 307 | ||
| 1673 | #define SSL_R_COMPRESSION_LIBRARY_ERROR 142 | 1869 | #define SSL_R_COMPRESSION_LIBRARY_ERROR 142 |
| 1674 | #define SSL_R_CONNECTION_ID_IS_DIFFERENT 143 | 1870 | #define SSL_R_CONNECTION_ID_IS_DIFFERENT 143 |
| 1675 | #define SSL_R_CONNECTION_TYPE_NOT_SET 144 | 1871 | #define SSL_R_CONNECTION_TYPE_NOT_SET 144 |
| 1872 | #define SSL_R_COOKIE_MISMATCH 308 | ||
| 1676 | #define SSL_R_DATA_BETWEEN_CCS_AND_FINISHED 145 | 1873 | #define SSL_R_DATA_BETWEEN_CCS_AND_FINISHED 145 |
| 1677 | #define SSL_R_DATA_LENGTH_TOO_LONG 146 | 1874 | #define SSL_R_DATA_LENGTH_TOO_LONG 146 |
| 1678 | #define SSL_R_DECRYPTION_FAILED 147 | 1875 | #define SSL_R_DECRYPTION_FAILED 147 |
| 1679 | #define SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC 281 | 1876 | #define SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC 281 |
| 1680 | #define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG 148 | 1877 | #define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG 148 |
| 1681 | #define SSL_R_DIGEST_CHECK_FAILED 149 | 1878 | #define SSL_R_DIGEST_CHECK_FAILED 149 |
| 1879 | #define SSL_R_DUPLICATE_COMPRESSION_ID 309 | ||
| 1880 | #define SSL_R_ECGROUP_TOO_LARGE_FOR_CIPHER 310 | ||
| 1682 | #define SSL_R_ENCRYPTED_LENGTH_TOO_LONG 150 | 1881 | #define SSL_R_ENCRYPTED_LENGTH_TOO_LONG 150 |
| 1683 | #define SSL_R_ERROR_GENERATING_TMP_RSA_KEY 282 | 1882 | #define SSL_R_ERROR_GENERATING_TMP_RSA_KEY 282 |
| 1684 | #define SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST 151 | 1883 | #define SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST 151 |
| @@ -1691,6 +1890,8 @@ void ERR_load_SSL_strings(void); | |||
| 1691 | #define SSL_R_INVALID_CHALLENGE_LENGTH 158 | 1890 | #define SSL_R_INVALID_CHALLENGE_LENGTH 158 |
| 1692 | #define SSL_R_INVALID_COMMAND 280 | 1891 | #define SSL_R_INVALID_COMMAND 280 |
| 1693 | #define SSL_R_INVALID_PURPOSE 278 | 1892 | #define SSL_R_INVALID_PURPOSE 278 |
| 1893 | #define SSL_R_INVALID_STATUS_RESPONSE 316 | ||
| 1894 | #define SSL_R_INVALID_TICKET_KEYS_LENGTH 275 | ||
| 1694 | #define SSL_R_INVALID_TRUST 279 | 1895 | #define SSL_R_INVALID_TRUST 279 |
| 1695 | #define SSL_R_KEY_ARG_TOO_LONG 284 | 1896 | #define SSL_R_KEY_ARG_TOO_LONG 284 |
| 1696 | #define SSL_R_KRB5 285 | 1897 | #define SSL_R_KRB5 285 |
| @@ -1719,6 +1920,7 @@ void ERR_load_SSL_strings(void); | |||
| 1719 | #define SSL_R_MISSING_RSA_ENCRYPTING_CERT 169 | 1920 | #define SSL_R_MISSING_RSA_ENCRYPTING_CERT 169 |
| 1720 | #define SSL_R_MISSING_RSA_SIGNING_CERT 170 | 1921 | #define SSL_R_MISSING_RSA_SIGNING_CERT 170 |
| 1721 | #define SSL_R_MISSING_TMP_DH_KEY 171 | 1922 | #define SSL_R_MISSING_TMP_DH_KEY 171 |
| 1923 | #define SSL_R_MISSING_TMP_ECDH_KEY 311 | ||
| 1722 | #define SSL_R_MISSING_TMP_RSA_KEY 172 | 1924 | #define SSL_R_MISSING_TMP_RSA_KEY 172 |
| 1723 | #define SSL_R_MISSING_TMP_RSA_PKEY 173 | 1925 | #define SSL_R_MISSING_TMP_RSA_PKEY 173 |
| 1724 | #define SSL_R_MISSING_VERIFY_MESSAGE 174 | 1926 | #define SSL_R_MISSING_VERIFY_MESSAGE 174 |
| @@ -1747,6 +1949,7 @@ void ERR_load_SSL_strings(void); | |||
| 1747 | #define SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED 197 | 1949 | #define SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED 197 |
| 1748 | #define SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE 297 | 1950 | #define SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE 297 |
| 1749 | #define SSL_R_PACKET_LENGTH_TOO_LONG 198 | 1951 | #define SSL_R_PACKET_LENGTH_TOO_LONG 198 |
| 1952 | #define SSL_R_PARSE_TLSEXT 223 | ||
| 1750 | #define SSL_R_PATH_TOO_LONG 270 | 1953 | #define SSL_R_PATH_TOO_LONG 270 |
| 1751 | #define SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE 199 | 1954 | #define SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE 199 |
| 1752 | #define SSL_R_PEER_ERROR 200 | 1955 | #define SSL_R_PEER_ERROR 200 |
| @@ -1761,6 +1964,7 @@ void ERR_load_SSL_strings(void); | |||
| 1761 | #define SSL_R_PUBLIC_KEY_IS_NOT_RSA 209 | 1964 | #define SSL_R_PUBLIC_KEY_IS_NOT_RSA 209 |
| 1762 | #define SSL_R_PUBLIC_KEY_NOT_RSA 210 | 1965 | #define SSL_R_PUBLIC_KEY_NOT_RSA 210 |
| 1763 | #define SSL_R_READ_BIO_NOT_SET 211 | 1966 | #define SSL_R_READ_BIO_NOT_SET 211 |
| 1967 | #define SSL_R_READ_TIMEOUT_EXPIRED 312 | ||
| 1764 | #define SSL_R_READ_WRONG_PACKET_TYPE 212 | 1968 | #define SSL_R_READ_WRONG_PACKET_TYPE 212 |
| 1765 | #define SSL_R_RECORD_LENGTH_MISMATCH 213 | 1969 | #define SSL_R_RECORD_LENGTH_MISMATCH 213 |
| 1766 | #define SSL_R_RECORD_TOO_LARGE 214 | 1970 | #define SSL_R_RECORD_TOO_LARGE 214 |
| @@ -1769,11 +1973,14 @@ void ERR_load_SSL_strings(void); | |||
| 1769 | #define SSL_R_REUSE_CERT_LENGTH_NOT_ZERO 216 | 1973 | #define SSL_R_REUSE_CERT_LENGTH_NOT_ZERO 216 |
| 1770 | #define SSL_R_REUSE_CERT_TYPE_NOT_ZERO 217 | 1974 | #define SSL_R_REUSE_CERT_TYPE_NOT_ZERO 217 |
| 1771 | #define SSL_R_REUSE_CIPHER_LIST_NOT_ZERO 218 | 1975 | #define SSL_R_REUSE_CIPHER_LIST_NOT_ZERO 218 |
| 1976 | #define SSL_R_SERVERHELLO_TLSEXT 224 | ||
| 1772 | #define SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED 277 | 1977 | #define SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED 277 |
| 1773 | #define SSL_R_SHORT_READ 219 | 1978 | #define SSL_R_SHORT_READ 219 |
| 1774 | #define SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE 220 | 1979 | #define SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE 220 |
| 1775 | #define SSL_R_SSL23_DOING_SESSION_ID_REUSE 221 | 1980 | #define SSL_R_SSL23_DOING_SESSION_ID_REUSE 221 |
| 1776 | #define SSL_R_SSL2_CONNECTION_ID_TOO_LONG 299 | 1981 | #define SSL_R_SSL2_CONNECTION_ID_TOO_LONG 299 |
| 1982 | #define SSL_R_SSL3_EXT_INVALID_SERVERNAME 225 | ||
| 1983 | #define SSL_R_SSL3_EXT_INVALID_SERVERNAME_TYPE 226 | ||
| 1777 | #define SSL_R_SSL3_SESSION_ID_TOO_LONG 300 | 1984 | #define SSL_R_SSL3_SESSION_ID_TOO_LONG 300 |
| 1778 | #define SSL_R_SSL3_SESSION_ID_TOO_SHORT 222 | 1985 | #define SSL_R_SSL3_SESSION_ID_TOO_SHORT 222 |
| 1779 | #define SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042 | 1986 | #define SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042 |
| @@ -1808,12 +2015,15 @@ void ERR_load_SSL_strings(void); | |||
| 1808 | #define SSL_R_TLSV1_ALERT_UNKNOWN_CA 1048 | 2015 | #define SSL_R_TLSV1_ALERT_UNKNOWN_CA 1048 |
| 1809 | #define SSL_R_TLSV1_ALERT_USER_CANCELLED 1090 | 2016 | #define SSL_R_TLSV1_ALERT_USER_CANCELLED 1090 |
| 1810 | #define SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER 232 | 2017 | #define SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER 232 |
| 2018 | #define SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST 227 | ||
| 1811 | #define SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST 233 | 2019 | #define SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST 233 |
| 1812 | #define SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG 234 | 2020 | #define SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG 234 |
| 1813 | #define SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER 235 | 2021 | #define SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER 235 |
| 1814 | #define SSL_R_UNABLE_TO_DECODE_DH_CERTS 236 | 2022 | #define SSL_R_UNABLE_TO_DECODE_DH_CERTS 236 |
| 2023 | #define SSL_R_UNABLE_TO_DECODE_ECDH_CERTS 313 | ||
| 1815 | #define SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY 237 | 2024 | #define SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY 237 |
| 1816 | #define SSL_R_UNABLE_TO_FIND_DH_PARAMETERS 238 | 2025 | #define SSL_R_UNABLE_TO_FIND_DH_PARAMETERS 238 |
| 2026 | #define SSL_R_UNABLE_TO_FIND_ECDH_PARAMETERS 314 | ||
| 1817 | #define SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS 239 | 2027 | #define SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS 239 |
| 1818 | #define SSL_R_UNABLE_TO_FIND_SSL_METHOD 240 | 2028 | #define SSL_R_UNABLE_TO_FIND_SSL_METHOD 240 |
| 1819 | #define SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES 241 | 2029 | #define SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES 241 |
| @@ -1834,8 +2044,10 @@ void ERR_load_SSL_strings(void); | |||
| 1834 | #define SSL_R_UNKNOWN_STATE 255 | 2044 | #define SSL_R_UNKNOWN_STATE 255 |
| 1835 | #define SSL_R_UNSUPPORTED_CIPHER 256 | 2045 | #define SSL_R_UNSUPPORTED_CIPHER 256 |
| 1836 | #define SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM 257 | 2046 | #define SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM 257 |
| 2047 | #define SSL_R_UNSUPPORTED_ELLIPTIC_CURVE 315 | ||
| 1837 | #define SSL_R_UNSUPPORTED_PROTOCOL 258 | 2048 | #define SSL_R_UNSUPPORTED_PROTOCOL 258 |
| 1838 | #define SSL_R_UNSUPPORTED_SSL_VERSION 259 | 2049 | #define SSL_R_UNSUPPORTED_SSL_VERSION 259 |
| 2050 | #define SSL_R_UNSUPPORTED_STATUS_TYPE 329 | ||
| 1839 | #define SSL_R_WRITE_BIO_NOT_SET 260 | 2051 | #define SSL_R_WRITE_BIO_NOT_SET 260 |
| 1840 | #define SSL_R_WRONG_CIPHER_RETURNED 261 | 2052 | #define SSL_R_WRONG_CIPHER_RETURNED 261 |
| 1841 | #define SSL_R_WRONG_MESSAGE_TYPE 262 | 2053 | #define SSL_R_WRONG_MESSAGE_TYPE 262 |
diff --git a/src/lib/libssl/ssl3.h b/src/lib/libssl/ssl3.h index 1153aeda74..4b1e2e9834 100644 --- a/src/lib/libssl/ssl3.h +++ b/src/lib/libssl/ssl3.h | |||
| @@ -108,6 +108,11 @@ | |||
| 108 | * Hudson (tjh@cryptsoft.com). | 108 | * Hudson (tjh@cryptsoft.com). |
| 109 | * | 109 | * |
| 110 | */ | 110 | */ |
| 111 | /* ==================================================================== | ||
| 112 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
| 113 | * ECC cipher suite support in OpenSSL originally developed by | ||
| 114 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. | ||
| 115 | */ | ||
| 111 | 116 | ||
| 112 | #ifndef HEADER_SSL3_H | 117 | #ifndef HEADER_SSL3_H |
| 113 | #define HEADER_SSL3_H | 118 | #define HEADER_SSL3_H |
| @@ -118,6 +123,7 @@ | |||
| 118 | #include <openssl/buffer.h> | 123 | #include <openssl/buffer.h> |
| 119 | #include <openssl/evp.h> | 124 | #include <openssl/evp.h> |
| 120 | #include <openssl/ssl.h> | 125 | #include <openssl/ssl.h> |
| 126 | #include <openssl/pq_compat.h> | ||
| 121 | 127 | ||
| 122 | #ifdef __cplusplus | 128 | #ifdef __cplusplus |
| 123 | extern "C" { | 129 | extern "C" { |
| @@ -248,7 +254,11 @@ extern "C" { | |||
| 248 | #endif | 254 | #endif |
| 249 | 255 | ||
| 250 | #define SSL3_RT_MAX_PLAIN_LENGTH 16384 | 256 | #define SSL3_RT_MAX_PLAIN_LENGTH 16384 |
| 257 | #ifdef OPENSSL_NO_COMP | ||
| 258 | #define SSL3_RT_MAX_COMPRESSED_LENGTH SSL3_RT_MAX_PLAIN_LENGTH | ||
| 259 | #else | ||
| 251 | #define SSL3_RT_MAX_COMPRESSED_LENGTH (1024+SSL3_RT_MAX_PLAIN_LENGTH) | 260 | #define SSL3_RT_MAX_COMPRESSED_LENGTH (1024+SSL3_RT_MAX_PLAIN_LENGTH) |
| 261 | #endif | ||
| 252 | #define SSL3_RT_MAX_ENCRYPTED_LENGTH (1024+SSL3_RT_MAX_COMPRESSED_LENGTH) | 262 | #define SSL3_RT_MAX_ENCRYPTED_LENGTH (1024+SSL3_RT_MAX_COMPRESSED_LENGTH) |
| 253 | #define SSL3_RT_MAX_PACKET_SIZE (SSL3_RT_MAX_ENCRYPTED_LENGTH+SSL3_RT_HEADER_LENGTH) | 263 | #define SSL3_RT_MAX_PACKET_SIZE (SSL3_RT_MAX_ENCRYPTED_LENGTH+SSL3_RT_HEADER_LENGTH) |
| 254 | #define SSL3_RT_MAX_DATA_SIZE (1024*1024) | 264 | #define SSL3_RT_MAX_DATA_SIZE (1024*1024) |
| @@ -289,6 +299,8 @@ typedef struct ssl3_record_st | |||
| 289 | /*rw*/ unsigned char *data; /* pointer to the record data */ | 299 | /*rw*/ unsigned char *data; /* pointer to the record data */ |
| 290 | /*rw*/ unsigned char *input; /* where the decode bytes are */ | 300 | /*rw*/ unsigned char *input; /* where the decode bytes are */ |
| 291 | /*r */ unsigned char *comp; /* only used with decompression - malloc()ed */ | 301 | /*r */ unsigned char *comp; /* only used with decompression - malloc()ed */ |
| 302 | /*r */ unsigned long epoch; /* epoch number, needed by DTLS1 */ | ||
| 303 | /*r */ PQ_64BIT seq_num; /* sequence number, needed by DTLS1 */ | ||
| 292 | } SSL3_RECORD; | 304 | } SSL3_RECORD; |
| 293 | 305 | ||
| 294 | typedef struct ssl3_buffer_st | 306 | typedef struct ssl3_buffer_st |
| @@ -307,7 +319,12 @@ typedef struct ssl3_buffer_st | |||
| 307 | #define SSL3_CT_RSA_EPHEMERAL_DH 5 | 319 | #define SSL3_CT_RSA_EPHEMERAL_DH 5 |
| 308 | #define SSL3_CT_DSS_EPHEMERAL_DH 6 | 320 | #define SSL3_CT_DSS_EPHEMERAL_DH 6 |
| 309 | #define SSL3_CT_FORTEZZA_DMS 20 | 321 | #define SSL3_CT_FORTEZZA_DMS 20 |
| 310 | #define SSL3_CT_NUMBER 7 | 322 | /* SSL3_CT_NUMBER is used to size arrays and it must be large |
| 323 | * enough to contain all of the cert types defined either for | ||
| 324 | * SSLv3 and TLSv1. | ||
| 325 | */ | ||
| 326 | #define SSL3_CT_NUMBER 7 | ||
| 327 | |||
| 311 | 328 | ||
| 312 | #define SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS 0x0001 | 329 | #define SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS 0x0001 |
| 313 | #define SSL3_FLAGS_DELAY_CLIENT_FINISHED 0x0002 | 330 | #define SSL3_FLAGS_DELAY_CLIENT_FINISHED 0x0002 |
| @@ -392,6 +409,11 @@ typedef struct ssl3_state_st | |||
| 392 | #ifndef OPENSSL_NO_DH | 409 | #ifndef OPENSSL_NO_DH |
| 393 | DH *dh; | 410 | DH *dh; |
| 394 | #endif | 411 | #endif |
| 412 | |||
| 413 | #ifndef OPENSSL_NO_ECDH | ||
| 414 | EC_KEY *ecdh; /* holds short lived ECDH key */ | ||
| 415 | #endif | ||
| 416 | |||
| 395 | /* used when SSL_ST_FLUSH_DATA is entered */ | 417 | /* used when SSL_ST_FLUSH_DATA is entered */ |
| 396 | int next_state; | 418 | int next_state; |
| 397 | 419 | ||
| @@ -420,6 +442,7 @@ typedef struct ssl3_state_st | |||
| 420 | 442 | ||
| 421 | } SSL3_STATE; | 443 | } SSL3_STATE; |
| 422 | 444 | ||
| 445 | |||
| 423 | /* SSLv3 */ | 446 | /* SSLv3 */ |
| 424 | /*client */ | 447 | /*client */ |
| 425 | /* extra state */ | 448 | /* extra state */ |
| @@ -430,6 +453,8 @@ typedef struct ssl3_state_st | |||
| 430 | /* read from server */ | 453 | /* read from server */ |
| 431 | #define SSL3_ST_CR_SRVR_HELLO_A (0x120|SSL_ST_CONNECT) | 454 | #define SSL3_ST_CR_SRVR_HELLO_A (0x120|SSL_ST_CONNECT) |
| 432 | #define SSL3_ST_CR_SRVR_HELLO_B (0x121|SSL_ST_CONNECT) | 455 | #define SSL3_ST_CR_SRVR_HELLO_B (0x121|SSL_ST_CONNECT) |
| 456 | #define DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A (0x126|SSL_ST_CONNECT) | ||
| 457 | #define DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B (0x127|SSL_ST_CONNECT) | ||
| 433 | #define SSL3_ST_CR_CERT_A (0x130|SSL_ST_CONNECT) | 458 | #define SSL3_ST_CR_CERT_A (0x130|SSL_ST_CONNECT) |
| 434 | #define SSL3_ST_CR_CERT_B (0x131|SSL_ST_CONNECT) | 459 | #define SSL3_ST_CR_CERT_B (0x131|SSL_ST_CONNECT) |
| 435 | #define SSL3_ST_CR_KEY_EXCH_A (0x140|SSL_ST_CONNECT) | 460 | #define SSL3_ST_CR_KEY_EXCH_A (0x140|SSL_ST_CONNECT) |
| @@ -456,6 +481,10 @@ typedef struct ssl3_state_st | |||
| 456 | #define SSL3_ST_CR_CHANGE_B (0x1C1|SSL_ST_CONNECT) | 481 | #define SSL3_ST_CR_CHANGE_B (0x1C1|SSL_ST_CONNECT) |
| 457 | #define SSL3_ST_CR_FINISHED_A (0x1D0|SSL_ST_CONNECT) | 482 | #define SSL3_ST_CR_FINISHED_A (0x1D0|SSL_ST_CONNECT) |
| 458 | #define SSL3_ST_CR_FINISHED_B (0x1D1|SSL_ST_CONNECT) | 483 | #define SSL3_ST_CR_FINISHED_B (0x1D1|SSL_ST_CONNECT) |
| 484 | #define SSL3_ST_CR_SESSION_TICKET_A (0x1E0|SSL_ST_CONNECT) | ||
| 485 | #define SSL3_ST_CR_SESSION_TICKET_B (0x1E1|SSL_ST_CONNECT) | ||
| 486 | #define SSL3_ST_CR_CERT_STATUS_A (0x1F0|SSL_ST_CONNECT) | ||
| 487 | #define SSL3_ST_CR_CERT_STATUS_B (0x1F1|SSL_ST_CONNECT) | ||
| 459 | 488 | ||
| 460 | /* server */ | 489 | /* server */ |
| 461 | /* extra state */ | 490 | /* extra state */ |
| @@ -466,6 +495,8 @@ typedef struct ssl3_state_st | |||
| 466 | #define SSL3_ST_SR_CLNT_HELLO_B (0x111|SSL_ST_ACCEPT) | 495 | #define SSL3_ST_SR_CLNT_HELLO_B (0x111|SSL_ST_ACCEPT) |
| 467 | #define SSL3_ST_SR_CLNT_HELLO_C (0x112|SSL_ST_ACCEPT) | 496 | #define SSL3_ST_SR_CLNT_HELLO_C (0x112|SSL_ST_ACCEPT) |
| 468 | /* write to client */ | 497 | /* write to client */ |
| 498 | #define DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A (0x113|SSL_ST_ACCEPT) | ||
| 499 | #define DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B (0x114|SSL_ST_ACCEPT) | ||
| 469 | #define SSL3_ST_SW_HELLO_REQ_A (0x120|SSL_ST_ACCEPT) | 500 | #define SSL3_ST_SW_HELLO_REQ_A (0x120|SSL_ST_ACCEPT) |
| 470 | #define SSL3_ST_SW_HELLO_REQ_B (0x121|SSL_ST_ACCEPT) | 501 | #define SSL3_ST_SW_HELLO_REQ_B (0x121|SSL_ST_ACCEPT) |
| 471 | #define SSL3_ST_SW_HELLO_REQ_C (0x122|SSL_ST_ACCEPT) | 502 | #define SSL3_ST_SW_HELLO_REQ_C (0x122|SSL_ST_ACCEPT) |
| @@ -495,10 +526,15 @@ typedef struct ssl3_state_st | |||
| 495 | #define SSL3_ST_SW_CHANGE_B (0x1D1|SSL_ST_ACCEPT) | 526 | #define SSL3_ST_SW_CHANGE_B (0x1D1|SSL_ST_ACCEPT) |
| 496 | #define SSL3_ST_SW_FINISHED_A (0x1E0|SSL_ST_ACCEPT) | 527 | #define SSL3_ST_SW_FINISHED_A (0x1E0|SSL_ST_ACCEPT) |
| 497 | #define SSL3_ST_SW_FINISHED_B (0x1E1|SSL_ST_ACCEPT) | 528 | #define SSL3_ST_SW_FINISHED_B (0x1E1|SSL_ST_ACCEPT) |
| 529 | #define SSL3_ST_SW_SESSION_TICKET_A (0x1F0|SSL_ST_ACCEPT) | ||
| 530 | #define SSL3_ST_SW_SESSION_TICKET_B (0x1F1|SSL_ST_ACCEPT) | ||
| 531 | #define SSL3_ST_SW_CERT_STATUS_A (0x200|SSL_ST_ACCEPT) | ||
| 532 | #define SSL3_ST_SW_CERT_STATUS_B (0x201|SSL_ST_ACCEPT) | ||
| 498 | 533 | ||
| 499 | #define SSL3_MT_HELLO_REQUEST 0 | 534 | #define SSL3_MT_HELLO_REQUEST 0 |
| 500 | #define SSL3_MT_CLIENT_HELLO 1 | 535 | #define SSL3_MT_CLIENT_HELLO 1 |
| 501 | #define SSL3_MT_SERVER_HELLO 2 | 536 | #define SSL3_MT_SERVER_HELLO 2 |
| 537 | #define SSL3_MT_NEWSESSION_TICKET 4 | ||
| 502 | #define SSL3_MT_CERTIFICATE 11 | 538 | #define SSL3_MT_CERTIFICATE 11 |
| 503 | #define SSL3_MT_SERVER_KEY_EXCHANGE 12 | 539 | #define SSL3_MT_SERVER_KEY_EXCHANGE 12 |
| 504 | #define SSL3_MT_CERTIFICATE_REQUEST 13 | 540 | #define SSL3_MT_CERTIFICATE_REQUEST 13 |
| @@ -506,6 +542,9 @@ typedef struct ssl3_state_st | |||
| 506 | #define SSL3_MT_CERTIFICATE_VERIFY 15 | 542 | #define SSL3_MT_CERTIFICATE_VERIFY 15 |
| 507 | #define SSL3_MT_CLIENT_KEY_EXCHANGE 16 | 543 | #define SSL3_MT_CLIENT_KEY_EXCHANGE 16 |
| 508 | #define SSL3_MT_FINISHED 20 | 544 | #define SSL3_MT_FINISHED 20 |
| 545 | #define SSL3_MT_CERTIFICATE_STATUS 22 | ||
| 546 | #define DTLS1_MT_HELLO_VERIFY_REQUEST 3 | ||
| 547 | |||
| 509 | 548 | ||
| 510 | #define SSL3_MT_CCS 1 | 549 | #define SSL3_MT_CCS 1 |
| 511 | 550 | ||
diff --git a/src/lib/libssl/ssl_algs.c b/src/lib/libssl/ssl_algs.c index 3d1299ee7b..4717c0e6e1 100644 --- a/src/lib/libssl/ssl_algs.c +++ b/src/lib/libssl/ssl_algs.c | |||
| @@ -82,6 +82,16 @@ int SSL_library_init(void) | |||
| 82 | EVP_add_cipher(EVP_aes_192_cbc()); | 82 | EVP_add_cipher(EVP_aes_192_cbc()); |
| 83 | EVP_add_cipher(EVP_aes_256_cbc()); | 83 | EVP_add_cipher(EVP_aes_256_cbc()); |
| 84 | #endif | 84 | #endif |
| 85 | |||
| 86 | #ifndef OPENSSL_NO_CAMELLIA | ||
| 87 | EVP_add_cipher(EVP_camellia_128_cbc()); | ||
| 88 | EVP_add_cipher(EVP_camellia_256_cbc()); | ||
| 89 | #endif | ||
| 90 | |||
| 91 | #ifndef OPENSSL_NO_SEED | ||
| 92 | EVP_add_cipher(EVP_seed_cbc()); | ||
| 93 | #endif | ||
| 94 | |||
| 85 | #ifndef OPENSSL_NO_MD2 | 95 | #ifndef OPENSSL_NO_MD2 |
| 86 | EVP_add_digest(EVP_md2()); | 96 | EVP_add_digest(EVP_md2()); |
| 87 | #endif | 97 | #endif |
| @@ -101,11 +111,22 @@ int SSL_library_init(void) | |||
| 101 | EVP_add_digest_alias(SN_dsaWithSHA1,"DSS1"); | 111 | EVP_add_digest_alias(SN_dsaWithSHA1,"DSS1"); |
| 102 | EVP_add_digest_alias(SN_dsaWithSHA1,"dss1"); | 112 | EVP_add_digest_alias(SN_dsaWithSHA1,"dss1"); |
| 103 | #endif | 113 | #endif |
| 114 | #ifndef OPENSSL_NO_ECDSA | ||
| 115 | EVP_add_digest(EVP_ecdsa()); | ||
| 116 | #endif | ||
| 104 | /* If you want support for phased out ciphers, add the following */ | 117 | /* If you want support for phased out ciphers, add the following */ |
| 105 | #if 0 | 118 | #if 0 |
| 106 | EVP_add_digest(EVP_sha()); | 119 | EVP_add_digest(EVP_sha()); |
| 107 | EVP_add_digest(EVP_dss()); | 120 | EVP_add_digest(EVP_dss()); |
| 108 | #endif | 121 | #endif |
| 122 | #ifndef OPENSSL_NO_COMP | ||
| 123 | /* This will initialise the built-in compression algorithms. | ||
| 124 | The value returned is a STACK_OF(SSL_COMP), but that can | ||
| 125 | be discarded safely */ | ||
| 126 | (void)SSL_COMP_get_compression_methods(); | ||
| 127 | #endif | ||
| 128 | /* initialize cipher/digest methods table */ | ||
| 129 | ssl_load_ciphers(); | ||
| 109 | return(1); | 130 | return(1); |
| 110 | } | 131 | } |
| 111 | 132 | ||
diff --git a/src/lib/libssl/ssl_asn1.c b/src/lib/libssl/ssl_asn1.c index fc5fcce108..6e14f4d834 100644 --- a/src/lib/libssl/ssl_asn1.c +++ b/src/lib/libssl/ssl_asn1.c | |||
| @@ -78,6 +78,11 @@ typedef struct ssl_session_asn1_st | |||
| 78 | ASN1_INTEGER time; | 78 | ASN1_INTEGER time; |
| 79 | ASN1_INTEGER timeout; | 79 | ASN1_INTEGER timeout; |
| 80 | ASN1_INTEGER verify_result; | 80 | ASN1_INTEGER verify_result; |
| 81 | #ifndef OPENSSL_NO_TLSEXT | ||
| 82 | ASN1_OCTET_STRING tlsext_hostname; | ||
| 83 | ASN1_INTEGER tlsext_tick_lifetime; | ||
| 84 | ASN1_OCTET_STRING tlsext_tick; | ||
| 85 | #endif /* OPENSSL_NO_TLSEXT */ | ||
| 81 | } SSL_SESSION_ASN1; | 86 | } SSL_SESSION_ASN1; |
| 82 | 87 | ||
| 83 | int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp) | 88 | int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp) |
| @@ -86,6 +91,10 @@ int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp) | |||
| 86 | int v1=0,v2=0,v3=0,v4=0,v5=0; | 91 | int v1=0,v2=0,v3=0,v4=0,v5=0; |
| 87 | unsigned char buf[4],ibuf1[LSIZE2],ibuf2[LSIZE2]; | 92 | unsigned char buf[4],ibuf1[LSIZE2],ibuf2[LSIZE2]; |
| 88 | unsigned char ibuf3[LSIZE2],ibuf4[LSIZE2],ibuf5[LSIZE2]; | 93 | unsigned char ibuf3[LSIZE2],ibuf4[LSIZE2],ibuf5[LSIZE2]; |
| 94 | #ifndef OPENSSL_NO_TLSEXT | ||
| 95 | int v6=0,v9=0,v10=0; | ||
| 96 | unsigned char ibuf6[LSIZE2]; | ||
| 97 | #endif | ||
| 89 | long l; | 98 | long l; |
| 90 | SSL_SESSION_ASN1 a; | 99 | SSL_SESSION_ASN1 a; |
| 91 | M_ASN1_I2D_vars(in); | 100 | M_ASN1_I2D_vars(in); |
| @@ -178,7 +187,33 @@ int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp) | |||
| 178 | ASN1_INTEGER_set(&a.verify_result,in->verify_result); | 187 | ASN1_INTEGER_set(&a.verify_result,in->verify_result); |
| 179 | } | 188 | } |
| 180 | 189 | ||
| 181 | 190 | #ifndef OPENSSL_NO_TLSEXT | |
| 191 | if (in->tlsext_hostname) | ||
| 192 | { | ||
| 193 | a.tlsext_hostname.length=strlen(in->tlsext_hostname); | ||
| 194 | a.tlsext_hostname.type=V_ASN1_OCTET_STRING; | ||
| 195 | a.tlsext_hostname.data=(unsigned char *)in->tlsext_hostname; | ||
| 196 | } | ||
| 197 | if (in->tlsext_tick) | ||
| 198 | { | ||
| 199 | a.tlsext_tick.length= in->tlsext_ticklen; | ||
| 200 | a.tlsext_tick.type=V_ASN1_OCTET_STRING; | ||
| 201 | a.tlsext_tick.data=(unsigned char *)in->tlsext_tick; | ||
| 202 | /* If we have a ticket set session ID to empty because | ||
| 203 | * it will be bogus. If liftime hint is -1 treat as a special | ||
| 204 | * case because the session is being used as a container | ||
| 205 | */ | ||
| 206 | if (in->tlsext_ticklen && (in->tlsext_tick_lifetime_hint != -1)) | ||
| 207 | a.session_id.length=0; | ||
| 208 | } | ||
| 209 | if (in->tlsext_tick_lifetime_hint > 0) | ||
| 210 | { | ||
| 211 | a.tlsext_tick_lifetime.length=LSIZE2; | ||
| 212 | a.tlsext_tick_lifetime.type=V_ASN1_INTEGER; | ||
| 213 | a.tlsext_tick_lifetime.data=ibuf6; | ||
| 214 | ASN1_INTEGER_set(&a.tlsext_tick_lifetime,in->tlsext_tick_lifetime_hint); | ||
| 215 | } | ||
| 216 | #endif /* OPENSSL_NO_TLSEXT */ | ||
| 182 | M_ASN1_I2D_len(&(a.version), i2d_ASN1_INTEGER); | 217 | M_ASN1_I2D_len(&(a.version), i2d_ASN1_INTEGER); |
| 183 | M_ASN1_I2D_len(&(a.ssl_version), i2d_ASN1_INTEGER); | 218 | M_ASN1_I2D_len(&(a.ssl_version), i2d_ASN1_INTEGER); |
| 184 | M_ASN1_I2D_len(&(a.cipher), i2d_ASN1_OCTET_STRING); | 219 | M_ASN1_I2D_len(&(a.cipher), i2d_ASN1_OCTET_STRING); |
| @@ -200,6 +235,14 @@ int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp) | |||
| 200 | if (in->verify_result != X509_V_OK) | 235 | if (in->verify_result != X509_V_OK) |
| 201 | M_ASN1_I2D_len_EXP_opt(&(a.verify_result),i2d_ASN1_INTEGER,5,v5); | 236 | M_ASN1_I2D_len_EXP_opt(&(a.verify_result),i2d_ASN1_INTEGER,5,v5); |
| 202 | 237 | ||
| 238 | #ifndef OPENSSL_NO_TLSEXT | ||
| 239 | if (in->tlsext_tick_lifetime_hint > 0) | ||
| 240 | M_ASN1_I2D_len_EXP_opt(&a.tlsext_tick_lifetime, i2d_ASN1_INTEGER,9,v9); | ||
| 241 | if (in->tlsext_tick) | ||
| 242 | M_ASN1_I2D_len_EXP_opt(&(a.tlsext_tick), i2d_ASN1_OCTET_STRING,10,v10); | ||
| 243 | if (in->tlsext_hostname) | ||
| 244 | M_ASN1_I2D_len_EXP_opt(&(a.tlsext_hostname), i2d_ASN1_OCTET_STRING,6,v6); | ||
| 245 | #endif /* OPENSSL_NO_TLSEXT */ | ||
| 203 | M_ASN1_I2D_seq_total(); | 246 | M_ASN1_I2D_seq_total(); |
| 204 | 247 | ||
| 205 | M_ASN1_I2D_put(&(a.version), i2d_ASN1_INTEGER); | 248 | M_ASN1_I2D_put(&(a.version), i2d_ASN1_INTEGER); |
| @@ -223,10 +266,18 @@ int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp) | |||
| 223 | v4); | 266 | v4); |
| 224 | if (in->verify_result != X509_V_OK) | 267 | if (in->verify_result != X509_V_OK) |
| 225 | M_ASN1_I2D_put_EXP_opt(&a.verify_result,i2d_ASN1_INTEGER,5,v5); | 268 | M_ASN1_I2D_put_EXP_opt(&a.verify_result,i2d_ASN1_INTEGER,5,v5); |
| 269 | #ifndef OPENSSL_NO_TLSEXT | ||
| 270 | if (in->tlsext_hostname) | ||
| 271 | M_ASN1_I2D_put_EXP_opt(&(a.tlsext_hostname), i2d_ASN1_OCTET_STRING,6,v6); | ||
| 272 | if (in->tlsext_tick_lifetime_hint > 0) | ||
| 273 | M_ASN1_I2D_put_EXP_opt(&a.tlsext_tick_lifetime, i2d_ASN1_INTEGER,9,v9); | ||
| 274 | if (in->tlsext_tick) | ||
| 275 | M_ASN1_I2D_put_EXP_opt(&(a.tlsext_tick), i2d_ASN1_OCTET_STRING,10,v10); | ||
| 276 | #endif /* OPENSSL_NO_TLSEXT */ | ||
| 226 | M_ASN1_I2D_finish(); | 277 | M_ASN1_I2D_finish(); |
| 227 | } | 278 | } |
| 228 | 279 | ||
| 229 | SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char * const *pp, | 280 | SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp, |
| 230 | long length) | 281 | long length) |
| 231 | { | 282 | { |
| 232 | int version,ssl_version=0,i; | 283 | int version,ssl_version=0,i; |
| @@ -242,18 +293,18 @@ SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char * const *pp, | |||
| 242 | M_ASN1_D2I_start_sequence(); | 293 | M_ASN1_D2I_start_sequence(); |
| 243 | 294 | ||
| 244 | ai.data=NULL; ai.length=0; | 295 | ai.data=NULL; ai.length=0; |
| 245 | M_ASN1_D2I_get(aip,d2i_ASN1_INTEGER); | 296 | M_ASN1_D2I_get_x(ASN1_INTEGER,aip,d2i_ASN1_INTEGER); |
| 246 | version=(int)ASN1_INTEGER_get(aip); | 297 | version=(int)ASN1_INTEGER_get(aip); |
| 247 | if (ai.data != NULL) { OPENSSL_free(ai.data); ai.data=NULL; ai.length=0; } | 298 | if (ai.data != NULL) { OPENSSL_free(ai.data); ai.data=NULL; ai.length=0; } |
| 248 | 299 | ||
| 249 | /* we don't care about the version right now :-) */ | 300 | /* we don't care about the version right now :-) */ |
| 250 | M_ASN1_D2I_get(aip,d2i_ASN1_INTEGER); | 301 | M_ASN1_D2I_get_x(ASN1_INTEGER,aip,d2i_ASN1_INTEGER); |
| 251 | ssl_version=(int)ASN1_INTEGER_get(aip); | 302 | ssl_version=(int)ASN1_INTEGER_get(aip); |
| 252 | ret->ssl_version=ssl_version; | 303 | ret->ssl_version=ssl_version; |
| 253 | if (ai.data != NULL) { OPENSSL_free(ai.data); ai.data=NULL; ai.length=0; } | 304 | if (ai.data != NULL) { OPENSSL_free(ai.data); ai.data=NULL; ai.length=0; } |
| 254 | 305 | ||
| 255 | os.data=NULL; os.length=0; | 306 | os.data=NULL; os.length=0; |
| 256 | M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING); | 307 | M_ASN1_D2I_get_x(ASN1_OCTET_STRING,osp,d2i_ASN1_OCTET_STRING); |
| 257 | if (ssl_version == SSL2_VERSION) | 308 | if (ssl_version == SSL2_VERSION) |
| 258 | { | 309 | { |
| 259 | if (os.length != 3) | 310 | if (os.length != 3) |
| @@ -286,22 +337,22 @@ SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char * const *pp, | |||
| 286 | ret->cipher=NULL; | 337 | ret->cipher=NULL; |
| 287 | ret->cipher_id=id; | 338 | ret->cipher_id=id; |
| 288 | 339 | ||
| 289 | M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING); | 340 | M_ASN1_D2I_get_x(ASN1_OCTET_STRING,osp,d2i_ASN1_OCTET_STRING); |
| 290 | if ((ssl_version>>8) == SSL3_VERSION_MAJOR) | 341 | if ((ssl_version>>8) == SSL3_VERSION_MAJOR) |
| 291 | i=SSL3_MAX_SSL_SESSION_ID_LENGTH; | 342 | i=SSL3_MAX_SSL_SESSION_ID_LENGTH; |
| 292 | else /* if (ssl_version == SSL2_VERSION_MAJOR) */ | 343 | else /* if (ssl_version>>8 == SSL2_VERSION_MAJOR) */ |
| 293 | i=SSL2_MAX_SSL_SESSION_ID_LENGTH; | 344 | i=SSL2_MAX_SSL_SESSION_ID_LENGTH; |
| 294 | 345 | ||
| 295 | if (os.length > i) | 346 | if (os.length > i) |
| 296 | os.length = i; | 347 | os.length = i; |
| 297 | if (os.length > sizeof ret->session_id) /* can't happen */ | 348 | if (os.length > (int)sizeof(ret->session_id)) /* can't happen */ |
| 298 | os.length = sizeof ret->session_id; | 349 | os.length = sizeof(ret->session_id); |
| 299 | 350 | ||
| 300 | ret->session_id_length=os.length; | 351 | ret->session_id_length=os.length; |
| 301 | OPENSSL_assert(os.length <= sizeof ret->session_id); | 352 | OPENSSL_assert(os.length <= (int)sizeof(ret->session_id)); |
| 302 | memcpy(ret->session_id,os.data,os.length); | 353 | memcpy(ret->session_id,os.data,os.length); |
| 303 | 354 | ||
| 304 | M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING); | 355 | M_ASN1_D2I_get_x(ASN1_OCTET_STRING,osp,d2i_ASN1_OCTET_STRING); |
| 305 | if (ret->master_key_length > SSL_MAX_MASTER_KEY_LENGTH) | 356 | if (ret->master_key_length > SSL_MAX_MASTER_KEY_LENGTH) |
| 306 | ret->master_key_length=SSL_MAX_MASTER_KEY_LENGTH; | 357 | ret->master_key_length=SSL_MAX_MASTER_KEY_LENGTH; |
| 307 | else | 358 | else |
| @@ -394,5 +445,56 @@ SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char * const *pp, | |||
| 394 | else | 445 | else |
| 395 | ret->verify_result=X509_V_OK; | 446 | ret->verify_result=X509_V_OK; |
| 396 | 447 | ||
| 448 | #ifndef OPENSSL_NO_TLSEXT | ||
| 449 | os.length=0; | ||
| 450 | os.data=NULL; | ||
| 451 | M_ASN1_D2I_get_EXP_opt(osp,d2i_ASN1_OCTET_STRING,6); | ||
| 452 | if (os.data) | ||
| 453 | { | ||
| 454 | ret->tlsext_hostname = BUF_strndup((char *)os.data, os.length); | ||
| 455 | OPENSSL_free(os.data); | ||
| 456 | os.data = NULL; | ||
| 457 | os.length = 0; | ||
| 458 | } | ||
| 459 | else | ||
| 460 | ret->tlsext_hostname=NULL; | ||
| 461 | ai.length=0; | ||
| 462 | M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,9); | ||
| 463 | if (ai.data != NULL) | ||
| 464 | { | ||
| 465 | ret->tlsext_tick_lifetime_hint=ASN1_INTEGER_get(aip); | ||
| 466 | OPENSSL_free(ai.data); ai.data=NULL; ai.length=0; | ||
| 467 | } | ||
| 468 | else if (ret->tlsext_ticklen && ret->session_id_length) | ||
| 469 | ret->tlsext_tick_lifetime_hint = -1; | ||
| 470 | else | ||
| 471 | ret->tlsext_tick_lifetime_hint = 0; | ||
| 472 | os.length=0; | ||
| 473 | os.data=NULL; | ||
| 474 | M_ASN1_D2I_get_EXP_opt(osp,d2i_ASN1_OCTET_STRING,10); | ||
| 475 | if (os.data) | ||
| 476 | { | ||
| 477 | ret->tlsext_tick = os.data; | ||
| 478 | ret->tlsext_ticklen = os.length; | ||
| 479 | os.data = NULL; | ||
| 480 | os.length = 0; | ||
| 481 | #if 0 | ||
| 482 | /* There are two ways to detect a resumed ticket sesion. | ||
| 483 | * One is to set a random session ID and then the server | ||
| 484 | * must return a match in ServerHello. This allows the normal | ||
| 485 | * client session ID matching to work. | ||
| 486 | */ | ||
| 487 | if (ret->session_id_length == 0) | ||
| 488 | { | ||
| 489 | ret->session_id_length=SSL3_MAX_SSL_SESSION_ID_LENGTH; | ||
| 490 | RAND_pseudo_bytes(ret->session_id, | ||
| 491 | ret->session_id_length); | ||
| 492 | } | ||
| 493 | #endif | ||
| 494 | } | ||
| 495 | else | ||
| 496 | ret->tlsext_tick=NULL; | ||
| 497 | #endif /* OPENSSL_NO_TLSEXT */ | ||
| 498 | |||
| 397 | M_ASN1_D2I_Finish(a,SSL_SESSION_free,SSL_F_D2I_SSL_SESSION); | 499 | M_ASN1_D2I_Finish(a,SSL_SESSION_free,SSL_F_D2I_SSL_SESSION); |
| 398 | } | 500 | } |
diff --git a/src/lib/libssl/ssl_cert.c b/src/lib/libssl/ssl_cert.c index b779e6bb4d..a32b2d4446 100644 --- a/src/lib/libssl/ssl_cert.c +++ b/src/lib/libssl/ssl_cert.c | |||
| @@ -56,7 +56,7 @@ | |||
| 56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
| 57 | */ | 57 | */ |
| 58 | /* ==================================================================== | 58 | /* ==================================================================== |
| 59 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | 59 | * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved. |
| 60 | * | 60 | * |
| 61 | * Redistribution and use in source and binary forms, with or without | 61 | * Redistribution and use in source and binary forms, with or without |
| 62 | * modification, are permitted provided that the following conditions | 62 | * modification, are permitted provided that the following conditions |
| @@ -73,12 +73,12 @@ | |||
| 73 | * 3. All advertising materials mentioning features or use of this | 73 | * 3. All advertising materials mentioning features or use of this |
| 74 | * software must display the following acknowledgment: | 74 | * software must display the following acknowledgment: |
| 75 | * "This product includes software developed by the OpenSSL Project | 75 | * "This product includes software developed by the OpenSSL Project |
| 76 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | 76 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" |
| 77 | * | 77 | * |
| 78 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | 78 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to |
| 79 | * endorse or promote products derived from this software without | 79 | * endorse or promote products derived from this software without |
| 80 | * prior written permission. For written permission, please contact | 80 | * prior written permission. For written permission, please contact |
| 81 | * openssl-core@OpenSSL.org. | 81 | * openssl-core@openssl.org. |
| 82 | * | 82 | * |
| 83 | * 5. Products derived from this software may not be called "OpenSSL" | 83 | * 5. Products derived from this software may not be called "OpenSSL" |
| 84 | * nor may "OpenSSL" appear in their names without prior written | 84 | * nor may "OpenSSL" appear in their names without prior written |
| @@ -87,7 +87,7 @@ | |||
| 87 | * 6. Redistributions of any form whatsoever must retain the following | 87 | * 6. Redistributions of any form whatsoever must retain the following |
| 88 | * acknowledgment: | 88 | * acknowledgment: |
| 89 | * "This product includes software developed by the OpenSSL Project | 89 | * "This product includes software developed by the OpenSSL Project |
| 90 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | 90 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" |
| 91 | * | 91 | * |
| 92 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | 92 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY |
| 93 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 93 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| @@ -102,6 +102,16 @@ | |||
| 102 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | 102 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 103 | * OF THE POSSIBILITY OF SUCH DAMAGE. | 103 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
| 104 | * ==================================================================== | 104 | * ==================================================================== |
| 105 | * | ||
| 106 | * This product includes cryptographic software written by Eric Young | ||
| 107 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 108 | * Hudson (tjh@cryptsoft.com). | ||
| 109 | * | ||
| 110 | */ | ||
| 111 | /* ==================================================================== | ||
| 112 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
| 113 | * ECC cipher suite support in OpenSSL originally developed by | ||
| 114 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. | ||
| 105 | */ | 115 | */ |
| 106 | 116 | ||
| 107 | #include <stdio.h> | 117 | #include <stdio.h> |
| @@ -111,45 +121,42 @@ | |||
| 111 | # include <sys/types.h> | 121 | # include <sys/types.h> |
| 112 | #endif | 122 | #endif |
| 113 | 123 | ||
| 114 | #if !defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_SYS_VMS) && !defined(NeXT) && !defined(MAC_OS_pre_X) | 124 | #include "o_dir.h" |
| 115 | #include <dirent.h> | ||
| 116 | #endif | ||
| 117 | |||
| 118 | #if defined(WIN32) | ||
| 119 | #include <windows.h> | ||
| 120 | #include <tchar.h> | ||
| 121 | #endif | ||
| 122 | |||
| 123 | #ifdef NeXT | ||
| 124 | #include <sys/dir.h> | ||
| 125 | #define dirent direct | ||
| 126 | #endif | ||
| 127 | |||
| 128 | #include <openssl/objects.h> | 125 | #include <openssl/objects.h> |
| 129 | #include <openssl/bio.h> | 126 | #include <openssl/bio.h> |
| 130 | #include <openssl/pem.h> | 127 | #include <openssl/pem.h> |
| 131 | #include <openssl/x509v3.h> | 128 | #include <openssl/x509v3.h> |
| 129 | #ifndef OPENSSL_NO_DH | ||
| 130 | #include <openssl/dh.h> | ||
| 131 | #endif | ||
| 132 | #include <openssl/bn.h> | ||
| 132 | #include "ssl_locl.h" | 133 | #include "ssl_locl.h" |
| 133 | #include <openssl/fips.h> | ||
| 134 | 134 | ||
| 135 | int SSL_get_ex_data_X509_STORE_CTX_idx(void) | 135 | int SSL_get_ex_data_X509_STORE_CTX_idx(void) |
| 136 | { | 136 | { |
| 137 | static volatile int ssl_x509_store_ctx_idx= -1; | 137 | static volatile int ssl_x509_store_ctx_idx= -1; |
| 138 | int got_write_lock = 0; | ||
| 139 | |||
| 140 | CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX); | ||
| 138 | 141 | ||
| 139 | if (ssl_x509_store_ctx_idx < 0) | 142 | if (ssl_x509_store_ctx_idx < 0) |
| 140 | { | 143 | { |
| 141 | /* any write lock will do; usually this branch | 144 | CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX); |
| 142 | * will only be taken once anyway */ | ||
| 143 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX); | 145 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX); |
| 146 | got_write_lock = 1; | ||
| 144 | 147 | ||
| 145 | if (ssl_x509_store_ctx_idx < 0) | 148 | if (ssl_x509_store_ctx_idx < 0) |
| 146 | { | 149 | { |
| 147 | ssl_x509_store_ctx_idx=X509_STORE_CTX_get_ex_new_index( | 150 | ssl_x509_store_ctx_idx=X509_STORE_CTX_get_ex_new_index( |
| 148 | 0,"SSL for verify callback",NULL,NULL,NULL); | 151 | 0,"SSL for verify callback",NULL,NULL,NULL); |
| 149 | } | 152 | } |
| 150 | |||
| 151 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX); | ||
| 152 | } | 153 | } |
| 154 | |||
| 155 | if (got_write_lock) | ||
| 156 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX); | ||
| 157 | else | ||
| 158 | CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX); | ||
| 159 | |||
| 153 | return ssl_x509_store_ctx_idx; | 160 | return ssl_x509_store_ctx_idx; |
| 154 | } | 161 | } |
| 155 | 162 | ||
| @@ -205,7 +212,6 @@ CERT *ssl_cert_dup(CERT *cert) | |||
| 205 | #ifndef OPENSSL_NO_DH | 212 | #ifndef OPENSSL_NO_DH |
| 206 | if (cert->dh_tmp != NULL) | 213 | if (cert->dh_tmp != NULL) |
| 207 | { | 214 | { |
| 208 | /* DH parameters don't have a reference count */ | ||
| 209 | ret->dh_tmp = DHparams_dup(cert->dh_tmp); | 215 | ret->dh_tmp = DHparams_dup(cert->dh_tmp); |
| 210 | if (ret->dh_tmp == NULL) | 216 | if (ret->dh_tmp == NULL) |
| 211 | { | 217 | { |
| @@ -236,6 +242,19 @@ CERT *ssl_cert_dup(CERT *cert) | |||
| 236 | ret->dh_tmp_cb = cert->dh_tmp_cb; | 242 | ret->dh_tmp_cb = cert->dh_tmp_cb; |
| 237 | #endif | 243 | #endif |
| 238 | 244 | ||
| 245 | #ifndef OPENSSL_NO_ECDH | ||
| 246 | if (cert->ecdh_tmp) | ||
| 247 | { | ||
| 248 | ret->ecdh_tmp = EC_KEY_dup(cert->ecdh_tmp); | ||
| 249 | if (ret->ecdh_tmp == NULL) | ||
| 250 | { | ||
| 251 | SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_EC_LIB); | ||
| 252 | goto err; | ||
| 253 | } | ||
| 254 | } | ||
| 255 | ret->ecdh_tmp_cb = cert->ecdh_tmp_cb; | ||
| 256 | #endif | ||
| 257 | |||
| 239 | for (i = 0; i < SSL_PKEY_NUM; i++) | 258 | for (i = 0; i < SSL_PKEY_NUM; i++) |
| 240 | { | 259 | { |
| 241 | if (cert->pkeys[i].x509 != NULL) | 260 | if (cert->pkeys[i].x509 != NULL) |
| @@ -270,7 +289,11 @@ CERT *ssl_cert_dup(CERT *cert) | |||
| 270 | case SSL_PKEY_DH_DSA: | 289 | case SSL_PKEY_DH_DSA: |
| 271 | /* We have a DH key. */ | 290 | /* We have a DH key. */ |
| 272 | break; | 291 | break; |
| 273 | 292 | ||
| 293 | case SSL_PKEY_ECC: | ||
| 294 | /* We have an ECC key */ | ||
| 295 | break; | ||
| 296 | |||
| 274 | default: | 297 | default: |
| 275 | /* Can't happen. */ | 298 | /* Can't happen. */ |
| 276 | SSLerr(SSL_F_SSL_CERT_DUP, SSL_R_LIBRARY_BUG); | 299 | SSLerr(SSL_F_SSL_CERT_DUP, SSL_R_LIBRARY_BUG); |
| @@ -285,7 +308,7 @@ CERT *ssl_cert_dup(CERT *cert) | |||
| 285 | 308 | ||
| 286 | return(ret); | 309 | return(ret); |
| 287 | 310 | ||
| 288 | #ifndef OPENSSL_NO_DH /* avoid 'unreferenced label' warning if OPENSSL_NO_DH is defined */ | 311 | #if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_ECDH) |
| 289 | err: | 312 | err: |
| 290 | #endif | 313 | #endif |
| 291 | #ifndef OPENSSL_NO_RSA | 314 | #ifndef OPENSSL_NO_RSA |
| @@ -296,6 +319,10 @@ err: | |||
| 296 | if (ret->dh_tmp != NULL) | 319 | if (ret->dh_tmp != NULL) |
| 297 | DH_free(ret->dh_tmp); | 320 | DH_free(ret->dh_tmp); |
| 298 | #endif | 321 | #endif |
| 322 | #ifndef OPENSSL_NO_ECDH | ||
| 323 | if (ret->ecdh_tmp != NULL) | ||
| 324 | EC_KEY_free(ret->ecdh_tmp); | ||
| 325 | #endif | ||
| 299 | 326 | ||
| 300 | for (i = 0; i < SSL_PKEY_NUM; i++) | 327 | for (i = 0; i < SSL_PKEY_NUM; i++) |
| 301 | { | 328 | { |
| @@ -335,6 +362,9 @@ void ssl_cert_free(CERT *c) | |||
| 335 | #ifndef OPENSSL_NO_DH | 362 | #ifndef OPENSSL_NO_DH |
| 336 | if (c->dh_tmp) DH_free(c->dh_tmp); | 363 | if (c->dh_tmp) DH_free(c->dh_tmp); |
| 337 | #endif | 364 | #endif |
| 365 | #ifndef OPENSSL_NO_ECDH | ||
| 366 | if (c->ecdh_tmp) EC_KEY_free(c->ecdh_tmp); | ||
| 367 | #endif | ||
| 338 | 368 | ||
| 339 | for (i=0; i<SSL_PKEY_NUM; i++) | 369 | for (i=0; i<SSL_PKEY_NUM; i++) |
| 340 | { | 370 | { |
| @@ -441,6 +471,10 @@ void ssl_sess_cert_free(SESS_CERT *sc) | |||
| 441 | if (sc->peer_dh_tmp != NULL) | 471 | if (sc->peer_dh_tmp != NULL) |
| 442 | DH_free(sc->peer_dh_tmp); | 472 | DH_free(sc->peer_dh_tmp); |
| 443 | #endif | 473 | #endif |
| 474 | #ifndef OPENSSL_NO_ECDH | ||
| 475 | if (sc->peer_ecdh_tmp != NULL) | ||
| 476 | EC_KEY_free(sc->peer_ecdh_tmp); | ||
| 477 | #endif | ||
| 444 | 478 | ||
| 445 | OPENSSL_free(sc); | 479 | OPENSSL_free(sc); |
| 446 | } | 480 | } |
| @@ -466,20 +500,22 @@ int ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk) | |||
| 466 | SSLerr(SSL_F_SSL_VERIFY_CERT_CHAIN,ERR_R_X509_LIB); | 500 | SSLerr(SSL_F_SSL_VERIFY_CERT_CHAIN,ERR_R_X509_LIB); |
| 467 | return(0); | 501 | return(0); |
| 468 | } | 502 | } |
| 503 | if (s->param) | ||
| 504 | X509_VERIFY_PARAM_inherit(X509_STORE_CTX_get0_param(&ctx), | ||
| 505 | s->param); | ||
| 506 | #if 0 | ||
| 469 | if (SSL_get_verify_depth(s) >= 0) | 507 | if (SSL_get_verify_depth(s) >= 0) |
| 470 | X509_STORE_CTX_set_depth(&ctx, SSL_get_verify_depth(s)); | 508 | X509_STORE_CTX_set_depth(&ctx, SSL_get_verify_depth(s)); |
| 509 | #endif | ||
| 471 | X509_STORE_CTX_set_ex_data(&ctx,SSL_get_ex_data_X509_STORE_CTX_idx(),s); | 510 | X509_STORE_CTX_set_ex_data(&ctx,SSL_get_ex_data_X509_STORE_CTX_idx(),s); |
| 472 | 511 | ||
| 473 | /* We need to set the verify purpose. The purpose can be determined by | 512 | /* We need to inherit the verify parameters. These can be determined by |
| 474 | * the context: if its a server it will verify SSL client certificates | 513 | * the context: if its a server it will verify SSL client certificates |
| 475 | * or vice versa. | 514 | * or vice versa. |
| 476 | */ | 515 | */ |
| 477 | if (s->server) | ||
| 478 | i = X509_PURPOSE_SSL_CLIENT; | ||
| 479 | else | ||
| 480 | i = X509_PURPOSE_SSL_SERVER; | ||
| 481 | 516 | ||
| 482 | X509_STORE_CTX_purpose_inherit(&ctx, i, s->purpose, s->trust); | 517 | X509_STORE_CTX_set_default(&ctx, |
| 518 | s->server ? "ssl_client" : "ssl_server"); | ||
| 483 | 519 | ||
| 484 | if (s->verify_callback) | 520 | if (s->verify_callback) |
| 485 | X509_STORE_CTX_set_verify_cb(&ctx, s->verify_callback); | 521 | X509_STORE_CTX_set_verify_cb(&ctx, s->verify_callback); |
| @@ -726,7 +762,7 @@ err: | |||
| 726 | if(x != NULL) | 762 | if(x != NULL) |
| 727 | X509_free(x); | 763 | X509_free(x); |
| 728 | 764 | ||
| 729 | sk_X509_NAME_set_cmp_func(stack,oldcmp); | 765 | (void)sk_X509_NAME_set_cmp_func(stack,oldcmp); |
| 730 | 766 | ||
| 731 | return ret; | 767 | return ret; |
| 732 | } | 768 | } |
| @@ -742,157 +778,52 @@ err: | |||
| 742 | * certs may have been added to \c stack. | 778 | * certs may have been added to \c stack. |
| 743 | */ | 779 | */ |
| 744 | 780 | ||
| 745 | #ifndef OPENSSL_SYS_WIN32 | ||
| 746 | #ifndef OPENSSL_SYS_VMS /* XXXX This may be fixed in the future */ | ||
| 747 | #ifndef OPENSSL_SYS_MACINTOSH_CLASSIC /* XXXXX: Better scheme needed! */ | ||
| 748 | |||
| 749 | int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack, | 781 | int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack, |
| 750 | const char *dir) | 782 | const char *dir) |
| 751 | { | 783 | { |
| 752 | DIR *d; | 784 | OPENSSL_DIR_CTX *d = NULL; |
| 753 | struct dirent *dstruct; | 785 | const char *filename; |
| 754 | int ret = 0; | 786 | int ret = 0; |
| 755 | 787 | ||
| 756 | CRYPTO_w_lock(CRYPTO_LOCK_READDIR); | 788 | CRYPTO_w_lock(CRYPTO_LOCK_READDIR); |
| 757 | d = opendir(dir); | ||
| 758 | 789 | ||
| 759 | /* Note that a side effect is that the CAs will be sorted by name */ | 790 | /* Note that a side effect is that the CAs will be sorted by name */ |
| 760 | if(!d) | 791 | |
| 761 | { | 792 | while((filename = OPENSSL_DIR_read(&d, dir))) |
| 762 | SYSerr(SYS_F_OPENDIR, get_last_sys_error()); | ||
| 763 | ERR_add_error_data(3, "opendir('", dir, "')"); | ||
| 764 | SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, ERR_R_SYS_LIB); | ||
| 765 | goto err; | ||
| 766 | } | ||
| 767 | |||
| 768 | while((dstruct=readdir(d))) | ||
| 769 | { | 793 | { |
| 770 | char buf[1024]; | 794 | char buf[1024]; |
| 771 | int r; | 795 | int r; |
| 772 | 796 | ||
| 773 | if(strlen(dir)+strlen(dstruct->d_name)+2 > sizeof buf) | 797 | if(strlen(dir)+strlen(filename)+2 > sizeof buf) |
| 774 | { | 798 | { |
| 775 | SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG); | 799 | SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG); |
| 776 | goto err; | 800 | goto err; |
| 777 | } | 801 | } |
| 778 | 802 | ||
| 779 | r = BIO_snprintf(buf,sizeof buf,"%s/%s",dir,dstruct->d_name); | 803 | #ifdef OPENSSL_SYS_VMS |
| 780 | if (r <= 0 || r >= sizeof buf) | 804 | r = BIO_snprintf(buf,sizeof buf,"%s%s",dir,filename); |
| 805 | #else | ||
| 806 | r = BIO_snprintf(buf,sizeof buf,"%s/%s",dir,filename); | ||
| 807 | #endif | ||
| 808 | if (r <= 0 || r >= (int)sizeof(buf)) | ||
| 781 | goto err; | 809 | goto err; |
| 782 | if(!SSL_add_file_cert_subjects_to_stack(stack,buf)) | 810 | if(!SSL_add_file_cert_subjects_to_stack(stack,buf)) |
| 783 | goto err; | 811 | goto err; |
| 784 | } | 812 | } |
| 785 | ret = 1; | ||
| 786 | |||
| 787 | err: | ||
| 788 | if (d) closedir(d); | ||
| 789 | CRYPTO_w_unlock(CRYPTO_LOCK_READDIR); | ||
| 790 | return ret; | ||
| 791 | } | ||
| 792 | |||
| 793 | #endif | ||
| 794 | #endif | ||
| 795 | |||
| 796 | #else /* OPENSSL_SYS_WIN32 */ | ||
| 797 | |||
| 798 | #if defined(_WIN32_WCE) | ||
| 799 | # ifndef UNICODE | ||
| 800 | # error "WinCE comes in UNICODE flavor only..." | ||
| 801 | # endif | ||
| 802 | # if _WIN32_WCE<101 && !defined(OPENSSL_NO_MULTIBYTE) | ||
| 803 | # define OPENSSL_NO_MULTIBYTE | ||
| 804 | # endif | ||
| 805 | # ifndef FindFirstFile | ||
| 806 | # define FindFirstFile FindFirstFileW | ||
| 807 | # endif | ||
| 808 | # ifndef FindNextFile | ||
| 809 | # define FindNextFile FindNextFileW | ||
| 810 | # endif | ||
| 811 | #endif | ||
| 812 | |||
| 813 | int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack, | ||
| 814 | const char *dir) | ||
| 815 | { | ||
| 816 | WIN32_FIND_DATA FindFileData; | ||
| 817 | HANDLE hFind; | ||
| 818 | int ret = 0; | ||
| 819 | TCHAR *wdir = NULL; | ||
| 820 | size_t i,len_0 = strlen(dir)+1; /* len_0 accounts for trailing 0 */ | ||
| 821 | char buf[1024],*slash; | ||
| 822 | |||
| 823 | if (len_0 > (sizeof(buf)-14)) /* 14 is just some value... */ | ||
| 824 | { | ||
| 825 | SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG); | ||
| 826 | return ret; | ||
| 827 | } | ||
| 828 | |||
| 829 | CRYPTO_w_lock(CRYPTO_LOCK_READDIR); | ||
| 830 | |||
| 831 | if (sizeof(TCHAR) != sizeof(char)) | ||
| 832 | { | ||
| 833 | wdir = (TCHAR *)malloc(len_0*sizeof(TCHAR)); | ||
| 834 | if (wdir == NULL) | ||
| 835 | goto err_noclose; | ||
| 836 | #ifndef OPENSSL_NO_MULTIBYTE | ||
| 837 | if (!MultiByteToWideChar(CP_ACP,0,dir,len_0, | ||
| 838 | (WCHAR *)wdir,len_0)) | ||
| 839 | #endif | ||
| 840 | for (i=0;i<len_0;i++) wdir[i]=(TCHAR)dir[i]; | ||
| 841 | |||
| 842 | hFind = FindFirstFile(wdir, &FindFileData); | ||
| 843 | } | ||
| 844 | else hFind = FindFirstFile((const TCHAR *)dir, &FindFileData); | ||
| 845 | 813 | ||
| 846 | /* Note that a side effect is that the CAs will be sorted by name */ | 814 | if (errno) |
| 847 | if(hFind == INVALID_HANDLE_VALUE) | ||
| 848 | { | 815 | { |
| 849 | SYSerr(SYS_F_OPENDIR, get_last_sys_error()); | 816 | SYSerr(SYS_F_OPENDIR, get_last_sys_error()); |
| 850 | ERR_add_error_data(3, "opendir('", dir, "')"); | 817 | ERR_add_error_data(3, "OPENSSL_DIR_read(&ctx, '", dir, "')"); |
| 851 | SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, ERR_R_SYS_LIB); | 818 | SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, ERR_R_SYS_LIB); |
| 852 | goto err_noclose; | 819 | goto err; |
| 853 | } | 820 | } |
| 854 | 821 | ||
| 855 | strncpy(buf,dir,sizeof(buf)); /* strcpy is safe too... */ | ||
| 856 | buf[len_0-1]='/'; /* no trailing zero! */ | ||
| 857 | slash=buf+len_0; | ||
| 858 | |||
| 859 | do { | ||
| 860 | const TCHAR *fnam=FindFileData.cFileName; | ||
| 861 | size_t flen_0=_tcslen(fnam)+1; | ||
| 862 | |||
| 863 | if (flen_0 > (sizeof(buf)-len_0)) | ||
| 864 | { | ||
| 865 | SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG); | ||
| 866 | goto err; | ||
| 867 | } | ||
| 868 | /* else strcpy would be safe too... */ | ||
| 869 | |||
| 870 | if (sizeof(TCHAR) != sizeof(char)) | ||
| 871 | { | ||
| 872 | #ifndef OPENSSL_NO_MULTIBYTE | ||
| 873 | if (!WideCharToMultiByte(CP_ACP,0, | ||
| 874 | (WCHAR *)fnam,flen_0, | ||
| 875 | slash,sizeof(buf)-len_0, | ||
| 876 | NULL,0)) | ||
| 877 | #endif | ||
| 878 | for (i=0;i<flen_0;i++) slash[i]=(char)fnam[i]; | ||
| 879 | } | ||
| 880 | else strncpy(slash,(const char *)fnam,sizeof(buf)-len_0); | ||
| 881 | |||
| 882 | if(!SSL_add_file_cert_subjects_to_stack(stack,buf)) | ||
| 883 | goto err; | ||
| 884 | } | ||
| 885 | while (FindNextFile(hFind, &FindFileData) != FALSE); | ||
| 886 | ret = 1; | 822 | ret = 1; |
| 887 | 823 | ||
| 888 | err: | 824 | err: |
| 889 | FindClose(hFind); | 825 | if (d) OPENSSL_DIR_end(&d); |
| 890 | err_noclose: | ||
| 891 | if (wdir != NULL) | ||
| 892 | free(wdir); | ||
| 893 | |||
| 894 | CRYPTO_w_unlock(CRYPTO_LOCK_READDIR); | 826 | CRYPTO_w_unlock(CRYPTO_LOCK_READDIR); |
| 895 | return ret; | 827 | return ret; |
| 896 | } | 828 | } |
| 897 | 829 | ||
| 898 | #endif | ||
diff --git a/src/lib/libssl/ssl_ciph.c b/src/lib/libssl/ssl_ciph.c index 3df5e2fa80..725f7f3c1f 100644 --- a/src/lib/libssl/ssl_ciph.c +++ b/src/lib/libssl/ssl_ciph.c | |||
| @@ -55,11 +55,67 @@ | |||
| 55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
| 56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
| 57 | */ | 57 | */ |
| 58 | 58 | /* ==================================================================== | |
| 59 | * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved. | ||
| 60 | * | ||
| 61 | * Redistribution and use in source and binary forms, with or without | ||
| 62 | * modification, are permitted provided that the following conditions | ||
| 63 | * are met: | ||
| 64 | * | ||
| 65 | * 1. Redistributions of source code must retain the above copyright | ||
| 66 | * notice, this list of conditions and the following disclaimer. | ||
| 67 | * | ||
| 68 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 69 | * notice, this list of conditions and the following disclaimer in | ||
| 70 | * the documentation and/or other materials provided with the | ||
| 71 | * distribution. | ||
| 72 | * | ||
| 73 | * 3. All advertising materials mentioning features or use of this | ||
| 74 | * software must display the following acknowledgment: | ||
| 75 | * "This product includes software developed by the OpenSSL Project | ||
| 76 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 77 | * | ||
| 78 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 79 | * endorse or promote products derived from this software without | ||
| 80 | * prior written permission. For written permission, please contact | ||
| 81 | * openssl-core@openssl.org. | ||
| 82 | * | ||
| 83 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 84 | * nor may "OpenSSL" appear in their names without prior written | ||
| 85 | * permission of the OpenSSL Project. | ||
| 86 | * | ||
| 87 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 88 | * acknowledgment: | ||
| 89 | * "This product includes software developed by the OpenSSL Project | ||
| 90 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 91 | * | ||
| 92 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 93 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 94 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 95 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 96 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 97 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 98 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 99 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 100 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 101 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 102 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 103 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 104 | * ==================================================================== | ||
| 105 | * | ||
| 106 | * This product includes cryptographic software written by Eric Young | ||
| 107 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 108 | * Hudson (tjh@cryptsoft.com). | ||
| 109 | * | ||
| 110 | */ | ||
| 111 | /* ==================================================================== | ||
| 112 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
| 113 | * ECC cipher suite support in OpenSSL originally developed by | ||
| 114 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. | ||
| 115 | */ | ||
| 59 | #include <stdio.h> | 116 | #include <stdio.h> |
| 60 | #include <openssl/objects.h> | 117 | #include <openssl/objects.h> |
| 61 | #include <openssl/comp.h> | 118 | #include <openssl/comp.h> |
| 62 | #include <openssl/fips.h> | ||
| 63 | #include "ssl_locl.h" | 119 | #include "ssl_locl.h" |
| 64 | 120 | ||
| 65 | #define SSL_ENC_DES_IDX 0 | 121 | #define SSL_ENC_DES_IDX 0 |
| @@ -71,12 +127,20 @@ | |||
| 71 | #define SSL_ENC_NULL_IDX 6 | 127 | #define SSL_ENC_NULL_IDX 6 |
| 72 | #define SSL_ENC_AES128_IDX 7 | 128 | #define SSL_ENC_AES128_IDX 7 |
| 73 | #define SSL_ENC_AES256_IDX 8 | 129 | #define SSL_ENC_AES256_IDX 8 |
| 74 | #define SSL_ENC_NUM_IDX 9 | 130 | #define SSL_ENC_CAMELLIA128_IDX 9 |
| 131 | #define SSL_ENC_CAMELLIA256_IDX 10 | ||
| 132 | #define SSL_ENC_SEED_IDX 11 | ||
| 133 | #define SSL_ENC_NUM_IDX 12 | ||
| 134 | |||
| 75 | 135 | ||
| 76 | static const EVP_CIPHER *ssl_cipher_methods[SSL_ENC_NUM_IDX]={ | 136 | static const EVP_CIPHER *ssl_cipher_methods[SSL_ENC_NUM_IDX]={ |
| 77 | NULL,NULL,NULL,NULL,NULL,NULL, | 137 | NULL,NULL,NULL,NULL,NULL,NULL, |
| 78 | }; | 138 | }; |
| 79 | 139 | ||
| 140 | #define SSL_COMP_NULL_IDX 0 | ||
| 141 | #define SSL_COMP_ZLIB_IDX 1 | ||
| 142 | #define SSL_COMP_NUM_IDX 2 | ||
| 143 | |||
| 80 | static STACK_OF(SSL_COMP) *ssl_comp_methods=NULL; | 144 | static STACK_OF(SSL_COMP) *ssl_comp_methods=NULL; |
| 81 | 145 | ||
| 82 | #define SSL_MD_MD5_IDX 0 | 146 | #define SSL_MD_MD5_IDX 0 |
| @@ -102,18 +166,20 @@ typedef struct cipher_order_st | |||
| 102 | 166 | ||
| 103 | static const SSL_CIPHER cipher_aliases[]={ | 167 | static const SSL_CIPHER cipher_aliases[]={ |
| 104 | /* Don't include eNULL unless specifically enabled. */ | 168 | /* Don't include eNULL unless specifically enabled. */ |
| 105 | {0,SSL_TXT_ALL, 0,SSL_ALL & ~SSL_eNULL, SSL_ALL ,0,0,0,SSL_ALL,SSL_ALL}, /* must be first */ | 169 | /* Don't include ECC in ALL because these ciphers are not yet official. */ |
| 106 | {0,SSL_TXT_CMPALL,0,SSL_eNULL,0,0,0,0,SSL_ENC_MASK,0}, /* COMPLEMENT OF ALL */ | 170 | {0,SSL_TXT_ALL, 0,SSL_ALL & ~SSL_eNULL & ~SSL_kECDH & ~SSL_kECDHE, SSL_ALL ,0,0,0,SSL_ALL,SSL_ALL}, /* must be first */ |
| 171 | /* TODO: COMPLEMENT OF ALL and COMPLEMENT OF DEFAULT do not have ECC cipher suites handled properly. */ | ||
| 172 | {0,SSL_TXT_CMPALL,0,SSL_eNULL,0,0,0,0,SSL_ENC_MASK,0}, /* COMPLEMENT OF ALL */ | ||
| 107 | {0,SSL_TXT_CMPDEF,0,SSL_ADH, 0,0,0,0,SSL_AUTH_MASK,0}, | 173 | {0,SSL_TXT_CMPDEF,0,SSL_ADH, 0,0,0,0,SSL_AUTH_MASK,0}, |
| 108 | {0,SSL_TXT_kKRB5,0,SSL_kKRB5,0,0,0,0,SSL_MKEY_MASK,0}, /* VRS Kerberos5 */ | 174 | {0,SSL_TXT_kKRB5,0,SSL_kKRB5,0,0,0,0,SSL_MKEY_MASK,0}, /* VRS Kerberos5 */ |
| 109 | {0,SSL_TXT_kRSA,0,SSL_kRSA, 0,0,0,0,SSL_MKEY_MASK,0}, | 175 | {0,SSL_TXT_kRSA,0,SSL_kRSA, 0,0,0,0,SSL_MKEY_MASK,0}, |
| 110 | {0,SSL_TXT_kDHr,0,SSL_kDHr, 0,0,0,0,SSL_MKEY_MASK,0}, | 176 | {0,SSL_TXT_kDHr,0,SSL_kDHr, 0,0,0,0,SSL_MKEY_MASK,0}, |
| 111 | {0,SSL_TXT_kDHd,0,SSL_kDHd, 0,0,0,0,SSL_MKEY_MASK,0}, | 177 | {0,SSL_TXT_kDHd,0,SSL_kDHd, 0,0,0,0,SSL_MKEY_MASK,0}, |
| 112 | {0,SSL_TXT_kEDH,0,SSL_kEDH, 0,0,0,0,SSL_MKEY_MASK,0}, | 178 | {0,SSL_TXT_kEDH,0,SSL_kEDH, 0,0,0,0,SSL_MKEY_MASK,0}, |
| 113 | {0,SSL_TXT_kFZA,0,SSL_kFZA, 0,0,0,0,SSL_MKEY_MASK,0}, | 179 | {0,SSL_TXT_kFZA,0,SSL_kFZA, 0,0,0,0,SSL_MKEY_MASK,0}, |
| 114 | {0,SSL_TXT_DH, 0,SSL_DH, 0,0,0,0,SSL_MKEY_MASK,0}, | 180 | {0,SSL_TXT_DH, 0,SSL_DH, 0,0,0,0,SSL_MKEY_MASK,0}, |
| 181 | {0,SSL_TXT_ECC, 0,(SSL_kECDH|SSL_kECDHE), 0,0,0,0,SSL_MKEY_MASK,0}, | ||
| 115 | {0,SSL_TXT_EDH, 0,SSL_EDH, 0,0,0,0,SSL_MKEY_MASK|SSL_AUTH_MASK,0}, | 182 | {0,SSL_TXT_EDH, 0,SSL_EDH, 0,0,0,0,SSL_MKEY_MASK|SSL_AUTH_MASK,0}, |
| 116 | |||
| 117 | {0,SSL_TXT_aKRB5,0,SSL_aKRB5,0,0,0,0,SSL_AUTH_MASK,0}, /* VRS Kerberos5 */ | 183 | {0,SSL_TXT_aKRB5,0,SSL_aKRB5,0,0,0,0,SSL_AUTH_MASK,0}, /* VRS Kerberos5 */ |
| 118 | {0,SSL_TXT_aRSA,0,SSL_aRSA, 0,0,0,0,SSL_AUTH_MASK,0}, | 184 | {0,SSL_TXT_aRSA,0,SSL_aRSA, 0,0,0,0,SSL_AUTH_MASK,0}, |
| 119 | {0,SSL_TXT_aDSS,0,SSL_aDSS, 0,0,0,0,SSL_AUTH_MASK,0}, | 185 | {0,SSL_TXT_aDSS,0,SSL_aDSS, 0,0,0,0,SSL_AUTH_MASK,0}, |
| @@ -129,9 +195,11 @@ static const SSL_CIPHER cipher_aliases[]={ | |||
| 129 | #ifndef OPENSSL_NO_IDEA | 195 | #ifndef OPENSSL_NO_IDEA |
| 130 | {0,SSL_TXT_IDEA,0,SSL_IDEA, 0,0,0,0,SSL_ENC_MASK,0}, | 196 | {0,SSL_TXT_IDEA,0,SSL_IDEA, 0,0,0,0,SSL_ENC_MASK,0}, |
| 131 | #endif | 197 | #endif |
| 198 | {0,SSL_TXT_SEED,0,SSL_SEED, 0,0,0,0,SSL_ENC_MASK,0}, | ||
| 132 | {0,SSL_TXT_eNULL,0,SSL_eNULL,0,0,0,0,SSL_ENC_MASK,0}, | 199 | {0,SSL_TXT_eNULL,0,SSL_eNULL,0,0,0,0,SSL_ENC_MASK,0}, |
| 133 | {0,SSL_TXT_eFZA,0,SSL_eFZA, 0,0,0,0,SSL_ENC_MASK,0}, | 200 | {0,SSL_TXT_eFZA,0,SSL_eFZA, 0,0,0,0,SSL_ENC_MASK,0}, |
| 134 | {0,SSL_TXT_AES, 0,SSL_AES, 0,0,0,0,SSL_ENC_MASK,0}, | 201 | {0,SSL_TXT_AES, 0,SSL_AES, 0,0,0,0,SSL_ENC_MASK,0}, |
| 202 | {0,SSL_TXT_CAMELLIA,0,SSL_CAMELLIA, 0,0,0,0,SSL_ENC_MASK,0}, | ||
| 135 | 203 | ||
| 136 | {0,SSL_TXT_MD5, 0,SSL_MD5, 0,0,0,0,SSL_MAC_MASK,0}, | 204 | {0,SSL_TXT_MD5, 0,SSL_MD5, 0,0,0,0,SSL_MAC_MASK,0}, |
| 137 | {0,SSL_TXT_SHA1,0,SSL_SHA1, 0,0,0,0,SSL_MAC_MASK,0}, | 205 | {0,SSL_TXT_SHA1,0,SSL_SHA1, 0,0,0,0,SSL_MAC_MASK,0}, |
| @@ -154,12 +222,9 @@ static const SSL_CIPHER cipher_aliases[]={ | |||
| 154 | {0,SSL_TXT_LOW, 0, 0, SSL_LOW, 0,0,0,0,SSL_STRONG_MASK}, | 222 | {0,SSL_TXT_LOW, 0, 0, SSL_LOW, 0,0,0,0,SSL_STRONG_MASK}, |
| 155 | {0,SSL_TXT_MEDIUM,0, 0,SSL_MEDIUM, 0,0,0,0,SSL_STRONG_MASK}, | 223 | {0,SSL_TXT_MEDIUM,0, 0,SSL_MEDIUM, 0,0,0,0,SSL_STRONG_MASK}, |
| 156 | {0,SSL_TXT_HIGH, 0, 0, SSL_HIGH, 0,0,0,0,SSL_STRONG_MASK}, | 224 | {0,SSL_TXT_HIGH, 0, 0, SSL_HIGH, 0,0,0,0,SSL_STRONG_MASK}, |
| 157 | {0,SSL_TXT_FIPS, 0, 0, SSL_FIPS, 0,0,0,0,SSL_FIPS|SSL_STRONG_NONE}, | ||
| 158 | }; | 225 | }; |
| 159 | 226 | ||
| 160 | static int init_ciphers=1; | 227 | void ssl_load_ciphers(void) |
| 161 | |||
| 162 | static void load_ciphers(void) | ||
| 163 | { | 228 | { |
| 164 | ssl_cipher_methods[SSL_ENC_DES_IDX]= | 229 | ssl_cipher_methods[SSL_ENC_DES_IDX]= |
| 165 | EVP_get_cipherbyname(SN_des_cbc); | 230 | EVP_get_cipherbyname(SN_des_cbc); |
| @@ -179,14 +244,73 @@ static void load_ciphers(void) | |||
| 179 | EVP_get_cipherbyname(SN_aes_128_cbc); | 244 | EVP_get_cipherbyname(SN_aes_128_cbc); |
| 180 | ssl_cipher_methods[SSL_ENC_AES256_IDX]= | 245 | ssl_cipher_methods[SSL_ENC_AES256_IDX]= |
| 181 | EVP_get_cipherbyname(SN_aes_256_cbc); | 246 | EVP_get_cipherbyname(SN_aes_256_cbc); |
| 247 | ssl_cipher_methods[SSL_ENC_CAMELLIA128_IDX]= | ||
| 248 | EVP_get_cipherbyname(SN_camellia_128_cbc); | ||
| 249 | ssl_cipher_methods[SSL_ENC_CAMELLIA256_IDX]= | ||
| 250 | EVP_get_cipherbyname(SN_camellia_256_cbc); | ||
| 251 | ssl_cipher_methods[SSL_ENC_SEED_IDX]= | ||
| 252 | EVP_get_cipherbyname(SN_seed_cbc); | ||
| 182 | 253 | ||
| 183 | ssl_digest_methods[SSL_MD_MD5_IDX]= | 254 | ssl_digest_methods[SSL_MD_MD5_IDX]= |
| 184 | EVP_get_digestbyname(SN_md5); | 255 | EVP_get_digestbyname(SN_md5); |
| 185 | ssl_digest_methods[SSL_MD_SHA1_IDX]= | 256 | ssl_digest_methods[SSL_MD_SHA1_IDX]= |
| 186 | EVP_get_digestbyname(SN_sha1); | 257 | EVP_get_digestbyname(SN_sha1); |
| 187 | init_ciphers=0; | ||
| 188 | } | 258 | } |
| 189 | 259 | ||
| 260 | |||
| 261 | #ifndef OPENSSL_NO_COMP | ||
| 262 | |||
| 263 | static int sk_comp_cmp(const SSL_COMP * const *a, | ||
| 264 | const SSL_COMP * const *b) | ||
| 265 | { | ||
| 266 | return((*a)->id-(*b)->id); | ||
| 267 | } | ||
| 268 | |||
| 269 | static void load_builtin_compressions(void) | ||
| 270 | { | ||
| 271 | int got_write_lock = 0; | ||
| 272 | |||
| 273 | CRYPTO_r_lock(CRYPTO_LOCK_SSL); | ||
| 274 | if (ssl_comp_methods == NULL) | ||
| 275 | { | ||
| 276 | CRYPTO_r_unlock(CRYPTO_LOCK_SSL); | ||
| 277 | CRYPTO_w_lock(CRYPTO_LOCK_SSL); | ||
| 278 | got_write_lock = 1; | ||
| 279 | |||
| 280 | if (ssl_comp_methods == NULL) | ||
| 281 | { | ||
| 282 | SSL_COMP *comp = NULL; | ||
| 283 | |||
| 284 | MemCheck_off(); | ||
| 285 | ssl_comp_methods=sk_SSL_COMP_new(sk_comp_cmp); | ||
| 286 | if (ssl_comp_methods != NULL) | ||
| 287 | { | ||
| 288 | comp=(SSL_COMP *)OPENSSL_malloc(sizeof(SSL_COMP)); | ||
| 289 | if (comp != NULL) | ||
| 290 | { | ||
| 291 | comp->method=COMP_zlib(); | ||
| 292 | if (comp->method | ||
| 293 | && comp->method->type == NID_undef) | ||
| 294 | OPENSSL_free(comp); | ||
| 295 | else | ||
| 296 | { | ||
| 297 | comp->id=SSL_COMP_ZLIB_IDX; | ||
| 298 | comp->name=comp->method->name; | ||
| 299 | sk_SSL_COMP_push(ssl_comp_methods,comp); | ||
| 300 | } | ||
| 301 | } | ||
| 302 | } | ||
| 303 | MemCheck_on(); | ||
| 304 | } | ||
| 305 | } | ||
| 306 | |||
| 307 | if (got_write_lock) | ||
| 308 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL); | ||
| 309 | else | ||
| 310 | CRYPTO_r_unlock(CRYPTO_LOCK_SSL); | ||
| 311 | } | ||
| 312 | #endif | ||
| 313 | |||
| 190 | int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc, | 314 | int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc, |
| 191 | const EVP_MD **md, SSL_COMP **comp) | 315 | const EVP_MD **md, SSL_COMP **comp) |
| 192 | { | 316 | { |
| @@ -198,18 +322,14 @@ int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc, | |||
| 198 | if (comp != NULL) | 322 | if (comp != NULL) |
| 199 | { | 323 | { |
| 200 | SSL_COMP ctmp; | 324 | SSL_COMP ctmp; |
| 325 | #ifndef OPENSSL_NO_COMP | ||
| 326 | load_builtin_compressions(); | ||
| 327 | #endif | ||
| 201 | 328 | ||
| 202 | if (s->compress_meth == 0) | 329 | *comp=NULL; |
| 203 | *comp=NULL; | 330 | ctmp.id=s->compress_meth; |
| 204 | else if (ssl_comp_methods == NULL) | 331 | if (ssl_comp_methods != NULL) |
| 205 | { | 332 | { |
| 206 | /* bad */ | ||
| 207 | *comp=NULL; | ||
| 208 | } | ||
| 209 | else | ||
| 210 | { | ||
| 211 | |||
| 212 | ctmp.id=s->compress_meth; | ||
| 213 | i=sk_SSL_COMP_find(ssl_comp_methods,&ctmp); | 333 | i=sk_SSL_COMP_find(ssl_comp_methods,&ctmp); |
| 214 | if (i >= 0) | 334 | if (i >= 0) |
| 215 | *comp=sk_SSL_COMP_value(ssl_comp_methods,i); | 335 | *comp=sk_SSL_COMP_value(ssl_comp_methods,i); |
| @@ -248,6 +368,18 @@ int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc, | |||
| 248 | default: i=-1; break; | 368 | default: i=-1; break; |
| 249 | } | 369 | } |
| 250 | break; | 370 | break; |
| 371 | case SSL_CAMELLIA: | ||
| 372 | switch(c->alg_bits) | ||
| 373 | { | ||
| 374 | case 128: i=SSL_ENC_CAMELLIA128_IDX; break; | ||
| 375 | case 256: i=SSL_ENC_CAMELLIA256_IDX; break; | ||
| 376 | default: i=-1; break; | ||
| 377 | } | ||
| 378 | break; | ||
| 379 | case SSL_SEED: | ||
| 380 | i=SSL_ENC_SEED_IDX; | ||
| 381 | break; | ||
| 382 | |||
| 251 | default: | 383 | default: |
| 252 | i= -1; | 384 | i= -1; |
| 253 | break; | 385 | break; |
| @@ -305,9 +437,18 @@ static void ll_append_tail(CIPHER_ORDER **head, CIPHER_ORDER *curr, | |||
| 305 | *tail=curr; | 437 | *tail=curr; |
| 306 | } | 438 | } |
| 307 | 439 | ||
| 308 | static unsigned long ssl_cipher_get_disabled(void) | 440 | struct disabled_masks { /* This is a kludge no longer needed with OpenSSL 0.9.9, |
| 441 | * where 128-bit and 256-bit algorithms simply will get | ||
| 442 | * separate bits. */ | ||
| 443 | unsigned long mask; /* everything except m256 */ | ||
| 444 | unsigned long m256; /* applies to 256-bit algorithms only */ | ||
| 445 | }; | ||
| 446 | |||
| 447 | static struct disabled_masks ssl_cipher_get_disabled(void) | ||
| 309 | { | 448 | { |
| 310 | unsigned long mask; | 449 | unsigned long mask; |
| 450 | unsigned long m256; | ||
| 451 | struct disabled_masks ret; | ||
| 311 | 452 | ||
| 312 | mask = SSL_kFZA; | 453 | mask = SSL_kFZA; |
| 313 | #ifdef OPENSSL_NO_RSA | 454 | #ifdef OPENSSL_NO_RSA |
| @@ -322,7 +463,9 @@ static unsigned long ssl_cipher_get_disabled(void) | |||
| 322 | #ifdef OPENSSL_NO_KRB5 | 463 | #ifdef OPENSSL_NO_KRB5 |
| 323 | mask |= SSL_kKRB5|SSL_aKRB5; | 464 | mask |= SSL_kKRB5|SSL_aKRB5; |
| 324 | #endif | 465 | #endif |
| 325 | 466 | #ifdef OPENSSL_NO_ECDH | |
| 467 | mask |= SSL_kECDH|SSL_kECDHE; | ||
| 468 | #endif | ||
| 326 | #ifdef SSL_FORBID_ENULL | 469 | #ifdef SSL_FORBID_ENULL |
| 327 | mask |= SSL_eNULL; | 470 | mask |= SSL_eNULL; |
| 328 | #endif | 471 | #endif |
| @@ -333,17 +476,27 @@ static unsigned long ssl_cipher_get_disabled(void) | |||
| 333 | mask |= (ssl_cipher_methods[SSL_ENC_RC2_IDX ] == NULL) ? SSL_RC2 :0; | 476 | mask |= (ssl_cipher_methods[SSL_ENC_RC2_IDX ] == NULL) ? SSL_RC2 :0; |
| 334 | mask |= (ssl_cipher_methods[SSL_ENC_IDEA_IDX] == NULL) ? SSL_IDEA:0; | 477 | mask |= (ssl_cipher_methods[SSL_ENC_IDEA_IDX] == NULL) ? SSL_IDEA:0; |
| 335 | mask |= (ssl_cipher_methods[SSL_ENC_eFZA_IDX] == NULL) ? SSL_eFZA:0; | 478 | mask |= (ssl_cipher_methods[SSL_ENC_eFZA_IDX] == NULL) ? SSL_eFZA:0; |
| 336 | mask |= (ssl_cipher_methods[SSL_ENC_AES128_IDX] == NULL) ? SSL_AES:0; | 479 | mask |= (ssl_cipher_methods[SSL_ENC_SEED_IDX] == NULL) ? SSL_SEED:0; |
| 337 | 480 | ||
| 338 | mask |= (ssl_digest_methods[SSL_MD_MD5_IDX ] == NULL) ? SSL_MD5 :0; | 481 | mask |= (ssl_digest_methods[SSL_MD_MD5_IDX ] == NULL) ? SSL_MD5 :0; |
| 339 | mask |= (ssl_digest_methods[SSL_MD_SHA1_IDX] == NULL) ? SSL_SHA1:0; | 482 | mask |= (ssl_digest_methods[SSL_MD_SHA1_IDX] == NULL) ? SSL_SHA1:0; |
| 340 | 483 | ||
| 341 | return(mask); | 484 | /* finally consider algorithms where mask and m256 differ */ |
| 485 | m256 = mask; | ||
| 486 | mask |= (ssl_cipher_methods[SSL_ENC_AES128_IDX] == NULL) ? SSL_AES:0; | ||
| 487 | mask |= (ssl_cipher_methods[SSL_ENC_CAMELLIA128_IDX] == NULL) ? SSL_CAMELLIA:0; | ||
| 488 | m256 |= (ssl_cipher_methods[SSL_ENC_AES256_IDX] == NULL) ? SSL_AES:0; | ||
| 489 | m256 |= (ssl_cipher_methods[SSL_ENC_CAMELLIA256_IDX] == NULL) ? SSL_CAMELLIA:0; | ||
| 490 | |||
| 491 | ret.mask = mask; | ||
| 492 | ret.m256 = m256; | ||
| 493 | return ret; | ||
| 342 | } | 494 | } |
| 343 | 495 | ||
| 344 | static void ssl_cipher_collect_ciphers(const SSL_METHOD *ssl_method, | 496 | static void ssl_cipher_collect_ciphers(const SSL_METHOD *ssl_method, |
| 345 | int num_of_ciphers, unsigned long mask, CIPHER_ORDER *co_list, | 497 | int num_of_ciphers, unsigned long mask, unsigned long m256, |
| 346 | CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p) | 498 | CIPHER_ORDER *co_list, CIPHER_ORDER **head_p, |
| 499 | CIPHER_ORDER **tail_p) | ||
| 347 | { | 500 | { |
| 348 | int i, co_list_num; | 501 | int i, co_list_num; |
| 349 | SSL_CIPHER *c; | 502 | SSL_CIPHER *c; |
| @@ -360,13 +513,9 @@ static void ssl_cipher_collect_ciphers(const SSL_METHOD *ssl_method, | |||
| 360 | for (i = 0; i < num_of_ciphers; i++) | 513 | for (i = 0; i < num_of_ciphers; i++) |
| 361 | { | 514 | { |
| 362 | c = ssl_method->get_cipher(i); | 515 | c = ssl_method->get_cipher(i); |
| 516 | #define IS_MASKED(c) ((c)->algorithms & (((c)->alg_bits == 256) ? m256 : mask)) | ||
| 363 | /* drop those that use any of that is not available */ | 517 | /* drop those that use any of that is not available */ |
| 364 | #ifdef OPENSSL_FIPS | 518 | if ((c != NULL) && c->valid && !IS_MASKED(c)) |
| 365 | if ((c != NULL) && c->valid && !(c->algorithms & mask) | ||
| 366 | && (!FIPS_mode() || (c->algo_strength & SSL_FIPS))) | ||
| 367 | #else | ||
| 368 | if ((c != NULL) && c->valid && !(c->algorithms & mask)) | ||
| 369 | #endif | ||
| 370 | { | 519 | { |
| 371 | co_list[co_list_num].cipher = c; | 520 | co_list[co_list_num].cipher = c; |
| 372 | co_list[co_list_num].next = NULL; | 521 | co_list[co_list_num].next = NULL; |
| @@ -440,7 +589,8 @@ static void ssl_cipher_collect_aliases(SSL_CIPHER **ca_list, | |||
| 440 | *ca_curr = NULL; /* end of list */ | 589 | *ca_curr = NULL; /* end of list */ |
| 441 | } | 590 | } |
| 442 | 591 | ||
| 443 | static void ssl_cipher_apply_rule(unsigned long algorithms, unsigned long mask, | 592 | static void ssl_cipher_apply_rule(unsigned long cipher_id, unsigned long ssl_version, |
| 593 | unsigned long algorithms, unsigned long mask, | ||
| 444 | unsigned long algo_strength, unsigned long mask_strength, | 594 | unsigned long algo_strength, unsigned long mask_strength, |
| 445 | int rule, int strength_bits, CIPHER_ORDER *co_list, | 595 | int rule, int strength_bits, CIPHER_ORDER *co_list, |
| 446 | CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p) | 596 | CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p) |
| @@ -466,11 +616,20 @@ static void ssl_cipher_apply_rule(unsigned long algorithms, unsigned long mask, | |||
| 466 | 616 | ||
| 467 | cp = curr->cipher; | 617 | cp = curr->cipher; |
| 468 | 618 | ||
| 619 | /* If explicit cipher suite, match only that one for its own protocol version. | ||
| 620 | * Usual selection criteria will be used for similar ciphersuites from other version! */ | ||
| 621 | |||
| 622 | if (cipher_id && (cp->algorithms & SSL_SSL_MASK) == ssl_version) | ||
| 623 | { | ||
| 624 | if (cp->id != cipher_id) | ||
| 625 | continue; | ||
| 626 | } | ||
| 627 | |||
| 469 | /* | 628 | /* |
| 470 | * Selection criteria is either the number of strength_bits | 629 | * Selection criteria is either the number of strength_bits |
| 471 | * or the algorithm used. | 630 | * or the algorithm used. |
| 472 | */ | 631 | */ |
| 473 | if (strength_bits == -1) | 632 | else if (strength_bits == -1) |
| 474 | { | 633 | { |
| 475 | ma = mask & cp->algorithms; | 634 | ma = mask & cp->algorithms; |
| 476 | ma_s = mask_strength & cp->algo_strength; | 635 | ma_s = mask_strength & cp->algo_strength; |
| @@ -501,8 +660,22 @@ static void ssl_cipher_apply_rule(unsigned long algorithms, unsigned long mask, | |||
| 501 | { | 660 | { |
| 502 | if (!curr->active) | 661 | if (!curr->active) |
| 503 | { | 662 | { |
| 504 | ll_append_tail(&head, curr, &tail); | 663 | int add_this_cipher = 1; |
| 505 | curr->active = 1; | 664 | |
| 665 | if (((cp->algorithms & (SSL_kECDHE|SSL_kECDH|SSL_aECDSA)) != 0)) | ||
| 666 | { | ||
| 667 | /* Make sure "ECCdraft" ciphersuites are activated only if | ||
| 668 | * *explicitly* requested, but not implicitly (such as | ||
| 669 | * as part of the "AES" alias). */ | ||
| 670 | |||
| 671 | add_this_cipher = (mask & (SSL_kECDHE|SSL_kECDH|SSL_aECDSA)) != 0 || cipher_id != 0; | ||
| 672 | } | ||
| 673 | |||
| 674 | if (add_this_cipher) | ||
| 675 | { | ||
| 676 | ll_append_tail(&head, curr, &tail); | ||
| 677 | curr->active = 1; | ||
| 678 | } | ||
| 506 | } | 679 | } |
| 507 | } | 680 | } |
| 508 | /* Move the added cipher to this location */ | 681 | /* Move the added cipher to this location */ |
| @@ -583,7 +756,7 @@ static int ssl_cipher_strength_sort(CIPHER_ORDER *co_list, | |||
| 583 | */ | 756 | */ |
| 584 | for (i = max_strength_bits; i >= 0; i--) | 757 | for (i = max_strength_bits; i >= 0; i--) |
| 585 | if (number_uses[i] > 0) | 758 | if (number_uses[i] > 0) |
| 586 | ssl_cipher_apply_rule(0, 0, 0, 0, CIPHER_ORD, i, | 759 | ssl_cipher_apply_rule(0, 0, 0, 0, 0, 0, CIPHER_ORD, i, |
| 587 | co_list, head_p, tail_p); | 760 | co_list, head_p, tail_p); |
| 588 | 761 | ||
| 589 | OPENSSL_free(number_uses); | 762 | OPENSSL_free(number_uses); |
| @@ -597,6 +770,7 @@ static int ssl_cipher_process_rulestr(const char *rule_str, | |||
| 597 | unsigned long algorithms, mask, algo_strength, mask_strength; | 770 | unsigned long algorithms, mask, algo_strength, mask_strength; |
| 598 | const char *l, *start, *buf; | 771 | const char *l, *start, *buf; |
| 599 | int j, multi, found, rule, retval, ok, buflen; | 772 | int j, multi, found, rule, retval, ok, buflen; |
| 773 | unsigned long cipher_id = 0, ssl_version = 0; | ||
| 600 | char ch; | 774 | char ch; |
| 601 | 775 | ||
| 602 | retval = 1; | 776 | retval = 1; |
| @@ -686,6 +860,8 @@ static int ssl_cipher_process_rulestr(const char *rule_str, | |||
| 686 | * use strcmp(), because buf is not '\0' terminated.) | 860 | * use strcmp(), because buf is not '\0' terminated.) |
| 687 | */ | 861 | */ |
| 688 | j = found = 0; | 862 | j = found = 0; |
| 863 | cipher_id = 0; | ||
| 864 | ssl_version = 0; | ||
| 689 | while (ca_list[j]) | 865 | while (ca_list[j]) |
| 690 | { | 866 | { |
| 691 | if (!strncmp(buf, ca_list[j]->name, buflen) && | 867 | if (!strncmp(buf, ca_list[j]->name, buflen) && |
| @@ -714,6 +890,14 @@ static int ssl_cipher_process_rulestr(const char *rule_str, | |||
| 714 | (algo_strength & ca_list[j]->algo_strength); | 890 | (algo_strength & ca_list[j]->algo_strength); |
| 715 | mask_strength |= ca_list[j]->mask_strength; | 891 | mask_strength |= ca_list[j]->mask_strength; |
| 716 | 892 | ||
| 893 | /* explicit ciphersuite found */ | ||
| 894 | if (ca_list[j]->valid) | ||
| 895 | { | ||
| 896 | cipher_id = ca_list[j]->id; | ||
| 897 | ssl_version = ca_list[j]->algorithms & SSL_SSL_MASK; | ||
| 898 | break; | ||
| 899 | } | ||
| 900 | |||
| 717 | if (!multi) break; | 901 | if (!multi) break; |
| 718 | } | 902 | } |
| 719 | 903 | ||
| @@ -738,18 +922,18 @@ static int ssl_cipher_process_rulestr(const char *rule_str, | |||
| 738 | * rest of the command, if any left, until | 922 | * rest of the command, if any left, until |
| 739 | * end or ':' is found. | 923 | * end or ':' is found. |
| 740 | */ | 924 | */ |
| 741 | while ((*l != '\0') && ITEM_SEP(*l)) | 925 | while ((*l != '\0') && !ITEM_SEP(*l)) |
| 742 | l++; | 926 | l++; |
| 743 | } | 927 | } |
| 744 | else if (found) | 928 | else if (found) |
| 745 | { | 929 | { |
| 746 | ssl_cipher_apply_rule(algorithms, mask, | 930 | ssl_cipher_apply_rule(cipher_id, ssl_version, algorithms, mask, |
| 747 | algo_strength, mask_strength, rule, -1, | 931 | algo_strength, mask_strength, rule, -1, |
| 748 | co_list, head_p, tail_p); | 932 | co_list, head_p, tail_p); |
| 749 | } | 933 | } |
| 750 | else | 934 | else |
| 751 | { | 935 | { |
| 752 | while ((*l != '\0') && ITEM_SEP(*l)) | 936 | while ((*l != '\0') && !ITEM_SEP(*l)) |
| 753 | l++; | 937 | l++; |
| 754 | } | 938 | } |
| 755 | if (*l == '\0') break; /* done */ | 939 | if (*l == '\0') break; /* done */ |
| @@ -765,6 +949,7 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method, | |||
| 765 | { | 949 | { |
| 766 | int ok, num_of_ciphers, num_of_alias_max, num_of_group_aliases; | 950 | int ok, num_of_ciphers, num_of_alias_max, num_of_group_aliases; |
| 767 | unsigned long disabled_mask; | 951 | unsigned long disabled_mask; |
| 952 | unsigned long disabled_m256; | ||
| 768 | STACK_OF(SSL_CIPHER) *cipherstack, *tmp_cipher_list; | 953 | STACK_OF(SSL_CIPHER) *cipherstack, *tmp_cipher_list; |
| 769 | const char *rule_p; | 954 | const char *rule_p; |
| 770 | CIPHER_ORDER *co_list = NULL, *head = NULL, *tail = NULL, *curr; | 955 | CIPHER_ORDER *co_list = NULL, *head = NULL, *tail = NULL, *curr; |
| @@ -776,18 +961,16 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method, | |||
| 776 | if (rule_str == NULL || cipher_list == NULL || cipher_list_by_id == NULL) | 961 | if (rule_str == NULL || cipher_list == NULL || cipher_list_by_id == NULL) |
| 777 | return NULL; | 962 | return NULL; |
| 778 | 963 | ||
| 779 | if (init_ciphers) | ||
| 780 | { | ||
| 781 | CRYPTO_w_lock(CRYPTO_LOCK_SSL); | ||
| 782 | if (init_ciphers) load_ciphers(); | ||
| 783 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL); | ||
| 784 | } | ||
| 785 | |||
| 786 | /* | 964 | /* |
| 787 | * To reduce the work to do we only want to process the compiled | 965 | * To reduce the work to do we only want to process the compiled |
| 788 | * in algorithms, so we first get the mask of disabled ciphers. | 966 | * in algorithms, so we first get the mask of disabled ciphers. |
| 789 | */ | 967 | */ |
| 790 | disabled_mask = ssl_cipher_get_disabled(); | 968 | { |
| 969 | struct disabled_masks d; | ||
| 970 | d = ssl_cipher_get_disabled(); | ||
| 971 | disabled_mask = d.mask; | ||
| 972 | disabled_m256 = d.m256; | ||
| 973 | } | ||
| 791 | 974 | ||
| 792 | /* | 975 | /* |
| 793 | * Now we have to collect the available ciphers from the compiled | 976 | * Now we have to collect the available ciphers from the compiled |
| @@ -806,7 +989,7 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method, | |||
| 806 | } | 989 | } |
| 807 | 990 | ||
| 808 | ssl_cipher_collect_ciphers(ssl_method, num_of_ciphers, disabled_mask, | 991 | ssl_cipher_collect_ciphers(ssl_method, num_of_ciphers, disabled_mask, |
| 809 | co_list, &head, &tail); | 992 | disabled_m256, co_list, &head, &tail); |
| 810 | 993 | ||
| 811 | /* | 994 | /* |
| 812 | * We also need cipher aliases for selecting based on the rule_str. | 995 | * We also need cipher aliases for selecting based on the rule_str. |
| @@ -826,8 +1009,8 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method, | |||
| 826 | SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST,ERR_R_MALLOC_FAILURE); | 1009 | SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST,ERR_R_MALLOC_FAILURE); |
| 827 | return(NULL); /* Failure */ | 1010 | return(NULL); /* Failure */ |
| 828 | } | 1011 | } |
| 829 | ssl_cipher_collect_aliases(ca_list, num_of_group_aliases, disabled_mask, | 1012 | ssl_cipher_collect_aliases(ca_list, num_of_group_aliases, |
| 830 | head); | 1013 | (disabled_mask & disabled_m256), head); |
| 831 | 1014 | ||
| 832 | /* | 1015 | /* |
| 833 | * If the rule_string begins with DEFAULT, apply the default rule | 1016 | * If the rule_string begins with DEFAULT, apply the default rule |
| @@ -871,11 +1054,7 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method, | |||
| 871 | */ | 1054 | */ |
| 872 | for (curr = head; curr != NULL; curr = curr->next) | 1055 | for (curr = head; curr != NULL; curr = curr->next) |
| 873 | { | 1056 | { |
| 874 | #ifdef OPENSSL_FIPS | ||
| 875 | if (curr->active && (!FIPS_mode() || curr->cipher->algo_strength & SSL_FIPS)) | ||
| 876 | #else | ||
| 877 | if (curr->active) | 1057 | if (curr->active) |
| 878 | #endif | ||
| 879 | { | 1058 | { |
| 880 | sk_SSL_CIPHER_push(cipherstack, curr->cipher); | 1059 | sk_SSL_CIPHER_push(cipherstack, curr->cipher); |
| 881 | #ifdef CIPHER_DEBUG | 1060 | #ifdef CIPHER_DEBUG |
| @@ -897,7 +1076,7 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method, | |||
| 897 | if (*cipher_list_by_id != NULL) | 1076 | if (*cipher_list_by_id != NULL) |
| 898 | sk_SSL_CIPHER_free(*cipher_list_by_id); | 1077 | sk_SSL_CIPHER_free(*cipher_list_by_id); |
| 899 | *cipher_list_by_id = tmp_cipher_list; | 1078 | *cipher_list_by_id = tmp_cipher_list; |
| 900 | sk_SSL_CIPHER_set_cmp_func(*cipher_list_by_id,ssl_cipher_ptr_id_cmp); | 1079 | (void)sk_SSL_CIPHER_set_cmp_func(*cipher_list_by_id,ssl_cipher_ptr_id_cmp); |
| 901 | 1080 | ||
| 902 | return(cipherstack); | 1081 | return(cipherstack); |
| 903 | } | 1082 | } |
| @@ -905,13 +1084,13 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method, | |||
| 905 | char *SSL_CIPHER_description(SSL_CIPHER *cipher, char *buf, int len) | 1084 | char *SSL_CIPHER_description(SSL_CIPHER *cipher, char *buf, int len) |
| 906 | { | 1085 | { |
| 907 | int is_export,pkl,kl; | 1086 | int is_export,pkl,kl; |
| 908 | char *ver,*exp_str; | 1087 | const char *ver,*exp_str; |
| 909 | char *kx,*au,*enc,*mac; | 1088 | const char *kx,*au,*enc,*mac; |
| 910 | unsigned long alg,alg2,alg_s; | 1089 | unsigned long alg,alg2,alg_s; |
| 911 | #ifdef KSSL_DEBUG | 1090 | #ifdef KSSL_DEBUG |
| 912 | static char *format="%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s%s AL=%lx\n"; | 1091 | static const char *format="%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s%s AL=%lx\n"; |
| 913 | #else | 1092 | #else |
| 914 | static char *format="%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s%s\n"; | 1093 | static const char *format="%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s%s\n"; |
| 915 | #endif /* KSSL_DEBUG */ | 1094 | #endif /* KSSL_DEBUG */ |
| 916 | 1095 | ||
| 917 | alg=cipher->algorithms; | 1096 | alg=cipher->algorithms; |
| @@ -922,7 +1101,7 @@ char *SSL_CIPHER_description(SSL_CIPHER *cipher, char *buf, int len) | |||
| 922 | pkl=SSL_C_EXPORT_PKEYLENGTH(cipher); | 1101 | pkl=SSL_C_EXPORT_PKEYLENGTH(cipher); |
| 923 | kl=SSL_C_EXPORT_KEYLENGTH(cipher); | 1102 | kl=SSL_C_EXPORT_KEYLENGTH(cipher); |
| 924 | exp_str=is_export?" export":""; | 1103 | exp_str=is_export?" export":""; |
| 925 | 1104 | ||
| 926 | if (alg & SSL_SSLV2) | 1105 | if (alg & SSL_SSLV2) |
| 927 | ver="SSLv2"; | 1106 | ver="SSLv2"; |
| 928 | else if (alg & SSL_SSLV3) | 1107 | else if (alg & SSL_SSLV3) |
| @@ -951,6 +1130,10 @@ char *SSL_CIPHER_description(SSL_CIPHER *cipher, char *buf, int len) | |||
| 951 | case SSL_kEDH: | 1130 | case SSL_kEDH: |
| 952 | kx=is_export?(pkl == 512 ? "DH(512)" : "DH(1024)"):"DH"; | 1131 | kx=is_export?(pkl == 512 ? "DH(512)" : "DH(1024)"):"DH"; |
| 953 | break; | 1132 | break; |
| 1133 | case SSL_kECDH: | ||
| 1134 | case SSL_kECDHE: | ||
| 1135 | kx=is_export?"ECDH(<=163)":"ECDH"; | ||
| 1136 | break; | ||
| 954 | default: | 1137 | default: |
| 955 | kx="unknown"; | 1138 | kx="unknown"; |
| 956 | } | 1139 | } |
| @@ -974,6 +1157,9 @@ char *SSL_CIPHER_description(SSL_CIPHER *cipher, char *buf, int len) | |||
| 974 | case SSL_aNULL: | 1157 | case SSL_aNULL: |
| 975 | au="None"; | 1158 | au="None"; |
| 976 | break; | 1159 | break; |
| 1160 | case SSL_aECDSA: | ||
| 1161 | au="ECDSA"; | ||
| 1162 | break; | ||
| 977 | default: | 1163 | default: |
| 978 | au="unknown"; | 1164 | au="unknown"; |
| 979 | break; | 1165 | break; |
| @@ -1012,6 +1198,18 @@ char *SSL_CIPHER_description(SSL_CIPHER *cipher, char *buf, int len) | |||
| 1012 | default: enc="AES(?""?""?)"; break; | 1198 | default: enc="AES(?""?""?)"; break; |
| 1013 | } | 1199 | } |
| 1014 | break; | 1200 | break; |
| 1201 | case SSL_CAMELLIA: | ||
| 1202 | switch(cipher->strength_bits) | ||
| 1203 | { | ||
| 1204 | case 128: enc="Camellia(128)"; break; | ||
| 1205 | case 256: enc="Camellia(256)"; break; | ||
| 1206 | default: enc="Camellia(?""?""?)"; break; | ||
| 1207 | } | ||
| 1208 | break; | ||
| 1209 | case SSL_SEED: | ||
| 1210 | enc="SEED(128)"; | ||
| 1211 | break; | ||
| 1212 | |||
| 1015 | default: | 1213 | default: |
| 1016 | enc="unknown"; | 1214 | enc="unknown"; |
| 1017 | break; | 1215 | break; |
| @@ -1098,35 +1296,63 @@ SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n) | |||
| 1098 | return(NULL); | 1296 | return(NULL); |
| 1099 | } | 1297 | } |
| 1100 | 1298 | ||
| 1101 | static int sk_comp_cmp(const SSL_COMP * const *a, | 1299 | #ifdef OPENSSL_NO_COMP |
| 1102 | const SSL_COMP * const *b) | 1300 | void *SSL_COMP_get_compression_methods(void) |
| 1103 | { | 1301 | { |
| 1104 | return((*a)->id-(*b)->id); | 1302 | return NULL; |
| 1303 | } | ||
| 1304 | int SSL_COMP_add_compression_method(int id, void *cm) | ||
| 1305 | { | ||
| 1306 | return 1; | ||
| 1105 | } | 1307 | } |
| 1106 | 1308 | ||
| 1309 | const char *SSL_COMP_get_name(const void *comp) | ||
| 1310 | { | ||
| 1311 | return NULL; | ||
| 1312 | } | ||
| 1313 | #else | ||
| 1107 | STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void) | 1314 | STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void) |
| 1108 | { | 1315 | { |
| 1316 | load_builtin_compressions(); | ||
| 1109 | return(ssl_comp_methods); | 1317 | return(ssl_comp_methods); |
| 1110 | } | 1318 | } |
| 1111 | 1319 | ||
| 1112 | int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm) | 1320 | int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm) |
| 1113 | { | 1321 | { |
| 1114 | SSL_COMP *comp; | 1322 | SSL_COMP *comp; |
| 1115 | STACK_OF(SSL_COMP) *sk; | ||
| 1116 | 1323 | ||
| 1117 | if (cm == NULL || cm->type == NID_undef) | 1324 | if (cm == NULL || cm->type == NID_undef) |
| 1118 | return 1; | 1325 | return 1; |
| 1119 | 1326 | ||
| 1327 | /* According to draft-ietf-tls-compression-04.txt, the | ||
| 1328 | compression number ranges should be the following: | ||
| 1329 | |||
| 1330 | 0 to 63: methods defined by the IETF | ||
| 1331 | 64 to 192: external party methods assigned by IANA | ||
| 1332 | 193 to 255: reserved for private use */ | ||
| 1333 | if (id < 193 || id > 255) | ||
| 1334 | { | ||
| 1335 | SSLerr(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,SSL_R_COMPRESSION_ID_NOT_WITHIN_PRIVATE_RANGE); | ||
| 1336 | return 0; | ||
| 1337 | } | ||
| 1338 | |||
| 1120 | MemCheck_off(); | 1339 | MemCheck_off(); |
| 1121 | comp=(SSL_COMP *)OPENSSL_malloc(sizeof(SSL_COMP)); | 1340 | comp=(SSL_COMP *)OPENSSL_malloc(sizeof(SSL_COMP)); |
| 1122 | comp->id=id; | 1341 | comp->id=id; |
| 1123 | comp->method=cm; | 1342 | comp->method=cm; |
| 1124 | if (ssl_comp_methods == NULL) | 1343 | load_builtin_compressions(); |
| 1125 | sk=ssl_comp_methods=sk_SSL_COMP_new(sk_comp_cmp); | 1344 | if (ssl_comp_methods |
| 1126 | else | 1345 | && !sk_SSL_COMP_find(ssl_comp_methods,comp)) |
| 1127 | sk=ssl_comp_methods; | ||
| 1128 | if ((sk == NULL) || !sk_SSL_COMP_push(sk,comp)) | ||
| 1129 | { | 1346 | { |
| 1347 | OPENSSL_free(comp); | ||
| 1348 | MemCheck_on(); | ||
| 1349 | SSLerr(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,SSL_R_DUPLICATE_COMPRESSION_ID); | ||
| 1350 | return(1); | ||
| 1351 | } | ||
| 1352 | else if ((ssl_comp_methods == NULL) | ||
| 1353 | || !sk_SSL_COMP_push(ssl_comp_methods,comp)) | ||
| 1354 | { | ||
| 1355 | OPENSSL_free(comp); | ||
| 1130 | MemCheck_on(); | 1356 | MemCheck_on(); |
| 1131 | SSLerr(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,ERR_R_MALLOC_FAILURE); | 1357 | SSLerr(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,ERR_R_MALLOC_FAILURE); |
| 1132 | return(1); | 1358 | return(1); |
| @@ -1137,3 +1363,12 @@ int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm) | |||
| 1137 | return(0); | 1363 | return(0); |
| 1138 | } | 1364 | } |
| 1139 | } | 1365 | } |
| 1366 | |||
| 1367 | const char *SSL_COMP_get_name(const COMP_METHOD *comp) | ||
| 1368 | { | ||
| 1369 | if (comp) | ||
| 1370 | return comp->name; | ||
| 1371 | return NULL; | ||
| 1372 | } | ||
| 1373 | |||
| 1374 | #endif | ||
diff --git a/src/lib/libssl/ssl_err.c b/src/lib/libssl/ssl_err.c index 4bcf591298..50779c1632 100644 --- a/src/lib/libssl/ssl_err.c +++ b/src/lib/libssl/ssl_err.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* ssl/ssl_err.c */ | 1 | /* ssl/ssl_err.c */ |
| 2 | /* ==================================================================== | 2 | /* ==================================================================== |
| 3 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. |
| 4 | * | 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions | 6 | * modification, are permitted provided that the following conditions |
| @@ -75,7 +75,32 @@ static ERR_STRING_DATA SSL_str_functs[]= | |||
| 75 | {ERR_FUNC(SSL_F_CLIENT_HELLO), "CLIENT_HELLO"}, | 75 | {ERR_FUNC(SSL_F_CLIENT_HELLO), "CLIENT_HELLO"}, |
| 76 | {ERR_FUNC(SSL_F_CLIENT_MASTER_KEY), "CLIENT_MASTER_KEY"}, | 76 | {ERR_FUNC(SSL_F_CLIENT_MASTER_KEY), "CLIENT_MASTER_KEY"}, |
| 77 | {ERR_FUNC(SSL_F_D2I_SSL_SESSION), "d2i_SSL_SESSION"}, | 77 | {ERR_FUNC(SSL_F_D2I_SSL_SESSION), "d2i_SSL_SESSION"}, |
| 78 | {ERR_FUNC(SSL_F_DO_DTLS1_WRITE), "DO_DTLS1_WRITE"}, | ||
| 78 | {ERR_FUNC(SSL_F_DO_SSL3_WRITE), "DO_SSL3_WRITE"}, | 79 | {ERR_FUNC(SSL_F_DO_SSL3_WRITE), "DO_SSL3_WRITE"}, |
| 80 | {ERR_FUNC(SSL_F_DTLS1_ACCEPT), "DTLS1_ACCEPT"}, | ||
| 81 | {ERR_FUNC(SSL_F_DTLS1_BUFFER_RECORD), "DTLS1_BUFFER_RECORD"}, | ||
| 82 | {ERR_FUNC(SSL_F_DTLS1_CLIENT_HELLO), "DTLS1_CLIENT_HELLO"}, | ||
| 83 | {ERR_FUNC(SSL_F_DTLS1_CONNECT), "DTLS1_CONNECT"}, | ||
| 84 | {ERR_FUNC(SSL_F_DTLS1_ENC), "DTLS1_ENC"}, | ||
| 85 | {ERR_FUNC(SSL_F_DTLS1_GET_HELLO_VERIFY), "DTLS1_GET_HELLO_VERIFY"}, | ||
| 86 | {ERR_FUNC(SSL_F_DTLS1_GET_MESSAGE), "DTLS1_GET_MESSAGE"}, | ||
| 87 | {ERR_FUNC(SSL_F_DTLS1_GET_MESSAGE_FRAGMENT), "DTLS1_GET_MESSAGE_FRAGMENT"}, | ||
| 88 | {ERR_FUNC(SSL_F_DTLS1_GET_RECORD), "DTLS1_GET_RECORD"}, | ||
| 89 | {ERR_FUNC(SSL_F_DTLS1_OUTPUT_CERT_CHAIN), "DTLS1_OUTPUT_CERT_CHAIN"}, | ||
| 90 | {ERR_FUNC(SSL_F_DTLS1_PREPROCESS_FRAGMENT), "DTLS1_PREPROCESS_FRAGMENT"}, | ||
| 91 | {ERR_FUNC(SSL_F_DTLS1_PROCESS_OUT_OF_SEQ_MESSAGE), "DTLS1_PROCESS_OUT_OF_SEQ_MESSAGE"}, | ||
| 92 | {ERR_FUNC(SSL_F_DTLS1_PROCESS_RECORD), "DTLS1_PROCESS_RECORD"}, | ||
| 93 | {ERR_FUNC(SSL_F_DTLS1_READ_BYTES), "DTLS1_READ_BYTES"}, | ||
| 94 | {ERR_FUNC(SSL_F_DTLS1_READ_FAILED), "DTLS1_READ_FAILED"}, | ||
| 95 | {ERR_FUNC(SSL_F_DTLS1_SEND_CERTIFICATE_REQUEST), "DTLS1_SEND_CERTIFICATE_REQUEST"}, | ||
| 96 | {ERR_FUNC(SSL_F_DTLS1_SEND_CLIENT_CERTIFICATE), "DTLS1_SEND_CLIENT_CERTIFICATE"}, | ||
| 97 | {ERR_FUNC(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE), "DTLS1_SEND_CLIENT_KEY_EXCHANGE"}, | ||
| 98 | {ERR_FUNC(SSL_F_DTLS1_SEND_CLIENT_VERIFY), "DTLS1_SEND_CLIENT_VERIFY"}, | ||
| 99 | {ERR_FUNC(SSL_F_DTLS1_SEND_HELLO_VERIFY_REQUEST), "DTLS1_SEND_HELLO_VERIFY_REQUEST"}, | ||
| 100 | {ERR_FUNC(SSL_F_DTLS1_SEND_SERVER_CERTIFICATE), "DTLS1_SEND_SERVER_CERTIFICATE"}, | ||
| 101 | {ERR_FUNC(SSL_F_DTLS1_SEND_SERVER_HELLO), "DTLS1_SEND_SERVER_HELLO"}, | ||
| 102 | {ERR_FUNC(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE), "DTLS1_SEND_SERVER_KEY_EXCHANGE"}, | ||
| 103 | {ERR_FUNC(SSL_F_DTLS1_WRITE_APP_DATA_BYTES), "DTLS1_WRITE_APP_DATA_BYTES"}, | ||
| 79 | {ERR_FUNC(SSL_F_GET_CLIENT_FINISHED), "GET_CLIENT_FINISHED"}, | 104 | {ERR_FUNC(SSL_F_GET_CLIENT_FINISHED), "GET_CLIENT_FINISHED"}, |
| 80 | {ERR_FUNC(SSL_F_GET_CLIENT_HELLO), "GET_CLIENT_HELLO"}, | 105 | {ERR_FUNC(SSL_F_GET_CLIENT_HELLO), "GET_CLIENT_HELLO"}, |
| 81 | {ERR_FUNC(SSL_F_GET_CLIENT_MASTER_KEY), "GET_CLIENT_MASTER_KEY"}, | 106 | {ERR_FUNC(SSL_F_GET_CLIENT_MASTER_KEY), "GET_CLIENT_MASTER_KEY"}, |
| @@ -116,6 +141,7 @@ static ERR_STRING_DATA SSL_str_functs[]= | |||
| 116 | {ERR_FUNC(SSL_F_SSL3_ENC), "SSL3_ENC"}, | 141 | {ERR_FUNC(SSL_F_SSL3_ENC), "SSL3_ENC"}, |
| 117 | {ERR_FUNC(SSL_F_SSL3_GENERATE_KEY_BLOCK), "SSL3_GENERATE_KEY_BLOCK"}, | 142 | {ERR_FUNC(SSL_F_SSL3_GENERATE_KEY_BLOCK), "SSL3_GENERATE_KEY_BLOCK"}, |
| 118 | {ERR_FUNC(SSL_F_SSL3_GET_CERTIFICATE_REQUEST), "SSL3_GET_CERTIFICATE_REQUEST"}, | 143 | {ERR_FUNC(SSL_F_SSL3_GET_CERTIFICATE_REQUEST), "SSL3_GET_CERTIFICATE_REQUEST"}, |
| 144 | {ERR_FUNC(SSL_F_SSL3_GET_CERT_STATUS), "SSL3_GET_CERT_STATUS"}, | ||
| 119 | {ERR_FUNC(SSL_F_SSL3_GET_CERT_VERIFY), "SSL3_GET_CERT_VERIFY"}, | 145 | {ERR_FUNC(SSL_F_SSL3_GET_CERT_VERIFY), "SSL3_GET_CERT_VERIFY"}, |
| 120 | {ERR_FUNC(SSL_F_SSL3_GET_CLIENT_CERTIFICATE), "SSL3_GET_CLIENT_CERTIFICATE"}, | 146 | {ERR_FUNC(SSL_F_SSL3_GET_CLIENT_CERTIFICATE), "SSL3_GET_CLIENT_CERTIFICATE"}, |
| 121 | {ERR_FUNC(SSL_F_SSL3_GET_CLIENT_HELLO), "SSL3_GET_CLIENT_HELLO"}, | 147 | {ERR_FUNC(SSL_F_SSL3_GET_CLIENT_HELLO), "SSL3_GET_CLIENT_HELLO"}, |
| @@ -123,10 +149,12 @@ static ERR_STRING_DATA SSL_str_functs[]= | |||
| 123 | {ERR_FUNC(SSL_F_SSL3_GET_FINISHED), "SSL3_GET_FINISHED"}, | 149 | {ERR_FUNC(SSL_F_SSL3_GET_FINISHED), "SSL3_GET_FINISHED"}, |
| 124 | {ERR_FUNC(SSL_F_SSL3_GET_KEY_EXCHANGE), "SSL3_GET_KEY_EXCHANGE"}, | 150 | {ERR_FUNC(SSL_F_SSL3_GET_KEY_EXCHANGE), "SSL3_GET_KEY_EXCHANGE"}, |
| 125 | {ERR_FUNC(SSL_F_SSL3_GET_MESSAGE), "SSL3_GET_MESSAGE"}, | 151 | {ERR_FUNC(SSL_F_SSL3_GET_MESSAGE), "SSL3_GET_MESSAGE"}, |
| 152 | {ERR_FUNC(SSL_F_SSL3_GET_NEW_SESSION_TICKET), "SSL3_GET_NEW_SESSION_TICKET"}, | ||
| 126 | {ERR_FUNC(SSL_F_SSL3_GET_RECORD), "SSL3_GET_RECORD"}, | 153 | {ERR_FUNC(SSL_F_SSL3_GET_RECORD), "SSL3_GET_RECORD"}, |
| 127 | {ERR_FUNC(SSL_F_SSL3_GET_SERVER_CERTIFICATE), "SSL3_GET_SERVER_CERTIFICATE"}, | 154 | {ERR_FUNC(SSL_F_SSL3_GET_SERVER_CERTIFICATE), "SSL3_GET_SERVER_CERTIFICATE"}, |
| 128 | {ERR_FUNC(SSL_F_SSL3_GET_SERVER_DONE), "SSL3_GET_SERVER_DONE"}, | 155 | {ERR_FUNC(SSL_F_SSL3_GET_SERVER_DONE), "SSL3_GET_SERVER_DONE"}, |
| 129 | {ERR_FUNC(SSL_F_SSL3_GET_SERVER_HELLO), "SSL3_GET_SERVER_HELLO"}, | 156 | {ERR_FUNC(SSL_F_SSL3_GET_SERVER_HELLO), "SSL3_GET_SERVER_HELLO"}, |
| 157 | {ERR_FUNC(SSL_F_SSL3_NEW_SESSION_TICKET), "SSL3_NEW_SESSION_TICKET"}, | ||
| 130 | {ERR_FUNC(SSL_F_SSL3_OUTPUT_CERT_CHAIN), "SSL3_OUTPUT_CERT_CHAIN"}, | 158 | {ERR_FUNC(SSL_F_SSL3_OUTPUT_CERT_CHAIN), "SSL3_OUTPUT_CERT_CHAIN"}, |
| 131 | {ERR_FUNC(SSL_F_SSL3_PEEK), "SSL3_PEEK"}, | 159 | {ERR_FUNC(SSL_F_SSL3_PEEK), "SSL3_PEEK"}, |
| 132 | {ERR_FUNC(SSL_F_SSL3_READ_BYTES), "SSL3_READ_BYTES"}, | 160 | {ERR_FUNC(SSL_F_SSL3_READ_BYTES), "SSL3_READ_BYTES"}, |
| @@ -142,8 +170,10 @@ static ERR_STRING_DATA SSL_str_functs[]= | |||
| 142 | {ERR_FUNC(SSL_F_SSL3_SETUP_KEY_BLOCK), "SSL3_SETUP_KEY_BLOCK"}, | 170 | {ERR_FUNC(SSL_F_SSL3_SETUP_KEY_BLOCK), "SSL3_SETUP_KEY_BLOCK"}, |
| 143 | {ERR_FUNC(SSL_F_SSL3_WRITE_BYTES), "SSL3_WRITE_BYTES"}, | 171 | {ERR_FUNC(SSL_F_SSL3_WRITE_BYTES), "SSL3_WRITE_BYTES"}, |
| 144 | {ERR_FUNC(SSL_F_SSL3_WRITE_PENDING), "SSL3_WRITE_PENDING"}, | 172 | {ERR_FUNC(SSL_F_SSL3_WRITE_PENDING), "SSL3_WRITE_PENDING"}, |
| 173 | {ERR_FUNC(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT), "SSL_ADD_CLIENTHELLO_TLSEXT"}, | ||
| 145 | {ERR_FUNC(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK), "SSL_add_dir_cert_subjects_to_stack"}, | 174 | {ERR_FUNC(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK), "SSL_add_dir_cert_subjects_to_stack"}, |
| 146 | {ERR_FUNC(SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK), "SSL_add_file_cert_subjects_to_stack"}, | 175 | {ERR_FUNC(SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK), "SSL_add_file_cert_subjects_to_stack"}, |
| 176 | {ERR_FUNC(SSL_F_SSL_ADD_SERVERHELLO_TLSEXT), "SSL_ADD_SERVERHELLO_TLSEXT"}, | ||
| 147 | {ERR_FUNC(SSL_F_SSL_BAD_METHOD), "SSL_BAD_METHOD"}, | 177 | {ERR_FUNC(SSL_F_SSL_BAD_METHOD), "SSL_BAD_METHOD"}, |
| 148 | {ERR_FUNC(SSL_F_SSL_BYTES_TO_CIPHER_LIST), "SSL_BYTES_TO_CIPHER_LIST"}, | 178 | {ERR_FUNC(SSL_F_SSL_BYTES_TO_CIPHER_LIST), "SSL_BYTES_TO_CIPHER_LIST"}, |
| 149 | {ERR_FUNC(SSL_F_SSL_CERT_DUP), "SSL_CERT_DUP"}, | 179 | {ERR_FUNC(SSL_F_SSL_CERT_DUP), "SSL_CERT_DUP"}, |
| @@ -151,6 +181,7 @@ static ERR_STRING_DATA SSL_str_functs[]= | |||
| 151 | {ERR_FUNC(SSL_F_SSL_CERT_INSTANTIATE), "SSL_CERT_INSTANTIATE"}, | 181 | {ERR_FUNC(SSL_F_SSL_CERT_INSTANTIATE), "SSL_CERT_INSTANTIATE"}, |
| 152 | {ERR_FUNC(SSL_F_SSL_CERT_NEW), "SSL_CERT_NEW"}, | 182 | {ERR_FUNC(SSL_F_SSL_CERT_NEW), "SSL_CERT_NEW"}, |
| 153 | {ERR_FUNC(SSL_F_SSL_CHECK_PRIVATE_KEY), "SSL_check_private_key"}, | 183 | {ERR_FUNC(SSL_F_SSL_CHECK_PRIVATE_KEY), "SSL_check_private_key"}, |
| 184 | {ERR_FUNC(SSL_F_SSL_CHECK_SERVERHELLO_TLSEXT), "SSL_CHECK_SERVERHELLO_TLSEXT"}, | ||
| 154 | {ERR_FUNC(SSL_F_SSL_CIPHER_PROCESS_RULESTR), "SSL_CIPHER_PROCESS_RULESTR"}, | 185 | {ERR_FUNC(SSL_F_SSL_CIPHER_PROCESS_RULESTR), "SSL_CIPHER_PROCESS_RULESTR"}, |
| 155 | {ERR_FUNC(SSL_F_SSL_CIPHER_STRENGTH_SORT), "SSL_CIPHER_STRENGTH_SORT"}, | 186 | {ERR_FUNC(SSL_F_SSL_CIPHER_STRENGTH_SORT), "SSL_CIPHER_STRENGTH_SORT"}, |
| 156 | {ERR_FUNC(SSL_F_SSL_CLEAR), "SSL_clear"}, | 187 | {ERR_FUNC(SSL_F_SSL_CLEAR), "SSL_clear"}, |
| @@ -182,6 +213,9 @@ static ERR_STRING_DATA SSL_str_functs[]= | |||
| 182 | {ERR_FUNC(SSL_F_SSL_INIT_WBIO_BUFFER), "SSL_INIT_WBIO_BUFFER"}, | 213 | {ERR_FUNC(SSL_F_SSL_INIT_WBIO_BUFFER), "SSL_INIT_WBIO_BUFFER"}, |
| 183 | {ERR_FUNC(SSL_F_SSL_LOAD_CLIENT_CA_FILE), "SSL_load_client_CA_file"}, | 214 | {ERR_FUNC(SSL_F_SSL_LOAD_CLIENT_CA_FILE), "SSL_load_client_CA_file"}, |
| 184 | {ERR_FUNC(SSL_F_SSL_NEW), "SSL_new"}, | 215 | {ERR_FUNC(SSL_F_SSL_NEW), "SSL_new"}, |
| 216 | {ERR_FUNC(SSL_F_SSL_PEEK), "SSL_peek"}, | ||
| 217 | {ERR_FUNC(SSL_F_SSL_PREPARE_CLIENTHELLO_TLSEXT), "SSL_PREPARE_CLIENTHELLO_TLSEXT"}, | ||
| 218 | {ERR_FUNC(SSL_F_SSL_PREPARE_SERVERHELLO_TLSEXT), "SSL_PREPARE_SERVERHELLO_TLSEXT"}, | ||
| 185 | {ERR_FUNC(SSL_F_SSL_READ), "SSL_read"}, | 219 | {ERR_FUNC(SSL_F_SSL_READ), "SSL_read"}, |
| 186 | {ERR_FUNC(SSL_F_SSL_RSA_PRIVATE_DECRYPT), "SSL_RSA_PRIVATE_DECRYPT"}, | 220 | {ERR_FUNC(SSL_F_SSL_RSA_PRIVATE_DECRYPT), "SSL_RSA_PRIVATE_DECRYPT"}, |
| 187 | {ERR_FUNC(SSL_F_SSL_RSA_PUBLIC_ENCRYPT), "SSL_RSA_PUBLIC_ENCRYPT"}, | 221 | {ERR_FUNC(SSL_F_SSL_RSA_PUBLIC_ENCRYPT), "SSL_RSA_PUBLIC_ENCRYPT"}, |
| @@ -201,6 +235,7 @@ static ERR_STRING_DATA SSL_str_functs[]= | |||
| 201 | {ERR_FUNC(SSL_F_SSL_SHUTDOWN), "SSL_shutdown"}, | 235 | {ERR_FUNC(SSL_F_SSL_SHUTDOWN), "SSL_shutdown"}, |
| 202 | {ERR_FUNC(SSL_F_SSL_UNDEFINED_CONST_FUNCTION), "SSL_UNDEFINED_CONST_FUNCTION"}, | 236 | {ERR_FUNC(SSL_F_SSL_UNDEFINED_CONST_FUNCTION), "SSL_UNDEFINED_CONST_FUNCTION"}, |
| 203 | {ERR_FUNC(SSL_F_SSL_UNDEFINED_FUNCTION), "SSL_UNDEFINED_FUNCTION"}, | 237 | {ERR_FUNC(SSL_F_SSL_UNDEFINED_FUNCTION), "SSL_UNDEFINED_FUNCTION"}, |
| 238 | {ERR_FUNC(SSL_F_SSL_UNDEFINED_VOID_FUNCTION), "SSL_UNDEFINED_VOID_FUNCTION"}, | ||
| 204 | {ERR_FUNC(SSL_F_SSL_USE_CERTIFICATE), "SSL_use_certificate"}, | 239 | {ERR_FUNC(SSL_F_SSL_USE_CERTIFICATE), "SSL_use_certificate"}, |
| 205 | {ERR_FUNC(SSL_F_SSL_USE_CERTIFICATE_ASN1), "SSL_use_certificate_ASN1"}, | 240 | {ERR_FUNC(SSL_F_SSL_USE_CERTIFICATE_ASN1), "SSL_use_certificate_ASN1"}, |
| 206 | {ERR_FUNC(SSL_F_SSL_USE_CERTIFICATE_FILE), "SSL_use_certificate_file"}, | 241 | {ERR_FUNC(SSL_F_SSL_USE_CERTIFICATE_FILE), "SSL_use_certificate_file"}, |
| @@ -234,6 +269,9 @@ static ERR_STRING_DATA SSL_str_reasons[]= | |||
| 234 | {ERR_REASON(SSL_R_BAD_DH_P_LENGTH) ,"bad dh p length"}, | 269 | {ERR_REASON(SSL_R_BAD_DH_P_LENGTH) ,"bad dh p length"}, |
| 235 | {ERR_REASON(SSL_R_BAD_DIGEST_LENGTH) ,"bad digest length"}, | 270 | {ERR_REASON(SSL_R_BAD_DIGEST_LENGTH) ,"bad digest length"}, |
| 236 | {ERR_REASON(SSL_R_BAD_DSA_SIGNATURE) ,"bad dsa signature"}, | 271 | {ERR_REASON(SSL_R_BAD_DSA_SIGNATURE) ,"bad dsa signature"}, |
| 272 | {ERR_REASON(SSL_R_BAD_ECC_CERT) ,"bad ecc cert"}, | ||
| 273 | {ERR_REASON(SSL_R_BAD_ECDSA_SIGNATURE) ,"bad ecdsa signature"}, | ||
| 274 | {ERR_REASON(SSL_R_BAD_ECPOINT) ,"bad ecpoint"}, | ||
| 237 | {ERR_REASON(SSL_R_BAD_HELLO_REQUEST) ,"bad hello request"}, | 275 | {ERR_REASON(SSL_R_BAD_HELLO_REQUEST) ,"bad hello request"}, |
| 238 | {ERR_REASON(SSL_R_BAD_LENGTH) ,"bad length"}, | 276 | {ERR_REASON(SSL_R_BAD_LENGTH) ,"bad length"}, |
| 239 | {ERR_REASON(SSL_R_BAD_MAC_DECODE) ,"bad mac decode"}, | 277 | {ERR_REASON(SSL_R_BAD_MAC_DECODE) ,"bad mac decode"}, |
| @@ -263,17 +301,22 @@ static ERR_STRING_DATA SSL_str_reasons[]= | |||
| 263 | {ERR_REASON(SSL_R_CIPHER_CODE_WRONG_LENGTH),"cipher code wrong length"}, | 301 | {ERR_REASON(SSL_R_CIPHER_CODE_WRONG_LENGTH),"cipher code wrong length"}, |
| 264 | {ERR_REASON(SSL_R_CIPHER_OR_HASH_UNAVAILABLE),"cipher or hash unavailable"}, | 302 | {ERR_REASON(SSL_R_CIPHER_OR_HASH_UNAVAILABLE),"cipher or hash unavailable"}, |
| 265 | {ERR_REASON(SSL_R_CIPHER_TABLE_SRC_ERROR),"cipher table src error"}, | 303 | {ERR_REASON(SSL_R_CIPHER_TABLE_SRC_ERROR),"cipher table src error"}, |
| 304 | {ERR_REASON(SSL_R_CLIENTHELLO_TLSEXT) ,"clienthello tlsext"}, | ||
| 266 | {ERR_REASON(SSL_R_COMPRESSED_LENGTH_TOO_LONG),"compressed length too long"}, | 305 | {ERR_REASON(SSL_R_COMPRESSED_LENGTH_TOO_LONG),"compressed length too long"}, |
| 267 | {ERR_REASON(SSL_R_COMPRESSION_FAILURE) ,"compression failure"}, | 306 | {ERR_REASON(SSL_R_COMPRESSION_FAILURE) ,"compression failure"}, |
| 307 | {ERR_REASON(SSL_R_COMPRESSION_ID_NOT_WITHIN_PRIVATE_RANGE),"compression id not within private range"}, | ||
| 268 | {ERR_REASON(SSL_R_COMPRESSION_LIBRARY_ERROR),"compression library error"}, | 308 | {ERR_REASON(SSL_R_COMPRESSION_LIBRARY_ERROR),"compression library error"}, |
| 269 | {ERR_REASON(SSL_R_CONNECTION_ID_IS_DIFFERENT),"connection id is different"}, | 309 | {ERR_REASON(SSL_R_CONNECTION_ID_IS_DIFFERENT),"connection id is different"}, |
| 270 | {ERR_REASON(SSL_R_CONNECTION_TYPE_NOT_SET),"connection type not set"}, | 310 | {ERR_REASON(SSL_R_CONNECTION_TYPE_NOT_SET),"connection type not set"}, |
| 311 | {ERR_REASON(SSL_R_COOKIE_MISMATCH) ,"cookie mismatch"}, | ||
| 271 | {ERR_REASON(SSL_R_DATA_BETWEEN_CCS_AND_FINISHED),"data between ccs and finished"}, | 312 | {ERR_REASON(SSL_R_DATA_BETWEEN_CCS_AND_FINISHED),"data between ccs and finished"}, |
| 272 | {ERR_REASON(SSL_R_DATA_LENGTH_TOO_LONG) ,"data length too long"}, | 313 | {ERR_REASON(SSL_R_DATA_LENGTH_TOO_LONG) ,"data length too long"}, |
| 273 | {ERR_REASON(SSL_R_DECRYPTION_FAILED) ,"decryption failed"}, | 314 | {ERR_REASON(SSL_R_DECRYPTION_FAILED) ,"decryption failed"}, |
| 274 | {ERR_REASON(SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC),"decryption failed or bad record mac"}, | 315 | {ERR_REASON(SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC),"decryption failed or bad record mac"}, |
| 275 | {ERR_REASON(SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG),"dh public value length is wrong"}, | 316 | {ERR_REASON(SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG),"dh public value length is wrong"}, |
| 276 | {ERR_REASON(SSL_R_DIGEST_CHECK_FAILED) ,"digest check failed"}, | 317 | {ERR_REASON(SSL_R_DIGEST_CHECK_FAILED) ,"digest check failed"}, |
| 318 | {ERR_REASON(SSL_R_DUPLICATE_COMPRESSION_ID),"duplicate compression id"}, | ||
| 319 | {ERR_REASON(SSL_R_ECGROUP_TOO_LARGE_FOR_CIPHER),"ecgroup too large for cipher"}, | ||
| 277 | {ERR_REASON(SSL_R_ENCRYPTED_LENGTH_TOO_LONG),"encrypted length too long"}, | 320 | {ERR_REASON(SSL_R_ENCRYPTED_LENGTH_TOO_LONG),"encrypted length too long"}, |
| 278 | {ERR_REASON(SSL_R_ERROR_GENERATING_TMP_RSA_KEY),"error generating tmp rsa key"}, | 321 | {ERR_REASON(SSL_R_ERROR_GENERATING_TMP_RSA_KEY),"error generating tmp rsa key"}, |
| 279 | {ERR_REASON(SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST),"error in received cipher list"}, | 322 | {ERR_REASON(SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST),"error in received cipher list"}, |
| @@ -286,6 +329,8 @@ static ERR_STRING_DATA SSL_str_reasons[]= | |||
| 286 | {ERR_REASON(SSL_R_INVALID_CHALLENGE_LENGTH),"invalid challenge length"}, | 329 | {ERR_REASON(SSL_R_INVALID_CHALLENGE_LENGTH),"invalid challenge length"}, |
| 287 | {ERR_REASON(SSL_R_INVALID_COMMAND) ,"invalid command"}, | 330 | {ERR_REASON(SSL_R_INVALID_COMMAND) ,"invalid command"}, |
| 288 | {ERR_REASON(SSL_R_INVALID_PURPOSE) ,"invalid purpose"}, | 331 | {ERR_REASON(SSL_R_INVALID_PURPOSE) ,"invalid purpose"}, |
| 332 | {ERR_REASON(SSL_R_INVALID_STATUS_RESPONSE),"invalid status response"}, | ||
| 333 | {ERR_REASON(SSL_R_INVALID_TICKET_KEYS_LENGTH),"invalid ticket keys length"}, | ||
| 289 | {ERR_REASON(SSL_R_INVALID_TRUST) ,"invalid trust"}, | 334 | {ERR_REASON(SSL_R_INVALID_TRUST) ,"invalid trust"}, |
| 290 | {ERR_REASON(SSL_R_KEY_ARG_TOO_LONG) ,"key arg too long"}, | 335 | {ERR_REASON(SSL_R_KEY_ARG_TOO_LONG) ,"key arg too long"}, |
| 291 | {ERR_REASON(SSL_R_KRB5) ,"krb5"}, | 336 | {ERR_REASON(SSL_R_KRB5) ,"krb5"}, |
| @@ -314,6 +359,7 @@ static ERR_STRING_DATA SSL_str_reasons[]= | |||
| 314 | {ERR_REASON(SSL_R_MISSING_RSA_ENCRYPTING_CERT),"missing rsa encrypting cert"}, | 359 | {ERR_REASON(SSL_R_MISSING_RSA_ENCRYPTING_CERT),"missing rsa encrypting cert"}, |
| 315 | {ERR_REASON(SSL_R_MISSING_RSA_SIGNING_CERT),"missing rsa signing cert"}, | 360 | {ERR_REASON(SSL_R_MISSING_RSA_SIGNING_CERT),"missing rsa signing cert"}, |
| 316 | {ERR_REASON(SSL_R_MISSING_TMP_DH_KEY) ,"missing tmp dh key"}, | 361 | {ERR_REASON(SSL_R_MISSING_TMP_DH_KEY) ,"missing tmp dh key"}, |
| 362 | {ERR_REASON(SSL_R_MISSING_TMP_ECDH_KEY) ,"missing tmp ecdh key"}, | ||
| 317 | {ERR_REASON(SSL_R_MISSING_TMP_RSA_KEY) ,"missing tmp rsa key"}, | 363 | {ERR_REASON(SSL_R_MISSING_TMP_RSA_KEY) ,"missing tmp rsa key"}, |
| 318 | {ERR_REASON(SSL_R_MISSING_TMP_RSA_PKEY) ,"missing tmp rsa pkey"}, | 364 | {ERR_REASON(SSL_R_MISSING_TMP_RSA_PKEY) ,"missing tmp rsa pkey"}, |
| 319 | {ERR_REASON(SSL_R_MISSING_VERIFY_MESSAGE),"missing verify message"}, | 365 | {ERR_REASON(SSL_R_MISSING_VERIFY_MESSAGE),"missing verify message"}, |
| @@ -342,6 +388,7 @@ static ERR_STRING_DATA SSL_str_reasons[]= | |||
| 342 | {ERR_REASON(SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED),"old session cipher not returned"}, | 388 | {ERR_REASON(SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED),"old session cipher not returned"}, |
| 343 | {ERR_REASON(SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE),"only tls allowed in fips mode"}, | 389 | {ERR_REASON(SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE),"only tls allowed in fips mode"}, |
| 344 | {ERR_REASON(SSL_R_PACKET_LENGTH_TOO_LONG),"packet length too long"}, | 390 | {ERR_REASON(SSL_R_PACKET_LENGTH_TOO_LONG),"packet length too long"}, |
| 391 | {ERR_REASON(SSL_R_PARSE_TLSEXT) ,"parse tlsext"}, | ||
| 345 | {ERR_REASON(SSL_R_PATH_TOO_LONG) ,"path too long"}, | 392 | {ERR_REASON(SSL_R_PATH_TOO_LONG) ,"path too long"}, |
| 346 | {ERR_REASON(SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE),"peer did not return a certificate"}, | 393 | {ERR_REASON(SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE),"peer did not return a certificate"}, |
| 347 | {ERR_REASON(SSL_R_PEER_ERROR) ,"peer error"}, | 394 | {ERR_REASON(SSL_R_PEER_ERROR) ,"peer error"}, |
| @@ -356,6 +403,7 @@ static ERR_STRING_DATA SSL_str_reasons[]= | |||
| 356 | {ERR_REASON(SSL_R_PUBLIC_KEY_IS_NOT_RSA) ,"public key is not rsa"}, | 403 | {ERR_REASON(SSL_R_PUBLIC_KEY_IS_NOT_RSA) ,"public key is not rsa"}, |
| 357 | {ERR_REASON(SSL_R_PUBLIC_KEY_NOT_RSA) ,"public key not rsa"}, | 404 | {ERR_REASON(SSL_R_PUBLIC_KEY_NOT_RSA) ,"public key not rsa"}, |
| 358 | {ERR_REASON(SSL_R_READ_BIO_NOT_SET) ,"read bio not set"}, | 405 | {ERR_REASON(SSL_R_READ_BIO_NOT_SET) ,"read bio not set"}, |
| 406 | {ERR_REASON(SSL_R_READ_TIMEOUT_EXPIRED) ,"read timeout expired"}, | ||
| 359 | {ERR_REASON(SSL_R_READ_WRONG_PACKET_TYPE),"read wrong packet type"}, | 407 | {ERR_REASON(SSL_R_READ_WRONG_PACKET_TYPE),"read wrong packet type"}, |
| 360 | {ERR_REASON(SSL_R_RECORD_LENGTH_MISMATCH),"record length mismatch"}, | 408 | {ERR_REASON(SSL_R_RECORD_LENGTH_MISMATCH),"record length mismatch"}, |
| 361 | {ERR_REASON(SSL_R_RECORD_TOO_LARGE) ,"record too large"}, | 409 | {ERR_REASON(SSL_R_RECORD_TOO_LARGE) ,"record too large"}, |
| @@ -364,11 +412,14 @@ static ERR_STRING_DATA SSL_str_reasons[]= | |||
| 364 | {ERR_REASON(SSL_R_REUSE_CERT_LENGTH_NOT_ZERO),"reuse cert length not zero"}, | 412 | {ERR_REASON(SSL_R_REUSE_CERT_LENGTH_NOT_ZERO),"reuse cert length not zero"}, |
| 365 | {ERR_REASON(SSL_R_REUSE_CERT_TYPE_NOT_ZERO),"reuse cert type not zero"}, | 413 | {ERR_REASON(SSL_R_REUSE_CERT_TYPE_NOT_ZERO),"reuse cert type not zero"}, |
| 366 | {ERR_REASON(SSL_R_REUSE_CIPHER_LIST_NOT_ZERO),"reuse cipher list not zero"}, | 414 | {ERR_REASON(SSL_R_REUSE_CIPHER_LIST_NOT_ZERO),"reuse cipher list not zero"}, |
| 415 | {ERR_REASON(SSL_R_SERVERHELLO_TLSEXT) ,"serverhello tlsext"}, | ||
| 367 | {ERR_REASON(SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED),"session id context uninitialized"}, | 416 | {ERR_REASON(SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED),"session id context uninitialized"}, |
| 368 | {ERR_REASON(SSL_R_SHORT_READ) ,"short read"}, | 417 | {ERR_REASON(SSL_R_SHORT_READ) ,"short read"}, |
| 369 | {ERR_REASON(SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE),"signature for non signing certificate"}, | 418 | {ERR_REASON(SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE),"signature for non signing certificate"}, |
| 370 | {ERR_REASON(SSL_R_SSL23_DOING_SESSION_ID_REUSE),"ssl23 doing session id reuse"}, | 419 | {ERR_REASON(SSL_R_SSL23_DOING_SESSION_ID_REUSE),"ssl23 doing session id reuse"}, |
| 371 | {ERR_REASON(SSL_R_SSL2_CONNECTION_ID_TOO_LONG),"ssl2 connection id too long"}, | 420 | {ERR_REASON(SSL_R_SSL2_CONNECTION_ID_TOO_LONG),"ssl2 connection id too long"}, |
| 421 | {ERR_REASON(SSL_R_SSL3_EXT_INVALID_SERVERNAME),"ssl3 ext invalid servername"}, | ||
| 422 | {ERR_REASON(SSL_R_SSL3_EXT_INVALID_SERVERNAME_TYPE),"ssl3 ext invalid servername type"}, | ||
| 372 | {ERR_REASON(SSL_R_SSL3_SESSION_ID_TOO_LONG),"ssl3 session id too long"}, | 423 | {ERR_REASON(SSL_R_SSL3_SESSION_ID_TOO_LONG),"ssl3 session id too long"}, |
| 373 | {ERR_REASON(SSL_R_SSL3_SESSION_ID_TOO_SHORT),"ssl3 session id too short"}, | 424 | {ERR_REASON(SSL_R_SSL3_SESSION_ID_TOO_SHORT),"ssl3 session id too short"}, |
| 374 | {ERR_REASON(SSL_R_SSLV3_ALERT_BAD_CERTIFICATE),"sslv3 alert bad certificate"}, | 425 | {ERR_REASON(SSL_R_SSLV3_ALERT_BAD_CERTIFICATE),"sslv3 alert bad certificate"}, |
| @@ -403,12 +454,15 @@ static ERR_STRING_DATA SSL_str_reasons[]= | |||
| 403 | {ERR_REASON(SSL_R_TLSV1_ALERT_UNKNOWN_CA),"tlsv1 alert unknown ca"}, | 454 | {ERR_REASON(SSL_R_TLSV1_ALERT_UNKNOWN_CA),"tlsv1 alert unknown ca"}, |
| 404 | {ERR_REASON(SSL_R_TLSV1_ALERT_USER_CANCELLED),"tlsv1 alert user cancelled"}, | 455 | {ERR_REASON(SSL_R_TLSV1_ALERT_USER_CANCELLED),"tlsv1 alert user cancelled"}, |
| 405 | {ERR_REASON(SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER),"tls client cert req with anon cipher"}, | 456 | {ERR_REASON(SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER),"tls client cert req with anon cipher"}, |
| 457 | {ERR_REASON(SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST),"tls invalid ecpointformat list"}, | ||
| 406 | {ERR_REASON(SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST),"tls peer did not respond with certificate list"}, | 458 | {ERR_REASON(SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST),"tls peer did not respond with certificate list"}, |
| 407 | {ERR_REASON(SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG),"tls rsa encrypted value length is wrong"}, | 459 | {ERR_REASON(SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG),"tls rsa encrypted value length is wrong"}, |
| 408 | {ERR_REASON(SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER),"tried to use unsupported cipher"}, | 460 | {ERR_REASON(SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER),"tried to use unsupported cipher"}, |
| 409 | {ERR_REASON(SSL_R_UNABLE_TO_DECODE_DH_CERTS),"unable to decode dh certs"}, | 461 | {ERR_REASON(SSL_R_UNABLE_TO_DECODE_DH_CERTS),"unable to decode dh certs"}, |
| 462 | {ERR_REASON(SSL_R_UNABLE_TO_DECODE_ECDH_CERTS),"unable to decode ecdh certs"}, | ||
| 410 | {ERR_REASON(SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY),"unable to extract public key"}, | 463 | {ERR_REASON(SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY),"unable to extract public key"}, |
| 411 | {ERR_REASON(SSL_R_UNABLE_TO_FIND_DH_PARAMETERS),"unable to find dh parameters"}, | 464 | {ERR_REASON(SSL_R_UNABLE_TO_FIND_DH_PARAMETERS),"unable to find dh parameters"}, |
| 465 | {ERR_REASON(SSL_R_UNABLE_TO_FIND_ECDH_PARAMETERS),"unable to find ecdh parameters"}, | ||
| 412 | {ERR_REASON(SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS),"unable to find public key parameters"}, | 466 | {ERR_REASON(SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS),"unable to find public key parameters"}, |
| 413 | {ERR_REASON(SSL_R_UNABLE_TO_FIND_SSL_METHOD),"unable to find ssl method"}, | 467 | {ERR_REASON(SSL_R_UNABLE_TO_FIND_SSL_METHOD),"unable to find ssl method"}, |
| 414 | {ERR_REASON(SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES),"unable to load ssl2 md5 routines"}, | 468 | {ERR_REASON(SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES),"unable to load ssl2 md5 routines"}, |
| @@ -429,8 +483,10 @@ static ERR_STRING_DATA SSL_str_reasons[]= | |||
| 429 | {ERR_REASON(SSL_R_UNKNOWN_STATE) ,"unknown state"}, | 483 | {ERR_REASON(SSL_R_UNKNOWN_STATE) ,"unknown state"}, |
| 430 | {ERR_REASON(SSL_R_UNSUPPORTED_CIPHER) ,"unsupported cipher"}, | 484 | {ERR_REASON(SSL_R_UNSUPPORTED_CIPHER) ,"unsupported cipher"}, |
| 431 | {ERR_REASON(SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM),"unsupported compression algorithm"}, | 485 | {ERR_REASON(SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM),"unsupported compression algorithm"}, |
| 486 | {ERR_REASON(SSL_R_UNSUPPORTED_ELLIPTIC_CURVE),"unsupported elliptic curve"}, | ||
| 432 | {ERR_REASON(SSL_R_UNSUPPORTED_PROTOCOL) ,"unsupported protocol"}, | 487 | {ERR_REASON(SSL_R_UNSUPPORTED_PROTOCOL) ,"unsupported protocol"}, |
| 433 | {ERR_REASON(SSL_R_UNSUPPORTED_SSL_VERSION),"unsupported ssl version"}, | 488 | {ERR_REASON(SSL_R_UNSUPPORTED_SSL_VERSION),"unsupported ssl version"}, |
| 489 | {ERR_REASON(SSL_R_UNSUPPORTED_STATUS_TYPE),"unsupported status type"}, | ||
| 434 | {ERR_REASON(SSL_R_WRITE_BIO_NOT_SET) ,"write bio not set"}, | 490 | {ERR_REASON(SSL_R_WRITE_BIO_NOT_SET) ,"write bio not set"}, |
| 435 | {ERR_REASON(SSL_R_WRONG_CIPHER_RETURNED) ,"wrong cipher returned"}, | 491 | {ERR_REASON(SSL_R_WRONG_CIPHER_RETURNED) ,"wrong cipher returned"}, |
| 436 | {ERR_REASON(SSL_R_WRONG_MESSAGE_TYPE) ,"wrong message type"}, | 492 | {ERR_REASON(SSL_R_WRONG_MESSAGE_TYPE) ,"wrong message type"}, |
| @@ -448,15 +504,12 @@ static ERR_STRING_DATA SSL_str_reasons[]= | |||
| 448 | 504 | ||
| 449 | void ERR_load_SSL_strings(void) | 505 | void ERR_load_SSL_strings(void) |
| 450 | { | 506 | { |
| 451 | static int init=1; | 507 | #ifndef OPENSSL_NO_ERR |
| 452 | 508 | ||
| 453 | if (init) | 509 | if (ERR_func_error_string(SSL_str_functs[0].error) == NULL) |
| 454 | { | 510 | { |
| 455 | init=0; | ||
| 456 | #ifndef OPENSSL_NO_ERR | ||
| 457 | ERR_load_strings(0,SSL_str_functs); | 511 | ERR_load_strings(0,SSL_str_functs); |
| 458 | ERR_load_strings(0,SSL_str_reasons); | 512 | ERR_load_strings(0,SSL_str_reasons); |
| 459 | #endif | ||
| 460 | |||
| 461 | } | 513 | } |
| 514 | #endif | ||
| 462 | } | 515 | } |
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c index 2bd9a5af86..065411aea8 100644 --- a/src/lib/libssl/ssl_lib.c +++ b/src/lib/libssl/ssl_lib.c | |||
| @@ -110,7 +110,11 @@ | |||
| 110 | * Hudson (tjh@cryptsoft.com). | 110 | * Hudson (tjh@cryptsoft.com). |
| 111 | * | 111 | * |
| 112 | */ | 112 | */ |
| 113 | 113 | /* ==================================================================== | |
| 114 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
| 115 | * ECC cipher suite support in OpenSSL originally developed by | ||
| 116 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. | ||
| 117 | */ | ||
| 114 | 118 | ||
| 115 | #ifdef REF_CHECK | 119 | #ifdef REF_CHECK |
| 116 | # include <assert.h> | 120 | # include <assert.h> |
| @@ -121,7 +125,11 @@ | |||
| 121 | #include <openssl/objects.h> | 125 | #include <openssl/objects.h> |
| 122 | #include <openssl/lhash.h> | 126 | #include <openssl/lhash.h> |
| 123 | #include <openssl/x509v3.h> | 127 | #include <openssl/x509v3.h> |
| 124 | #include <openssl/fips.h> | 128 | #include <openssl/rand.h> |
| 129 | #include <openssl/ocsp.h> | ||
| 130 | #ifndef OPENSSL_NO_DH | ||
| 131 | #include <openssl/dh.h> | ||
| 132 | #endif | ||
| 125 | 133 | ||
| 126 | const char *SSL_version_str=OPENSSL_VERSION_TEXT; | 134 | const char *SSL_version_str=OPENSSL_VERSION_TEXT; |
| 127 | 135 | ||
| @@ -132,7 +140,14 @@ SSL3_ENC_METHOD ssl3_undef_enc_method={ | |||
| 132 | ssl_undefined_function, | 140 | ssl_undefined_function, |
| 133 | (int (*)(SSL *, unsigned char *, unsigned char *, int))ssl_undefined_function, | 141 | (int (*)(SSL *, unsigned char *, unsigned char *, int))ssl_undefined_function, |
| 134 | (int (*)(SSL*, int))ssl_undefined_function, | 142 | (int (*)(SSL*, int))ssl_undefined_function, |
| 135 | (int (*)(SSL *, EVP_MD_CTX *, EVP_MD_CTX *, const char*, int, unsigned char *))ssl_undefined_function | 143 | (int (*)(SSL *, EVP_MD_CTX *, EVP_MD_CTX *, const char*, int, unsigned char *))ssl_undefined_function, |
| 144 | 0, /* finish_mac_length */ | ||
| 145 | (int (*)(SSL *, EVP_MD_CTX *, unsigned char *))ssl_undefined_function, | ||
| 146 | NULL, /* client_finished_label */ | ||
| 147 | 0, /* client_finished_label_len */ | ||
| 148 | NULL, /* server_finished_label */ | ||
| 149 | 0, /* server_finished_label_len */ | ||
| 150 | (int (*)(int))ssl_undefined_function | ||
| 136 | }; | 151 | }; |
| 137 | 152 | ||
| 138 | int SSL_clear(SSL *s) | 153 | int SSL_clear(SSL *s) |
| @@ -272,19 +287,40 @@ SSL *SSL_new(SSL_CTX *ctx) | |||
| 272 | s->msg_callback=ctx->msg_callback; | 287 | s->msg_callback=ctx->msg_callback; |
| 273 | s->msg_callback_arg=ctx->msg_callback_arg; | 288 | s->msg_callback_arg=ctx->msg_callback_arg; |
| 274 | s->verify_mode=ctx->verify_mode; | 289 | s->verify_mode=ctx->verify_mode; |
| 290 | #if 0 | ||
| 275 | s->verify_depth=ctx->verify_depth; | 291 | s->verify_depth=ctx->verify_depth; |
| 292 | #endif | ||
| 276 | s->sid_ctx_length=ctx->sid_ctx_length; | 293 | s->sid_ctx_length=ctx->sid_ctx_length; |
| 277 | OPENSSL_assert(s->sid_ctx_length <= sizeof s->sid_ctx); | 294 | OPENSSL_assert(s->sid_ctx_length <= sizeof s->sid_ctx); |
| 278 | memcpy(&s->sid_ctx,&ctx->sid_ctx,sizeof(s->sid_ctx)); | 295 | memcpy(&s->sid_ctx,&ctx->sid_ctx,sizeof(s->sid_ctx)); |
| 279 | s->verify_callback=ctx->default_verify_callback; | 296 | s->verify_callback=ctx->default_verify_callback; |
| 280 | s->generate_session_id=ctx->generate_session_id; | 297 | s->generate_session_id=ctx->generate_session_id; |
| 298 | |||
| 299 | s->param = X509_VERIFY_PARAM_new(); | ||
| 300 | if (!s->param) | ||
| 301 | goto err; | ||
| 302 | X509_VERIFY_PARAM_inherit(s->param, ctx->param); | ||
| 303 | #if 0 | ||
| 281 | s->purpose = ctx->purpose; | 304 | s->purpose = ctx->purpose; |
| 282 | s->trust = ctx->trust; | 305 | s->trust = ctx->trust; |
| 306 | #endif | ||
| 283 | s->quiet_shutdown=ctx->quiet_shutdown; | 307 | s->quiet_shutdown=ctx->quiet_shutdown; |
| 284 | 308 | ||
| 285 | CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX); | 309 | CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX); |
| 286 | s->ctx=ctx; | 310 | s->ctx=ctx; |
| 287 | 311 | #ifndef OPENSSL_NO_TLSEXT | |
| 312 | s->tlsext_debug_cb = 0; | ||
| 313 | s->tlsext_debug_arg = NULL; | ||
| 314 | s->tlsext_ticket_expected = 0; | ||
| 315 | s->tlsext_status_type = -1; | ||
| 316 | s->tlsext_status_expected = 0; | ||
| 317 | s->tlsext_ocsp_ids = NULL; | ||
| 318 | s->tlsext_ocsp_exts = NULL; | ||
| 319 | s->tlsext_ocsp_resp = NULL; | ||
| 320 | s->tlsext_ocsp_resplen = -1; | ||
| 321 | CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX); | ||
| 322 | s->initial_ctx=ctx; | ||
| 323 | #endif | ||
| 288 | s->verify_result=X509_V_OK; | 324 | s->verify_result=X509_V_OK; |
| 289 | 325 | ||
| 290 | s->method=ctx->method; | 326 | s->method=ctx->method; |
| @@ -393,22 +429,22 @@ int SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id, | |||
| 393 | 429 | ||
| 394 | int SSL_CTX_set_purpose(SSL_CTX *s, int purpose) | 430 | int SSL_CTX_set_purpose(SSL_CTX *s, int purpose) |
| 395 | { | 431 | { |
| 396 | return X509_PURPOSE_set(&s->purpose, purpose); | 432 | return X509_VERIFY_PARAM_set_purpose(s->param, purpose); |
| 397 | } | 433 | } |
| 398 | 434 | ||
| 399 | int SSL_set_purpose(SSL *s, int purpose) | 435 | int SSL_set_purpose(SSL *s, int purpose) |
| 400 | { | 436 | { |
| 401 | return X509_PURPOSE_set(&s->purpose, purpose); | 437 | return X509_VERIFY_PARAM_set_purpose(s->param, purpose); |
| 402 | } | 438 | } |
| 403 | 439 | ||
| 404 | int SSL_CTX_set_trust(SSL_CTX *s, int trust) | 440 | int SSL_CTX_set_trust(SSL_CTX *s, int trust) |
| 405 | { | 441 | { |
| 406 | return X509_TRUST_set(&s->trust, trust); | 442 | return X509_VERIFY_PARAM_set_trust(s->param, trust); |
| 407 | } | 443 | } |
| 408 | 444 | ||
| 409 | int SSL_set_trust(SSL *s, int trust) | 445 | int SSL_set_trust(SSL *s, int trust) |
| 410 | { | 446 | { |
| 411 | return X509_TRUST_set(&s->trust, trust); | 447 | return X509_VERIFY_PARAM_set_trust(s->param, trust); |
| 412 | } | 448 | } |
| 413 | 449 | ||
| 414 | void SSL_free(SSL *s) | 450 | void SSL_free(SSL *s) |
| @@ -431,6 +467,9 @@ void SSL_free(SSL *s) | |||
| 431 | } | 467 | } |
| 432 | #endif | 468 | #endif |
| 433 | 469 | ||
| 470 | if (s->param) | ||
| 471 | X509_VERIFY_PARAM_free(s->param); | ||
| 472 | |||
| 434 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data); | 473 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data); |
| 435 | 474 | ||
| 436 | if (s->bbio != NULL) | 475 | if (s->bbio != NULL) |
| @@ -467,7 +506,16 @@ void SSL_free(SSL *s) | |||
| 467 | /* Free up if allocated */ | 506 | /* Free up if allocated */ |
| 468 | 507 | ||
| 469 | if (s->ctx) SSL_CTX_free(s->ctx); | 508 | if (s->ctx) SSL_CTX_free(s->ctx); |
| 470 | 509 | #ifndef OPENSSL_NO_TLSEXT | |
| 510 | if (s->initial_ctx) SSL_CTX_free(s->initial_ctx); | ||
| 511 | if (s->tlsext_ocsp_exts) | ||
| 512 | sk_X509_EXTENSION_pop_free(s->tlsext_ocsp_exts, | ||
| 513 | X509_EXTENSION_free); | ||
| 514 | if (s->tlsext_ocsp_ids) | ||
| 515 | sk_OCSP_RESPID_pop_free(s->tlsext_ocsp_ids, OCSP_RESPID_free); | ||
| 516 | if (s->tlsext_ocsp_resp) | ||
| 517 | OPENSSL_free(s->tlsext_ocsp_resp); | ||
| 518 | #endif | ||
| 471 | if (s->client_CA != NULL) | 519 | if (s->client_CA != NULL) |
| 472 | sk_X509_NAME_pop_free(s->client_CA,X509_NAME_free); | 520 | sk_X509_NAME_pop_free(s->client_CA,X509_NAME_free); |
| 473 | 521 | ||
| @@ -643,7 +691,7 @@ int SSL_get_verify_mode(const SSL *s) | |||
| 643 | 691 | ||
| 644 | int SSL_get_verify_depth(const SSL *s) | 692 | int SSL_get_verify_depth(const SSL *s) |
| 645 | { | 693 | { |
| 646 | return(s->verify_depth); | 694 | return X509_VERIFY_PARAM_get_depth(s->param); |
| 647 | } | 695 | } |
| 648 | 696 | ||
| 649 | int (*SSL_get_verify_callback(const SSL *s))(int,X509_STORE_CTX *) | 697 | int (*SSL_get_verify_callback(const SSL *s))(int,X509_STORE_CTX *) |
| @@ -658,7 +706,7 @@ int SSL_CTX_get_verify_mode(const SSL_CTX *ctx) | |||
| 658 | 706 | ||
| 659 | int SSL_CTX_get_verify_depth(const SSL_CTX *ctx) | 707 | int SSL_CTX_get_verify_depth(const SSL_CTX *ctx) |
| 660 | { | 708 | { |
| 661 | return(ctx->verify_depth); | 709 | return X509_VERIFY_PARAM_get_depth(ctx->param); |
| 662 | } | 710 | } |
| 663 | 711 | ||
| 664 | int (*SSL_CTX_get_verify_callback(const SSL_CTX *ctx))(int,X509_STORE_CTX *) | 712 | int (*SSL_CTX_get_verify_callback(const SSL_CTX *ctx))(int,X509_STORE_CTX *) |
| @@ -676,7 +724,7 @@ void SSL_set_verify(SSL *s,int mode, | |||
| 676 | 724 | ||
| 677 | void SSL_set_verify_depth(SSL *s,int depth) | 725 | void SSL_set_verify_depth(SSL *s,int depth) |
| 678 | { | 726 | { |
| 679 | s->verify_depth=depth; | 727 | X509_VERIFY_PARAM_set_depth(s->param, depth); |
| 680 | } | 728 | } |
| 681 | 729 | ||
| 682 | void SSL_set_read_ahead(SSL *s,int yes) | 730 | void SSL_set_read_ahead(SSL *s,int yes) |
| @@ -850,7 +898,7 @@ int SSL_peek(SSL *s,void *buf,int num) | |||
| 850 | { | 898 | { |
| 851 | if (s->handshake_func == 0) | 899 | if (s->handshake_func == 0) |
| 852 | { | 900 | { |
| 853 | SSLerr(SSL_F_SSL_READ, SSL_R_UNINITIALIZED); | 901 | SSLerr(SSL_F_SSL_PEEK, SSL_R_UNINITIALIZED); |
| 854 | return -1; | 902 | return -1; |
| 855 | } | 903 | } |
| 856 | 904 | ||
| @@ -941,12 +989,19 @@ long SSL_ctrl(SSL *s,int cmd,long larg,void *parg) | |||
| 941 | l=s->max_cert_list; | 989 | l=s->max_cert_list; |
| 942 | s->max_cert_list=larg; | 990 | s->max_cert_list=larg; |
| 943 | return(l); | 991 | return(l); |
| 992 | case SSL_CTRL_SET_MTU: | ||
| 993 | if (SSL_version(s) == DTLS1_VERSION) | ||
| 994 | { | ||
| 995 | s->d1->mtu = larg; | ||
| 996 | return larg; | ||
| 997 | } | ||
| 998 | return 0; | ||
| 944 | default: | 999 | default: |
| 945 | return(s->method->ssl_ctrl(s,cmd,larg,parg)); | 1000 | return(s->method->ssl_ctrl(s,cmd,larg,parg)); |
| 946 | } | 1001 | } |
| 947 | } | 1002 | } |
| 948 | 1003 | ||
| 949 | long SSL_callback_ctrl(SSL *s, int cmd, void (*fp)()) | 1004 | long SSL_callback_ctrl(SSL *s, int cmd, void (*fp)(void)) |
| 950 | { | 1005 | { |
| 951 | switch(cmd) | 1006 | switch(cmd) |
| 952 | { | 1007 | { |
| @@ -1034,7 +1089,7 @@ long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd,long larg,void *parg) | |||
| 1034 | } | 1089 | } |
| 1035 | } | 1090 | } |
| 1036 | 1091 | ||
| 1037 | long SSL_CTX_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)()) | 1092 | long SSL_CTX_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)(void)) |
| 1038 | { | 1093 | { |
| 1039 | switch(cmd) | 1094 | switch(cmd) |
| 1040 | { | 1095 | { |
| @@ -1169,7 +1224,6 @@ int SSL_set_cipher_list(SSL *s,const char *str) | |||
| 1169 | char *SSL_get_shared_ciphers(const SSL *s,char *buf,int len) | 1224 | char *SSL_get_shared_ciphers(const SSL *s,char *buf,int len) |
| 1170 | { | 1225 | { |
| 1171 | char *p; | 1226 | char *p; |
| 1172 | const char *cp; | ||
| 1173 | STACK_OF(SSL_CIPHER) *sk; | 1227 | STACK_OF(SSL_CIPHER) *sk; |
| 1174 | SSL_CIPHER *c; | 1228 | SSL_CIPHER *c; |
| 1175 | int i; | 1229 | int i; |
| @@ -1182,20 +1236,21 @@ char *SSL_get_shared_ciphers(const SSL *s,char *buf,int len) | |||
| 1182 | sk=s->session->ciphers; | 1236 | sk=s->session->ciphers; |
| 1183 | for (i=0; i<sk_SSL_CIPHER_num(sk); i++) | 1237 | for (i=0; i<sk_SSL_CIPHER_num(sk); i++) |
| 1184 | { | 1238 | { |
| 1185 | /* Decrement for either the ':' or a '\0' */ | 1239 | int n; |
| 1186 | len--; | 1240 | |
| 1187 | c=sk_SSL_CIPHER_value(sk,i); | 1241 | c=sk_SSL_CIPHER_value(sk,i); |
| 1188 | for (cp=c->name; *cp; ) | 1242 | n=strlen(c->name); |
| 1243 | if (n+1 > len) | ||
| 1189 | { | 1244 | { |
| 1190 | if (len-- == 0) | 1245 | if (p != buf) |
| 1191 | { | 1246 | --p; |
| 1192 | *p='\0'; | 1247 | *p='\0'; |
| 1193 | return(buf); | 1248 | return buf; |
| 1194 | } | ||
| 1195 | else | ||
| 1196 | *(p++)= *(cp++); | ||
| 1197 | } | 1249 | } |
| 1250 | strcpy(p,c->name); | ||
| 1251 | p+=n; | ||
| 1198 | *(p++)=':'; | 1252 | *(p++)=':'; |
| 1253 | len-=n+1; | ||
| 1199 | } | 1254 | } |
| 1200 | p[-1]='\0'; | 1255 | p[-1]='\0'; |
| 1201 | return(buf); | 1256 | return(buf); |
| @@ -1272,6 +1327,29 @@ err: | |||
| 1272 | return(NULL); | 1327 | return(NULL); |
| 1273 | } | 1328 | } |
| 1274 | 1329 | ||
| 1330 | #ifndef OPENSSL_NO_TLSEXT | ||
| 1331 | /** return a servername extension value if provided in Client Hello, or NULL. | ||
| 1332 | * So far, only host_name types are defined (RFC 3546). | ||
| 1333 | */ | ||
| 1334 | |||
| 1335 | const char *SSL_get_servername(const SSL *s, const int type) | ||
| 1336 | { | ||
| 1337 | if (type != TLSEXT_NAMETYPE_host_name) | ||
| 1338 | return NULL; | ||
| 1339 | |||
| 1340 | return s->session && !s->tlsext_hostname ? | ||
| 1341 | s->session->tlsext_hostname : | ||
| 1342 | s->tlsext_hostname; | ||
| 1343 | } | ||
| 1344 | |||
| 1345 | int SSL_get_servername_type(const SSL *s) | ||
| 1346 | { | ||
| 1347 | if (s->session && (!s->tlsext_hostname ? s->session->tlsext_hostname : s->tlsext_hostname)) | ||
| 1348 | return TLSEXT_NAMETYPE_host_name; | ||
| 1349 | return -1; | ||
| 1350 | } | ||
| 1351 | #endif | ||
| 1352 | |||
| 1275 | unsigned long SSL_SESSION_hash(const SSL_SESSION *a) | 1353 | unsigned long SSL_SESSION_hash(const SSL_SESSION *a) |
| 1276 | { | 1354 | { |
| 1277 | unsigned long l; | 1355 | unsigned long l; |
| @@ -1315,14 +1393,6 @@ SSL_CTX *SSL_CTX_new(SSL_METHOD *meth) | |||
| 1315 | return(NULL); | 1393 | return(NULL); |
| 1316 | } | 1394 | } |
| 1317 | 1395 | ||
| 1318 | #ifdef OPENSSL_FIPS | ||
| 1319 | if (FIPS_mode() && (meth->version < TLS1_VERSION)) | ||
| 1320 | { | ||
| 1321 | SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE); | ||
| 1322 | return NULL; | ||
| 1323 | } | ||
| 1324 | #endif | ||
| 1325 | |||
| 1326 | if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0) | 1396 | if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0) |
| 1327 | { | 1397 | { |
| 1328 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS); | 1398 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS); |
| @@ -1371,7 +1441,9 @@ SSL_CTX *SSL_CTX_new(SSL_METHOD *meth) | |||
| 1371 | ret->msg_callback=0; | 1441 | ret->msg_callback=0; |
| 1372 | ret->msg_callback_arg=NULL; | 1442 | ret->msg_callback_arg=NULL; |
| 1373 | ret->verify_mode=SSL_VERIFY_NONE; | 1443 | ret->verify_mode=SSL_VERIFY_NONE; |
| 1444 | #if 0 | ||
| 1374 | ret->verify_depth=-1; /* Don't impose a limit (but x509_lu.c does) */ | 1445 | ret->verify_depth=-1; /* Don't impose a limit (but x509_lu.c does) */ |
| 1446 | #endif | ||
| 1375 | ret->sid_ctx_length=0; | 1447 | ret->sid_ctx_length=0; |
| 1376 | ret->default_verify_callback=NULL; | 1448 | ret->default_verify_callback=NULL; |
| 1377 | if ((ret->cert=ssl_cert_new()) == NULL) | 1449 | if ((ret->cert=ssl_cert_new()) == NULL) |
| @@ -1380,6 +1452,8 @@ SSL_CTX *SSL_CTX_new(SSL_METHOD *meth) | |||
| 1380 | ret->default_passwd_callback=0; | 1452 | ret->default_passwd_callback=0; |
| 1381 | ret->default_passwd_callback_userdata=NULL; | 1453 | ret->default_passwd_callback_userdata=NULL; |
| 1382 | ret->client_cert_cb=0; | 1454 | ret->client_cert_cb=0; |
| 1455 | ret->app_gen_cookie_cb=0; | ||
| 1456 | ret->app_verify_cookie_cb=0; | ||
| 1383 | 1457 | ||
| 1384 | ret->sessions=lh_new(LHASH_HASH_FN(SSL_SESSION_hash), | 1458 | ret->sessions=lh_new(LHASH_HASH_FN(SSL_SESSION_hash), |
| 1385 | LHASH_COMP_FN(SSL_SESSION_cmp)); | 1459 | LHASH_COMP_FN(SSL_SESSION_cmp)); |
| @@ -1397,6 +1471,10 @@ SSL_CTX *SSL_CTX_new(SSL_METHOD *meth) | |||
| 1397 | goto err2; | 1471 | goto err2; |
| 1398 | } | 1472 | } |
| 1399 | 1473 | ||
| 1474 | ret->param = X509_VERIFY_PARAM_new(); | ||
| 1475 | if (!ret->param) | ||
| 1476 | goto err; | ||
| 1477 | |||
| 1400 | if ((ret->rsa_md5=EVP_get_digestbyname("ssl2-md5")) == NULL) | 1478 | if ((ret->rsa_md5=EVP_get_digestbyname("ssl2-md5")) == NULL) |
| 1401 | { | 1479 | { |
| 1402 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES); | 1480 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES); |
| @@ -1421,6 +1499,20 @@ SSL_CTX *SSL_CTX_new(SSL_METHOD *meth) | |||
| 1421 | ret->extra_certs=NULL; | 1499 | ret->extra_certs=NULL; |
| 1422 | ret->comp_methods=SSL_COMP_get_compression_methods(); | 1500 | ret->comp_methods=SSL_COMP_get_compression_methods(); |
| 1423 | 1501 | ||
| 1502 | #ifndef OPENSSL_NO_TLSEXT | ||
| 1503 | ret->tlsext_servername_callback = 0; | ||
| 1504 | ret->tlsext_servername_arg = NULL; | ||
| 1505 | /* Setup RFC4507 ticket keys */ | ||
| 1506 | if ((RAND_pseudo_bytes(ret->tlsext_tick_key_name, 16) <= 0) | ||
| 1507 | || (RAND_bytes(ret->tlsext_tick_hmac_key, 16) <= 0) | ||
| 1508 | || (RAND_bytes(ret->tlsext_tick_aes_key, 16) <= 0)) | ||
| 1509 | ret->options |= SSL_OP_NO_TICKET; | ||
| 1510 | |||
| 1511 | ret->tlsext_status_cb = 0; | ||
| 1512 | ret->tlsext_status_arg = NULL; | ||
| 1513 | |||
| 1514 | #endif | ||
| 1515 | |||
| 1424 | return(ret); | 1516 | return(ret); |
| 1425 | err: | 1517 | err: |
| 1426 | SSLerr(SSL_F_SSL_CTX_NEW,ERR_R_MALLOC_FAILURE); | 1518 | SSLerr(SSL_F_SSL_CTX_NEW,ERR_R_MALLOC_FAILURE); |
| @@ -1453,6 +1545,9 @@ void SSL_CTX_free(SSL_CTX *a) | |||
| 1453 | } | 1545 | } |
| 1454 | #endif | 1546 | #endif |
| 1455 | 1547 | ||
| 1548 | if (a->param) | ||
| 1549 | X509_VERIFY_PARAM_free(a->param); | ||
| 1550 | |||
| 1456 | /* | 1551 | /* |
| 1457 | * Free internal session cache. However: the remove_cb() may reference | 1552 | * Free internal session cache. However: the remove_cb() may reference |
| 1458 | * the ex_data of SSL_CTX, thus the ex_data store can only be removed | 1553 | * the ex_data of SSL_CTX, thus the ex_data store can only be removed |
| @@ -1515,7 +1610,7 @@ void SSL_CTX_set_verify(SSL_CTX *ctx,int mode,int (*cb)(int, X509_STORE_CTX *)) | |||
| 1515 | 1610 | ||
| 1516 | void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth) | 1611 | void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth) |
| 1517 | { | 1612 | { |
| 1518 | ctx->verify_depth=depth; | 1613 | X509_VERIFY_PARAM_set_depth(ctx->param, depth); |
| 1519 | } | 1614 | } |
| 1520 | 1615 | ||
| 1521 | void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher) | 1616 | void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher) |
| @@ -1525,6 +1620,13 @@ void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher) | |||
| 1525 | int rsa_enc_export,dh_rsa_export,dh_dsa_export; | 1620 | int rsa_enc_export,dh_rsa_export,dh_dsa_export; |
| 1526 | int rsa_tmp_export,dh_tmp_export,kl; | 1621 | int rsa_tmp_export,dh_tmp_export,kl; |
| 1527 | unsigned long mask,emask; | 1622 | unsigned long mask,emask; |
| 1623 | int have_ecc_cert, ecdh_ok, ecdsa_ok, ecc_pkey_size; | ||
| 1624 | #ifndef OPENSSL_NO_ECDH | ||
| 1625 | int have_ecdh_tmp; | ||
| 1626 | #endif | ||
| 1627 | X509 *x = NULL; | ||
| 1628 | EVP_PKEY *ecc_pkey = NULL; | ||
| 1629 | int signature_nid = 0; | ||
| 1528 | 1630 | ||
| 1529 | if (c == NULL) return; | 1631 | if (c == NULL) return; |
| 1530 | 1632 | ||
| @@ -1545,6 +1647,9 @@ void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher) | |||
| 1545 | dh_tmp=dh_tmp_export=0; | 1647 | dh_tmp=dh_tmp_export=0; |
| 1546 | #endif | 1648 | #endif |
| 1547 | 1649 | ||
| 1650 | #ifndef OPENSSL_NO_ECDH | ||
| 1651 | have_ecdh_tmp=(c->ecdh_tmp != NULL || c->ecdh_tmp_cb != NULL); | ||
| 1652 | #endif | ||
| 1548 | cpk= &(c->pkeys[SSL_PKEY_RSA_ENC]); | 1653 | cpk= &(c->pkeys[SSL_PKEY_RSA_ENC]); |
| 1549 | rsa_enc= (cpk->x509 != NULL && cpk->privatekey != NULL); | 1654 | rsa_enc= (cpk->x509 != NULL && cpk->privatekey != NULL); |
| 1550 | rsa_enc_export=(rsa_enc && EVP_PKEY_size(cpk->privatekey)*8 <= kl); | 1655 | rsa_enc_export=(rsa_enc && EVP_PKEY_size(cpk->privatekey)*8 <= kl); |
| @@ -1559,7 +1664,8 @@ void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher) | |||
| 1559 | /* FIX THIS EAY EAY EAY */ | 1664 | /* FIX THIS EAY EAY EAY */ |
| 1560 | dh_dsa= (cpk->x509 != NULL && cpk->privatekey != NULL); | 1665 | dh_dsa= (cpk->x509 != NULL && cpk->privatekey != NULL); |
| 1561 | dh_dsa_export=(dh_dsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl); | 1666 | dh_dsa_export=(dh_dsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl); |
| 1562 | 1667 | cpk= &(c->pkeys[SSL_PKEY_ECC]); | |
| 1668 | have_ecc_cert= (cpk->x509 != NULL && cpk->privatekey != NULL); | ||
| 1563 | mask=0; | 1669 | mask=0; |
| 1564 | emask=0; | 1670 | emask=0; |
| 1565 | 1671 | ||
| @@ -1616,11 +1722,127 @@ void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher) | |||
| 1616 | emask|=SSL_kKRB5|SSL_aKRB5; | 1722 | emask|=SSL_kKRB5|SSL_aKRB5; |
| 1617 | #endif | 1723 | #endif |
| 1618 | 1724 | ||
| 1725 | /* An ECC certificate may be usable for ECDH and/or | ||
| 1726 | * ECDSA cipher suites depending on the key usage extension. | ||
| 1727 | */ | ||
| 1728 | if (have_ecc_cert) | ||
| 1729 | { | ||
| 1730 | /* This call populates extension flags (ex_flags) */ | ||
| 1731 | x = (c->pkeys[SSL_PKEY_ECC]).x509; | ||
| 1732 | X509_check_purpose(x, -1, 0); | ||
| 1733 | ecdh_ok = (x->ex_flags & EXFLAG_KUSAGE) ? | ||
| 1734 | (x->ex_kusage & X509v3_KU_KEY_AGREEMENT) : 1; | ||
| 1735 | ecdsa_ok = (x->ex_flags & EXFLAG_KUSAGE) ? | ||
| 1736 | (x->ex_kusage & X509v3_KU_DIGITAL_SIGNATURE) : 1; | ||
| 1737 | ecc_pkey = X509_get_pubkey(x); | ||
| 1738 | ecc_pkey_size = (ecc_pkey != NULL) ? | ||
| 1739 | EVP_PKEY_bits(ecc_pkey) : 0; | ||
| 1740 | EVP_PKEY_free(ecc_pkey); | ||
| 1741 | if ((x->sig_alg) && (x->sig_alg->algorithm)) | ||
| 1742 | signature_nid = OBJ_obj2nid(x->sig_alg->algorithm); | ||
| 1743 | #ifndef OPENSSL_NO_ECDH | ||
| 1744 | if (ecdh_ok) | ||
| 1745 | { | ||
| 1746 | if ((signature_nid == NID_md5WithRSAEncryption) || | ||
| 1747 | (signature_nid == NID_md4WithRSAEncryption) || | ||
| 1748 | (signature_nid == NID_md2WithRSAEncryption)) | ||
| 1749 | { | ||
| 1750 | mask|=SSL_kECDH|SSL_aRSA; | ||
| 1751 | if (ecc_pkey_size <= 163) | ||
| 1752 | emask|=SSL_kECDH|SSL_aRSA; | ||
| 1753 | } | ||
| 1754 | if (signature_nid == NID_ecdsa_with_SHA1) | ||
| 1755 | { | ||
| 1756 | mask|=SSL_kECDH|SSL_aECDSA; | ||
| 1757 | if (ecc_pkey_size <= 163) | ||
| 1758 | emask|=SSL_kECDH|SSL_aECDSA; | ||
| 1759 | } | ||
| 1760 | } | ||
| 1761 | #endif | ||
| 1762 | #ifndef OPENSSL_NO_ECDSA | ||
| 1763 | if (ecdsa_ok) | ||
| 1764 | { | ||
| 1765 | mask|=SSL_aECDSA; | ||
| 1766 | emask|=SSL_aECDSA; | ||
| 1767 | } | ||
| 1768 | #endif | ||
| 1769 | } | ||
| 1770 | |||
| 1771 | #ifndef OPENSSL_NO_ECDH | ||
| 1772 | if (have_ecdh_tmp) | ||
| 1773 | { | ||
| 1774 | mask|=SSL_kECDHE; | ||
| 1775 | emask|=SSL_kECDHE; | ||
| 1776 | } | ||
| 1777 | #endif | ||
| 1619 | c->mask=mask; | 1778 | c->mask=mask; |
| 1620 | c->export_mask=emask; | 1779 | c->export_mask=emask; |
| 1621 | c->valid=1; | 1780 | c->valid=1; |
| 1622 | } | 1781 | } |
| 1623 | 1782 | ||
| 1783 | /* This handy macro borrowed from crypto/x509v3/v3_purp.c */ | ||
| 1784 | #define ku_reject(x, usage) \ | ||
| 1785 | (((x)->ex_flags & EXFLAG_KUSAGE) && !((x)->ex_kusage & (usage))) | ||
| 1786 | |||
| 1787 | int check_srvr_ecc_cert_and_alg(X509 *x, SSL_CIPHER *cs) | ||
| 1788 | { | ||
| 1789 | unsigned long alg = cs->algorithms; | ||
| 1790 | EVP_PKEY *pkey = NULL; | ||
| 1791 | int keysize = 0; | ||
| 1792 | int signature_nid = 0; | ||
| 1793 | |||
| 1794 | if (SSL_C_IS_EXPORT(cs)) | ||
| 1795 | { | ||
| 1796 | /* ECDH key length in export ciphers must be <= 163 bits */ | ||
| 1797 | pkey = X509_get_pubkey(x); | ||
| 1798 | if (pkey == NULL) return 0; | ||
| 1799 | keysize = EVP_PKEY_bits(pkey); | ||
| 1800 | EVP_PKEY_free(pkey); | ||
| 1801 | if (keysize > 163) return 0; | ||
| 1802 | } | ||
| 1803 | |||
| 1804 | /* This call populates the ex_flags field correctly */ | ||
| 1805 | X509_check_purpose(x, -1, 0); | ||
| 1806 | if ((x->sig_alg) && (x->sig_alg->algorithm)) | ||
| 1807 | signature_nid = OBJ_obj2nid(x->sig_alg->algorithm); | ||
| 1808 | if (alg & SSL_kECDH) | ||
| 1809 | { | ||
| 1810 | /* key usage, if present, must allow key agreement */ | ||
| 1811 | if (ku_reject(x, X509v3_KU_KEY_AGREEMENT)) | ||
| 1812 | { | ||
| 1813 | return 0; | ||
| 1814 | } | ||
| 1815 | if (alg & SSL_aECDSA) | ||
| 1816 | { | ||
| 1817 | /* signature alg must be ECDSA */ | ||
| 1818 | if (signature_nid != NID_ecdsa_with_SHA1) | ||
| 1819 | { | ||
| 1820 | return 0; | ||
| 1821 | } | ||
| 1822 | } | ||
| 1823 | if (alg & SSL_aRSA) | ||
| 1824 | { | ||
| 1825 | /* signature alg must be RSA */ | ||
| 1826 | if ((signature_nid != NID_md5WithRSAEncryption) && | ||
| 1827 | (signature_nid != NID_md4WithRSAEncryption) && | ||
| 1828 | (signature_nid != NID_md2WithRSAEncryption)) | ||
| 1829 | { | ||
| 1830 | return 0; | ||
| 1831 | } | ||
| 1832 | } | ||
| 1833 | } | ||
| 1834 | else if (alg & SSL_aECDSA) | ||
| 1835 | { | ||
| 1836 | /* key usage, if present, must allow signing */ | ||
| 1837 | if (ku_reject(x, X509v3_KU_DIGITAL_SIGNATURE)) | ||
| 1838 | { | ||
| 1839 | return 0; | ||
| 1840 | } | ||
| 1841 | } | ||
| 1842 | |||
| 1843 | return 1; /* all checks are ok */ | ||
| 1844 | } | ||
| 1845 | |||
| 1624 | /* THIS NEEDS CLEANING UP */ | 1846 | /* THIS NEEDS CLEANING UP */ |
| 1625 | X509 *ssl_get_server_send_cert(SSL *s) | 1847 | X509 *ssl_get_server_send_cert(SSL *s) |
| 1626 | { | 1848 | { |
| @@ -1635,7 +1857,26 @@ X509 *ssl_get_server_send_cert(SSL *s) | |||
| 1635 | mask=is_export?c->export_mask:c->mask; | 1857 | mask=is_export?c->export_mask:c->mask; |
| 1636 | kalg=alg&(SSL_MKEY_MASK|SSL_AUTH_MASK); | 1858 | kalg=alg&(SSL_MKEY_MASK|SSL_AUTH_MASK); |
| 1637 | 1859 | ||
| 1638 | if (kalg & SSL_kDHr) | 1860 | if (kalg & SSL_kECDH) |
| 1861 | { | ||
| 1862 | /* we don't need to look at SSL_kECDHE | ||
| 1863 | * since no certificate is needed for | ||
| 1864 | * anon ECDH and for authenticated | ||
| 1865 | * ECDHE, the check for the auth | ||
| 1866 | * algorithm will set i correctly | ||
| 1867 | * NOTE: For ECDH-RSA, we need an ECC | ||
| 1868 | * not an RSA cert but for ECDHE-RSA | ||
| 1869 | * we need an RSA cert. Placing the | ||
| 1870 | * checks for SSL_kECDH before RSA | ||
| 1871 | * checks ensures the correct cert is chosen. | ||
| 1872 | */ | ||
| 1873 | i=SSL_PKEY_ECC; | ||
| 1874 | } | ||
| 1875 | else if (kalg & SSL_aECDSA) | ||
| 1876 | { | ||
| 1877 | i=SSL_PKEY_ECC; | ||
| 1878 | } | ||
| 1879 | else if (kalg & SSL_kDHr) | ||
| 1639 | i=SSL_PKEY_DH_RSA; | 1880 | i=SSL_PKEY_DH_RSA; |
| 1640 | else if (kalg & SSL_kDHd) | 1881 | else if (kalg & SSL_kDHd) |
| 1641 | i=SSL_PKEY_DH_DSA; | 1882 | i=SSL_PKEY_DH_DSA; |
| @@ -1659,6 +1900,7 @@ X509 *ssl_get_server_send_cert(SSL *s) | |||
| 1659 | return(NULL); | 1900 | return(NULL); |
| 1660 | } | 1901 | } |
| 1661 | if (c->pkeys[i].x509 == NULL) return(NULL); | 1902 | if (c->pkeys[i].x509 == NULL) return(NULL); |
| 1903 | |||
| 1662 | return(c->pkeys[i].x509); | 1904 | return(c->pkeys[i].x509); |
| 1663 | } | 1905 | } |
| 1664 | 1906 | ||
| @@ -1682,6 +1924,9 @@ EVP_PKEY *ssl_get_sign_pkey(SSL *s,SSL_CIPHER *cipher) | |||
| 1682 | else | 1924 | else |
| 1683 | return(NULL); | 1925 | return(NULL); |
| 1684 | } | 1926 | } |
| 1927 | else if ((alg & SSL_aECDSA) && | ||
| 1928 | (c->pkeys[SSL_PKEY_ECC].privatekey != NULL)) | ||
| 1929 | return(c->pkeys[SSL_PKEY_ECC].privatekey); | ||
| 1685 | else /* if (alg & SSL_aNULL) */ | 1930 | else /* if (alg & SSL_aNULL) */ |
| 1686 | { | 1931 | { |
| 1687 | SSLerr(SSL_F_SSL_GET_SIGN_PKEY,ERR_R_INTERNAL_ERROR); | 1932 | SSLerr(SSL_F_SSL_GET_SIGN_PKEY,ERR_R_INTERNAL_ERROR); |
| @@ -1887,6 +2132,12 @@ int ssl_undefined_function(SSL *s) | |||
| 1887 | return(0); | 2132 | return(0); |
| 1888 | } | 2133 | } |
| 1889 | 2134 | ||
| 2135 | int ssl_undefined_void_function(void) | ||
| 2136 | { | ||
| 2137 | SSLerr(SSL_F_SSL_UNDEFINED_VOID_FUNCTION,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
| 2138 | return(0); | ||
| 2139 | } | ||
| 2140 | |||
| 1890 | int ssl_undefined_const_function(const SSL *s) | 2141 | int ssl_undefined_const_function(const SSL *s) |
| 1891 | { | 2142 | { |
| 1892 | SSLerr(SSL_F_SSL_UNDEFINED_CONST_FUNCTION,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | 2143 | SSLerr(SSL_F_SSL_UNDEFINED_CONST_FUNCTION,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); |
| @@ -2002,8 +2253,8 @@ SSL *SSL_dup(SSL *s) | |||
| 2002 | ret->rstate=s->rstate; | 2253 | ret->rstate=s->rstate; |
| 2003 | ret->init_num = 0; /* would have to copy ret->init_buf, ret->init_msg, ret->init_num, ret->init_off */ | 2254 | ret->init_num = 0; /* would have to copy ret->init_buf, ret->init_msg, ret->init_num, ret->init_off */ |
| 2004 | ret->hit=s->hit; | 2255 | ret->hit=s->hit; |
| 2005 | ret->purpose=s->purpose; | 2256 | |
| 2006 | ret->trust=s->trust; | 2257 | X509_VERIFY_PARAM_inherit(ret->param, s->param); |
| 2007 | 2258 | ||
| 2008 | /* dup the cipher_list and cipher_list_by_id stacks */ | 2259 | /* dup the cipher_list and cipher_list_by_id stacks */ |
| 2009 | if (s->cipher_list != NULL) | 2260 | if (s->cipher_list != NULL) |
| @@ -2055,6 +2306,7 @@ void ssl_clear_cipher_ctx(SSL *s) | |||
| 2055 | OPENSSL_free(s->enc_write_ctx); | 2306 | OPENSSL_free(s->enc_write_ctx); |
| 2056 | s->enc_write_ctx=NULL; | 2307 | s->enc_write_ctx=NULL; |
| 2057 | } | 2308 | } |
| 2309 | #ifndef OPENSSL_NO_COMP | ||
| 2058 | if (s->expand != NULL) | 2310 | if (s->expand != NULL) |
| 2059 | { | 2311 | { |
| 2060 | COMP_CTX_free(s->expand); | 2312 | COMP_CTX_free(s->expand); |
| @@ -2065,6 +2317,7 @@ void ssl_clear_cipher_ctx(SSL *s) | |||
| 2065 | COMP_CTX_free(s->compress); | 2317 | COMP_CTX_free(s->compress); |
| 2066 | s->compress=NULL; | 2318 | s->compress=NULL; |
| 2067 | } | 2319 | } |
| 2320 | #endif | ||
| 2068 | } | 2321 | } |
| 2069 | 2322 | ||
| 2070 | /* Fix this function so that it takes an optional type parameter */ | 2323 | /* Fix this function so that it takes an optional type parameter */ |
| @@ -2091,6 +2344,31 @@ SSL_CIPHER *SSL_get_current_cipher(const SSL *s) | |||
| 2091 | return(s->session->cipher); | 2344 | return(s->session->cipher); |
| 2092 | return(NULL); | 2345 | return(NULL); |
| 2093 | } | 2346 | } |
| 2347 | #ifdef OPENSSL_NO_COMP | ||
| 2348 | const void *SSL_get_current_compression(SSL *s) | ||
| 2349 | { | ||
| 2350 | return NULL; | ||
| 2351 | } | ||
| 2352 | const void *SSL_get_current_expansion(SSL *s) | ||
| 2353 | { | ||
| 2354 | return NULL; | ||
| 2355 | } | ||
| 2356 | #else | ||
| 2357 | |||
| 2358 | const COMP_METHOD *SSL_get_current_compression(SSL *s) | ||
| 2359 | { | ||
| 2360 | if (s->compress != NULL) | ||
| 2361 | return(s->compress->meth); | ||
| 2362 | return(NULL); | ||
| 2363 | } | ||
| 2364 | |||
| 2365 | const COMP_METHOD *SSL_get_current_expansion(SSL *s) | ||
| 2366 | { | ||
| 2367 | if (s->expand != NULL) | ||
| 2368 | return(s->expand->meth); | ||
| 2369 | return(NULL); | ||
| 2370 | } | ||
| 2371 | #endif | ||
| 2094 | 2372 | ||
| 2095 | int ssl_init_wbio_buffer(SSL *s,int push) | 2373 | int ssl_init_wbio_buffer(SSL *s,int push) |
| 2096 | { | 2374 | { |
| @@ -2184,6 +2462,24 @@ SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl) | |||
| 2184 | return(ssl->ctx); | 2462 | return(ssl->ctx); |
| 2185 | } | 2463 | } |
| 2186 | 2464 | ||
| 2465 | SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX* ctx) | ||
| 2466 | { | ||
| 2467 | if (ssl->ctx == ctx) | ||
| 2468 | return ssl->ctx; | ||
| 2469 | #ifndef OPENSSL_NO_TLSEXT | ||
| 2470 | if (ctx == NULL) | ||
| 2471 | ctx = ssl->initial_ctx; | ||
| 2472 | #endif | ||
| 2473 | if (ssl->cert != NULL) | ||
| 2474 | ssl_cert_free(ssl->cert); | ||
| 2475 | ssl->cert = ssl_cert_dup(ctx->cert); | ||
| 2476 | CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX); | ||
| 2477 | if (ssl->ctx != NULL) | ||
| 2478 | SSL_CTX_free(ssl->ctx); /* decrement reference count */ | ||
| 2479 | ssl->ctx = ctx; | ||
| 2480 | return(ssl->ctx); | ||
| 2481 | } | ||
| 2482 | |||
| 2187 | #ifndef OPENSSL_NO_STDIO | 2483 | #ifndef OPENSSL_NO_STDIO |
| 2188 | int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx) | 2484 | int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx) |
| 2189 | { | 2485 | { |
| @@ -2193,19 +2489,19 @@ int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx) | |||
| 2193 | int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile, | 2489 | int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile, |
| 2194 | const char *CApath) | 2490 | const char *CApath) |
| 2195 | { | 2491 | { |
| 2196 | int r; | 2492 | return(X509_STORE_load_locations(ctx->cert_store,CAfile,CApath)); |
| 2197 | r=X509_STORE_load_locations(ctx->cert_store,CAfile,CApath); | ||
| 2198 | return r; | ||
| 2199 | } | 2493 | } |
| 2200 | #endif | 2494 | #endif |
| 2201 | 2495 | ||
| 2202 | void SSL_set_info_callback(SSL *ssl, | 2496 | void SSL_set_info_callback(SSL *ssl, |
| 2203 | void (*cb)(const SSL *ssl,int type,int val)) | 2497 | void (*cb)(const SSL *ssl,int type,int val)) |
| 2204 | { | 2498 | { |
| 2205 | ssl->info_callback=cb; | 2499 | ssl->info_callback=cb; |
| 2206 | } | 2500 | } |
| 2207 | 2501 | ||
| 2208 | void (*SSL_get_info_callback(const SSL *ssl))(const SSL *ssl,int type,int val) | 2502 | /* One compiler (Diab DCC) doesn't like argument names in returned |
| 2503 | function pointer. */ | ||
| 2504 | void (*SSL_get_info_callback(const SSL *ssl))(const SSL * /*ssl*/,int /*type*/,int /*val*/) | ||
| 2209 | { | 2505 | { |
| 2210 | return ssl->info_callback; | 2506 | return ssl->info_callback; |
| 2211 | } | 2507 | } |
| @@ -2292,14 +2588,14 @@ void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,RSA *(*cb)(SSL *ssl, | |||
| 2292 | int is_export, | 2588 | int is_export, |
| 2293 | int keylength)) | 2589 | int keylength)) |
| 2294 | { | 2590 | { |
| 2295 | SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_RSA_CB,(void (*)())cb); | 2591 | SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_RSA_CB,(void (*)(void))cb); |
| 2296 | } | 2592 | } |
| 2297 | 2593 | ||
| 2298 | void SSL_set_tmp_rsa_callback(SSL *ssl,RSA *(*cb)(SSL *ssl, | 2594 | void SSL_set_tmp_rsa_callback(SSL *ssl,RSA *(*cb)(SSL *ssl, |
| 2299 | int is_export, | 2595 | int is_export, |
| 2300 | int keylength)) | 2596 | int keylength)) |
| 2301 | { | 2597 | { |
| 2302 | SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_RSA_CB,(void (*)())cb); | 2598 | SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_RSA_CB,(void (*)(void))cb); |
| 2303 | } | 2599 | } |
| 2304 | #endif | 2600 | #endif |
| 2305 | 2601 | ||
| @@ -2328,24 +2624,38 @@ RSA *cb(SSL *ssl,int is_export,int keylength) | |||
| 2328 | void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,DH *(*dh)(SSL *ssl,int is_export, | 2624 | void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,DH *(*dh)(SSL *ssl,int is_export, |
| 2329 | int keylength)) | 2625 | int keylength)) |
| 2330 | { | 2626 | { |
| 2331 | SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_DH_CB,(void (*)())dh); | 2627 | SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_DH_CB,(void (*)(void))dh); |
| 2332 | } | 2628 | } |
| 2333 | 2629 | ||
| 2334 | void SSL_set_tmp_dh_callback(SSL *ssl,DH *(*dh)(SSL *ssl,int is_export, | 2630 | void SSL_set_tmp_dh_callback(SSL *ssl,DH *(*dh)(SSL *ssl,int is_export, |
| 2335 | int keylength)) | 2631 | int keylength)) |
| 2336 | { | 2632 | { |
| 2337 | SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_DH_CB,(void (*)())dh); | 2633 | SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_DH_CB,(void (*)(void))dh); |
| 2634 | } | ||
| 2635 | #endif | ||
| 2636 | |||
| 2637 | #ifndef OPENSSL_NO_ECDH | ||
| 2638 | void SSL_CTX_set_tmp_ecdh_callback(SSL_CTX *ctx,EC_KEY *(*ecdh)(SSL *ssl,int is_export, | ||
| 2639 | int keylength)) | ||
| 2640 | { | ||
| 2641 | SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_ECDH_CB,(void (*)(void))ecdh); | ||
| 2642 | } | ||
| 2643 | |||
| 2644 | void SSL_set_tmp_ecdh_callback(SSL *ssl,EC_KEY *(*ecdh)(SSL *ssl,int is_export, | ||
| 2645 | int keylength)) | ||
| 2646 | { | ||
| 2647 | SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_ECDH_CB,(void (*)(void))ecdh); | ||
| 2338 | } | 2648 | } |
| 2339 | #endif | 2649 | #endif |
| 2340 | 2650 | ||
| 2341 | 2651 | ||
| 2342 | void SSL_CTX_set_msg_callback(SSL_CTX *ctx, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg)) | 2652 | void SSL_CTX_set_msg_callback(SSL_CTX *ctx, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg)) |
| 2343 | { | 2653 | { |
| 2344 | SSL_CTX_callback_ctrl(ctx, SSL_CTRL_SET_MSG_CALLBACK, (void (*)())cb); | 2654 | SSL_CTX_callback_ctrl(ctx, SSL_CTRL_SET_MSG_CALLBACK, (void (*)(void))cb); |
| 2345 | } | 2655 | } |
| 2346 | void SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg)) | 2656 | void SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg)) |
| 2347 | { | 2657 | { |
| 2348 | SSL_callback_ctrl(ssl, SSL_CTRL_SET_MSG_CALLBACK, (void (*)())cb); | 2658 | SSL_callback_ctrl(ssl, SSL_CTRL_SET_MSG_CALLBACK, (void (*)(void))cb); |
| 2349 | } | 2659 | } |
| 2350 | 2660 | ||
| 2351 | 2661 | ||
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h index 6a0b7595f4..de94c0d0c7 100644 --- a/src/lib/libssl/ssl_locl.h +++ b/src/lib/libssl/ssl_locl.h | |||
| @@ -108,6 +108,11 @@ | |||
| 108 | * Hudson (tjh@cryptsoft.com). | 108 | * Hudson (tjh@cryptsoft.com). |
| 109 | * | 109 | * |
| 110 | */ | 110 | */ |
| 111 | /* ==================================================================== | ||
| 112 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
| 113 | * ECC cipher suite support in OpenSSL originally developed by | ||
| 114 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. | ||
| 115 | */ | ||
| 111 | 116 | ||
| 112 | #ifndef HEADER_SSL_LOCL_H | 117 | #ifndef HEADER_SSL_LOCL_H |
| 113 | #define HEADER_SSL_LOCL_H | 118 | #define HEADER_SSL_LOCL_H |
| @@ -121,10 +126,13 @@ | |||
| 121 | #include <openssl/buffer.h> | 126 | #include <openssl/buffer.h> |
| 122 | #include <openssl/comp.h> | 127 | #include <openssl/comp.h> |
| 123 | #include <openssl/bio.h> | 128 | #include <openssl/bio.h> |
| 124 | #include <openssl/crypto.h> | ||
| 125 | #include <openssl/evp.h> | ||
| 126 | #include <openssl/stack.h> | 129 | #include <openssl/stack.h> |
| 127 | #include <openssl/x509.h> | 130 | #ifndef OPENSSL_NO_RSA |
| 131 | #include <openssl/rsa.h> | ||
| 132 | #endif | ||
| 133 | #ifndef OPENSSL_NO_DSA | ||
| 134 | #include <openssl/dsa.h> | ||
| 135 | #endif | ||
| 128 | #include <openssl/err.h> | 136 | #include <openssl/err.h> |
| 129 | #include <openssl/ssl.h> | 137 | #include <openssl/ssl.h> |
| 130 | #include <openssl/symhacks.h> | 138 | #include <openssl/symhacks.h> |
| @@ -172,6 +180,20 @@ | |||
| 172 | *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ | 180 | *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ |
| 173 | *((c)++)=(unsigned char)(((l) )&0xff)) | 181 | *((c)++)=(unsigned char)(((l) )&0xff)) |
| 174 | 182 | ||
| 183 | #define l2n6(l,c) (*((c)++)=(unsigned char)(((l)>>40)&0xff), \ | ||
| 184 | *((c)++)=(unsigned char)(((l)>>32)&0xff), \ | ||
| 185 | *((c)++)=(unsigned char)(((l)>>24)&0xff), \ | ||
| 186 | *((c)++)=(unsigned char)(((l)>>16)&0xff), \ | ||
| 187 | *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ | ||
| 188 | *((c)++)=(unsigned char)(((l) )&0xff)) | ||
| 189 | |||
| 190 | #define n2l6(c,l) (l =((BN_ULLONG)(*((c)++)))<<40, \ | ||
| 191 | l|=((BN_ULLONG)(*((c)++)))<<32, \ | ||
| 192 | l|=((BN_ULLONG)(*((c)++)))<<24, \ | ||
| 193 | l|=((BN_ULLONG)(*((c)++)))<<16, \ | ||
| 194 | l|=((BN_ULLONG)(*((c)++)))<< 8, \ | ||
| 195 | l|=((BN_ULLONG)(*((c)++)))) | ||
| 196 | |||
| 175 | /* NOTE - c is not incremented as per l2c */ | 197 | /* NOTE - c is not incremented as per l2c */ |
| 176 | #define l2cn(l1,l2,c,n) { \ | 198 | #define l2cn(l1,l2,c,n) { \ |
| 177 | c+=n; \ | 199 | c+=n; \ |
| @@ -227,52 +249,58 @@ | |||
| 227 | * that the different entities within are mutually exclusive: | 249 | * that the different entities within are mutually exclusive: |
| 228 | * ONLY ONE BIT PER MASK CAN BE SET AT A TIME. | 250 | * ONLY ONE BIT PER MASK CAN BE SET AT A TIME. |
| 229 | */ | 251 | */ |
| 230 | #define SSL_MKEY_MASK 0x0000003FL | 252 | #define SSL_MKEY_MASK 0x000000FFL |
| 231 | #define SSL_kRSA 0x00000001L /* RSA key exchange */ | 253 | #define SSL_kRSA 0x00000001L /* RSA key exchange */ |
| 232 | #define SSL_kDHr 0x00000002L /* DH cert RSA CA cert */ | 254 | #define SSL_kDHr 0x00000002L /* DH cert RSA CA cert */ |
| 233 | #define SSL_kDHd 0x00000004L /* DH cert DSA CA cert */ | 255 | #define SSL_kDHd 0x00000004L /* DH cert DSA CA cert */ |
| 234 | #define SSL_kFZA 0x00000008L | 256 | #define SSL_kFZA 0x00000008L |
| 235 | #define SSL_kEDH 0x00000010L /* tmp DH key no DH cert */ | 257 | #define SSL_kEDH 0x00000010L /* tmp DH key no DH cert */ |
| 236 | #define SSL_kKRB5 0x00000020L /* Kerberos5 key exchange */ | 258 | #define SSL_kKRB5 0x00000020L /* Kerberos5 key exchange */ |
| 259 | #define SSL_kECDH 0x00000040L /* ECDH w/ long-term keys */ | ||
| 260 | #define SSL_kECDHE 0x00000080L /* ephemeral ECDH */ | ||
| 237 | #define SSL_EDH (SSL_kEDH|(SSL_AUTH_MASK^SSL_aNULL)) | 261 | #define SSL_EDH (SSL_kEDH|(SSL_AUTH_MASK^SSL_aNULL)) |
| 238 | 262 | ||
| 239 | #define SSL_AUTH_MASK 0x00000FC0L | 263 | #define SSL_AUTH_MASK 0x00007F00L |
| 240 | #define SSL_aRSA 0x00000040L /* Authenticate with RSA */ | 264 | #define SSL_aRSA 0x00000100L /* Authenticate with RSA */ |
| 241 | #define SSL_aDSS 0x00000080L /* Authenticate with DSS */ | 265 | #define SSL_aDSS 0x00000200L /* Authenticate with DSS */ |
| 242 | #define SSL_DSS SSL_aDSS | 266 | #define SSL_DSS SSL_aDSS |
| 243 | #define SSL_aFZA 0x00000100L | 267 | #define SSL_aFZA 0x00000400L |
| 244 | #define SSL_aNULL 0x00000200L /* no Authenticate, ADH */ | 268 | #define SSL_aNULL 0x00000800L /* no Authenticate, ADH */ |
| 245 | #define SSL_aDH 0x00000400L /* no Authenticate, ADH */ | 269 | #define SSL_aDH 0x00001000L /* no Authenticate, ADH */ |
| 246 | #define SSL_aKRB5 0x00000800L /* Authenticate with KRB5 */ | 270 | #define SSL_aKRB5 0x00002000L /* Authenticate with KRB5 */ |
| 271 | #define SSL_aECDSA 0x00004000L /* Authenticate with ECDSA */ | ||
| 247 | 272 | ||
| 248 | #define SSL_NULL (SSL_eNULL) | 273 | #define SSL_NULL (SSL_eNULL) |
| 249 | #define SSL_ADH (SSL_kEDH|SSL_aNULL) | 274 | #define SSL_ADH (SSL_kEDH|SSL_aNULL) |
| 250 | #define SSL_RSA (SSL_kRSA|SSL_aRSA) | 275 | #define SSL_RSA (SSL_kRSA|SSL_aRSA) |
| 251 | #define SSL_DH (SSL_kDHr|SSL_kDHd|SSL_kEDH) | 276 | #define SSL_DH (SSL_kDHr|SSL_kDHd|SSL_kEDH) |
| 277 | #define SSL_ECDH (SSL_kECDH|SSL_kECDHE) | ||
| 252 | #define SSL_FZA (SSL_aFZA|SSL_kFZA|SSL_eFZA) | 278 | #define SSL_FZA (SSL_aFZA|SSL_kFZA|SSL_eFZA) |
| 253 | #define SSL_KRB5 (SSL_kKRB5|SSL_aKRB5) | 279 | #define SSL_KRB5 (SSL_kKRB5|SSL_aKRB5) |
| 254 | 280 | ||
| 255 | #define SSL_ENC_MASK 0x0087F000L | 281 | #define SSL_ENC_MASK 0x1C3F8000L |
| 256 | #define SSL_DES 0x00001000L | 282 | #define SSL_DES 0x00008000L |
| 257 | #define SSL_3DES 0x00002000L | 283 | #define SSL_3DES 0x00010000L |
| 258 | #define SSL_RC4 0x00004000L | 284 | #define SSL_RC4 0x00020000L |
| 259 | #define SSL_RC2 0x00008000L | 285 | #define SSL_RC2 0x00040000L |
| 260 | #define SSL_IDEA 0x00010000L | 286 | #define SSL_IDEA 0x00080000L |
| 261 | #define SSL_eFZA 0x00020000L | 287 | #define SSL_eFZA 0x00100000L |
| 262 | #define SSL_eNULL 0x00040000L | 288 | #define SSL_eNULL 0x00200000L |
| 263 | #define SSL_AES 0x00800000L | 289 | #define SSL_AES 0x04000000L |
| 264 | 290 | #define SSL_CAMELLIA 0x08000000L | |
| 265 | #define SSL_MAC_MASK 0x00180000L | 291 | #define SSL_SEED 0x10000000L |
| 266 | #define SSL_MD5 0x00080000L | 292 | |
| 267 | #define SSL_SHA1 0x00100000L | 293 | #define SSL_MAC_MASK 0x00c00000L |
| 294 | #define SSL_MD5 0x00400000L | ||
| 295 | #define SSL_SHA1 0x00800000L | ||
| 268 | #define SSL_SHA (SSL_SHA1) | 296 | #define SSL_SHA (SSL_SHA1) |
| 269 | 297 | ||
| 270 | #define SSL_SSL_MASK 0x00600000L | 298 | #define SSL_SSL_MASK 0x03000000L |
| 271 | #define SSL_SSLV2 0x00200000L | 299 | #define SSL_SSLV2 0x01000000L |
| 272 | #define SSL_SSLV3 0x00400000L | 300 | #define SSL_SSLV3 0x02000000L |
| 273 | #define SSL_TLSV1 SSL_SSLV3 /* for now */ | 301 | #define SSL_TLSV1 SSL_SSLV3 /* for now */ |
| 274 | 302 | ||
| 275 | /* we have used 007fffff - 9 bits left to go */ | 303 | /* we have used 1fffffff - 3 bits left to go. */ |
| 276 | 304 | ||
| 277 | /* | 305 | /* |
| 278 | * Export and cipher strength information. For each cipher we have to decide | 306 | * Export and cipher strength information. For each cipher we have to decide |
| @@ -302,9 +330,8 @@ | |||
| 302 | #define SSL_LOW 0x00000020L | 330 | #define SSL_LOW 0x00000020L |
| 303 | #define SSL_MEDIUM 0x00000040L | 331 | #define SSL_MEDIUM 0x00000040L |
| 304 | #define SSL_HIGH 0x00000080L | 332 | #define SSL_HIGH 0x00000080L |
| 305 | #define SSL_FIPS 0x00000100L | ||
| 306 | 333 | ||
| 307 | /* we have used 000001ff - 23 bits left to go */ | 334 | /* we have used 000000ff - 24 bits left to go */ |
| 308 | 335 | ||
| 309 | /* | 336 | /* |
| 310 | * Macros to check the export status and cipher strength for export ciphers. | 337 | * Macros to check the export status and cipher strength for export ciphers. |
| @@ -345,7 +372,8 @@ | |||
| 345 | #define SSL_PKEY_DSA_SIGN 2 | 372 | #define SSL_PKEY_DSA_SIGN 2 |
| 346 | #define SSL_PKEY_DH_RSA 3 | 373 | #define SSL_PKEY_DH_RSA 3 |
| 347 | #define SSL_PKEY_DH_DSA 4 | 374 | #define SSL_PKEY_DH_DSA 4 |
| 348 | #define SSL_PKEY_NUM 5 | 375 | #define SSL_PKEY_ECC 5 |
| 376 | #define SSL_PKEY_NUM 6 | ||
| 349 | 377 | ||
| 350 | /* SSL_kRSA <- RSA_ENC | (RSA_TMP & RSA_SIGN) | | 378 | /* SSL_kRSA <- RSA_ENC | (RSA_TMP & RSA_SIGN) | |
| 351 | * <- (EXPORT & (RSA_ENC | RSA_TMP) & RSA_SIGN) | 379 | * <- (EXPORT & (RSA_ENC | RSA_TMP) & RSA_SIGN) |
| @@ -361,6 +389,15 @@ | |||
| 361 | #define CERT_PRIVATE_KEY 2 | 389 | #define CERT_PRIVATE_KEY 2 |
| 362 | */ | 390 | */ |
| 363 | 391 | ||
| 392 | #ifndef OPENSSL_NO_EC | ||
| 393 | /* From ECC-TLS draft, used in encoding the curve type in | ||
| 394 | * ECParameters | ||
| 395 | */ | ||
| 396 | #define EXPLICIT_PRIME_CURVE_TYPE 1 | ||
| 397 | #define EXPLICIT_CHAR2_CURVE_TYPE 2 | ||
| 398 | #define NAMED_CURVE_TYPE 3 | ||
| 399 | #endif /* OPENSSL_NO_EC */ | ||
| 400 | |||
| 364 | typedef struct cert_pkey_st | 401 | typedef struct cert_pkey_st |
| 365 | { | 402 | { |
| 366 | X509 *x509; | 403 | X509 *x509; |
| @@ -387,6 +424,11 @@ typedef struct cert_st | |||
| 387 | DH *dh_tmp; | 424 | DH *dh_tmp; |
| 388 | DH *(*dh_tmp_cb)(SSL *ssl,int is_export,int keysize); | 425 | DH *(*dh_tmp_cb)(SSL *ssl,int is_export,int keysize); |
| 389 | #endif | 426 | #endif |
| 427 | #ifndef OPENSSL_NO_ECDH | ||
| 428 | EC_KEY *ecdh_tmp; | ||
| 429 | /* Callback for generating ephemeral ECDH keys */ | ||
| 430 | EC_KEY *(*ecdh_tmp_cb)(SSL *ssl,int is_export,int keysize); | ||
| 431 | #endif | ||
| 390 | 432 | ||
| 391 | CERT_PKEY pkeys[SSL_PKEY_NUM]; | 433 | CERT_PKEY pkeys[SSL_PKEY_NUM]; |
| 392 | 434 | ||
| @@ -412,6 +454,9 @@ typedef struct sess_cert_st | |||
| 412 | #ifndef OPENSSL_NO_DH | 454 | #ifndef OPENSSL_NO_DH |
| 413 | DH *peer_dh_tmp; /* not used for SSL 2 */ | 455 | DH *peer_dh_tmp; /* not used for SSL 2 */ |
| 414 | #endif | 456 | #endif |
| 457 | #ifndef OPENSSL_NO_ECDH | ||
| 458 | EC_KEY *peer_ecdh_tmp; | ||
| 459 | #endif | ||
| 415 | 460 | ||
| 416 | int references; /* actually always 1 at the moment */ | 461 | int references; /* actually always 1 at the moment */ |
| 417 | } SESS_CERT; | 462 | } SESS_CERT; |
| @@ -466,17 +511,201 @@ extern SSL3_ENC_METHOD ssl3_undef_enc_method; | |||
| 466 | OPENSSL_EXTERN SSL_CIPHER ssl2_ciphers[]; | 511 | OPENSSL_EXTERN SSL_CIPHER ssl2_ciphers[]; |
| 467 | OPENSSL_EXTERN SSL_CIPHER ssl3_ciphers[]; | 512 | OPENSSL_EXTERN SSL_CIPHER ssl3_ciphers[]; |
| 468 | 513 | ||
| 469 | #ifdef OPENSSL_SYS_VMS | ||
| 470 | #undef SSL_COMP_get_compression_methods | ||
| 471 | #define SSL_COMP_get_compression_methods SSL_COMP_get_compress_methods | ||
| 472 | #endif | ||
| 473 | |||
| 474 | 514 | ||
| 475 | SSL_METHOD *ssl_bad_method(int ver); | 515 | SSL_METHOD *ssl_bad_method(int ver); |
| 476 | SSL_METHOD *sslv2_base_method(void); | 516 | SSL_METHOD *sslv2_base_method(void); |
| 477 | SSL_METHOD *sslv23_base_method(void); | 517 | SSL_METHOD *sslv23_base_method(void); |
| 478 | SSL_METHOD *sslv3_base_method(void); | 518 | SSL_METHOD *sslv3_base_method(void); |
| 479 | 519 | ||
| 520 | extern SSL3_ENC_METHOD TLSv1_enc_data; | ||
| 521 | extern SSL3_ENC_METHOD SSLv3_enc_data; | ||
| 522 | extern SSL3_ENC_METHOD DTLSv1_enc_data; | ||
| 523 | |||
| 524 | #define IMPLEMENT_tls1_meth_func(func_name, s_accept, s_connect, s_get_meth) \ | ||
| 525 | SSL_METHOD *func_name(void) \ | ||
| 526 | { \ | ||
| 527 | static SSL_METHOD func_name##_data= { \ | ||
| 528 | TLS1_VERSION, \ | ||
| 529 | tls1_new, \ | ||
| 530 | tls1_clear, \ | ||
| 531 | tls1_free, \ | ||
| 532 | s_accept, \ | ||
| 533 | s_connect, \ | ||
| 534 | ssl3_read, \ | ||
| 535 | ssl3_peek, \ | ||
| 536 | ssl3_write, \ | ||
| 537 | ssl3_shutdown, \ | ||
| 538 | ssl3_renegotiate, \ | ||
| 539 | ssl3_renegotiate_check, \ | ||
| 540 | ssl3_get_message, \ | ||
| 541 | ssl3_read_bytes, \ | ||
| 542 | ssl3_write_bytes, \ | ||
| 543 | ssl3_dispatch_alert, \ | ||
| 544 | ssl3_ctrl, \ | ||
| 545 | ssl3_ctx_ctrl, \ | ||
| 546 | ssl3_get_cipher_by_char, \ | ||
| 547 | ssl3_put_cipher_by_char, \ | ||
| 548 | ssl3_pending, \ | ||
| 549 | ssl3_num_ciphers, \ | ||
| 550 | ssl3_get_cipher, \ | ||
| 551 | s_get_meth, \ | ||
| 552 | tls1_default_timeout, \ | ||
| 553 | &TLSv1_enc_data, \ | ||
| 554 | ssl_undefined_void_function, \ | ||
| 555 | ssl3_callback_ctrl, \ | ||
| 556 | ssl3_ctx_callback_ctrl, \ | ||
| 557 | }; \ | ||
| 558 | return &func_name##_data; \ | ||
| 559 | } | ||
| 560 | |||
| 561 | #define IMPLEMENT_ssl3_meth_func(func_name, s_accept, s_connect, s_get_meth) \ | ||
| 562 | SSL_METHOD *func_name(void) \ | ||
| 563 | { \ | ||
| 564 | static SSL_METHOD func_name##_data= { \ | ||
| 565 | SSL3_VERSION, \ | ||
| 566 | ssl3_new, \ | ||
| 567 | ssl3_clear, \ | ||
| 568 | ssl3_free, \ | ||
| 569 | s_accept, \ | ||
| 570 | s_connect, \ | ||
| 571 | ssl3_read, \ | ||
| 572 | ssl3_peek, \ | ||
| 573 | ssl3_write, \ | ||
| 574 | ssl3_shutdown, \ | ||
| 575 | ssl3_renegotiate, \ | ||
| 576 | ssl3_renegotiate_check, \ | ||
| 577 | ssl3_get_message, \ | ||
| 578 | ssl3_read_bytes, \ | ||
| 579 | ssl3_write_bytes, \ | ||
| 580 | ssl3_dispatch_alert, \ | ||
| 581 | ssl3_ctrl, \ | ||
| 582 | ssl3_ctx_ctrl, \ | ||
| 583 | ssl3_get_cipher_by_char, \ | ||
| 584 | ssl3_put_cipher_by_char, \ | ||
| 585 | ssl3_pending, \ | ||
| 586 | ssl3_num_ciphers, \ | ||
| 587 | ssl3_get_cipher, \ | ||
| 588 | s_get_meth, \ | ||
| 589 | ssl3_default_timeout, \ | ||
| 590 | &SSLv3_enc_data, \ | ||
| 591 | ssl_undefined_void_function, \ | ||
| 592 | ssl3_callback_ctrl, \ | ||
| 593 | ssl3_ctx_callback_ctrl, \ | ||
| 594 | }; \ | ||
| 595 | return &func_name##_data; \ | ||
| 596 | } | ||
| 597 | |||
| 598 | #define IMPLEMENT_ssl23_meth_func(func_name, s_accept, s_connect, s_get_meth) \ | ||
| 599 | SSL_METHOD *func_name(void) \ | ||
| 600 | { \ | ||
| 601 | static SSL_METHOD func_name##_data= { \ | ||
| 602 | TLS1_VERSION, \ | ||
| 603 | tls1_new, \ | ||
| 604 | tls1_clear, \ | ||
| 605 | tls1_free, \ | ||
| 606 | s_accept, \ | ||
| 607 | s_connect, \ | ||
| 608 | ssl23_read, \ | ||
| 609 | ssl23_peek, \ | ||
| 610 | ssl23_write, \ | ||
| 611 | ssl_undefined_function, \ | ||
| 612 | ssl_undefined_function, \ | ||
| 613 | ssl_ok, \ | ||
| 614 | ssl3_get_message, \ | ||
| 615 | ssl3_read_bytes, \ | ||
| 616 | ssl3_write_bytes, \ | ||
| 617 | ssl3_dispatch_alert, \ | ||
| 618 | ssl3_ctrl, \ | ||
| 619 | ssl3_ctx_ctrl, \ | ||
| 620 | ssl23_get_cipher_by_char, \ | ||
| 621 | ssl23_put_cipher_by_char, \ | ||
| 622 | ssl_undefined_const_function, \ | ||
| 623 | ssl23_num_ciphers, \ | ||
| 624 | ssl23_get_cipher, \ | ||
| 625 | s_get_meth, \ | ||
| 626 | ssl23_default_timeout, \ | ||
| 627 | &ssl3_undef_enc_method, \ | ||
| 628 | ssl_undefined_void_function, \ | ||
| 629 | ssl3_callback_ctrl, \ | ||
| 630 | ssl3_ctx_callback_ctrl, \ | ||
| 631 | }; \ | ||
| 632 | return &func_name##_data; \ | ||
| 633 | } | ||
| 634 | |||
| 635 | #define IMPLEMENT_ssl2_meth_func(func_name, s_accept, s_connect, s_get_meth) \ | ||
| 636 | SSL_METHOD *func_name(void) \ | ||
| 637 | { \ | ||
| 638 | static SSL_METHOD func_name##_data= { \ | ||
| 639 | SSL2_VERSION, \ | ||
| 640 | ssl2_new, /* local */ \ | ||
| 641 | ssl2_clear, /* local */ \ | ||
| 642 | ssl2_free, /* local */ \ | ||
| 643 | s_accept, \ | ||
| 644 | s_connect, \ | ||
| 645 | ssl2_read, \ | ||
| 646 | ssl2_peek, \ | ||
| 647 | ssl2_write, \ | ||
| 648 | ssl2_shutdown, \ | ||
| 649 | ssl_ok, /* NULL - renegotiate */ \ | ||
| 650 | ssl_ok, /* NULL - check renegotiate */ \ | ||
| 651 | NULL, /* NULL - ssl_get_message */ \ | ||
| 652 | NULL, /* NULL - ssl_get_record */ \ | ||
| 653 | NULL, /* NULL - ssl_write_bytes */ \ | ||
| 654 | NULL, /* NULL - dispatch_alert */ \ | ||
| 655 | ssl2_ctrl, /* local */ \ | ||
| 656 | ssl2_ctx_ctrl, /* local */ \ | ||
| 657 | ssl2_get_cipher_by_char, \ | ||
| 658 | ssl2_put_cipher_by_char, \ | ||
| 659 | ssl2_pending, \ | ||
| 660 | ssl2_num_ciphers, \ | ||
| 661 | ssl2_get_cipher, \ | ||
| 662 | s_get_meth, \ | ||
| 663 | ssl2_default_timeout, \ | ||
| 664 | &ssl3_undef_enc_method, \ | ||
| 665 | ssl_undefined_void_function, \ | ||
| 666 | ssl2_callback_ctrl, /* local */ \ | ||
| 667 | ssl2_ctx_callback_ctrl, /* local */ \ | ||
| 668 | }; \ | ||
| 669 | return &func_name##_data; \ | ||
| 670 | } | ||
| 671 | |||
| 672 | #define IMPLEMENT_dtls1_meth_func(func_name, s_accept, s_connect, s_get_meth) \ | ||
| 673 | SSL_METHOD *func_name(void) \ | ||
| 674 | { \ | ||
| 675 | static SSL_METHOD func_name##_data= { \ | ||
| 676 | DTLS1_VERSION, \ | ||
| 677 | dtls1_new, \ | ||
| 678 | dtls1_clear, \ | ||
| 679 | dtls1_free, \ | ||
| 680 | s_accept, \ | ||
| 681 | s_connect, \ | ||
| 682 | ssl3_read, \ | ||
| 683 | ssl3_peek, \ | ||
| 684 | ssl3_write, \ | ||
| 685 | ssl3_shutdown, \ | ||
| 686 | ssl3_renegotiate, \ | ||
| 687 | ssl3_renegotiate_check, \ | ||
| 688 | dtls1_get_message, \ | ||
| 689 | dtls1_read_bytes, \ | ||
| 690 | dtls1_write_app_data_bytes, \ | ||
| 691 | dtls1_dispatch_alert, \ | ||
| 692 | ssl3_ctrl, \ | ||
| 693 | ssl3_ctx_ctrl, \ | ||
| 694 | ssl3_get_cipher_by_char, \ | ||
| 695 | ssl3_put_cipher_by_char, \ | ||
| 696 | ssl3_pending, \ | ||
| 697 | ssl3_num_ciphers, \ | ||
| 698 | dtls1_get_cipher, \ | ||
| 699 | s_get_meth, \ | ||
| 700 | dtls1_default_timeout, \ | ||
| 701 | &DTLSv1_enc_data, \ | ||
| 702 | ssl_undefined_void_function, \ | ||
| 703 | ssl3_callback_ctrl, \ | ||
| 704 | ssl3_ctx_callback_ctrl, \ | ||
| 705 | }; \ | ||
| 706 | return &func_name##_data; \ | ||
| 707 | } | ||
| 708 | |||
| 480 | void ssl_clear_cipher_ctx(SSL *s); | 709 | void ssl_clear_cipher_ctx(SSL *s); |
| 481 | int ssl_clear_bad_session(SSL *s); | 710 | int ssl_clear_bad_session(SSL *s); |
| 482 | CERT *ssl_cert_new(void); | 711 | CERT *ssl_cert_new(void); |
| @@ -487,7 +716,7 @@ SESS_CERT *ssl_sess_cert_new(void); | |||
| 487 | void ssl_sess_cert_free(SESS_CERT *sc); | 716 | void ssl_sess_cert_free(SESS_CERT *sc); |
| 488 | int ssl_set_peer_cert_type(SESS_CERT *c, int type); | 717 | int ssl_set_peer_cert_type(SESS_CERT *c, int type); |
| 489 | int ssl_get_new_session(SSL *s, int session); | 718 | int ssl_get_new_session(SSL *s, int session); |
| 490 | int ssl_get_prev_session(SSL *s, unsigned char *session,int len); | 719 | int ssl_get_prev_session(SSL *s, unsigned char *session,int len, const unsigned char *limit); |
| 491 | int ssl_cipher_id_cmp(const SSL_CIPHER *a,const SSL_CIPHER *b); | 720 | int ssl_cipher_id_cmp(const SSL_CIPHER *a,const SSL_CIPHER *b); |
| 492 | int ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap, | 721 | int ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap, |
| 493 | const SSL_CIPHER * const *bp); | 722 | const SSL_CIPHER * const *bp); |
| @@ -504,6 +733,7 @@ int ssl_cipher_get_evp(const SSL_SESSION *s,const EVP_CIPHER **enc, | |||
| 504 | const EVP_MD **md,SSL_COMP **comp); | 733 | const EVP_MD **md,SSL_COMP **comp); |
| 505 | int ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk); | 734 | int ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk); |
| 506 | int ssl_undefined_function(SSL *s); | 735 | int ssl_undefined_function(SSL *s); |
| 736 | int ssl_undefined_void_function(void); | ||
| 507 | int ssl_undefined_const_function(const SSL *s); | 737 | int ssl_undefined_const_function(const SSL *s); |
| 508 | X509 *ssl_get_server_send_cert(SSL *); | 738 | X509 *ssl_get_server_send_cert(SSL *); |
| 509 | EVP_PKEY *ssl_get_sign_pkey(SSL *,SSL_CIPHER *); | 739 | EVP_PKEY *ssl_get_sign_pkey(SSL *,SSL_CIPHER *); |
| @@ -511,6 +741,7 @@ int ssl_cert_type(X509 *x,EVP_PKEY *pkey); | |||
| 511 | void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher); | 741 | void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher); |
| 512 | STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s); | 742 | STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s); |
| 513 | int ssl_verify_alarm_type(long type); | 743 | int ssl_verify_alarm_type(long type); |
| 744 | void ssl_load_ciphers(void); | ||
| 514 | 745 | ||
| 515 | int ssl2_enc_init(SSL *s, int client); | 746 | int ssl2_enc_init(SSL *s, int client); |
| 516 | int ssl2_generate_key_material(SSL *s); | 747 | int ssl2_generate_key_material(SSL *s); |
| @@ -520,7 +751,7 @@ SSL_CIPHER *ssl2_get_cipher_by_char(const unsigned char *p); | |||
| 520 | int ssl2_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p); | 751 | int ssl2_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p); |
| 521 | int ssl2_part_read(SSL *s, unsigned long f, int i); | 752 | int ssl2_part_read(SSL *s, unsigned long f, int i); |
| 522 | int ssl2_do_write(SSL *s); | 753 | int ssl2_do_write(SSL *s); |
| 523 | int ssl2_set_certificate(SSL *s, int type, int len, unsigned char *data); | 754 | int ssl2_set_certificate(SSL *s, int type, int len, const unsigned char *data); |
| 524 | void ssl2_return_error(SSL *s,int reason); | 755 | void ssl2_return_error(SSL *s,int reason); |
| 525 | void ssl2_write_error(SSL *s); | 756 | void ssl2_write_error(SSL *s); |
| 526 | int ssl2_num_ciphers(void); | 757 | int ssl2_num_ciphers(void); |
| @@ -536,14 +767,17 @@ int ssl2_shutdown(SSL *s); | |||
| 536 | void ssl2_clear(SSL *s); | 767 | void ssl2_clear(SSL *s); |
| 537 | long ssl2_ctrl(SSL *s,int cmd, long larg, void *parg); | 768 | long ssl2_ctrl(SSL *s,int cmd, long larg, void *parg); |
| 538 | long ssl2_ctx_ctrl(SSL_CTX *s,int cmd, long larg, void *parg); | 769 | long ssl2_ctx_ctrl(SSL_CTX *s,int cmd, long larg, void *parg); |
| 539 | long ssl2_callback_ctrl(SSL *s,int cmd, void (*fp)()); | 770 | long ssl2_callback_ctrl(SSL *s,int cmd, void (*fp)(void)); |
| 540 | long ssl2_ctx_callback_ctrl(SSL_CTX *s,int cmd, void (*fp)()); | 771 | long ssl2_ctx_callback_ctrl(SSL_CTX *s,int cmd, void (*fp)(void)); |
| 541 | int ssl2_pending(const SSL *s); | 772 | int ssl2_pending(const SSL *s); |
| 773 | long ssl2_default_timeout(void ); | ||
| 542 | 774 | ||
| 543 | SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p); | 775 | SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p); |
| 544 | int ssl3_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p); | 776 | int ssl3_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p); |
| 545 | void ssl3_init_finished_mac(SSL *s); | 777 | void ssl3_init_finished_mac(SSL *s); |
| 546 | int ssl3_send_server_certificate(SSL *s); | 778 | int ssl3_send_server_certificate(SSL *s); |
| 779 | int ssl3_send_newsession_ticket(SSL *s); | ||
| 780 | int ssl3_send_cert_status(SSL *s); | ||
| 547 | int ssl3_get_finished(SSL *s,int state_a,int state_b); | 781 | int ssl3_get_finished(SSL *s,int state_a,int state_b); |
| 548 | int ssl3_setup_key_block(SSL *s); | 782 | int ssl3_setup_key_block(SSL *s); |
| 549 | int ssl3_send_change_cipher_spec(SSL *s,int state_a,int state_b); | 783 | int ssl3_send_change_cipher_spec(SSL *s,int state_a,int state_b); |
| @@ -584,10 +818,94 @@ int ssl3_shutdown(SSL *s); | |||
| 584 | void ssl3_clear(SSL *s); | 818 | void ssl3_clear(SSL *s); |
| 585 | long ssl3_ctrl(SSL *s,int cmd, long larg, void *parg); | 819 | long ssl3_ctrl(SSL *s,int cmd, long larg, void *parg); |
| 586 | long ssl3_ctx_ctrl(SSL_CTX *s,int cmd, long larg, void *parg); | 820 | long ssl3_ctx_ctrl(SSL_CTX *s,int cmd, long larg, void *parg); |
| 587 | long ssl3_callback_ctrl(SSL *s,int cmd, void (*fp)()); | 821 | long ssl3_callback_ctrl(SSL *s,int cmd, void (*fp)(void)); |
| 588 | long ssl3_ctx_callback_ctrl(SSL_CTX *s,int cmd, void (*fp)()); | 822 | long ssl3_ctx_callback_ctrl(SSL_CTX *s,int cmd, void (*fp)(void)); |
| 589 | int ssl3_pending(const SSL *s); | 823 | int ssl3_pending(const SSL *s); |
| 590 | 824 | ||
| 825 | void ssl3_record_sequence_update(unsigned char *seq); | ||
| 826 | int ssl3_do_change_cipher_spec(SSL *ssl); | ||
| 827 | long ssl3_default_timeout(void ); | ||
| 828 | |||
| 829 | int ssl23_num_ciphers(void ); | ||
| 830 | SSL_CIPHER *ssl23_get_cipher(unsigned int u); | ||
| 831 | int ssl23_read(SSL *s, void *buf, int len); | ||
| 832 | int ssl23_peek(SSL *s, void *buf, int len); | ||
| 833 | int ssl23_write(SSL *s, const void *buf, int len); | ||
| 834 | int ssl23_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p); | ||
| 835 | SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p); | ||
| 836 | long ssl23_default_timeout(void ); | ||
| 837 | |||
| 838 | long tls1_default_timeout(void); | ||
| 839 | int dtls1_do_write(SSL *s,int type); | ||
| 840 | int ssl3_read_n(SSL *s, int n, int max, int extend); | ||
| 841 | int dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek); | ||
| 842 | int ssl3_do_compress(SSL *ssl); | ||
| 843 | int ssl3_do_uncompress(SSL *ssl); | ||
| 844 | int ssl3_write_pending(SSL *s, int type, const unsigned char *buf, | ||
| 845 | unsigned int len); | ||
| 846 | unsigned char *dtls1_set_message_header(SSL *s, | ||
| 847 | unsigned char *p, unsigned char mt, unsigned long len, | ||
| 848 | unsigned long frag_off, unsigned long frag_len); | ||
| 849 | |||
| 850 | int dtls1_write_app_data_bytes(SSL *s, int type, const void *buf, int len); | ||
| 851 | int dtls1_write_bytes(SSL *s, int type, const void *buf, int len); | ||
| 852 | |||
| 853 | int dtls1_send_change_cipher_spec(SSL *s, int a, int b); | ||
| 854 | int dtls1_send_finished(SSL *s, int a, int b, const char *sender, int slen); | ||
| 855 | unsigned long dtls1_output_cert_chain(SSL *s, X509 *x); | ||
| 856 | int dtls1_read_failed(SSL *s, int code); | ||
| 857 | int dtls1_buffer_message(SSL *s, int ccs); | ||
| 858 | int dtls1_retransmit_message(SSL *s, unsigned short seq, | ||
| 859 | unsigned long frag_off, int *found); | ||
| 860 | void dtls1_clear_record_buffer(SSL *s); | ||
| 861 | void dtls1_get_message_header(unsigned char *data, struct hm_header_st *msg_hdr); | ||
| 862 | void dtls1_get_ccs_header(unsigned char *data, struct ccs_header_st *ccs_hdr); | ||
| 863 | void dtls1_reset_seq_numbers(SSL *s, int rw); | ||
| 864 | long dtls1_default_timeout(void); | ||
| 865 | SSL_CIPHER *dtls1_get_cipher(unsigned int u); | ||
| 866 | |||
| 867 | |||
| 868 | |||
| 869 | /* some client-only functions */ | ||
| 870 | int ssl3_client_hello(SSL *s); | ||
| 871 | int ssl3_get_server_hello(SSL *s); | ||
| 872 | int ssl3_get_certificate_request(SSL *s); | ||
| 873 | int ssl3_get_new_session_ticket(SSL *s); | ||
| 874 | int ssl3_get_cert_status(SSL *s); | ||
| 875 | int ssl3_get_server_done(SSL *s); | ||
| 876 | int ssl3_send_client_verify(SSL *s); | ||
| 877 | int ssl3_send_client_certificate(SSL *s); | ||
| 878 | int ssl3_send_client_key_exchange(SSL *s); | ||
| 879 | int ssl3_get_key_exchange(SSL *s); | ||
| 880 | int ssl3_get_server_certificate(SSL *s); | ||
| 881 | int ssl3_check_cert_and_algorithm(SSL *s); | ||
| 882 | |||
| 883 | int dtls1_client_hello(SSL *s); | ||
| 884 | int dtls1_send_client_certificate(SSL *s); | ||
| 885 | int dtls1_send_client_key_exchange(SSL *s); | ||
| 886 | int dtls1_send_client_verify(SSL *s); | ||
| 887 | |||
| 888 | /* some server-only functions */ | ||
| 889 | int ssl3_get_client_hello(SSL *s); | ||
| 890 | int ssl3_send_server_hello(SSL *s); | ||
| 891 | int ssl3_send_hello_request(SSL *s); | ||
| 892 | int ssl3_send_server_key_exchange(SSL *s); | ||
| 893 | int ssl3_send_certificate_request(SSL *s); | ||
| 894 | int ssl3_send_server_done(SSL *s); | ||
| 895 | int ssl3_check_client_hello(SSL *s); | ||
| 896 | int ssl3_get_client_certificate(SSL *s); | ||
| 897 | int ssl3_get_client_key_exchange(SSL *s); | ||
| 898 | int ssl3_get_cert_verify(SSL *s); | ||
| 899 | |||
| 900 | int dtls1_send_hello_request(SSL *s); | ||
| 901 | int dtls1_send_server_hello(SSL *s); | ||
| 902 | int dtls1_send_server_certificate(SSL *s); | ||
| 903 | int dtls1_send_server_key_exchange(SSL *s); | ||
| 904 | int dtls1_send_certificate_request(SSL *s); | ||
| 905 | int dtls1_send_server_done(SSL *s); | ||
| 906 | |||
| 907 | |||
| 908 | |||
| 591 | int ssl23_accept(SSL *s); | 909 | int ssl23_accept(SSL *s); |
| 592 | int ssl23_connect(SSL *s); | 910 | int ssl23_connect(SSL *s); |
| 593 | int ssl23_read_bytes(SSL *s, int n); | 911 | int ssl23_read_bytes(SSL *s, int n); |
| @@ -597,9 +915,24 @@ int tls1_new(SSL *s); | |||
| 597 | void tls1_free(SSL *s); | 915 | void tls1_free(SSL *s); |
| 598 | void tls1_clear(SSL *s); | 916 | void tls1_clear(SSL *s); |
| 599 | long tls1_ctrl(SSL *s,int cmd, long larg, void *parg); | 917 | long tls1_ctrl(SSL *s,int cmd, long larg, void *parg); |
| 600 | long tls1_callback_ctrl(SSL *s,int cmd, void (*fp)()); | 918 | long tls1_callback_ctrl(SSL *s,int cmd, void (*fp)(void)); |
| 601 | SSL_METHOD *tlsv1_base_method(void ); | 919 | SSL_METHOD *tlsv1_base_method(void ); |
| 602 | 920 | ||
| 921 | int dtls1_new(SSL *s); | ||
| 922 | int dtls1_accept(SSL *s); | ||
| 923 | int dtls1_connect(SSL *s); | ||
| 924 | void dtls1_free(SSL *s); | ||
| 925 | void dtls1_clear(SSL *s); | ||
| 926 | long dtls1_ctrl(SSL *s,int cmd, long larg, void *parg); | ||
| 927 | SSL_METHOD *dtlsv1_base_method(void ); | ||
| 928 | |||
| 929 | long dtls1_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok); | ||
| 930 | int dtls1_get_record(SSL *s); | ||
| 931 | int do_dtls1_write(SSL *s, int type, const unsigned char *buf, | ||
| 932 | unsigned int len, int create_empty_fragement); | ||
| 933 | int dtls1_dispatch_alert(SSL *s); | ||
| 934 | int dtls1_enc(SSL *s, int snd); | ||
| 935 | |||
| 603 | int ssl_init_wbio_buffer(SSL *s, int push); | 936 | int ssl_init_wbio_buffer(SSL *s, int push); |
| 604 | void ssl_free_wbio_buffer(SSL *s); | 937 | void ssl_free_wbio_buffer(SSL *s); |
| 605 | 938 | ||
| @@ -616,8 +949,28 @@ int tls1_alert_code(int code); | |||
| 616 | int ssl3_alert_code(int code); | 949 | int ssl3_alert_code(int code); |
| 617 | int ssl_ok(SSL *s); | 950 | int ssl_ok(SSL *s); |
| 618 | 951 | ||
| 952 | int check_srvr_ecc_cert_and_alg(X509 *x, SSL_CIPHER *cs); | ||
| 953 | |||
| 619 | SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n); | 954 | SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n); |
| 620 | STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void); | ||
| 621 | 955 | ||
| 956 | #ifndef OPENSSL_NO_TLSEXT | ||
| 957 | unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *p, unsigned char *limit); | ||
| 958 | unsigned char *ssl_add_serverhello_tlsext(SSL *s, unsigned char *p, unsigned char *limit); | ||
| 959 | int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **data, unsigned char *d, int n, int *al); | ||
| 960 | int ssl_parse_serverhello_tlsext(SSL *s, unsigned char **data, unsigned char *d, int n, int *al); | ||
| 961 | int ssl_prepare_clienthello_tlsext(SSL *s); | ||
| 962 | int ssl_prepare_serverhello_tlsext(SSL *s); | ||
| 963 | int ssl_check_clienthello_tlsext(SSL *s); | ||
| 964 | int ssl_check_serverhello_tlsext(SSL *s); | ||
| 965 | #ifdef OPENSSL_NO_SHA256 | ||
| 966 | #define tlsext_tick_md EVP_sha1 | ||
| 967 | #else | ||
| 968 | #define tlsext_tick_md EVP_sha256 | ||
| 969 | #endif | ||
| 970 | int tls1_process_ticket(SSL *s, unsigned char *session_id, int len, | ||
| 971 | const unsigned char *limit, SSL_SESSION **ret); | ||
| 972 | EVP_MD_CTX* ssl_replace_hash(EVP_MD_CTX **hash,const EVP_MD *md) ; | ||
| 973 | void ssl_clear_hash_ctx(EVP_MD_CTX **hash); | ||
| 974 | #endif | ||
| 622 | 975 | ||
| 623 | #endif | 976 | #endif |
diff --git a/src/lib/libssl/ssl_rsa.c b/src/lib/libssl/ssl_rsa.c index fb0bd4d045..27113eba50 100644 --- a/src/lib/libssl/ssl_rsa.c +++ b/src/lib/libssl/ssl_rsa.c | |||
| @@ -131,7 +131,7 @@ end: | |||
| 131 | } | 131 | } |
| 132 | #endif | 132 | #endif |
| 133 | 133 | ||
| 134 | int SSL_use_certificate_ASN1(SSL *ssl, unsigned char *d, int len) | 134 | int SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len) |
| 135 | { | 135 | { |
| 136 | X509 *x; | 136 | X509 *x; |
| 137 | int ret; | 137 | int ret; |
| @@ -181,7 +181,7 @@ int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa) | |||
| 181 | 181 | ||
| 182 | static int ssl_set_pkey(CERT *c, EVP_PKEY *pkey) | 182 | static int ssl_set_pkey(CERT *c, EVP_PKEY *pkey) |
| 183 | { | 183 | { |
| 184 | int i,ok=0,bad=0; | 184 | int i; |
| 185 | 185 | ||
| 186 | i=ssl_cert_type(NULL,pkey); | 186 | i=ssl_cert_type(NULL,pkey); |
| 187 | if (i < 0) | 187 | if (i < 0) |
| @@ -202,47 +202,18 @@ static int ssl_set_pkey(CERT *c, EVP_PKEY *pkey) | |||
| 202 | /* Don't check the public/private key, this is mostly | 202 | /* Don't check the public/private key, this is mostly |
| 203 | * for smart cards. */ | 203 | * for smart cards. */ |
| 204 | if ((pkey->type == EVP_PKEY_RSA) && | 204 | if ((pkey->type == EVP_PKEY_RSA) && |
| 205 | (RSA_flags(pkey->pkey.rsa) & | 205 | (RSA_flags(pkey->pkey.rsa) & RSA_METHOD_FLAG_NO_CHECK)) |
| 206 | RSA_METHOD_FLAG_NO_CHECK)) | 206 | ; |
| 207 | ok=1; | ||
| 208 | else | 207 | else |
| 209 | #endif | 208 | #endif |
| 210 | if (!X509_check_private_key(c->pkeys[i].x509,pkey)) | 209 | if (!X509_check_private_key(c->pkeys[i].x509,pkey)) |
| 211 | { | 210 | { |
| 212 | if ((i == SSL_PKEY_DH_RSA) || (i == SSL_PKEY_DH_DSA)) | 211 | X509_free(c->pkeys[i].x509); |
| 213 | { | 212 | c->pkeys[i].x509 = NULL; |
| 214 | i=(i == SSL_PKEY_DH_RSA)? | 213 | return 0; |
| 215 | SSL_PKEY_DH_DSA:SSL_PKEY_DH_RSA; | ||
| 216 | |||
| 217 | if (c->pkeys[i].x509 == NULL) | ||
| 218 | ok=1; | ||
| 219 | else | ||
| 220 | { | ||
| 221 | if (!X509_check_private_key( | ||
| 222 | c->pkeys[i].x509,pkey)) | ||
| 223 | bad=1; | ||
| 224 | else | ||
| 225 | ok=1; | ||
| 226 | } | ||
| 227 | } | ||
| 228 | else | ||
| 229 | bad=1; | ||
| 230 | } | 214 | } |
| 231 | else | ||
| 232 | ok=1; | ||
| 233 | } | ||
| 234 | else | ||
| 235 | ok=1; | ||
| 236 | |||
| 237 | if (bad) | ||
| 238 | { | ||
| 239 | X509_free(c->pkeys[i].x509); | ||
| 240 | c->pkeys[i].x509=NULL; | ||
| 241 | return(0); | ||
| 242 | } | 215 | } |
| 243 | 216 | ||
| 244 | ERR_clear_error(); /* make sure no error from X509_check_private_key() | ||
| 245 | * is left if we have chosen to ignore it */ | ||
| 246 | if (c->pkeys[i].privatekey != NULL) | 217 | if (c->pkeys[i].privatekey != NULL) |
| 247 | EVP_PKEY_free(c->pkeys[i].privatekey); | 218 | EVP_PKEY_free(c->pkeys[i].privatekey); |
| 248 | CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY); | 219 | CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY); |
| @@ -364,6 +335,11 @@ int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type) | |||
| 364 | pkey=PEM_read_bio_PrivateKey(in,NULL, | 335 | pkey=PEM_read_bio_PrivateKey(in,NULL, |
| 365 | ssl->ctx->default_passwd_callback,ssl->ctx->default_passwd_callback_userdata); | 336 | ssl->ctx->default_passwd_callback,ssl->ctx->default_passwd_callback_userdata); |
| 366 | } | 337 | } |
| 338 | else if (type == SSL_FILETYPE_ASN1) | ||
| 339 | { | ||
| 340 | j = ERR_R_ASN1_LIB; | ||
| 341 | pkey = d2i_PrivateKey_bio(in,NULL); | ||
| 342 | } | ||
| 367 | else | 343 | else |
| 368 | { | 344 | { |
| 369 | SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE); | 345 | SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE); |
| @@ -382,10 +358,10 @@ end: | |||
| 382 | } | 358 | } |
| 383 | #endif | 359 | #endif |
| 384 | 360 | ||
| 385 | int SSL_use_PrivateKey_ASN1(int type, SSL *ssl, unsigned char *d, long len) | 361 | int SSL_use_PrivateKey_ASN1(int type, SSL *ssl, const unsigned char *d, long len) |
| 386 | { | 362 | { |
| 387 | int ret; | 363 | int ret; |
| 388 | unsigned char *p; | 364 | const unsigned char *p; |
| 389 | EVP_PKEY *pkey; | 365 | EVP_PKEY *pkey; |
| 390 | 366 | ||
| 391 | p=d; | 367 | p=d; |
| @@ -418,7 +394,7 @@ int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x) | |||
| 418 | static int ssl_set_cert(CERT *c, X509 *x) | 394 | static int ssl_set_cert(CERT *c, X509 *x) |
| 419 | { | 395 | { |
| 420 | EVP_PKEY *pkey; | 396 | EVP_PKEY *pkey; |
| 421 | int i,ok=0,bad=0; | 397 | int i; |
| 422 | 398 | ||
| 423 | pkey=X509_get_pubkey(x); | 399 | pkey=X509_get_pubkey(x); |
| 424 | if (pkey == NULL) | 400 | if (pkey == NULL) |
| @@ -446,44 +422,23 @@ static int ssl_set_cert(CERT *c, X509 *x) | |||
| 446 | if ((c->pkeys[i].privatekey->type == EVP_PKEY_RSA) && | 422 | if ((c->pkeys[i].privatekey->type == EVP_PKEY_RSA) && |
| 447 | (RSA_flags(c->pkeys[i].privatekey->pkey.rsa) & | 423 | (RSA_flags(c->pkeys[i].privatekey->pkey.rsa) & |
| 448 | RSA_METHOD_FLAG_NO_CHECK)) | 424 | RSA_METHOD_FLAG_NO_CHECK)) |
| 449 | ok=1; | 425 | ; |
| 450 | else | 426 | else |
| 451 | #endif | 427 | #endif /* OPENSSL_NO_RSA */ |
| 452 | { | ||
| 453 | if (!X509_check_private_key(x,c->pkeys[i].privatekey)) | 428 | if (!X509_check_private_key(x,c->pkeys[i].privatekey)) |
| 454 | { | 429 | { |
| 455 | if ((i == SSL_PKEY_DH_RSA) || (i == SSL_PKEY_DH_DSA)) | 430 | /* don't fail for a cert/key mismatch, just free |
| 456 | { | 431 | * current private key (when switching to a different |
| 457 | i=(i == SSL_PKEY_DH_RSA)? | 432 | * cert & key, first this function should be used, |
| 458 | SSL_PKEY_DH_DSA:SSL_PKEY_DH_RSA; | 433 | * then ssl_set_pkey */ |
| 459 | 434 | EVP_PKEY_free(c->pkeys[i].privatekey); | |
| 460 | if (c->pkeys[i].privatekey == NULL) | 435 | c->pkeys[i].privatekey=NULL; |
| 461 | ok=1; | 436 | /* clear error queue */ |
| 462 | else | 437 | ERR_clear_error(); |
| 463 | { | ||
| 464 | if (!X509_check_private_key(x, | ||
| 465 | c->pkeys[i].privatekey)) | ||
| 466 | bad=1; | ||
| 467 | else | ||
| 468 | ok=1; | ||
| 469 | } | ||
| 470 | } | ||
| 471 | else | ||
| 472 | bad=1; | ||
| 473 | } | 438 | } |
| 474 | else | ||
| 475 | ok=1; | ||
| 476 | } /* OPENSSL_NO_RSA */ | ||
| 477 | } | 439 | } |
| 478 | else | ||
| 479 | ok=1; | ||
| 480 | 440 | ||
| 481 | EVP_PKEY_free(pkey); | 441 | EVP_PKEY_free(pkey); |
| 482 | if (bad) | ||
| 483 | { | ||
| 484 | EVP_PKEY_free(c->pkeys[i].privatekey); | ||
| 485 | c->pkeys[i].privatekey=NULL; | ||
| 486 | } | ||
| 487 | 442 | ||
| 488 | if (c->pkeys[i].x509 != NULL) | 443 | if (c->pkeys[i].x509 != NULL) |
| 489 | X509_free(c->pkeys[i].x509); | 444 | X509_free(c->pkeys[i].x509); |
| @@ -545,7 +500,7 @@ end: | |||
| 545 | } | 500 | } |
| 546 | #endif | 501 | #endif |
| 547 | 502 | ||
| 548 | int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, unsigned char *d) | 503 | int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, const unsigned char *d) |
| 549 | { | 504 | { |
| 550 | X509 *x; | 505 | X509 *x; |
| 551 | int ret; | 506 | int ret; |
| @@ -640,7 +595,7 @@ end: | |||
| 640 | } | 595 | } |
| 641 | #endif | 596 | #endif |
| 642 | 597 | ||
| 643 | int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, unsigned char *d, long len) | 598 | int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, const unsigned char *d, long len) |
| 644 | { | 599 | { |
| 645 | int ret; | 600 | int ret; |
| 646 | const unsigned char *p; | 601 | const unsigned char *p; |
| @@ -699,6 +654,11 @@ int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type) | |||
| 699 | pkey=PEM_read_bio_PrivateKey(in,NULL, | 654 | pkey=PEM_read_bio_PrivateKey(in,NULL, |
| 700 | ctx->default_passwd_callback,ctx->default_passwd_callback_userdata); | 655 | ctx->default_passwd_callback,ctx->default_passwd_callback_userdata); |
| 701 | } | 656 | } |
| 657 | else if (type == SSL_FILETYPE_ASN1) | ||
| 658 | { | ||
| 659 | j = ERR_R_ASN1_LIB; | ||
| 660 | pkey = d2i_PrivateKey_bio(in,NULL); | ||
| 661 | } | ||
| 702 | else | 662 | else |
| 703 | { | 663 | { |
| 704 | SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE); | 664 | SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE); |
| @@ -717,11 +677,11 @@ end: | |||
| 717 | } | 677 | } |
| 718 | #endif | 678 | #endif |
| 719 | 679 | ||
| 720 | int SSL_CTX_use_PrivateKey_ASN1(int type, SSL_CTX *ctx, unsigned char *d, | 680 | int SSL_CTX_use_PrivateKey_ASN1(int type, SSL_CTX *ctx, const unsigned char *d, |
| 721 | long len) | 681 | long len) |
| 722 | { | 682 | { |
| 723 | int ret; | 683 | int ret; |
| 724 | unsigned char *p; | 684 | const unsigned char *p; |
| 725 | EVP_PKEY *pkey; | 685 | EVP_PKEY *pkey; |
| 726 | 686 | ||
| 727 | p=d; | 687 | p=d; |
| @@ -748,6 +708,8 @@ int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file) | |||
| 748 | int ret=0; | 708 | int ret=0; |
| 749 | X509 *x=NULL; | 709 | X509 *x=NULL; |
| 750 | 710 | ||
| 711 | ERR_clear_error(); /* clear error stack for SSL_CTX_use_certificate() */ | ||
| 712 | |||
| 751 | in=BIO_new(BIO_s_file_internal()); | 713 | in=BIO_new(BIO_s_file_internal()); |
| 752 | if (in == NULL) | 714 | if (in == NULL) |
| 753 | { | 715 | { |
diff --git a/src/lib/libssl/ssl_sess.c b/src/lib/libssl/ssl_sess.c index 2ba8b9612e..ee88be2b88 100644 --- a/src/lib/libssl/ssl_sess.c +++ b/src/lib/libssl/ssl_sess.c | |||
| @@ -122,10 +122,20 @@ SSL_SESSION *SSL_SESSION_new(void) | |||
| 122 | ss->prev=NULL; | 122 | ss->prev=NULL; |
| 123 | ss->next=NULL; | 123 | ss->next=NULL; |
| 124 | ss->compress_meth=0; | 124 | ss->compress_meth=0; |
| 125 | #ifndef OPENSSL_NO_TLSEXT | ||
| 126 | ss->tlsext_hostname = NULL; | ||
| 127 | #endif | ||
| 125 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data); | 128 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data); |
| 126 | return(ss); | 129 | return(ss); |
| 127 | } | 130 | } |
| 128 | 131 | ||
| 132 | const unsigned char *SSL_SESSION_get_id(const SSL_SESSION *s, unsigned int *len) | ||
| 133 | { | ||
| 134 | if(len) | ||
| 135 | *len = s->session_id_length; | ||
| 136 | return s->session_id; | ||
| 137 | } | ||
| 138 | |||
| 129 | /* Even with SSLv2, we have 16 bytes (128 bits) of session ID space. SSLv3/TLSv1 | 139 | /* Even with SSLv2, we have 16 bytes (128 bits) of session ID space. SSLv3/TLSv1 |
| 130 | * has 32 bytes (256 bits). As such, filling the ID with random gunk repeatedly | 140 | * has 32 bytes (256 bits). As such, filling the ID with random gunk repeatedly |
| 131 | * until we have no conflict is going to complete in one iteration pretty much | 141 | * until we have no conflict is going to complete in one iteration pretty much |
| @@ -141,7 +151,7 @@ static int def_generate_session_id(const SSL *ssl, unsigned char *id, | |||
| 141 | { | 151 | { |
| 142 | unsigned int retry = 0; | 152 | unsigned int retry = 0; |
| 143 | do | 153 | do |
| 144 | if(RAND_pseudo_bytes(id, *id_len) <= 0) | 154 | if (RAND_pseudo_bytes(id, *id_len) <= 0) |
| 145 | return 0; | 155 | return 0; |
| 146 | while(SSL_has_matching_session_id(ssl, id, *id_len) && | 156 | while(SSL_has_matching_session_id(ssl, id, *id_len) && |
| 147 | (++retry < MAX_SESS_ID_ATTEMPTS)); | 157 | (++retry < MAX_SESS_ID_ATTEMPTS)); |
| @@ -198,12 +208,25 @@ int ssl_get_new_session(SSL *s, int session) | |||
| 198 | ss->ssl_version=TLS1_VERSION; | 208 | ss->ssl_version=TLS1_VERSION; |
| 199 | ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH; | 209 | ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH; |
| 200 | } | 210 | } |
| 211 | else if (s->version == DTLS1_VERSION) | ||
| 212 | { | ||
| 213 | ss->ssl_version=DTLS1_VERSION; | ||
| 214 | ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH; | ||
| 215 | } | ||
| 201 | else | 216 | else |
| 202 | { | 217 | { |
| 203 | SSLerr(SSL_F_SSL_GET_NEW_SESSION,SSL_R_UNSUPPORTED_SSL_VERSION); | 218 | SSLerr(SSL_F_SSL_GET_NEW_SESSION,SSL_R_UNSUPPORTED_SSL_VERSION); |
| 204 | SSL_SESSION_free(ss); | 219 | SSL_SESSION_free(ss); |
| 205 | return(0); | 220 | return(0); |
| 206 | } | 221 | } |
| 222 | #ifndef OPENSSL_NO_TLSEXT | ||
| 223 | /* If RFC4507 ticket use empty session ID */ | ||
| 224 | if (s->tlsext_ticket_expected) | ||
| 225 | { | ||
| 226 | ss->session_id_length = 0; | ||
| 227 | goto sess_id_done; | ||
| 228 | } | ||
| 229 | #endif | ||
| 207 | /* Choose which callback will set the session ID */ | 230 | /* Choose which callback will set the session ID */ |
| 208 | CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX); | 231 | CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX); |
| 209 | if(s->generate_session_id) | 232 | if(s->generate_session_id) |
| @@ -245,6 +268,17 @@ int ssl_get_new_session(SSL *s, int session) | |||
| 245 | SSL_SESSION_free(ss); | 268 | SSL_SESSION_free(ss); |
| 246 | return(0); | 269 | return(0); |
| 247 | } | 270 | } |
| 271 | #ifndef OPENSSL_NO_TLSEXT | ||
| 272 | sess_id_done: | ||
| 273 | if (s->tlsext_hostname) { | ||
| 274 | ss->tlsext_hostname = BUF_strdup(s->tlsext_hostname); | ||
| 275 | if (ss->tlsext_hostname == NULL) { | ||
| 276 | SSLerr(SSL_F_SSL_GET_NEW_SESSION, ERR_R_INTERNAL_ERROR); | ||
| 277 | SSL_SESSION_free(ss); | ||
| 278 | return 0; | ||
| 279 | } | ||
| 280 | } | ||
| 281 | #endif | ||
| 248 | } | 282 | } |
| 249 | else | 283 | else |
| 250 | { | 284 | { |
| @@ -266,21 +300,41 @@ int ssl_get_new_session(SSL *s, int session) | |||
| 266 | return(1); | 300 | return(1); |
| 267 | } | 301 | } |
| 268 | 302 | ||
| 269 | int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len) | 303 | int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len, |
| 304 | const unsigned char *limit) | ||
| 270 | { | 305 | { |
| 271 | /* This is used only by servers. */ | 306 | /* This is used only by servers. */ |
| 272 | 307 | ||
| 273 | SSL_SESSION *ret=NULL,data; | 308 | SSL_SESSION *ret=NULL; |
| 274 | int fatal = 0; | 309 | int fatal = 0; |
| 275 | 310 | #ifndef OPENSSL_NO_TLSEXT | |
| 276 | data.ssl_version=s->version; | 311 | int r; |
| 277 | data.session_id_length=len; | 312 | #endif |
| 313 | |||
| 278 | if (len > SSL_MAX_SSL_SESSION_ID_LENGTH) | 314 | if (len > SSL_MAX_SSL_SESSION_ID_LENGTH) |
| 279 | goto err; | 315 | goto err; |
| 280 | memcpy(data.session_id,session_id,len); | 316 | #ifndef OPENSSL_NO_TLSEXT |
| 281 | 317 | r = tls1_process_ticket(s, session_id, len, limit, &ret); | |
| 318 | if (r == -1) | ||
| 319 | { | ||
| 320 | fatal = 1; | ||
| 321 | goto err; | ||
| 322 | } | ||
| 323 | else if (r == 0 || (!ret && !len)) | ||
| 324 | goto err; | ||
| 325 | else if (!ret && !(s->session_ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_LOOKUP)) | ||
| 326 | #else | ||
| 327 | if (len == 0) | ||
| 328 | goto err; | ||
| 282 | if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_LOOKUP)) | 329 | if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_LOOKUP)) |
| 330 | #endif | ||
| 283 | { | 331 | { |
| 332 | SSL_SESSION data; | ||
| 333 | data.ssl_version=s->version; | ||
| 334 | data.session_id_length=len; | ||
| 335 | if (len == 0) | ||
| 336 | return 0; | ||
| 337 | memcpy(data.session_id,session_id,len); | ||
| 284 | CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX); | 338 | CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX); |
| 285 | ret=(SSL_SESSION *)lh_retrieve(s->ctx->sessions,&data); | 339 | ret=(SSL_SESSION *)lh_retrieve(s->ctx->sessions,&data); |
| 286 | if (ret != NULL) | 340 | if (ret != NULL) |
| @@ -322,33 +376,35 @@ int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len) | |||
| 322 | 376 | ||
| 323 | /* Now ret is non-NULL, and we own one of its reference counts. */ | 377 | /* Now ret is non-NULL, and we own one of its reference counts. */ |
| 324 | 378 | ||
| 325 | if((s->verify_mode&SSL_VERIFY_PEER) | 379 | if (ret->sid_ctx_length != s->sid_ctx_length |
| 326 | && (!s->sid_ctx_length || ret->sid_ctx_length != s->sid_ctx_length | 380 | || memcmp(ret->sid_ctx,s->sid_ctx,ret->sid_ctx_length)) |
| 327 | || memcmp(ret->sid_ctx,s->sid_ctx,ret->sid_ctx_length))) | 381 | { |
| 328 | { | ||
| 329 | /* We've found the session named by the client, but we don't | 382 | /* We've found the session named by the client, but we don't |
| 330 | * want to use it in this context. */ | 383 | * want to use it in this context. */ |
| 331 | |||
| 332 | if (s->sid_ctx_length == 0) | ||
| 333 | { | ||
| 334 | /* application should have used SSL[_CTX]_set_session_id_context | ||
| 335 | * -- we could tolerate this and just pretend we never heard | ||
| 336 | * of this session, but then applications could effectively | ||
| 337 | * disable the session cache by accident without anyone noticing */ | ||
| 338 | 384 | ||
| 339 | SSLerr(SSL_F_SSL_GET_PREV_SESSION,SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED); | ||
| 340 | fatal = 1; | ||
| 341 | goto err; | ||
| 342 | } | ||
| 343 | else | ||
| 344 | { | ||
| 345 | #if 0 /* The client cannot always know when a session is not appropriate, | 385 | #if 0 /* The client cannot always know when a session is not appropriate, |
| 346 | * so we shouldn't generate an error message. */ | 386 | * so we shouldn't generate an error message. */ |
| 347 | 387 | ||
| 348 | SSLerr(SSL_F_SSL_GET_PREV_SESSION,SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT); | 388 | SSLerr(SSL_F_SSL_GET_PREV_SESSION,SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT); |
| 349 | #endif | 389 | #endif |
| 350 | goto err; /* treat like cache miss */ | 390 | goto err; /* treat like cache miss */ |
| 351 | } | 391 | } |
| 392 | |||
| 393 | if((s->verify_mode & SSL_VERIFY_PEER) && s->sid_ctx_length == 0) | ||
| 394 | { | ||
| 395 | /* We can't be sure if this session is being used out of | ||
| 396 | * context, which is especially important for SSL_VERIFY_PEER. | ||
| 397 | * The application should have used SSL[_CTX]_set_session_id_context. | ||
| 398 | * | ||
| 399 | * For this error case, we generate an error instead of treating | ||
| 400 | * the event like a cache miss (otherwise it would be easy for | ||
| 401 | * applications to effectively disable the session cache by | ||
| 402 | * accident without anyone noticing). | ||
| 403 | */ | ||
| 404 | |||
| 405 | SSLerr(SSL_F_SSL_GET_PREV_SESSION,SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED); | ||
| 406 | fatal = 1; | ||
| 407 | goto err; | ||
| 352 | } | 408 | } |
| 353 | 409 | ||
| 354 | if (ret->cipher == NULL) | 410 | if (ret->cipher == NULL) |
| @@ -534,6 +590,10 @@ void SSL_SESSION_free(SSL_SESSION *ss) | |||
| 534 | if (ss->sess_cert != NULL) ssl_sess_cert_free(ss->sess_cert); | 590 | if (ss->sess_cert != NULL) ssl_sess_cert_free(ss->sess_cert); |
| 535 | if (ss->peer != NULL) X509_free(ss->peer); | 591 | if (ss->peer != NULL) X509_free(ss->peer); |
| 536 | if (ss->ciphers != NULL) sk_SSL_CIPHER_free(ss->ciphers); | 592 | if (ss->ciphers != NULL) sk_SSL_CIPHER_free(ss->ciphers); |
| 593 | #ifndef OPENSSL_NO_TLSEXT | ||
| 594 | if (ss->tlsext_hostname != NULL) OPENSSL_free(ss->tlsext_hostname); | ||
| 595 | if (ss->tlsext_tick != NULL) OPENSSL_free(ss->tlsext_tick); | ||
| 596 | #endif | ||
| 537 | OPENSSL_cleanse(ss,sizeof(*ss)); | 597 | OPENSSL_cleanse(ss,sizeof(*ss)); |
| 538 | OPENSSL_free(ss); | 598 | OPENSSL_free(ss); |
| 539 | } | 599 | } |
| @@ -568,7 +628,7 @@ int SSL_set_session(SSL *s, SSL_SESSION *session) | |||
| 568 | if (s->kssl_ctx && !s->kssl_ctx->client_princ && | 628 | if (s->kssl_ctx && !s->kssl_ctx->client_princ && |
| 569 | session->krb5_client_princ_len > 0) | 629 | session->krb5_client_princ_len > 0) |
| 570 | { | 630 | { |
| 571 | s->kssl_ctx->client_princ = (char *)malloc(session->krb5_client_princ_len + 1); | 631 | s->kssl_ctx->client_princ = (char *)OPENSSL_malloc(session->krb5_client_princ_len + 1); |
| 572 | memcpy(s->kssl_ctx->client_princ,session->krb5_client_princ, | 632 | memcpy(s->kssl_ctx->client_princ,session->krb5_client_princ, |
| 573 | session->krb5_client_princ_len); | 633 | session->krb5_client_princ_len); |
| 574 | s->kssl_ctx->client_princ[session->krb5_client_princ_len] = '\0'; | 634 | s->kssl_ctx->client_princ[session->krb5_client_princ_len] = '\0'; |
| @@ -753,3 +813,72 @@ static void SSL_SESSION_list_add(SSL_CTX *ctx, SSL_SESSION *s) | |||
| 753 | } | 813 | } |
| 754 | } | 814 | } |
| 755 | 815 | ||
| 816 | void SSL_CTX_sess_set_new_cb(SSL_CTX *ctx, | ||
| 817 | int (*cb)(struct ssl_st *ssl,SSL_SESSION *sess)) | ||
| 818 | { | ||
| 819 | ctx->new_session_cb=cb; | ||
| 820 | } | ||
| 821 | |||
| 822 | int (*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx))(SSL *ssl, SSL_SESSION *sess) | ||
| 823 | { | ||
| 824 | return ctx->new_session_cb; | ||
| 825 | } | ||
| 826 | |||
| 827 | void SSL_CTX_sess_set_remove_cb(SSL_CTX *ctx, | ||
| 828 | void (*cb)(SSL_CTX *ctx,SSL_SESSION *sess)) | ||
| 829 | { | ||
| 830 | ctx->remove_session_cb=cb; | ||
| 831 | } | ||
| 832 | |||
| 833 | void (*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx))(SSL_CTX * ctx,SSL_SESSION *sess) | ||
| 834 | { | ||
| 835 | return ctx->remove_session_cb; | ||
| 836 | } | ||
| 837 | |||
| 838 | void SSL_CTX_sess_set_get_cb(SSL_CTX *ctx, | ||
| 839 | SSL_SESSION *(*cb)(struct ssl_st *ssl, | ||
| 840 | unsigned char *data,int len,int *copy)) | ||
| 841 | { | ||
| 842 | ctx->get_session_cb=cb; | ||
| 843 | } | ||
| 844 | |||
| 845 | SSL_SESSION * (*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx))(SSL *ssl, | ||
| 846 | unsigned char *data,int len,int *copy) | ||
| 847 | { | ||
| 848 | return ctx->get_session_cb; | ||
| 849 | } | ||
| 850 | |||
| 851 | void SSL_CTX_set_info_callback(SSL_CTX *ctx, | ||
| 852 | void (*cb)(const SSL *ssl,int type,int val)) | ||
| 853 | { | ||
| 854 | ctx->info_callback=cb; | ||
| 855 | } | ||
| 856 | |||
| 857 | void (*SSL_CTX_get_info_callback(SSL_CTX *ctx))(const SSL *ssl,int type,int val) | ||
| 858 | { | ||
| 859 | return ctx->info_callback; | ||
| 860 | } | ||
| 861 | |||
| 862 | void SSL_CTX_set_client_cert_cb(SSL_CTX *ctx, | ||
| 863 | int (*cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey)) | ||
| 864 | { | ||
| 865 | ctx->client_cert_cb=cb; | ||
| 866 | } | ||
| 867 | |||
| 868 | int (*SSL_CTX_get_client_cert_cb(SSL_CTX *ctx))(SSL * ssl, X509 ** x509 , EVP_PKEY **pkey) | ||
| 869 | { | ||
| 870 | return ctx->client_cert_cb; | ||
| 871 | } | ||
| 872 | |||
| 873 | void SSL_CTX_set_cookie_generate_cb(SSL_CTX *ctx, | ||
| 874 | int (*cb)(SSL *ssl, unsigned char *cookie, unsigned int *cookie_len)) | ||
| 875 | { | ||
| 876 | ctx->app_gen_cookie_cb=cb; | ||
| 877 | } | ||
| 878 | |||
| 879 | void SSL_CTX_set_cookie_verify_cb(SSL_CTX *ctx, | ||
| 880 | int (*cb)(SSL *ssl, unsigned char *cookie, unsigned int cookie_len)) | ||
| 881 | { | ||
| 882 | ctx->app_verify_cookie_cb=cb; | ||
| 883 | } | ||
| 884 | |||
diff --git a/src/lib/libssl/ssl_stat.c b/src/lib/libssl/ssl_stat.c index b16d253081..73b02509d4 100644 --- a/src/lib/libssl/ssl_stat.c +++ b/src/lib/libssl/ssl_stat.c | |||
| @@ -127,6 +127,8 @@ case SSL3_ST_CR_KEY_EXCH_A: str="SSLv3 read server key exchange A"; break; | |||
| 127 | case SSL3_ST_CR_KEY_EXCH_B: str="SSLv3 read server key exchange B"; break; | 127 | case SSL3_ST_CR_KEY_EXCH_B: str="SSLv3 read server key exchange B"; break; |
| 128 | case SSL3_ST_CR_CERT_REQ_A: str="SSLv3 read server certificate request A"; break; | 128 | case SSL3_ST_CR_CERT_REQ_A: str="SSLv3 read server certificate request A"; break; |
| 129 | case SSL3_ST_CR_CERT_REQ_B: str="SSLv3 read server certificate request B"; break; | 129 | case SSL3_ST_CR_CERT_REQ_B: str="SSLv3 read server certificate request B"; break; |
| 130 | case SSL3_ST_CR_SESSION_TICKET_A: str="SSLv3 read server session ticket A";break; | ||
| 131 | case SSL3_ST_CR_SESSION_TICKET_B: str="SSLv3 read server session ticket B";break; | ||
| 130 | case SSL3_ST_CR_SRVR_DONE_A: str="SSLv3 read server done A"; break; | 132 | case SSL3_ST_CR_SRVR_DONE_A: str="SSLv3 read server done A"; break; |
| 131 | case SSL3_ST_CR_SRVR_DONE_B: str="SSLv3 read server done B"; break; | 133 | case SSL3_ST_CR_SRVR_DONE_B: str="SSLv3 read server done B"; break; |
| 132 | case SSL3_ST_CW_CERT_A: str="SSLv3 write client certificate A"; break; | 134 | case SSL3_ST_CW_CERT_A: str="SSLv3 write client certificate A"; break; |
| @@ -172,6 +174,8 @@ case SSL3_ST_SW_KEY_EXCH_A: str="SSLv3 write key exchange A"; break; | |||
| 172 | case SSL3_ST_SW_KEY_EXCH_B: str="SSLv3 write key exchange B"; break; | 174 | case SSL3_ST_SW_KEY_EXCH_B: str="SSLv3 write key exchange B"; break; |
| 173 | case SSL3_ST_SW_CERT_REQ_A: str="SSLv3 write certificate request A"; break; | 175 | case SSL3_ST_SW_CERT_REQ_A: str="SSLv3 write certificate request A"; break; |
| 174 | case SSL3_ST_SW_CERT_REQ_B: str="SSLv3 write certificate request B"; break; | 176 | case SSL3_ST_SW_CERT_REQ_B: str="SSLv3 write certificate request B"; break; |
| 177 | case SSL3_ST_SW_SESSION_TICKET_A: str="SSLv3 write session ticket A"; break; | ||
| 178 | case SSL3_ST_SW_SESSION_TICKET_B: str="SSLv3 write session ticket B"; break; | ||
| 175 | case SSL3_ST_SW_SRVR_DONE_A: str="SSLv3 write server done A"; break; | 179 | case SSL3_ST_SW_SRVR_DONE_A: str="SSLv3 write server done A"; break; |
| 176 | case SSL3_ST_SW_SRVR_DONE_B: str="SSLv3 write server done B"; break; | 180 | case SSL3_ST_SW_SRVR_DONE_B: str="SSLv3 write server done B"; break; |
| 177 | case SSL3_ST_SR_CERT_A: str="SSLv3 read client certificate A"; break; | 181 | case SSL3_ST_SR_CERT_A: str="SSLv3 read client certificate A"; break; |
diff --git a/src/lib/libssl/ssl_txt.c b/src/lib/libssl/ssl_txt.c index 8655a31333..06b86750fd 100644 --- a/src/lib/libssl/ssl_txt.c +++ b/src/lib/libssl/ssl_txt.c | |||
| @@ -81,7 +81,7 @@ int SSL_SESSION_print_fp(FILE *fp, const SSL_SESSION *x) | |||
| 81 | int SSL_SESSION_print(BIO *bp, const SSL_SESSION *x) | 81 | int SSL_SESSION_print(BIO *bp, const SSL_SESSION *x) |
| 82 | { | 82 | { |
| 83 | unsigned int i; | 83 | unsigned int i; |
| 84 | char *s; | 84 | const char *s; |
| 85 | 85 | ||
| 86 | if (x == NULL) goto err; | 86 | if (x == NULL) goto err; |
| 87 | if (BIO_puts(bp,"SSL-Session:\n") <= 0) goto err; | 87 | if (BIO_puts(bp,"SSL-Session:\n") <= 0) goto err; |
| @@ -151,9 +151,25 @@ int SSL_SESSION_print(BIO *bp, const SSL_SESSION *x) | |||
| 151 | if (BIO_printf(bp,"%02X",x->krb5_client_princ[i]) <= 0) goto err; | 151 | if (BIO_printf(bp,"%02X",x->krb5_client_princ[i]) <= 0) goto err; |
| 152 | } | 152 | } |
| 153 | #endif /* OPENSSL_NO_KRB5 */ | 153 | #endif /* OPENSSL_NO_KRB5 */ |
| 154 | #ifndef OPENSSL_NO_TLSEXT | ||
| 155 | if (x->tlsext_tick_lifetime_hint) | ||
| 156 | { | ||
| 157 | if (BIO_printf(bp, | ||
| 158 | "\n TLS session ticket lifetime hint: %ld (seconds)", | ||
| 159 | x->tlsext_tick_lifetime_hint) <=0) | ||
| 160 | goto err; | ||
| 161 | } | ||
| 162 | if (x->tlsext_tick) | ||
| 163 | { | ||
| 164 | if (BIO_puts(bp, "\n TLS session ticket:\n") <= 0) goto err; | ||
| 165 | if (BIO_dump_indent(bp, (char *)x->tlsext_tick, x->tlsext_ticklen, 4) <= 0) | ||
| 166 | goto err; | ||
| 167 | } | ||
| 168 | #endif | ||
| 169 | #ifndef OPENSSL_NO_COMP | ||
| 154 | if (x->compress_meth != 0) | 170 | if (x->compress_meth != 0) |
| 155 | { | 171 | { |
| 156 | SSL_COMP *comp; | 172 | SSL_COMP *comp = NULL; |
| 157 | 173 | ||
| 158 | ssl_cipher_get_evp(x,NULL,NULL,&comp); | 174 | ssl_cipher_get_evp(x,NULL,NULL,&comp); |
| 159 | if (comp == NULL) | 175 | if (comp == NULL) |
| @@ -165,6 +181,7 @@ int SSL_SESSION_print(BIO *bp, const SSL_SESSION *x) | |||
| 165 | if (BIO_printf(bp,"\n Compression: %d (%s)", comp->id,comp->method->name) <= 0) goto err; | 181 | if (BIO_printf(bp,"\n Compression: %d (%s)", comp->id,comp->method->name) <= 0) goto err; |
| 166 | } | 182 | } |
| 167 | } | 183 | } |
| 184 | #endif | ||
| 168 | if (x->time != 0L) | 185 | if (x->time != 0L) |
| 169 | { | 186 | { |
| 170 | if (BIO_printf(bp, "\n Start Time: %ld",x->time) <= 0) goto err; | 187 | if (BIO_printf(bp, "\n Start Time: %ld",x->time) <= 0) goto err; |
diff --git a/src/lib/libssl/t1_clnt.c b/src/lib/libssl/t1_clnt.c index 57205fb429..4d1e198cdc 100644 --- a/src/lib/libssl/t1_clnt.c +++ b/src/lib/libssl/t1_clnt.c | |||
| @@ -72,26 +72,8 @@ static SSL_METHOD *tls1_get_client_method(int ver) | |||
| 72 | return(NULL); | 72 | return(NULL); |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | SSL_METHOD *TLSv1_client_method(void) | 75 | IMPLEMENT_tls1_meth_func(TLSv1_client_method, |
| 76 | { | 76 | ssl_undefined_function, |
| 77 | static int init=1; | 77 | ssl3_connect, |
| 78 | static SSL_METHOD TLSv1_client_data; | 78 | tls1_get_client_method) |
| 79 | |||
| 80 | if (init) | ||
| 81 | { | ||
| 82 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD); | ||
| 83 | |||
| 84 | if (init) | ||
| 85 | { | ||
| 86 | memcpy((char *)&TLSv1_client_data,(char *)tlsv1_base_method(), | ||
| 87 | sizeof(SSL_METHOD)); | ||
| 88 | TLSv1_client_data.ssl_connect=ssl3_connect; | ||
| 89 | TLSv1_client_data.get_ssl_method=tls1_get_client_method; | ||
| 90 | init=0; | ||
| 91 | } | ||
| 92 | |||
| 93 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD); | ||
| 94 | } | ||
| 95 | return(&TLSv1_client_data); | ||
| 96 | } | ||
| 97 | 79 | ||
diff --git a/src/lib/libssl/t1_enc.c b/src/lib/libssl/t1_enc.c index 2c6246abf5..ed5a4a7255 100644 --- a/src/lib/libssl/t1_enc.c +++ b/src/lib/libssl/t1_enc.c | |||
| @@ -115,7 +115,6 @@ | |||
| 115 | #include <openssl/evp.h> | 115 | #include <openssl/evp.h> |
| 116 | #include <openssl/hmac.h> | 116 | #include <openssl/hmac.h> |
| 117 | #include <openssl/md5.h> | 117 | #include <openssl/md5.h> |
| 118 | #include <openssl/fips.h> | ||
| 119 | 118 | ||
| 120 | static void tls1_P_hash(const EVP_MD *md, const unsigned char *sec, | 119 | static void tls1_P_hash(const EVP_MD *md, const unsigned char *sec, |
| 121 | int sec_len, unsigned char *seed, int seed_len, | 120 | int sec_len, unsigned char *seed, int seed_len, |
| @@ -132,8 +131,6 @@ static void tls1_P_hash(const EVP_MD *md, const unsigned char *sec, | |||
| 132 | 131 | ||
| 133 | HMAC_CTX_init(&ctx); | 132 | HMAC_CTX_init(&ctx); |
| 134 | HMAC_CTX_init(&ctx_tmp); | 133 | HMAC_CTX_init(&ctx_tmp); |
| 135 | HMAC_CTX_set_flags(&ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW); | ||
| 136 | HMAC_CTX_set_flags(&ctx_tmp, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW); | ||
| 137 | HMAC_Init_ex(&ctx,sec,sec_len,md, NULL); | 134 | HMAC_Init_ex(&ctx,sec,sec_len,md, NULL); |
| 138 | HMAC_Init_ex(&ctx_tmp,sec,sec_len,md, NULL); | 135 | HMAC_Init_ex(&ctx_tmp,sec,sec_len,md, NULL); |
| 139 | HMAC_Update(&ctx,seed,seed_len); | 136 | HMAC_Update(&ctx,seed,seed_len); |
| @@ -180,6 +177,7 @@ static void tls1_PRF(const EVP_MD *md5, const EVP_MD *sha1, | |||
| 180 | S2= &(sec[len]); | 177 | S2= &(sec[len]); |
| 181 | len+=(slen&1); /* add for odd, make longer */ | 178 | len+=(slen&1); /* add for odd, make longer */ |
| 182 | 179 | ||
| 180 | |||
| 183 | tls1_P_hash(md5 ,S1,len,label,label_len,out1,olen); | 181 | tls1_P_hash(md5 ,S1,len,label,label_len,out1,olen); |
| 184 | tls1_P_hash(sha1,S2,len,label,label_len,out2,olen); | 182 | tls1_P_hash(sha1,S2,len,label,label_len,out2,olen); |
| 185 | 183 | ||
| @@ -233,7 +231,9 @@ int tls1_change_cipher_state(SSL *s, int which) | |||
| 233 | int client_write; | 231 | int client_write; |
| 234 | EVP_CIPHER_CTX *dd; | 232 | EVP_CIPHER_CTX *dd; |
| 235 | const EVP_CIPHER *c; | 233 | const EVP_CIPHER *c; |
| 234 | #ifndef OPENSSL_NO_COMP | ||
| 236 | const SSL_COMP *comp; | 235 | const SSL_COMP *comp; |
| 236 | #endif | ||
| 237 | const EVP_MD *m; | 237 | const EVP_MD *m; |
| 238 | int is_export,n,i,j,k,exp_label_len,cl; | 238 | int is_export,n,i,j,k,exp_label_len,cl; |
| 239 | int reuse_dd = 0; | 239 | int reuse_dd = 0; |
| @@ -241,7 +241,9 @@ int tls1_change_cipher_state(SSL *s, int which) | |||
| 241 | is_export=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher); | 241 | is_export=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher); |
| 242 | c=s->s3->tmp.new_sym_enc; | 242 | c=s->s3->tmp.new_sym_enc; |
| 243 | m=s->s3->tmp.new_hash; | 243 | m=s->s3->tmp.new_hash; |
| 244 | #ifndef OPENSSL_NO_COMP | ||
| 244 | comp=s->s3->tmp.new_compression; | 245 | comp=s->s3->tmp.new_compression; |
| 246 | #endif | ||
| 245 | key_block=s->s3->tmp.key_block; | 247 | key_block=s->s3->tmp.key_block; |
| 246 | 248 | ||
| 247 | #ifdef KSSL_DEBUG | 249 | #ifdef KSSL_DEBUG |
| @@ -265,8 +267,12 @@ int tls1_change_cipher_state(SSL *s, int which) | |||
| 265 | reuse_dd = 1; | 267 | reuse_dd = 1; |
| 266 | else if ((s->enc_read_ctx=OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL) | 268 | else if ((s->enc_read_ctx=OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL) |
| 267 | goto err; | 269 | goto err; |
| 270 | else | ||
| 271 | /* make sure it's intialized in case we exit later with an error */ | ||
| 272 | EVP_CIPHER_CTX_init(s->enc_read_ctx); | ||
| 268 | dd= s->enc_read_ctx; | 273 | dd= s->enc_read_ctx; |
| 269 | s->read_hash=m; | 274 | s->read_hash=m; |
| 275 | #ifndef OPENSSL_NO_COMP | ||
| 270 | if (s->expand != NULL) | 276 | if (s->expand != NULL) |
| 271 | { | 277 | { |
| 272 | COMP_CTX_free(s->expand); | 278 | COMP_CTX_free(s->expand); |
| @@ -286,7 +292,10 @@ int tls1_change_cipher_state(SSL *s, int which) | |||
| 286 | if (s->s3->rrec.comp == NULL) | 292 | if (s->s3->rrec.comp == NULL) |
| 287 | goto err; | 293 | goto err; |
| 288 | } | 294 | } |
| 289 | memset(&(s->s3->read_sequence[0]),0,8); | 295 | #endif |
| 296 | /* this is done by dtls1_reset_seq_numbers for DTLS1_VERSION */ | ||
| 297 | if (s->version != DTLS1_VERSION) | ||
| 298 | memset(&(s->s3->read_sequence[0]),0,8); | ||
| 290 | mac_secret= &(s->s3->read_mac_secret[0]); | 299 | mac_secret= &(s->s3->read_mac_secret[0]); |
| 291 | } | 300 | } |
| 292 | else | 301 | else |
| @@ -295,12 +304,12 @@ int tls1_change_cipher_state(SSL *s, int which) | |||
| 295 | reuse_dd = 1; | 304 | reuse_dd = 1; |
| 296 | else if ((s->enc_write_ctx=OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL) | 305 | else if ((s->enc_write_ctx=OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL) |
| 297 | goto err; | 306 | goto err; |
| 298 | if ((s->enc_write_ctx == NULL) && | 307 | else |
| 299 | ((s->enc_write_ctx=(EVP_CIPHER_CTX *) | 308 | /* make sure it's intialized in case we exit later with an error */ |
| 300 | OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL)) | 309 | EVP_CIPHER_CTX_init(s->enc_write_ctx); |
| 301 | goto err; | ||
| 302 | dd= s->enc_write_ctx; | 310 | dd= s->enc_write_ctx; |
| 303 | s->write_hash=m; | 311 | s->write_hash=m; |
| 312 | #ifndef OPENSSL_NO_COMP | ||
| 304 | if (s->compress != NULL) | 313 | if (s->compress != NULL) |
| 305 | { | 314 | { |
| 306 | COMP_CTX_free(s->compress); | 315 | COMP_CTX_free(s->compress); |
| @@ -315,13 +324,15 @@ int tls1_change_cipher_state(SSL *s, int which) | |||
| 315 | goto err2; | 324 | goto err2; |
| 316 | } | 325 | } |
| 317 | } | 326 | } |
| 318 | memset(&(s->s3->write_sequence[0]),0,8); | 327 | #endif |
| 328 | /* this is done by dtls1_reset_seq_numbers for DTLS1_VERSION */ | ||
| 329 | if (s->version != DTLS1_VERSION) | ||
| 330 | memset(&(s->s3->write_sequence[0]),0,8); | ||
| 319 | mac_secret= &(s->s3->write_mac_secret[0]); | 331 | mac_secret= &(s->s3->write_mac_secret[0]); |
| 320 | } | 332 | } |
| 321 | 333 | ||
| 322 | if (reuse_dd) | 334 | if (reuse_dd) |
| 323 | EVP_CIPHER_CTX_cleanup(dd); | 335 | EVP_CIPHER_CTX_cleanup(dd); |
| 324 | EVP_CIPHER_CTX_init(dd); | ||
| 325 | 336 | ||
| 326 | p=s->s3->tmp.key_block; | 337 | p=s->s3->tmp.key_block; |
| 327 | i=EVP_MD_size(m); | 338 | i=EVP_MD_size(m); |
| @@ -503,7 +514,7 @@ printf("\nkey block\n"); | |||
| 503 | #endif | 514 | #endif |
| 504 | } | 515 | } |
| 505 | } | 516 | } |
| 506 | 517 | ||
| 507 | return(1); | 518 | return(1); |
| 508 | err: | 519 | err: |
| 509 | SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK,ERR_R_MALLOC_FAILURE); | 520 | SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK,ERR_R_MALLOC_FAILURE); |
| @@ -618,7 +629,15 @@ int tls1_enc(SSL *s, int send) | |||
| 618 | { | 629 | { |
| 619 | ii=i=rec->data[l-1]; /* padding_length */ | 630 | ii=i=rec->data[l-1]; /* padding_length */ |
| 620 | i++; | 631 | i++; |
| 621 | if (s->options&SSL_OP_TLS_BLOCK_PADDING_BUG) | 632 | /* NB: if compression is in operation the first packet |
| 633 | * may not be of even length so the padding bug check | ||
| 634 | * cannot be performed. This bug workaround has been | ||
| 635 | * around since SSLeay so hopefully it is either fixed | ||
| 636 | * now or no buggy implementation supports compression | ||
| 637 | * [steve] | ||
| 638 | */ | ||
| 639 | if ( (s->options&SSL_OP_TLS_BLOCK_PADDING_BUG) | ||
| 640 | && !s->expand) | ||
| 622 | { | 641 | { |
| 623 | /* First packet is even in size, so check */ | 642 | /* First packet is even in size, so check */ |
| 624 | if ((memcmp(s->s3->read_sequence, | 643 | if ((memcmp(s->s3->read_sequence, |
| @@ -719,15 +738,35 @@ int tls1_mac(SSL *ssl, unsigned char *md, int send) | |||
| 719 | md_size=EVP_MD_size(hash); | 738 | md_size=EVP_MD_size(hash); |
| 720 | 739 | ||
| 721 | buf[0]=rec->type; | 740 | buf[0]=rec->type; |
| 722 | buf[1]=TLS1_VERSION_MAJOR; | 741 | if (ssl->version == DTLS1_VERSION && ssl->client_version == DTLS1_BAD_VER) |
| 723 | buf[2]=TLS1_VERSION_MINOR; | 742 | { |
| 743 | buf[1]=TLS1_VERSION_MAJOR; | ||
| 744 | buf[2]=TLS1_VERSION_MINOR; | ||
| 745 | } | ||
| 746 | else { | ||
| 747 | buf[1]=(unsigned char)(ssl->version>>8); | ||
| 748 | buf[2]=(unsigned char)(ssl->version); | ||
| 749 | } | ||
| 750 | |||
| 724 | buf[3]=rec->length>>8; | 751 | buf[3]=rec->length>>8; |
| 725 | buf[4]=rec->length&0xff; | 752 | buf[4]=rec->length&0xff; |
| 726 | 753 | ||
| 727 | /* I should fix this up TLS TLS TLS TLS TLS XXXXXXXX */ | 754 | /* I should fix this up TLS TLS TLS TLS TLS XXXXXXXX */ |
| 728 | HMAC_CTX_init(&hmac); | 755 | HMAC_CTX_init(&hmac); |
| 729 | HMAC_Init_ex(&hmac,mac_sec,EVP_MD_size(hash),hash,NULL); | 756 | HMAC_Init_ex(&hmac,mac_sec,EVP_MD_size(hash),hash,NULL); |
| 730 | HMAC_Update(&hmac,seq,8); | 757 | |
| 758 | if (ssl->version == DTLS1_VERSION && ssl->client_version != DTLS1_BAD_VER) | ||
| 759 | { | ||
| 760 | unsigned char dtlsseq[8],*p=dtlsseq; | ||
| 761 | |||
| 762 | s2n(send?ssl->d1->w_epoch:ssl->d1->r_epoch, p); | ||
| 763 | memcpy (p,&seq[2],6); | ||
| 764 | |||
| 765 | HMAC_Update(&hmac,dtlsseq,8); | ||
| 766 | } | ||
| 767 | else | ||
| 768 | HMAC_Update(&hmac,seq,8); | ||
| 769 | |||
| 731 | HMAC_Update(&hmac,buf,5); | 770 | HMAC_Update(&hmac,buf,5); |
| 732 | HMAC_Update(&hmac,rec->input,rec->length); | 771 | HMAC_Update(&hmac,rec->input,rec->length); |
| 733 | HMAC_Final(&hmac,md,&md_size); | 772 | HMAC_Final(&hmac,md,&md_size); |
| @@ -744,10 +783,13 @@ printf("rec="); | |||
| 744 | {unsigned int z; for (z=0; z<rec->length; z++) printf("%02X ",buf[z]); printf("\n"); } | 783 | {unsigned int z; for (z=0; z<rec->length; z++) printf("%02X ",buf[z]); printf("\n"); } |
| 745 | #endif | 784 | #endif |
| 746 | 785 | ||
| 747 | for (i=7; i>=0; i--) | 786 | if ( SSL_version(ssl) != DTLS1_VERSION) |
| 748 | { | 787 | { |
| 749 | ++seq[i]; | 788 | for (i=7; i>=0; i--) |
| 750 | if (seq[i] != 0) break; | 789 | { |
| 790 | ++seq[i]; | ||
| 791 | if (seq[i] != 0) break; | ||
| 792 | } | ||
| 751 | } | 793 | } |
| 752 | 794 | ||
| 753 | #ifdef TLS_DEBUG | 795 | #ifdef TLS_DEBUG |
| @@ -810,6 +852,8 @@ int tls1_alert_code(int code) | |||
| 810 | case SSL_AD_INTERNAL_ERROR: return(TLS1_AD_INTERNAL_ERROR); | 852 | case SSL_AD_INTERNAL_ERROR: return(TLS1_AD_INTERNAL_ERROR); |
| 811 | case SSL_AD_USER_CANCELLED: return(TLS1_AD_USER_CANCELLED); | 853 | case SSL_AD_USER_CANCELLED: return(TLS1_AD_USER_CANCELLED); |
| 812 | case SSL_AD_NO_RENEGOTIATION: return(TLS1_AD_NO_RENEGOTIATION); | 854 | case SSL_AD_NO_RENEGOTIATION: return(TLS1_AD_NO_RENEGOTIATION); |
| 855 | case DTLS1_AD_MISSING_HANDSHAKE_MESSAGE: return | ||
| 856 | (DTLS1_AD_MISSING_HANDSHAKE_MESSAGE); | ||
| 813 | default: return(-1); | 857 | default: return(-1); |
| 814 | } | 858 | } |
| 815 | } | 859 | } |
diff --git a/src/lib/libssl/t1_lib.c b/src/lib/libssl/t1_lib.c index ca6c03d5af..35f04afa4a 100644 --- a/src/lib/libssl/t1_lib.c +++ b/src/lib/libssl/t1_lib.c | |||
| @@ -58,13 +58,20 @@ | |||
| 58 | 58 | ||
| 59 | #include <stdio.h> | 59 | #include <stdio.h> |
| 60 | #include <openssl/objects.h> | 60 | #include <openssl/objects.h> |
| 61 | #include <openssl/evp.h> | ||
| 62 | #include <openssl/hmac.h> | ||
| 63 | #include <openssl/ocsp.h> | ||
| 61 | #include "ssl_locl.h" | 64 | #include "ssl_locl.h" |
| 62 | 65 | ||
| 63 | const char *tls1_version_str="TLSv1" OPENSSL_VERSION_PTEXT; | 66 | const char tls1_version_str[]="TLSv1" OPENSSL_VERSION_PTEXT; |
| 64 | 67 | ||
| 65 | static long tls1_default_timeout(void); | 68 | #ifndef OPENSSL_NO_TLSEXT |
| 69 | static int tls_decrypt_ticket(SSL *s, const unsigned char *tick, int ticklen, | ||
| 70 | const unsigned char *sess_id, int sesslen, | ||
| 71 | SSL_SESSION **psess); | ||
| 72 | #endif | ||
| 66 | 73 | ||
| 67 | static SSL3_ENC_METHOD TLSv1_enc_data={ | 74 | SSL3_ENC_METHOD TLSv1_enc_data={ |
| 68 | tls1_enc, | 75 | tls1_enc, |
| 69 | tls1_mac, | 76 | tls1_mac, |
| 70 | tls1_setup_key_block, | 77 | tls1_setup_key_block, |
| @@ -78,45 +85,17 @@ static SSL3_ENC_METHOD TLSv1_enc_data={ | |||
| 78 | tls1_alert_code, | 85 | tls1_alert_code, |
| 79 | }; | 86 | }; |
| 80 | 87 | ||
| 81 | static SSL_METHOD TLSv1_data= { | 88 | long tls1_default_timeout(void) |
| 82 | TLS1_VERSION, | ||
| 83 | tls1_new, | ||
| 84 | tls1_clear, | ||
| 85 | tls1_free, | ||
| 86 | ssl_undefined_function, | ||
| 87 | ssl_undefined_function, | ||
| 88 | ssl3_read, | ||
| 89 | ssl3_peek, | ||
| 90 | ssl3_write, | ||
| 91 | ssl3_shutdown, | ||
| 92 | ssl3_renegotiate, | ||
| 93 | ssl3_renegotiate_check, | ||
| 94 | ssl3_ctrl, | ||
| 95 | ssl3_ctx_ctrl, | ||
| 96 | ssl3_get_cipher_by_char, | ||
| 97 | ssl3_put_cipher_by_char, | ||
| 98 | ssl3_pending, | ||
| 99 | ssl3_num_ciphers, | ||
| 100 | ssl3_get_cipher, | ||
| 101 | ssl_bad_method, | ||
| 102 | tls1_default_timeout, | ||
| 103 | &TLSv1_enc_data, | ||
| 104 | ssl_undefined_function, | ||
| 105 | ssl3_callback_ctrl, | ||
| 106 | ssl3_ctx_callback_ctrl, | ||
| 107 | }; | ||
| 108 | |||
| 109 | static long tls1_default_timeout(void) | ||
| 110 | { | 89 | { |
| 111 | /* 2 hours, the 24 hours mentioned in the TLSv1 spec | 90 | /* 2 hours, the 24 hours mentioned in the TLSv1 spec |
| 112 | * is way too long for http, the cache would over fill */ | 91 | * is way too long for http, the cache would over fill */ |
| 113 | return(60*60*2); | 92 | return(60*60*2); |
| 114 | } | 93 | } |
| 115 | 94 | ||
| 116 | SSL_METHOD *tlsv1_base_method(void) | 95 | IMPLEMENT_tls1_meth_func(tlsv1_base_method, |
| 117 | { | 96 | ssl_undefined_function, |
| 118 | return(&TLSv1_data); | 97 | ssl_undefined_function, |
| 119 | } | 98 | ssl_bad_method) |
| 120 | 99 | ||
| 121 | int tls1_new(SSL *s) | 100 | int tls1_new(SSL *s) |
| 122 | { | 101 | { |
| @@ -147,3 +126,751 @@ long tls1_callback_ctrl(SSL *s, int cmd, void *(*fp)()) | |||
| 147 | return(0); | 126 | return(0); |
| 148 | } | 127 | } |
| 149 | #endif | 128 | #endif |
| 129 | |||
| 130 | #ifndef OPENSSL_NO_TLSEXT | ||
| 131 | unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *p, unsigned char *limit) | ||
| 132 | { | ||
| 133 | int extdatalen=0; | ||
| 134 | unsigned char *ret = p; | ||
| 135 | |||
| 136 | ret+=2; | ||
| 137 | |||
| 138 | if (ret>=limit) return NULL; /* this really never occurs, but ... */ | ||
| 139 | |||
| 140 | if (s->tlsext_hostname != NULL) | ||
| 141 | { | ||
| 142 | /* Add TLS extension servername to the Client Hello message */ | ||
| 143 | unsigned long size_str; | ||
| 144 | long lenmax; | ||
| 145 | |||
| 146 | /* check for enough space. | ||
| 147 | 4 for the servername type and entension length | ||
| 148 | 2 for servernamelist length | ||
| 149 | 1 for the hostname type | ||
| 150 | 2 for hostname length | ||
| 151 | + hostname length | ||
| 152 | */ | ||
| 153 | |||
| 154 | if ((lenmax = limit - ret - 9) < 0 | ||
| 155 | || (size_str = strlen(s->tlsext_hostname)) > (unsigned long)lenmax) | ||
| 156 | return NULL; | ||
| 157 | |||
| 158 | /* extension type and length */ | ||
| 159 | s2n(TLSEXT_TYPE_server_name,ret); | ||
| 160 | s2n(size_str+5,ret); | ||
| 161 | |||
| 162 | /* length of servername list */ | ||
| 163 | s2n(size_str+3,ret); | ||
| 164 | |||
| 165 | /* hostname type, length and hostname */ | ||
| 166 | *(ret++) = (unsigned char) TLSEXT_NAMETYPE_host_name; | ||
| 167 | s2n(size_str,ret); | ||
| 168 | memcpy(ret, s->tlsext_hostname, size_str); | ||
| 169 | ret+=size_str; | ||
| 170 | |||
| 171 | } | ||
| 172 | |||
| 173 | if (!(SSL_get_options(s) & SSL_OP_NO_TICKET)) | ||
| 174 | { | ||
| 175 | int ticklen; | ||
| 176 | if (s->session && s->session->tlsext_tick) | ||
| 177 | ticklen = s->session->tlsext_ticklen; | ||
| 178 | else | ||
| 179 | ticklen = 0; | ||
| 180 | /* Check for enough room 2 for extension type, 2 for len | ||
| 181 | * rest for ticket | ||
| 182 | */ | ||
| 183 | if (limit - ret - 4 - ticklen < 0) | ||
| 184 | return NULL; | ||
| 185 | s2n(TLSEXT_TYPE_session_ticket,ret); | ||
| 186 | s2n(ticklen,ret); | ||
| 187 | if (ticklen) | ||
| 188 | { | ||
| 189 | memcpy(ret, s->session->tlsext_tick, ticklen); | ||
| 190 | ret += ticklen; | ||
| 191 | } | ||
| 192 | } | ||
| 193 | |||
| 194 | if (s->tlsext_status_type == TLSEXT_STATUSTYPE_ocsp) | ||
| 195 | { | ||
| 196 | int i; | ||
| 197 | long extlen, idlen, itmp; | ||
| 198 | OCSP_RESPID *id; | ||
| 199 | |||
| 200 | idlen = 0; | ||
| 201 | for (i = 0; i < sk_OCSP_RESPID_num(s->tlsext_ocsp_ids); i++) | ||
| 202 | { | ||
| 203 | id = sk_OCSP_RESPID_value(s->tlsext_ocsp_ids, i); | ||
| 204 | itmp = i2d_OCSP_RESPID(id, NULL); | ||
| 205 | if (itmp <= 0) | ||
| 206 | return NULL; | ||
| 207 | idlen += itmp + 2; | ||
| 208 | } | ||
| 209 | |||
| 210 | if (s->tlsext_ocsp_exts) | ||
| 211 | { | ||
| 212 | extlen = i2d_X509_EXTENSIONS(s->tlsext_ocsp_exts, NULL); | ||
| 213 | if (extlen < 0) | ||
| 214 | return NULL; | ||
| 215 | } | ||
| 216 | else | ||
| 217 | extlen = 0; | ||
| 218 | |||
| 219 | if ((long)(limit - ret - 7 - extlen - idlen) < 0) return NULL; | ||
| 220 | s2n(TLSEXT_TYPE_status_request, ret); | ||
| 221 | if (extlen + idlen > 0xFFF0) | ||
| 222 | return NULL; | ||
| 223 | s2n(extlen + idlen + 5, ret); | ||
| 224 | *(ret++) = TLSEXT_STATUSTYPE_ocsp; | ||
| 225 | s2n(idlen, ret); | ||
| 226 | for (i = 0; i < sk_OCSP_RESPID_num(s->tlsext_ocsp_ids); i++) | ||
| 227 | { | ||
| 228 | /* save position of id len */ | ||
| 229 | unsigned char *q = ret; | ||
| 230 | id = sk_OCSP_RESPID_value(s->tlsext_ocsp_ids, i); | ||
| 231 | /* skip over id len */ | ||
| 232 | ret += 2; | ||
| 233 | itmp = i2d_OCSP_RESPID(id, &ret); | ||
| 234 | /* write id len */ | ||
| 235 | s2n(itmp, q); | ||
| 236 | } | ||
| 237 | s2n(extlen, ret); | ||
| 238 | if (extlen > 0) | ||
| 239 | i2d_X509_EXTENSIONS(s->tlsext_ocsp_exts, &ret); | ||
| 240 | } | ||
| 241 | |||
| 242 | if ((extdatalen = ret-p-2)== 0) | ||
| 243 | return p; | ||
| 244 | |||
| 245 | s2n(extdatalen,p); | ||
| 246 | return ret; | ||
| 247 | } | ||
| 248 | |||
| 249 | unsigned char *ssl_add_serverhello_tlsext(SSL *s, unsigned char *p, unsigned char *limit) | ||
| 250 | { | ||
| 251 | int extdatalen=0; | ||
| 252 | unsigned char *ret = p; | ||
| 253 | |||
| 254 | ret+=2; | ||
| 255 | if (ret>=limit) return NULL; /* this really never occurs, but ... */ | ||
| 256 | |||
| 257 | if (!s->hit && s->servername_done == 1 && s->session->tlsext_hostname != NULL) | ||
| 258 | { | ||
| 259 | if (limit - ret - 4 < 0) return NULL; | ||
| 260 | |||
| 261 | s2n(TLSEXT_TYPE_server_name,ret); | ||
| 262 | s2n(0,ret); | ||
| 263 | } | ||
| 264 | |||
| 265 | if (s->tlsext_ticket_expected | ||
| 266 | && !(SSL_get_options(s) & SSL_OP_NO_TICKET)) | ||
| 267 | { | ||
| 268 | if (limit - ret - 4 < 0) return NULL; | ||
| 269 | s2n(TLSEXT_TYPE_session_ticket,ret); | ||
| 270 | s2n(0,ret); | ||
| 271 | } | ||
| 272 | |||
| 273 | if (s->tlsext_status_expected) | ||
| 274 | { | ||
| 275 | if ((long)(limit - ret - 4) < 0) return NULL; | ||
| 276 | s2n(TLSEXT_TYPE_status_request,ret); | ||
| 277 | s2n(0,ret); | ||
| 278 | } | ||
| 279 | |||
| 280 | if ((extdatalen = ret-p-2)== 0) | ||
| 281 | return p; | ||
| 282 | |||
| 283 | s2n(extdatalen,p); | ||
| 284 | return ret; | ||
| 285 | } | ||
| 286 | |||
| 287 | int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d, int n, int *al) | ||
| 288 | { | ||
| 289 | unsigned short type; | ||
| 290 | unsigned short size; | ||
| 291 | unsigned short len; | ||
| 292 | unsigned char *data = *p; | ||
| 293 | s->servername_done = 0; | ||
| 294 | s->tlsext_status_type = -1; | ||
| 295 | |||
| 296 | if (data >= (d+n-2)) | ||
| 297 | return 1; | ||
| 298 | n2s(data,len); | ||
| 299 | |||
| 300 | if (data > (d+n-len)) | ||
| 301 | return 1; | ||
| 302 | |||
| 303 | while (data <= (d+n-4)) | ||
| 304 | { | ||
| 305 | n2s(data,type); | ||
| 306 | n2s(data,size); | ||
| 307 | |||
| 308 | if (data+size > (d+n)) | ||
| 309 | return 1; | ||
| 310 | |||
| 311 | if (s->tlsext_debug_cb) | ||
| 312 | s->tlsext_debug_cb(s, 0, type, data, size, | ||
| 313 | s->tlsext_debug_arg); | ||
| 314 | /* The servername extension is treated as follows: | ||
| 315 | |||
| 316 | - Only the hostname type is supported with a maximum length of 255. | ||
| 317 | - The servername is rejected if too long or if it contains zeros, | ||
| 318 | in which case an fatal alert is generated. | ||
| 319 | - The servername field is maintained together with the session cache. | ||
| 320 | - When a session is resumed, the servername call back invoked in order | ||
| 321 | to allow the application to position itself to the right context. | ||
| 322 | - The servername is acknowledged if it is new for a session or when | ||
| 323 | it is identical to a previously used for the same session. | ||
| 324 | Applications can control the behaviour. They can at any time | ||
| 325 | set a 'desirable' servername for a new SSL object. This can be the | ||
| 326 | case for example with HTTPS when a Host: header field is received and | ||
| 327 | a renegotiation is requested. In this case, a possible servername | ||
| 328 | presented in the new client hello is only acknowledged if it matches | ||
| 329 | the value of the Host: field. | ||
| 330 | - Applications must use SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION | ||
| 331 | if they provide for changing an explicit servername context for the session, | ||
| 332 | i.e. when the session has been established with a servername extension. | ||
| 333 | - On session reconnect, the servername extension may be absent. | ||
| 334 | |||
| 335 | */ | ||
| 336 | |||
| 337 | if (type == TLSEXT_TYPE_server_name) | ||
| 338 | { | ||
| 339 | unsigned char *sdata; | ||
| 340 | int servname_type; | ||
| 341 | int dsize; | ||
| 342 | |||
| 343 | if (size < 2) | ||
| 344 | { | ||
| 345 | *al = SSL_AD_DECODE_ERROR; | ||
| 346 | return 0; | ||
| 347 | } | ||
| 348 | n2s(data,dsize); | ||
| 349 | size -= 2; | ||
| 350 | if (dsize > size ) | ||
| 351 | { | ||
| 352 | *al = SSL_AD_DECODE_ERROR; | ||
| 353 | return 0; | ||
| 354 | } | ||
| 355 | |||
| 356 | sdata = data; | ||
| 357 | while (dsize > 3) | ||
| 358 | { | ||
| 359 | servname_type = *(sdata++); | ||
| 360 | n2s(sdata,len); | ||
| 361 | dsize -= 3; | ||
| 362 | |||
| 363 | if (len > dsize) | ||
| 364 | { | ||
| 365 | *al = SSL_AD_DECODE_ERROR; | ||
| 366 | return 0; | ||
| 367 | } | ||
| 368 | if (s->servername_done == 0) | ||
| 369 | switch (servname_type) | ||
| 370 | { | ||
| 371 | case TLSEXT_NAMETYPE_host_name: | ||
| 372 | if (s->session->tlsext_hostname == NULL) | ||
| 373 | { | ||
| 374 | if (len > TLSEXT_MAXLEN_host_name || | ||
| 375 | ((s->session->tlsext_hostname = OPENSSL_malloc(len+1)) == NULL)) | ||
| 376 | { | ||
| 377 | *al = TLS1_AD_UNRECOGNIZED_NAME; | ||
| 378 | return 0; | ||
| 379 | } | ||
| 380 | memcpy(s->session->tlsext_hostname, sdata, len); | ||
| 381 | s->session->tlsext_hostname[len]='\0'; | ||
| 382 | if (strlen(s->session->tlsext_hostname) != len) { | ||
| 383 | OPENSSL_free(s->session->tlsext_hostname); | ||
| 384 | s->session->tlsext_hostname = NULL; | ||
| 385 | *al = TLS1_AD_UNRECOGNIZED_NAME; | ||
| 386 | return 0; | ||
| 387 | } | ||
| 388 | s->servername_done = 1; | ||
| 389 | |||
| 390 | } | ||
| 391 | else | ||
| 392 | s->servername_done = strlen(s->session->tlsext_hostname) == len | ||
| 393 | && strncmp(s->session->tlsext_hostname, (char *)sdata, len) == 0; | ||
| 394 | |||
| 395 | break; | ||
| 396 | |||
| 397 | default: | ||
| 398 | break; | ||
| 399 | } | ||
| 400 | |||
| 401 | dsize -= len; | ||
| 402 | } | ||
| 403 | if (dsize != 0) | ||
| 404 | { | ||
| 405 | *al = SSL_AD_DECODE_ERROR; | ||
| 406 | return 0; | ||
| 407 | } | ||
| 408 | |||
| 409 | } | ||
| 410 | else if (type == TLSEXT_TYPE_status_request | ||
| 411 | && s->ctx->tlsext_status_cb) | ||
| 412 | { | ||
| 413 | |||
| 414 | if (size < 5) | ||
| 415 | { | ||
| 416 | *al = SSL_AD_DECODE_ERROR; | ||
| 417 | return 0; | ||
| 418 | } | ||
| 419 | |||
| 420 | s->tlsext_status_type = *data++; | ||
| 421 | size--; | ||
| 422 | if (s->tlsext_status_type == TLSEXT_STATUSTYPE_ocsp) | ||
| 423 | { | ||
| 424 | const unsigned char *sdata; | ||
| 425 | int dsize; | ||
| 426 | /* Read in responder_id_list */ | ||
| 427 | n2s(data,dsize); | ||
| 428 | size -= 2; | ||
| 429 | if (dsize > size ) | ||
| 430 | { | ||
| 431 | *al = SSL_AD_DECODE_ERROR; | ||
| 432 | return 0; | ||
| 433 | } | ||
| 434 | while (dsize > 0) | ||
| 435 | { | ||
| 436 | OCSP_RESPID *id; | ||
| 437 | int idsize; | ||
| 438 | if (dsize < 4) | ||
| 439 | { | ||
| 440 | *al = SSL_AD_DECODE_ERROR; | ||
| 441 | return 0; | ||
| 442 | } | ||
| 443 | n2s(data, idsize); | ||
| 444 | dsize -= 2 + idsize; | ||
| 445 | if (dsize < 0) | ||
| 446 | { | ||
| 447 | *al = SSL_AD_DECODE_ERROR; | ||
| 448 | return 0; | ||
| 449 | } | ||
| 450 | sdata = data; | ||
| 451 | data += idsize; | ||
| 452 | id = d2i_OCSP_RESPID(NULL, | ||
| 453 | &sdata, idsize); | ||
| 454 | if (!id) | ||
| 455 | { | ||
| 456 | *al = SSL_AD_DECODE_ERROR; | ||
| 457 | return 0; | ||
| 458 | } | ||
| 459 | if (data != sdata) | ||
| 460 | { | ||
| 461 | OCSP_RESPID_free(id); | ||
| 462 | *al = SSL_AD_DECODE_ERROR; | ||
| 463 | return 0; | ||
| 464 | } | ||
| 465 | if (!s->tlsext_ocsp_ids | ||
| 466 | && !(s->tlsext_ocsp_ids = | ||
| 467 | sk_OCSP_RESPID_new_null())) | ||
| 468 | { | ||
| 469 | OCSP_RESPID_free(id); | ||
| 470 | *al = SSL_AD_INTERNAL_ERROR; | ||
| 471 | return 0; | ||
| 472 | } | ||
| 473 | if (!sk_OCSP_RESPID_push( | ||
| 474 | s->tlsext_ocsp_ids, id)) | ||
| 475 | { | ||
| 476 | OCSP_RESPID_free(id); | ||
| 477 | *al = SSL_AD_INTERNAL_ERROR; | ||
| 478 | return 0; | ||
| 479 | } | ||
| 480 | } | ||
| 481 | |||
| 482 | /* Read in request_extensions */ | ||
| 483 | n2s(data,dsize); | ||
| 484 | size -= 2; | ||
| 485 | if (dsize > size) | ||
| 486 | { | ||
| 487 | *al = SSL_AD_DECODE_ERROR; | ||
| 488 | return 0; | ||
| 489 | } | ||
| 490 | sdata = data; | ||
| 491 | if (dsize > 0) | ||
| 492 | { | ||
| 493 | s->tlsext_ocsp_exts = | ||
| 494 | d2i_X509_EXTENSIONS(NULL, | ||
| 495 | &sdata, dsize); | ||
| 496 | if (!s->tlsext_ocsp_exts | ||
| 497 | || (data + dsize != sdata)) | ||
| 498 | { | ||
| 499 | *al = SSL_AD_DECODE_ERROR; | ||
| 500 | return 0; | ||
| 501 | } | ||
| 502 | } | ||
| 503 | } | ||
| 504 | /* We don't know what to do with any other type | ||
| 505 | * so ignore it. | ||
| 506 | */ | ||
| 507 | else | ||
| 508 | s->tlsext_status_type = -1; | ||
| 509 | } | ||
| 510 | /* session ticket processed earlier */ | ||
| 511 | |||
| 512 | data+=size; | ||
| 513 | } | ||
| 514 | |||
| 515 | *p = data; | ||
| 516 | return 1; | ||
| 517 | } | ||
| 518 | |||
| 519 | int ssl_parse_serverhello_tlsext(SSL *s, unsigned char **p, unsigned char *d, int n, int *al) | ||
| 520 | { | ||
| 521 | unsigned short type; | ||
| 522 | unsigned short size; | ||
| 523 | unsigned short len; | ||
| 524 | unsigned char *data = *p; | ||
| 525 | |||
| 526 | int tlsext_servername = 0; | ||
| 527 | |||
| 528 | if (data >= (d+n-2)) | ||
| 529 | return 1; | ||
| 530 | |||
| 531 | n2s(data,len); | ||
| 532 | |||
| 533 | while(data <= (d+n-4)) | ||
| 534 | { | ||
| 535 | n2s(data,type); | ||
| 536 | n2s(data,size); | ||
| 537 | |||
| 538 | if (data+size > (d+n)) | ||
| 539 | return 1; | ||
| 540 | |||
| 541 | if (s->tlsext_debug_cb) | ||
| 542 | s->tlsext_debug_cb(s, 1, type, data, size, | ||
| 543 | s->tlsext_debug_arg); | ||
| 544 | |||
| 545 | if (type == TLSEXT_TYPE_server_name) | ||
| 546 | { | ||
| 547 | if (s->tlsext_hostname == NULL || size > 0) | ||
| 548 | { | ||
| 549 | *al = TLS1_AD_UNRECOGNIZED_NAME; | ||
| 550 | return 0; | ||
| 551 | } | ||
| 552 | tlsext_servername = 1; | ||
| 553 | } | ||
| 554 | else if (type == TLSEXT_TYPE_session_ticket) | ||
| 555 | { | ||
| 556 | if ((SSL_get_options(s) & SSL_OP_NO_TICKET) | ||
| 557 | || (size > 0)) | ||
| 558 | { | ||
| 559 | *al = TLS1_AD_UNSUPPORTED_EXTENSION; | ||
| 560 | return 0; | ||
| 561 | } | ||
| 562 | s->tlsext_ticket_expected = 1; | ||
| 563 | } | ||
| 564 | else if (type == TLSEXT_TYPE_status_request) | ||
| 565 | { | ||
| 566 | /* MUST be empty and only sent if we've requested | ||
| 567 | * a status request message. | ||
| 568 | */ | ||
| 569 | if ((s->tlsext_status_type == -1) || (size > 0)) | ||
| 570 | { | ||
| 571 | *al = TLS1_AD_UNSUPPORTED_EXTENSION; | ||
| 572 | return 0; | ||
| 573 | } | ||
| 574 | /* Set flag to expect CertificateStatus message */ | ||
| 575 | s->tlsext_status_expected = 1; | ||
| 576 | } | ||
| 577 | |||
| 578 | data+=size; | ||
| 579 | } | ||
| 580 | |||
| 581 | if (data != d+n) | ||
| 582 | { | ||
| 583 | *al = SSL_AD_DECODE_ERROR; | ||
| 584 | return 0; | ||
| 585 | } | ||
| 586 | |||
| 587 | if (!s->hit && tlsext_servername == 1) | ||
| 588 | { | ||
| 589 | if (s->tlsext_hostname) | ||
| 590 | { | ||
| 591 | if (s->session->tlsext_hostname == NULL) | ||
| 592 | { | ||
| 593 | s->session->tlsext_hostname = BUF_strdup(s->tlsext_hostname); | ||
| 594 | if (!s->session->tlsext_hostname) | ||
| 595 | { | ||
| 596 | *al = SSL_AD_UNRECOGNIZED_NAME; | ||
| 597 | return 0; | ||
| 598 | } | ||
| 599 | } | ||
| 600 | else | ||
| 601 | { | ||
| 602 | *al = SSL_AD_DECODE_ERROR; | ||
| 603 | return 0; | ||
| 604 | } | ||
| 605 | } | ||
| 606 | } | ||
| 607 | |||
| 608 | *p = data; | ||
| 609 | return 1; | ||
| 610 | } | ||
| 611 | |||
| 612 | int ssl_check_clienthello_tlsext(SSL *s) | ||
| 613 | { | ||
| 614 | int ret=SSL_TLSEXT_ERR_NOACK; | ||
| 615 | int al = SSL_AD_UNRECOGNIZED_NAME; | ||
| 616 | |||
| 617 | if (s->ctx != NULL && s->ctx->tlsext_servername_callback != 0) | ||
| 618 | ret = s->ctx->tlsext_servername_callback(s, &al, s->ctx->tlsext_servername_arg); | ||
| 619 | else if (s->initial_ctx != NULL && s->initial_ctx->tlsext_servername_callback != 0) | ||
| 620 | ret = s->initial_ctx->tlsext_servername_callback(s, &al, s->initial_ctx->tlsext_servername_arg); | ||
| 621 | |||
| 622 | /* If status request then ask callback what to do. | ||
| 623 | * Note: this must be called after servername callbacks in case | ||
| 624 | * the certificate has changed. | ||
| 625 | */ | ||
| 626 | if ((s->tlsext_status_type != -1) && s->ctx->tlsext_status_cb) | ||
| 627 | { | ||
| 628 | int r; | ||
| 629 | r = s->ctx->tlsext_status_cb(s, s->ctx->tlsext_status_arg); | ||
| 630 | switch (r) | ||
| 631 | { | ||
| 632 | /* We don't want to send a status request response */ | ||
| 633 | case SSL_TLSEXT_ERR_NOACK: | ||
| 634 | s->tlsext_status_expected = 0; | ||
| 635 | break; | ||
| 636 | /* status request response should be sent */ | ||
| 637 | case SSL_TLSEXT_ERR_OK: | ||
| 638 | if (s->tlsext_ocsp_resp) | ||
| 639 | s->tlsext_status_expected = 1; | ||
| 640 | else | ||
| 641 | s->tlsext_status_expected = 0; | ||
| 642 | break; | ||
| 643 | /* something bad happened */ | ||
| 644 | case SSL_TLSEXT_ERR_ALERT_FATAL: | ||
| 645 | ret = SSL_TLSEXT_ERR_ALERT_FATAL; | ||
| 646 | al = SSL_AD_INTERNAL_ERROR; | ||
| 647 | goto err; | ||
| 648 | } | ||
| 649 | } | ||
| 650 | else | ||
| 651 | s->tlsext_status_expected = 0; | ||
| 652 | err: | ||
| 653 | switch (ret) | ||
| 654 | { | ||
| 655 | case SSL_TLSEXT_ERR_ALERT_FATAL: | ||
| 656 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
| 657 | return -1; | ||
| 658 | |||
| 659 | case SSL_TLSEXT_ERR_ALERT_WARNING: | ||
| 660 | ssl3_send_alert(s,SSL3_AL_WARNING,al); | ||
| 661 | return 1; | ||
| 662 | |||
| 663 | case SSL_TLSEXT_ERR_NOACK: | ||
| 664 | s->servername_done=0; | ||
| 665 | default: | ||
| 666 | return 1; | ||
| 667 | } | ||
| 668 | } | ||
| 669 | |||
| 670 | int ssl_check_serverhello_tlsext(SSL *s) | ||
| 671 | { | ||
| 672 | int ret=SSL_TLSEXT_ERR_NOACK; | ||
| 673 | int al = SSL_AD_UNRECOGNIZED_NAME; | ||
| 674 | |||
| 675 | if (s->ctx != NULL && s->ctx->tlsext_servername_callback != 0) | ||
| 676 | ret = s->ctx->tlsext_servername_callback(s, &al, s->ctx->tlsext_servername_arg); | ||
| 677 | else if (s->initial_ctx != NULL && s->initial_ctx->tlsext_servername_callback != 0) | ||
| 678 | ret = s->initial_ctx->tlsext_servername_callback(s, &al, s->initial_ctx->tlsext_servername_arg); | ||
| 679 | |||
| 680 | /* If we've requested certificate status and we wont get one | ||
| 681 | * tell the callback | ||
| 682 | */ | ||
| 683 | if ((s->tlsext_status_type != -1) && !(s->tlsext_status_expected) | ||
| 684 | && s->ctx->tlsext_status_cb) | ||
| 685 | { | ||
| 686 | int r; | ||
| 687 | /* Set resp to NULL, resplen to -1 so callback knows | ||
| 688 | * there is no response. | ||
| 689 | */ | ||
| 690 | if (s->tlsext_ocsp_resp) | ||
| 691 | { | ||
| 692 | OPENSSL_free(s->tlsext_ocsp_resp); | ||
| 693 | s->tlsext_ocsp_resp = NULL; | ||
| 694 | } | ||
| 695 | s->tlsext_ocsp_resplen = -1; | ||
| 696 | r = s->ctx->tlsext_status_cb(s, s->ctx->tlsext_status_arg); | ||
| 697 | if (r == 0) | ||
| 698 | { | ||
| 699 | al = SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE; | ||
| 700 | ret = SSL_TLSEXT_ERR_ALERT_FATAL; | ||
| 701 | } | ||
| 702 | if (r < 0) | ||
| 703 | { | ||
| 704 | al = SSL_AD_INTERNAL_ERROR; | ||
| 705 | ret = SSL_TLSEXT_ERR_ALERT_FATAL; | ||
| 706 | } | ||
| 707 | } | ||
| 708 | |||
| 709 | switch (ret) | ||
| 710 | { | ||
| 711 | case SSL_TLSEXT_ERR_ALERT_FATAL: | ||
| 712 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
| 713 | return -1; | ||
| 714 | |||
| 715 | case SSL_TLSEXT_ERR_ALERT_WARNING: | ||
| 716 | ssl3_send_alert(s,SSL3_AL_WARNING,al); | ||
| 717 | return 1; | ||
| 718 | |||
| 719 | case SSL_TLSEXT_ERR_NOACK: | ||
| 720 | s->servername_done=0; | ||
| 721 | default: | ||
| 722 | return 1; | ||
| 723 | } | ||
| 724 | } | ||
| 725 | |||
| 726 | /* Since the server cache lookup is done early on in the processing of client | ||
| 727 | * hello and other operations depend on the result we need to handle any TLS | ||
| 728 | * session ticket extension at the same time. | ||
| 729 | */ | ||
| 730 | |||
| 731 | int tls1_process_ticket(SSL *s, unsigned char *session_id, int len, | ||
| 732 | const unsigned char *limit, SSL_SESSION **ret) | ||
| 733 | { | ||
| 734 | /* Point after session ID in client hello */ | ||
| 735 | const unsigned char *p = session_id + len; | ||
| 736 | unsigned short i; | ||
| 737 | if ((s->version <= SSL3_VERSION) || !limit) | ||
| 738 | return 1; | ||
| 739 | if (p >= limit) | ||
| 740 | return -1; | ||
| 741 | /* Skip past cipher list */ | ||
| 742 | n2s(p, i); | ||
| 743 | p+= i; | ||
| 744 | if (p >= limit) | ||
| 745 | return -1; | ||
| 746 | /* Skip past compression algorithm list */ | ||
| 747 | i = *(p++); | ||
| 748 | p += i; | ||
| 749 | if (p > limit) | ||
| 750 | return -1; | ||
| 751 | /* Now at start of extensions */ | ||
| 752 | if ((p + 2) >= limit) | ||
| 753 | return 1; | ||
| 754 | n2s(p, i); | ||
| 755 | while ((p + 4) <= limit) | ||
| 756 | { | ||
| 757 | unsigned short type, size; | ||
| 758 | n2s(p, type); | ||
| 759 | n2s(p, size); | ||
| 760 | if (p + size > limit) | ||
| 761 | return 1; | ||
| 762 | if (type == TLSEXT_TYPE_session_ticket) | ||
| 763 | { | ||
| 764 | /* If tickets disabled indicate cache miss which will | ||
| 765 | * trigger a full handshake | ||
| 766 | */ | ||
| 767 | if (SSL_get_options(s) & SSL_OP_NO_TICKET) | ||
| 768 | return 0; | ||
| 769 | /* If zero length not client will accept a ticket | ||
| 770 | * and indicate cache miss to trigger full handshake | ||
| 771 | */ | ||
| 772 | if (size == 0) | ||
| 773 | { | ||
| 774 | s->tlsext_ticket_expected = 1; | ||
| 775 | return 0; /* Cache miss */ | ||
| 776 | } | ||
| 777 | return tls_decrypt_ticket(s, p, size, session_id, len, | ||
| 778 | ret); | ||
| 779 | } | ||
| 780 | p += size; | ||
| 781 | } | ||
| 782 | return 1; | ||
| 783 | } | ||
| 784 | |||
| 785 | static int tls_decrypt_ticket(SSL *s, const unsigned char *etick, int eticklen, | ||
| 786 | const unsigned char *sess_id, int sesslen, | ||
| 787 | SSL_SESSION **psess) | ||
| 788 | { | ||
| 789 | SSL_SESSION *sess; | ||
| 790 | unsigned char *sdec; | ||
| 791 | const unsigned char *p; | ||
| 792 | int slen, mlen, renew_ticket = 0; | ||
| 793 | unsigned char tick_hmac[EVP_MAX_MD_SIZE]; | ||
| 794 | HMAC_CTX hctx; | ||
| 795 | EVP_CIPHER_CTX ctx; | ||
| 796 | /* Need at least keyname + iv + some encrypted data */ | ||
| 797 | if (eticklen < 48) | ||
| 798 | goto tickerr; | ||
| 799 | /* Initialize session ticket encryption and HMAC contexts */ | ||
| 800 | HMAC_CTX_init(&hctx); | ||
| 801 | EVP_CIPHER_CTX_init(&ctx); | ||
| 802 | if (s->ctx->tlsext_ticket_key_cb) | ||
| 803 | { | ||
| 804 | unsigned char *nctick = (unsigned char *)etick; | ||
| 805 | int rv = s->ctx->tlsext_ticket_key_cb(s, nctick, nctick + 16, | ||
| 806 | &ctx, &hctx, 0); | ||
| 807 | if (rv < 0) | ||
| 808 | return -1; | ||
| 809 | if (rv == 0) | ||
| 810 | goto tickerr; | ||
| 811 | if (rv == 2) | ||
| 812 | renew_ticket = 1; | ||
| 813 | } | ||
| 814 | else | ||
| 815 | { | ||
| 816 | /* Check key name matches */ | ||
| 817 | if (memcmp(etick, s->ctx->tlsext_tick_key_name, 16)) | ||
| 818 | goto tickerr; | ||
| 819 | HMAC_Init_ex(&hctx, s->ctx->tlsext_tick_hmac_key, 16, | ||
| 820 | tlsext_tick_md(), NULL); | ||
| 821 | EVP_DecryptInit_ex(&ctx, EVP_aes_128_cbc(), NULL, | ||
| 822 | s->ctx->tlsext_tick_aes_key, etick + 16); | ||
| 823 | } | ||
| 824 | /* Attempt to process session ticket, first conduct sanity and | ||
| 825 | * integrity checks on ticket. | ||
| 826 | */ | ||
| 827 | mlen = HMAC_size(&hctx); | ||
| 828 | eticklen -= mlen; | ||
| 829 | /* Check HMAC of encrypted ticket */ | ||
| 830 | HMAC_Update(&hctx, etick, eticklen); | ||
| 831 | HMAC_Final(&hctx, tick_hmac, NULL); | ||
| 832 | HMAC_CTX_cleanup(&hctx); | ||
| 833 | if (memcmp(tick_hmac, etick + eticklen, mlen)) | ||
| 834 | goto tickerr; | ||
| 835 | /* Attempt to decrypt session data */ | ||
| 836 | /* Move p after IV to start of encrypted ticket, update length */ | ||
| 837 | p = etick + 16 + EVP_CIPHER_CTX_iv_length(&ctx); | ||
| 838 | eticklen -= 16 + EVP_CIPHER_CTX_iv_length(&ctx); | ||
| 839 | sdec = OPENSSL_malloc(eticklen); | ||
| 840 | if (!sdec) | ||
| 841 | { | ||
| 842 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
| 843 | return -1; | ||
| 844 | } | ||
| 845 | EVP_DecryptUpdate(&ctx, sdec, &slen, p, eticklen); | ||
| 846 | if (EVP_DecryptFinal(&ctx, sdec + slen, &mlen) <= 0) | ||
| 847 | goto tickerr; | ||
| 848 | slen += mlen; | ||
| 849 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
| 850 | p = sdec; | ||
| 851 | |||
| 852 | sess = d2i_SSL_SESSION(NULL, &p, slen); | ||
| 853 | OPENSSL_free(sdec); | ||
| 854 | if (sess) | ||
| 855 | { | ||
| 856 | /* The session ID if non-empty is used by some clients to | ||
| 857 | * detect that the ticket has been accepted. So we copy it to | ||
| 858 | * the session structure. If it is empty set length to zero | ||
| 859 | * as required by standard. | ||
| 860 | */ | ||
| 861 | if (sesslen) | ||
| 862 | memcpy(sess->session_id, sess_id, sesslen); | ||
| 863 | sess->session_id_length = sesslen; | ||
| 864 | *psess = sess; | ||
| 865 | s->tlsext_ticket_expected = renew_ticket; | ||
| 866 | return 1; | ||
| 867 | } | ||
| 868 | /* If session decrypt failure indicate a cache miss and set state to | ||
| 869 | * send a new ticket | ||
| 870 | */ | ||
| 871 | tickerr: | ||
| 872 | s->tlsext_ticket_expected = 1; | ||
| 873 | return 0; | ||
| 874 | } | ||
| 875 | |||
| 876 | #endif | ||
diff --git a/src/lib/libssl/t1_meth.c b/src/lib/libssl/t1_meth.c index fcc243f782..f5d8df634e 100644 --- a/src/lib/libssl/t1_meth.c +++ b/src/lib/libssl/t1_meth.c | |||
| @@ -69,28 +69,8 @@ static SSL_METHOD *tls1_get_method(int ver) | |||
| 69 | return(NULL); | 69 | return(NULL); |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | SSL_METHOD *TLSv1_method(void) | 72 | IMPLEMENT_tls1_meth_func(TLSv1_method, |
| 73 | { | 73 | ssl3_accept, |
| 74 | static int init=1; | 74 | ssl3_connect, |
| 75 | static SSL_METHOD TLSv1_data; | 75 | tls1_get_method) |
| 76 | |||
| 77 | if (init) | ||
| 78 | { | ||
| 79 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD); | ||
| 80 | |||
| 81 | if (init) | ||
| 82 | { | ||
| 83 | memcpy((char *)&TLSv1_data,(char *)tlsv1_base_method(), | ||
| 84 | sizeof(SSL_METHOD)); | ||
| 85 | TLSv1_data.ssl_connect=ssl3_connect; | ||
| 86 | TLSv1_data.ssl_accept=ssl3_accept; | ||
| 87 | TLSv1_data.get_ssl_method=tls1_get_method; | ||
| 88 | init=0; | ||
| 89 | } | ||
| 90 | |||
| 91 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD); | ||
| 92 | } | ||
| 93 | |||
| 94 | return(&TLSv1_data); | ||
| 95 | } | ||
| 96 | 76 | ||
diff --git a/src/lib/libssl/t1_srvr.c b/src/lib/libssl/t1_srvr.c index 1c1149e49f..b75636abba 100644 --- a/src/lib/libssl/t1_srvr.c +++ b/src/lib/libssl/t1_srvr.c | |||
| @@ -73,26 +73,8 @@ static SSL_METHOD *tls1_get_server_method(int ver) | |||
| 73 | return(NULL); | 73 | return(NULL); |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | SSL_METHOD *TLSv1_server_method(void) | 76 | IMPLEMENT_tls1_meth_func(TLSv1_server_method, |
| 77 | { | 77 | ssl3_accept, |
| 78 | static int init=1; | 78 | ssl_undefined_function, |
| 79 | static SSL_METHOD TLSv1_server_data; | 79 | tls1_get_server_method) |
| 80 | |||
| 81 | if (init) | ||
| 82 | { | ||
| 83 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD); | ||
| 84 | |||
| 85 | if (init) | ||
| 86 | { | ||
| 87 | memcpy((char *)&TLSv1_server_data,(char *)tlsv1_base_method(), | ||
| 88 | sizeof(SSL_METHOD)); | ||
| 89 | TLSv1_server_data.ssl_accept=ssl3_accept; | ||
| 90 | TLSv1_server_data.get_ssl_method=tls1_get_server_method; | ||
| 91 | init=0; | ||
| 92 | } | ||
| 93 | |||
| 94 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD); | ||
| 95 | } | ||
| 96 | return(&TLSv1_server_data); | ||
| 97 | } | ||
| 98 | 80 | ||
diff --git a/src/lib/libssl/test/CAss.cnf b/src/lib/libssl/test/CAss.cnf index 21da59a73a..20f8f05e3d 100644 --- a/src/lib/libssl/test/CAss.cnf +++ b/src/lib/libssl/test/CAss.cnf | |||
| @@ -24,10 +24,53 @@ organizationName_value = Dodgy Brothers | |||
| 24 | commonName = Common Name (eg, YOUR name) | 24 | commonName = Common Name (eg, YOUR name) |
| 25 | commonName_value = Dodgy CA | 25 | commonName_value = Dodgy CA |
| 26 | 26 | ||
| 27 | #################################################################### | ||
| 28 | [ ca ] | ||
| 29 | default_ca = CA_default # The default ca section | ||
| 30 | |||
| 31 | #################################################################### | ||
| 32 | [ CA_default ] | ||
| 33 | |||
| 34 | dir = ./demoCA # Where everything is kept | ||
| 35 | certs = $dir/certs # Where the issued certs are kept | ||
| 36 | crl_dir = $dir/crl # Where the issued crl are kept | ||
| 37 | database = $dir/index.txt # database index file. | ||
| 38 | #unique_subject = no # Set to 'no' to allow creation of | ||
| 39 | # several ctificates with same subject. | ||
| 40 | new_certs_dir = $dir/newcerts # default place for new certs. | ||
| 41 | |||
| 42 | certificate = $dir/cacert.pem # The CA certificate | ||
| 43 | serial = $dir/serial # The current serial number | ||
| 44 | crl = $dir/crl.pem # The current CRL | ||
| 45 | private_key = $dir/private/cakey.pem# The private key | ||
| 46 | RANDFILE = $dir/private/.rand # private random number file | ||
| 47 | |||
| 48 | x509_extensions = v3_ca # The extentions to add to the cert | ||
| 49 | |||
| 50 | name_opt = ca_default # Subject Name options | ||
| 51 | cert_opt = ca_default # Certificate field options | ||
| 52 | |||
| 53 | default_days = 365 # how long to certify for | ||
| 54 | default_crl_days= 30 # how long before next CRL | ||
| 55 | default_md = md5 # which md to use. | ||
| 56 | preserve = no # keep passed DN ordering | ||
| 57 | |||
| 58 | policy = policy_anything | ||
| 59 | |||
| 60 | [ policy_anything ] | ||
| 61 | countryName = optional | ||
| 62 | stateOrProvinceName = optional | ||
| 63 | localityName = optional | ||
| 64 | organizationName = optional | ||
| 65 | organizationalUnitName = optional | ||
| 66 | commonName = supplied | ||
| 67 | emailAddress = optional | ||
| 68 | |||
| 69 | |||
| 70 | |||
| 27 | [ v3_ca ] | 71 | [ v3_ca ] |
| 28 | subjectKeyIdentifier=hash | 72 | subjectKeyIdentifier=hash |
| 29 | authorityKeyIdentifier=keyid:always,issuer:always | 73 | authorityKeyIdentifier=keyid:always,issuer:always |
| 30 | basicConstraints = CA:true,pathlen:1 | 74 | basicConstraints = CA:true,pathlen:1 |
| 31 | keyUsage = cRLSign, keyCertSign | 75 | keyUsage = cRLSign, keyCertSign |
| 32 | issuerAltName=issuer:copy | 76 | issuerAltName=issuer:copy |
| 33 | |||
diff --git a/src/lib/libssl/test/bctest b/src/lib/libssl/test/bctest index e81fc0733a..bdb3218f7a 100644 --- a/src/lib/libssl/test/bctest +++ b/src/lib/libssl/test/bctest | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | #!/bin/sh | 1 | #!/bin/sh |
| 2 | 2 | ||
| 3 | # This script is used by test/Makefile to check whether a sane 'bc' | 3 | # This script is used by test/Makefile.ssl to check whether a sane 'bc' |
| 4 | # is installed. | 4 | # is installed. |
| 5 | # ('make test_bn' should not try to run 'bc' if it does not exist or if | 5 | # ('make test_bn' should not try to run 'bc' if it does not exist or if |
| 6 | # it is a broken 'bc' version that is known to cause trouble.) | 6 | # it is a broken 'bc' version that is known to cause trouble.) |
diff --git a/src/lib/libssl/test/cms-examples.pl b/src/lib/libssl/test/cms-examples.pl new file mode 100644 index 0000000000..2e95b48ba4 --- /dev/null +++ b/src/lib/libssl/test/cms-examples.pl | |||
| @@ -0,0 +1,409 @@ | |||
| 1 | # test/cms-examples.pl | ||
| 2 | # Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | # project. | ||
| 4 | # | ||
| 5 | # ==================================================================== | ||
| 6 | # Copyright (c) 2008 The OpenSSL Project. All rights reserved. | ||
| 7 | # | ||
| 8 | # Redistribution and use in source and binary forms, with or without | ||
| 9 | # modification, are permitted provided that the following conditions | ||
| 10 | # are met: | ||
| 11 | # | ||
| 12 | # 1. Redistributions of source code must retain the above copyright | ||
| 13 | # notice, this list of conditions and the following disclaimer. | ||
| 14 | # | ||
| 15 | # 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | # notice, this list of conditions and the following disclaimer in | ||
| 17 | # the documentation and/or other materials provided with the | ||
| 18 | # distribution. | ||
| 19 | # | ||
| 20 | # 3. All advertising materials mentioning features or use of this | ||
| 21 | # software must display the following acknowledgment: | ||
| 22 | # "This product includes software developed by the OpenSSL Project | ||
| 23 | # for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | # | ||
| 25 | # 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | # endorse or promote products derived from this software without | ||
| 27 | # prior written permission. For written permission, please contact | ||
| 28 | # licensing@OpenSSL.org. | ||
| 29 | # | ||
| 30 | # 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | # nor may "OpenSSL" appear in their names without prior written | ||
| 32 | # permission of the OpenSSL Project. | ||
| 33 | # | ||
| 34 | # 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | # acknowledgment: | ||
| 36 | # "This product includes software developed by the OpenSSL Project | ||
| 37 | # for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | # | ||
| 39 | # THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | # EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | # ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | # OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | # ==================================================================== | ||
| 52 | |||
| 53 | # Perl script to run tests against S/MIME examples in RFC4134 | ||
| 54 | # Assumes RFC is in current directory and called "rfc4134.txt" | ||
| 55 | |||
| 56 | use MIME::Base64; | ||
| 57 | |||
| 58 | my $badttest = 0; | ||
| 59 | my $verbose = 1; | ||
| 60 | |||
| 61 | my $cmscmd; | ||
| 62 | my $exdir = "./"; | ||
| 63 | my $exfile = "./rfc4134.txt"; | ||
| 64 | |||
| 65 | if (-f "../apps/openssl") | ||
| 66 | { | ||
| 67 | $cmscmd = "../util/shlib_wrap.sh ../apps/openssl cms"; | ||
| 68 | } | ||
| 69 | elsif (-f "..\\out32dll\\openssl.exe") | ||
| 70 | { | ||
| 71 | $cmscmd = "..\\out32dll\\openssl.exe cms"; | ||
| 72 | } | ||
| 73 | elsif (-f "..\\out32\\openssl.exe") | ||
| 74 | { | ||
| 75 | $cmscmd = "..\\out32\\openssl.exe cms"; | ||
| 76 | } | ||
| 77 | |||
| 78 | my @test_list = ( | ||
| 79 | [ "3.1.bin" => "dataout" ], | ||
| 80 | [ "3.2.bin" => "encode, dataout" ], | ||
| 81 | [ "4.1.bin" => "encode, verifyder, cont, dss" ], | ||
| 82 | [ "4.2.bin" => "encode, verifyder, cont, rsa" ], | ||
| 83 | [ "4.3.bin" => "encode, verifyder, cont_extern, dss" ], | ||
| 84 | [ "4.4.bin" => "encode, verifyder, cont, dss" ], | ||
| 85 | [ "4.5.bin" => "verifyder, cont, rsa" ], | ||
| 86 | [ "4.6.bin" => "encode, verifyder, cont, dss" ], | ||
| 87 | [ "4.7.bin" => "encode, verifyder, cont, dss" ], | ||
| 88 | [ "4.8.eml" => "verifymime, dss" ], | ||
| 89 | [ "4.9.eml" => "verifymime, dss" ], | ||
| 90 | [ "4.10.bin" => "encode, verifyder, cont, dss" ], | ||
| 91 | [ "4.11.bin" => "encode, certsout" ], | ||
| 92 | [ "5.1.bin" => "encode, envelopeder, cont" ], | ||
| 93 | [ "5.2.bin" => "encode, envelopeder, cont" ], | ||
| 94 | [ "5.3.eml" => "envelopemime, cont" ], | ||
| 95 | [ "6.0.bin" => "encode, digest, cont" ], | ||
| 96 | [ "7.1.bin" => "encode, encrypted, cont" ], | ||
| 97 | [ "7.2.bin" => "encode, encrypted, cont" ] | ||
| 98 | ); | ||
| 99 | |||
| 100 | # Extract examples from RFC4134 text. | ||
| 101 | # Base64 decode all examples, certificates and | ||
| 102 | # private keys are converted to PEM format. | ||
| 103 | |||
| 104 | my ( $filename, $data ); | ||
| 105 | |||
| 106 | my @cleanup = ( "cms.out", "cms.err", "tmp.der", "tmp.txt" ); | ||
| 107 | |||
| 108 | $data = ""; | ||
| 109 | |||
| 110 | open( IN, $exfile ) || die "Can't Open RFC examples file $exfile"; | ||
| 111 | |||
| 112 | while (<IN>) { | ||
| 113 | next unless (/^\|/); | ||
| 114 | s/^\|//; | ||
| 115 | next if (/^\*/); | ||
| 116 | if (/^>(.*)$/) { | ||
| 117 | $filename = $1; | ||
| 118 | next; | ||
| 119 | } | ||
| 120 | if (/^</) { | ||
| 121 | $filename = "$exdir/$filename"; | ||
| 122 | if ( $filename =~ /\.bin$/ || $filename =~ /\.eml$/ ) { | ||
| 123 | $data = decode_base64($data); | ||
| 124 | open OUT, ">$filename"; | ||
| 125 | binmode OUT; | ||
| 126 | print OUT $data; | ||
| 127 | close OUT; | ||
| 128 | push @cleanup, $filename; | ||
| 129 | } | ||
| 130 | elsif ( $filename =~ /\.cer$/ ) { | ||
| 131 | write_pem( $filename, "CERTIFICATE", $data ); | ||
| 132 | } | ||
| 133 | elsif ( $filename =~ /\.pri$/ ) { | ||
| 134 | write_pem( $filename, "PRIVATE KEY", $data ); | ||
| 135 | } | ||
| 136 | $data = ""; | ||
| 137 | $filename = ""; | ||
| 138 | } | ||
| 139 | else { | ||
| 140 | $data .= $_; | ||
| 141 | } | ||
| 142 | |||
| 143 | } | ||
| 144 | |||
| 145 | my $secretkey = | ||
| 146 | "73:7c:79:1f:25:ea:d0:e0:46:29:25:43:52:f7:dc:62:91:e5:cb:26:91:7a:da:32"; | ||
| 147 | |||
| 148 | foreach (@test_list) { | ||
| 149 | my ( $file, $tlist ) = @$_; | ||
| 150 | print "Example file $file:\n"; | ||
| 151 | if ( $tlist =~ /encode/ ) { | ||
| 152 | run_reencode_test( $exdir, $file ); | ||
| 153 | } | ||
| 154 | if ( $tlist =~ /certsout/ ) { | ||
| 155 | run_certsout_test( $exdir, $file ); | ||
| 156 | } | ||
| 157 | if ( $tlist =~ /dataout/ ) { | ||
| 158 | run_dataout_test( $exdir, $file ); | ||
| 159 | } | ||
| 160 | if ( $tlist =~ /verify/ ) { | ||
| 161 | run_verify_test( $exdir, $tlist, $file ); | ||
| 162 | } | ||
| 163 | if ( $tlist =~ /digest/ ) { | ||
| 164 | run_digest_test( $exdir, $tlist, $file ); | ||
| 165 | } | ||
| 166 | if ( $tlist =~ /encrypted/ ) { | ||
| 167 | run_encrypted_test( $exdir, $tlist, $file, $secretkey ); | ||
| 168 | } | ||
| 169 | if ( $tlist =~ /envelope/ ) { | ||
| 170 | run_envelope_test( $exdir, $tlist, $file ); | ||
| 171 | } | ||
| 172 | |||
| 173 | } | ||
| 174 | |||
| 175 | foreach (@cleanup) { | ||
| 176 | unlink $_; | ||
| 177 | } | ||
| 178 | |||
| 179 | if ($badtest) { | ||
| 180 | print "\n$badtest TESTS FAILED!!\n"; | ||
| 181 | } | ||
| 182 | else { | ||
| 183 | print "\n***All tests successful***\n"; | ||
| 184 | } | ||
| 185 | |||
| 186 | sub write_pem { | ||
| 187 | my ( $filename, $str, $data ) = @_; | ||
| 188 | |||
| 189 | $filename =~ s/\.[^.]*$/.pem/; | ||
| 190 | |||
| 191 | push @cleanup, $filename; | ||
| 192 | |||
| 193 | open OUT, ">$filename"; | ||
| 194 | |||
| 195 | print OUT "-----BEGIN $str-----\n"; | ||
| 196 | print OUT $data; | ||
| 197 | print OUT "-----END $str-----\n"; | ||
| 198 | |||
| 199 | close OUT; | ||
| 200 | } | ||
| 201 | |||
| 202 | sub run_reencode_test { | ||
| 203 | my ( $cmsdir, $tfile ) = @_; | ||
| 204 | unlink "tmp.der"; | ||
| 205 | |||
| 206 | system( "$cmscmd -cmsout -inform DER -outform DER" | ||
| 207 | . " -in $cmsdir/$tfile -out tmp.der" ); | ||
| 208 | |||
| 209 | if ($?) { | ||
| 210 | print "\tReencode command FAILED!!\n"; | ||
| 211 | $badtest++; | ||
| 212 | } | ||
| 213 | elsif ( !cmp_files( "$cmsdir/$tfile", "tmp.der" ) ) { | ||
| 214 | print "\tReencode FAILED!!\n"; | ||
| 215 | $badtest++; | ||
| 216 | } | ||
| 217 | else { | ||
| 218 | print "\tReencode passed\n" if $verbose; | ||
| 219 | } | ||
| 220 | } | ||
| 221 | |||
| 222 | sub run_certsout_test { | ||
| 223 | my ( $cmsdir, $tfile ) = @_; | ||
| 224 | unlink "tmp.der"; | ||
| 225 | unlink "tmp.pem"; | ||
| 226 | |||
| 227 | system( "$cmscmd -cmsout -inform DER -certsout tmp.pem" | ||
| 228 | . " -in $cmsdir/$tfile -out tmp.der" ); | ||
| 229 | |||
| 230 | if ($?) { | ||
| 231 | print "\tCertificate output command FAILED!!\n"; | ||
| 232 | $badtest++; | ||
| 233 | } | ||
| 234 | else { | ||
| 235 | print "\tCertificate output passed\n" if $verbose; | ||
| 236 | } | ||
| 237 | } | ||
| 238 | |||
| 239 | sub run_dataout_test { | ||
| 240 | my ( $cmsdir, $tfile ) = @_; | ||
| 241 | unlink "tmp.txt"; | ||
| 242 | |||
| 243 | system( | ||
| 244 | "$cmscmd -data_out -inform DER" . " -in $cmsdir/$tfile -out tmp.txt" ); | ||
| 245 | |||
| 246 | if ($?) { | ||
| 247 | print "\tDataout command FAILED!!\n"; | ||
| 248 | $badtest++; | ||
| 249 | } | ||
| 250 | elsif ( !cmp_files( "$cmsdir/ExContent.bin", "tmp.txt" ) ) { | ||
| 251 | print "\tDataout compare FAILED!!\n"; | ||
| 252 | $badtest++; | ||
| 253 | } | ||
| 254 | else { | ||
| 255 | print "\tDataout passed\n" if $verbose; | ||
| 256 | } | ||
| 257 | } | ||
| 258 | |||
| 259 | sub run_verify_test { | ||
| 260 | my ( $cmsdir, $tlist, $tfile ) = @_; | ||
| 261 | unlink "tmp.txt"; | ||
| 262 | |||
| 263 | $form = "DER" if $tlist =~ /verifyder/; | ||
| 264 | $form = "SMIME" if $tlist =~ /verifymime/; | ||
| 265 | $cafile = "$cmsdir/CarlDSSSelf.pem" if $tlist =~ /dss/; | ||
| 266 | $cafile = "$cmsdir/CarlRSASelf.pem" if $tlist =~ /rsa/; | ||
| 267 | |||
| 268 | $cmd = | ||
| 269 | "$cmscmd -verify -inform $form" | ||
| 270 | . " -CAfile $cafile" | ||
| 271 | . " -in $cmsdir/$tfile -out tmp.txt"; | ||
| 272 | |||
| 273 | $cmd .= " -content $cmsdir/ExContent.bin" if $tlist =~ /cont_extern/; | ||
| 274 | |||
| 275 | system("$cmd 2>cms.err 1>cms.out"); | ||
| 276 | |||
| 277 | if ($?) { | ||
| 278 | print "\tVerify command FAILED!!\n"; | ||
| 279 | $badtest++; | ||
| 280 | } | ||
| 281 | elsif ( $tlist =~ /cont/ | ||
| 282 | && !cmp_files( "$cmsdir/ExContent.bin", "tmp.txt" ) ) | ||
| 283 | { | ||
| 284 | print "\tVerify content compare FAILED!!\n"; | ||
| 285 | $badtest++; | ||
| 286 | } | ||
| 287 | else { | ||
| 288 | print "\tVerify passed\n" if $verbose; | ||
| 289 | } | ||
| 290 | } | ||
| 291 | |||
| 292 | sub run_envelope_test { | ||
| 293 | my ( $cmsdir, $tlist, $tfile ) = @_; | ||
| 294 | unlink "tmp.txt"; | ||
| 295 | |||
| 296 | $form = "DER" if $tlist =~ /envelopeder/; | ||
| 297 | $form = "SMIME" if $tlist =~ /envelopemime/; | ||
| 298 | |||
| 299 | $cmd = | ||
| 300 | "$cmscmd -decrypt -inform $form" | ||
| 301 | . " -recip $cmsdir/BobRSASignByCarl.pem" | ||
| 302 | . " -inkey $cmsdir/BobPrivRSAEncrypt.pem" | ||
| 303 | . " -in $cmsdir/$tfile -out tmp.txt"; | ||
| 304 | |||
| 305 | system("$cmd 2>cms.err 1>cms.out"); | ||
| 306 | |||
| 307 | if ($?) { | ||
| 308 | print "\tDecrypt command FAILED!!\n"; | ||
| 309 | $badtest++; | ||
| 310 | } | ||
| 311 | elsif ( $tlist =~ /cont/ | ||
| 312 | && !cmp_files( "$cmsdir/ExContent.bin", "tmp.txt" ) ) | ||
| 313 | { | ||
| 314 | print "\tDecrypt content compare FAILED!!\n"; | ||
| 315 | $badtest++; | ||
| 316 | } | ||
| 317 | else { | ||
| 318 | print "\tDecrypt passed\n" if $verbose; | ||
| 319 | } | ||
| 320 | } | ||
| 321 | |||
| 322 | sub run_digest_test { | ||
| 323 | my ( $cmsdir, $tlist, $tfile ) = @_; | ||
| 324 | unlink "tmp.txt"; | ||
| 325 | |||
| 326 | my $cmd = | ||
| 327 | "$cmscmd -digest_verify -inform DER" . " -in $cmsdir/$tfile -out tmp.txt"; | ||
| 328 | |||
| 329 | system("$cmd 2>cms.err 1>cms.out"); | ||
| 330 | |||
| 331 | if ($?) { | ||
| 332 | print "\tDigest verify command FAILED!!\n"; | ||
| 333 | $badtest++; | ||
| 334 | } | ||
| 335 | elsif ( $tlist =~ /cont/ | ||
| 336 | && !cmp_files( "$cmsdir/ExContent.bin", "tmp.txt" ) ) | ||
| 337 | { | ||
| 338 | print "\tDigest verify content compare FAILED!!\n"; | ||
| 339 | $badtest++; | ||
| 340 | } | ||
| 341 | else { | ||
| 342 | print "\tDigest verify passed\n" if $verbose; | ||
| 343 | } | ||
| 344 | } | ||
| 345 | |||
| 346 | sub run_encrypted_test { | ||
| 347 | my ( $cmsdir, $tlist, $tfile, $key ) = @_; | ||
| 348 | unlink "tmp.txt"; | ||
| 349 | |||
| 350 | system( "$cmscmd -EncryptedData_decrypt -inform DER" | ||
| 351 | . " -secretkey $key" | ||
| 352 | . " -in $cmsdir/$tfile -out tmp.txt" ); | ||
| 353 | |||
| 354 | if ($?) { | ||
| 355 | print "\tEncrypted Data command FAILED!!\n"; | ||
| 356 | $badtest++; | ||
| 357 | } | ||
| 358 | elsif ( $tlist =~ /cont/ | ||
| 359 | && !cmp_files( "$cmsdir/ExContent.bin", "tmp.txt" ) ) | ||
| 360 | { | ||
| 361 | print "\tEncrypted Data content compare FAILED!!\n"; | ||
| 362 | $badtest++; | ||
| 363 | } | ||
| 364 | else { | ||
| 365 | print "\tEncryptedData verify passed\n" if $verbose; | ||
| 366 | } | ||
| 367 | } | ||
| 368 | |||
| 369 | sub cmp_files { | ||
| 370 | my ( $f1, $f2 ) = @_; | ||
| 371 | my ( $fp1, $fp2 ); | ||
| 372 | |||
| 373 | my ( $rd1, $rd2 ); | ||
| 374 | |||
| 375 | if ( !open( $fp1, "<$f1" ) ) { | ||
| 376 | print STDERR "Can't Open file $f1\n"; | ||
| 377 | return 0; | ||
| 378 | } | ||
| 379 | |||
| 380 | if ( !open( $fp2, "<$f2" ) ) { | ||
| 381 | print STDERR "Can't Open file $f2\n"; | ||
| 382 | return 0; | ||
| 383 | } | ||
| 384 | |||
| 385 | binmode $fp1; | ||
| 386 | binmode $fp2; | ||
| 387 | |||
| 388 | my $ret = 0; | ||
| 389 | |||
| 390 | for ( ; ; ) { | ||
| 391 | $n1 = sysread $fp1, $rd1, 4096; | ||
| 392 | $n2 = sysread $fp2, $rd2, 4096; | ||
| 393 | last if ( $n1 != $n2 ); | ||
| 394 | last if ( $rd1 ne $rd2 ); | ||
| 395 | |||
| 396 | if ( $n1 == 0 ) { | ||
| 397 | $ret = 1; | ||
| 398 | last; | ||
| 399 | } | ||
| 400 | |||
| 401 | } | ||
| 402 | |||
| 403 | close $fp1; | ||
| 404 | close $fp2; | ||
| 405 | |||
| 406 | return $ret; | ||
| 407 | |||
| 408 | } | ||
| 409 | |||
diff --git a/src/lib/libssl/test/cms-test.pl b/src/lib/libssl/test/cms-test.pl new file mode 100644 index 0000000000..a84e089ddc --- /dev/null +++ b/src/lib/libssl/test/cms-test.pl | |||
| @@ -0,0 +1,453 @@ | |||
| 1 | # test/cms-test.pl | ||
| 2 | # Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | # project. | ||
| 4 | # | ||
| 5 | # ==================================================================== | ||
| 6 | # Copyright (c) 2008 The OpenSSL Project. All rights reserved. | ||
| 7 | # | ||
| 8 | # Redistribution and use in source and binary forms, with or without | ||
| 9 | # modification, are permitted provided that the following conditions | ||
| 10 | # are met: | ||
| 11 | # | ||
| 12 | # 1. Redistributions of source code must retain the above copyright | ||
| 13 | # notice, this list of conditions and the following disclaimer. | ||
| 14 | # | ||
| 15 | # 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | # notice, this list of conditions and the following disclaimer in | ||
| 17 | # the documentation and/or other materials provided with the | ||
| 18 | # distribution. | ||
| 19 | # | ||
| 20 | # 3. All advertising materials mentioning features or use of this | ||
| 21 | # software must display the following acknowledgment: | ||
| 22 | # "This product includes software developed by the OpenSSL Project | ||
| 23 | # for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | # | ||
| 25 | # 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | # endorse or promote products derived from this software without | ||
| 27 | # prior written permission. For written permission, please contact | ||
| 28 | # licensing@OpenSSL.org. | ||
| 29 | # | ||
| 30 | # 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | # nor may "OpenSSL" appear in their names without prior written | ||
| 32 | # permission of the OpenSSL Project. | ||
| 33 | # | ||
| 34 | # 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | # acknowledgment: | ||
| 36 | # "This product includes software developed by the OpenSSL Project | ||
| 37 | # for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | # | ||
| 39 | # THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | # EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | # ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | # OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | # ==================================================================== | ||
| 52 | |||
| 53 | # CMS, PKCS7 consistency test script. Run extensive tests on | ||
| 54 | # OpenSSL PKCS#7 and CMS implementations. | ||
| 55 | |||
| 56 | my $ossl_path; | ||
| 57 | |||
| 58 | if ( -f "../apps/openssl" ) { | ||
| 59 | $ossl_path = "../util/shlib_wrap.sh ../apps/openssl"; | ||
| 60 | } | ||
| 61 | elsif ( -f "..\\out32dll\\openssl.exe" ) { | ||
| 62 | $ossl_path = "..\\out32dll\\openssl.exe"; | ||
| 63 | } | ||
| 64 | elsif ( -f "..\\out32\\openssl.exe" ) { | ||
| 65 | $ossl_path = "..\\out32\\openssl.exe"; | ||
| 66 | } | ||
| 67 | else { | ||
| 68 | die "Can't find OpenSSL executable"; | ||
| 69 | } | ||
| 70 | |||
| 71 | my $pk7cmd = "$ossl_path smime "; | ||
| 72 | my $cmscmd = "$ossl_path cms "; | ||
| 73 | my $smdir = "smime-certs"; | ||
| 74 | my $halt_err = 1; | ||
| 75 | |||
| 76 | my $badcmd = 0; | ||
| 77 | my $ossl8 = `$ossl_path version -v` =~ /0\.9\.8/; | ||
| 78 | |||
| 79 | my @smime_pkcs7_tests = ( | ||
| 80 | |||
| 81 | [ | ||
| 82 | "signed content DER format, RSA key", | ||
| 83 | "-sign -in smcont.txt -outform DER -nodetach" | ||
| 84 | . " -certfile $smdir/smroot.pem" | ||
| 85 | . " -signer $smdir/smrsa1.pem -out test.cms", | ||
| 86 | "-verify -in test.cms -inform DER " | ||
| 87 | . " -CAfile $smdir/smroot.pem -out smtst.txt" | ||
| 88 | ], | ||
| 89 | |||
| 90 | [ | ||
| 91 | "signed detached content DER format, RSA key", | ||
| 92 | "-sign -in smcont.txt -outform DER" | ||
| 93 | . " -signer $smdir/smrsa1.pem -out test.cms", | ||
| 94 | "-verify -in test.cms -inform DER " | ||
| 95 | . " -CAfile $smdir/smroot.pem -out smtst.txt -content smcont.txt" | ||
| 96 | ], | ||
| 97 | |||
| 98 | [ | ||
| 99 | "signed content test streaming BER format, RSA", | ||
| 100 | "-sign -in smcont.txt -outform DER -nodetach" | ||
| 101 | . " -stream -signer $smdir/smrsa1.pem -out test.cms", | ||
| 102 | "-verify -in test.cms -inform DER " | ||
| 103 | . " -CAfile $smdir/smroot.pem -out smtst.txt" | ||
| 104 | ], | ||
| 105 | |||
| 106 | [ | ||
| 107 | "signed content DER format, DSA key", | ||
| 108 | "-sign -in smcont.txt -outform DER -nodetach" | ||
| 109 | . " -signer $smdir/smdsa1.pem -out test.cms", | ||
| 110 | "-verify -in test.cms -inform DER " | ||
| 111 | . " -CAfile $smdir/smroot.pem -out smtst.txt" | ||
| 112 | ], | ||
| 113 | |||
| 114 | [ | ||
| 115 | "signed detached content DER format, DSA key", | ||
| 116 | "-sign -in smcont.txt -outform DER" | ||
| 117 | . " -signer $smdir/smdsa1.pem -out test.cms", | ||
| 118 | "-verify -in test.cms -inform DER " | ||
| 119 | . " -CAfile $smdir/smroot.pem -out smtst.txt -content smcont.txt" | ||
| 120 | ], | ||
| 121 | |||
| 122 | [ | ||
| 123 | "signed detached content DER format, add RSA signer", | ||
| 124 | "-resign -inform DER -in test.cms -outform DER" | ||
| 125 | . " -signer $smdir/smrsa1.pem -out test2.cms", | ||
| 126 | "-verify -in test2.cms -inform DER " | ||
| 127 | . " -CAfile $smdir/smroot.pem -out smtst.txt -content smcont.txt" | ||
| 128 | ], | ||
| 129 | |||
| 130 | [ | ||
| 131 | "signed content test streaming BER format, DSA key", | ||
| 132 | "-sign -in smcont.txt -outform DER -nodetach" | ||
| 133 | . " -stream -signer $smdir/smdsa1.pem -out test.cms", | ||
| 134 | "-verify -in test.cms -inform DER " | ||
| 135 | . " -CAfile $smdir/smroot.pem -out smtst.txt" | ||
| 136 | ], | ||
| 137 | |||
| 138 | [ | ||
| 139 | "signed content test streaming BER format, 2 DSA and 2 RSA keys", | ||
| 140 | "-sign -in smcont.txt -outform DER -nodetach" | ||
| 141 | . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem" | ||
| 142 | . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem" | ||
| 143 | . " -stream -out test.cms", | ||
| 144 | "-verify -in test.cms -inform DER " | ||
| 145 | . " -CAfile $smdir/smroot.pem -out smtst.txt" | ||
| 146 | ], | ||
| 147 | |||
| 148 | [ | ||
| 149 | "signed content test streaming BER format, 2 DSA and 2 RSA keys, no attributes", | ||
| 150 | "-sign -in smcont.txt -outform DER -noattr -nodetach" | ||
| 151 | . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem" | ||
| 152 | . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem" | ||
| 153 | . " -stream -out test.cms", | ||
| 154 | "-verify -in test.cms -inform DER " | ||
| 155 | . " -CAfile $smdir/smroot.pem -out smtst.txt" | ||
| 156 | ], | ||
| 157 | |||
| 158 | [ | ||
| 159 | "signed content test streaming S/MIME format, 2 DSA and 2 RSA keys", | ||
| 160 | "-sign -in smcont.txt -nodetach" | ||
| 161 | . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem" | ||
| 162 | . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem" | ||
| 163 | . " -stream -out test.cms", | ||
| 164 | "-verify -in test.cms " . " -CAfile $smdir/smroot.pem -out smtst.txt" | ||
| 165 | ], | ||
| 166 | |||
| 167 | [ | ||
| 168 | "signed content test streaming multipart S/MIME format, 2 DSA and 2 RSA keys", | ||
| 169 | "-sign -in smcont.txt" | ||
| 170 | . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem" | ||
| 171 | . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem" | ||
| 172 | . " -stream -out test.cms", | ||
| 173 | "-verify -in test.cms " . " -CAfile $smdir/smroot.pem -out smtst.txt" | ||
| 174 | ], | ||
| 175 | |||
| 176 | [ | ||
| 177 | "enveloped content test streaming S/MIME format, 3 recipients", | ||
| 178 | "-encrypt -in smcont.txt" | ||
| 179 | . " -stream -out test.cms" | ||
| 180 | . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ", | ||
| 181 | "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt" | ||
| 182 | ], | ||
| 183 | |||
| 184 | [ | ||
| 185 | "enveloped content test streaming S/MIME format, 3 recipients, 3rd used", | ||
| 186 | "-encrypt -in smcont.txt" | ||
| 187 | . " -stream -out test.cms" | ||
| 188 | . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ", | ||
| 189 | "-decrypt -recip $smdir/smrsa3.pem -in test.cms -out smtst.txt" | ||
| 190 | ], | ||
| 191 | |||
| 192 | [ | ||
| 193 | "enveloped content test streaming S/MIME format, 3 recipients, key only used", | ||
| 194 | "-encrypt -in smcont.txt" | ||
| 195 | . " -stream -out test.cms" | ||
| 196 | . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ", | ||
| 197 | "-decrypt -inkey $smdir/smrsa3.pem -in test.cms -out smtst.txt" | ||
| 198 | ], | ||
| 199 | |||
| 200 | [ | ||
| 201 | "enveloped content test streaming S/MIME format, AES-256 cipher, 3 recipients", | ||
| 202 | "-encrypt -in smcont.txt" | ||
| 203 | . " -aes256 -stream -out test.cms" | ||
| 204 | . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ", | ||
| 205 | "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt" | ||
| 206 | ], | ||
| 207 | |||
| 208 | ); | ||
| 209 | |||
| 210 | my @smime_cms_tests = ( | ||
| 211 | |||
| 212 | [ | ||
| 213 | "signed content test streaming BER format, 2 DSA and 2 RSA keys, keyid", | ||
| 214 | "-sign -in smcont.txt -outform DER -nodetach -keyid" | ||
| 215 | . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem" | ||
| 216 | . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem" | ||
| 217 | . " -stream -out test.cms", | ||
| 218 | "-verify -in test.cms -inform DER " | ||
| 219 | . " -CAfile $smdir/smroot.pem -out smtst.txt" | ||
| 220 | ], | ||
| 221 | |||
| 222 | [ | ||
| 223 | "signed content test streaming PEM format, 2 DSA and 2 RSA keys", | ||
| 224 | "-sign -in smcont.txt -outform PEM -nodetach" | ||
| 225 | . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem" | ||
| 226 | . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem" | ||
| 227 | . " -stream -out test.cms", | ||
| 228 | "-verify -in test.cms -inform PEM " | ||
| 229 | . " -CAfile $smdir/smroot.pem -out smtst.txt" | ||
| 230 | ], | ||
| 231 | |||
| 232 | [ | ||
| 233 | "signed content MIME format, RSA key, signed receipt request", | ||
| 234 | "-sign -in smcont.txt -signer $smdir/smrsa1.pem -nodetach" | ||
| 235 | . " -receipt_request_to test@openssl.org -receipt_request_all" | ||
| 236 | . " -out test.cms", | ||
| 237 | "-verify -in test.cms " | ||
| 238 | . " -CAfile $smdir/smroot.pem -out smtst.txt" | ||
| 239 | ], | ||
| 240 | |||
| 241 | [ | ||
| 242 | "signed receipt MIME format, RSA key", | ||
| 243 | "-sign_receipt -in test.cms" | ||
| 244 | . " -signer $smdir/smrsa2.pem" | ||
| 245 | . " -out test2.cms", | ||
| 246 | "-verify_receipt test2.cms -in test.cms" | ||
| 247 | . " -CAfile $smdir/smroot.pem" | ||
| 248 | ], | ||
| 249 | |||
| 250 | [ | ||
| 251 | "enveloped content test streaming S/MIME format, 3 recipients, keyid", | ||
| 252 | "-encrypt -in smcont.txt" | ||
| 253 | . " -stream -out test.cms -keyid" | ||
| 254 | . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ", | ||
| 255 | "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt" | ||
| 256 | ], | ||
| 257 | |||
| 258 | [ | ||
| 259 | "enveloped content test streaming PEM format, KEK", | ||
| 260 | "-encrypt -in smcont.txt -outform PEM -aes128" | ||
| 261 | . " -stream -out test.cms " | ||
| 262 | . " -secretkey 000102030405060708090A0B0C0D0E0F " | ||
| 263 | . " -secretkeyid C0FEE0", | ||
| 264 | "-decrypt -in test.cms -out smtst.txt -inform PEM" | ||
| 265 | . " -secretkey 000102030405060708090A0B0C0D0E0F " | ||
| 266 | . " -secretkeyid C0FEE0" | ||
| 267 | ], | ||
| 268 | |||
| 269 | [ | ||
| 270 | "enveloped content test streaming PEM format, KEK, key only", | ||
| 271 | "-encrypt -in smcont.txt -outform PEM -aes128" | ||
| 272 | . " -stream -out test.cms " | ||
| 273 | . " -secretkey 000102030405060708090A0B0C0D0E0F " | ||
| 274 | . " -secretkeyid C0FEE0", | ||
| 275 | "-decrypt -in test.cms -out smtst.txt -inform PEM" | ||
| 276 | . " -secretkey 000102030405060708090A0B0C0D0E0F " | ||
| 277 | ], | ||
| 278 | |||
| 279 | [ | ||
| 280 | "data content test streaming PEM format", | ||
| 281 | "-data_create -in smcont.txt -outform PEM -nodetach" | ||
| 282 | . " -stream -out test.cms", | ||
| 283 | "-data_out -in test.cms -inform PEM -out smtst.txt" | ||
| 284 | ], | ||
| 285 | |||
| 286 | [ | ||
| 287 | "encrypted content test streaming PEM format, 128 bit RC2 key", | ||
| 288 | "-EncryptedData_encrypt -in smcont.txt -outform PEM" | ||
| 289 | . " -rc2 -secretkey 000102030405060708090A0B0C0D0E0F" | ||
| 290 | . " -stream -out test.cms", | ||
| 291 | "-EncryptedData_decrypt -in test.cms -inform PEM " | ||
| 292 | . " -secretkey 000102030405060708090A0B0C0D0E0F -out smtst.txt" | ||
| 293 | ], | ||
| 294 | |||
| 295 | [ | ||
| 296 | "encrypted content test streaming PEM format, 40 bit RC2 key", | ||
| 297 | "-EncryptedData_encrypt -in smcont.txt -outform PEM" | ||
| 298 | . " -rc2 -secretkey 0001020304" | ||
| 299 | . " -stream -out test.cms", | ||
| 300 | "-EncryptedData_decrypt -in test.cms -inform PEM " | ||
| 301 | . " -secretkey 0001020304 -out smtst.txt" | ||
| 302 | ], | ||
| 303 | |||
| 304 | [ | ||
| 305 | "encrypted content test streaming PEM format, triple DES key", | ||
| 306 | "-EncryptedData_encrypt -in smcont.txt -outform PEM" | ||
| 307 | . " -des3 -secretkey 000102030405060708090A0B0C0D0E0F1011121314151617" | ||
| 308 | . " -stream -out test.cms", | ||
| 309 | "-EncryptedData_decrypt -in test.cms -inform PEM " | ||
| 310 | . " -secretkey 000102030405060708090A0B0C0D0E0F1011121314151617" | ||
| 311 | . " -out smtst.txt" | ||
| 312 | ], | ||
| 313 | |||
| 314 | [ | ||
| 315 | "encrypted content test streaming PEM format, 128 bit AES key", | ||
| 316 | "-EncryptedData_encrypt -in smcont.txt -outform PEM" | ||
| 317 | . " -aes128 -secretkey 000102030405060708090A0B0C0D0E0F" | ||
| 318 | . " -stream -out test.cms", | ||
| 319 | "-EncryptedData_decrypt -in test.cms -inform PEM " | ||
| 320 | . " -secretkey 000102030405060708090A0B0C0D0E0F -out smtst.txt" | ||
| 321 | ], | ||
| 322 | |||
| 323 | ); | ||
| 324 | |||
| 325 | my @smime_cms_comp_tests = ( | ||
| 326 | |||
| 327 | [ | ||
| 328 | "compressed content test streaming PEM format", | ||
| 329 | "-compress -in smcont.txt -outform PEM -nodetach" | ||
| 330 | . " -stream -out test.cms", | ||
| 331 | "-uncompress -in test.cms -inform PEM -out smtst.txt" | ||
| 332 | ] | ||
| 333 | |||
| 334 | ); | ||
| 335 | |||
| 336 | print "PKCS#7 <=> PKCS#7 consistency tests\n"; | ||
| 337 | |||
| 338 | run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $pk7cmd, $pk7cmd ); | ||
| 339 | |||
| 340 | print "CMS => PKCS#7 compatibility tests\n"; | ||
| 341 | |||
| 342 | run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $cmscmd, $pk7cmd ); | ||
| 343 | |||
| 344 | print "CMS <= PKCS#7 compatibility tests\n"; | ||
| 345 | |||
| 346 | run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $pk7cmd, $cmscmd ); | ||
| 347 | |||
| 348 | print "CMS <=> CMS consistency tests\n"; | ||
| 349 | |||
| 350 | run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $cmscmd, $cmscmd ); | ||
| 351 | run_smime_tests( \$badcmd, \@smime_cms_tests, $cmscmd, $cmscmd ); | ||
| 352 | |||
| 353 | if ( `$ossl_path version -f` =~ /ZLIB/ ) { | ||
| 354 | run_smime_tests( \$badcmd, \@smime_cms_comp_tests, $cmscmd, $cmscmd ); | ||
| 355 | } | ||
| 356 | else { | ||
| 357 | print "Zlib not supported: compression tests skipped\n"; | ||
| 358 | } | ||
| 359 | |||
| 360 | print "Running modified tests for OpenSSL 0.9.8 cms backport\n" if($ossl8); | ||
| 361 | |||
| 362 | if ($badcmd) { | ||
| 363 | print "$badcmd TESTS FAILED!!\n"; | ||
| 364 | } | ||
| 365 | else { | ||
| 366 | print "ALL TESTS SUCCESSFUL.\n"; | ||
| 367 | } | ||
| 368 | |||
| 369 | unlink "test.cms"; | ||
| 370 | unlink "test2.cms"; | ||
| 371 | unlink "smtst.txt"; | ||
| 372 | unlink "cms.out"; | ||
| 373 | unlink "cms.err"; | ||
| 374 | |||
| 375 | sub run_smime_tests { | ||
| 376 | my ( $rv, $aref, $scmd, $vcmd ) = @_; | ||
| 377 | |||
| 378 | foreach $smtst (@$aref) { | ||
| 379 | my ( $tnam, $rscmd, $rvcmd ) = @$smtst; | ||
| 380 | if ($ossl8) | ||
| 381 | { | ||
| 382 | # Skip smime resign: 0.9.8 smime doesn't support -resign | ||
| 383 | next if ($scmd =~ /smime/ && $rscmd =~ /-resign/); | ||
| 384 | # Disable streaming: option not supported in 0.9.8 | ||
| 385 | $tnam =~ s/streaming//; | ||
| 386 | $rscmd =~ s/-stream//; | ||
| 387 | $rvcmd =~ s/-stream//; | ||
| 388 | } | ||
| 389 | system("$scmd$rscmd 2>cms.err 1>cms.out"); | ||
| 390 | if ($?) { | ||
| 391 | print "$tnam: generation error\n"; | ||
| 392 | $$rv++; | ||
| 393 | exit 1 if $halt_err; | ||
| 394 | next; | ||
| 395 | } | ||
| 396 | system("$vcmd$rvcmd 2>cms.err 1>cms.out"); | ||
| 397 | if ($?) { | ||
| 398 | print "$tnam: verify error\n"; | ||
| 399 | $$rv++; | ||
| 400 | exit 1 if $halt_err; | ||
| 401 | next; | ||
| 402 | } | ||
| 403 | if (!cmp_files("smtst.txt", "smcont.txt")) { | ||
| 404 | print "$tnam: content verify error\n"; | ||
| 405 | $$rv++; | ||
| 406 | exit 1 if $halt_err; | ||
| 407 | next; | ||
| 408 | } | ||
| 409 | print "$tnam: OK\n"; | ||
| 410 | } | ||
| 411 | } | ||
| 412 | |||
| 413 | sub cmp_files { | ||
| 414 | my ( $f1, $f2 ) = @_; | ||
| 415 | my ( $fp1, $fp2 ); | ||
| 416 | |||
| 417 | my ( $rd1, $rd2 ); | ||
| 418 | |||
| 419 | if ( !open( $fp1, "<$f1" ) ) { | ||
| 420 | print STDERR "Can't Open file $f1\n"; | ||
| 421 | return 0; | ||
| 422 | } | ||
| 423 | |||
| 424 | if ( !open( $fp2, "<$f2" ) ) { | ||
| 425 | print STDERR "Can't Open file $f2\n"; | ||
| 426 | return 0; | ||
| 427 | } | ||
| 428 | |||
| 429 | binmode $fp1; | ||
| 430 | binmode $fp2; | ||
| 431 | |||
| 432 | my $ret = 0; | ||
| 433 | |||
| 434 | for ( ; ; ) { | ||
| 435 | $n1 = sysread $fp1, $rd1, 4096; | ||
| 436 | $n2 = sysread $fp2, $rd2, 4096; | ||
| 437 | last if ( $n1 != $n2 ); | ||
| 438 | last if ( $rd1 ne $rd2 ); | ||
| 439 | |||
| 440 | if ( $n1 == 0 ) { | ||
| 441 | $ret = 1; | ||
| 442 | last; | ||
| 443 | } | ||
| 444 | |||
| 445 | } | ||
| 446 | |||
| 447 | close $fp1; | ||
| 448 | close $fp2; | ||
| 449 | |||
| 450 | return $ret; | ||
| 451 | |||
| 452 | } | ||
| 453 | |||
diff --git a/src/lib/libssl/test/smcont.txt b/src/lib/libssl/test/smcont.txt new file mode 100644 index 0000000000..e837c0b75b --- /dev/null +++ b/src/lib/libssl/test/smcont.txt | |||
| @@ -0,0 +1 @@ | |||
| Some test content for OpenSSL CMS \ No newline at end of file | |||
diff --git a/src/lib/libssl/test/smime-certs/smdsa1.pem b/src/lib/libssl/test/smime-certs/smdsa1.pem new file mode 100644 index 0000000000..d5677dbfbe --- /dev/null +++ b/src/lib/libssl/test/smime-certs/smdsa1.pem | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | -----BEGIN DSA PRIVATE KEY----- | ||
| 2 | MIIBuwIBAAKBgQDFJfsIPOIawMO5biw+AoYUhNVxReBOLQosU3Qv4B8krac0BNr3 | ||
| 3 | OjSGLh1wZxHqhlAE0QmasTaKojuk20nNWeFnczSz6vDl0IVJEhS8VYor5kt9gLqt | ||
| 4 | GcoAgsf4gRDIutJyQDaNn3IVY89uXUVIoexvQeLQDBCgQPC5O8rJdqBwtwIVAK2J | ||
| 5 | jt+dqk07eQUE59koYUEKyNorAoGBAI4IEpusf8G14kCHmRtnHXM2tG5EWJDmW6Qt | ||
| 6 | wjqvWp1GKUx5WFy1tVWR9nl5rL0Di+kNdENo+SkKj7h3uDulGOI6T0mQYbV2h1IK | ||
| 7 | +FMOGnOqvZ8eNTE2n4PGTo5puZ63LBm+QYrQsrNiUY4vakLFQ2rEK/SLwdsDFK4Z | ||
| 8 | SJCBQw5zAoGATQlPPF+OeU8nu3rsdXGDiZdJzOkuCce3KQfTABA9C+Dk4CVcvBdd | ||
| 9 | YRLGpnykumkNTO1sTO+4/Gphsuje1ujK9td4UEhdYqylCe5QjEMrszDlJtelDQF9 | ||
| 10 | C0yhdjKGTP0kxofLhsGckcuQvcKEKffT2pDDKJIy4vWQO0UyJl1vjLcCFG2uiGGx | ||
| 11 | 9fMUZq1v0ePD4Wo0Xkxo | ||
| 12 | -----END DSA PRIVATE KEY----- | ||
| 13 | -----BEGIN CERTIFICATE----- | ||
| 14 | MIIDpDCCAw2gAwIBAgIJAMtotfHYdEsWMA0GCSqGSIb3DQEBBQUAMEQxCzAJBgNV | ||
| 15 | BAYTAlVLMRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMR0wGwYDVQQDExRUZXN0IFMv | ||
| 16 | TUlNRSBSU0EgUm9vdDAeFw0wODAyMjIxMzUzMDlaFw0xNjA1MTAxMzUzMDlaMEUx | ||
| 17 | CzAJBgNVBAYTAlVLMRYwFAYDVQQKDA1PcGVuU1NMIEdyb3VwMR4wHAYDVQQDDBVU | ||
| 18 | ZXN0IFMvTUlNRSBFRSBEU0EgIzEwggG3MIIBLAYHKoZIzjgEATCCAR8CgYEAxSX7 | ||
| 19 | CDziGsDDuW4sPgKGFITVcUXgTi0KLFN0L+AfJK2nNATa9zo0hi4dcGcR6oZQBNEJ | ||
| 20 | mrE2iqI7pNtJzVnhZ3M0s+rw5dCFSRIUvFWKK+ZLfYC6rRnKAILH+IEQyLrSckA2 | ||
| 21 | jZ9yFWPPbl1FSKHsb0Hi0AwQoEDwuTvKyXagcLcCFQCtiY7fnapNO3kFBOfZKGFB | ||
| 22 | CsjaKwKBgQCOCBKbrH/BteJAh5kbZx1zNrRuRFiQ5lukLcI6r1qdRilMeVhctbVV | ||
| 23 | kfZ5eay9A4vpDXRDaPkpCo+4d7g7pRjiOk9JkGG1dodSCvhTDhpzqr2fHjUxNp+D | ||
| 24 | xk6OabmetywZvkGK0LKzYlGOL2pCxUNqxCv0i8HbAxSuGUiQgUMOcwOBhAACgYBN | ||
| 25 | CU88X455Tye7eux1cYOJl0nM6S4Jx7cpB9MAED0L4OTgJVy8F11hEsamfKS6aQ1M | ||
| 26 | 7WxM77j8amGy6N7W6Mr213hQSF1irKUJ7lCMQyuzMOUm16UNAX0LTKF2MoZM/STG | ||
| 27 | h8uGwZyRy5C9woQp99PakMMokjLi9ZA7RTImXW+Mt6OBgzCBgDAdBgNVHQ4EFgQU | ||
| 28 | 4Qfbhpi5yqXaXuCLXj427mR25MkwHwYDVR0jBBgwFoAUE89Lp7uJLrM4Vxd2xput | ||
| 29 | aFvl7RcwDAYDVR0TAQH/BAIwADAOBgNVHQ8BAf8EBAMCBsAwIAYDVR0RBBkwF4EV | ||
| 30 | c21pbWVkc2ExQG9wZW5zc2wub3JnMA0GCSqGSIb3DQEBBQUAA4GBAFrdUzKK1pWO | ||
| 31 | kd02S423KUBc4GWWyiGlVoEO7WxVhHLJ8sm67X7OtJOwe0UGt+Nc5qLtyJYSirw8 | ||
| 32 | phjiTdNpQCTJ8+Kc56tWkJ6H7NAI4vTJtPL5BM/EmeYrVSU9JI9xhqpyKw9IBD+n | ||
| 33 | hRJ79W9FaiJRvaAOX+TkyTukJrxAWRyv | ||
| 34 | -----END CERTIFICATE----- | ||
diff --git a/src/lib/libssl/test/smime-certs/smdsa2.pem b/src/lib/libssl/test/smime-certs/smdsa2.pem new file mode 100644 index 0000000000..ef86c115d7 --- /dev/null +++ b/src/lib/libssl/test/smime-certs/smdsa2.pem | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | -----BEGIN DSA PRIVATE KEY----- | ||
| 2 | MIIBvAIBAAKBgQDFJfsIPOIawMO5biw+AoYUhNVxReBOLQosU3Qv4B8krac0BNr3 | ||
| 3 | OjSGLh1wZxHqhlAE0QmasTaKojuk20nNWeFnczSz6vDl0IVJEhS8VYor5kt9gLqt | ||
| 4 | GcoAgsf4gRDIutJyQDaNn3IVY89uXUVIoexvQeLQDBCgQPC5O8rJdqBwtwIVAK2J | ||
| 5 | jt+dqk07eQUE59koYUEKyNorAoGBAI4IEpusf8G14kCHmRtnHXM2tG5EWJDmW6Qt | ||
| 6 | wjqvWp1GKUx5WFy1tVWR9nl5rL0Di+kNdENo+SkKj7h3uDulGOI6T0mQYbV2h1IK | ||
| 7 | +FMOGnOqvZ8eNTE2n4PGTo5puZ63LBm+QYrQsrNiUY4vakLFQ2rEK/SLwdsDFK4Z | ||
| 8 | SJCBQw5zAoGBAIPmO8BtJ+Yac58trrPwq9b/6VW3jQTWzTLWSH84/QQdqQa+Pz3v | ||
| 9 | It/+hHM0daNF5uls8ICsPL1aLXmRx0pHvIyb0aAzYae4T4Jv/COPDMTdKbA1uitJ | ||
| 10 | VbkGZrm+LIrs7I9lOkb4T0vI6kL/XdOCXY1469zsqCgJ/O2ibn6mq0nWAhR716o2 | ||
| 11 | Nf8SimTZYB0/CKje6M5ufA== | ||
| 12 | -----END DSA PRIVATE KEY----- | ||
| 13 | -----BEGIN CERTIFICATE----- | ||
| 14 | MIIDpTCCAw6gAwIBAgIJAMtotfHYdEsXMA0GCSqGSIb3DQEBBQUAMEQxCzAJBgNV | ||
| 15 | BAYTAlVLMRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMR0wGwYDVQQDExRUZXN0IFMv | ||
| 16 | TUlNRSBSU0EgUm9vdDAeFw0wODAyMjIxMzUzMDlaFw0xNjA1MTAxMzUzMDlaMEUx | ||
| 17 | CzAJBgNVBAYTAlVLMRYwFAYDVQQKDA1PcGVuU1NMIEdyb3VwMR4wHAYDVQQDDBVU | ||
| 18 | ZXN0IFMvTUlNRSBFRSBEU0EgIzIwggG4MIIBLAYHKoZIzjgEATCCAR8CgYEAxSX7 | ||
| 19 | CDziGsDDuW4sPgKGFITVcUXgTi0KLFN0L+AfJK2nNATa9zo0hi4dcGcR6oZQBNEJ | ||
| 20 | mrE2iqI7pNtJzVnhZ3M0s+rw5dCFSRIUvFWKK+ZLfYC6rRnKAILH+IEQyLrSckA2 | ||
| 21 | jZ9yFWPPbl1FSKHsb0Hi0AwQoEDwuTvKyXagcLcCFQCtiY7fnapNO3kFBOfZKGFB | ||
| 22 | CsjaKwKBgQCOCBKbrH/BteJAh5kbZx1zNrRuRFiQ5lukLcI6r1qdRilMeVhctbVV | ||
| 23 | kfZ5eay9A4vpDXRDaPkpCo+4d7g7pRjiOk9JkGG1dodSCvhTDhpzqr2fHjUxNp+D | ||
| 24 | xk6OabmetywZvkGK0LKzYlGOL2pCxUNqxCv0i8HbAxSuGUiQgUMOcwOBhQACgYEA | ||
| 25 | g+Y7wG0n5hpzny2us/Cr1v/pVbeNBNbNMtZIfzj9BB2pBr4/Pe8i3/6EczR1o0Xm | ||
| 26 | 6WzwgKw8vVoteZHHSke8jJvRoDNhp7hPgm/8I48MxN0psDW6K0lVuQZmub4siuzs | ||
| 27 | j2U6RvhPS8jqQv9d04JdjXjr3OyoKAn87aJufqarSdajgYMwgYAwHQYDVR0OBBYE | ||
| 28 | FHsAGNfVltSYUq4hC+YVYwsYtA+dMB8GA1UdIwQYMBaAFBPPS6e7iS6zOFcXdsab | ||
| 29 | rWhb5e0XMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgbAMCAGA1UdEQQZMBeB | ||
| 30 | FXNtaW1lZHNhMkBvcGVuc3NsLm9yZzANBgkqhkiG9w0BAQUFAAOBgQCx9BtCbaYF | ||
| 31 | FXjLClkuKXbESaDZA1biPgY25i00FsUzARuhCpqD2v+0tu5c33ZzIhL6xlvBRU5l | ||
| 32 | 6Atw/xpZhae+hdBEtxPJoGekLLrHOau7Md3XwDjV4lFgcEJkWZoaSOOIK+4D5jF0 | ||
| 33 | jZWtHjnwEzuLYlo7ScHSsbcQfjH0M1TP5A== | ||
| 34 | -----END CERTIFICATE----- | ||
diff --git a/src/lib/libssl/test/smime-certs/smdsa3.pem b/src/lib/libssl/test/smime-certs/smdsa3.pem new file mode 100644 index 0000000000..eeb848dabc --- /dev/null +++ b/src/lib/libssl/test/smime-certs/smdsa3.pem | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | -----BEGIN DSA PRIVATE KEY----- | ||
| 2 | MIIBvAIBAAKBgQDFJfsIPOIawMO5biw+AoYUhNVxReBOLQosU3Qv4B8krac0BNr3 | ||
| 3 | OjSGLh1wZxHqhlAE0QmasTaKojuk20nNWeFnczSz6vDl0IVJEhS8VYor5kt9gLqt | ||
| 4 | GcoAgsf4gRDIutJyQDaNn3IVY89uXUVIoexvQeLQDBCgQPC5O8rJdqBwtwIVAK2J | ||
| 5 | jt+dqk07eQUE59koYUEKyNorAoGBAI4IEpusf8G14kCHmRtnHXM2tG5EWJDmW6Qt | ||
| 6 | wjqvWp1GKUx5WFy1tVWR9nl5rL0Di+kNdENo+SkKj7h3uDulGOI6T0mQYbV2h1IK | ||
| 7 | +FMOGnOqvZ8eNTE2n4PGTo5puZ63LBm+QYrQsrNiUY4vakLFQ2rEK/SLwdsDFK4Z | ||
| 8 | SJCBQw5zAoGAYzOpPmh8Je1IDauEXhgaLz14wqYUHHcrj2VWVJ6fRm8GhdQFJSI7 | ||
| 9 | GUk08pgKZSKic2lNqxuzW7/vFxKQ/nvzfytY16b+2i+BR4Q6yvMzCebE1hHVg0Ju | ||
| 10 | TwfUMwoFEOhYP6ZwHSUiQl9IBMH9TNJCMwYMxfY+VOrURFsjGTRUgpwCFQCIGt5g | ||
| 11 | Y+XZd0Sv69CatDIRYWvaIA== | ||
| 12 | -----END DSA PRIVATE KEY----- | ||
| 13 | -----BEGIN CERTIFICATE----- | ||
| 14 | MIIDpDCCAw2gAwIBAgIJAMtotfHYdEsYMA0GCSqGSIb3DQEBBQUAMEQxCzAJBgNV | ||
| 15 | BAYTAlVLMRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMR0wGwYDVQQDExRUZXN0IFMv | ||
| 16 | TUlNRSBSU0EgUm9vdDAeFw0wODAyMjIxMzUzMDlaFw0xNjA1MTAxMzUzMDlaMEUx | ||
| 17 | CzAJBgNVBAYTAlVLMRYwFAYDVQQKDA1PcGVuU1NMIEdyb3VwMR4wHAYDVQQDDBVU | ||
| 18 | ZXN0IFMvTUlNRSBFRSBEU0EgIzMwggG3MIIBLAYHKoZIzjgEATCCAR8CgYEAxSX7 | ||
| 19 | CDziGsDDuW4sPgKGFITVcUXgTi0KLFN0L+AfJK2nNATa9zo0hi4dcGcR6oZQBNEJ | ||
| 20 | mrE2iqI7pNtJzVnhZ3M0s+rw5dCFSRIUvFWKK+ZLfYC6rRnKAILH+IEQyLrSckA2 | ||
| 21 | jZ9yFWPPbl1FSKHsb0Hi0AwQoEDwuTvKyXagcLcCFQCtiY7fnapNO3kFBOfZKGFB | ||
| 22 | CsjaKwKBgQCOCBKbrH/BteJAh5kbZx1zNrRuRFiQ5lukLcI6r1qdRilMeVhctbVV | ||
| 23 | kfZ5eay9A4vpDXRDaPkpCo+4d7g7pRjiOk9JkGG1dodSCvhTDhpzqr2fHjUxNp+D | ||
| 24 | xk6OabmetywZvkGK0LKzYlGOL2pCxUNqxCv0i8HbAxSuGUiQgUMOcwOBhAACgYBj | ||
| 25 | M6k+aHwl7UgNq4ReGBovPXjCphQcdyuPZVZUnp9GbwaF1AUlIjsZSTTymAplIqJz | ||
| 26 | aU2rG7Nbv+8XEpD+e/N/K1jXpv7aL4FHhDrK8zMJ5sTWEdWDQm5PB9QzCgUQ6Fg/ | ||
| 27 | pnAdJSJCX0gEwf1M0kIzBgzF9j5U6tREWyMZNFSCnKOBgzCBgDAdBgNVHQ4EFgQU | ||
| 28 | VhpVXqQ/EzUMdxLvP7o9EhJ8h70wHwYDVR0jBBgwFoAUE89Lp7uJLrM4Vxd2xput | ||
| 29 | aFvl7RcwDAYDVR0TAQH/BAIwADAOBgNVHQ8BAf8EBAMCBsAwIAYDVR0RBBkwF4EV | ||
| 30 | c21pbWVkc2EzQG9wZW5zc2wub3JnMA0GCSqGSIb3DQEBBQUAA4GBACM9e75EQa8m | ||
| 31 | k/AZkH/tROqf3yeqijULl9x8FjFatqoY+29OM6oMGM425IqSkKd2ipz7OxO0SShu | ||
| 32 | rE0O3edS7DvYBwvhWPviRaYBMyZ4iFJVup+fOzoYK/j/bASxS3BHQBwb2r4rhe25 | ||
| 33 | OlTyyFEk7DJyW18YFOG97S1P52oQ5f5x | ||
| 34 | -----END CERTIFICATE----- | ||
diff --git a/src/lib/libssl/test/smime-certs/smdsap.pem b/src/lib/libssl/test/smime-certs/smdsap.pem new file mode 100644 index 0000000000..249706c8c7 --- /dev/null +++ b/src/lib/libssl/test/smime-certs/smdsap.pem | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | -----BEGIN DSA PARAMETERS----- | ||
| 2 | MIIBHwKBgQDFJfsIPOIawMO5biw+AoYUhNVxReBOLQosU3Qv4B8krac0BNr3OjSG | ||
| 3 | Lh1wZxHqhlAE0QmasTaKojuk20nNWeFnczSz6vDl0IVJEhS8VYor5kt9gLqtGcoA | ||
| 4 | gsf4gRDIutJyQDaNn3IVY89uXUVIoexvQeLQDBCgQPC5O8rJdqBwtwIVAK2Jjt+d | ||
| 5 | qk07eQUE59koYUEKyNorAoGBAI4IEpusf8G14kCHmRtnHXM2tG5EWJDmW6Qtwjqv | ||
| 6 | Wp1GKUx5WFy1tVWR9nl5rL0Di+kNdENo+SkKj7h3uDulGOI6T0mQYbV2h1IK+FMO | ||
| 7 | GnOqvZ8eNTE2n4PGTo5puZ63LBm+QYrQsrNiUY4vakLFQ2rEK/SLwdsDFK4ZSJCB | ||
| 8 | Qw5z | ||
| 9 | -----END DSA PARAMETERS----- | ||
diff --git a/src/lib/libssl/test/smime-certs/smroot.pem b/src/lib/libssl/test/smime-certs/smroot.pem new file mode 100644 index 0000000000..a59eb2684c --- /dev/null +++ b/src/lib/libssl/test/smime-certs/smroot.pem | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | -----BEGIN RSA PRIVATE KEY----- | ||
| 2 | MIICXAIBAAKBgQDBV1Z/Q5gPF7lojc8pKUdyz5+Jf2B3vs4he6egekugWnoJduki | ||
| 3 | 9Lnae/JchB/soIX0co3nLc11NuFFlnAWJNMDJr08l5AHAJLYNHevF5l/f9oDQwvZ | ||
| 4 | speKh1xpIAJNqCTzVeQ/ZLx6/GccIXV/xDuKIiovqJTPgR5WPkYKaw++lQIDAQAB | ||
| 5 | AoGALXnUj5SflJU4+B2652ydMKUjWl0KnL/VjkyejgGV/j6py8Ybaixz9q8Gv7oY | ||
| 6 | JDlRqMC1HfZJCFQDQrHy5VJ+CywA/H9WrqKo/Ch9U4tJAZtkig1Cmay/BAYixVu0 | ||
| 7 | xBeim10aKF6hxHH4Chg9We+OCuzWBWJhqveNjuDedL/i7JUCQQDlejovcwBUCbhJ | ||
| 8 | U12qKOwlaboolWbl7yF3XdckTJZg7+1UqQHZH5jYZlLZyZxiaC92SNV0SyTLJZnS | ||
| 9 | Jh5CO+VDAkEA16/pPcuVtMMz/R6SSPpRSIAa1stLs0mFSs3NpR4pdm0n42mu05pO | ||
| 10 | 1tJEt3a1g7zkreQBf53+Dwb+lA841EkjRwJBAIFmt0DifKDnCkBu/jZh9SfzwsH3 | ||
| 11 | 3Zpzik+hXxxdA7+ODCrdUul449vDd5zQD5t+XKU61QNLDGhxv5e9XvrCg7kCQH/a | ||
| 12 | 3ldsVF0oDaxxL+QkxoREtCQ5tLEd1u7F2q6Tl56FDE0pe6Ih6bQ8RtG+g9EI60IN | ||
| 13 | U7oTrOO5kLWx5E0q4ccCQAZVgoenn9MhRU1agKOCuM6LT2DxReTu4XztJzynej+8 | ||
| 14 | 0J93n3ebanB1MlRpn1XJwhQ7gAC8ImaQKLJK5jdJzFc= | ||
| 15 | -----END RSA PRIVATE KEY----- | ||
| 16 | -----BEGIN CERTIFICATE----- | ||
| 17 | MIICaTCCAdKgAwIBAgIJAP6VN47boiXRMA0GCSqGSIb3DQEBBQUAMEQxCzAJBgNV | ||
| 18 | BAYTAlVLMRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMR0wGwYDVQQDExRUZXN0IFMv | ||
| 19 | TUlNRSBSU0EgUm9vdDAeFw0wODAyMjIxMzUzMDdaFw0xNjA1MTExMzUzMDdaMEQx | ||
| 20 | CzAJBgNVBAYTAlVLMRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMR0wGwYDVQQDExRU | ||
| 21 | ZXN0IFMvTUlNRSBSU0EgUm9vdDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA | ||
| 22 | wVdWf0OYDxe5aI3PKSlHcs+fiX9gd77OIXunoHpLoFp6CXbpIvS52nvyXIQf7KCF | ||
| 23 | 9HKN5y3NdTbhRZZwFiTTAya9PJeQBwCS2DR3rxeZf3/aA0ML2bKXiodcaSACTagk | ||
| 24 | 81XkP2S8evxnHCF1f8Q7iiIqL6iUz4EeVj5GCmsPvpUCAwEAAaNjMGEwHQYDVR0O | ||
| 25 | BBYEFBPPS6e7iS6zOFcXdsabrWhb5e0XMB8GA1UdIwQYMBaAFBPPS6e7iS6zOFcX | ||
| 26 | dsabrWhb5e0XMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgEGMA0GCSqG | ||
| 27 | SIb3DQEBBQUAA4GBAIECprq5viDvnDbkyOaiSr9ubMUmWqvycfAJMdPZRKcOZczS | ||
| 28 | l+L9R9lF3JSqbt3knOe9u6bGDBOTY2285PdCCuHRVMk2Af1f6El1fqAlRUwNqipp | ||
| 29 | r68sWFuRqrcRNtk6QQvXfkOhrqQBuDa7te/OVQLa2lGN9Dr2mQsD8ijctatG | ||
| 30 | -----END CERTIFICATE----- | ||
diff --git a/src/lib/libssl/test/smime-certs/smrsa1.pem b/src/lib/libssl/test/smime-certs/smrsa1.pem new file mode 100644 index 0000000000..2cf3148e33 --- /dev/null +++ b/src/lib/libssl/test/smime-certs/smrsa1.pem | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | -----BEGIN RSA PRIVATE KEY----- | ||
| 2 | MIICXgIBAAKBgQC6A978j4pmPgUtUQqF+bjh6vdhwGOGZSD7xXgFTMjm88twfv+E | ||
| 3 | ixkq2KXSDjD0ZXoQbdOaSbvGRQrIJpG2NGiKAFdYNrP025kCCdh5wF/aEI7KLEm7 | ||
| 4 | JlHwXpQsuj4wkMgmkFjL3Ty4Z55aNH+2pPQIa0k+ENJXm2gDuhqgBmduAwIDAQAB | ||
| 5 | AoGBAJMuYu51aO2THyeHGwt81uOytcCbqGP7eoib62ZOJhxPRGYjpmuqX+R9/V5i | ||
| 6 | KiwGavm63JYUx0WO9YP+uIZxm1BUATzkgkS74u5LP6ajhkZh6/Bck1oIYYkbVOXl | ||
| 7 | JVrdENuH6U7nupznsyYgONByo+ykFPVUGmutgiaC7NMVo/MxAkEA6KLejWXdCIEn | ||
| 8 | xr7hGph9NlvY9xuRIMexRV/WrddcFfCdjI1PciIupgrIkR65M9yr7atm1iU6/aRf | ||
| 9 | KOr8rLZsSQJBAMyyXN71NsDNx4BP6rtJ/LJMP0BylznWkA7zWfGCbAYn9VhZVlSY | ||
| 10 | Eu9Gyr7quD1ix7G3kInKVYOEEOpockBLz+sCQQCedyMmKjcQLfpMVYW8uhbAynvW | ||
| 11 | h36qV5yXZxszO7nMcCTBsxhk5IfmLv5EbCs3+p9avCDGyoGOeUMg+kC33WORAkAg | ||
| 12 | oUIarH4o5+SoeJTTfCzTA0KF9H5U0vYt2+73h7HOnWoHxl3zqDZEfEVvf50U8/0f | ||
| 13 | QELDJETTbScBJtsnkq43AkEA38etvoZ2i4FJvvo7R/9gWBHVEcrGzcsCBYrNnIR1 | ||
| 14 | SZLRwHEGaiOK1wxMsWzqp7PJwL9z/M8A8DyOFBx3GPOniA== | ||
| 15 | -----END RSA PRIVATE KEY----- | ||
| 16 | -----BEGIN CERTIFICATE----- | ||
| 17 | MIICizCCAfSgAwIBAgIJAMtotfHYdEsTMA0GCSqGSIb3DQEBBQUAMEQxCzAJBgNV | ||
| 18 | BAYTAlVLMRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMR0wGwYDVQQDExRUZXN0IFMv | ||
| 19 | TUlNRSBSU0EgUm9vdDAeFw0wODAyMjIxMzUzMDhaFw0xNjA1MTAxMzUzMDhaMEUx | ||
| 20 | CzAJBgNVBAYTAlVLMRYwFAYDVQQKDA1PcGVuU1NMIEdyb3VwMR4wHAYDVQQDDBVU | ||
| 21 | ZXN0IFMvTUlNRSBFRSBSU0EgIzEwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGB | ||
| 22 | ALoD3vyPimY+BS1RCoX5uOHq92HAY4ZlIPvFeAVMyObzy3B+/4SLGSrYpdIOMPRl | ||
| 23 | ehBt05pJu8ZFCsgmkbY0aIoAV1g2s/TbmQIJ2HnAX9oQjsosSbsmUfBelCy6PjCQ | ||
| 24 | yCaQWMvdPLhnnlo0f7ak9AhrST4Q0lebaAO6GqAGZ24DAgMBAAGjgYMwgYAwHQYD | ||
| 25 | VR0OBBYEFE2vMvKz5jrC7Lbdg68XwZ95iL/QMB8GA1UdIwQYMBaAFBPPS6e7iS6z | ||
| 26 | OFcXdsabrWhb5e0XMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgXgMCAGA1Ud | ||
| 27 | EQQZMBeBFXNtaW1lcnNhMUBvcGVuc3NsLm9yZzANBgkqhkiG9w0BAQUFAAOBgQAi | ||
| 28 | O3GOkUl646oLnOimc36i9wxZ1tejsqs8vMjJ0Pym6Uq9FE2JoGzJ6OhB1GOsEVmj | ||
| 29 | 9cQ5UNQcRYL3cqOFtl6f4Dpu/lhzfbaqgmLjv29G1mS0uuTZrixhlyCXjwcbOkNC | ||
| 30 | I/+wvHHENYIK5+T/79M9LaZ2Qk4F9MNE1VMljdz9Qw== | ||
| 31 | -----END CERTIFICATE----- | ||
diff --git a/src/lib/libssl/test/smime-certs/smrsa2.pem b/src/lib/libssl/test/smime-certs/smrsa2.pem new file mode 100644 index 0000000000..d41f69c82f --- /dev/null +++ b/src/lib/libssl/test/smime-certs/smrsa2.pem | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | -----BEGIN RSA PRIVATE KEY----- | ||
| 2 | MIICWwIBAAKBgQCwBfryW4Vu5U9wNIDKspJO/N9YF4CcTlrCUyzVlKgb+8urHlSe | ||
| 3 | 59i5verR9IOCCXkemjOzZ/3nALTGqYZlnEvHp0Rjk+KdKXnKBIB+SRPpeu3LcXMT | ||
| 4 | WPgsThPa0UQxedNKG0g6aG+kLhsDlFBCoxd09jJtSpb9jmroJOq0ZYEHLwIDAQAB | ||
| 5 | AoGAKa/w4677Je1W5+r3SYoLDnvi5TkDs4D3C6ipKJgBTEdQz+DqB4w/DpZE4551 | ||
| 6 | +rkFn1LDxcxuHGRVa+tAMhZW97fwq9YUbjVZEyOz79qrX+BMyl/NbHkf1lIKDo3q | ||
| 7 | dWalzQvop7nbzeLC+VmmviwZfLQUbA61AQl3jm4dswT4XykCQQDloDadEv/28NTx | ||
| 8 | bvvywvyGuvJkCkEIycm4JrIInvwsd76h/chZ3oymrqzc7hkEtK6kThqlS5y+WXl6 | ||
| 9 | QzPruTKTAkEAxD2ro/VUoN+scIVaLmn0RBmZ67+9Pdn6pNSfjlK3s0T0EM6/iUWS | ||
| 10 | M06l6L9wFS3/ceu1tIifsh9BeqOGTa+udQJARIFnybTBaIqw/NZ/lA1YCVn8tpvY | ||
| 11 | iyaoZ6gjtS65TQrsdKeh/i3HCHNUXxUpoZ3F/H7QtD+6o49ODou+EbVOwQJAVmex | ||
| 12 | A2gp8wuJKaINqxIL81AybZLnCCzKJ3lXJ5tUNyLNM/lUbGStktm2Q1zHRQwTxV07 | ||
| 13 | jFn7trn8YrtNjzcjYQJAUKIJRt38A8Jw3HoPT+D0WS2IgxjVL0eYGsZX1lyeammG | ||
| 14 | 6rfnQ3u5uP7mEK2EH2o8mDUpAE0gclWBU9UkKxJsGA== | ||
| 15 | -----END RSA PRIVATE KEY----- | ||
| 16 | -----BEGIN CERTIFICATE----- | ||
| 17 | MIICizCCAfSgAwIBAgIJAMtotfHYdEsUMA0GCSqGSIb3DQEBBQUAMEQxCzAJBgNV | ||
| 18 | BAYTAlVLMRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMR0wGwYDVQQDExRUZXN0IFMv | ||
| 19 | TUlNRSBSU0EgUm9vdDAeFw0wODAyMjIxMzUzMDhaFw0xNjA1MTAxMzUzMDhaMEUx | ||
| 20 | CzAJBgNVBAYTAlVLMRYwFAYDVQQKDA1PcGVuU1NMIEdyb3VwMR4wHAYDVQQDDBVU | ||
| 21 | ZXN0IFMvTUlNRSBFRSBSU0EgIzIwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGB | ||
| 22 | ALAF+vJbhW7lT3A0gMqykk7831gXgJxOWsJTLNWUqBv7y6seVJ7n2Lm96tH0g4IJ | ||
| 23 | eR6aM7Nn/ecAtMaphmWcS8enRGOT4p0pecoEgH5JE+l67ctxcxNY+CxOE9rRRDF5 | ||
| 24 | 00obSDpob6QuGwOUUEKjF3T2Mm1Klv2Oaugk6rRlgQcvAgMBAAGjgYMwgYAwHQYD | ||
| 25 | VR0OBBYEFIL/u+mEvaw7RuKLRuElfVkxSQjYMB8GA1UdIwQYMBaAFBPPS6e7iS6z | ||
| 26 | OFcXdsabrWhb5e0XMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgXgMCAGA1Ud | ||
| 27 | EQQZMBeBFXNtaW1lcnNhMkBvcGVuc3NsLm9yZzANBgkqhkiG9w0BAQUFAAOBgQC2 | ||
| 28 | rXR5bm/9RtOMQPleNpd3y6uUX3oy+0CafK5Yl3PMnItjjnKJ0l1/DbLbDj2twehe | ||
| 29 | ewaB8CROcBCA3AMLSmGvPKgUCFMGtWam3328M4fBHzon5ka7qDXzM+imkAly/Yx2 | ||
| 30 | YNdR/aNOug+5sXygHmTSKqiCpQjOIClzXoPVVeEVHw== | ||
| 31 | -----END CERTIFICATE----- | ||
diff --git a/src/lib/libssl/test/smime-certs/smrsa3.pem b/src/lib/libssl/test/smime-certs/smrsa3.pem new file mode 100644 index 0000000000..c8cbe55151 --- /dev/null +++ b/src/lib/libssl/test/smime-certs/smrsa3.pem | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | -----BEGIN RSA PRIVATE KEY----- | ||
| 2 | MIICXAIBAAKBgQC6syTZtZNe1hRScFc4PUVyVLsr7+C1HDIZnOHmwFoLayX6RHwy | ||
| 3 | ep/TkdwiPHnemVLuwvpSjLMLZkXy/J764kSHJrNeVl3UvmCVCOm40hAtK1+F39pM | ||
| 4 | h8phkbPPD7i+hwq4/Vs79o46nzwbVKmzgoZBJhZ+codujUSYM3LjJ4aq+wIDAQAB | ||
| 5 | AoGAE1Zixrnr3bLGwBMqtYSDIOhtyos59whImCaLr17U9MHQWS+mvYO98if1aQZi | ||
| 6 | iQ/QazJ+wvYXxWJ+dEB+JvYwqrGeuAU6He/rAb4OShG4FPVU2D19gzRnaButWMeT | ||
| 7 | /1lgXV08hegGBL7RQNaN7b0viFYMcKnSghleMP0/q+Y/oaECQQDkXEwDYJW13X9p | ||
| 8 | ijS20ykWdY5lLknjkHRhhOYux0rlhOqsyMZjoUmwI2m0qj9yrIysKhrk4MZaM/uC | ||
| 9 | hy0xp3hdAkEA0Uv/UY0Kwsgc+W6YxeypECtg1qCE6FBib8n4iFy/6VcWqhvE5xrs | ||
| 10 | OdhKv9/p6aLjLneGd1sU+F8eS9LGyKIbNwJBAJPgbNzXA7uUZriqZb5qeTXxBDfj | ||
| 11 | RLfXSHYKAKEULxz3+JvRHB9SR4yHMiFrCdExiZrHXUkPgYLSHLGG5a4824UCQD6T | ||
| 12 | 9XvhquUARkGCAuWy0/3Eqoihp/t6BWSdQ9Upviu7YUhtUxsyXo0REZB7F4pGrJx5 | ||
| 13 | GlhXgFaewgUzuUHFzlMCQCzJMMWslWpoLntnR6sMhBMhBFHSw+Y5CbxBmFrdtSkd | ||
| 14 | VdtNO1VuDCTxjjW7W3Khj7LX4KZ1ye/5jfAgnnnXisc= | ||
| 15 | -----END RSA PRIVATE KEY----- | ||
| 16 | -----BEGIN CERTIFICATE----- | ||
| 17 | MIICizCCAfSgAwIBAgIJAMtotfHYdEsVMA0GCSqGSIb3DQEBBQUAMEQxCzAJBgNV | ||
| 18 | BAYTAlVLMRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMR0wGwYDVQQDExRUZXN0IFMv | ||
| 19 | TUlNRSBSU0EgUm9vdDAeFw0wODAyMjIxMzUzMDlaFw0xNjA1MTAxMzUzMDlaMEUx | ||
| 20 | CzAJBgNVBAYTAlVLMRYwFAYDVQQKDA1PcGVuU1NMIEdyb3VwMR4wHAYDVQQDDBVU | ||
| 21 | ZXN0IFMvTUlNRSBFRSBSU0EgIzMwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGB | ||
| 22 | ALqzJNm1k17WFFJwVzg9RXJUuyvv4LUcMhmc4ebAWgtrJfpEfDJ6n9OR3CI8ed6Z | ||
| 23 | Uu7C+lKMswtmRfL8nvriRIcms15WXdS+YJUI6bjSEC0rX4Xf2kyHymGRs88PuL6H | ||
| 24 | Crj9Wzv2jjqfPBtUqbOChkEmFn5yh26NRJgzcuMnhqr7AgMBAAGjgYMwgYAwHQYD | ||
| 25 | VR0OBBYEFDsSFjNtYZzd0tTHafNS7tneQQj6MB8GA1UdIwQYMBaAFBPPS6e7iS6z | ||
| 26 | OFcXdsabrWhb5e0XMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgXgMCAGA1Ud | ||
| 27 | EQQZMBeBFXNtaW1lcnNhM0BvcGVuc3NsLm9yZzANBgkqhkiG9w0BAQUFAAOBgQBE | ||
| 28 | tUDB+1Dqigu4p1xtdq7JRK6S+gfA7RWmhz0j2scb2zhpS12h37JLHsidGeKAzZYq | ||
| 29 | jUjOrH/j3xcV5AnuJoqImJaN23nzzxtR4qGGX2mrq6EtObzdEGgCUaizsGM+0slJ | ||
| 30 | PYxcy8KeY/63B1BpYhj2RjGkL6HrvuAaxVORa3acoA== | ||
| 31 | -----END CERTIFICATE----- | ||
diff --git a/src/lib/libssl/test/tcrl b/src/lib/libssl/test/tcrl index 3ffed12a03..055269eab8 100644 --- a/src/lib/libssl/test/tcrl +++ b/src/lib/libssl/test/tcrl | |||
| @@ -1,12 +1,5 @@ | |||
| 1 | #!/bin/sh | 1 | #!/bin/sh |
| 2 | 2 | ||
| 3 | if test "$OSTYPE" = msdosdjgpp; then | ||
| 4 | PATH=../apps\;$PATH | ||
| 5 | else | ||
| 6 | PATH=../apps:$PATH | ||
| 7 | fi | ||
| 8 | export PATH | ||
| 9 | |||
| 10 | cmd='../util/shlib_wrap.sh ../apps/openssl crl' | 3 | cmd='../util/shlib_wrap.sh ../apps/openssl crl' |
| 11 | 4 | ||
| 12 | if [ "$1"x != "x" ]; then | 5 | if [ "$1"x != "x" ]; then |
diff --git a/src/lib/libssl/test/testca b/src/lib/libssl/test/testca index 5b2faa78f1..b109cfe271 100644 --- a/src/lib/libssl/test/testca +++ b/src/lib/libssl/test/testca | |||
| @@ -2,16 +2,16 @@ | |||
| 2 | 2 | ||
| 3 | SH="/bin/sh" | 3 | SH="/bin/sh" |
| 4 | if test "$OSTYPE" = msdosdjgpp; then | 4 | if test "$OSTYPE" = msdosdjgpp; then |
| 5 | PATH=./apps\;../apps\;$PATH | 5 | PATH="../apps\;$PATH" |
| 6 | else | 6 | else |
| 7 | PATH=../apps:$PATH | 7 | PATH="../apps:$PATH" |
| 8 | fi | 8 | fi |
| 9 | export SH PATH | 9 | export SH PATH |
| 10 | 10 | ||
| 11 | SSLEAY_CONFIG="-config CAss.cnf" | 11 | SSLEAY_CONFIG="-config CAss.cnf" |
| 12 | export SSLEAY_CONFIG | 12 | export SSLEAY_CONFIG |
| 13 | 13 | ||
| 14 | OPENSSL="`pwd`/../util/shlib_wrap.sh openssl" | 14 | OPENSSL="`pwd`/../util/opensslwrap.sh" |
| 15 | export OPENSSL | 15 | export OPENSSL |
| 16 | 16 | ||
| 17 | /bin/rm -fr demoCA | 17 | /bin/rm -fr demoCA |
diff --git a/src/lib/libssl/test/testenc b/src/lib/libssl/test/testenc index 4571ea2875..f5ce7c0c45 100644 --- a/src/lib/libssl/test/testenc +++ b/src/lib/libssl/test/testenc | |||
| @@ -7,8 +7,8 @@ cmd="../util/shlib_wrap.sh ../apps/openssl" | |||
| 7 | cat $testsrc >$test; | 7 | cat $testsrc >$test; |
| 8 | 8 | ||
| 9 | echo cat | 9 | echo cat |
| 10 | $cmd enc -non-fips-allow < $test > $test.cipher | 10 | $cmd enc < $test > $test.cipher |
| 11 | $cmd enc -non-fips-allow < $test.cipher >$test.clear | 11 | $cmd enc < $test.cipher >$test.clear |
| 12 | cmp $test $test.clear | 12 | cmp $test $test.clear |
| 13 | if [ $? != 0 ] | 13 | if [ $? != 0 ] |
| 14 | then | 14 | then |
| @@ -17,8 +17,8 @@ else | |||
| 17 | /bin/rm $test.cipher $test.clear | 17 | /bin/rm $test.cipher $test.clear |
| 18 | fi | 18 | fi |
| 19 | echo base64 | 19 | echo base64 |
| 20 | $cmd enc -non-fips-allow -a -e < $test > $test.cipher | 20 | $cmd enc -a -e < $test > $test.cipher |
| 21 | $cmd enc -non-fips-allow -a -d < $test.cipher >$test.clear | 21 | $cmd enc -a -d < $test.cipher >$test.clear |
| 22 | cmp $test $test.clear | 22 | cmp $test $test.clear |
| 23 | if [ $? != 0 ] | 23 | if [ $? != 0 ] |
| 24 | then | 24 | then |
| @@ -30,8 +30,8 @@ fi | |||
| 30 | for i in `$cmd list-cipher-commands` | 30 | for i in `$cmd list-cipher-commands` |
| 31 | do | 31 | do |
| 32 | echo $i | 32 | echo $i |
| 33 | $cmd $i -non-fips-allow -bufsize 113 -e -k test < $test > $test.$i.cipher | 33 | $cmd $i -bufsize 113 -e -k test < $test > $test.$i.cipher |
| 34 | $cmd $i -non-fips-allow -bufsize 157 -d -k test < $test.$i.cipher >$test.$i.clear | 34 | $cmd $i -bufsize 157 -d -k test < $test.$i.cipher >$test.$i.clear |
| 35 | cmp $test $test.$i.clear | 35 | cmp $test $test.$i.clear |
| 36 | if [ $? != 0 ] | 36 | if [ $? != 0 ] |
| 37 | then | 37 | then |
| @@ -41,8 +41,8 @@ do | |||
| 41 | fi | 41 | fi |
| 42 | 42 | ||
| 43 | echo $i base64 | 43 | echo $i base64 |
| 44 | $cmd $i -non-fips-allow -bufsize 113 -a -e -k test < $test > $test.$i.cipher | 44 | $cmd $i -bufsize 113 -a -e -k test < $test > $test.$i.cipher |
| 45 | $cmd $i -non-fips-allow -bufsize 157 -a -d -k test < $test.$i.cipher >$test.$i.clear | 45 | $cmd $i -bufsize 157 -a -d -k test < $test.$i.cipher >$test.$i.clear |
| 46 | cmp $test $test.$i.clear | 46 | cmp $test $test.$i.clear |
| 47 | if [ $? != 0 ] | 47 | if [ $? != 0 ] |
| 48 | then | 48 | then |
diff --git a/src/lib/libssl/test/tpkcs7 b/src/lib/libssl/test/tpkcs7 index 79bb6e0edf..3e435ffbf9 100644 --- a/src/lib/libssl/test/tpkcs7 +++ b/src/lib/libssl/test/tpkcs7 | |||
| @@ -1,12 +1,5 @@ | |||
| 1 | #!/bin/sh | 1 | #!/bin/sh |
| 2 | 2 | ||
| 3 | if test "$OSTYPE" = msdosdjgpp; then | ||
| 4 | PATH=../apps\;$PATH | ||
| 5 | else | ||
| 6 | PATH=../apps:$PATH | ||
| 7 | fi | ||
| 8 | export PATH | ||
| 9 | |||
| 10 | cmd='../util/shlib_wrap.sh ../apps/openssl pkcs7' | 3 | cmd='../util/shlib_wrap.sh ../apps/openssl pkcs7' |
| 11 | 4 | ||
| 12 | if [ "$1"x != "x" ]; then | 5 | if [ "$1"x != "x" ]; then |
diff --git a/src/lib/libssl/test/tpkcs7d b/src/lib/libssl/test/tpkcs7d index 20394b34c4..64fc28e88f 100644 --- a/src/lib/libssl/test/tpkcs7d +++ b/src/lib/libssl/test/tpkcs7d | |||
| @@ -1,12 +1,5 @@ | |||
| 1 | #!/bin/sh | 1 | #!/bin/sh |
| 2 | 2 | ||
| 3 | if test "$OSTYPE" = msdosdjgpp; then | ||
| 4 | PATH=../apps\;$PATH | ||
| 5 | else | ||
| 6 | PATH=../apps:$PATH | ||
| 7 | fi | ||
| 8 | export PATH | ||
| 9 | |||
| 10 | cmd='../util/shlib_wrap.sh ../apps/openssl pkcs7' | 3 | cmd='../util/shlib_wrap.sh ../apps/openssl pkcs7' |
| 11 | 4 | ||
| 12 | if [ "$1"x != "x" ]; then | 5 | if [ "$1"x != "x" ]; then |
diff --git a/src/lib/libssl/test/treq b/src/lib/libssl/test/treq index 7e020210a5..77f37dcf3a 100644 --- a/src/lib/libssl/test/treq +++ b/src/lib/libssl/test/treq | |||
| @@ -1,12 +1,5 @@ | |||
| 1 | #!/bin/sh | 1 | #!/bin/sh |
| 2 | 2 | ||
| 3 | if test "$OSTYPE" = msdosdjgpp; then | ||
| 4 | PATH=../apps\;$PATH | ||
| 5 | else | ||
| 6 | PATH=../apps:$PATH | ||
| 7 | fi | ||
| 8 | export PATH | ||
| 9 | |||
| 10 | cmd='../util/shlib_wrap.sh ../apps/openssl req -config ../apps/openssl.cnf' | 3 | cmd='../util/shlib_wrap.sh ../apps/openssl req -config ../apps/openssl.cnf' |
| 11 | 4 | ||
| 12 | if [ "$1"x != "x" ]; then | 5 | if [ "$1"x != "x" ]; then |
| @@ -15,7 +8,7 @@ else | |||
| 15 | t=testreq.pem | 8 | t=testreq.pem |
| 16 | fi | 9 | fi |
| 17 | 10 | ||
| 18 | if $cmd -in $t -inform p -noout -text | fgrep 'Unknown Public Key'; then | 11 | if $cmd -in $t -inform p -noout -text 2>&1 | fgrep -i 'Unknown Public Key'; then |
| 19 | echo "skipping req conversion test for $t" | 12 | echo "skipping req conversion test for $t" |
| 20 | exit 0 | 13 | exit 0 |
| 21 | fi | 14 | fi |
diff --git a/src/lib/libssl/test/trsa b/src/lib/libssl/test/trsa index 67b4a98841..249ac1ddcc 100644 --- a/src/lib/libssl/test/trsa +++ b/src/lib/libssl/test/trsa | |||
| @@ -1,12 +1,5 @@ | |||
| 1 | #!/bin/sh | 1 | #!/bin/sh |
| 2 | 2 | ||
| 3 | if test "$OSTYPE" = msdosdjgpp; then | ||
| 4 | PATH=../apps\;$PATH | ||
| 5 | else | ||
| 6 | PATH=../apps:$PATH | ||
| 7 | fi | ||
| 8 | export PATH | ||
| 9 | |||
| 10 | if ../util/shlib_wrap.sh ../apps/openssl no-rsa; then | 3 | if ../util/shlib_wrap.sh ../apps/openssl no-rsa; then |
| 11 | echo skipping rsa conversion test | 4 | echo skipping rsa conversion test |
| 12 | exit 0 | 5 | exit 0 |
diff --git a/src/lib/libssl/test/tsid b/src/lib/libssl/test/tsid index fb4a7213b9..6adbd531ce 100644 --- a/src/lib/libssl/test/tsid +++ b/src/lib/libssl/test/tsid | |||
| @@ -1,12 +1,5 @@ | |||
| 1 | #!/bin/sh | 1 | #!/bin/sh |
| 2 | 2 | ||
| 3 | if test "$OSTYPE" = msdosdjgpp; then | ||
| 4 | PATH=../apps\;$PATH | ||
| 5 | else | ||
| 6 | PATH=../apps:$PATH | ||
| 7 | fi | ||
| 8 | export PATH | ||
| 9 | |||
| 10 | cmd='../util/shlib_wrap.sh ../apps/openssl sess_id' | 3 | cmd='../util/shlib_wrap.sh ../apps/openssl sess_id' |
| 11 | 4 | ||
| 12 | if [ "$1"x != "x" ]; then | 5 | if [ "$1"x != "x" ]; then |
diff --git a/src/lib/libssl/test/tx509 b/src/lib/libssl/test/tx509 index 1b9c8661f3..4a15b98d17 100644 --- a/src/lib/libssl/test/tx509 +++ b/src/lib/libssl/test/tx509 | |||
| @@ -1,12 +1,5 @@ | |||
| 1 | #!/bin/sh | 1 | #!/bin/sh |
| 2 | 2 | ||
| 3 | if test "$OSTYPE" = msdosdjgpp; then | ||
| 4 | PATH=../apps\;$PATH | ||
| 5 | else | ||
| 6 | PATH=../apps:$PATH | ||
| 7 | fi | ||
| 8 | export PATH | ||
| 9 | |||
| 10 | cmd='../util/shlib_wrap.sh ../apps/openssl x509' | 3 | cmd='../util/shlib_wrap.sh ../apps/openssl x509' |
| 11 | 4 | ||
| 12 | if [ "$1"x != "x" ]; then | 5 | if [ "$1"x != "x" ]; then |
diff --git a/src/lib/libssl/tls1.h b/src/lib/libssl/tls1.h index 38838ea9a5..2d1d293e1a 100644 --- a/src/lib/libssl/tls1.h +++ b/src/lib/libssl/tls1.h | |||
| @@ -55,6 +55,19 @@ | |||
| 55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
| 56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
| 57 | */ | 57 | */ |
| 58 | /* ==================================================================== | ||
| 59 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
| 60 | * | ||
| 61 | * Portions of the attached software ("Contribution") are developed by | ||
| 62 | * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. | ||
| 63 | * | ||
| 64 | * The Contribution is licensed pursuant to the OpenSSL open source | ||
| 65 | * license provided above. | ||
| 66 | * | ||
| 67 | * ECC cipher suite support in OpenSSL originally written by | ||
| 68 | * Vipul Gupta and Sumit Gupta of Sun Microsystems Laboratories. | ||
| 69 | * | ||
| 70 | */ | ||
| 58 | 71 | ||
| 59 | #ifndef HEADER_TLS1_H | 72 | #ifndef HEADER_TLS1_H |
| 60 | #define HEADER_TLS1_H | 73 | #define HEADER_TLS1_H |
| @@ -65,7 +78,7 @@ | |||
| 65 | extern "C" { | 78 | extern "C" { |
| 66 | #endif | 79 | #endif |
| 67 | 80 | ||
| 68 | #define TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES 1 | 81 | #define TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES 0 |
| 69 | 82 | ||
| 70 | #define TLS1_VERSION 0x0301 | 83 | #define TLS1_VERSION 0x0301 |
| 71 | #define TLS1_VERSION_MAJOR 0x03 | 84 | #define TLS1_VERSION_MAJOR 0x03 |
| @@ -83,6 +96,93 @@ extern "C" { | |||
| 83 | #define TLS1_AD_INTERNAL_ERROR 80 /* fatal */ | 96 | #define TLS1_AD_INTERNAL_ERROR 80 /* fatal */ |
| 84 | #define TLS1_AD_USER_CANCELLED 90 | 97 | #define TLS1_AD_USER_CANCELLED 90 |
| 85 | #define TLS1_AD_NO_RENEGOTIATION 100 | 98 | #define TLS1_AD_NO_RENEGOTIATION 100 |
| 99 | /* codes 110-114 are from RFC3546 */ | ||
| 100 | #define TLS1_AD_UNSUPPORTED_EXTENSION 110 | ||
| 101 | #define TLS1_AD_CERTIFICATE_UNOBTAINABLE 111 | ||
| 102 | #define TLS1_AD_UNRECOGNIZED_NAME 112 | ||
| 103 | #define TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE 113 | ||
| 104 | #define TLS1_AD_BAD_CERTIFICATE_HASH_VALUE 114 | ||
| 105 | #define TLS1_AD_UNKNOWN_PSK_IDENTITY 115 /* fatal */ | ||
| 106 | |||
| 107 | /* ExtensionType values from RFC 3546 */ | ||
| 108 | #define TLSEXT_TYPE_server_name 0 | ||
| 109 | #define TLSEXT_TYPE_max_fragment_length 1 | ||
| 110 | #define TLSEXT_TYPE_client_certificate_url 2 | ||
| 111 | #define TLSEXT_TYPE_trusted_ca_keys 3 | ||
| 112 | #define TLSEXT_TYPE_truncated_hmac 4 | ||
| 113 | #define TLSEXT_TYPE_status_request 5 | ||
| 114 | #define TLSEXT_TYPE_elliptic_curves 10 | ||
| 115 | #define TLSEXT_TYPE_ec_point_formats 11 | ||
| 116 | #define TLSEXT_TYPE_session_ticket 35 | ||
| 117 | |||
| 118 | /* NameType value from RFC 3546 */ | ||
| 119 | #define TLSEXT_NAMETYPE_host_name 0 | ||
| 120 | /* status request value from RFC 3546 */ | ||
| 121 | #define TLSEXT_STATUSTYPE_ocsp 1 | ||
| 122 | |||
| 123 | #ifndef OPENSSL_NO_TLSEXT | ||
| 124 | |||
| 125 | #define TLSEXT_MAXLEN_host_name 255 | ||
| 126 | |||
| 127 | const char *SSL_get_servername(const SSL *s, const int type) ; | ||
| 128 | int SSL_get_servername_type(const SSL *s) ; | ||
| 129 | |||
| 130 | #define SSL_set_tlsext_host_name(s,name) \ | ||
| 131 | SSL_ctrl(s,SSL_CTRL_SET_TLSEXT_HOSTNAME,TLSEXT_NAMETYPE_host_name,(char *)name) | ||
| 132 | |||
| 133 | #define SSL_set_tlsext_debug_callback(ssl, cb) \ | ||
| 134 | SSL_callback_ctrl(ssl,SSL_CTRL_SET_TLSEXT_DEBUG_CB,(void (*)(void))cb) | ||
| 135 | |||
| 136 | #define SSL_set_tlsext_debug_arg(ssl, arg) \ | ||
| 137 | SSL_ctrl(ssl,SSL_CTRL_SET_TLSEXT_DEBUG_ARG,0, (void *)arg) | ||
| 138 | |||
| 139 | #define SSL_set_tlsext_status_type(ssl, type) \ | ||
| 140 | SSL_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE,type, NULL) | ||
| 141 | |||
| 142 | #define SSL_get_tlsext_status_exts(ssl, arg) \ | ||
| 143 | SSL_ctrl(ssl,SSL_CTRL_GET_TLSEXT_STATUS_REQ_EXTS,0, (void *)arg) | ||
| 144 | |||
| 145 | #define SSL_set_tlsext_status_exts(ssl, arg) \ | ||
| 146 | SSL_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_EXTS,0, (void *)arg) | ||
| 147 | |||
| 148 | #define SSL_get_tlsext_status_ids(ssl, arg) \ | ||
| 149 | SSL_ctrl(ssl,SSL_CTRL_GET_TLSEXT_STATUS_REQ_IDS,0, (void *)arg) | ||
| 150 | |||
| 151 | #define SSL_set_tlsext_status_ids(ssl, arg) \ | ||
| 152 | SSL_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_IDS,0, (void *)arg) | ||
| 153 | |||
| 154 | #define SSL_get_tlsext_status_ocsp_resp(ssl, arg) \ | ||
| 155 | SSL_ctrl(ssl,SSL_CTRL_GET_TLSEXT_STATUS_REQ_OCSP_RESP,0, (void *)arg) | ||
| 156 | |||
| 157 | #define SSL_set_tlsext_status_ocsp_resp(ssl, arg, arglen) \ | ||
| 158 | SSL_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_OCSP_RESP,arglen, (void *)arg) | ||
| 159 | |||
| 160 | #define SSL_CTX_set_tlsext_servername_callback(ctx, cb) \ | ||
| 161 | SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TLSEXT_SERVERNAME_CB,(void (*)(void))cb) | ||
| 162 | |||
| 163 | #define SSL_TLSEXT_ERR_OK 0 | ||
| 164 | #define SSL_TLSEXT_ERR_ALERT_WARNING 1 | ||
| 165 | #define SSL_TLSEXT_ERR_ALERT_FATAL 2 | ||
| 166 | #define SSL_TLSEXT_ERR_NOACK 3 | ||
| 167 | |||
| 168 | #define SSL_CTX_set_tlsext_servername_arg(ctx, arg) \ | ||
| 169 | SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG,0, (void *)arg) | ||
| 170 | |||
| 171 | #define SSL_CTX_get_tlsext_ticket_keys(ctx, keys, keylen) \ | ||
| 172 | SSL_CTX_ctrl((ctx),SSL_CTRL_GET_TLXEXT_TICKET_KEYS,(keylen),(keys)) | ||
| 173 | #define SSL_CTX_set_tlsext_ticket_keys(ctx, keys, keylen) \ | ||
| 174 | SSL_CTX_ctrl((ctx),SSL_CTRL_SET_TLXEXT_TICKET_KEYS,(keylen),(keys)) | ||
| 175 | |||
| 176 | #define SSL_CTX_set_tlsext_status_cb(ssl, cb) \ | ||
| 177 | SSL_CTX_callback_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB,(void (*)(void))cb) | ||
| 178 | |||
| 179 | #define SSL_CTX_set_tlsext_status_arg(ssl, arg) \ | ||
| 180 | SSL_CTX_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG,0, (void *)arg) | ||
| 181 | |||
| 182 | #define SSL_CTX_set_tlsext_ticket_key_cb(ssl, cb) \ | ||
| 183 | SSL_CTX_callback_ctrl(ssl,SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB,(void (*)(void))cb) | ||
| 184 | |||
| 185 | #endif | ||
| 86 | 186 | ||
| 87 | /* Additional TLS ciphersuites from draft-ietf-tls-56-bit-ciphersuites-00.txt | 187 | /* Additional TLS ciphersuites from draft-ietf-tls-56-bit-ciphersuites-00.txt |
| 88 | * (available if TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES is defined, see | 188 | * (available if TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES is defined, see |
| @@ -112,6 +212,60 @@ extern "C" { | |||
| 112 | #define TLS1_CK_DHE_RSA_WITH_AES_256_SHA 0x03000039 | 212 | #define TLS1_CK_DHE_RSA_WITH_AES_256_SHA 0x03000039 |
| 113 | #define TLS1_CK_ADH_WITH_AES_256_SHA 0x0300003A | 213 | #define TLS1_CK_ADH_WITH_AES_256_SHA 0x0300003A |
| 114 | 214 | ||
| 215 | /* Camellia ciphersuites from RFC4132 */ | ||
| 216 | #define TLS1_CK_RSA_WITH_CAMELLIA_128_CBC_SHA 0x03000041 | ||
| 217 | #define TLS1_CK_DH_DSS_WITH_CAMELLIA_128_CBC_SHA 0x03000042 | ||
| 218 | #define TLS1_CK_DH_RSA_WITH_CAMELLIA_128_CBC_SHA 0x03000043 | ||
| 219 | #define TLS1_CK_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA 0x03000044 | ||
| 220 | #define TLS1_CK_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA 0x03000045 | ||
| 221 | #define TLS1_CK_ADH_WITH_CAMELLIA_128_CBC_SHA 0x03000046 | ||
| 222 | |||
| 223 | #define TLS1_CK_RSA_WITH_CAMELLIA_256_CBC_SHA 0x03000084 | ||
| 224 | #define TLS1_CK_DH_DSS_WITH_CAMELLIA_256_CBC_SHA 0x03000085 | ||
| 225 | #define TLS1_CK_DH_RSA_WITH_CAMELLIA_256_CBC_SHA 0x03000086 | ||
| 226 | #define TLS1_CK_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA 0x03000087 | ||
| 227 | #define TLS1_CK_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA 0x03000088 | ||
| 228 | #define TLS1_CK_ADH_WITH_CAMELLIA_256_CBC_SHA 0x03000089 | ||
| 229 | |||
| 230 | /* SEED ciphersuites from RFC4162 */ | ||
| 231 | #define TLS1_CK_RSA_WITH_SEED_SHA 0x03000096 | ||
| 232 | #define TLS1_CK_DH_DSS_WITH_SEED_SHA 0x03000097 | ||
| 233 | #define TLS1_CK_DH_RSA_WITH_SEED_SHA 0x03000098 | ||
| 234 | #define TLS1_CK_DHE_DSS_WITH_SEED_SHA 0x03000099 | ||
| 235 | #define TLS1_CK_DHE_RSA_WITH_SEED_SHA 0x0300009A | ||
| 236 | #define TLS1_CK_ADH_WITH_SEED_SHA 0x0300009B | ||
| 237 | |||
| 238 | /* ECC ciphersuites from draft-ietf-tls-ecc-12.txt with changes soon to be in draft 13 */ | ||
| 239 | #define TLS1_CK_ECDH_ECDSA_WITH_NULL_SHA 0x0300C001 | ||
| 240 | #define TLS1_CK_ECDH_ECDSA_WITH_RC4_128_SHA 0x0300C002 | ||
| 241 | #define TLS1_CK_ECDH_ECDSA_WITH_DES_192_CBC3_SHA 0x0300C003 | ||
| 242 | #define TLS1_CK_ECDH_ECDSA_WITH_AES_128_CBC_SHA 0x0300C004 | ||
| 243 | #define TLS1_CK_ECDH_ECDSA_WITH_AES_256_CBC_SHA 0x0300C005 | ||
| 244 | |||
| 245 | #define TLS1_CK_ECDHE_ECDSA_WITH_NULL_SHA 0x0300C006 | ||
| 246 | #define TLS1_CK_ECDHE_ECDSA_WITH_RC4_128_SHA 0x0300C007 | ||
| 247 | #define TLS1_CK_ECDHE_ECDSA_WITH_DES_192_CBC3_SHA 0x0300C008 | ||
| 248 | #define TLS1_CK_ECDHE_ECDSA_WITH_AES_128_CBC_SHA 0x0300C009 | ||
| 249 | #define TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA 0x0300C00A | ||
| 250 | |||
| 251 | #define TLS1_CK_ECDH_RSA_WITH_NULL_SHA 0x0300C00B | ||
| 252 | #define TLS1_CK_ECDH_RSA_WITH_RC4_128_SHA 0x0300C00C | ||
| 253 | #define TLS1_CK_ECDH_RSA_WITH_DES_192_CBC3_SHA 0x0300C00D | ||
| 254 | #define TLS1_CK_ECDH_RSA_WITH_AES_128_CBC_SHA 0x0300C00E | ||
| 255 | #define TLS1_CK_ECDH_RSA_WITH_AES_256_CBC_SHA 0x0300C00F | ||
| 256 | |||
| 257 | #define TLS1_CK_ECDHE_RSA_WITH_NULL_SHA 0x0300C010 | ||
| 258 | #define TLS1_CK_ECDHE_RSA_WITH_RC4_128_SHA 0x0300C011 | ||
| 259 | #define TLS1_CK_ECDHE_RSA_WITH_DES_192_CBC3_SHA 0x0300C012 | ||
| 260 | #define TLS1_CK_ECDHE_RSA_WITH_AES_128_CBC_SHA 0x0300C013 | ||
| 261 | #define TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA 0x0300C014 | ||
| 262 | |||
| 263 | #define TLS1_CK_ECDH_anon_WITH_NULL_SHA 0x0300C015 | ||
| 264 | #define TLS1_CK_ECDH_anon_WITH_RC4_128_SHA 0x0300C016 | ||
| 265 | #define TLS1_CK_ECDH_anon_WITH_DES_192_CBC3_SHA 0x0300C017 | ||
| 266 | #define TLS1_CK_ECDH_anon_WITH_AES_128_CBC_SHA 0x0300C018 | ||
| 267 | #define TLS1_CK_ECDH_anon_WITH_AES_256_CBC_SHA 0x0300C019 | ||
| 268 | |||
| 115 | /* XXX | 269 | /* XXX |
| 116 | * Inconsistency alert: | 270 | * Inconsistency alert: |
| 117 | * The OpenSSL names of ciphers with ephemeral DH here include the string | 271 | * The OpenSSL names of ciphers with ephemeral DH here include the string |
| @@ -142,12 +296,68 @@ extern "C" { | |||
| 142 | #define TLS1_TXT_DHE_RSA_WITH_AES_256_SHA "DHE-RSA-AES256-SHA" | 296 | #define TLS1_TXT_DHE_RSA_WITH_AES_256_SHA "DHE-RSA-AES256-SHA" |
| 143 | #define TLS1_TXT_ADH_WITH_AES_256_SHA "ADH-AES256-SHA" | 297 | #define TLS1_TXT_ADH_WITH_AES_256_SHA "ADH-AES256-SHA" |
| 144 | 298 | ||
| 299 | /* ECC ciphersuites from draft-ietf-tls-ecc-01.txt (Mar 15, 2001) */ | ||
| 300 | #define TLS1_TXT_ECDH_ECDSA_WITH_NULL_SHA "ECDH-ECDSA-NULL-SHA" | ||
| 301 | #define TLS1_TXT_ECDH_ECDSA_WITH_RC4_128_SHA "ECDH-ECDSA-RC4-SHA" | ||
| 302 | #define TLS1_TXT_ECDH_ECDSA_WITH_DES_192_CBC3_SHA "ECDH-ECDSA-DES-CBC3-SHA" | ||
| 303 | #define TLS1_TXT_ECDH_ECDSA_WITH_AES_128_CBC_SHA "ECDH-ECDSA-AES128-SHA" | ||
| 304 | #define TLS1_TXT_ECDH_ECDSA_WITH_AES_256_CBC_SHA "ECDH-ECDSA-AES256-SHA" | ||
| 305 | |||
| 306 | #define TLS1_TXT_ECDHE_ECDSA_WITH_NULL_SHA "ECDHE-ECDSA-NULL-SHA" | ||
| 307 | #define TLS1_TXT_ECDHE_ECDSA_WITH_RC4_128_SHA "ECDHE-ECDSA-RC4-SHA" | ||
| 308 | #define TLS1_TXT_ECDHE_ECDSA_WITH_DES_192_CBC3_SHA "ECDHE-ECDSA-DES-CBC3-SHA" | ||
| 309 | #define TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_CBC_SHA "ECDHE-ECDSA-AES128-SHA" | ||
| 310 | #define TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_CBC_SHA "ECDHE-ECDSA-AES256-SHA" | ||
| 311 | |||
| 312 | #define TLS1_TXT_ECDH_RSA_WITH_NULL_SHA "ECDH-RSA-NULL-SHA" | ||
| 313 | #define TLS1_TXT_ECDH_RSA_WITH_RC4_128_SHA "ECDH-RSA-RC4-SHA" | ||
| 314 | #define TLS1_TXT_ECDH_RSA_WITH_DES_192_CBC3_SHA "ECDH-RSA-DES-CBC3-SHA" | ||
| 315 | #define TLS1_TXT_ECDH_RSA_WITH_AES_128_CBC_SHA "ECDH-RSA-AES128-SHA" | ||
| 316 | #define TLS1_TXT_ECDH_RSA_WITH_AES_256_CBC_SHA "ECDH-RSA-AES256-SHA" | ||
| 317 | |||
| 318 | #define TLS1_TXT_ECDHE_RSA_WITH_NULL_SHA "ECDHE-RSA-NULL-SHA" | ||
| 319 | #define TLS1_TXT_ECDHE_RSA_WITH_RC4_128_SHA "ECDHE-RSA-RC4-SHA" | ||
| 320 | #define TLS1_TXT_ECDHE_RSA_WITH_DES_192_CBC3_SHA "ECDHE-RSA-DES-CBC3-SHA" | ||
| 321 | #define TLS1_TXT_ECDHE_RSA_WITH_AES_128_CBC_SHA "ECDHE-RSA-AES128-SHA" | ||
| 322 | #define TLS1_TXT_ECDHE_RSA_WITH_AES_256_CBC_SHA "ECDHE-RSA-AES256-SHA" | ||
| 323 | |||
| 324 | #define TLS1_TXT_ECDH_anon_WITH_NULL_SHA "AECDH-NULL-SHA" | ||
| 325 | #define TLS1_TXT_ECDH_anon_WITH_RC4_128_SHA "AECDH-RC4-SHA" | ||
| 326 | #define TLS1_TXT_ECDH_anon_WITH_DES_192_CBC3_SHA "AECDH-DES-CBC3-SHA" | ||
| 327 | #define TLS1_TXT_ECDH_anon_WITH_AES_128_CBC_SHA "AECDH-AES128-SHA" | ||
| 328 | #define TLS1_TXT_ECDH_anon_WITH_AES_256_CBC_SHA "AECDH-AES256-SHA" | ||
| 329 | |||
| 330 | /* Camellia ciphersuites from RFC4132 */ | ||
| 331 | #define TLS1_TXT_RSA_WITH_CAMELLIA_128_CBC_SHA "CAMELLIA128-SHA" | ||
| 332 | #define TLS1_TXT_DH_DSS_WITH_CAMELLIA_128_CBC_SHA "DH-DSS-CAMELLIA128-SHA" | ||
| 333 | #define TLS1_TXT_DH_RSA_WITH_CAMELLIA_128_CBC_SHA "DH-RSA-CAMELLIA128-SHA" | ||
| 334 | #define TLS1_TXT_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA "DHE-DSS-CAMELLIA128-SHA" | ||
| 335 | #define TLS1_TXT_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA "DHE-RSA-CAMELLIA128-SHA" | ||
| 336 | #define TLS1_TXT_ADH_WITH_CAMELLIA_128_CBC_SHA "ADH-CAMELLIA128-SHA" | ||
| 337 | |||
| 338 | #define TLS1_TXT_RSA_WITH_CAMELLIA_256_CBC_SHA "CAMELLIA256-SHA" | ||
| 339 | #define TLS1_TXT_DH_DSS_WITH_CAMELLIA_256_CBC_SHA "DH-DSS-CAMELLIA256-SHA" | ||
| 340 | #define TLS1_TXT_DH_RSA_WITH_CAMELLIA_256_CBC_SHA "DH-RSA-CAMELLIA256-SHA" | ||
| 341 | #define TLS1_TXT_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA "DHE-DSS-CAMELLIA256-SHA" | ||
| 342 | #define TLS1_TXT_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA "DHE-RSA-CAMELLIA256-SHA" | ||
| 343 | #define TLS1_TXT_ADH_WITH_CAMELLIA_256_CBC_SHA "ADH-CAMELLIA256-SHA" | ||
| 344 | |||
| 345 | /* SEED ciphersuites from RFC4162 */ | ||
| 346 | #define TLS1_TXT_RSA_WITH_SEED_SHA "SEED-SHA" | ||
| 347 | #define TLS1_TXT_DH_DSS_WITH_SEED_SHA "DH-DSS-SEED-SHA" | ||
| 348 | #define TLS1_TXT_DH_RSA_WITH_SEED_SHA "DH-RSA-SEED-SHA" | ||
| 349 | #define TLS1_TXT_DHE_DSS_WITH_SEED_SHA "DHE-DSS-SEED-SHA" | ||
| 350 | #define TLS1_TXT_DHE_RSA_WITH_SEED_SHA "DHE-RSA-SEED-SHA" | ||
| 351 | #define TLS1_TXT_ADH_WITH_SEED_SHA "ADH-SEED-SHA" | ||
| 145 | 352 | ||
| 146 | #define TLS_CT_RSA_SIGN 1 | 353 | #define TLS_CT_RSA_SIGN 1 |
| 147 | #define TLS_CT_DSS_SIGN 2 | 354 | #define TLS_CT_DSS_SIGN 2 |
| 148 | #define TLS_CT_RSA_FIXED_DH 3 | 355 | #define TLS_CT_RSA_FIXED_DH 3 |
| 149 | #define TLS_CT_DSS_FIXED_DH 4 | 356 | #define TLS_CT_DSS_FIXED_DH 4 |
| 150 | #define TLS_CT_NUMBER 4 | 357 | #define TLS_CT_ECDSA_SIGN 64 |
| 358 | #define TLS_CT_RSA_FIXED_ECDH 65 | ||
| 359 | #define TLS_CT_ECDSA_FIXED_ECDH 66 | ||
| 360 | #define TLS_CT_NUMBER 7 | ||
| 151 | 361 | ||
| 152 | #define TLS1_FINISH_MAC_LENGTH 12 | 362 | #define TLS1_FINISH_MAC_LENGTH 12 |
| 153 | 363 | ||
| @@ -193,3 +403,5 @@ extern "C" { | |||
| 193 | #endif | 403 | #endif |
| 194 | #endif | 404 | #endif |
| 195 | 405 | ||
| 406 | |||
| 407 | |||
