summaryrefslogtreecommitdiff
path: root/src/lib/libssl/s3_clnt.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libssl/s3_clnt.c')
-rw-r--r--src/lib/libssl/s3_clnt.c137
1 files changed, 1 insertions, 136 deletions
diff --git a/src/lib/libssl/s3_clnt.c b/src/lib/libssl/s3_clnt.c
index 079544da84..b70719f75a 100644
--- a/src/lib/libssl/s3_clnt.c
+++ b/src/lib/libssl/s3_clnt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: s3_clnt.c,v 1.74 2014/07/10 08:51:14 tedu Exp $ */ 1/* $OpenBSD: s3_clnt.c,v 1.75 2014/07/11 09:24:44 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -1173,20 +1173,6 @@ ssl3_get_key_exchange(SSL *s)
1173 return ((int)n); 1173 return ((int)n);
1174 1174
1175 if (s->s3->tmp.message_type != SSL3_MT_SERVER_KEY_EXCHANGE) { 1175 if (s->s3->tmp.message_type != SSL3_MT_SERVER_KEY_EXCHANGE) {
1176#ifndef OPENSSL_NO_PSK
1177 /*
1178 * In plain PSK ciphersuite, ServerKeyExchange can be
1179 * omitted if no identity hint is sent. Set session->sess_cert
1180 * anyway to avoid problems later.
1181 */
1182 if (s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK) {
1183 s->session->sess_cert = ssl_sess_cert_new();
1184 if (s->session->sess_cert == NULL)
1185 goto err;
1186 free(s->ctx->psk_identity_hint);
1187 s->ctx->psk_identity_hint = NULL;
1188 }
1189#endif
1190 s->s3->tmp.reuse_message = 1; 1176 s->s3->tmp.reuse_message = 1;
1191 return (1); 1177 return (1);
1192 } 1178 }
@@ -1212,50 +1198,6 @@ ssl3_get_key_exchange(SSL *s)
1212 alg_a = s->s3->tmp.new_cipher->algorithm_auth; 1198 alg_a = s->s3->tmp.new_cipher->algorithm_auth;
1213 EVP_MD_CTX_init(&md_ctx); 1199 EVP_MD_CTX_init(&md_ctx);
1214 1200
1215#ifndef OPENSSL_NO_PSK
1216 if (alg_k & SSL_kPSK) {
1217 char tmp_id_hint[PSK_MAX_IDENTITY_LEN + 1];
1218
1219 al = SSL_AD_HANDSHAKE_FAILURE;
1220 n2s(p, i);
1221 param_len = i + 2;
1222 /*
1223 * Store PSK identity hint for later use, hint is used
1224 * in ssl3_send_client_key_exchange. Assume that the
1225 * maximum length of a PSK identity hint can be as
1226 * long as the maximum length of a PSK identity.
1227 */
1228 if (i > PSK_MAX_IDENTITY_LEN) {
1229 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,
1230 SSL_R_DATA_LENGTH_TOO_LONG);
1231 goto f_err;
1232 }
1233 if (param_len > n) {
1234 al = SSL_AD_DECODE_ERROR;
1235 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,
1236 SSL_R_BAD_PSK_IDENTITY_HINT_LENGTH);
1237 goto f_err;
1238 }
1239 /*
1240 * If received PSK identity hint contains NULL
1241 * characters, the hint is truncated from the first
1242 * NULL. p may not be ending with NULL, so create a
1243 * NULL-terminated string.
1244 */
1245 memcpy(tmp_id_hint, p, i);
1246 memset(tmp_id_hint + i, 0, PSK_MAX_IDENTITY_LEN + 1 - i);
1247 free(s->ctx->psk_identity_hint);
1248 s->ctx->psk_identity_hint = BUF_strdup(tmp_id_hint);
1249 if (s->ctx->psk_identity_hint == NULL) {
1250 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,
1251 ERR_R_MALLOC_FAILURE);
1252 goto f_err;
1253 }
1254
1255 p += i;
1256 n -= param_len;
1257 } else
1258#endif /* !OPENSSL_NO_PSK */
1259 if (alg_k & SSL_kRSA) { 1201 if (alg_k & SSL_kRSA) {
1260 if ((rsa = RSA_new()) == NULL) { 1202 if ((rsa = RSA_new()) == NULL) {
1261 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE, 1203 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,
@@ -2363,83 +2305,6 @@ ssl3_send_client_key_exchange(SSL *s)
2363 EVP_PKEY_free(pub_key); 2305 EVP_PKEY_free(pub_key);
2364 2306
2365 } 2307 }
2366#ifndef OPENSSL_NO_PSK
2367 else if (alg_k & SSL_kPSK) {
2368 char identity[PSK_MAX_IDENTITY_LEN];
2369 unsigned char *t = NULL;
2370 unsigned char psk_or_pre_ms[PSK_MAX_PSK_LEN*2 + 4];
2371 unsigned int pre_ms_len = 0, psk_len = 0;
2372 int psk_err = 1;
2373
2374 n = 0;
2375 if (s->psk_client_callback == NULL) {
2376 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
2377 SSL_R_PSK_NO_CLIENT_CB);
2378 goto err;
2379 }
2380
2381 psk_len = s->psk_client_callback(s,
2382 s->ctx->psk_identity_hint, identity,
2383 PSK_MAX_IDENTITY_LEN, psk_or_pre_ms,
2384 sizeof(psk_or_pre_ms));
2385 if (psk_len > PSK_MAX_PSK_LEN) {
2386 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
2387 ERR_R_INTERNAL_ERROR);
2388 goto psk_err;
2389 } else if (psk_len == 0) {
2390 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
2391 SSL_R_PSK_IDENTITY_NOT_FOUND);
2392 goto psk_err;
2393 }
2394
2395 /* create PSK pre_master_secret */
2396 pre_ms_len = 2 + psk_len + 2 + psk_len;
2397 t = psk_or_pre_ms;
2398 memmove(psk_or_pre_ms + psk_len + 4,
2399 psk_or_pre_ms, psk_len);
2400 s2n(psk_len, t);
2401 memset(t, 0, psk_len);
2402 t += psk_len;
2403 s2n(psk_len, t);
2404
2405 free(s->session->psk_identity_hint);
2406 s->session->psk_identity_hint =
2407 BUF_strdup(s->ctx->psk_identity_hint);
2408 if (s->ctx->psk_identity_hint != NULL &&
2409 s->session->psk_identity_hint == NULL) {
2410 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
2411 ERR_R_MALLOC_FAILURE);
2412 goto psk_err;
2413 }
2414
2415 free(s->session->psk_identity);
2416 s->session->psk_identity = BUF_strdup(identity);
2417 if (s->session->psk_identity == NULL) {
2418 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
2419 ERR_R_MALLOC_FAILURE);
2420 goto psk_err;
2421 }
2422
2423 s->session->master_key_length =
2424 s->method->ssl3_enc->generate_master_secret(
2425 s, s->session->master_key, psk_or_pre_ms,
2426 pre_ms_len);
2427
2428 n = strlen(identity);
2429 s2n(n, p);
2430 memcpy(p, identity, n);
2431 n += 2;
2432 psk_err = 0;
2433psk_err:
2434 OPENSSL_cleanse(identity, PSK_MAX_IDENTITY_LEN);
2435 OPENSSL_cleanse(psk_or_pre_ms, sizeof(psk_or_pre_ms));
2436 if (psk_err != 0) {
2437 ssl3_send_alert(s, SSL3_AL_FATAL,
2438 SSL_AD_HANDSHAKE_FAILURE);
2439 goto err;
2440 }
2441 }
2442#endif
2443 else { 2308 else {
2444 ssl3_send_alert(s, SSL3_AL_FATAL, 2309 ssl3_send_alert(s, SSL3_AL_FATAL,
2445 SSL_AD_HANDSHAKE_FAILURE); 2310 SSL_AD_HANDSHAKE_FAILURE);