summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortedu <>2014-05-05 15:03:22 +0000
committertedu <>2014-05-05 15:03:22 +0000
commit5b4326f23352be2e7084f2020795d8aa042c746f (patch)
treec342d9903092a19dfda173837629fd04c429eda9 /src
parent77dd1ca11ad22b323b27beea447edd1e35c3b24e (diff)
downloadopenbsd-5b4326f23352be2e7084f2020795d8aa042c746f.tar.gz
openbsd-5b4326f23352be2e7084f2020795d8aa042c746f.tar.bz2
openbsd-5b4326f23352be2e7084f2020795d8aa042c746f.zip
Remove SRP and Kerberos support from libssl. These are complex protocols
all on their own and we can't effectively maintain them without using them, which we don't. If the need arises, the code can be resurrected.
Diffstat (limited to 'src')
-rw-r--r--src/lib/libssl/d1_clnt.c134
-rw-r--r--src/lib/libssl/d1_srvr.c3
-rw-r--r--src/lib/libssl/s3_clnt.c258
-rw-r--r--src/lib/libssl/s3_lib.c445
-rw-r--r--src/lib/libssl/s3_srvr.c317
-rw-r--r--src/lib/libssl/src/ssl/d1_clnt.c134
-rw-r--r--src/lib/libssl/src/ssl/d1_srvr.c3
-rw-r--r--src/lib/libssl/src/ssl/kssl.c1549
-rw-r--r--src/lib/libssl/src/ssl/kssl.h114
-rw-r--r--src/lib/libssl/src/ssl/kssl_lcl.h23
-rw-r--r--src/lib/libssl/src/ssl/s3_clnt.c258
-rw-r--r--src/lib/libssl/src/ssl/s3_lib.c445
-rw-r--r--src/lib/libssl/src/ssl/s3_srvr.c317
-rw-r--r--src/lib/libssl/src/ssl/ssl.h70
-rw-r--r--src/lib/libssl/src/ssl/ssl_asn1.c66
-rw-r--r--src/lib/libssl/src/ssl/ssl_ciph.c4
-rw-r--r--src/lib/libssl/src/ssl/ssl_lib.c27
-rw-r--r--src/lib/libssl/src/ssl/ssl_sess.c16
-rw-r--r--src/lib/libssl/src/ssl/ssl_txt.c19
-rw-r--r--src/lib/libssl/src/ssl/ssltest.c98
-rw-r--r--src/lib/libssl/src/ssl/t1_lib.c50
-rw-r--r--src/lib/libssl/src/ssl/tls_srp.c516
-rw-r--r--src/lib/libssl/ssl.h70
-rw-r--r--src/lib/libssl/ssl/Makefile4
-rw-r--r--src/lib/libssl/ssl_asn1.c66
-rw-r--r--src/lib/libssl/ssl_ciph.c4
-rw-r--r--src/lib/libssl/ssl_lib.c27
-rw-r--r--src/lib/libssl/ssl_sess.c16
-rw-r--r--src/lib/libssl/ssl_txt.c19
-rw-r--r--src/lib/libssl/t1_lib.c50
30 files changed, 2 insertions, 5120 deletions
diff --git a/src/lib/libssl/d1_clnt.c b/src/lib/libssl/d1_clnt.c
index 38118b1385..8967879f70 100644
--- a/src/lib/libssl/d1_clnt.c
+++ b/src/lib/libssl/d1_clnt.c
@@ -115,9 +115,6 @@
115 115
116#include <stdio.h> 116#include <stdio.h>
117#include "ssl_locl.h" 117#include "ssl_locl.h"
118#ifndef OPENSSL_NO_KRB5
119#include "kssl_lcl.h"
120#endif
121#include <openssl/buffer.h> 118#include <openssl/buffer.h>
122#include <openssl/rand.h> 119#include <openssl/rand.h>
123#include <openssl/objects.h> 120#include <openssl/objects.h>
@@ -926,9 +923,6 @@ dtls1_send_client_key_exchange(SSL *s)
926 unsigned long alg_k; 923 unsigned long alg_k;
927 unsigned char *q; 924 unsigned char *q;
928 EVP_PKEY *pkey = NULL; 925 EVP_PKEY *pkey = NULL;
929#ifndef OPENSSL_NO_KRB5
930 KSSL_ERR kssl_err;
931#endif /* OPENSSL_NO_KRB5 */
932#ifndef OPENSSL_NO_ECDH 926#ifndef OPENSSL_NO_ECDH
933 EC_KEY *clnt_ecdh = NULL; 927 EC_KEY *clnt_ecdh = NULL;
934 const EC_POINT *srvr_ecpoint = NULL; 928 const EC_POINT *srvr_ecpoint = NULL;
@@ -992,134 +986,6 @@ dtls1_send_client_key_exchange(SSL *s)
992 tmp_buf, sizeof tmp_buf); 986 tmp_buf, sizeof tmp_buf);
993 OPENSSL_cleanse(tmp_buf, sizeof tmp_buf); 987 OPENSSL_cleanse(tmp_buf, sizeof tmp_buf);
994 } 988 }
995#ifndef OPENSSL_NO_KRB5
996 else if (alg_k & SSL_kKRB5) {
997 krb5_error_code krb5rc;
998 KSSL_CTX *kssl_ctx = s->kssl_ctx;
999 /* krb5_data krb5_ap_req; */
1000 krb5_data *enc_ticket;
1001 krb5_data authenticator, *authp = NULL;
1002 EVP_CIPHER_CTX ciph_ctx;
1003 const EVP_CIPHER *enc = NULL;
1004 unsigned char iv[EVP_MAX_IV_LENGTH];
1005 unsigned char tmp_buf[SSL_MAX_MASTER_KEY_LENGTH];
1006 unsigned char epms[SSL_MAX_MASTER_KEY_LENGTH
1007 + EVP_MAX_IV_LENGTH];
1008 int padl, outl = sizeof(epms);
1009
1010 EVP_CIPHER_CTX_init(&ciph_ctx);
1011
1012#ifdef KSSL_DEBUG
1013 printf("ssl3_send_client_key_exchange(%lx & %lx)\n",
1014 alg_k, SSL_kKRB5);
1015#endif /* KSSL_DEBUG */
1016
1017 authp = NULL;
1018#ifdef KRB5SENDAUTH
1019 if (KRB5SENDAUTH)
1020 authp = &authenticator;
1021#endif /* KRB5SENDAUTH */
1022
1023 krb5rc = kssl_cget_tkt(kssl_ctx, &enc_ticket, authp,
1024 &kssl_err);
1025 enc = kssl_map_enc(kssl_ctx->enctype);
1026 if (enc == NULL)
1027 goto err;
1028#ifdef KSSL_DEBUG
1029 {
1030 printf("kssl_cget_tkt rtn %d\n", krb5rc);
1031 if (krb5rc && kssl_err.text)
1032 printf("kssl_cget_tkt kssl_err=%s\n", kssl_err.text);
1033 }
1034#endif /* KSSL_DEBUG */
1035
1036 if (krb5rc) {
1037 ssl3_send_alert(s, SSL3_AL_FATAL,
1038 SSL_AD_HANDSHAKE_FAILURE);
1039 SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,
1040 kssl_err.reason);
1041 goto err;
1042 }
1043
1044 /* 20010406 VRS - Earlier versions used KRB5 AP_REQ
1045 ** in place of RFC 2712 KerberosWrapper, as in:
1046 **
1047 ** Send ticket (copy to *p, set n = length)
1048 ** n = krb5_ap_req.length;
1049 ** memcpy(p, krb5_ap_req.data, krb5_ap_req.length);
1050 ** if (krb5_ap_req.data)
1051 ** kssl_krb5_free_data_contents(NULL,&krb5_ap_req);
1052 **
1053 ** Now using real RFC 2712 KerberosWrapper
1054 ** (Thanks to Simon Wilkinson <sxw@sxw.org.uk>)
1055 ** Note: 2712 "opaque" types are here replaced
1056 ** with a 2-byte length followed by the value.
1057 ** Example:
1058 ** KerberosWrapper= xx xx asn1ticket 0 0 xx xx encpms
1059 ** Where "xx xx" = length bytes. Shown here with
1060 ** optional authenticator omitted.
1061 */
1062
1063 /* KerberosWrapper.Ticket */
1064 s2n(enc_ticket->length, p);
1065 memcpy(p, enc_ticket->data, enc_ticket->length);
1066 p += enc_ticket->length;
1067 n = enc_ticket->length + 2;
1068
1069 /* KerberosWrapper.Authenticator */
1070 if (authp && authp->length) {
1071 s2n(authp->length, p);
1072 memcpy(p, authp->data, authp->length);
1073 p += authp->length;
1074 n += authp->length + 2;
1075
1076 free(authp->data);
1077 authp->data = NULL;
1078 authp->length = 0;
1079 } else {
1080 s2n(0, p);/* null authenticator length */
1081 n += 2;
1082 }
1083
1084 if (RAND_bytes(tmp_buf, sizeof tmp_buf) <= 0)
1085 goto err;
1086
1087 /* 20010420 VRS. Tried it this way; failed.
1088 ** EVP_EncryptInit_ex(&ciph_ctx,enc, NULL,NULL);
1089 ** EVP_CIPHER_CTX_set_key_length(&ciph_ctx,
1090 ** kssl_ctx->length);
1091 ** EVP_EncryptInit_ex(&ciph_ctx,NULL, key,iv);
1092 */
1093
1094 memset(iv, 0, sizeof iv);
1095 /* per RFC 1510 */
1096 EVP_EncryptInit_ex(&ciph_ctx, enc, NULL,
1097 kssl_ctx->key, iv);
1098 EVP_EncryptUpdate(&ciph_ctx, epms, &outl, tmp_buf,
1099 sizeof tmp_buf);
1100 EVP_EncryptFinal_ex(&ciph_ctx, &(epms[outl]), &padl);
1101 outl += padl;
1102 if (outl > (int)sizeof epms) {
1103 SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);
1104 goto err;
1105 }
1106 EVP_CIPHER_CTX_cleanup(&ciph_ctx);
1107
1108 /* KerberosWrapper.EncryptedPreMasterSecret */
1109 s2n(outl, p);
1110 memcpy(p, epms, outl);
1111 p += outl;
1112 n += outl + 2;
1113
1114 s->session->master_key_length =
1115 s->method->ssl3_enc->generate_master_secret(s,
1116 s->session->master_key,
1117 tmp_buf, sizeof tmp_buf);
1118
1119 OPENSSL_cleanse(tmp_buf, sizeof tmp_buf);
1120 OPENSSL_cleanse(epms, outl);
1121 }
1122#endif
1123#ifndef OPENSSL_NO_DH 989#ifndef OPENSSL_NO_DH
1124 else if (alg_k & (SSL_kEDH|SSL_kDHr|SSL_kDHd)) { 990 else if (alg_k & (SSL_kEDH|SSL_kDHr|SSL_kDHd)) {
1125 DH *dh_srvr, *dh_clnt; 991 DH *dh_srvr, *dh_clnt;
diff --git a/src/lib/libssl/d1_srvr.c b/src/lib/libssl/d1_srvr.c
index 9995278a26..6183815a6d 100644
--- a/src/lib/libssl/d1_srvr.c
+++ b/src/lib/libssl/d1_srvr.c
@@ -429,9 +429,6 @@ dtls1_accept(SSL *s)
429 /* clear this, it may get reset by 429 /* clear this, it may get reset by
430 * send_server_key_exchange */ 430 * send_server_key_exchange */
431 if ((s->options & SSL_OP_EPHEMERAL_RSA) 431 if ((s->options & SSL_OP_EPHEMERAL_RSA)
432#ifndef OPENSSL_NO_KRB5
433 && !(alg_k & SSL_kKRB5)
434#endif /* OPENSSL_NO_KRB5 */
435 ) 432 )
436 /* option SSL_OP_EPHEMERAL_RSA sends temporary RSA key 433 /* option SSL_OP_EPHEMERAL_RSA sends temporary RSA key
437 * even when forbidden by protocol specs 434 * even when forbidden by protocol specs
diff --git a/src/lib/libssl/s3_clnt.c b/src/lib/libssl/s3_clnt.c
index eb55fc9682..68817cd33a 100644
--- a/src/lib/libssl/s3_clnt.c
+++ b/src/lib/libssl/s3_clnt.c
@@ -369,17 +369,6 @@ ssl3_connect(SSL *s)
369 ret = ssl3_get_server_done(s); 369 ret = ssl3_get_server_done(s);
370 if (ret <= 0) 370 if (ret <= 0)
371 goto end; 371 goto end;
372#ifndef OPENSSL_NO_SRP
373 if (s->s3->tmp.new_cipher->algorithm_mkey & SSL_kSRP) {
374 if ((ret = SRP_Calc_A_param(s)) <= 0) {
375 SSLerr(SSL_F_SSL3_CONNECT,
376 SSL_R_SRP_A_CALC);
377 ssl3_send_alert(s, SSL3_AL_FATAL,
378 SSL_AD_INTERNAL_ERROR);
379 goto end;
380 }
381 }
382#endif
383 if (s->s3->tmp.cert_req) 372 if (s->s3->tmp.cert_req)
384 s->state = SSL3_ST_CW_CERT_A; 373 s->state = SSL3_ST_CW_CERT_A;
385 else 374 else
@@ -1137,10 +1126,6 @@ ssl3_get_server_certificate(SSL *s)
1137 1126
1138 i = ssl_verify_cert_chain(s, sk); 1127 i = ssl_verify_cert_chain(s, sk);
1139 if ((s->verify_mode != SSL_VERIFY_NONE) && (i <= 0) 1128 if ((s->verify_mode != SSL_VERIFY_NONE) && (i <= 0)
1140#ifndef OPENSSL_NO_KRB5
1141 && !((s->s3->tmp.new_cipher->algorithm_mkey & SSL_kKRB5) &&
1142 (s->s3->tmp.new_cipher->algorithm_auth & SSL_aKRB5))
1143#endif /* OPENSSL_NO_KRB5 */
1144 ) { 1129 ) {
1145 al = ssl_verify_alarm_type(s->verify_result); 1130 al = ssl_verify_alarm_type(s->verify_result);
1146 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE, 1131 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,
@@ -1361,81 +1346,6 @@ ssl3_get_key_exchange(SSL *s)
1361 n -= param_len; 1346 n -= param_len;
1362 } else 1347 } else
1363#endif /* !OPENSSL_NO_PSK */ 1348#endif /* !OPENSSL_NO_PSK */
1364#ifndef OPENSSL_NO_SRP
1365 if (alg_k & SSL_kSRP) {
1366 n2s(p, i);
1367 param_len = i + 2;
1368 if (param_len > n) {
1369 al = SSL_AD_DECODE_ERROR;
1370 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,
1371 SSL_R_BAD_SRP_N_LENGTH);
1372 goto f_err;
1373 }
1374 if (!(s->srp_ctx.N = BN_bin2bn(p, i, NULL))) {
1375 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,
1376 ERR_R_BN_LIB);
1377 goto err;
1378 }
1379 p += i;
1380
1381 n2s(p, i);
1382 param_len += i + 2;
1383 if (param_len > n) {
1384 al = SSL_AD_DECODE_ERROR;
1385 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,
1386 SSL_R_BAD_SRP_G_LENGTH);
1387 goto f_err;
1388 }
1389 if (!(s->srp_ctx.g = BN_bin2bn(p, i, NULL))) {
1390 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,
1391 ERR_R_BN_LIB);
1392 goto err;
1393 }
1394 p += i;
1395
1396 i = (unsigned int)(p[0]);
1397 p++;
1398 param_len += i + 1;
1399 if (param_len > n) {
1400 al = SSL_AD_DECODE_ERROR;
1401 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,
1402 SSL_R_BAD_SRP_S_LENGTH);
1403 goto f_err;
1404 }
1405 if (!(s->srp_ctx.s = BN_bin2bn(p, i, NULL))) {
1406 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,
1407 ERR_R_BN_LIB);
1408 goto err;
1409 }
1410 p += i;
1411
1412 n2s(p, i);
1413 param_len += i + 2;
1414 if (param_len > n) {
1415 al = SSL_AD_DECODE_ERROR;
1416 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,
1417 SSL_R_BAD_SRP_B_LENGTH);
1418 goto f_err;
1419 }
1420 if (!(s->srp_ctx.B = BN_bin2bn(p, i, NULL))) {
1421 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,
1422 ERR_R_BN_LIB);
1423 goto err;
1424 }
1425 p += i;
1426 n -= param_len;
1427
1428 /* We must check if there is a certificate */
1429 if (alg_a & SSL_aRSA)
1430 pkey = X509_get_pubkey(
1431 s->session->sess_cert->peer_pkeys[
1432 SSL_PKEY_RSA_ENC].x509);
1433 else if (alg_a & SSL_aDSS)
1434 pkey = X509_get_pubkey(
1435 s->session->sess_cert->peer_pkeys[
1436 SSL_PKEY_DSA_SIGN].x509);
1437 } else
1438#endif /* !OPENSSL_NO_SRP */
1439 if (alg_k & SSL_kRSA) { 1349 if (alg_k & SSL_kRSA) {
1440 if ((rsa = RSA_new()) == NULL) { 1350 if ((rsa = RSA_new()) == NULL) {
1441 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE, 1351 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,
@@ -2156,9 +2066,6 @@ ssl3_send_client_key_exchange(SSL *s)
2156 unsigned long alg_k; 2066 unsigned long alg_k;
2157 unsigned char *q; 2067 unsigned char *q;
2158 EVP_PKEY *pkey = NULL; 2068 EVP_PKEY *pkey = NULL;
2159#ifndef OPENSSL_NO_KRB5
2160 KSSL_ERR kssl_err;
2161#endif /* OPENSSL_NO_KRB5 */
2162#ifndef OPENSSL_NO_ECDH 2069#ifndef OPENSSL_NO_ECDH
2163 EC_KEY *clnt_ecdh = NULL; 2070 EC_KEY *clnt_ecdh = NULL;
2164 const EC_POINT *srvr_ecpoint = NULL; 2071 const EC_POINT *srvr_ecpoint = NULL;
@@ -2226,140 +2133,6 @@ ssl3_send_client_key_exchange(SSL *s)
2226 s, s->session->master_key, tmp_buf, sizeof tmp_buf); 2133 s, s->session->master_key, tmp_buf, sizeof tmp_buf);
2227 OPENSSL_cleanse(tmp_buf, sizeof tmp_buf); 2134 OPENSSL_cleanse(tmp_buf, sizeof tmp_buf);
2228 } 2135 }
2229#ifndef OPENSSL_NO_KRB5
2230 else if (alg_k & SSL_kKRB5) {
2231 krb5_error_code krb5rc;
2232 KSSL_CTX *kssl_ctx = s->kssl_ctx;
2233 /* krb5_data krb5_ap_req; */
2234 krb5_data *enc_ticket;
2235 krb5_data authenticator, *authp = NULL;
2236 EVP_CIPHER_CTX ciph_ctx;
2237 const EVP_CIPHER *enc = NULL;
2238 unsigned char iv[EVP_MAX_IV_LENGTH];
2239 unsigned char tmp_buf[SSL_MAX_MASTER_KEY_LENGTH];
2240 unsigned char epms[SSL_MAX_MASTER_KEY_LENGTH
2241 + EVP_MAX_IV_LENGTH];
2242 int padl, outl = sizeof(epms);
2243
2244 EVP_CIPHER_CTX_init(&ciph_ctx);
2245
2246#ifdef KSSL_DEBUG
2247 printf("ssl3_send_client_key_exchange(%lx & %lx)\n",
2248 alg_k, SSL_kKRB5);
2249#endif /* KSSL_DEBUG */
2250
2251 authp = NULL;
2252#ifdef KRB5SENDAUTH
2253 if (KRB5SENDAUTH)
2254 authp = &authenticator;
2255#endif /* KRB5SENDAUTH */
2256
2257 krb5rc = kssl_cget_tkt(kssl_ctx, &enc_ticket,
2258 authp, &kssl_err);
2259 enc = kssl_map_enc(kssl_ctx->enctype);
2260 if (enc == NULL)
2261 goto err;
2262#ifdef KSSL_DEBUG
2263 {
2264 printf("kssl_cget_tkt rtn %d\n", krb5rc);
2265 if (krb5rc && kssl_err.text)
2266 printf("kssl_cget_tkt kssl_err=%s\n",
2267 kssl_err.text);
2268 }
2269#endif /* KSSL_DEBUG */
2270
2271 if (krb5rc) {
2272 ssl3_send_alert(s, SSL3_AL_FATAL,
2273 SSL_AD_HANDSHAKE_FAILURE);
2274 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
2275 kssl_err.reason);
2276 goto err;
2277 }
2278
2279 /*
2280 * 20010406 VRS - Earlier versions used KRB5 AP_REQ
2281 * in place of RFC 2712 KerberosWrapper, as in:
2282 *
2283 * Send ticket (copy to *p, set n = length)
2284 * n = krb5_ap_req.length;
2285 * memcpy(p, krb5_ap_req.data, krb5_ap_req.length);
2286 * if (krb5_ap_req.data)
2287 * kssl_krb5_free_data_contents(NULL,&krb5_ap_req);
2288 *
2289 * Now using real RFC 2712 KerberosWrapper
2290 * (Thanks to Simon Wilkinson <sxw@sxw.org.uk>)
2291 * Note: 2712 "opaque" types are here replaced
2292 * with a 2-byte length followed by the value.
2293 * Example:
2294 * KerberosWrapper= xx xx asn1ticket 0 0 xx xx encpms
2295 * Where "xx xx" = length bytes. Shown here with
2296 * optional authenticator omitted.
2297 */
2298
2299 /* KerberosWrapper.Ticket */
2300 s2n(enc_ticket->length, p);
2301 memcpy(p, enc_ticket->data, enc_ticket->length);
2302 p += enc_ticket->length;
2303 n = enc_ticket->length + 2;
2304
2305 /* KerberosWrapper.Authenticator */
2306 if (authp && authp->length) {
2307 s2n(authp->length, p);
2308 memcpy(p, authp->data, authp->length);
2309 p += authp->length;
2310 n += authp->length + 2;
2311
2312 free(authp->data);
2313 authp->data = NULL;
2314 authp->length = 0;
2315 } else {
2316 s2n(0,p);/* null authenticator length */
2317 n += 2;
2318 }
2319
2320 tmp_buf[0] = s->client_version >> 8;
2321 tmp_buf[1] = s->client_version & 0xff;
2322 if (RAND_bytes(&(tmp_buf[2]), sizeof tmp_buf - 2) <= 0)
2323 goto err;
2324
2325 /*
2326 * 20010420 VRS. Tried it this way; failed.
2327 * EVP_EncryptInit_ex(&ciph_ctx,enc, NULL,NULL);
2328 * EVP_CIPHER_CTX_set_key_length(&ciph_ctx,
2329 * kssl_ctx->length);
2330 * EVP_EncryptInit_ex(&ciph_ctx,NULL, key,iv);
2331 */
2332
2333 memset(iv, 0, sizeof iv);
2334 /* per RFC 1510 */
2335 EVP_EncryptInit_ex(&ciph_ctx, enc, NULL,
2336 kssl_ctx->key, iv);
2337 EVP_EncryptUpdate(&ciph_ctx, epms, &outl, tmp_buf,
2338 sizeof tmp_buf);
2339 EVP_EncryptFinal_ex(&ciph_ctx, &(epms[outl]), &padl);
2340 outl += padl;
2341 if (outl > (int)sizeof epms) {
2342 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
2343 ERR_R_INTERNAL_ERROR);
2344 goto err;
2345 }
2346 EVP_CIPHER_CTX_cleanup(&ciph_ctx);
2347
2348 /* KerberosWrapper.EncryptedPreMasterSecret */
2349 s2n(outl, p);
2350 memcpy(p, epms, outl);
2351 p += outl;
2352 n += outl + 2;
2353
2354 s->session->master_key_length =
2355 s->method->ssl3_enc->generate_master_secret(s,
2356 s->session->master_key,
2357 tmp_buf, sizeof tmp_buf);
2358
2359 OPENSSL_cleanse(tmp_buf, sizeof tmp_buf);
2360 OPENSSL_cleanse(epms, outl);
2361 }
2362#endif
2363#ifndef OPENSSL_NO_DH 2136#ifndef OPENSSL_NO_DH
2364 else if (alg_k & (SSL_kEDH|SSL_kDHr|SSL_kDHd)) { 2137 else if (alg_k & (SSL_kEDH|SSL_kDHr|SSL_kDHd)) {
2365 DH *dh_srvr, *dh_clnt; 2138 DH *dh_srvr, *dh_clnt;
@@ -2716,37 +2489,6 @@ ssl3_send_client_key_exchange(SSL *s)
2716 EVP_PKEY_free(pub_key); 2489 EVP_PKEY_free(pub_key);
2717 2490
2718 } 2491 }
2719#ifndef OPENSSL_NO_SRP
2720 else if (alg_k & SSL_kSRP) {
2721 if (s->srp_ctx.A != NULL) {
2722 /* send off the data */
2723 n = BN_num_bytes(s->srp_ctx.A);
2724 s2n(n, p);
2725 BN_bn2bin(s->srp_ctx.A, p);
2726 n += 2;
2727 } else {
2728 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
2729 ERR_R_INTERNAL_ERROR);
2730 goto err;
2731 }
2732 if (s->session->srp_username != NULL)
2733 free(s->session->srp_username);
2734 s->session->srp_username = BUF_strdup(s->srp_ctx.login);
2735 if (s->session->srp_username == NULL) {
2736 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
2737 ERR_R_MALLOC_FAILURE);
2738 goto err;
2739 }
2740
2741 if ((s->session->master_key_length =
2742 SRP_generate_client_master_secret(s,
2743 s->session->master_key)) < 0) {
2744 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
2745 ERR_R_INTERNAL_ERROR);
2746 goto err;
2747 }
2748 }
2749#endif
2750#ifndef OPENSSL_NO_PSK 2492#ifndef OPENSSL_NO_PSK
2751 else if (alg_k & SSL_kPSK) { 2493 else if (alg_k & SSL_kPSK) {
2752 char identity[PSK_MAX_IDENTITY_LEN]; 2494 char identity[PSK_MAX_IDENTITY_LEN];
diff --git a/src/lib/libssl/s3_lib.c b/src/lib/libssl/s3_lib.c
index 12ce8a1605..c68748809c 100644
--- a/src/lib/libssl/s3_lib.c
+++ b/src/lib/libssl/s3_lib.c
@@ -605,232 +605,6 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[] = {
605 168, 605 168,
606 168, 606 168,
607 }, 607 },
608#ifndef OPENSSL_NO_KRB5
609/* The Kerberos ciphers*/
610/* Cipher 1E */
611 {
612 1,
613 SSL3_TXT_KRB5_DES_64_CBC_SHA,
614 SSL3_CK_KRB5_DES_64_CBC_SHA,
615 SSL_kKRB5,
616 SSL_aKRB5,
617 SSL_DES,
618 SSL_SHA1,
619 SSL_SSLV3,
620 SSL_NOT_EXP|SSL_LOW,
621 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
622 56,
623 56,
624 },
625
626/* Cipher 1F */
627 {
628 1,
629 SSL3_TXT_KRB5_DES_192_CBC3_SHA,
630 SSL3_CK_KRB5_DES_192_CBC3_SHA,
631 SSL_kKRB5,
632 SSL_aKRB5,
633 SSL_3DES,
634 SSL_SHA1,
635 SSL_SSLV3,
636 SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
637 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
638 168,
639 168,
640 },
641
642/* Cipher 20 */
643 {
644 1,
645 SSL3_TXT_KRB5_RC4_128_SHA,
646 SSL3_CK_KRB5_RC4_128_SHA,
647 SSL_kKRB5,
648 SSL_aKRB5,
649 SSL_RC4,
650 SSL_SHA1,
651 SSL_SSLV3,
652 SSL_NOT_EXP|SSL_MEDIUM,
653 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
654 128,
655 128,
656 },
657
658/* Cipher 21 */
659 {
660 1,
661 SSL3_TXT_KRB5_IDEA_128_CBC_SHA,
662 SSL3_CK_KRB5_IDEA_128_CBC_SHA,
663 SSL_kKRB5,
664 SSL_aKRB5,
665 SSL_IDEA,
666 SSL_SHA1,
667 SSL_SSLV3,
668 SSL_NOT_EXP|SSL_MEDIUM,
669 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
670 128,
671 128,
672 },
673
674/* Cipher 22 */
675 {
676 1,
677 SSL3_TXT_KRB5_DES_64_CBC_MD5,
678 SSL3_CK_KRB5_DES_64_CBC_MD5,
679 SSL_kKRB5,
680 SSL_aKRB5,
681 SSL_DES,
682 SSL_MD5,
683 SSL_SSLV3,
684 SSL_NOT_EXP|SSL_LOW,
685 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
686 56,
687 56,
688 },
689
690/* Cipher 23 */
691 {
692 1,
693 SSL3_TXT_KRB5_DES_192_CBC3_MD5,
694 SSL3_CK_KRB5_DES_192_CBC3_MD5,
695 SSL_kKRB5,
696 SSL_aKRB5,
697 SSL_3DES,
698 SSL_MD5,
699 SSL_SSLV3,
700 SSL_NOT_EXP|SSL_HIGH,
701 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
702 168,
703 168,
704 },
705
706/* Cipher 24 */
707 {
708 1,
709 SSL3_TXT_KRB5_RC4_128_MD5,
710 SSL3_CK_KRB5_RC4_128_MD5,
711 SSL_kKRB5,
712 SSL_aKRB5,
713 SSL_RC4,
714 SSL_MD5,
715 SSL_SSLV3,
716 SSL_NOT_EXP|SSL_MEDIUM,
717 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
718 128,
719 128,
720 },
721
722/* Cipher 25 */
723 {
724 1,
725 SSL3_TXT_KRB5_IDEA_128_CBC_MD5,
726 SSL3_CK_KRB5_IDEA_128_CBC_MD5,
727 SSL_kKRB5,
728 SSL_aKRB5,
729 SSL_IDEA,
730 SSL_MD5,
731 SSL_SSLV3,
732 SSL_NOT_EXP|SSL_MEDIUM,
733 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
734 128,
735 128,
736 },
737
738/* Cipher 26 */
739 {
740 1,
741 SSL3_TXT_KRB5_DES_40_CBC_SHA,
742 SSL3_CK_KRB5_DES_40_CBC_SHA,
743 SSL_kKRB5,
744 SSL_aKRB5,
745 SSL_DES,
746 SSL_SHA1,
747 SSL_SSLV3,
748 SSL_EXPORT|SSL_EXP40,
749 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
750 40,
751 56,
752 },
753
754/* Cipher 27 */
755 {
756 1,
757 SSL3_TXT_KRB5_RC2_40_CBC_SHA,
758 SSL3_CK_KRB5_RC2_40_CBC_SHA,
759 SSL_kKRB5,
760 SSL_aKRB5,
761 SSL_RC2,
762 SSL_SHA1,
763 SSL_SSLV3,
764 SSL_EXPORT|SSL_EXP40,
765 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
766 40,
767 128,
768 },
769
770/* Cipher 28 */
771 {
772 1,
773 SSL3_TXT_KRB5_RC4_40_SHA,
774 SSL3_CK_KRB5_RC4_40_SHA,
775 SSL_kKRB5,
776 SSL_aKRB5,
777 SSL_RC4,
778 SSL_SHA1,
779 SSL_SSLV3,
780 SSL_EXPORT|SSL_EXP40,
781 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
782 40,
783 128,
784 },
785
786/* Cipher 29 */
787 {
788 1,
789 SSL3_TXT_KRB5_DES_40_CBC_MD5,
790 SSL3_CK_KRB5_DES_40_CBC_MD5,
791 SSL_kKRB5,
792 SSL_aKRB5,
793 SSL_DES,
794 SSL_MD5,
795 SSL_SSLV3,
796 SSL_EXPORT|SSL_EXP40,
797 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
798 40,
799 56,
800 },
801
802/* Cipher 2A */
803 {
804 1,
805 SSL3_TXT_KRB5_RC2_40_CBC_MD5,
806 SSL3_CK_KRB5_RC2_40_CBC_MD5,
807 SSL_kKRB5,
808 SSL_aKRB5,
809 SSL_RC2,
810 SSL_MD5,
811 SSL_SSLV3,
812 SSL_EXPORT|SSL_EXP40,
813 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
814 40,
815 128,
816 },
817
818/* Cipher 2B */
819 {
820 1,
821 SSL3_TXT_KRB5_RC4_40_MD5,
822 SSL3_CK_KRB5_RC4_40_MD5,
823 SSL_kKRB5,
824 SSL_aKRB5,
825 SSL_RC4,
826 SSL_MD5,
827 SSL_SSLV3,
828 SSL_EXPORT|SSL_EXP40,
829 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
830 40,
831 128,
832 },
833#endif /* OPENSSL_NO_KRB5 */
834 608
835/* New AES ciphersuites */ 609/* New AES ciphersuites */
836/* Cipher 2F */ 610/* Cipher 2F */
@@ -2250,151 +2024,6 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[] = {
2250 }, 2024 },
2251#endif /* OPENSSL_NO_ECDH */ 2025#endif /* OPENSSL_NO_ECDH */
2252 2026
2253#ifndef OPENSSL_NO_SRP
2254 /* Cipher C01A */
2255 {
2256 1,
2257 TLS1_TXT_SRP_SHA_WITH_3DES_EDE_CBC_SHA,
2258 TLS1_CK_SRP_SHA_WITH_3DES_EDE_CBC_SHA,
2259 SSL_kSRP,
2260 SSL_aNULL,
2261 SSL_3DES,
2262 SSL_SHA1,
2263 SSL_TLSV1,
2264 SSL_NOT_EXP|SSL_HIGH,
2265 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
2266 168,
2267 168,
2268 },
2269
2270 /* Cipher C01B */
2271 {
2272 1,
2273 TLS1_TXT_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA,
2274 TLS1_CK_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA,
2275 SSL_kSRP,
2276 SSL_aRSA,
2277 SSL_3DES,
2278 SSL_SHA1,
2279 SSL_TLSV1,
2280 SSL_NOT_EXP|SSL_HIGH,
2281 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
2282 168,
2283 168,
2284 },
2285
2286 /* Cipher C01C */
2287 {
2288 1,
2289 TLS1_TXT_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA,
2290 TLS1_CK_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA,
2291 SSL_kSRP,
2292 SSL_aDSS,
2293 SSL_3DES,
2294 SSL_SHA1,
2295 SSL_TLSV1,
2296 SSL_NOT_EXP|SSL_HIGH,
2297 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
2298 168,
2299 168,
2300 },
2301
2302 /* Cipher C01D */
2303 {
2304 1,
2305 TLS1_TXT_SRP_SHA_WITH_AES_128_CBC_SHA,
2306 TLS1_CK_SRP_SHA_WITH_AES_128_CBC_SHA,
2307 SSL_kSRP,
2308 SSL_aNULL,
2309 SSL_AES128,
2310 SSL_SHA1,
2311 SSL_TLSV1,
2312 SSL_NOT_EXP|SSL_HIGH,
2313 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
2314 128,
2315 128,
2316 },
2317
2318 /* Cipher C01E */
2319 {
2320 1,
2321 TLS1_TXT_SRP_SHA_RSA_WITH_AES_128_CBC_SHA,
2322 TLS1_CK_SRP_SHA_RSA_WITH_AES_128_CBC_SHA,
2323 SSL_kSRP,
2324 SSL_aRSA,
2325 SSL_AES128,
2326 SSL_SHA1,
2327 SSL_TLSV1,
2328 SSL_NOT_EXP|SSL_HIGH,
2329 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
2330 128,
2331 128,
2332 },
2333
2334 /* Cipher C01F */
2335 {
2336 1,
2337 TLS1_TXT_SRP_SHA_DSS_WITH_AES_128_CBC_SHA,
2338 TLS1_CK_SRP_SHA_DSS_WITH_AES_128_CBC_SHA,
2339 SSL_kSRP,
2340 SSL_aDSS,
2341 SSL_AES128,
2342 SSL_SHA1,
2343 SSL_TLSV1,
2344 SSL_NOT_EXP|SSL_HIGH,
2345 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
2346 128,
2347 128,
2348 },
2349
2350 /* Cipher C020 */
2351 {
2352 1,
2353 TLS1_TXT_SRP_SHA_WITH_AES_256_CBC_SHA,
2354 TLS1_CK_SRP_SHA_WITH_AES_256_CBC_SHA,
2355 SSL_kSRP,
2356 SSL_aNULL,
2357 SSL_AES256,
2358 SSL_SHA1,
2359 SSL_TLSV1,
2360 SSL_NOT_EXP|SSL_HIGH,
2361 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
2362 256,
2363 256,
2364 },
2365
2366 /* Cipher C021 */
2367 {
2368 1,
2369 TLS1_TXT_SRP_SHA_RSA_WITH_AES_256_CBC_SHA,
2370 TLS1_CK_SRP_SHA_RSA_WITH_AES_256_CBC_SHA,
2371 SSL_kSRP,
2372 SSL_aRSA,
2373 SSL_AES256,
2374 SSL_SHA1,
2375 SSL_TLSV1,
2376 SSL_NOT_EXP|SSL_HIGH,
2377 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
2378 256,
2379 256,
2380 },
2381
2382 /* Cipher C022 */
2383 {
2384 1,
2385 TLS1_TXT_SRP_SHA_DSS_WITH_AES_256_CBC_SHA,
2386 TLS1_CK_SRP_SHA_DSS_WITH_AES_256_CBC_SHA,
2387 SSL_kSRP,
2388 SSL_aDSS,
2389 SSL_AES256,
2390 SSL_SHA1,
2391 SSL_TLSV1,
2392 SSL_NOT_EXP|SSL_HIGH,
2393 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
2394 256,
2395 256,
2396 },
2397#endif /* OPENSSL_NO_SRP */
2398#ifndef OPENSSL_NO_ECDH 2027#ifndef OPENSSL_NO_ECDH
2399 2028
2400 /* HMAC based TLS v1.2 ciphersuites from RFC5289 */ 2029 /* HMAC based TLS v1.2 ciphersuites from RFC5289 */
@@ -2787,9 +2416,6 @@ ssl3_new(SSL *s)
2787 2416
2788 s->s3 = s3; 2417 s->s3 = s3;
2789 2418
2790#ifndef OPENSSL_NO_SRP
2791 SSL_SRP_CTX_init(s);
2792#endif
2793 s->method->ssl_clear(s); 2419 s->method->ssl_clear(s);
2794 return (1); 2420 return (1);
2795err: 2421err:
@@ -2832,9 +2458,6 @@ ssl3_free(SSL *s)
2832 } 2458 }
2833 if (s->s3->handshake_dgst) 2459 if (s->s3->handshake_dgst)
2834 ssl3_free_digest_list(s); 2460 ssl3_free_digest_list(s);
2835#ifndef OPENSSL_NO_SRP
2836 SSL_SRP_CTX_free(s);
2837#endif
2838 OPENSSL_cleanse(s->s3, sizeof *s->s3); 2461 OPENSSL_cleanse(s->s3, sizeof *s->s3);
2839 free(s->s3); 2462 free(s->s3);
2840 s->s3 = NULL; 2463 s->s3 = NULL;
@@ -2919,13 +2542,6 @@ ssl3_clear(SSL *s)
2919#endif 2542#endif
2920} 2543}
2921 2544
2922#ifndef OPENSSL_NO_SRP
2923static char *
2924srp_password_from_info_cb(SSL *s, void *arg)
2925{
2926 return BUF_strdup(s->srp_ctx.info);
2927}
2928#endif
2929 2545
2930long 2546long
2931ssl3_ctrl(SSL *s, int cmd, long larg, void *parg) 2547ssl3_ctrl(SSL *s, int cmd, long larg, void *parg)
@@ -3380,40 +2996,6 @@ ssl3_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg)
3380 return 1; 2996 return 1;
3381 break; 2997 break;
3382 2998
3383#ifndef OPENSSL_NO_SRP
3384 case SSL_CTRL_SET_TLS_EXT_SRP_USERNAME:
3385 ctx->srp_ctx.srp_Mask|=SSL_kSRP;
3386 if (ctx->srp_ctx.login != NULL)
3387 free(ctx->srp_ctx.login);
3388 ctx->srp_ctx.login = NULL;
3389 if (parg == NULL)
3390 break;
3391 if (strlen((const char *)parg) > 255 ||
3392 strlen((const char *)parg) < 1) {
3393 SSLerr(SSL_F_SSL3_CTX_CTRL,
3394 SSL_R_INVALID_SRP_USERNAME);
3395 return 0;
3396 }
3397 if ((ctx->srp_ctx.login = BUF_strdup((char *)parg)) == NULL) {
3398 SSLerr(SSL_F_SSL3_CTX_CTRL,
3399 ERR_R_INTERNAL_ERROR);
3400 return 0;
3401 }
3402 break;
3403 case SSL_CTRL_SET_TLS_EXT_SRP_PASSWORD:
3404 ctx->srp_ctx.SRP_give_srp_client_pwd_callback =
3405 srp_password_from_info_cb;
3406 ctx->srp_ctx.info = parg;
3407 break;
3408 case SSL_CTRL_SET_SRP_ARG:
3409 ctx->srp_ctx.srp_Mask|=SSL_kSRP;
3410 ctx->srp_ctx.SRP_cb_arg = parg;
3411 break;
3412
3413 case SSL_CTRL_SET_TLS_EXT_SRP_STRENGTH:
3414 ctx->srp_ctx.strength = larg;
3415 break;
3416#endif
3417#endif /* !OPENSSL_NO_TLSEXT */ 2999#endif /* !OPENSSL_NO_TLSEXT */
3418 3000
3419 /* A Thawte special :-) */ 3001 /* A Thawte special :-) */
@@ -3491,23 +3073,6 @@ ssl3_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)(void))
3491 unsigned char *, EVP_CIPHER_CTX *, HMAC_CTX *, int))fp; 3073 unsigned char *, EVP_CIPHER_CTX *, HMAC_CTX *, int))fp;
3492 break; 3074 break;
3493 3075
3494#ifndef OPENSSL_NO_SRP
3495 case SSL_CTRL_SET_SRP_VERIFY_PARAM_CB:
3496 ctx->srp_ctx.srp_Mask|=SSL_kSRP;
3497 ctx->srp_ctx.SRP_verify_param_callback =
3498 (int (*)(SSL *, void *))fp;
3499 break;
3500 case SSL_CTRL_SET_TLS_EXT_SRP_USERNAME_CB:
3501 ctx->srp_ctx.srp_Mask|=SSL_kSRP;
3502 ctx->srp_ctx.TLS_ext_srp_username_callback =
3503 (int (*)(SSL *, int *, void *))fp;
3504 break;
3505 case SSL_CTRL_SET_SRP_GIVE_CLIENT_PWD_CB:
3506 ctx->srp_ctx.srp_Mask|=SSL_kSRP;
3507 ctx->srp_ctx.SRP_give_srp_client_pwd_callback =
3508 (char *(*)(SSL *, void *))fp;
3509 break;
3510#endif
3511#endif 3076#endif
3512 default: 3077 default:
3513 return (0); 3078 return (0);
@@ -3616,10 +3181,6 @@ SSL_CIPHER *ssl3_choose_cipher(SSL *s, STACK_OF(SSL_CIPHER) *clnt,
3616 mask_a = cert->mask_a; 3181 mask_a = cert->mask_a;
3617 emask_k = cert->export_mask_k; 3182 emask_k = cert->export_mask_k;
3618 emask_a = cert->export_mask_a; 3183 emask_a = cert->export_mask_a;
3619#ifndef OPENSSL_NO_SRP
3620 mask_k = cert->mask_k | s->srp_ctx.srp_Mask;
3621 emask_k = cert->export_mask_k | s->srp_ctx.srp_Mask;
3622#endif
3623 3184
3624#ifdef KSSL_DEBUG 3185#ifdef KSSL_DEBUG
3625/* printf("ssl3_choose_cipher %d alg= %lx\n", i,c->algorithms);*/ 3186/* printf("ssl3_choose_cipher %d alg= %lx\n", i,c->algorithms);*/
@@ -3628,12 +3189,6 @@ SSL_CIPHER *ssl3_choose_cipher(SSL *s, STACK_OF(SSL_CIPHER) *clnt,
3628 alg_k = c->algorithm_mkey; 3189 alg_k = c->algorithm_mkey;
3629 alg_a = c->algorithm_auth; 3190 alg_a = c->algorithm_auth;
3630 3191
3631#ifndef OPENSSL_NO_KRB5
3632 if (alg_k & SSL_kKRB5) {
3633 if (!kssl_keytab_is_available(s->kssl_ctx) )
3634 continue;
3635 }
3636#endif /* OPENSSL_NO_KRB5 */
3637#ifndef OPENSSL_NO_PSK 3192#ifndef OPENSSL_NO_PSK
3638 /* with PSK there must be server callback set */ 3193 /* with PSK there must be server callback set */
3639 if ((alg_k & SSL_kPSK) && s->psk_server_callback == NULL) 3194 if ((alg_k & SSL_kPSK) && s->psk_server_callback == NULL)
diff --git a/src/lib/libssl/s3_srvr.c b/src/lib/libssl/s3_srvr.c
index 6d8ccd66b7..081aebf1f5 100644
--- a/src/lib/libssl/s3_srvr.c
+++ b/src/lib/libssl/s3_srvr.c
@@ -164,9 +164,6 @@
164#include <openssl/dh.h> 164#include <openssl/dh.h>
165#endif 165#endif
166#include <openssl/bn.h> 166#include <openssl/bn.h>
167#ifndef OPENSSL_NO_KRB5
168#include <openssl/krb5_asn.h>
169#endif
170#include <openssl/md5.h> 167#include <openssl/md5.h>
171 168
172static const SSL_METHOD *ssl3_get_server_method(int ver); 169static const SSL_METHOD *ssl3_get_server_method(int ver);
@@ -179,30 +176,6 @@ ssl3_get_server_method(int ver)
179 return (NULL); 176 return (NULL);
180} 177}
181 178
182#ifndef OPENSSL_NO_SRP
183static int
184ssl_check_srp_ext_ClientHello(SSL *s, int *al)
185{
186 int ret = SSL_ERROR_NONE;
187
188 *al = SSL_AD_UNRECOGNIZED_NAME;
189
190 if ((s->s3->tmp.new_cipher->algorithm_mkey & SSL_kSRP) &&
191 (s->srp_ctx.TLS_ext_srp_username_callback != NULL)) {
192 if (s->srp_ctx.login == NULL) {
193 /*
194 * RFC 5054 says SHOULD reject,
195 * we do so if There is no srp login name
196 */
197 ret = SSL3_AL_FATAL;
198 *al = SSL_AD_UNKNOWN_PSK_IDENTITY;
199 } else {
200 ret = SSL_srp_server_param_with_username(s, al);
201 }
202 }
203 return (ret);
204}
205#endif
206 179
207IMPLEMENT_ssl3_meth_func(SSLv3_server_method, 180IMPLEMENT_ssl3_meth_func(SSLv3_server_method,
208 ssl3_accept, ssl_undefined_function, ssl3_get_server_method) 181 ssl3_accept, ssl_undefined_function, ssl3_get_server_method)
@@ -342,39 +315,6 @@ ssl3_accept(SSL *s)
342 if (ret <= 0) 315 if (ret <= 0)
343 goto end; 316 goto end;
344 } 317 }
345#ifndef OPENSSL_NO_SRP
346 {
347 int al;
348 if ((ret =
349 ssl_check_srp_ext_ClientHello(s, &al))
350 < 0) {
351 /*
352 * Callback indicates further work to
353 * be done.
354 */
355 s->rwstate = SSL_X509_LOOKUP;
356 goto end;
357 }
358 if (ret != SSL_ERROR_NONE) {
359 ssl3_send_alert(s, SSL3_AL_FATAL, al);
360
361 /*
362 * This is not really an error but the
363 * only means for a client to detect
364 * whether srp is supported.
365 */
366 if (al != TLS1_AD_UNKNOWN_PSK_IDENTITY)
367 SSLerr(SSL_F_SSL3_ACCEPT,
368 SSL_R_CLIENTHELLO_TLSEXT);
369
370 ret = SSL_TLSEXT_ERR_ALERT_FATAL;
371
372 ret = -1;
373 goto end;
374
375 }
376 }
377#endif
378 318
379 s->renegotiate = 2; 319 s->renegotiate = 2;
380 s->state = SSL3_ST_SW_SRVR_HELLO_A; 320 s->state = SSL3_ST_SW_SRVR_HELLO_A;
@@ -441,9 +381,6 @@ ssl3_accept(SSL *s)
441 * send_server_key_exchange. 381 * send_server_key_exchange.
442 */ 382 */
443 if ((s->options & SSL_OP_EPHEMERAL_RSA) 383 if ((s->options & SSL_OP_EPHEMERAL_RSA)
444#ifndef OPENSSL_NO_KRB5
445 && !(alg_k & SSL_kKRB5)
446#endif /* OPENSSL_NO_KRB5 */
447 ) 384 )
448 /* 385 /*
449 * option SSL_OP_EPHEMERAL_RSA sends temporary 386 * option SSL_OP_EPHEMERAL_RSA sends temporary
@@ -473,10 +410,6 @@ ssl3_accept(SSL *s)
473#ifndef OPENSSL_NO_PSK 410#ifndef OPENSSL_NO_PSK
474 || ((alg_k & SSL_kPSK) && s->ctx->psk_identity_hint) 411 || ((alg_k & SSL_kPSK) && s->ctx->psk_identity_hint)
475#endif 412#endif
476#ifndef OPENSSL_NO_SRP
477 /* SRP: send ServerKeyExchange */
478 || (alg_k & SSL_kSRP)
479#endif
480 || (alg_k & (SSL_kDHr|SSL_kDHd|SSL_kEDH)) 413 || (alg_k & (SSL_kDHr|SSL_kDHd|SSL_kEDH))
481 || (alg_k & SSL_kEECDH) 414 || (alg_k & SSL_kEECDH)
482 || ((alg_k & SSL_kRSA) 415 || ((alg_k & SSL_kRSA)
@@ -1796,20 +1729,6 @@ ssl3_send_server_key_exchange(SSL *s)
1796 n += 2 + pskhintlen; 1729 n += 2 + pskhintlen;
1797 } else 1730 } else
1798#endif /* !OPENSSL_NO_PSK */ 1731#endif /* !OPENSSL_NO_PSK */
1799#ifndef OPENSSL_NO_SRP
1800 if (type & SSL_kSRP) {
1801 if ((s->srp_ctx.N == NULL) || (s->srp_ctx.g == NULL) ||
1802 (s->srp_ctx.s == NULL) || (s->srp_ctx.B == NULL)) {
1803 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,
1804 SSL_R_MISSING_SRP_PARAM);
1805 goto err;
1806 }
1807 r[0] = s->srp_ctx.N;
1808 r[1] = s->srp_ctx.g;
1809 r[2] = s->srp_ctx.s;
1810 r[3] = s->srp_ctx.B;
1811 } else
1812#endif
1813 { 1732 {
1814 al = SSL_AD_HANDSHAKE_FAILURE; 1733 al = SSL_AD_HANDSHAKE_FAILURE;
1815 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, 1734 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,
@@ -1818,11 +1737,6 @@ ssl3_send_server_key_exchange(SSL *s)
1818 } 1737 }
1819 for (i = 0; i < 4 && r[i] != NULL; i++) { 1738 for (i = 0; i < 4 && r[i] != NULL; i++) {
1820 nr[i] = BN_num_bytes(r[i]); 1739 nr[i] = BN_num_bytes(r[i]);
1821#ifndef OPENSSL_NO_SRP
1822 if ((i == 2) && (type & SSL_kSRP))
1823 n += 1 + nr[i];
1824 else
1825#endif
1826 n += 2 + nr[i]; 1740 n += 2 + nr[i];
1827 } 1741 }
1828 1742
@@ -1848,12 +1762,6 @@ ssl3_send_server_key_exchange(SSL *s)
1848 p = &(d[4]); 1762 p = &(d[4]);
1849 1763
1850 for (i = 0; i < 4 && r[i] != NULL; i++) { 1764 for (i = 0; i < 4 && r[i] != NULL; i++) {
1851#ifndef OPENSSL_NO_SRP
1852 if ((i == 2) && (type & SSL_kSRP)) {
1853 *p = nr[i];
1854 p++;
1855 } else
1856#endif
1857 s2n(nr[i], p); 1765 s2n(nr[i], p);
1858 BN_bn2bin(r[i], p); 1766 BN_bn2bin(r[i], p);
1859 p += nr[i]; 1767 p += nr[i];
@@ -2112,9 +2020,6 @@ ssl3_get_client_key_exchange(SSL *s)
2112 BIGNUM *pub = NULL; 2020 BIGNUM *pub = NULL;
2113 DH *dh_srvr; 2021 DH *dh_srvr;
2114#endif 2022#endif
2115#ifndef OPENSSL_NO_KRB5
2116 KSSL_ERR kssl_err;
2117#endif /* OPENSSL_NO_KRB5 */
2118 2023
2119#ifndef OPENSSL_NO_ECDH 2024#ifndef OPENSSL_NO_ECDH
2120 EC_KEY *srvr_ecdh = NULL; 2025 EC_KEY *srvr_ecdh = NULL;
@@ -2299,191 +2204,6 @@ ssl3_get_client_key_exchange(SSL *s)
2299 OPENSSL_cleanse(p, i); 2204 OPENSSL_cleanse(p, i);
2300 } else 2205 } else
2301#endif 2206#endif
2302#ifndef OPENSSL_NO_KRB5
2303 if (alg_k & SSL_kKRB5) {
2304 krb5_error_code krb5rc;
2305 krb5_data enc_ticket;
2306 krb5_data authenticator;
2307 krb5_data enc_pms;
2308 KSSL_CTX *kssl_ctx = s->kssl_ctx;
2309 EVP_CIPHER_CTX ciph_ctx;
2310 const EVP_CIPHER *enc = NULL;
2311 unsigned char iv[EVP_MAX_IV_LENGTH];
2312 unsigned char pms[SSL_MAX_MASTER_KEY_LENGTH
2313 + EVP_MAX_BLOCK_LENGTH];
2314 int padl, outl;
2315 krb5_timestamp authtime = 0;
2316 krb5_ticket_times ttimes;
2317
2318 EVP_CIPHER_CTX_init(&ciph_ctx);
2319
2320 if (!kssl_ctx)
2321 kssl_ctx = kssl_ctx_new();
2322
2323 n2s(p, i);
2324 enc_ticket.length = i;
2325
2326 if (n < (long)(enc_ticket.length + 6)) {
2327 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2328 SSL_R_DATA_LENGTH_TOO_LONG);
2329 goto err;
2330 }
2331
2332 enc_ticket.data = (char *)p;
2333 p += enc_ticket.length;
2334
2335 n2s(p, i);
2336 authenticator.length = i;
2337
2338 if (n < (long)(enc_ticket.length + authenticator.length + 6)) {
2339 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2340 SSL_R_DATA_LENGTH_TOO_LONG);
2341 goto err;
2342 }
2343
2344 authenticator.data = (char *)p;
2345 p += authenticator.length;
2346
2347 n2s(p, i);
2348 enc_pms.length = i;
2349 enc_pms.data = (char *)p;
2350 p += enc_pms.length;
2351
2352 /*
2353 * Note that the length is checked again below,
2354 * after decryption
2355 */
2356 if (enc_pms.length > sizeof pms) {
2357 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2358 SSL_R_DATA_LENGTH_TOO_LONG);
2359 goto err;
2360 }
2361
2362 if (n != (long)(enc_ticket.length + authenticator.length +
2363 enc_pms.length + 6)) {
2364 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2365 SSL_R_DATA_LENGTH_TOO_LONG);
2366 goto err;
2367 }
2368
2369 if ((krb5rc = kssl_sget_tkt(kssl_ctx, &enc_ticket, &ttimes,
2370 &kssl_err)) != 0) {
2371#ifdef KSSL_DEBUG
2372 printf("kssl_sget_tkt rtn %d [%d]\n",
2373 krb5rc, kssl_err.reason);
2374 if (kssl_err.text)
2375 printf("kssl_err text= %s\n", kssl_err.text);
2376#endif /* KSSL_DEBUG */
2377 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2378 kssl_err.reason);
2379 goto err;
2380 }
2381
2382 /* Note: no authenticator is not considered an error,
2383 ** but will return authtime == 0.
2384 */
2385 if ((krb5rc = kssl_check_authent(kssl_ctx, &authenticator,
2386 &authtime, &kssl_err)) != 0) {
2387#ifdef KSSL_DEBUG
2388 printf("kssl_check_authent rtn %d [%d]\n",
2389 krb5rc, kssl_err.reason);
2390 if (kssl_err.text)
2391 printf("kssl_err text= %s\n", kssl_err.text);
2392#endif /* KSSL_DEBUG */
2393 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2394 kssl_err.reason);
2395 goto err;
2396 }
2397
2398 if ((krb5rc = kssl_validate_times(authtime, &ttimes)) != 0) {
2399 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2400 krb5rc);
2401 goto err;
2402 }
2403
2404#ifdef KSSL_DEBUG
2405 kssl_ctx_show(kssl_ctx);
2406#endif /* KSSL_DEBUG */
2407
2408 enc = kssl_map_enc(kssl_ctx->enctype);
2409 if (enc == NULL)
2410 goto err;
2411
2412 memset(iv, 0, sizeof iv); /* per RFC 1510 */
2413
2414 if (!EVP_DecryptInit_ex(&ciph_ctx, enc, NULL,
2415 kssl_ctx->key, iv)) {
2416 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2417 SSL_R_DECRYPTION_FAILED);
2418 goto err;
2419 }
2420 if (!EVP_DecryptUpdate(&ciph_ctx, pms, &outl,
2421 (unsigned char *)enc_pms.data, enc_pms.length)) {
2422 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2423 SSL_R_DECRYPTION_FAILED);
2424 goto err;
2425 }
2426 if (outl > SSL_MAX_MASTER_KEY_LENGTH) {
2427 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2428 SSL_R_DATA_LENGTH_TOO_LONG);
2429 goto err;
2430 }
2431 if (!EVP_DecryptFinal_ex(&ciph_ctx, &(pms[outl]), &padl)) {
2432 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2433 SSL_R_DECRYPTION_FAILED);
2434 goto err;
2435 }
2436 outl += padl;
2437 if (outl > SSL_MAX_MASTER_KEY_LENGTH) {
2438 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2439 SSL_R_DATA_LENGTH_TOO_LONG);
2440 goto err;
2441 }
2442 if (!((pms[0] == (s->client_version >> 8)) && (pms[1] == (s->client_version & 0xff)))) {
2443 /*
2444 * The premaster secret must contain the same version
2445 * number as the ClientHello to detect version rollback
2446 * attacks (strangely, the protocol does not offer such
2447 * protection for DH ciphersuites).
2448 * However, buggy clients exist that send random bytes
2449 * instead of the protocol version.
2450 *
2451 * If SSL_OP_TLS_ROLLBACK_BUG is set, tolerate such
2452 * clients.
2453 * (Perhaps we should have a separate BUG value for
2454 * the Kerberos cipher)
2455 */
2456 if (!(s->options & SSL_OP_TLS_ROLLBACK_BUG)) {
2457 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2458 SSL_AD_DECODE_ERROR);
2459 goto err;
2460 }
2461 }
2462
2463 EVP_CIPHER_CTX_cleanup(&ciph_ctx);
2464
2465 s->session->master_key_length =
2466 s->method->ssl3_enc->generate_master_secret(s,
2467 s->session->master_key, pms, outl);
2468
2469 if (kssl_ctx->client_princ) {
2470 size_t len = strlen(kssl_ctx->client_princ);
2471 if (len < SSL_MAX_KRB5_PRINCIPAL_LENGTH ) {
2472 s->session->krb5_client_princ_len = len;
2473 memcpy(s->session->krb5_client_princ,
2474 kssl_ctx->client_princ, len);
2475 }
2476 }
2477
2478
2479 /*
2480 * Was doing kssl_ctx_free() here, but it caused problems for
2481 * apache.
2482 * kssl_ctx = kssl_ctx_free(kssl_ctx);
2483 * if (s->kssl_ctx) s->kssl_ctx = NULL;
2484 */
2485 } else
2486#endif /* OPENSSL_NO_KRB5 */
2487 2207
2488#ifndef OPENSSL_NO_ECDH 2208#ifndef OPENSSL_NO_ECDH
2489 if (alg_k & (SSL_kEECDH|SSL_kECDHr|SSL_kECDHe)) { 2209 if (alg_k & (SSL_kEECDH|SSL_kECDHr|SSL_kECDHe)) {
@@ -2717,43 +2437,6 @@ ssl3_get_client_key_exchange(SSL *s)
2717 goto f_err; 2437 goto f_err;
2718 } else 2438 } else
2719#endif 2439#endif
2720#ifndef OPENSSL_NO_SRP
2721 if (alg_k & SSL_kSRP) {
2722 int param_len;
2723
2724 n2s(p, i);
2725 param_len = i + 2;
2726 if (param_len > n) {
2727 al = SSL_AD_DECODE_ERROR;
2728 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2729 SSL_R_BAD_SRP_A_LENGTH);
2730 goto f_err;
2731 }
2732 if (!(s->srp_ctx.A = BN_bin2bn(p, i, NULL))) {
2733 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2734 ERR_R_BN_LIB);
2735 goto err;
2736 }
2737 if (s->session->srp_username != NULL)
2738 free(s->session->srp_username);
2739 s->session->srp_username = BUF_strdup(s->srp_ctx.login);
2740 if (s->session->srp_username == NULL) {
2741 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2742 ERR_R_MALLOC_FAILURE);
2743 goto err;
2744 }
2745
2746 if ((s->session->master_key_length =
2747 SRP_generate_server_master_secret(s,
2748 s->session->master_key)) < 0) {
2749 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2750 ERR_R_INTERNAL_ERROR);
2751 goto err;
2752 }
2753
2754 p += i;
2755 } else
2756#endif /* OPENSSL_NO_SRP */
2757 if (alg_k & SSL_kGOST) { 2440 if (alg_k & SSL_kGOST) {
2758 int ret = 0; 2441 int ret = 0;
2759 EVP_PKEY_CTX *pkey_ctx; 2442 EVP_PKEY_CTX *pkey_ctx;
diff --git a/src/lib/libssl/src/ssl/d1_clnt.c b/src/lib/libssl/src/ssl/d1_clnt.c
index 38118b1385..8967879f70 100644
--- a/src/lib/libssl/src/ssl/d1_clnt.c
+++ b/src/lib/libssl/src/ssl/d1_clnt.c
@@ -115,9 +115,6 @@
115 115
116#include <stdio.h> 116#include <stdio.h>
117#include "ssl_locl.h" 117#include "ssl_locl.h"
118#ifndef OPENSSL_NO_KRB5
119#include "kssl_lcl.h"
120#endif
121#include <openssl/buffer.h> 118#include <openssl/buffer.h>
122#include <openssl/rand.h> 119#include <openssl/rand.h>
123#include <openssl/objects.h> 120#include <openssl/objects.h>
@@ -926,9 +923,6 @@ dtls1_send_client_key_exchange(SSL *s)
926 unsigned long alg_k; 923 unsigned long alg_k;
927 unsigned char *q; 924 unsigned char *q;
928 EVP_PKEY *pkey = NULL; 925 EVP_PKEY *pkey = NULL;
929#ifndef OPENSSL_NO_KRB5
930 KSSL_ERR kssl_err;
931#endif /* OPENSSL_NO_KRB5 */
932#ifndef OPENSSL_NO_ECDH 926#ifndef OPENSSL_NO_ECDH
933 EC_KEY *clnt_ecdh = NULL; 927 EC_KEY *clnt_ecdh = NULL;
934 const EC_POINT *srvr_ecpoint = NULL; 928 const EC_POINT *srvr_ecpoint = NULL;
@@ -992,134 +986,6 @@ dtls1_send_client_key_exchange(SSL *s)
992 tmp_buf, sizeof tmp_buf); 986 tmp_buf, sizeof tmp_buf);
993 OPENSSL_cleanse(tmp_buf, sizeof tmp_buf); 987 OPENSSL_cleanse(tmp_buf, sizeof tmp_buf);
994 } 988 }
995#ifndef OPENSSL_NO_KRB5
996 else if (alg_k & SSL_kKRB5) {
997 krb5_error_code krb5rc;
998 KSSL_CTX *kssl_ctx = s->kssl_ctx;
999 /* krb5_data krb5_ap_req; */
1000 krb5_data *enc_ticket;
1001 krb5_data authenticator, *authp = NULL;
1002 EVP_CIPHER_CTX ciph_ctx;
1003 const EVP_CIPHER *enc = NULL;
1004 unsigned char iv[EVP_MAX_IV_LENGTH];
1005 unsigned char tmp_buf[SSL_MAX_MASTER_KEY_LENGTH];
1006 unsigned char epms[SSL_MAX_MASTER_KEY_LENGTH
1007 + EVP_MAX_IV_LENGTH];
1008 int padl, outl = sizeof(epms);
1009
1010 EVP_CIPHER_CTX_init(&ciph_ctx);
1011
1012#ifdef KSSL_DEBUG
1013 printf("ssl3_send_client_key_exchange(%lx & %lx)\n",
1014 alg_k, SSL_kKRB5);
1015#endif /* KSSL_DEBUG */
1016
1017 authp = NULL;
1018#ifdef KRB5SENDAUTH
1019 if (KRB5SENDAUTH)
1020 authp = &authenticator;
1021#endif /* KRB5SENDAUTH */
1022
1023 krb5rc = kssl_cget_tkt(kssl_ctx, &enc_ticket, authp,
1024 &kssl_err);
1025 enc = kssl_map_enc(kssl_ctx->enctype);
1026 if (enc == NULL)
1027 goto err;
1028#ifdef KSSL_DEBUG
1029 {
1030 printf("kssl_cget_tkt rtn %d\n", krb5rc);
1031 if (krb5rc && kssl_err.text)
1032 printf("kssl_cget_tkt kssl_err=%s\n", kssl_err.text);
1033 }
1034#endif /* KSSL_DEBUG */
1035
1036 if (krb5rc) {
1037 ssl3_send_alert(s, SSL3_AL_FATAL,
1038 SSL_AD_HANDSHAKE_FAILURE);
1039 SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE,
1040 kssl_err.reason);
1041 goto err;
1042 }
1043
1044 /* 20010406 VRS - Earlier versions used KRB5 AP_REQ
1045 ** in place of RFC 2712 KerberosWrapper, as in:
1046 **
1047 ** Send ticket (copy to *p, set n = length)
1048 ** n = krb5_ap_req.length;
1049 ** memcpy(p, krb5_ap_req.data, krb5_ap_req.length);
1050 ** if (krb5_ap_req.data)
1051 ** kssl_krb5_free_data_contents(NULL,&krb5_ap_req);
1052 **
1053 ** Now using real RFC 2712 KerberosWrapper
1054 ** (Thanks to Simon Wilkinson <sxw@sxw.org.uk>)
1055 ** Note: 2712 "opaque" types are here replaced
1056 ** with a 2-byte length followed by the value.
1057 ** Example:
1058 ** KerberosWrapper= xx xx asn1ticket 0 0 xx xx encpms
1059 ** Where "xx xx" = length bytes. Shown here with
1060 ** optional authenticator omitted.
1061 */
1062
1063 /* KerberosWrapper.Ticket */
1064 s2n(enc_ticket->length, p);
1065 memcpy(p, enc_ticket->data, enc_ticket->length);
1066 p += enc_ticket->length;
1067 n = enc_ticket->length + 2;
1068
1069 /* KerberosWrapper.Authenticator */
1070 if (authp && authp->length) {
1071 s2n(authp->length, p);
1072 memcpy(p, authp->data, authp->length);
1073 p += authp->length;
1074 n += authp->length + 2;
1075
1076 free(authp->data);
1077 authp->data = NULL;
1078 authp->length = 0;
1079 } else {
1080 s2n(0, p);/* null authenticator length */
1081 n += 2;
1082 }
1083
1084 if (RAND_bytes(tmp_buf, sizeof tmp_buf) <= 0)
1085 goto err;
1086
1087 /* 20010420 VRS. Tried it this way; failed.
1088 ** EVP_EncryptInit_ex(&ciph_ctx,enc, NULL,NULL);
1089 ** EVP_CIPHER_CTX_set_key_length(&ciph_ctx,
1090 ** kssl_ctx->length);
1091 ** EVP_EncryptInit_ex(&ciph_ctx,NULL, key,iv);
1092 */
1093
1094 memset(iv, 0, sizeof iv);
1095 /* per RFC 1510 */
1096 EVP_EncryptInit_ex(&ciph_ctx, enc, NULL,
1097 kssl_ctx->key, iv);
1098 EVP_EncryptUpdate(&ciph_ctx, epms, &outl, tmp_buf,
1099 sizeof tmp_buf);
1100 EVP_EncryptFinal_ex(&ciph_ctx, &(epms[outl]), &padl);
1101 outl += padl;
1102 if (outl > (int)sizeof epms) {
1103 SSLerr(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);
1104 goto err;
1105 }
1106 EVP_CIPHER_CTX_cleanup(&ciph_ctx);
1107
1108 /* KerberosWrapper.EncryptedPreMasterSecret */
1109 s2n(outl, p);
1110 memcpy(p, epms, outl);
1111 p += outl;
1112 n += outl + 2;
1113
1114 s->session->master_key_length =
1115 s->method->ssl3_enc->generate_master_secret(s,
1116 s->session->master_key,
1117 tmp_buf, sizeof tmp_buf);
1118
1119 OPENSSL_cleanse(tmp_buf, sizeof tmp_buf);
1120 OPENSSL_cleanse(epms, outl);
1121 }
1122#endif
1123#ifndef OPENSSL_NO_DH 989#ifndef OPENSSL_NO_DH
1124 else if (alg_k & (SSL_kEDH|SSL_kDHr|SSL_kDHd)) { 990 else if (alg_k & (SSL_kEDH|SSL_kDHr|SSL_kDHd)) {
1125 DH *dh_srvr, *dh_clnt; 991 DH *dh_srvr, *dh_clnt;
diff --git a/src/lib/libssl/src/ssl/d1_srvr.c b/src/lib/libssl/src/ssl/d1_srvr.c
index 9995278a26..6183815a6d 100644
--- a/src/lib/libssl/src/ssl/d1_srvr.c
+++ b/src/lib/libssl/src/ssl/d1_srvr.c
@@ -429,9 +429,6 @@ dtls1_accept(SSL *s)
429 /* clear this, it may get reset by 429 /* clear this, it may get reset by
430 * send_server_key_exchange */ 430 * send_server_key_exchange */
431 if ((s->options & SSL_OP_EPHEMERAL_RSA) 431 if ((s->options & SSL_OP_EPHEMERAL_RSA)
432#ifndef OPENSSL_NO_KRB5
433 && !(alg_k & SSL_kKRB5)
434#endif /* OPENSSL_NO_KRB5 */
435 ) 432 )
436 /* option SSL_OP_EPHEMERAL_RSA sends temporary RSA key 433 /* option SSL_OP_EPHEMERAL_RSA sends temporary RSA key
437 * even when forbidden by protocol specs 434 * even when forbidden by protocol specs
diff --git a/src/lib/libssl/src/ssl/kssl.c b/src/lib/libssl/src/ssl/kssl.c
deleted file mode 100644
index b04c83e17f..0000000000
--- a/src/lib/libssl/src/ssl/kssl.c
+++ /dev/null
@@ -1,1549 +0,0 @@
1/* ssl/kssl.c -*- mode: C; c-file-style: "eay" -*- */
2/* Written by Vern Staats <staatsvr@asc.hpc.mil> for the OpenSSL project 2000.
3 */
4/* ====================================================================
5 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * 3. All advertising materials mentioning features or use of this
20 * software must display the following acknowledgment:
21 * "This product includes software developed by the OpenSSL Project
22 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
23 *
24 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25 * endorse or promote products derived from this software without
26 * prior written permission. For written permission, please contact
27 * licensing@OpenSSL.org.
28 *
29 * 5. Products derived from this software may not be called "OpenSSL"
30 * nor may "OpenSSL" appear in their names without prior written
31 * permission of the OpenSSL Project.
32 *
33 * 6. Redistributions of any form whatsoever must retain the following
34 * acknowledgment:
35 * "This product includes software developed by the OpenSSL Project
36 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
37 *
38 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49 * OF THE POSSIBILITY OF SUCH DAMAGE.
50 * ====================================================================
51 *
52 * This product includes cryptographic software written by Eric Young
53 * (eay@cryptsoft.com). This product includes software written by Tim
54 * Hudson (tjh@cryptsoft.com).
55 *
56 */
57
58
59/* ssl/kssl.c -- Routines to support (& debug) Kerberos5 auth for openssl
60**
61** 19990701 VRS Started.
62** 200011?? Jeffrey Altman, Richard Levitte
63** Generalized for Heimdal, Newer MIT, & Win32.
64** Integrated into main OpenSSL 0.9.7 snapshots.
65** 20010413 Simon Wilkinson, VRS
66** Real RFC2712 KerberosWrapper replaces AP_REQ.
67*/
68
69#include <openssl/opensslconf.h>
70
71#include <string.h>
72
73#define KRB5_PRIVATE 1
74
75#include <openssl/ssl.h>
76#include <openssl/evp.h>
77#include <openssl/objects.h>
78#include <openssl/krb5_asn.h>
79#include "kssl_lcl.h"
80
81#ifndef OPENSSL_NO_KRB5
82
83#ifndef ENOMEM
84#define ENOMEM KRB5KRB_ERR_GENERIC
85#endif
86
87char *
88kstring(char *string)
89{
90 static char *null = "[NULL]";
91
92 return ((string == NULL) ? null : string);
93}
94
95/* Given KRB5 enctype (basically DES or 3DES),
96** return closest match openssl EVP_ encryption algorithm.
97** Return NULL for unknown or problematic (krb5_dk_encrypt) enctypes.
98** Assume ENCTYPE_*_RAW (krb5_raw_encrypt) are OK.
99*/
100const EVP_CIPHER *
101kssl_map_enc(krb5_enctype enctype)
102{
103 switch (enctype) {
104 case ENCTYPE_DES_HMAC_SHA1: /* EVP_des_cbc(); */
105 case ENCTYPE_DES_CBC_CRC:
106 case ENCTYPE_DES_CBC_MD4:
107 case ENCTYPE_DES_CBC_MD5:
108 case ENCTYPE_DES_CBC_RAW:
109 return EVP_des_cbc();
110 break;
111 case ENCTYPE_DES3_CBC_SHA1: /* EVP_des_ede3_cbc(); */
112 case ENCTYPE_DES3_CBC_SHA:
113 case ENCTYPE_DES3_CBC_RAW:
114 return EVP_des_ede3_cbc();
115 break;
116 default:
117 return NULL;
118 break;
119 }
120}
121
122
123/* Return true:1 if p "looks like" the start of the real authenticator
124** described in kssl_skip_confound() below. The ASN.1 pattern is
125** "62 xx 30 yy" (APPLICATION-2, SEQUENCE), where xx-yy =~ 2, and
126** xx and yy are possibly multi-byte length fields.
127*/
128static int
129kssl_test_confound(unsigned char *p)
130{
131 int len = 2;
132 int xx = 0, yy = 0;
133
134 if (*p++ != 0x62)
135 return 0;
136 if (*p > 0x82)
137 return 0;
138 switch (*p) {
139 case 0x82:
140 p++;
141 xx = (*p++ << 8);
142 xx += *p++;
143 break;
144 case 0x81:
145 p++;
146 xx = *p++;
147 break;
148 case 0x80:
149 return 0;
150 default:
151 xx = *p++;
152 break;
153 }
154 if (*p++ != 0x30)
155 return 0;
156 if (*p > 0x82)
157 return 0;
158 switch (*p) {
159 case 0x82:
160 p++;
161 len += 2;
162 yy = (*p++ << 8);
163 yy += *p++;
164 break;
165 case 0x81:
166 p++;
167 len++;
168 yy = *p++;
169 break;
170 case 0x80:
171 return 0;
172 default:
173 yy = *p++;
174 break;
175 }
176
177 return (xx - len == yy) ? 1 : 0;
178}
179
180/* Allocate, fill, and return cksumlens array of checksum lengths.
181** This array holds just the unique elements from the krb5_cksumarray[].
182** array[n] == 0 signals end of data.
183**
184** The krb5_cksumarray[] was an internal variable that has since been
185** replaced by a more general method for storing the data. It should
186** not be used. Instead we use real API calls and make a guess for
187** what the highest assigned CKSUMTYPE_ constant is. As of 1.2.2
188** it is 0x000c (CKSUMTYPE_HMAC_SHA1_DES3). So we will use 0x0010.
189*/
190static size_t *
191populate_cksumlens(void)
192{
193 int i, j, n;
194 static size_t *cklens = NULL;
195
196#ifdef KRB5_MIT_OLD11
197 n = krb5_max_cksum;
198#else
199 n = 0x0010;
200#endif /* KRB5_MIT_OLD11 */
201
202#ifdef KRB5CHECKAUTH
203 if (!cklens && !(cklens = (size_t *)
204 calloc(sizeof(int), n + 1))) return NULL;
205
206 for (i = 0; i < n; i++) {
207 if (!valid_cksumtype(i))
208 continue; /* array has holes */
209 for (j = 0; j < n; j++) {
210 if (cklens[j] == 0) {
211 cklens[j] = krb5_checksum_size(NULL, i);
212 break;
213 /* krb5 elem was new: add */
214 }
215 if (cklens[j] == krb5_checksum_size(NULL, i)) {
216 break;
217 /* ignore duplicate elements */
218 }
219 }
220 }
221#endif /* KRB5CHECKAUTH */
222
223 return cklens;
224}
225
226/* Return pointer to start of real authenticator within authenticator, or
227** return NULL on error.
228** Decrypted authenticator looks like this:
229** [0 or 8 byte confounder] [4-24 byte checksum] [real authent'r]
230** This hackery wouldn't be necessary if MIT KRB5 1.0.6 had the
231** krb5_auth_con_getcksumtype() function advertised in its krb5.h.
232*/
233unsigned char *
234kssl_skip_confound(krb5_enctype etype, unsigned char *a)
235{
236 int i, conlen;
237 size_t cklen;
238 static size_t *cksumlens = NULL;
239 unsigned char *test_auth;
240
241 conlen = (etype) ? 8 : 0;
242
243 if (!cksumlens && !(cksumlens = populate_cksumlens()))
244 return NULL;
245 for (i = 0; (cklen = cksumlens[i]) != 0; i++) {
246 test_auth = a + conlen + cklen;
247 if (kssl_test_confound(test_auth))
248 return test_auth;
249 }
250
251 return NULL;
252}
253
254
255/* Set kssl_err error info when reason text is a simple string
256** kssl_err = struct { int reason; char text[KSSL_ERR_MAX]; }
257*/
258void
259kssl_err_set(KSSL_ERR *kssl_err, int reason, char *text)
260{
261 if (kssl_err == NULL)
262 return;
263
264 kssl_err->reason = reason;
265 (void) snprintf(kssl_err->text, KSSL_ERR_MAX, "%s", text);
266 return;
267}
268
269
270/* Display contents of krb5_data struct, for debugging
271*/
272void
273print_krb5_data(char *label, krb5_data *kdata)
274{
275 int i;
276
277 printf("%s[%d] ", label, kdata->length);
278 for (i = 0; i < (int)kdata->length; i++) {
279 if (0 && isprint((int) kdata->data[i]))
280 printf( "%c ", kdata->data[i]);
281 else
282 printf( "%02x ", (unsigned char) kdata->data[i]);
283 }
284 printf("\n");
285}
286
287
288/* Display contents of krb5_authdata struct, for debugging
289*/
290void
291print_krb5_authdata(char *label, krb5_authdata **adata)
292{
293 if (adata == NULL) {
294 printf("%s, authdata==0\n", label);
295 return;
296 }
297 printf("%s [%p]\n", label, (void *)adata);
298#if 0
299 {
300 int i;
301 printf("%s[at%d:%d] ", label, adata->ad_type, adata->length);
302 for (i = 0; i < adata->length; i++) {
303 printf((isprint(adata->contents[i]))? "%c ": "%02x",
304 adata->contents[i]);
305 }
306 printf("\n");
307 }
308#endif
309}
310
311
312/* Display contents of krb5_keyblock struct, for debugging
313*/
314void
315print_krb5_keyblock(char *label, krb5_keyblock *keyblk)
316{
317 int i;
318
319 if (keyblk == NULL) {
320 printf("%s, keyblk==0\n", label);
321 return;
322 }
323#ifdef KRB5_HEIMDAL
324 printf("%s\n\t[et%d:%d]: ", label, keyblk->keytype,
325 keyblk->keyvalue->length);
326 for (i = 0; i < (int)keyblk->keyvalue->length; i++) {
327 printf("%02x",(unsigned char *)(keyblk->keyvalue->contents)[i]);
328 }
329 printf("\n");
330#else
331 printf("%s\n\t[et%d:%d]: ", label, keyblk->enctype, keyblk->length);
332 for (i = 0; i < (int)keyblk->length; i++) {
333 printf("%02x", keyblk->contents[i]);
334 }
335 printf("\n");
336#endif
337}
338
339
340/* Display contents of krb5_principal_data struct, for debugging
341** (krb5_principal is typedef'd == krb5_principal_data *)
342*/
343static void
344print_krb5_princ(char *label, krb5_principal_data *princ)
345{
346 int i, ui, uj;
347
348 printf("%s principal Realm: ", label);
349 if (princ == NULL)
350 return;
351 for (ui = 0; ui < (int)princ->realm.length; ui++)
352 putchar(princ->realm.data[ui]);
353 printf(" (nametype %d) has %d strings:\n", princ->type, princ->length);
354 for (i = 0; i < (int)princ->length; i++) {
355 printf("\t%d [%d]: ", i, princ->data[i].length);
356 for (uj = 0; uj < (int)princ->data[i].length; uj++) {
357 putchar(princ->data[i].data[uj]);
358 }
359 printf("\n");
360 }
361 return;
362}
363
364
365/* Given krb5 service (typically "kssl") and hostname in kssl_ctx,
366** Return encrypted Kerberos ticket for service @ hostname.
367** If authenp is non-NULL, also return encrypted authenticator,
368** whose data should be freed by caller.
369** (Originally was: Create Kerberos AP_REQ message for SSL Client.)
370**
371** 19990628 VRS Started; Returns Kerberos AP_REQ message.
372** 20010409 VRS Modified for RFC2712; Returns enc tkt.
373** 20010606 VRS May also return optional authenticator.
374*/
375krb5_error_code
376kssl_cget_tkt(
377 /* UPDATE */ KSSL_CTX *kssl_ctx,
378 /* OUT */ krb5_data **enc_ticketp,
379 /* UPDATE */ krb5_data *authenp,
380 /* OUT */ KSSL_ERR *kssl_err)
381{
382 krb5_error_code krb5rc = KRB5KRB_ERR_GENERIC;
383 krb5_context krb5context = NULL;
384 krb5_auth_context krb5auth_context = NULL;
385 krb5_ccache krb5ccdef = NULL;
386 krb5_creds krb5creds, *krb5credsp = NULL;
387 krb5_data krb5_app_req;
388
389 kssl_err_set(kssl_err, 0, "");
390 memset((char *)&krb5creds, 0, sizeof(krb5creds));
391
392 if (!kssl_ctx) {
393 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
394 "No kssl_ctx defined.\n");
395 goto err;
396 } else if (!kssl_ctx->service_host) {
397 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
398 "kssl_ctx service_host undefined.\n");
399 goto err;
400 }
401
402 if ((krb5rc = krb5_init_context(&krb5context)) != 0) {
403 (void) snprintf(kssl_err->text, KSSL_ERR_MAX,
404 "krb5_init_context() fails: %d\n", krb5rc);
405 kssl_err->reason = SSL_R_KRB5_C_INIT;
406 goto err;
407 }
408
409 if ((krb5rc = krb5_sname_to_principal(krb5context,
410 kssl_ctx->service_host,
411 (kssl_ctx->service_name) ? kssl_ctx->service_name : KRB5SVC,
412 KRB5_NT_SRV_HST, &krb5creds.server)) != 0) {
413 (void) snprintf(kssl_err->text, KSSL_ERR_MAX,
414 "krb5_sname_to_principal() fails for %s/%s\n",
415 kssl_ctx->service_host, (kssl_ctx->service_name) ?
416 kssl_ctx->service_name : KRB5SVC);
417 kssl_err->reason = SSL_R_KRB5_C_INIT;
418 goto err;
419 }
420
421 if ((krb5rc = krb5_cc_default(krb5context, &krb5ccdef)) != 0) {
422 kssl_err_set(kssl_err, SSL_R_KRB5_C_CC_PRINC,
423 "krb5_cc_default fails.\n");
424 goto err;
425 }
426
427 if ((krb5rc = krb5_cc_get_principal(krb5context, krb5ccdef,
428 &krb5creds.client)) != 0) {
429 kssl_err_set(kssl_err, SSL_R_KRB5_C_CC_PRINC,
430 "krb5_cc_get_principal() fails.\n");
431 goto err;
432 }
433
434 if ((krb5rc = krb5_get_credentials(krb5context, 0, krb5ccdef,
435 &krb5creds, &krb5credsp)) != 0) {
436 kssl_err_set(kssl_err, SSL_R_KRB5_C_GET_CRED,
437 "krb5_get_credentials() fails.\n");
438 goto err;
439 }
440
441 *enc_ticketp = &krb5credsp->ticket;
442#ifdef KRB5_HEIMDAL
443 kssl_ctx->enctype = krb5credsp->session.keytype;
444#else
445 kssl_ctx->enctype = krb5credsp->keyblock.enctype;
446#endif
447
448 krb5rc = KRB5KRB_ERR_GENERIC;
449 /* caller should free data of krb5_app_req */
450 /* 20010406 VRS deleted for real KerberosWrapper
451 ** 20010605 VRS reinstated to offer Authenticator to KerberosWrapper
452 */
453 krb5_app_req.length = 0;
454 if (authenp) {
455 krb5_data krb5in_data;
456 const unsigned char *p;
457 long arlen;
458 KRB5_APREQBODY *ap_req;
459
460 authenp->length = 0;
461 krb5in_data.data = NULL;
462 krb5in_data.length = 0;
463 if ((krb5rc = krb5_mk_req_extended(krb5context,
464 &krb5auth_context, 0, &krb5in_data, krb5credsp,
465 &krb5_app_req)) != 0) {
466 kssl_err_set(kssl_err, SSL_R_KRB5_C_MK_REQ,
467 "krb5_mk_req_extended() fails.\n");
468 goto err;
469 }
470
471 arlen = krb5_app_req.length;
472 p = (unsigned char *)krb5_app_req.data;
473 ap_req = (KRB5_APREQBODY *) d2i_KRB5_APREQ(NULL, &p, arlen);
474 if (ap_req) {
475 authenp->length = i2d_KRB5_ENCDATA(
476 ap_req->authenticator, NULL);
477 if (authenp->length &&
478 (authenp->data = malloc(authenp->length))) {
479 unsigned char *adp = (unsigned char *)authenp->data;
480 authenp->length = i2d_KRB5_ENCDATA(
481 ap_req->authenticator, &adp);
482 }
483 }
484
485 if (ap_req)
486 KRB5_APREQ_free((KRB5_APREQ *) ap_req);
487 if (krb5_app_req.length)
488 kssl_krb5_free_data_contents(krb5context, &krb5_app_req);
489 }
490#ifdef KRB5_HEIMDAL
491 if (kssl_ctx_setkey(kssl_ctx, &krb5credsp->session)) {
492 kssl_err_set(kssl_err, SSL_R_KRB5_C_INIT,
493 "kssl_ctx_setkey() fails.\n");
494 }
495#else
496 if (kssl_ctx_setkey(kssl_ctx, &krb5credsp->keyblock)) {
497 kssl_err_set(kssl_err, SSL_R_KRB5_C_INIT,
498 "kssl_ctx_setkey() fails.\n");
499 }
500#endif
501 else
502 krb5rc = 0;
503
504err:
505#ifdef KSSL_DEBUG
506 kssl_ctx_show(kssl_ctx);
507#endif /* KSSL_DEBUG */
508
509 if (krb5creds.client)
510 krb5_free_principal(krb5context, krb5creds.client);
511 if (krb5creds.server)
512 krb5_free_principal(krb5context, krb5creds.server);
513 if (krb5auth_context)
514 krb5_auth_con_free(krb5context, krb5auth_context);
515 if (krb5context)
516 krb5_free_context(krb5context);
517 return (krb5rc);
518}
519
520
521/* Given d2i_-decoded asn1ticket, allocate and return a new krb5_ticket.
522** Return Kerberos error code and kssl_err struct on error.
523** Allocates krb5_ticket and krb5_principal; caller should free these.
524**
525** 20010410 VRS Implemented krb5_decode_ticket() as
526** old_krb5_decode_ticket(). Missing from MIT1.0.6.
527** 20010615 VRS Re-cast as openssl/asn1 d2i_*() functions.
528** Re-used some of the old krb5_decode_ticket()
529** code here. This tkt should alloc/free just
530** like the real thing.
531*/
532static krb5_error_code
533kssl_TKT2tkt(
534 /* IN */ krb5_context krb5context,
535 /* IN */ KRB5_TKTBODY *asn1ticket,
536 /* OUT */ krb5_ticket **krb5ticket,
537 /* OUT */ KSSL_ERR *kssl_err )
538{
539 krb5_error_code krb5rc = KRB5KRB_ERR_GENERIC;
540 krb5_ticket *new5ticket = NULL;
541 ASN1_GENERALSTRING *gstr_svc, *gstr_host;
542
543 *krb5ticket = NULL;
544
545 if (asn1ticket == NULL || asn1ticket->realm == NULL ||
546 asn1ticket->sname == NULL ||
547 sk_ASN1_GENERALSTRING_num(asn1ticket->sname->namestring) < 2) {
548 (void) snprintf(kssl_err->text, KSSL_ERR_MAX,
549 "Null field in asn1ticket.\n");
550 kssl_err->reason = SSL_R_KRB5_S_RD_REQ;
551 return KRB5KRB_ERR_GENERIC;
552 }
553
554 if ((new5ticket = calloc(1, sizeof(krb5_ticket))) == NULL) {
555 (void) snprintf(kssl_err->text, KSSL_ERR_MAX,
556 "Unable to allocate new krb5_ticket.\n");
557 kssl_err->reason = SSL_R_KRB5_S_RD_REQ;
558 return ENOMEM; /* or KRB5KRB_ERR_GENERIC; */
559 }
560
561 gstr_svc = sk_ASN1_GENERALSTRING_value(asn1ticket->sname->namestring, 0);
562 gstr_host = sk_ASN1_GENERALSTRING_value(asn1ticket->sname->namestring, 1);
563
564 if ((krb5rc = kssl_build_principal_2(krb5context, &new5ticket->server,
565 asn1ticket->realm->length, (char *)asn1ticket->realm->data,
566 gstr_svc->length, (char *)gstr_svc->data, gstr_host->length,
567 (char *)gstr_host->data)) != 0) {
568 free(new5ticket);
569 (void) snprintf(kssl_err->text, KSSL_ERR_MAX,
570 "Error building ticket server principal.\n");
571 kssl_err->reason = SSL_R_KRB5_S_RD_REQ;
572 return krb5rc; /* or KRB5KRB_ERR_GENERIC; */
573 }
574
575 krb5_princ_type(krb5context, new5ticket->server) =
576 asn1ticket->sname->nametype->data[0];
577 new5ticket->enc_part.enctype = asn1ticket->encdata->etype->data[0];
578 new5ticket->enc_part.kvno = asn1ticket->encdata->kvno->data[0];
579 new5ticket->enc_part.ciphertext.length =
580 asn1ticket->encdata->cipher->length;
581 if ((new5ticket->enc_part.ciphertext.data =
582 calloc(1, asn1ticket->encdata->cipher->length)) == NULL) {
583 free(new5ticket);
584 (void) snprintf(kssl_err->text, KSSL_ERR_MAX,
585 "Error allocating cipher in krb5ticket.\n");
586 kssl_err->reason = SSL_R_KRB5_S_RD_REQ;
587 return KRB5KRB_ERR_GENERIC;
588 } else {
589 memcpy(new5ticket->enc_part.ciphertext.data,
590 asn1ticket->encdata->cipher->data,
591 asn1ticket->encdata->cipher->length);
592 }
593
594 *krb5ticket = new5ticket;
595 return 0;
596}
597
598
599/* Given krb5 service name in KSSL_CTX *kssl_ctx (typically "kssl"),
600** and krb5 AP_REQ message & message length,
601** Return Kerberos session key and client principle
602** to SSL Server in KSSL_CTX *kssl_ctx.
603**
604** 19990702 VRS Started.
605*/
606krb5_error_code
607kssl_sget_tkt(
608 /* UPDATE */ KSSL_CTX *kssl_ctx,
609 /* IN */ krb5_data *indata,
610 /* OUT */ krb5_ticket_times *ttimes,
611 /* OUT */ KSSL_ERR *kssl_err )
612{
613 krb5_error_code krb5rc = KRB5KRB_ERR_GENERIC;
614 static krb5_context krb5context = NULL;
615 static krb5_auth_context krb5auth_context = NULL;
616 krb5_ticket *krb5ticket = NULL;
617 KRB5_TKTBODY *asn1ticket = NULL;
618 const unsigned char *p;
619 krb5_keytab krb5keytab = NULL;
620 krb5_keytab_entry kt_entry;
621 krb5_principal krb5server;
622 krb5_rcache rcache = NULL;
623
624 kssl_err_set(kssl_err, 0, "");
625
626 if (!kssl_ctx) {
627 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
628 "No kssl_ctx defined.\n");
629 goto err;
630 }
631
632#ifdef KSSL_DEBUG
633 printf("in kssl_sget_tkt(%s)\n", kstring(kssl_ctx->service_name));
634#endif /* KSSL_DEBUG */
635
636 if (!krb5context && (krb5rc = krb5_init_context(&krb5context))) {
637 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
638 "krb5_init_context() fails.\n");
639 goto err;
640 }
641 if (krb5auth_context &&
642 (krb5rc = krb5_auth_con_free(krb5context, krb5auth_context))) {
643 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
644 "krb5_auth_con_free() fails.\n");
645 goto err;
646 } else
647 krb5auth_context = NULL;
648 if (!krb5auth_context &&
649 (krb5rc = krb5_auth_con_init(krb5context, &krb5auth_context))) {
650 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
651 "krb5_auth_con_init() fails.\n");
652 goto err;
653 }
654
655 if ((krb5rc = krb5_auth_con_getrcache(krb5context, krb5auth_context,
656 &rcache))) {
657 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
658 "krb5_auth_con_getrcache() fails.\n");
659 goto err;
660 }
661
662 if ((krb5rc = krb5_sname_to_principal(krb5context, NULL,
663 (kssl_ctx->service_name) ? kssl_ctx->service_name : KRB5SVC,
664 KRB5_NT_SRV_HST, &krb5server)) != 0) {
665 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
666 "krb5_sname_to_principal() fails.\n");
667 goto err;
668 }
669
670 if (rcache == NULL) {
671 if ((krb5rc = krb5_get_server_rcache(krb5context,
672 krb5_princ_component(krb5context, krb5server, 0),
673 &rcache))) {
674 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
675 "krb5_get_server_rcache() fails.\n");
676 goto err;
677 }
678 }
679
680 if ((krb5rc = krb5_auth_con_setrcache(krb5context, krb5auth_context,
681 rcache))) {
682 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
683 "krb5_auth_con_setrcache() fails.\n");
684 goto err;
685 }
686
687
688 /* kssl_ctx->keytab_file == NULL ==> use Kerberos default
689 */
690 if (kssl_ctx->keytab_file) {
691 krb5rc = krb5_kt_resolve(krb5context, kssl_ctx->keytab_file,
692 &krb5keytab);
693 if (krb5rc) {
694 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
695 "krb5_kt_resolve() fails.\n");
696 goto err;
697 }
698 } else {
699 krb5rc = krb5_kt_default(krb5context, &krb5keytab);
700 if (krb5rc) {
701 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
702 "krb5_kt_default() fails.\n");
703 goto err;
704 }
705 }
706
707 /* Actual Kerberos5 krb5_recvauth() has initial conversation here
708 ** o check KRB5_SENDAUTH_BADAUTHVERS
709 ** unless KRB5_RECVAUTH_SKIP_VERSION
710 ** o check KRB5_SENDAUTH_BADAPPLVERS
711 ** o send "0" msg if all OK
712 */
713
714 /* 20010411 was using AP_REQ instead of true KerberosWrapper
715 **
716 ** if ((krb5rc = krb5_rd_req(krb5context, &krb5auth_context,
717 ** &krb5in_data, krb5server, krb5keytab,
718 ** &ap_option, &krb5ticket)) != 0) { Error }
719 */
720
721 p = (unsigned char *)indata->data;
722 if ((asn1ticket = (KRB5_TKTBODY *) d2i_KRB5_TICKET(NULL, &p,
723 (long)indata->length)) == NULL) {
724 (void) snprintf(kssl_err->text, KSSL_ERR_MAX,
725 "d2i_KRB5_TICKET() ASN.1 decode failure.\n");
726 kssl_err->reason = SSL_R_KRB5_S_RD_REQ;
727 goto err;
728 }
729
730 /* Was: krb5rc = krb5_decode_ticket(krb5in_data,&krb5ticket)) != 0) */
731 if ((krb5rc = kssl_TKT2tkt(krb5context, asn1ticket, &krb5ticket,
732 kssl_err)) != 0) {
733 (void) snprintf(kssl_err->text, KSSL_ERR_MAX,
734 "Error converting ASN.1 ticket to krb5_ticket.\n");
735 kssl_err->reason = SSL_R_KRB5_S_RD_REQ;
736 goto err;
737 }
738
739 if (!krb5_principal_compare(krb5context, krb5server,
740 krb5ticket->server)) {
741 krb5rc = KRB5_PRINC_NOMATCH;
742 (void) snprintf(kssl_err->text, KSSL_ERR_MAX,
743 "server principal != ticket principal\n");
744 kssl_err->reason = SSL_R_KRB5_S_RD_REQ;
745 goto err;
746 }
747 if ((krb5rc = krb5_kt_get_entry(krb5context, krb5keytab,
748 krb5ticket->server, krb5ticket->enc_part.kvno,
749 krb5ticket->enc_part.enctype, &kt_entry)) != 0) {
750 (void) snprintf(kssl_err->text, KSSL_ERR_MAX,
751 "krb5_kt_get_entry() fails with %x.\n", krb5rc);
752 kssl_err->reason = SSL_R_KRB5_S_RD_REQ;
753 goto err;
754 }
755 if ((krb5rc = krb5_decrypt_tkt_part(krb5context, &kt_entry.key,
756 krb5ticket)) != 0) {
757 (void) snprintf(kssl_err->text, KSSL_ERR_MAX,
758 "krb5_decrypt_tkt_part() failed.\n");
759 kssl_err->reason = SSL_R_KRB5_S_RD_REQ;
760 goto err;
761 } else {
762 krb5_kt_free_entry(krb5context, &kt_entry);
763#ifdef KSSL_DEBUG
764 {
765 int i;
766 krb5_address **paddr = krb5ticket->enc_part2->caddrs;
767 printf("Decrypted ticket fields:\n");
768 printf("\tflags: %X, transit-type: %X",
769 krb5ticket->enc_part2->flags,
770 krb5ticket->enc_part2->transited.tr_type);
771 print_krb5_data("\ttransit-data: ",
772 &(krb5ticket->enc_part2->transited.tr_contents));
773 printf("\tcaddrs: %p, authdata: %p\n",
774 krb5ticket->enc_part2->caddrs,
775 krb5ticket->enc_part2->authorization_data);
776 if (paddr) {
777 printf("\tcaddrs:\n");
778 for (i = 0; paddr[i] != NULL; i++) {
779 krb5_data d;
780 d.length = paddr[i]->length;
781 d.data = paddr[i]->contents;
782 print_krb5_data("\t\tIP: ", &d);
783 }
784 }
785 printf("\tstart/auth/end times: %d / %d / %d\n",
786 krb5ticket->enc_part2->times.starttime,
787 krb5ticket->enc_part2->times.authtime,
788 krb5ticket->enc_part2->times.endtime);
789 }
790#endif /* KSSL_DEBUG */
791 }
792
793 krb5rc = KRB5_NO_TKT_SUPPLIED;
794 if (!krb5ticket || !krb5ticket->enc_part2 ||
795 !krb5ticket->enc_part2->client ||
796 !krb5ticket->enc_part2->client->data ||
797 !krb5ticket->enc_part2->session) {
798 kssl_err_set(kssl_err, SSL_R_KRB5_S_BAD_TICKET,
799 "bad ticket from krb5_rd_req.\n");
800 } else if (kssl_ctx_setprinc(kssl_ctx, KSSL_CLIENT,
801 &krb5ticket->enc_part2->client->realm,
802 krb5ticket->enc_part2->client->data,
803 krb5ticket->enc_part2->client->length)) {
804 kssl_err_set(kssl_err, SSL_R_KRB5_S_BAD_TICKET,
805 "kssl_ctx_setprinc() fails.\n");
806 } else if (kssl_ctx_setkey(kssl_ctx, krb5ticket->enc_part2->session)) {
807 kssl_err_set(kssl_err, SSL_R_KRB5_S_BAD_TICKET,
808 "kssl_ctx_setkey() fails.\n");
809 } else if (krb5ticket->enc_part2->flags & TKT_FLG_INVALID) {
810 krb5rc = KRB5KRB_AP_ERR_TKT_INVALID;
811 kssl_err_set(kssl_err, SSL_R_KRB5_S_BAD_TICKET,
812 "invalid ticket from krb5_rd_req.\n");
813 } else
814 krb5rc = 0;
815
816 kssl_ctx->enctype = krb5ticket->enc_part.enctype;
817 ttimes->authtime = krb5ticket->enc_part2->times.authtime;
818 ttimes->starttime = krb5ticket->enc_part2->times.starttime;
819 ttimes->endtime = krb5ticket->enc_part2->times.endtime;
820 ttimes->renew_till = krb5ticket->enc_part2->times.renew_till;
821
822err:
823#ifdef KSSL_DEBUG
824 kssl_ctx_show(kssl_ctx);
825#endif /* KSSL_DEBUG */
826
827 if (asn1ticket)
828 KRB5_TICKET_free((KRB5_TICKET *) asn1ticket);
829 if (krb5keytab)
830 krb5_kt_close(krb5context, krb5keytab);
831 if (krb5ticket)
832 krb5_free_ticket(krb5context, krb5ticket);
833 if (krb5server)
834 krb5_free_principal(krb5context, krb5server);
835 return (krb5rc);
836}
837
838
839/* Allocate & return a new kssl_ctx struct.
840*/
841KSSL_CTX *
842kssl_ctx_new(void)
843{
844 return (calloc(1, sizeof(KSSL_CTX)));
845}
846
847
848/* Frees a kssl_ctx struct and any allocated memory it holds.
849** Returns NULL.
850*/
851KSSL_CTX *
852kssl_ctx_free(KSSL_CTX *kssl_ctx)
853{
854 if (kssl_ctx == NULL)
855 return kssl_ctx;
856
857 if (kssl_ctx->key)
858 OPENSSL_cleanse(kssl_ctx->key, kssl_ctx->length);
859 if (kssl_ctx->key)
860 free(kssl_ctx->key);
861 if (kssl_ctx->client_princ)
862 free(kssl_ctx->client_princ);
863 if (kssl_ctx->service_host)
864 free(kssl_ctx->service_host);
865 if (kssl_ctx->service_name)
866 free(kssl_ctx->service_name);
867 if (kssl_ctx->keytab_file)
868 free(kssl_ctx->keytab_file);
869
870 free(kssl_ctx);
871 return (KSSL_CTX *) NULL;
872}
873
874
875/* Given an array of (krb5_data *) entity (and optional realm),
876** set the plain (char *) client_princ or service_host member
877** of the kssl_ctx struct.
878*/
879krb5_error_code
880kssl_ctx_setprinc(KSSL_CTX *kssl_ctx, int which, krb5_data *realm,
881 krb5_data *entity, int nentities)
882{
883 char **princ;
884 int length;
885 int i;
886
887 if (kssl_ctx == NULL || entity == NULL)
888 return KSSL_CTX_ERR;
889
890 switch (which) {
891 case KSSL_CLIENT:
892 princ = &kssl_ctx->client_princ;
893 break;
894 case KSSL_SERVER:
895 princ = &kssl_ctx->service_host;
896 break;
897 default:
898 return KSSL_CTX_ERR;
899 break;
900 }
901 free(*princ);
902 *princ = NULL;
903
904 /* Add up all the entity->lengths */
905 length = 0;
906 for (i = 0; i < nentities; i++) {
907 length += entity[i].length;
908 }
909 /* Add in space for the '/' character(s) (if any) */
910 length += nentities - 1;
911 /* Space for the ('@'+realm+NULL | NULL) */
912 length += ((realm) ? realm->length + 2 : 1);
913
914 if ((*princ = calloc(1, length)) == NULL)
915 return KSSL_CTX_ERR;
916 else {
917 for (i = 0; i < nentities; i++) {
918 strncat(*princ, entity[i].data, entity[i].length);
919 if (i < nentities - 1) {
920 strcat (*princ, "/");
921 }
922 }
923 if (realm) {
924 strcat (*princ, "@");
925 (void) strncat(*princ, realm->data, realm->length);
926 }
927 }
928
929 return KSSL_CTX_OK;
930}
931
932
933/* Set one of the plain (char *) string members of the kssl_ctx struct.
934** Default values should be:
935** which == KSSL_SERVICE => "khost" (KRB5SVC)
936** which == KSSL_KEYTAB => "/etc/krb5.keytab" (KRB5KEYTAB)
937*/
938krb5_error_code
939kssl_ctx_setstring(KSSL_CTX *kssl_ctx, int which, char *text)
940{
941 char **string;
942
943 if (!kssl_ctx)
944 return KSSL_CTX_ERR;
945
946 switch (which) {
947 case KSSL_SERVICE:
948 string = &kssl_ctx->service_name;
949 break;
950 case KSSL_SERVER:
951 string = &kssl_ctx->service_host;
952 break;
953 case KSSL_CLIENT:
954 string = &kssl_ctx->client_princ;
955 break;
956 case KSSL_KEYTAB:
957 string = &kssl_ctx->keytab_file;
958 break;
959 default:
960 return KSSL_CTX_ERR;
961 break;
962 }
963 free(*string);
964 *string = NULL;
965
966 if (text && (*string = strdup(text)) == NULL)
967 return KSSL_CTX_ERR;
968
969 return KSSL_CTX_OK;
970}
971
972
973/* Copy the Kerberos session key from a (krb5_keyblock *) to a kssl_ctx
974** struct. Clear kssl_ctx->key if Kerberos session key is NULL.
975*/
976krb5_error_code
977kssl_ctx_setkey(KSSL_CTX *kssl_ctx, krb5_keyblock *session)
978{
979 int length;
980 krb5_enctype enctype;
981 krb5_octet FAR *contents = NULL;
982
983 if (!kssl_ctx)
984 return KSSL_CTX_ERR;
985
986 if (kssl_ctx->key) {
987 OPENSSL_cleanse(kssl_ctx->key, kssl_ctx->length);
988 free(kssl_ctx->key);
989 kssl_ctx->key = NULL;
990 }
991
992 if (session) {
993
994#ifdef KRB5_HEIMDAL
995 length = session->keyvalue->length;
996 enctype = session->keytype;
997 contents = session->keyvalue->contents;
998#else
999 length = session->length;
1000 enctype = session->enctype;
1001 contents = session->contents;
1002#endif
1003 kssl_ctx->enctype = enctype;
1004 kssl_ctx->length = length;
1005 } else {
1006 kssl_ctx->enctype = ENCTYPE_UNKNOWN;
1007 kssl_ctx->length = 0;
1008 return KSSL_CTX_OK;
1009 }
1010
1011 if ((kssl_ctx->key = calloc(1, kssl_ctx->length)) == NULL) {
1012 kssl_ctx->length = 0;
1013 return KSSL_CTX_ERR;
1014 } else
1015 memcpy(kssl_ctx->key, contents, length);
1016
1017 return KSSL_CTX_OK;
1018}
1019
1020
1021/* Display contents of kssl_ctx struct
1022*/
1023void
1024kssl_ctx_show(KSSL_CTX *kssl_ctx)
1025{
1026 int i;
1027
1028 printf("kssl_ctx: ");
1029 if (kssl_ctx == NULL) {
1030 printf("NULL\n");
1031 return;
1032 } else
1033 printf("%p\n", (void *)kssl_ctx);
1034
1035 printf("\tservice:\t%s\n",
1036 (kssl_ctx->service_name) ? kssl_ctx->service_name : "NULL");
1037 printf("\tclient:\t%s\n",
1038 (kssl_ctx->client_princ) ? kssl_ctx->client_princ : "NULL");
1039 printf("\tserver:\t%s\n",
1040 (kssl_ctx->service_host) ? kssl_ctx->service_host : "NULL");
1041 printf("\tkeytab:\t%s\n",
1042 (kssl_ctx->keytab_file) ? kssl_ctx->keytab_file : "NULL");
1043 printf("\tkey [%d:%d]:\t",
1044 kssl_ctx->enctype, kssl_ctx->length);
1045
1046 for (i = 0; i < kssl_ctx->length && kssl_ctx->key; i++) {
1047 printf("%02x", kssl_ctx->key[i]);
1048 }
1049 printf("\n");
1050 return;
1051}
1052
1053int
1054kssl_keytab_is_available(KSSL_CTX *kssl_ctx)
1055{
1056 krb5_context krb5context = NULL;
1057 krb5_keytab krb5keytab = NULL;
1058 krb5_keytab_entry entry;
1059 krb5_principal princ = NULL;
1060 krb5_error_code krb5rc = KRB5KRB_ERR_GENERIC;
1061 int rc = 0;
1062
1063 if ((krb5rc = krb5_init_context(&krb5context)))
1064 return (0);
1065
1066 /* kssl_ctx->keytab_file == NULL ==> use Kerberos default
1067 */
1068 if (kssl_ctx->keytab_file) {
1069 krb5rc = krb5_kt_resolve(krb5context, kssl_ctx->keytab_file,
1070 &krb5keytab);
1071 if (krb5rc)
1072 goto exit;
1073 } else {
1074 krb5rc = krb5_kt_default(krb5context, &krb5keytab);
1075 if (krb5rc)
1076 goto exit;
1077 }
1078
1079 /* the host key we are looking for */
1080 krb5rc = krb5_sname_to_principal(krb5context, NULL,
1081 kssl_ctx->service_name ? kssl_ctx->service_name : KRB5SVC,
1082 KRB5_NT_SRV_HST, &princ);
1083
1084 if (krb5rc)
1085 goto exit;
1086
1087 krb5rc = krb5_kt_get_entry(krb5context, krb5keytab, princ,
1088 0 /* IGNORE_VNO */,
1089 0 /* IGNORE_ENCTYPE */,
1090 &entry);
1091 if (krb5rc == KRB5_KT_NOTFOUND) {
1092 rc = 1;
1093 goto exit;
1094 } else if (krb5rc)
1095 goto exit;
1096
1097 krb5_kt_free_entry(krb5context, &entry);
1098 rc = 1;
1099
1100exit:
1101 if (krb5keytab)
1102 krb5_kt_close(krb5context, krb5keytab);
1103 if (princ)
1104 krb5_free_principal(krb5context, princ);
1105 if (krb5context)
1106 krb5_free_context(krb5context);
1107 return (rc);
1108}
1109
1110int
1111kssl_tgt_is_available(KSSL_CTX *kssl_ctx)
1112{
1113 krb5_error_code krb5rc = KRB5KRB_ERR_GENERIC;
1114 krb5_context krb5context = NULL;
1115 krb5_ccache krb5ccdef = NULL;
1116 krb5_creds krb5creds, *krb5credsp = NULL;
1117 int rc = 0;
1118
1119 memset((char *)&krb5creds, 0, sizeof(krb5creds));
1120
1121 if (!kssl_ctx)
1122 return (0);
1123
1124 if (!kssl_ctx->service_host)
1125 return (0);
1126
1127 if ((krb5rc = krb5_init_context(&krb5context)) != 0)
1128 goto err;
1129
1130 if ((krb5rc = krb5_sname_to_principal(
1131 krb5context, kssl_ctx->service_host,
1132 (kssl_ctx->service_name) ? kssl_ctx->service_name : KRB5SVC,
1133 KRB5_NT_SRV_HST, &krb5creds.server)) != 0)
1134 goto err;
1135
1136 if ((krb5rc = krb5_cc_default(krb5context, &krb5ccdef)) != 0)
1137 goto err;
1138
1139 if ((krb5rc = krb5_cc_get_principal(krb5context, krb5ccdef,
1140 &krb5creds.client)) != 0)
1141 goto err;
1142
1143 if ((krb5rc = krb5_get_credentials(krb5context, 0, krb5ccdef,
1144 &krb5creds, &krb5credsp)) != 0)
1145 goto err;
1146
1147 rc = 1;
1148
1149err:
1150#ifdef KSSL_DEBUG
1151 kssl_ctx_show(kssl_ctx);
1152#endif /* KSSL_DEBUG */
1153
1154 if (krb5creds.client)
1155 krb5_free_principal(krb5context, krb5creds.client);
1156 if (krb5creds.server)
1157 krb5_free_principal(krb5context, krb5creds.server);
1158 if (krb5context)
1159 krb5_free_context(krb5context);
1160 return (rc);
1161}
1162
1163void
1164kssl_krb5_free_data_contents(krb5_context context, krb5_data *data)
1165{
1166#ifdef KRB5_HEIMDAL
1167 data->length = 0;
1168 if (data->data)
1169 free(data->data);
1170#elif defined(KRB5_MIT_OLD11)
1171 if (data->data) {
1172 krb5_xfree(data->data);
1173 data->data = 0;
1174 }
1175#else
1176 krb5_free_data_contents(NULL, data);
1177#endif
1178}
1179
1180/* Given pointers to KerberosTime and struct tm structs, convert the
1181** KerberosTime string to struct tm. Note that KerberosTime is a
1182** ASN1_GENERALIZEDTIME value, constrained to GMT with no fractional
1183** seconds as defined in RFC 1510.
1184** Return pointer to the (partially) filled in struct tm on success,
1185** return NULL on failure.
1186*/
1187static struct tm *
1188k_gmtime(ASN1_GENERALIZEDTIME *gtime, struct tm *k_tm)
1189{
1190 char c, *p;
1191
1192 if (!k_tm)
1193 return NULL;
1194 if (gtime == NULL || gtime->length < 14)
1195 return NULL;
1196 if (gtime->data == NULL)
1197 return NULL;
1198
1199 p = (char *)&gtime->data[14];
1200
1201 c = *p;
1202 *p = '\0';
1203 p -= 2;
1204 k_tm->tm_sec = atoi(p);
1205 *(p + 2) = c;
1206 c = *p;
1207 *p = '\0';
1208 p -= 2;
1209 k_tm->tm_min = atoi(p);
1210 *(p + 2) = c;
1211 c = *p;
1212 *p = '\0';
1213 p -= 2;
1214 k_tm->tm_hour = atoi(p);
1215 *(p + 2) = c;
1216 c = *p;
1217 *p = '\0';
1218 p -= 2;
1219 k_tm->tm_mday = atoi(p);
1220 *(p + 2) = c;
1221 c = *p;
1222 *p = '\0';
1223 p -= 2;
1224 k_tm->tm_mon = atoi(p) - 1;
1225 *(p + 2) = c;
1226 c = *p;
1227 *p = '\0';
1228 p -= 4;
1229 k_tm->tm_year = atoi(p) - 1900;
1230 *(p + 4) = c;
1231
1232 return k_tm;
1233}
1234
1235
1236/* Helper function for kssl_validate_times().
1237** We need context->clockskew, but krb5_context is an opaque struct.
1238** So we try to sneek the clockskew out through the replay cache.
1239** If that fails just return a likely default (300 seconds).
1240*/
1241static krb5_deltat
1242get_rc_clockskew(krb5_context context)
1243{
1244 krb5_rcache rc;
1245 krb5_deltat clockskew;
1246
1247 if (krb5_rc_default(context, &rc))
1248 return KSSL_CLOCKSKEW;
1249 if (krb5_rc_initialize(context, rc, 0))
1250 return KSSL_CLOCKSKEW;
1251 if (krb5_rc_get_lifespan(context, rc, &clockskew)) {
1252 clockskew = KSSL_CLOCKSKEW;
1253 }
1254 (void)krb5_rc_destroy(context, rc);
1255 return clockskew;
1256}
1257
1258
1259/* kssl_validate_times() combines (and more importantly exposes)
1260** the MIT KRB5 internal function krb5_validate_times() and the
1261** in_clock_skew() macro. The authenticator client time is checked
1262** to be within clockskew secs of the current time and the current
1263** time is checked to be within the ticket start and expire times.
1264** Either check may be omitted by supplying a NULL value.
1265** Returns 0 for valid times, SSL_R_KRB5* error codes otherwise.
1266** See Also: (Kerberos source)/krb5/lib/krb5/krb/valid_times.c
1267** 20010420 VRS
1268*/
1269krb5_error_code
1270kssl_validate_times(krb5_timestamp atime, krb5_ticket_times *ttimes)
1271{
1272 krb5_deltat skew;
1273 krb5_timestamp start, now;
1274 krb5_error_code rc;
1275 krb5_context context;
1276
1277 if ((rc = krb5_init_context(&context)))
1278 return SSL_R_KRB5_S_BAD_TICKET;
1279 skew = get_rc_clockskew(context);
1280
1281 if ((rc = krb5_timeofday(context, &now)))
1282 return SSL_R_KRB5_S_BAD_TICKET;
1283 krb5_free_context(context);
1284
1285 if (atime && labs(atime - now) >= skew)
1286 return SSL_R_KRB5_S_TKT_SKEW;
1287
1288 if (!ttimes)
1289 return 0;
1290
1291 start = (ttimes->starttime != 0) ? ttimes->starttime : ttimes->authtime;
1292 if (start - now > skew)
1293 return SSL_R_KRB5_S_TKT_NYV;
1294 if ((now - ttimes->endtime) > skew)
1295 return SSL_R_KRB5_S_TKT_EXPIRED;
1296
1297#ifdef KSSL_DEBUG
1298 printf("kssl_validate_times: %d |<- | %d - %d | < %d ->| %d\n",
1299 start, atime, now, skew, ttimes->endtime);
1300#endif /* KSSL_DEBUG */
1301
1302 return 0;
1303}
1304
1305
1306/* Decode and decrypt given DER-encoded authenticator, then pass
1307** authenticator ctime back in *atimep (or 0 if time unavailable).
1308** Returns krb5_error_code and kssl_err on error. A NULL
1309** authenticator (authentp->length == 0) is not considered an error.
1310** Note that kssl_check_authent() makes use of the KRB5 session key;
1311** you must call kssl_sget_tkt() to get the key before calling this routine.
1312*/
1313krb5_error_code
1314kssl_check_authent(
1315 /* IN */ KSSL_CTX *kssl_ctx,
1316 /* IN */ krb5_data *authentp,
1317 /* OUT */ krb5_timestamp *atimep,
1318 /* OUT */ KSSL_ERR *kssl_err )
1319{
1320 krb5_error_code krb5rc = 0;
1321 KRB5_ENCDATA *dec_authent = NULL;
1322 KRB5_AUTHENTBODY *auth = NULL;
1323 krb5_enctype enctype;
1324 EVP_CIPHER_CTX ciph_ctx;
1325 const EVP_CIPHER *enc = NULL;
1326 unsigned char iv[EVP_MAX_IV_LENGTH];
1327 const unsigned char *p;
1328 unsigned char *unenc_authent;
1329 int outl, unencbufsize;
1330 struct tm tm_time, *tm_l, *tm_g;
1331 time_t now, tl, tg, tr, tz_offset;
1332
1333 EVP_CIPHER_CTX_init(&ciph_ctx);
1334 *atimep = 0;
1335 kssl_err_set(kssl_err, 0, "");
1336
1337#ifndef KRB5CHECKAUTH
1338 authentp = NULL;
1339#else
1340#if KRB5CHECKAUTH == 0
1341 authentp = NULL;
1342#endif
1343#endif /* KRB5CHECKAUTH */
1344
1345 if (authentp == NULL || authentp->length == 0)
1346 return 0;
1347
1348#ifdef KSSL_DEBUG
1349 {
1350 unsigned int ui;
1351 printf("kssl_check_authent: authenticator[%d]:\n", authentp->length);
1352 p = authentp->data;
1353
1354 for (ui = 0; ui < authentp->length; ui++) printf("%02x ", p[ui]);
1355 printf("\n");
1356 }
1357#endif /* KSSL_DEBUG */
1358
1359 unencbufsize = 2 * authentp->length;
1360 if ((unenc_authent = calloc(1, unencbufsize)) == NULL) {
1361 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
1362 "Unable to allocate authenticator buffer.\n");
1363 krb5rc = KRB5KRB_ERR_GENERIC;
1364 goto err;
1365 }
1366
1367 p = (unsigned char *)authentp->data;
1368 if ((dec_authent = d2i_KRB5_ENCDATA(NULL, &p,
1369 (long)authentp->length)) == NULL) {
1370 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
1371 "Error decoding authenticator.\n");
1372 krb5rc = KRB5KRB_AP_ERR_BAD_INTEGRITY;
1373 goto err;
1374 }
1375
1376 enctype = dec_authent->etype->data[0]; /* should = kssl_ctx->enctype */
1377#if !defined(KRB5_MIT_OLD11)
1378 switch (enctype ) {
1379 case ENCTYPE_DES3_CBC_SHA1: /* EVP_des_ede3_cbc(); */
1380 case ENCTYPE_DES3_CBC_SHA:
1381 case ENCTYPE_DES3_CBC_RAW:
1382 krb5rc = 0;
1383 /* Skip, can't handle derived keys */
1384 goto err;
1385 }
1386#endif
1387 enc = kssl_map_enc(enctype);
1388 memset(iv, 0, sizeof iv);
1389 /* per RFC 1510 */
1390
1391 if (enc == NULL) {
1392 /* Disable kssl_check_authent for ENCTYPE_DES3_CBC_SHA1.
1393 ** This enctype indicates the authenticator was encrypted
1394 ** using key-usage derived keys which openssl cannot decrypt.
1395 */
1396 goto err;
1397 }
1398
1399 if (!EVP_CipherInit(&ciph_ctx, enc, kssl_ctx->key, iv, 0)) {
1400 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
1401 "EVP_CipherInit error decrypting authenticator.\n");
1402 krb5rc = KRB5KRB_AP_ERR_BAD_INTEGRITY;
1403 goto err;
1404 }
1405 outl = dec_authent->cipher->length;
1406 if (!EVP_Cipher(&ciph_ctx, unenc_authent, dec_authent->cipher->data, outl)) {
1407 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
1408 "EVP_Cipher error decrypting authenticator.\n");
1409 krb5rc = KRB5KRB_AP_ERR_BAD_INTEGRITY;
1410 goto err;
1411 }
1412 EVP_CIPHER_CTX_cleanup(&ciph_ctx);
1413
1414#ifdef KSSL_DEBUG
1415 {
1416 int padl;
1417 printf("kssl_check_authent: decrypted authenticator[%d] =\n", outl);
1418 for (padl = 0; padl < outl; padl++) printf("%02x ", unenc_authent[padl]);
1419 printf("\n");
1420 }
1421#endif /* KSSL_DEBUG */
1422
1423 if ((p = kssl_skip_confound(enctype, unenc_authent)) == NULL) {
1424 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
1425 "confounded by authenticator.\n");
1426 krb5rc = KRB5KRB_AP_ERR_BAD_INTEGRITY;
1427 goto err;
1428 }
1429 outl -= p - unenc_authent;
1430
1431 if ((auth = (KRB5_AUTHENTBODY *)d2i_KRB5_AUTHENT(NULL, &p,
1432 (long)outl)) == NULL) {
1433 kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT,
1434 "Error decoding authenticator body.\n");
1435 krb5rc = KRB5KRB_AP_ERR_BAD_INTEGRITY;
1436 goto err;
1437 }
1438
1439 memset(&tm_time, 0, sizeof(struct tm));
1440 if (k_gmtime(auth->ctime, &tm_time) &&
1441 ((tr = mktime(&tm_time)) != (time_t)(-1))) {
1442 now = time(&now);
1443 tm_l = localtime(&now);
1444 tl = mktime(tm_l);
1445 tm_g = gmtime(&now);
1446 tg = mktime(tm_g);
1447 tz_offset = tg - tl;
1448
1449 *atimep = (krb5_timestamp)(tr - tz_offset);
1450 }
1451
1452#ifdef KSSL_DEBUG
1453 printf("kssl_check_authent: returns %d for client time ", *atimep);
1454 if (auth && auth->ctime && auth->ctime->length && auth->ctime->data)
1455 printf("%.*s\n", auth->ctime->length, auth->ctime->data);
1456 else
1457 printf("NULL\n");
1458#endif /* KSSL_DEBUG */
1459
1460err:
1461 if (auth)
1462 KRB5_AUTHENT_free((KRB5_AUTHENT *) auth);
1463 if (dec_authent)
1464 KRB5_ENCDATA_free(dec_authent);
1465 if (unenc_authent)
1466 free(unenc_authent);
1467 EVP_CIPHER_CTX_cleanup(&ciph_ctx);
1468 return krb5rc;
1469}
1470
1471
1472/* Replaces krb5_build_principal_ext(), with varargs length == 2 (svc, host),
1473** because I dont't know how to stub varargs.
1474** Returns krb5_error_code == ENOMEM on alloc error, otherwise
1475** passes back newly constructed principal, which should be freed by caller.
1476*/
1477krb5_error_code
1478kssl_build_principal_2(
1479 /* UPDATE */ krb5_context context,
1480 /* OUT */ krb5_principal *princ,
1481 /* IN */ int rlen, const char *realm,
1482 /* IN */ int slen, const char *svc,
1483 /* IN */ int hlen, const char *host)
1484{
1485 krb5_data *p_data = NULL;
1486 krb5_principal new_p = NULL;
1487 char *new_r = NULL;
1488
1489 if ((p_data = calloc(2, sizeof(krb5_data))) == NULL ||
1490 (new_p = calloc(1, sizeof(krb5_principal_data))) == NULL)
1491 goto err;
1492 new_p->length = 2;
1493 new_p->data = p_data;
1494
1495 if ((new_r = calloc(1, rlen + 1)) == NULL)
1496 goto err;
1497 memcpy(new_r, realm, rlen);
1498 krb5_princ_set_realm_length(context, new_p, rlen);
1499 krb5_princ_set_realm_data(context, new_p, new_r);
1500
1501 if ((new_p->data[0].data = calloc(1, slen + 1)) == NULL)
1502 goto err;
1503 memcpy(new_p->data[0].data, svc, slen);
1504 new_p->data[0].length = slen;
1505
1506 if ((new_p->data[1].data = calloc(1, hlen + 1)) == NULL)
1507 goto err;
1508 memcpy(new_p->data[1].data, host, hlen);
1509 new_p->data[1].length = hlen;
1510
1511 krb5_princ_type(context, new_p) = KRB5_NT_UNKNOWN;
1512 *princ = new_p;
1513 return 0;
1514
1515err:
1516 if (new_p && new_p[0].data)
1517 free(new_p[0].data);
1518 if (new_p && new_p[1].data)
1519 free(new_p[1].data);
1520 if (new_p)
1521 free(new_p);
1522 if (new_r)
1523 free(new_r);
1524 return ENOMEM;
1525}
1526
1527void
1528SSL_set0_kssl_ctx(SSL *s, KSSL_CTX *kctx)
1529{
1530 s->kssl_ctx = kctx;
1531}
1532
1533KSSL_CTX *
1534SSL_get0_kssl_ctx(SSL *s)
1535{
1536 return s->kssl_ctx;
1537}
1538
1539char *
1540kssl_ctx_get0_client_princ(KSSL_CTX *kctx)
1541{
1542 if (kctx)
1543 return kctx->client_princ;
1544 return NULL;
1545}
1546
1547#else /* !OPENSSL_NO_KRB5 */
1548
1549#endif /* !OPENSSL_NO_KRB5 */
diff --git a/src/lib/libssl/src/ssl/kssl.h b/src/lib/libssl/src/ssl/kssl.h
index ec75188a8e..5070066cb3 100644
--- a/src/lib/libssl/src/ssl/kssl.h
+++ b/src/lib/libssl/src/ssl/kssl.h
@@ -65,118 +65,4 @@
65 65
66#include <openssl/opensslconf.h> 66#include <openssl/opensslconf.h>
67 67
68#ifndef OPENSSL_NO_KRB5
69
70#include <stdio.h>
71#include <ctype.h>
72#include <krb5.h>
73
74#ifdef __cplusplus
75extern "C" {
76#endif
77
78/*
79** Depending on which KRB5 implementation used, some types from
80** the other may be missing. Resolve that here and now
81*/
82#ifdef KRB5_HEIMDAL
83typedef unsigned char krb5_octet;
84#define FAR
85#else
86
87#ifndef FAR
88#define FAR
89#endif
90
91#endif
92
93/* Uncomment this to debug kssl problems or
94** to trace usage of the Kerberos session key
95**
96** #define KSSL_DEBUG
97*/
98
99#ifndef KRB5SVC
100#define KRB5SVC "host"
101#endif
102
103#ifndef KRB5KEYTAB
104#define KRB5KEYTAB "/etc/krb5.keytab"
105#endif
106
107#ifndef KRB5SENDAUTH
108#define KRB5SENDAUTH 1
109#endif
110
111#ifndef KRB5CHECKAUTH
112#define KRB5CHECKAUTH 1
113#endif
114
115#ifndef KSSL_CLOCKSKEW
116#define KSSL_CLOCKSKEW 300;
117#endif
118
119#define KSSL_ERR_MAX 256
120typedef struct kssl_err_st {
121 int reason;
122 char text[KSSL_ERR_MAX];
123} KSSL_ERR;
124
125
126/* Context for passing
127** (1) Kerberos session key to SSL, and
128** (2) Config data between application and SSL lib
129*/
130typedef struct kssl_ctx_st {
131 /* used by: disposition: */
132 char *service_name; /* C,S default ok (kssl) */
133 char *service_host; /* C input, REQUIRED */
134 char *client_princ; /* S output from krb5 ticket */
135 char *keytab_file; /* S NULL (/etc/krb5.keytab) */
136 char *cred_cache; /* C NULL (default) */
137 krb5_enctype enctype;
138 int length;
139 krb5_octet FAR *key;
140} KSSL_CTX;
141
142#define KSSL_CLIENT 1
143#define KSSL_SERVER 2
144#define KSSL_SERVICE 3
145#define KSSL_KEYTAB 4
146
147#define KSSL_CTX_OK 0
148#define KSSL_CTX_ERR 1
149#define KSSL_NOMEM 2
150
151/* Public (for use by applications that use OpenSSL with Kerberos 5 support */
152krb5_error_code kssl_ctx_setstring(KSSL_CTX *kssl_ctx, int which, char *text);
153KSSL_CTX *kssl_ctx_new(void);
154KSSL_CTX *kssl_ctx_free(KSSL_CTX *kssl_ctx);
155void kssl_ctx_show(KSSL_CTX *kssl_ctx);
156krb5_error_code kssl_ctx_setprinc(KSSL_CTX *kssl_ctx, int which,
157 krb5_data *realm, krb5_data *entity, int nentities);
158krb5_error_code kssl_cget_tkt(KSSL_CTX *kssl_ctx, krb5_data **enc_tktp,
159 krb5_data *authenp, KSSL_ERR *kssl_err);
160krb5_error_code kssl_sget_tkt(KSSL_CTX *kssl_ctx, krb5_data *indata,
161 krb5_ticket_times *ttimes, KSSL_ERR *kssl_err);
162krb5_error_code kssl_ctx_setkey(KSSL_CTX *kssl_ctx, krb5_keyblock *session);
163void kssl_err_set(KSSL_ERR *kssl_err, int reason, char *text);
164void kssl_krb5_free_data_contents(krb5_context context, krb5_data *data);
165krb5_error_code kssl_build_principal_2(krb5_context context,
166 krb5_principal *princ, int rlen, const char *realm, int slen,
167 const char *svc, int hlen, const char *host);
168krb5_error_code kssl_validate_times(krb5_timestamp atime,
169 krb5_ticket_times *ttimes);
170krb5_error_code kssl_check_authent(KSSL_CTX *kssl_ctx, krb5_data *authentp,
171 krb5_timestamp *atimep, KSSL_ERR *kssl_err);
172unsigned char *kssl_skip_confound(krb5_enctype enctype, unsigned char *authn);
173
174void SSL_set0_kssl_ctx(SSL *s, KSSL_CTX *kctx);
175KSSL_CTX *SSL_get0_kssl_ctx(SSL *s);
176char *kssl_ctx_get0_client_princ(KSSL_CTX *kctx);
177
178#ifdef __cplusplus
179}
180#endif
181#endif /* OPENSSL_NO_KRB5 */
182#endif /* KSSL_H */ 68#endif /* KSSL_H */
diff --git a/src/lib/libssl/src/ssl/kssl_lcl.h b/src/lib/libssl/src/ssl/kssl_lcl.h
index c039c91b4e..35e203b7d6 100644
--- a/src/lib/libssl/src/ssl/kssl_lcl.h
+++ b/src/lib/libssl/src/ssl/kssl_lcl.h
@@ -61,27 +61,4 @@
61 61
62#include <openssl/kssl.h> 62#include <openssl/kssl.h>
63 63
64#ifndef OPENSSL_NO_KRB5
65
66#ifdef __cplusplus
67extern "C" {
68#endif
69
70/* Private (internal to OpenSSL) */
71void print_krb5_data(char *label, krb5_data *kdata);
72void print_krb5_authdata(char *label, krb5_authdata **adata);
73void print_krb5_keyblock(char *label, krb5_keyblock *keyblk);
74
75char *kstring(char *string);
76char *knumber(int len, krb5_octet *contents);
77
78const EVP_CIPHER *kssl_map_enc(krb5_enctype enctype);
79
80int kssl_keytab_is_available(KSSL_CTX *kssl_ctx);
81int kssl_tgt_is_available(KSSL_CTX *kssl_ctx);
82
83#ifdef __cplusplus
84}
85#endif
86#endif /* OPENSSL_NO_KRB5 */
87#endif /* KSSL_LCL_H */ 64#endif /* KSSL_LCL_H */
diff --git a/src/lib/libssl/src/ssl/s3_clnt.c b/src/lib/libssl/src/ssl/s3_clnt.c
index eb55fc9682..68817cd33a 100644
--- a/src/lib/libssl/src/ssl/s3_clnt.c
+++ b/src/lib/libssl/src/ssl/s3_clnt.c
@@ -369,17 +369,6 @@ ssl3_connect(SSL *s)
369 ret = ssl3_get_server_done(s); 369 ret = ssl3_get_server_done(s);
370 if (ret <= 0) 370 if (ret <= 0)
371 goto end; 371 goto end;
372#ifndef OPENSSL_NO_SRP
373 if (s->s3->tmp.new_cipher->algorithm_mkey & SSL_kSRP) {
374 if ((ret = SRP_Calc_A_param(s)) <= 0) {
375 SSLerr(SSL_F_SSL3_CONNECT,
376 SSL_R_SRP_A_CALC);
377 ssl3_send_alert(s, SSL3_AL_FATAL,
378 SSL_AD_INTERNAL_ERROR);
379 goto end;
380 }
381 }
382#endif
383 if (s->s3->tmp.cert_req) 372 if (s->s3->tmp.cert_req)
384 s->state = SSL3_ST_CW_CERT_A; 373 s->state = SSL3_ST_CW_CERT_A;
385 else 374 else
@@ -1137,10 +1126,6 @@ ssl3_get_server_certificate(SSL *s)
1137 1126
1138 i = ssl_verify_cert_chain(s, sk); 1127 i = ssl_verify_cert_chain(s, sk);
1139 if ((s->verify_mode != SSL_VERIFY_NONE) && (i <= 0) 1128 if ((s->verify_mode != SSL_VERIFY_NONE) && (i <= 0)
1140#ifndef OPENSSL_NO_KRB5
1141 && !((s->s3->tmp.new_cipher->algorithm_mkey & SSL_kKRB5) &&
1142 (s->s3->tmp.new_cipher->algorithm_auth & SSL_aKRB5))
1143#endif /* OPENSSL_NO_KRB5 */
1144 ) { 1129 ) {
1145 al = ssl_verify_alarm_type(s->verify_result); 1130 al = ssl_verify_alarm_type(s->verify_result);
1146 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE, 1131 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,
@@ -1361,81 +1346,6 @@ ssl3_get_key_exchange(SSL *s)
1361 n -= param_len; 1346 n -= param_len;
1362 } else 1347 } else
1363#endif /* !OPENSSL_NO_PSK */ 1348#endif /* !OPENSSL_NO_PSK */
1364#ifndef OPENSSL_NO_SRP
1365 if (alg_k & SSL_kSRP) {
1366 n2s(p, i);
1367 param_len = i + 2;
1368 if (param_len > n) {
1369 al = SSL_AD_DECODE_ERROR;
1370 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,
1371 SSL_R_BAD_SRP_N_LENGTH);
1372 goto f_err;
1373 }
1374 if (!(s->srp_ctx.N = BN_bin2bn(p, i, NULL))) {
1375 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,
1376 ERR_R_BN_LIB);
1377 goto err;
1378 }
1379 p += i;
1380
1381 n2s(p, i);
1382 param_len += i + 2;
1383 if (param_len > n) {
1384 al = SSL_AD_DECODE_ERROR;
1385 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,
1386 SSL_R_BAD_SRP_G_LENGTH);
1387 goto f_err;
1388 }
1389 if (!(s->srp_ctx.g = BN_bin2bn(p, i, NULL))) {
1390 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,
1391 ERR_R_BN_LIB);
1392 goto err;
1393 }
1394 p += i;
1395
1396 i = (unsigned int)(p[0]);
1397 p++;
1398 param_len += i + 1;
1399 if (param_len > n) {
1400 al = SSL_AD_DECODE_ERROR;
1401 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,
1402 SSL_R_BAD_SRP_S_LENGTH);
1403 goto f_err;
1404 }
1405 if (!(s->srp_ctx.s = BN_bin2bn(p, i, NULL))) {
1406 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,
1407 ERR_R_BN_LIB);
1408 goto err;
1409 }
1410 p += i;
1411
1412 n2s(p, i);
1413 param_len += i + 2;
1414 if (param_len > n) {
1415 al = SSL_AD_DECODE_ERROR;
1416 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,
1417 SSL_R_BAD_SRP_B_LENGTH);
1418 goto f_err;
1419 }
1420 if (!(s->srp_ctx.B = BN_bin2bn(p, i, NULL))) {
1421 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,
1422 ERR_R_BN_LIB);
1423 goto err;
1424 }
1425 p += i;
1426 n -= param_len;
1427
1428 /* We must check if there is a certificate */
1429 if (alg_a & SSL_aRSA)
1430 pkey = X509_get_pubkey(
1431 s->session->sess_cert->peer_pkeys[
1432 SSL_PKEY_RSA_ENC].x509);
1433 else if (alg_a & SSL_aDSS)
1434 pkey = X509_get_pubkey(
1435 s->session->sess_cert->peer_pkeys[
1436 SSL_PKEY_DSA_SIGN].x509);
1437 } else
1438#endif /* !OPENSSL_NO_SRP */
1439 if (alg_k & SSL_kRSA) { 1349 if (alg_k & SSL_kRSA) {
1440 if ((rsa = RSA_new()) == NULL) { 1350 if ((rsa = RSA_new()) == NULL) {
1441 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE, 1351 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,
@@ -2156,9 +2066,6 @@ ssl3_send_client_key_exchange(SSL *s)
2156 unsigned long alg_k; 2066 unsigned long alg_k;
2157 unsigned char *q; 2067 unsigned char *q;
2158 EVP_PKEY *pkey = NULL; 2068 EVP_PKEY *pkey = NULL;
2159#ifndef OPENSSL_NO_KRB5
2160 KSSL_ERR kssl_err;
2161#endif /* OPENSSL_NO_KRB5 */
2162#ifndef OPENSSL_NO_ECDH 2069#ifndef OPENSSL_NO_ECDH
2163 EC_KEY *clnt_ecdh = NULL; 2070 EC_KEY *clnt_ecdh = NULL;
2164 const EC_POINT *srvr_ecpoint = NULL; 2071 const EC_POINT *srvr_ecpoint = NULL;
@@ -2226,140 +2133,6 @@ ssl3_send_client_key_exchange(SSL *s)
2226 s, s->session->master_key, tmp_buf, sizeof tmp_buf); 2133 s, s->session->master_key, tmp_buf, sizeof tmp_buf);
2227 OPENSSL_cleanse(tmp_buf, sizeof tmp_buf); 2134 OPENSSL_cleanse(tmp_buf, sizeof tmp_buf);
2228 } 2135 }
2229#ifndef OPENSSL_NO_KRB5
2230 else if (alg_k & SSL_kKRB5) {
2231 krb5_error_code krb5rc;
2232 KSSL_CTX *kssl_ctx = s->kssl_ctx;
2233 /* krb5_data krb5_ap_req; */
2234 krb5_data *enc_ticket;
2235 krb5_data authenticator, *authp = NULL;
2236 EVP_CIPHER_CTX ciph_ctx;
2237 const EVP_CIPHER *enc = NULL;
2238 unsigned char iv[EVP_MAX_IV_LENGTH];
2239 unsigned char tmp_buf[SSL_MAX_MASTER_KEY_LENGTH];
2240 unsigned char epms[SSL_MAX_MASTER_KEY_LENGTH
2241 + EVP_MAX_IV_LENGTH];
2242 int padl, outl = sizeof(epms);
2243
2244 EVP_CIPHER_CTX_init(&ciph_ctx);
2245
2246#ifdef KSSL_DEBUG
2247 printf("ssl3_send_client_key_exchange(%lx & %lx)\n",
2248 alg_k, SSL_kKRB5);
2249#endif /* KSSL_DEBUG */
2250
2251 authp = NULL;
2252#ifdef KRB5SENDAUTH
2253 if (KRB5SENDAUTH)
2254 authp = &authenticator;
2255#endif /* KRB5SENDAUTH */
2256
2257 krb5rc = kssl_cget_tkt(kssl_ctx, &enc_ticket,
2258 authp, &kssl_err);
2259 enc = kssl_map_enc(kssl_ctx->enctype);
2260 if (enc == NULL)
2261 goto err;
2262#ifdef KSSL_DEBUG
2263 {
2264 printf("kssl_cget_tkt rtn %d\n", krb5rc);
2265 if (krb5rc && kssl_err.text)
2266 printf("kssl_cget_tkt kssl_err=%s\n",
2267 kssl_err.text);
2268 }
2269#endif /* KSSL_DEBUG */
2270
2271 if (krb5rc) {
2272 ssl3_send_alert(s, SSL3_AL_FATAL,
2273 SSL_AD_HANDSHAKE_FAILURE);
2274 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
2275 kssl_err.reason);
2276 goto err;
2277 }
2278
2279 /*
2280 * 20010406 VRS - Earlier versions used KRB5 AP_REQ
2281 * in place of RFC 2712 KerberosWrapper, as in:
2282 *
2283 * Send ticket (copy to *p, set n = length)
2284 * n = krb5_ap_req.length;
2285 * memcpy(p, krb5_ap_req.data, krb5_ap_req.length);
2286 * if (krb5_ap_req.data)
2287 * kssl_krb5_free_data_contents(NULL,&krb5_ap_req);
2288 *
2289 * Now using real RFC 2712 KerberosWrapper
2290 * (Thanks to Simon Wilkinson <sxw@sxw.org.uk>)
2291 * Note: 2712 "opaque" types are here replaced
2292 * with a 2-byte length followed by the value.
2293 * Example:
2294 * KerberosWrapper= xx xx asn1ticket 0 0 xx xx encpms
2295 * Where "xx xx" = length bytes. Shown here with
2296 * optional authenticator omitted.
2297 */
2298
2299 /* KerberosWrapper.Ticket */
2300 s2n(enc_ticket->length, p);
2301 memcpy(p, enc_ticket->data, enc_ticket->length);
2302 p += enc_ticket->length;
2303 n = enc_ticket->length + 2;
2304
2305 /* KerberosWrapper.Authenticator */
2306 if (authp && authp->length) {
2307 s2n(authp->length, p);
2308 memcpy(p, authp->data, authp->length);
2309 p += authp->length;
2310 n += authp->length + 2;
2311
2312 free(authp->data);
2313 authp->data = NULL;
2314 authp->length = 0;
2315 } else {
2316 s2n(0,p);/* null authenticator length */
2317 n += 2;
2318 }
2319
2320 tmp_buf[0] = s->client_version >> 8;
2321 tmp_buf[1] = s->client_version & 0xff;
2322 if (RAND_bytes(&(tmp_buf[2]), sizeof tmp_buf - 2) <= 0)
2323 goto err;
2324
2325 /*
2326 * 20010420 VRS. Tried it this way; failed.
2327 * EVP_EncryptInit_ex(&ciph_ctx,enc, NULL,NULL);
2328 * EVP_CIPHER_CTX_set_key_length(&ciph_ctx,
2329 * kssl_ctx->length);
2330 * EVP_EncryptInit_ex(&ciph_ctx,NULL, key,iv);
2331 */
2332
2333 memset(iv, 0, sizeof iv);
2334 /* per RFC 1510 */
2335 EVP_EncryptInit_ex(&ciph_ctx, enc, NULL,
2336 kssl_ctx->key, iv);
2337 EVP_EncryptUpdate(&ciph_ctx, epms, &outl, tmp_buf,
2338 sizeof tmp_buf);
2339 EVP_EncryptFinal_ex(&ciph_ctx, &(epms[outl]), &padl);
2340 outl += padl;
2341 if (outl > (int)sizeof epms) {
2342 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
2343 ERR_R_INTERNAL_ERROR);
2344 goto err;
2345 }
2346 EVP_CIPHER_CTX_cleanup(&ciph_ctx);
2347
2348 /* KerberosWrapper.EncryptedPreMasterSecret */
2349 s2n(outl, p);
2350 memcpy(p, epms, outl);
2351 p += outl;
2352 n += outl + 2;
2353
2354 s->session->master_key_length =
2355 s->method->ssl3_enc->generate_master_secret(s,
2356 s->session->master_key,
2357 tmp_buf, sizeof tmp_buf);
2358
2359 OPENSSL_cleanse(tmp_buf, sizeof tmp_buf);
2360 OPENSSL_cleanse(epms, outl);
2361 }
2362#endif
2363#ifndef OPENSSL_NO_DH 2136#ifndef OPENSSL_NO_DH
2364 else if (alg_k & (SSL_kEDH|SSL_kDHr|SSL_kDHd)) { 2137 else if (alg_k & (SSL_kEDH|SSL_kDHr|SSL_kDHd)) {
2365 DH *dh_srvr, *dh_clnt; 2138 DH *dh_srvr, *dh_clnt;
@@ -2716,37 +2489,6 @@ ssl3_send_client_key_exchange(SSL *s)
2716 EVP_PKEY_free(pub_key); 2489 EVP_PKEY_free(pub_key);
2717 2490
2718 } 2491 }
2719#ifndef OPENSSL_NO_SRP
2720 else if (alg_k & SSL_kSRP) {
2721 if (s->srp_ctx.A != NULL) {
2722 /* send off the data */
2723 n = BN_num_bytes(s->srp_ctx.A);
2724 s2n(n, p);
2725 BN_bn2bin(s->srp_ctx.A, p);
2726 n += 2;
2727 } else {
2728 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
2729 ERR_R_INTERNAL_ERROR);
2730 goto err;
2731 }
2732 if (s->session->srp_username != NULL)
2733 free(s->session->srp_username);
2734 s->session->srp_username = BUF_strdup(s->srp_ctx.login);
2735 if (s->session->srp_username == NULL) {
2736 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
2737 ERR_R_MALLOC_FAILURE);
2738 goto err;
2739 }
2740
2741 if ((s->session->master_key_length =
2742 SRP_generate_client_master_secret(s,
2743 s->session->master_key)) < 0) {
2744 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
2745 ERR_R_INTERNAL_ERROR);
2746 goto err;
2747 }
2748 }
2749#endif
2750#ifndef OPENSSL_NO_PSK 2492#ifndef OPENSSL_NO_PSK
2751 else if (alg_k & SSL_kPSK) { 2493 else if (alg_k & SSL_kPSK) {
2752 char identity[PSK_MAX_IDENTITY_LEN]; 2494 char identity[PSK_MAX_IDENTITY_LEN];
diff --git a/src/lib/libssl/src/ssl/s3_lib.c b/src/lib/libssl/src/ssl/s3_lib.c
index 12ce8a1605..c68748809c 100644
--- a/src/lib/libssl/src/ssl/s3_lib.c
+++ b/src/lib/libssl/src/ssl/s3_lib.c
@@ -605,232 +605,6 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[] = {
605 168, 605 168,
606 168, 606 168,
607 }, 607 },
608#ifndef OPENSSL_NO_KRB5
609/* The Kerberos ciphers*/
610/* Cipher 1E */
611 {
612 1,
613 SSL3_TXT_KRB5_DES_64_CBC_SHA,
614 SSL3_CK_KRB5_DES_64_CBC_SHA,
615 SSL_kKRB5,
616 SSL_aKRB5,
617 SSL_DES,
618 SSL_SHA1,
619 SSL_SSLV3,
620 SSL_NOT_EXP|SSL_LOW,
621 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
622 56,
623 56,
624 },
625
626/* Cipher 1F */
627 {
628 1,
629 SSL3_TXT_KRB5_DES_192_CBC3_SHA,
630 SSL3_CK_KRB5_DES_192_CBC3_SHA,
631 SSL_kKRB5,
632 SSL_aKRB5,
633 SSL_3DES,
634 SSL_SHA1,
635 SSL_SSLV3,
636 SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
637 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
638 168,
639 168,
640 },
641
642/* Cipher 20 */
643 {
644 1,
645 SSL3_TXT_KRB5_RC4_128_SHA,
646 SSL3_CK_KRB5_RC4_128_SHA,
647 SSL_kKRB5,
648 SSL_aKRB5,
649 SSL_RC4,
650 SSL_SHA1,
651 SSL_SSLV3,
652 SSL_NOT_EXP|SSL_MEDIUM,
653 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
654 128,
655 128,
656 },
657
658/* Cipher 21 */
659 {
660 1,
661 SSL3_TXT_KRB5_IDEA_128_CBC_SHA,
662 SSL3_CK_KRB5_IDEA_128_CBC_SHA,
663 SSL_kKRB5,
664 SSL_aKRB5,
665 SSL_IDEA,
666 SSL_SHA1,
667 SSL_SSLV3,
668 SSL_NOT_EXP|SSL_MEDIUM,
669 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
670 128,
671 128,
672 },
673
674/* Cipher 22 */
675 {
676 1,
677 SSL3_TXT_KRB5_DES_64_CBC_MD5,
678 SSL3_CK_KRB5_DES_64_CBC_MD5,
679 SSL_kKRB5,
680 SSL_aKRB5,
681 SSL_DES,
682 SSL_MD5,
683 SSL_SSLV3,
684 SSL_NOT_EXP|SSL_LOW,
685 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
686 56,
687 56,
688 },
689
690/* Cipher 23 */
691 {
692 1,
693 SSL3_TXT_KRB5_DES_192_CBC3_MD5,
694 SSL3_CK_KRB5_DES_192_CBC3_MD5,
695 SSL_kKRB5,
696 SSL_aKRB5,
697 SSL_3DES,
698 SSL_MD5,
699 SSL_SSLV3,
700 SSL_NOT_EXP|SSL_HIGH,
701 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
702 168,
703 168,
704 },
705
706/* Cipher 24 */
707 {
708 1,
709 SSL3_TXT_KRB5_RC4_128_MD5,
710 SSL3_CK_KRB5_RC4_128_MD5,
711 SSL_kKRB5,
712 SSL_aKRB5,
713 SSL_RC4,
714 SSL_MD5,
715 SSL_SSLV3,
716 SSL_NOT_EXP|SSL_MEDIUM,
717 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
718 128,
719 128,
720 },
721
722/* Cipher 25 */
723 {
724 1,
725 SSL3_TXT_KRB5_IDEA_128_CBC_MD5,
726 SSL3_CK_KRB5_IDEA_128_CBC_MD5,
727 SSL_kKRB5,
728 SSL_aKRB5,
729 SSL_IDEA,
730 SSL_MD5,
731 SSL_SSLV3,
732 SSL_NOT_EXP|SSL_MEDIUM,
733 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
734 128,
735 128,
736 },
737
738/* Cipher 26 */
739 {
740 1,
741 SSL3_TXT_KRB5_DES_40_CBC_SHA,
742 SSL3_CK_KRB5_DES_40_CBC_SHA,
743 SSL_kKRB5,
744 SSL_aKRB5,
745 SSL_DES,
746 SSL_SHA1,
747 SSL_SSLV3,
748 SSL_EXPORT|SSL_EXP40,
749 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
750 40,
751 56,
752 },
753
754/* Cipher 27 */
755 {
756 1,
757 SSL3_TXT_KRB5_RC2_40_CBC_SHA,
758 SSL3_CK_KRB5_RC2_40_CBC_SHA,
759 SSL_kKRB5,
760 SSL_aKRB5,
761 SSL_RC2,
762 SSL_SHA1,
763 SSL_SSLV3,
764 SSL_EXPORT|SSL_EXP40,
765 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
766 40,
767 128,
768 },
769
770/* Cipher 28 */
771 {
772 1,
773 SSL3_TXT_KRB5_RC4_40_SHA,
774 SSL3_CK_KRB5_RC4_40_SHA,
775 SSL_kKRB5,
776 SSL_aKRB5,
777 SSL_RC4,
778 SSL_SHA1,
779 SSL_SSLV3,
780 SSL_EXPORT|SSL_EXP40,
781 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
782 40,
783 128,
784 },
785
786/* Cipher 29 */
787 {
788 1,
789 SSL3_TXT_KRB5_DES_40_CBC_MD5,
790 SSL3_CK_KRB5_DES_40_CBC_MD5,
791 SSL_kKRB5,
792 SSL_aKRB5,
793 SSL_DES,
794 SSL_MD5,
795 SSL_SSLV3,
796 SSL_EXPORT|SSL_EXP40,
797 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
798 40,
799 56,
800 },
801
802/* Cipher 2A */
803 {
804 1,
805 SSL3_TXT_KRB5_RC2_40_CBC_MD5,
806 SSL3_CK_KRB5_RC2_40_CBC_MD5,
807 SSL_kKRB5,
808 SSL_aKRB5,
809 SSL_RC2,
810 SSL_MD5,
811 SSL_SSLV3,
812 SSL_EXPORT|SSL_EXP40,
813 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
814 40,
815 128,
816 },
817
818/* Cipher 2B */
819 {
820 1,
821 SSL3_TXT_KRB5_RC4_40_MD5,
822 SSL3_CK_KRB5_RC4_40_MD5,
823 SSL_kKRB5,
824 SSL_aKRB5,
825 SSL_RC4,
826 SSL_MD5,
827 SSL_SSLV3,
828 SSL_EXPORT|SSL_EXP40,
829 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
830 40,
831 128,
832 },
833#endif /* OPENSSL_NO_KRB5 */
834 608
835/* New AES ciphersuites */ 609/* New AES ciphersuites */
836/* Cipher 2F */ 610/* Cipher 2F */
@@ -2250,151 +2024,6 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[] = {
2250 }, 2024 },
2251#endif /* OPENSSL_NO_ECDH */ 2025#endif /* OPENSSL_NO_ECDH */
2252 2026
2253#ifndef OPENSSL_NO_SRP
2254 /* Cipher C01A */
2255 {
2256 1,
2257 TLS1_TXT_SRP_SHA_WITH_3DES_EDE_CBC_SHA,
2258 TLS1_CK_SRP_SHA_WITH_3DES_EDE_CBC_SHA,
2259 SSL_kSRP,
2260 SSL_aNULL,
2261 SSL_3DES,
2262 SSL_SHA1,
2263 SSL_TLSV1,
2264 SSL_NOT_EXP|SSL_HIGH,
2265 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
2266 168,
2267 168,
2268 },
2269
2270 /* Cipher C01B */
2271 {
2272 1,
2273 TLS1_TXT_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA,
2274 TLS1_CK_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA,
2275 SSL_kSRP,
2276 SSL_aRSA,
2277 SSL_3DES,
2278 SSL_SHA1,
2279 SSL_TLSV1,
2280 SSL_NOT_EXP|SSL_HIGH,
2281 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
2282 168,
2283 168,
2284 },
2285
2286 /* Cipher C01C */
2287 {
2288 1,
2289 TLS1_TXT_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA,
2290 TLS1_CK_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA,
2291 SSL_kSRP,
2292 SSL_aDSS,
2293 SSL_3DES,
2294 SSL_SHA1,
2295 SSL_TLSV1,
2296 SSL_NOT_EXP|SSL_HIGH,
2297 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
2298 168,
2299 168,
2300 },
2301
2302 /* Cipher C01D */
2303 {
2304 1,
2305 TLS1_TXT_SRP_SHA_WITH_AES_128_CBC_SHA,
2306 TLS1_CK_SRP_SHA_WITH_AES_128_CBC_SHA,
2307 SSL_kSRP,
2308 SSL_aNULL,
2309 SSL_AES128,
2310 SSL_SHA1,
2311 SSL_TLSV1,
2312 SSL_NOT_EXP|SSL_HIGH,
2313 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
2314 128,
2315 128,
2316 },
2317
2318 /* Cipher C01E */
2319 {
2320 1,
2321 TLS1_TXT_SRP_SHA_RSA_WITH_AES_128_CBC_SHA,
2322 TLS1_CK_SRP_SHA_RSA_WITH_AES_128_CBC_SHA,
2323 SSL_kSRP,
2324 SSL_aRSA,
2325 SSL_AES128,
2326 SSL_SHA1,
2327 SSL_TLSV1,
2328 SSL_NOT_EXP|SSL_HIGH,
2329 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
2330 128,
2331 128,
2332 },
2333
2334 /* Cipher C01F */
2335 {
2336 1,
2337 TLS1_TXT_SRP_SHA_DSS_WITH_AES_128_CBC_SHA,
2338 TLS1_CK_SRP_SHA_DSS_WITH_AES_128_CBC_SHA,
2339 SSL_kSRP,
2340 SSL_aDSS,
2341 SSL_AES128,
2342 SSL_SHA1,
2343 SSL_TLSV1,
2344 SSL_NOT_EXP|SSL_HIGH,
2345 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
2346 128,
2347 128,
2348 },
2349
2350 /* Cipher C020 */
2351 {
2352 1,
2353 TLS1_TXT_SRP_SHA_WITH_AES_256_CBC_SHA,
2354 TLS1_CK_SRP_SHA_WITH_AES_256_CBC_SHA,
2355 SSL_kSRP,
2356 SSL_aNULL,
2357 SSL_AES256,
2358 SSL_SHA1,
2359 SSL_TLSV1,
2360 SSL_NOT_EXP|SSL_HIGH,
2361 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
2362 256,
2363 256,
2364 },
2365
2366 /* Cipher C021 */
2367 {
2368 1,
2369 TLS1_TXT_SRP_SHA_RSA_WITH_AES_256_CBC_SHA,
2370 TLS1_CK_SRP_SHA_RSA_WITH_AES_256_CBC_SHA,
2371 SSL_kSRP,
2372 SSL_aRSA,
2373 SSL_AES256,
2374 SSL_SHA1,
2375 SSL_TLSV1,
2376 SSL_NOT_EXP|SSL_HIGH,
2377 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
2378 256,
2379 256,
2380 },
2381
2382 /* Cipher C022 */
2383 {
2384 1,
2385 TLS1_TXT_SRP_SHA_DSS_WITH_AES_256_CBC_SHA,
2386 TLS1_CK_SRP_SHA_DSS_WITH_AES_256_CBC_SHA,
2387 SSL_kSRP,
2388 SSL_aDSS,
2389 SSL_AES256,
2390 SSL_SHA1,
2391 SSL_TLSV1,
2392 SSL_NOT_EXP|SSL_HIGH,
2393 SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
2394 256,
2395 256,
2396 },
2397#endif /* OPENSSL_NO_SRP */
2398#ifndef OPENSSL_NO_ECDH 2027#ifndef OPENSSL_NO_ECDH
2399 2028
2400 /* HMAC based TLS v1.2 ciphersuites from RFC5289 */ 2029 /* HMAC based TLS v1.2 ciphersuites from RFC5289 */
@@ -2787,9 +2416,6 @@ ssl3_new(SSL *s)
2787 2416
2788 s->s3 = s3; 2417 s->s3 = s3;
2789 2418
2790#ifndef OPENSSL_NO_SRP
2791 SSL_SRP_CTX_init(s);
2792#endif
2793 s->method->ssl_clear(s); 2419 s->method->ssl_clear(s);
2794 return (1); 2420 return (1);
2795err: 2421err:
@@ -2832,9 +2458,6 @@ ssl3_free(SSL *s)
2832 } 2458 }
2833 if (s->s3->handshake_dgst) 2459 if (s->s3->handshake_dgst)
2834 ssl3_free_digest_list(s); 2460 ssl3_free_digest_list(s);
2835#ifndef OPENSSL_NO_SRP
2836 SSL_SRP_CTX_free(s);
2837#endif
2838 OPENSSL_cleanse(s->s3, sizeof *s->s3); 2461 OPENSSL_cleanse(s->s3, sizeof *s->s3);
2839 free(s->s3); 2462 free(s->s3);
2840 s->s3 = NULL; 2463 s->s3 = NULL;
@@ -2919,13 +2542,6 @@ ssl3_clear(SSL *s)
2919#endif 2542#endif
2920} 2543}
2921 2544
2922#ifndef OPENSSL_NO_SRP
2923static char *
2924srp_password_from_info_cb(SSL *s, void *arg)
2925{
2926 return BUF_strdup(s->srp_ctx.info);
2927}
2928#endif
2929 2545
2930long 2546long
2931ssl3_ctrl(SSL *s, int cmd, long larg, void *parg) 2547ssl3_ctrl(SSL *s, int cmd, long larg, void *parg)
@@ -3380,40 +2996,6 @@ ssl3_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg)
3380 return 1; 2996 return 1;
3381 break; 2997 break;
3382 2998
3383#ifndef OPENSSL_NO_SRP
3384 case SSL_CTRL_SET_TLS_EXT_SRP_USERNAME:
3385 ctx->srp_ctx.srp_Mask|=SSL_kSRP;
3386 if (ctx->srp_ctx.login != NULL)
3387 free(ctx->srp_ctx.login);
3388 ctx->srp_ctx.login = NULL;
3389 if (parg == NULL)
3390 break;
3391 if (strlen((const char *)parg) > 255 ||
3392 strlen((const char *)parg) < 1) {
3393 SSLerr(SSL_F_SSL3_CTX_CTRL,
3394 SSL_R_INVALID_SRP_USERNAME);
3395 return 0;
3396 }
3397 if ((ctx->srp_ctx.login = BUF_strdup((char *)parg)) == NULL) {
3398 SSLerr(SSL_F_SSL3_CTX_CTRL,
3399 ERR_R_INTERNAL_ERROR);
3400 return 0;
3401 }
3402 break;
3403 case SSL_CTRL_SET_TLS_EXT_SRP_PASSWORD:
3404 ctx->srp_ctx.SRP_give_srp_client_pwd_callback =
3405 srp_password_from_info_cb;
3406 ctx->srp_ctx.info = parg;
3407 break;
3408 case SSL_CTRL_SET_SRP_ARG:
3409 ctx->srp_ctx.srp_Mask|=SSL_kSRP;
3410 ctx->srp_ctx.SRP_cb_arg = parg;
3411 break;
3412
3413 case SSL_CTRL_SET_TLS_EXT_SRP_STRENGTH:
3414 ctx->srp_ctx.strength = larg;
3415 break;
3416#endif
3417#endif /* !OPENSSL_NO_TLSEXT */ 2999#endif /* !OPENSSL_NO_TLSEXT */
3418 3000
3419 /* A Thawte special :-) */ 3001 /* A Thawte special :-) */
@@ -3491,23 +3073,6 @@ ssl3_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)(void))
3491 unsigned char *, EVP_CIPHER_CTX *, HMAC_CTX *, int))fp; 3073 unsigned char *, EVP_CIPHER_CTX *, HMAC_CTX *, int))fp;
3492 break; 3074 break;
3493 3075
3494#ifndef OPENSSL_NO_SRP
3495 case SSL_CTRL_SET_SRP_VERIFY_PARAM_CB:
3496 ctx->srp_ctx.srp_Mask|=SSL_kSRP;
3497 ctx->srp_ctx.SRP_verify_param_callback =
3498 (int (*)(SSL *, void *))fp;
3499 break;
3500 case SSL_CTRL_SET_TLS_EXT_SRP_USERNAME_CB:
3501 ctx->srp_ctx.srp_Mask|=SSL_kSRP;
3502 ctx->srp_ctx.TLS_ext_srp_username_callback =
3503 (int (*)(SSL *, int *, void *))fp;
3504 break;
3505 case SSL_CTRL_SET_SRP_GIVE_CLIENT_PWD_CB:
3506 ctx->srp_ctx.srp_Mask|=SSL_kSRP;
3507 ctx->srp_ctx.SRP_give_srp_client_pwd_callback =
3508 (char *(*)(SSL *, void *))fp;
3509 break;
3510#endif
3511#endif 3076#endif
3512 default: 3077 default:
3513 return (0); 3078 return (0);
@@ -3616,10 +3181,6 @@ SSL_CIPHER *ssl3_choose_cipher(SSL *s, STACK_OF(SSL_CIPHER) *clnt,
3616 mask_a = cert->mask_a; 3181 mask_a = cert->mask_a;
3617 emask_k = cert->export_mask_k; 3182 emask_k = cert->export_mask_k;
3618 emask_a = cert->export_mask_a; 3183 emask_a = cert->export_mask_a;
3619#ifndef OPENSSL_NO_SRP
3620 mask_k = cert->mask_k | s->srp_ctx.srp_Mask;
3621 emask_k = cert->export_mask_k | s->srp_ctx.srp_Mask;
3622#endif
3623 3184
3624#ifdef KSSL_DEBUG 3185#ifdef KSSL_DEBUG
3625/* printf("ssl3_choose_cipher %d alg= %lx\n", i,c->algorithms);*/ 3186/* printf("ssl3_choose_cipher %d alg= %lx\n", i,c->algorithms);*/
@@ -3628,12 +3189,6 @@ SSL_CIPHER *ssl3_choose_cipher(SSL *s, STACK_OF(SSL_CIPHER) *clnt,
3628 alg_k = c->algorithm_mkey; 3189 alg_k = c->algorithm_mkey;
3629 alg_a = c->algorithm_auth; 3190 alg_a = c->algorithm_auth;
3630 3191
3631#ifndef OPENSSL_NO_KRB5
3632 if (alg_k & SSL_kKRB5) {
3633 if (!kssl_keytab_is_available(s->kssl_ctx) )
3634 continue;
3635 }
3636#endif /* OPENSSL_NO_KRB5 */
3637#ifndef OPENSSL_NO_PSK 3192#ifndef OPENSSL_NO_PSK
3638 /* with PSK there must be server callback set */ 3193 /* with PSK there must be server callback set */
3639 if ((alg_k & SSL_kPSK) && s->psk_server_callback == NULL) 3194 if ((alg_k & SSL_kPSK) && s->psk_server_callback == NULL)
diff --git a/src/lib/libssl/src/ssl/s3_srvr.c b/src/lib/libssl/src/ssl/s3_srvr.c
index 6d8ccd66b7..081aebf1f5 100644
--- a/src/lib/libssl/src/ssl/s3_srvr.c
+++ b/src/lib/libssl/src/ssl/s3_srvr.c
@@ -164,9 +164,6 @@
164#include <openssl/dh.h> 164#include <openssl/dh.h>
165#endif 165#endif
166#include <openssl/bn.h> 166#include <openssl/bn.h>
167#ifndef OPENSSL_NO_KRB5
168#include <openssl/krb5_asn.h>
169#endif
170#include <openssl/md5.h> 167#include <openssl/md5.h>
171 168
172static const SSL_METHOD *ssl3_get_server_method(int ver); 169static const SSL_METHOD *ssl3_get_server_method(int ver);
@@ -179,30 +176,6 @@ ssl3_get_server_method(int ver)
179 return (NULL); 176 return (NULL);
180} 177}
181 178
182#ifndef OPENSSL_NO_SRP
183static int
184ssl_check_srp_ext_ClientHello(SSL *s, int *al)
185{
186 int ret = SSL_ERROR_NONE;
187
188 *al = SSL_AD_UNRECOGNIZED_NAME;
189
190 if ((s->s3->tmp.new_cipher->algorithm_mkey & SSL_kSRP) &&
191 (s->srp_ctx.TLS_ext_srp_username_callback != NULL)) {
192 if (s->srp_ctx.login == NULL) {
193 /*
194 * RFC 5054 says SHOULD reject,
195 * we do so if There is no srp login name
196 */
197 ret = SSL3_AL_FATAL;
198 *al = SSL_AD_UNKNOWN_PSK_IDENTITY;
199 } else {
200 ret = SSL_srp_server_param_with_username(s, al);
201 }
202 }
203 return (ret);
204}
205#endif
206 179
207IMPLEMENT_ssl3_meth_func(SSLv3_server_method, 180IMPLEMENT_ssl3_meth_func(SSLv3_server_method,
208 ssl3_accept, ssl_undefined_function, ssl3_get_server_method) 181 ssl3_accept, ssl_undefined_function, ssl3_get_server_method)
@@ -342,39 +315,6 @@ ssl3_accept(SSL *s)
342 if (ret <= 0) 315 if (ret <= 0)
343 goto end; 316 goto end;
344 } 317 }
345#ifndef OPENSSL_NO_SRP
346 {
347 int al;
348 if ((ret =
349 ssl_check_srp_ext_ClientHello(s, &al))
350 < 0) {
351 /*
352 * Callback indicates further work to
353 * be done.
354 */
355 s->rwstate = SSL_X509_LOOKUP;
356 goto end;
357 }
358 if (ret != SSL_ERROR_NONE) {
359 ssl3_send_alert(s, SSL3_AL_FATAL, al);
360
361 /*
362 * This is not really an error but the
363 * only means for a client to detect
364 * whether srp is supported.
365 */
366 if (al != TLS1_AD_UNKNOWN_PSK_IDENTITY)
367 SSLerr(SSL_F_SSL3_ACCEPT,
368 SSL_R_CLIENTHELLO_TLSEXT);
369
370 ret = SSL_TLSEXT_ERR_ALERT_FATAL;
371
372 ret = -1;
373 goto end;
374
375 }
376 }
377#endif
378 318
379 s->renegotiate = 2; 319 s->renegotiate = 2;
380 s->state = SSL3_ST_SW_SRVR_HELLO_A; 320 s->state = SSL3_ST_SW_SRVR_HELLO_A;
@@ -441,9 +381,6 @@ ssl3_accept(SSL *s)
441 * send_server_key_exchange. 381 * send_server_key_exchange.
442 */ 382 */
443 if ((s->options & SSL_OP_EPHEMERAL_RSA) 383 if ((s->options & SSL_OP_EPHEMERAL_RSA)
444#ifndef OPENSSL_NO_KRB5
445 && !(alg_k & SSL_kKRB5)
446#endif /* OPENSSL_NO_KRB5 */
447 ) 384 )
448 /* 385 /*
449 * option SSL_OP_EPHEMERAL_RSA sends temporary 386 * option SSL_OP_EPHEMERAL_RSA sends temporary
@@ -473,10 +410,6 @@ ssl3_accept(SSL *s)
473#ifndef OPENSSL_NO_PSK 410#ifndef OPENSSL_NO_PSK
474 || ((alg_k & SSL_kPSK) && s->ctx->psk_identity_hint) 411 || ((alg_k & SSL_kPSK) && s->ctx->psk_identity_hint)
475#endif 412#endif
476#ifndef OPENSSL_NO_SRP
477 /* SRP: send ServerKeyExchange */
478 || (alg_k & SSL_kSRP)
479#endif
480 || (alg_k & (SSL_kDHr|SSL_kDHd|SSL_kEDH)) 413 || (alg_k & (SSL_kDHr|SSL_kDHd|SSL_kEDH))
481 || (alg_k & SSL_kEECDH) 414 || (alg_k & SSL_kEECDH)
482 || ((alg_k & SSL_kRSA) 415 || ((alg_k & SSL_kRSA)
@@ -1796,20 +1729,6 @@ ssl3_send_server_key_exchange(SSL *s)
1796 n += 2 + pskhintlen; 1729 n += 2 + pskhintlen;
1797 } else 1730 } else
1798#endif /* !OPENSSL_NO_PSK */ 1731#endif /* !OPENSSL_NO_PSK */
1799#ifndef OPENSSL_NO_SRP
1800 if (type & SSL_kSRP) {
1801 if ((s->srp_ctx.N == NULL) || (s->srp_ctx.g == NULL) ||
1802 (s->srp_ctx.s == NULL) || (s->srp_ctx.B == NULL)) {
1803 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,
1804 SSL_R_MISSING_SRP_PARAM);
1805 goto err;
1806 }
1807 r[0] = s->srp_ctx.N;
1808 r[1] = s->srp_ctx.g;
1809 r[2] = s->srp_ctx.s;
1810 r[3] = s->srp_ctx.B;
1811 } else
1812#endif
1813 { 1732 {
1814 al = SSL_AD_HANDSHAKE_FAILURE; 1733 al = SSL_AD_HANDSHAKE_FAILURE;
1815 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, 1734 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,
@@ -1818,11 +1737,6 @@ ssl3_send_server_key_exchange(SSL *s)
1818 } 1737 }
1819 for (i = 0; i < 4 && r[i] != NULL; i++) { 1738 for (i = 0; i < 4 && r[i] != NULL; i++) {
1820 nr[i] = BN_num_bytes(r[i]); 1739 nr[i] = BN_num_bytes(r[i]);
1821#ifndef OPENSSL_NO_SRP
1822 if ((i == 2) && (type & SSL_kSRP))
1823 n += 1 + nr[i];
1824 else
1825#endif
1826 n += 2 + nr[i]; 1740 n += 2 + nr[i];
1827 } 1741 }
1828 1742
@@ -1848,12 +1762,6 @@ ssl3_send_server_key_exchange(SSL *s)
1848 p = &(d[4]); 1762 p = &(d[4]);
1849 1763
1850 for (i = 0; i < 4 && r[i] != NULL; i++) { 1764 for (i = 0; i < 4 && r[i] != NULL; i++) {
1851#ifndef OPENSSL_NO_SRP
1852 if ((i == 2) && (type & SSL_kSRP)) {
1853 *p = nr[i];
1854 p++;
1855 } else
1856#endif
1857 s2n(nr[i], p); 1765 s2n(nr[i], p);
1858 BN_bn2bin(r[i], p); 1766 BN_bn2bin(r[i], p);
1859 p += nr[i]; 1767 p += nr[i];
@@ -2112,9 +2020,6 @@ ssl3_get_client_key_exchange(SSL *s)
2112 BIGNUM *pub = NULL; 2020 BIGNUM *pub = NULL;
2113 DH *dh_srvr; 2021 DH *dh_srvr;
2114#endif 2022#endif
2115#ifndef OPENSSL_NO_KRB5
2116 KSSL_ERR kssl_err;
2117#endif /* OPENSSL_NO_KRB5 */
2118 2023
2119#ifndef OPENSSL_NO_ECDH 2024#ifndef OPENSSL_NO_ECDH
2120 EC_KEY *srvr_ecdh = NULL; 2025 EC_KEY *srvr_ecdh = NULL;
@@ -2299,191 +2204,6 @@ ssl3_get_client_key_exchange(SSL *s)
2299 OPENSSL_cleanse(p, i); 2204 OPENSSL_cleanse(p, i);
2300 } else 2205 } else
2301#endif 2206#endif
2302#ifndef OPENSSL_NO_KRB5
2303 if (alg_k & SSL_kKRB5) {
2304 krb5_error_code krb5rc;
2305 krb5_data enc_ticket;
2306 krb5_data authenticator;
2307 krb5_data enc_pms;
2308 KSSL_CTX *kssl_ctx = s->kssl_ctx;
2309 EVP_CIPHER_CTX ciph_ctx;
2310 const EVP_CIPHER *enc = NULL;
2311 unsigned char iv[EVP_MAX_IV_LENGTH];
2312 unsigned char pms[SSL_MAX_MASTER_KEY_LENGTH
2313 + EVP_MAX_BLOCK_LENGTH];
2314 int padl, outl;
2315 krb5_timestamp authtime = 0;
2316 krb5_ticket_times ttimes;
2317
2318 EVP_CIPHER_CTX_init(&ciph_ctx);
2319
2320 if (!kssl_ctx)
2321 kssl_ctx = kssl_ctx_new();
2322
2323 n2s(p, i);
2324 enc_ticket.length = i;
2325
2326 if (n < (long)(enc_ticket.length + 6)) {
2327 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2328 SSL_R_DATA_LENGTH_TOO_LONG);
2329 goto err;
2330 }
2331
2332 enc_ticket.data = (char *)p;
2333 p += enc_ticket.length;
2334
2335 n2s(p, i);
2336 authenticator.length = i;
2337
2338 if (n < (long)(enc_ticket.length + authenticator.length + 6)) {
2339 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2340 SSL_R_DATA_LENGTH_TOO_LONG);
2341 goto err;
2342 }
2343
2344 authenticator.data = (char *)p;
2345 p += authenticator.length;
2346
2347 n2s(p, i);
2348 enc_pms.length = i;
2349 enc_pms.data = (char *)p;
2350 p += enc_pms.length;
2351
2352 /*
2353 * Note that the length is checked again below,
2354 * after decryption
2355 */
2356 if (enc_pms.length > sizeof pms) {
2357 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2358 SSL_R_DATA_LENGTH_TOO_LONG);
2359 goto err;
2360 }
2361
2362 if (n != (long)(enc_ticket.length + authenticator.length +
2363 enc_pms.length + 6)) {
2364 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2365 SSL_R_DATA_LENGTH_TOO_LONG);
2366 goto err;
2367 }
2368
2369 if ((krb5rc = kssl_sget_tkt(kssl_ctx, &enc_ticket, &ttimes,
2370 &kssl_err)) != 0) {
2371#ifdef KSSL_DEBUG
2372 printf("kssl_sget_tkt rtn %d [%d]\n",
2373 krb5rc, kssl_err.reason);
2374 if (kssl_err.text)
2375 printf("kssl_err text= %s\n", kssl_err.text);
2376#endif /* KSSL_DEBUG */
2377 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2378 kssl_err.reason);
2379 goto err;
2380 }
2381
2382 /* Note: no authenticator is not considered an error,
2383 ** but will return authtime == 0.
2384 */
2385 if ((krb5rc = kssl_check_authent(kssl_ctx, &authenticator,
2386 &authtime, &kssl_err)) != 0) {
2387#ifdef KSSL_DEBUG
2388 printf("kssl_check_authent rtn %d [%d]\n",
2389 krb5rc, kssl_err.reason);
2390 if (kssl_err.text)
2391 printf("kssl_err text= %s\n", kssl_err.text);
2392#endif /* KSSL_DEBUG */
2393 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2394 kssl_err.reason);
2395 goto err;
2396 }
2397
2398 if ((krb5rc = kssl_validate_times(authtime, &ttimes)) != 0) {
2399 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2400 krb5rc);
2401 goto err;
2402 }
2403
2404#ifdef KSSL_DEBUG
2405 kssl_ctx_show(kssl_ctx);
2406#endif /* KSSL_DEBUG */
2407
2408 enc = kssl_map_enc(kssl_ctx->enctype);
2409 if (enc == NULL)
2410 goto err;
2411
2412 memset(iv, 0, sizeof iv); /* per RFC 1510 */
2413
2414 if (!EVP_DecryptInit_ex(&ciph_ctx, enc, NULL,
2415 kssl_ctx->key, iv)) {
2416 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2417 SSL_R_DECRYPTION_FAILED);
2418 goto err;
2419 }
2420 if (!EVP_DecryptUpdate(&ciph_ctx, pms, &outl,
2421 (unsigned char *)enc_pms.data, enc_pms.length)) {
2422 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2423 SSL_R_DECRYPTION_FAILED);
2424 goto err;
2425 }
2426 if (outl > SSL_MAX_MASTER_KEY_LENGTH) {
2427 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2428 SSL_R_DATA_LENGTH_TOO_LONG);
2429 goto err;
2430 }
2431 if (!EVP_DecryptFinal_ex(&ciph_ctx, &(pms[outl]), &padl)) {
2432 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2433 SSL_R_DECRYPTION_FAILED);
2434 goto err;
2435 }
2436 outl += padl;
2437 if (outl > SSL_MAX_MASTER_KEY_LENGTH) {
2438 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2439 SSL_R_DATA_LENGTH_TOO_LONG);
2440 goto err;
2441 }
2442 if (!((pms[0] == (s->client_version >> 8)) && (pms[1] == (s->client_version & 0xff)))) {
2443 /*
2444 * The premaster secret must contain the same version
2445 * number as the ClientHello to detect version rollback
2446 * attacks (strangely, the protocol does not offer such
2447 * protection for DH ciphersuites).
2448 * However, buggy clients exist that send random bytes
2449 * instead of the protocol version.
2450 *
2451 * If SSL_OP_TLS_ROLLBACK_BUG is set, tolerate such
2452 * clients.
2453 * (Perhaps we should have a separate BUG value for
2454 * the Kerberos cipher)
2455 */
2456 if (!(s->options & SSL_OP_TLS_ROLLBACK_BUG)) {
2457 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2458 SSL_AD_DECODE_ERROR);
2459 goto err;
2460 }
2461 }
2462
2463 EVP_CIPHER_CTX_cleanup(&ciph_ctx);
2464
2465 s->session->master_key_length =
2466 s->method->ssl3_enc->generate_master_secret(s,
2467 s->session->master_key, pms, outl);
2468
2469 if (kssl_ctx->client_princ) {
2470 size_t len = strlen(kssl_ctx->client_princ);
2471 if (len < SSL_MAX_KRB5_PRINCIPAL_LENGTH ) {
2472 s->session->krb5_client_princ_len = len;
2473 memcpy(s->session->krb5_client_princ,
2474 kssl_ctx->client_princ, len);
2475 }
2476 }
2477
2478
2479 /*
2480 * Was doing kssl_ctx_free() here, but it caused problems for
2481 * apache.
2482 * kssl_ctx = kssl_ctx_free(kssl_ctx);
2483 * if (s->kssl_ctx) s->kssl_ctx = NULL;
2484 */
2485 } else
2486#endif /* OPENSSL_NO_KRB5 */
2487 2207
2488#ifndef OPENSSL_NO_ECDH 2208#ifndef OPENSSL_NO_ECDH
2489 if (alg_k & (SSL_kEECDH|SSL_kECDHr|SSL_kECDHe)) { 2209 if (alg_k & (SSL_kEECDH|SSL_kECDHr|SSL_kECDHe)) {
@@ -2717,43 +2437,6 @@ ssl3_get_client_key_exchange(SSL *s)
2717 goto f_err; 2437 goto f_err;
2718 } else 2438 } else
2719#endif 2439#endif
2720#ifndef OPENSSL_NO_SRP
2721 if (alg_k & SSL_kSRP) {
2722 int param_len;
2723
2724 n2s(p, i);
2725 param_len = i + 2;
2726 if (param_len > n) {
2727 al = SSL_AD_DECODE_ERROR;
2728 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2729 SSL_R_BAD_SRP_A_LENGTH);
2730 goto f_err;
2731 }
2732 if (!(s->srp_ctx.A = BN_bin2bn(p, i, NULL))) {
2733 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2734 ERR_R_BN_LIB);
2735 goto err;
2736 }
2737 if (s->session->srp_username != NULL)
2738 free(s->session->srp_username);
2739 s->session->srp_username = BUF_strdup(s->srp_ctx.login);
2740 if (s->session->srp_username == NULL) {
2741 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2742 ERR_R_MALLOC_FAILURE);
2743 goto err;
2744 }
2745
2746 if ((s->session->master_key_length =
2747 SRP_generate_server_master_secret(s,
2748 s->session->master_key)) < 0) {
2749 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
2750 ERR_R_INTERNAL_ERROR);
2751 goto err;
2752 }
2753
2754 p += i;
2755 } else
2756#endif /* OPENSSL_NO_SRP */
2757 if (alg_k & SSL_kGOST) { 2440 if (alg_k & SSL_kGOST) {
2758 int ret = 0; 2441 int ret = 0;
2759 EVP_PKEY_CTX *pkey_ctx; 2442 EVP_PKEY_CTX *pkey_ctx;
diff --git a/src/lib/libssl/src/ssl/ssl.h b/src/lib/libssl/src/ssl/ssl.h
index 0e117dbca4..dc56abaa99 100644
--- a/src/lib/libssl/src/ssl/ssl.h
+++ b/src/lib/libssl/src/ssl/ssl.h
@@ -466,10 +466,6 @@ struct ssl_session_st {
466 unsigned int sid_ctx_length; 466 unsigned int sid_ctx_length;
467 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH]; 467 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
468 468
469#ifndef OPENSSL_NO_KRB5
470 unsigned int krb5_client_princ_len;
471 unsigned char krb5_client_princ[SSL_MAX_KRB5_PRINCIPAL_LENGTH];
472#endif /* OPENSSL_NO_KRB5 */
473#ifndef OPENSSL_NO_PSK 469#ifndef OPENSSL_NO_PSK
474 char *psk_identity_hint; 470 char *psk_identity_hint;
475 char *psk_identity; 471 char *psk_identity;
@@ -522,9 +518,6 @@ struct ssl_session_st {
522 size_t tlsext_ticklen; /* Session ticket length */ 518 size_t tlsext_ticklen; /* Session ticket length */
523 long tlsext_tick_lifetime_hint; /* Session lifetime hint in seconds */ 519 long tlsext_tick_lifetime_hint; /* Session lifetime hint in seconds */
524#endif 520#endif
525#ifndef OPENSSL_NO_SRP
526 char *srp_username;
527#endif
528}; 521};
529 522
530#endif 523#endif
@@ -672,42 +665,6 @@ void SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version,
672#define SSL_CTX_set_msg_callback_arg(ctx, arg) SSL_CTX_ctrl((ctx), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg)) 665#define SSL_CTX_set_msg_callback_arg(ctx, arg) SSL_CTX_ctrl((ctx), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg))
673#define SSL_set_msg_callback_arg(ssl, arg) SSL_ctrl((ssl), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg)) 666#define SSL_set_msg_callback_arg(ssl, arg) SSL_ctrl((ssl), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg))
674 667
675#ifndef OPENSSL_NO_SRP
676
677#ifndef OPENSSL_NO_SSL_INTERN
678
679typedef struct srp_ctx_st {
680 /* param for all the callbacks */
681 void *SRP_cb_arg;
682 /* set client Hello login callback */
683 int (*TLS_ext_srp_username_callback)(SSL *, int *, void *);
684 /* set SRP N/g param callback for verification */
685 int (*SRP_verify_param_callback)(SSL *, void *);
686 /* set SRP client passwd callback */
687 char *(*SRP_give_srp_client_pwd_callback)(SSL *, void *);
688
689 char *login;
690 BIGNUM *N, *g, *s, *B, *A;
691 BIGNUM *a, *b, *v;
692 char *info;
693 int strength;
694
695 unsigned long srp_Mask;
696} SRP_CTX;
697
698#endif
699
700/* see tls_srp.c */
701int SSL_SRP_CTX_init(SSL *s);
702int SSL_CTX_SRP_CTX_init(SSL_CTX *ctx);
703int SSL_SRP_CTX_free(SSL *ctx);
704int SSL_CTX_SRP_CTX_free(SSL_CTX *ctx);
705int SSL_srp_server_param_with_username(SSL *s, int *ad);
706int SRP_generate_server_master_secret(SSL *s, unsigned char *master_key);
707int SRP_Calc_A_param(SSL *s);
708int SRP_generate_client_master_secret(SSL *s, unsigned char *master_key);
709
710#endif
711 668
712#define SSL_MAX_CERT_LIST_DEFAULT 1024*100 /* 100k max cert list :-) */ 669#define SSL_MAX_CERT_LIST_DEFAULT 1024*100 /* 100k max cert list :-) */
713 670
@@ -922,9 +879,6 @@ struct ssl_ctx_st {
922 unsigned char *psk, unsigned int max_psk_len); 879 unsigned char *psk, unsigned int max_psk_len);
923#endif 880#endif
924 881
925#ifndef OPENSSL_NO_SRP
926 SRP_CTX srp_ctx; /* ctx for SRP authentication */
927#endif
928 882
929#ifndef OPENSSL_NO_TLSEXT 883#ifndef OPENSSL_NO_TLSEXT
930 884
@@ -1213,9 +1167,6 @@ struct ssl_st {
1213 int error; /* error bytes to be written */ 1167 int error; /* error bytes to be written */
1214 int error_code; /* actual code */ 1168 int error_code; /* actual code */
1215 1169
1216#ifndef OPENSSL_NO_KRB5
1217 KSSL_CTX *kssl_ctx; /* Kerberos 5 context */
1218#endif /* OPENSSL_NO_KRB5 */
1219 1170
1220#ifndef OPENSSL_NO_PSK 1171#ifndef OPENSSL_NO_PSK
1221 unsigned int (*psk_client_callback)(SSL *ssl, const char *hint, 1172 unsigned int (*psk_client_callback)(SSL *ssl, const char *hint,
@@ -1327,9 +1278,6 @@ struct ssl_st {
1327 * 2 if we are a server and are inside a handshake 1278 * 2 if we are a server and are inside a handshake
1328 * (i.e. not just sending a HelloRequest) */ 1279 * (i.e. not just sending a HelloRequest) */
1329 1280
1330#ifndef OPENSSL_NO_SRP
1331 SRP_CTX srp_ctx; /* ctx for SRP authentication */
1332#endif
1333}; 1281};
1334 1282
1335#endif 1283#endif
@@ -1771,24 +1719,6 @@ int SSL_set_trust(SSL *s, int trust);
1771int SSL_CTX_set1_param(SSL_CTX *ctx, X509_VERIFY_PARAM *vpm); 1719int SSL_CTX_set1_param(SSL_CTX *ctx, X509_VERIFY_PARAM *vpm);
1772int SSL_set1_param(SSL *ssl, X509_VERIFY_PARAM *vpm); 1720int SSL_set1_param(SSL *ssl, X509_VERIFY_PARAM *vpm);
1773 1721
1774#ifndef OPENSSL_NO_SRP
1775int SSL_CTX_set_srp_username(SSL_CTX *ctx, char *name);
1776int SSL_CTX_set_srp_password(SSL_CTX *ctx, char *password);
1777int SSL_CTX_set_srp_strength(SSL_CTX *ctx, int strength);
1778int SSL_CTX_set_srp_client_pwd_callback(SSL_CTX *ctx, char *(*cb)(SSL *, void *));
1779int SSL_CTX_set_srp_verify_param_callback(SSL_CTX *ctx, int (*cb)(SSL *, void *));
1780int SSL_CTX_set_srp_username_callback(SSL_CTX *ctx, int (*cb)(SSL *, int *, void *));
1781int SSL_CTX_set_srp_cb_arg(SSL_CTX *ctx, void *arg);
1782
1783int SSL_set_srp_server_param(SSL *s, const BIGNUM *N, const BIGNUM *g, BIGNUM *sa, BIGNUM *v, char *info);
1784int SSL_set_srp_server_param_pw(SSL *s, const char *user, const char *pass, const char *grp);
1785
1786BIGNUM *SSL_get_srp_g(SSL *s);
1787BIGNUM *SSL_get_srp_N(SSL *s);
1788
1789char *SSL_get_srp_username(SSL *s);
1790char *SSL_get_srp_userinfo(SSL *s);
1791#endif
1792 1722
1793void SSL_free(SSL *ssl); 1723void SSL_free(SSL *ssl);
1794int SSL_accept(SSL *ssl); 1724int SSL_accept(SSL *ssl);
diff --git a/src/lib/libssl/src/ssl/ssl_asn1.c b/src/lib/libssl/src/ssl/ssl_asn1.c
index 1d2590268c..566590f171 100644
--- a/src/lib/libssl/src/ssl/ssl_asn1.c
+++ b/src/lib/libssl/src/ssl/ssl_asn1.c
@@ -97,9 +97,6 @@ typedef struct ssl_session_asn1_st {
97 ASN1_OCTET_STRING master_key; 97 ASN1_OCTET_STRING master_key;
98 ASN1_OCTET_STRING session_id; 98 ASN1_OCTET_STRING session_id;
99 ASN1_OCTET_STRING session_id_context; 99 ASN1_OCTET_STRING session_id_context;
100#ifndef OPENSSL_NO_KRB5
101 ASN1_OCTET_STRING krb5_princ;
102#endif /* OPENSSL_NO_KRB5 */
103 ASN1_INTEGER time; 100 ASN1_INTEGER time;
104 ASN1_INTEGER timeout; 101 ASN1_INTEGER timeout;
105 ASN1_INTEGER verify_result; 102 ASN1_INTEGER verify_result;
@@ -112,9 +109,6 @@ typedef struct ssl_session_asn1_st {
112 ASN1_OCTET_STRING psk_identity_hint; 109 ASN1_OCTET_STRING psk_identity_hint;
113 ASN1_OCTET_STRING psk_identity; 110 ASN1_OCTET_STRING psk_identity;
114#endif /* OPENSSL_NO_PSK */ 111#endif /* OPENSSL_NO_PSK */
115#ifndef OPENSSL_NO_SRP
116 ASN1_OCTET_STRING srp_username;
117#endif /* OPENSSL_NO_SRP */
118} SSL_SESSION_ASN1; 112} SSL_SESSION_ASN1;
119 113
120int 114int
@@ -132,9 +126,6 @@ i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
132 unsigned char cbuf; 126 unsigned char cbuf;
133 int v11 = 0; 127 int v11 = 0;
134#endif 128#endif
135#ifndef OPENSSL_NO_SRP
136 int v12 = 0;
137#endif
138 long l; 129 long l;
139 SSL_SESSION_ASN1 a; 130 SSL_SESSION_ASN1 a;
140 M_ASN1_I2D_vars(in); 131 M_ASN1_I2D_vars(in);
@@ -189,13 +180,6 @@ i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
189 a.session_id_context.type = V_ASN1_OCTET_STRING; 180 a.session_id_context.type = V_ASN1_OCTET_STRING;
190 a.session_id_context.data = in->sid_ctx; 181 a.session_id_context.data = in->sid_ctx;
191 182
192#ifndef OPENSSL_NO_KRB5
193 if (in->krb5_client_princ_len) {
194 a.krb5_princ.length = in->krb5_client_princ_len;
195 a.krb5_princ.type = V_ASN1_OCTET_STRING;
196 a.krb5_princ.data = in->krb5_client_princ;
197 }
198#endif /* OPENSSL_NO_KRB5 */
199 183
200 if (in->time != 0L) { 184 if (in->time != 0L) {
201 a.time.length = LSIZE2; 185 a.time.length = LSIZE2;
@@ -248,23 +232,12 @@ i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
248 a.psk_identity.data = (unsigned char *)(in->psk_identity); 232 a.psk_identity.data = (unsigned char *)(in->psk_identity);
249 } 233 }
250#endif /* OPENSSL_NO_PSK */ 234#endif /* OPENSSL_NO_PSK */
251#ifndef OPENSSL_NO_SRP
252 if (in->srp_username) {
253 a.srp_username.length = strlen(in->srp_username);
254 a.srp_username.type = V_ASN1_OCTET_STRING;
255 a.srp_username.data = (unsigned char *)(in->srp_username);
256 }
257#endif /* OPENSSL_NO_SRP */
258 235
259 M_ASN1_I2D_len(&(a.version), i2d_ASN1_INTEGER); 236 M_ASN1_I2D_len(&(a.version), i2d_ASN1_INTEGER);
260 M_ASN1_I2D_len(&(a.ssl_version), i2d_ASN1_INTEGER); 237 M_ASN1_I2D_len(&(a.ssl_version), i2d_ASN1_INTEGER);
261 M_ASN1_I2D_len(&(a.cipher), i2d_ASN1_OCTET_STRING); 238 M_ASN1_I2D_len(&(a.cipher), i2d_ASN1_OCTET_STRING);
262 M_ASN1_I2D_len(&(a.session_id), i2d_ASN1_OCTET_STRING); 239 M_ASN1_I2D_len(&(a.session_id), i2d_ASN1_OCTET_STRING);
263 M_ASN1_I2D_len(&(a.master_key), i2d_ASN1_OCTET_STRING); 240 M_ASN1_I2D_len(&(a.master_key), i2d_ASN1_OCTET_STRING);
264#ifndef OPENSSL_NO_KRB5
265 if (in->krb5_client_princ_len)
266 M_ASN1_I2D_len(&(a.krb5_princ), i2d_ASN1_OCTET_STRING);
267#endif /* OPENSSL_NO_KRB5 */
268 if (in->time != 0L) 241 if (in->time != 0L)
269 M_ASN1_I2D_len_EXP_opt(&(a.time), i2d_ASN1_INTEGER, 1, v1); 242 M_ASN1_I2D_len_EXP_opt(&(a.time), i2d_ASN1_INTEGER, 1, v1);
270 if (in->timeout != 0L) 243 if (in->timeout != 0L)
@@ -293,10 +266,6 @@ i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
293 if (in->psk_identity) 266 if (in->psk_identity)
294 M_ASN1_I2D_len_EXP_opt(&(a.psk_identity), i2d_ASN1_OCTET_STRING, 8, v8); 267 M_ASN1_I2D_len_EXP_opt(&(a.psk_identity), i2d_ASN1_OCTET_STRING, 8, v8);
295#endif /* OPENSSL_NO_PSK */ 268#endif /* OPENSSL_NO_PSK */
296#ifndef OPENSSL_NO_SRP
297 if (in->srp_username)
298 M_ASN1_I2D_len_EXP_opt(&(a.srp_username), i2d_ASN1_OCTET_STRING, 12, v12);
299#endif /* OPENSSL_NO_SRP */
300 269
301 M_ASN1_I2D_seq_total(); 270 M_ASN1_I2D_seq_total();
302 271
@@ -305,10 +274,6 @@ i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
305 M_ASN1_I2D_put(&(a.cipher), i2d_ASN1_OCTET_STRING); 274 M_ASN1_I2D_put(&(a.cipher), i2d_ASN1_OCTET_STRING);
306 M_ASN1_I2D_put(&(a.session_id), i2d_ASN1_OCTET_STRING); 275 M_ASN1_I2D_put(&(a.session_id), i2d_ASN1_OCTET_STRING);
307 M_ASN1_I2D_put(&(a.master_key), i2d_ASN1_OCTET_STRING); 276 M_ASN1_I2D_put(&(a.master_key), i2d_ASN1_OCTET_STRING);
308#ifndef OPENSSL_NO_KRB5
309 if (in->krb5_client_princ_len)
310 M_ASN1_I2D_put(&(a.krb5_princ), i2d_ASN1_OCTET_STRING);
311#endif /* OPENSSL_NO_KRB5 */
312 if (in->time != 0L) 277 if (in->time != 0L)
313 M_ASN1_I2D_put_EXP_opt(&(a.time), i2d_ASN1_INTEGER, 1, v1); 278 M_ASN1_I2D_put_EXP_opt(&(a.time), i2d_ASN1_INTEGER, 1, v1);
314 if (in->timeout != 0L) 279 if (in->timeout != 0L)
@@ -339,10 +304,6 @@ i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
339 if (in->compress_meth) 304 if (in->compress_meth)
340 M_ASN1_I2D_put_EXP_opt(&(a.comp_id), i2d_ASN1_OCTET_STRING, 11, v11); 305 M_ASN1_I2D_put_EXP_opt(&(a.comp_id), i2d_ASN1_OCTET_STRING, 11, v11);
341#endif 306#endif
342#ifndef OPENSSL_NO_SRP
343 if (in->srp_username)
344 M_ASN1_I2D_put_EXP_opt(&(a.srp_username), i2d_ASN1_OCTET_STRING, 12, v12);
345#endif /* OPENSSL_NO_SRP */
346 M_ASN1_I2D_finish(); 307 M_ASN1_I2D_finish();
347} 308}
348 309
@@ -420,21 +381,6 @@ d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp, long length)
420 381
421 os.length = 0; 382 os.length = 0;
422 383
423#ifndef OPENSSL_NO_KRB5
424 os.length = 0;
425 M_ASN1_D2I_get_opt(osp, d2i_ASN1_OCTET_STRING, V_ASN1_OCTET_STRING);
426 if (os.data) {
427 if (os.length > SSL_MAX_KRB5_PRINCIPAL_LENGTH)
428 ret->krb5_client_princ_len = 0;
429 else
430 ret->krb5_client_princ_len = os.length;
431 memcpy(ret->krb5_client_princ, os.data, ret->krb5_client_princ_len);
432 free(os.data);
433 os.data = NULL;
434 os.length = 0;
435 } else
436 ret->krb5_client_princ_len = 0;
437#endif /* OPENSSL_NO_KRB5 */
438 384
439 ai.length = 0; 385 ai.length = 0;
440 M_ASN1_D2I_get_EXP_opt(aip, d2i_ASN1_INTEGER, 1); /* XXX 2038 */ 386 M_ASN1_D2I_get_EXP_opt(aip, d2i_ASN1_INTEGER, 1); /* XXX 2038 */
@@ -561,18 +507,6 @@ d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp, long length)
561 } 507 }
562#endif 508#endif
563 509
564#ifndef OPENSSL_NO_SRP
565 os.length = 0;
566 os.data = NULL;
567 M_ASN1_D2I_get_EXP_opt(osp, d2i_ASN1_OCTET_STRING, 12);
568 if (os.data) {
569 ret->srp_username = BUF_strndup((char *)os.data, os.length);
570 free(os.data);
571 os.data = NULL;
572 os.length = 0;
573 } else
574 ret->srp_username = NULL;
575#endif /* OPENSSL_NO_SRP */
576 510
577 M_ASN1_D2I_Finish(a, SSL_SESSION_free, SSL_F_D2I_SSL_SESSION); 511 M_ASN1_D2I_Finish(a, SSL_SESSION_free, SSL_F_D2I_SSL_SESSION);
578} 512}
diff --git a/src/lib/libssl/src/ssl/ssl_ciph.c b/src/lib/libssl/src/ssl/ssl_ciph.c
index 00ab752de1..a1523524a1 100644
--- a/src/lib/libssl/src/ssl/ssl_ciph.c
+++ b/src/lib/libssl/src/ssl/ssl_ciph.c
@@ -702,10 +702,8 @@ ssl_cipher_get_disabled(unsigned long *mkey, unsigned long *auth, unsigned long
702 *mkey |= SSL_kDHr|SSL_kDHd|SSL_kEDH; 702 *mkey |= SSL_kDHr|SSL_kDHd|SSL_kEDH;
703 *auth |= SSL_aDH; 703 *auth |= SSL_aDH;
704#endif 704#endif
705#ifdef OPENSSL_NO_KRB5
706 *mkey |= SSL_kKRB5; 705 *mkey |= SSL_kKRB5;
707 *auth |= SSL_aKRB5; 706 *auth |= SSL_aKRB5;
708#endif
709#ifdef OPENSSL_NO_ECDSA 707#ifdef OPENSSL_NO_ECDSA
710 *auth |= SSL_aECDSA; 708 *auth |= SSL_aECDSA;
711#endif 709#endif
@@ -717,9 +715,7 @@ ssl_cipher_get_disabled(unsigned long *mkey, unsigned long *auth, unsigned long
717 *mkey |= SSL_kPSK; 715 *mkey |= SSL_kPSK;
718 *auth |= SSL_aPSK; 716 *auth |= SSL_aPSK;
719#endif 717#endif
720#ifdef OPENSSL_NO_SRP
721 *mkey |= SSL_kSRP; 718 *mkey |= SSL_kSRP;
722#endif
723 /* Check for presence of GOST 34.10 algorithms, and if they 719 /* Check for presence of GOST 34.10 algorithms, and if they
724 * do not present, disable appropriate auth and key exchange */ 720 * do not present, disable appropriate auth and key exchange */
725 if (!get_optional_pkey_id("gost94")) { 721 if (!get_optional_pkey_id("gost94")) {
diff --git a/src/lib/libssl/src/ssl/ssl_lib.c b/src/lib/libssl/src/ssl/ssl_lib.c
index 195271a554..d046480feb 100644
--- a/src/lib/libssl/src/ssl/ssl_lib.c
+++ b/src/lib/libssl/src/ssl/ssl_lib.c
@@ -284,9 +284,6 @@ SSL_new(SSL_CTX *ctx)
284 if (s == NULL) 284 if (s == NULL)
285 goto err; 285 goto err;
286 286
287#ifndef OPENSSL_NO_KRB5
288 s->kssl_ctx = kssl_ctx_new();
289#endif /* OPENSSL_NO_KRB5 */
290 287
291 s->options = ctx->options; 288 s->options = ctx->options;
292 s->mode = ctx->mode; 289 s->mode = ctx->mode;
@@ -580,10 +577,6 @@ SSL_free(SSL *s)
580 if (s->ctx) 577 if (s->ctx)
581 SSL_CTX_free(s->ctx); 578 SSL_CTX_free(s->ctx);
582 579
583#ifndef OPENSSL_NO_KRB5
584 if (s->kssl_ctx != NULL)
585 kssl_ctx_free(s->kssl_ctx);
586#endif /* OPENSSL_NO_KRB5 */
587 580
588#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG) 581#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
589 if (s->next_proto_negotiated) 582 if (s->next_proto_negotiated)
@@ -1415,9 +1408,6 @@ ssl_cipher_list_to_bytes(SSL *s, STACK_OF(SSL_CIPHER) *sk, unsigned char *p,
1415 int i, j = 0; 1408 int i, j = 0;
1416 SSL_CIPHER *c; 1409 SSL_CIPHER *c;
1417 unsigned char *q; 1410 unsigned char *q;
1418#ifndef OPENSSL_NO_KRB5
1419 int nokrb5 = !kssl_tgt_is_available(s->kssl_ctx);
1420#endif /* OPENSSL_NO_KRB5 */
1421 1411
1422 if (sk == NULL) 1412 if (sk == NULL)
1423 return (0); 1413 return (0);
@@ -1429,11 +1419,6 @@ ssl_cipher_list_to_bytes(SSL *s, STACK_OF(SSL_CIPHER) *sk, unsigned char *p,
1429 if ((c->algorithm_ssl & SSL_TLSV1_2) && 1419 if ((c->algorithm_ssl & SSL_TLSV1_2) &&
1430 (TLS1_get_client_version(s) < TLS1_2_VERSION)) 1420 (TLS1_get_client_version(s) < TLS1_2_VERSION))
1431 continue; 1421 continue;
1432#ifndef OPENSSL_NO_KRB5
1433 if (((c->algorithm_mkey & SSL_kKRB5) ||
1434 (c->algorithm_auth & SSL_aKRB5)) && nokrb5)
1435 continue;
1436#endif /* OPENSSL_NO_KRB5 */
1437#ifndef OPENSSL_NO_PSK 1422#ifndef OPENSSL_NO_PSK
1438 /* with PSK there must be client callback set */ 1423 /* with PSK there must be client callback set */
1439 if (((c->algorithm_mkey & SSL_kPSK) || 1424 if (((c->algorithm_mkey & SSL_kPSK) ||
@@ -1877,9 +1862,6 @@ SSL_CTX_new(const SSL_METHOD *meth)
1877 ret->psk_client_callback = NULL; 1862 ret->psk_client_callback = NULL;
1878 ret->psk_server_callback = NULL; 1863 ret->psk_server_callback = NULL;
1879#endif 1864#endif
1880#ifndef OPENSSL_NO_SRP
1881 SSL_CTX_SRP_CTX_init(ret);
1882#endif
1883#ifndef OPENSSL_NO_ENGINE 1865#ifndef OPENSSL_NO_ENGINE
1884 ret->client_cert_engine = NULL; 1866 ret->client_cert_engine = NULL;
1885#ifdef OPENSSL_SSL_CLIENT_ENGINE_AUTO 1867#ifdef OPENSSL_SSL_CLIENT_ENGINE_AUTO
@@ -1983,9 +1965,6 @@ SSL_CTX_free(SSL_CTX *a)
1983 if (a->psk_identity_hint) 1965 if (a->psk_identity_hint)
1984 free(a->psk_identity_hint); 1966 free(a->psk_identity_hint);
1985#endif 1967#endif
1986#ifndef OPENSSL_NO_SRP
1987 SSL_CTX_SRP_CTX_free(a);
1988#endif
1989#ifndef OPENSSL_NO_ENGINE 1968#ifndef OPENSSL_NO_ENGINE
1990 if (a->client_cert_engine) 1969 if (a->client_cert_engine)
1991 ENGINE_finish(a->client_cert_engine); 1970 ENGINE_finish(a->client_cert_engine);
@@ -2147,12 +2126,6 @@ ssl_set_cert_masks(CERT *c, const SSL_CIPHER *cipher)
2147 mask_a|=SSL_aNULL; 2126 mask_a|=SSL_aNULL;
2148 emask_a|=SSL_aNULL; 2127 emask_a|=SSL_aNULL;
2149 2128
2150#ifndef OPENSSL_NO_KRB5
2151 mask_k|=SSL_kKRB5;
2152 mask_a|=SSL_aKRB5;
2153 emask_k|=SSL_kKRB5;
2154 emask_a|=SSL_aKRB5;
2155#endif
2156 2129
2157 /* 2130 /*
2158 * An ECC certificate may be usable for ECDH and/or 2131 * An ECC certificate may be usable for ECDH and/or
diff --git a/src/lib/libssl/src/ssl/ssl_sess.c b/src/lib/libssl/src/ssl/ssl_sess.c
index 2b8da1ccae..05c6948efc 100644
--- a/src/lib/libssl/src/ssl/ssl_sess.c
+++ b/src/lib/libssl/src/ssl/ssl_sess.c
@@ -223,9 +223,6 @@ SSL_SESSION_new(void)
223 ss->psk_identity_hint = NULL; 223 ss->psk_identity_hint = NULL;
224 ss->psk_identity = NULL; 224 ss->psk_identity = NULL;
225#endif 225#endif
226#ifndef OPENSSL_NO_SRP
227 ss->srp_username = NULL;
228#endif
229 return (ss); 226 return (ss);
230} 227}
231 228
@@ -726,10 +723,6 @@ SSL_SESSION_free(SSL_SESSION *ss)
726 if (ss->psk_identity != NULL) 723 if (ss->psk_identity != NULL)
727 free(ss->psk_identity); 724 free(ss->psk_identity);
728#endif 725#endif
729#ifndef OPENSSL_NO_SRP
730 if (ss->srp_username != NULL)
731 free(ss->srp_username);
732#endif
733 OPENSSL_cleanse(ss, sizeof(*ss)); 726 OPENSSL_cleanse(ss, sizeof(*ss));
734 free(ss); 727 free(ss);
735} 728}
@@ -754,15 +747,6 @@ SSL_set_session(SSL *s, SSL_SESSION *session)
754 return (0); 747 return (0);
755 } 748 }
756 749
757#ifndef OPENSSL_NO_KRB5
758 if (s->kssl_ctx && !s->kssl_ctx->client_princ &&
759 session->krb5_client_princ_len > 0) {
760 s->kssl_ctx->client_princ = malloc(session->krb5_client_princ_len + 1);
761 memcpy(s->kssl_ctx->client_princ, session->krb5_client_princ,
762 session->krb5_client_princ_len);
763 s->kssl_ctx->client_princ[session->krb5_client_princ_len] = '\0';
764 }
765#endif /* OPENSSL_NO_KRB5 */
766 750
767 /* CRYPTO_w_lock(CRYPTO_LOCK_SSL);*/ 751 /* CRYPTO_w_lock(CRYPTO_LOCK_SSL);*/
768 CRYPTO_add(&session->references, 1, CRYPTO_LOCK_SSL_SESSION); 752 CRYPTO_add(&session->references, 1, CRYPTO_LOCK_SSL_SESSION);
diff --git a/src/lib/libssl/src/ssl/ssl_txt.c b/src/lib/libssl/src/ssl/ssl_txt.c
index c6bfd68de6..01dd846596 100644
--- a/src/lib/libssl/src/ssl/ssl_txt.c
+++ b/src/lib/libssl/src/ssl/ssl_txt.c
@@ -161,19 +161,6 @@ SSL_SESSION_print(BIO *bp, const SSL_SESSION *x)
161 if (BIO_printf(bp, "%02X", x->master_key[i]) <= 0) 161 if (BIO_printf(bp, "%02X", x->master_key[i]) <= 0)
162 goto err; 162 goto err;
163 } 163 }
164#ifndef OPENSSL_NO_KRB5
165 if (BIO_puts(bp, "\n Krb5 Principal: ") <= 0)
166 goto err;
167 if (x->krb5_client_princ_len == 0) {
168 if (BIO_puts(bp, "None") <= 0)
169 goto err;
170 } else {
171 for (i = 0; i < x->krb5_client_princ_len; i++) {
172 if (BIO_printf(bp, "%02X", x->krb5_client_princ[i]) <= 0)
173 goto err;
174 }
175 }
176#endif /* OPENSSL_NO_KRB5 */
177#ifndef OPENSSL_NO_PSK 164#ifndef OPENSSL_NO_PSK
178 if (BIO_puts(bp, "\n PSK identity: ") <= 0) 165 if (BIO_puts(bp, "\n PSK identity: ") <= 0)
179 goto err; 166 goto err;
@@ -184,12 +171,6 @@ SSL_SESSION_print(BIO *bp, const SSL_SESSION *x)
184 if (BIO_printf(bp, "%s", x->psk_identity_hint ? x->psk_identity_hint : "None") <= 0) 171 if (BIO_printf(bp, "%s", x->psk_identity_hint ? x->psk_identity_hint : "None") <= 0)
185 goto err; 172 goto err;
186#endif 173#endif
187#ifndef OPENSSL_NO_SRP
188 if (BIO_puts(bp, "\n SRP username: ") <= 0)
189 goto err;
190 if (BIO_printf(bp, "%s", x->srp_username ? x->srp_username : "None") <= 0)
191 goto err;
192#endif
193#ifndef OPENSSL_NO_TLSEXT 174#ifndef OPENSSL_NO_TLSEXT
194 if (x->tlsext_tick_lifetime_hint) { 175 if (x->tlsext_tick_lifetime_hint) {
195 if (BIO_printf(bp, 176 if (BIO_printf(bp,
diff --git a/src/lib/libssl/src/ssl/ssltest.c b/src/lib/libssl/src/ssl/ssltest.c
index 1f5014baf3..879bf4b3ed 100644
--- a/src/lib/libssl/src/ssl/ssltest.c
+++ b/src/lib/libssl/src/ssl/ssltest.c
@@ -178,9 +178,6 @@
178#ifndef OPENSSL_NO_DH 178#ifndef OPENSSL_NO_DH
179#include <openssl/dh.h> 179#include <openssl/dh.h>
180#endif 180#endif
181#ifndef OPENSSL_NO_SRP
182#include <openssl/srp.h>
183#endif
184#include <openssl/bn.h> 181#include <openssl/bn.h>
185 182
186#define _XOPEN_SOURCE_EXTENDED 1 183#define _XOPEN_SOURCE_EXTENDED 1
@@ -227,46 +224,6 @@ static unsigned int psk_server_callback(SSL *ssl, const char *identity,
227 unsigned char *psk, unsigned int max_psk_len); 224 unsigned char *psk, unsigned int max_psk_len);
228#endif 225#endif
229 226
230#ifndef OPENSSL_NO_SRP
231/* SRP client */
232/* This is a context that we pass to all callbacks */
233typedef struct srp_client_arg_st {
234 char *srppassin;
235 char *srplogin;
236} SRP_CLIENT_ARG;
237
238#define PWD_STRLEN 1024
239
240static char *
241ssl_give_srp_client_pwd_cb(SSL *s, void *arg)
242{
243 SRP_CLIENT_ARG *srp_client_arg = (SRP_CLIENT_ARG *)arg;
244 return BUF_strdup((char *)srp_client_arg->srppassin);
245}
246
247/* SRP server */
248/* This is a context that we pass to SRP server callbacks */
249typedef struct srp_server_arg_st {
250 char *expected_user;
251 char *pass;
252} SRP_SERVER_ARG;
253
254static int
255ssl_srp_server_param_cb(SSL *s, int *ad, void *arg)
256{
257 SRP_SERVER_ARG *p = (SRP_SERVER_ARG *) arg;
258
259 if (strcmp(p->expected_user, SSL_get_srp_username(s)) != 0) {
260 fprintf(stderr, "User %s doesn't exist\n", SSL_get_srp_username(s));
261 return SSL3_AL_FATAL;
262 }
263 if (SSL_set_srp_server_param_pw(s, p->expected_user, p->pass, "1024") < 0) {
264 *ad = SSL_AD_INTERNAL_ERROR;
265 return SSL3_AL_FATAL;
266 }
267 return SSL_ERROR_NONE;
268}
269#endif
270 227
271static BIO *bio_err = NULL; 228static BIO *bio_err = NULL;
272static BIO *bio_stdout = NULL; 229static BIO *bio_stdout = NULL;
@@ -311,10 +268,6 @@ sv_usage(void)
311#ifndef OPENSSL_NO_PSK 268#ifndef OPENSSL_NO_PSK
312 fprintf(stderr, " -psk arg - PSK in hex (without 0x)\n"); 269 fprintf(stderr, " -psk arg - PSK in hex (without 0x)\n");
313#endif 270#endif
314#ifndef OPENSSL_NO_SRP
315 fprintf(stderr, " -srpuser user - SRP username to use\n");
316 fprintf(stderr, " -srppass arg - password for 'user'\n");
317#endif
318 fprintf(stderr, " -ssl3 - use SSLv3\n"); 271 fprintf(stderr, " -ssl3 - use SSLv3\n");
319 fprintf(stderr, " -tls1 - use TLSv1\n"); 272 fprintf(stderr, " -tls1 - use TLSv1\n");
320 fprintf(stderr, " -CApath arg - PEM format directory of CA's\n"); 273 fprintf(stderr, " -CApath arg - PEM format directory of CA's\n");
@@ -484,12 +437,6 @@ main(int argc, char *argv[])
484#ifndef OPENSSL_NO_ECDH 437#ifndef OPENSSL_NO_ECDH
485 EC_KEY *ecdh = NULL; 438 EC_KEY *ecdh = NULL;
486#endif 439#endif
487#ifndef OPENSSL_NO_SRP
488 /* client */
489 SRP_CLIENT_ARG srp_client_arg = {NULL, NULL};
490 /* server */
491 SRP_SERVER_ARG srp_server_arg = {NULL, NULL};
492#endif
493 int no_dhe = 0; 440 int no_dhe = 0;
494 int no_ecdhe = 0; 441 int no_ecdhe = 0;
495 int no_psk = 0; 442 int no_psk = 0;
@@ -577,19 +524,6 @@ main(int argc, char *argv[])
577 no_psk = 1; 524 no_psk = 1;
578#endif 525#endif
579 } 526 }
580#ifndef OPENSSL_NO_SRP
581 else if (strcmp(*argv, "-srpuser") == 0) {
582 if (--argc < 1)
583 goto bad;
584 srp_server_arg.expected_user = srp_client_arg.srplogin= *(++argv);
585 tls1 = 1;
586 } else if (strcmp(*argv, "-srppass") == 0) {
587 if (--argc < 1)
588 goto bad;
589 srp_server_arg.pass = srp_client_arg.srppassin= *(++argv);
590 tls1 = 1;
591 }
592#endif
593 else if (strcmp(*argv, "-ssl2") == 0) 527 else if (strcmp(*argv, "-ssl2") == 0)
594 ssl2 = 1; 528 ssl2 = 1;
595 else if (strcmp(*argv, "-tls1") == 0) 529 else if (strcmp(*argv, "-tls1") == 0)
@@ -895,42 +829,10 @@ bad:
895 } 829 }
896#endif 830#endif
897 } 831 }
898#ifndef OPENSSL_NO_SRP
899 if (srp_client_arg.srplogin) {
900 if (!SSL_CTX_set_srp_username(c_ctx, srp_client_arg.srplogin)) {
901 BIO_printf(bio_err, "Unable to set SRP username\n");
902 goto end;
903 }
904 SSL_CTX_set_srp_cb_arg(c_ctx, &srp_client_arg);
905 SSL_CTX_set_srp_client_pwd_callback(c_ctx, ssl_give_srp_client_pwd_cb);
906 /*SSL_CTX_set_srp_strength(c_ctx, srp_client_arg.strength);*/
907 }
908
909 if (srp_server_arg.expected_user != NULL) {
910 SSL_CTX_set_verify(s_ctx, SSL_VERIFY_NONE, verify_callback);
911 SSL_CTX_set_srp_cb_arg(s_ctx, &srp_server_arg);
912 SSL_CTX_set_srp_username_callback(s_ctx, ssl_srp_server_param_cb);
913 }
914#endif
915 832
916 c_ssl = SSL_new(c_ctx); 833 c_ssl = SSL_new(c_ctx);
917 s_ssl = SSL_new(s_ctx); 834 s_ssl = SSL_new(s_ctx);
918 835
919#ifndef OPENSSL_NO_KRB5
920 if (c_ssl && c_ssl->kssl_ctx) {
921 char localhost[MAXHOSTNAMELEN + 2];
922
923 if (gethostname(localhost, sizeof localhost - 1) == 0) {
924 localhost[sizeof localhost - 1] = '\0';
925 if (strlen(localhost) == sizeof localhost - 1) {
926 BIO_printf(bio_err, "localhost name too long\n");
927 goto end;
928 }
929 kssl_ctx_setstring(c_ssl->kssl_ctx, KSSL_SERVER,
930 localhost);
931 }
932 }
933#endif /* OPENSSL_NO_KRB5 */
934 836
935 for (i = 0; i < number; i++) { 837 for (i = 0; i < number; i++) {
936 if (!reuse) 838 if (!reuse)
diff --git a/src/lib/libssl/src/ssl/t1_lib.c b/src/lib/libssl/src/ssl/t1_lib.c
index bb33331862..2e183bb233 100644
--- a/src/lib/libssl/src/ssl/t1_lib.c
+++ b/src/lib/libssl/src/ssl/t1_lib.c
@@ -415,35 +415,6 @@ ssl_add_clienthello_tlsext(SSL *s, unsigned char *p, unsigned char *limit)
415 ret += el; 415 ret += el;
416 } 416 }
417 417
418#ifndef OPENSSL_NO_SRP
419 /* Add SRP username if there is one */
420 if (s->srp_ctx.login != NULL) {
421 /* Add TLS extension SRP username to the Client Hello message */
422
423 int login_len = strlen(s->srp_ctx.login);
424
425 if (login_len > 255 || login_len == 0) {
426 SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);
427 return NULL;
428 }
429
430 /* check for enough space.
431 4 for the srp type type and entension length
432 1 for the srp user identity
433 + srp user identity length
434 */
435 if ((limit - ret - 5 - login_len) < 0)
436 return NULL;
437
438
439 /* fill in the extension */
440 s2n(TLSEXT_TYPE_srp, ret);
441 s2n(login_len + 1, ret);
442 (*ret++) = (unsigned char) login_len;
443 memcpy(ret, s->srp_ctx.login, login_len);
444 ret += login_len;
445 }
446#endif
447 418
448#ifndef OPENSSL_NO_EC 419#ifndef OPENSSL_NO_EC
449 if (s->tlsext_ecpointformatlist != NULL && 420 if (s->tlsext_ecpointformatlist != NULL &&
@@ -1063,27 +1034,6 @@ ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d,
1063 } 1034 }
1064 1035
1065 } 1036 }
1066#ifndef OPENSSL_NO_SRP
1067 else if (type == TLSEXT_TYPE_srp) {
1068 if (size <= 0 || ((len = data[0])) != (size - 1)) {
1069 *al = SSL_AD_DECODE_ERROR;
1070 return 0;
1071 }
1072 if (s->srp_ctx.login != NULL) {
1073 *al = SSL_AD_DECODE_ERROR;
1074 return 0;
1075 }
1076 if ((s->srp_ctx.login = malloc(len + 1)) == NULL)
1077 return -1;
1078 memcpy(s->srp_ctx.login, &data[1], len);
1079 s->srp_ctx.login[len] = '\0';
1080
1081 if (strlen(s->srp_ctx.login) != len) {
1082 *al = SSL_AD_DECODE_ERROR;
1083 return 0;
1084 }
1085 }
1086#endif
1087 1037
1088#ifndef OPENSSL_NO_EC 1038#ifndef OPENSSL_NO_EC
1089 else if (type == TLSEXT_TYPE_ec_point_formats && 1039 else if (type == TLSEXT_TYPE_ec_point_formats &&
diff --git a/src/lib/libssl/src/ssl/tls_srp.c b/src/lib/libssl/src/ssl/tls_srp.c
deleted file mode 100644
index e03eabcef6..0000000000
--- a/src/lib/libssl/src/ssl/tls_srp.c
+++ /dev/null
@@ -1,516 +0,0 @@
1/* ssl/tls_srp.c */
2/* Written by Christophe Renou (christophe.renou@edelweb.fr) with
3 * the precious help of Peter Sylvester (peter.sylvester@edelweb.fr)
4 * for the EdelKey project and contributed to the OpenSSL project 2004.
5 */
6/* ====================================================================
7 * Copyright (c) 2004-2011 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 * licensing@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#include "ssl_locl.h"
60#ifndef OPENSSL_NO_SRP
61
62#include <openssl/rand.h>
63#include <openssl/srp.h>
64#include <openssl/err.h>
65
66int
67SSL_CTX_SRP_CTX_free(struct ssl_ctx_st *ctx)
68{
69 if (ctx == NULL)
70 return 0;
71 free(ctx->srp_ctx.login);
72 BN_free(ctx->srp_ctx.N);
73 BN_free(ctx->srp_ctx.g);
74 BN_free(ctx->srp_ctx.s);
75 BN_free(ctx->srp_ctx.B);
76 BN_free(ctx->srp_ctx.A);
77 BN_free(ctx->srp_ctx.a);
78 BN_free(ctx->srp_ctx.b);
79 BN_free(ctx->srp_ctx.v);
80 ctx->srp_ctx.TLS_ext_srp_username_callback = NULL;
81 ctx->srp_ctx.SRP_cb_arg = NULL;
82 ctx->srp_ctx.SRP_verify_param_callback = NULL;
83 ctx->srp_ctx.SRP_give_srp_client_pwd_callback = NULL;
84 ctx->srp_ctx.N = NULL;
85 ctx->srp_ctx.g = NULL;
86 ctx->srp_ctx.s = NULL;
87 ctx->srp_ctx.B = NULL;
88 ctx->srp_ctx.A = NULL;
89 ctx->srp_ctx.a = NULL;
90 ctx->srp_ctx.b = NULL;
91 ctx->srp_ctx.v = NULL;
92 ctx->srp_ctx.login = NULL;
93 ctx->srp_ctx.info = NULL;
94 ctx->srp_ctx.strength = SRP_MINIMAL_N;
95 ctx->srp_ctx.srp_Mask = 0;
96 return (1);
97}
98
99int
100SSL_SRP_CTX_free(struct ssl_st *s)
101{
102 if (s == NULL)
103 return 0;
104 free(s->srp_ctx.login);
105 BN_free(s->srp_ctx.N);
106 BN_free(s->srp_ctx.g);
107 BN_free(s->srp_ctx.s);
108 BN_free(s->srp_ctx.B);
109 BN_free(s->srp_ctx.A);
110 BN_free(s->srp_ctx.a);
111 BN_free(s->srp_ctx.b);
112 BN_free(s->srp_ctx.v);
113 s->srp_ctx.TLS_ext_srp_username_callback = NULL;
114 s->srp_ctx.SRP_cb_arg = NULL;
115 s->srp_ctx.SRP_verify_param_callback = NULL;
116 s->srp_ctx.SRP_give_srp_client_pwd_callback = NULL;
117 s->srp_ctx.N = NULL;
118 s->srp_ctx.g = NULL;
119 s->srp_ctx.s = NULL;
120 s->srp_ctx.B = NULL;
121 s->srp_ctx.A = NULL;
122 s->srp_ctx.a = NULL;
123 s->srp_ctx.b = NULL;
124 s->srp_ctx.v = NULL;
125 s->srp_ctx.login = NULL;
126 s->srp_ctx.info = NULL;
127 s->srp_ctx.strength = SRP_MINIMAL_N;
128 s->srp_ctx.srp_Mask = 0;
129 return (1);
130}
131
132int
133SSL_SRP_CTX_init(struct ssl_st *s)
134{
135 SSL_CTX *ctx;
136
137 if ((s == NULL) || ((ctx = s->ctx) == NULL))
138 return 0;
139 s->srp_ctx.SRP_cb_arg = ctx->srp_ctx.SRP_cb_arg;
140 /* set client Hello login callback */
141 s->srp_ctx.TLS_ext_srp_username_callback = ctx->srp_ctx.TLS_ext_srp_username_callback;
142 /* set SRP N/g param callback for verification */
143 s->srp_ctx.SRP_verify_param_callback = ctx->srp_ctx.SRP_verify_param_callback;
144 /* set SRP client passwd callback */
145 s->srp_ctx.SRP_give_srp_client_pwd_callback = ctx->srp_ctx.SRP_give_srp_client_pwd_callback;
146
147 s->srp_ctx.N = NULL;
148 s->srp_ctx.g = NULL;
149 s->srp_ctx.s = NULL;
150 s->srp_ctx.B = NULL;
151 s->srp_ctx.A = NULL;
152 s->srp_ctx.a = NULL;
153 s->srp_ctx.b = NULL;
154 s->srp_ctx.v = NULL;
155 s->srp_ctx.login = NULL;
156 s->srp_ctx.info = ctx->srp_ctx.info;
157 s->srp_ctx.strength = ctx->srp_ctx.strength;
158
159 if (((ctx->srp_ctx.N != NULL) &&
160 ((s->srp_ctx.N = BN_dup(ctx->srp_ctx.N)) == NULL)) ||
161 ((ctx->srp_ctx.g != NULL) &&
162 ((s->srp_ctx.g = BN_dup(ctx->srp_ctx.g)) == NULL)) ||
163 ((ctx->srp_ctx.s != NULL) &&
164 ((s->srp_ctx.s = BN_dup(ctx->srp_ctx.s)) == NULL)) ||
165 ((ctx->srp_ctx.B != NULL) &&
166 ((s->srp_ctx.B = BN_dup(ctx->srp_ctx.B)) == NULL)) ||
167 ((ctx->srp_ctx.A != NULL) &&
168 ((s->srp_ctx.A = BN_dup(ctx->srp_ctx.A)) == NULL)) ||
169 ((ctx->srp_ctx.a != NULL) &&
170 ((s->srp_ctx.a = BN_dup(ctx->srp_ctx.a)) == NULL)) ||
171 ((ctx->srp_ctx.v != NULL) &&
172 ((s->srp_ctx.v = BN_dup(ctx->srp_ctx.v)) == NULL)) ||
173 ((ctx->srp_ctx.b != NULL) &&
174 ((s->srp_ctx.b = BN_dup(ctx->srp_ctx.b)) == NULL))) {
175 SSLerr(SSL_F_SSL_SRP_CTX_INIT, ERR_R_BN_LIB);
176 goto err;
177 }
178 if ((ctx->srp_ctx.login != NULL) &&
179 ((s->srp_ctx.login = BUF_strdup(ctx->srp_ctx.login)) == NULL)) {
180 SSLerr(SSL_F_SSL_SRP_CTX_INIT, ERR_R_INTERNAL_ERROR);
181 goto err;
182 }
183 s->srp_ctx.srp_Mask = ctx->srp_ctx.srp_Mask;
184
185 return (1);
186err:
187 free(s->srp_ctx.login);
188 BN_free(s->srp_ctx.N);
189 BN_free(s->srp_ctx.g);
190 BN_free(s->srp_ctx.s);
191 BN_free(s->srp_ctx.B);
192 BN_free(s->srp_ctx.A);
193 BN_free(s->srp_ctx.a);
194 BN_free(s->srp_ctx.b);
195 BN_free(s->srp_ctx.v);
196 return (0);
197}
198
199int
200SSL_CTX_SRP_CTX_init(struct ssl_ctx_st *ctx)
201{
202 if (ctx == NULL)
203 return 0;
204
205 ctx->srp_ctx.SRP_cb_arg = NULL;
206 /* set client Hello login callback */
207 ctx->srp_ctx.TLS_ext_srp_username_callback = NULL;
208 /* set SRP N/g param callback for verification */
209 ctx->srp_ctx.SRP_verify_param_callback = NULL;
210 /* set SRP client passwd callback */
211 ctx->srp_ctx.SRP_give_srp_client_pwd_callback = NULL;
212
213 ctx->srp_ctx.N = NULL;
214 ctx->srp_ctx.g = NULL;
215 ctx->srp_ctx.s = NULL;
216 ctx->srp_ctx.B = NULL;
217 ctx->srp_ctx.A = NULL;
218 ctx->srp_ctx.a = NULL;
219 ctx->srp_ctx.b = NULL;
220 ctx->srp_ctx.v = NULL;
221 ctx->srp_ctx.login = NULL;
222 ctx->srp_ctx.srp_Mask = 0;
223 ctx->srp_ctx.info = NULL;
224 ctx->srp_ctx.strength = SRP_MINIMAL_N;
225
226 return (1);
227}
228
229/* server side */
230int
231SSL_srp_server_param_with_username(SSL *s, int *ad)
232{
233 unsigned char b[SSL_MAX_MASTER_KEY_LENGTH];
234 int al;
235
236 *ad = SSL_AD_UNKNOWN_PSK_IDENTITY;
237 if ((s->srp_ctx.TLS_ext_srp_username_callback !=NULL) &&
238 ((al = s->srp_ctx.TLS_ext_srp_username_callback(s, ad,
239 s->srp_ctx.SRP_cb_arg)) != SSL_ERROR_NONE))
240 return al;
241
242 *ad = SSL_AD_INTERNAL_ERROR;
243 if ((s->srp_ctx.N == NULL) || (s->srp_ctx.g == NULL) ||
244 (s->srp_ctx.s == NULL) || (s->srp_ctx.v == NULL))
245 return SSL3_AL_FATAL;
246
247 if (RAND_bytes(b, sizeof(b)) <= 0)
248 return SSL3_AL_FATAL;
249 s->srp_ctx.b = BN_bin2bn(b, sizeof(b), NULL);
250 OPENSSL_cleanse(b, sizeof(b));
251
252 /* Calculate: B = (kv + g^b) % N */
253
254 return ((s->srp_ctx.B = SRP_Calc_B(s->srp_ctx.b, s->srp_ctx.N, s->srp_ctx.g, s->srp_ctx.v)) != NULL) ? SSL_ERROR_NONE : SSL3_AL_FATAL;
255}
256
257/* If the server just has the raw password, make up a verifier entry on the fly */
258int
259SSL_set_srp_server_param_pw(SSL *s, const char *user, const char *pass, const char *grp)
260{
261 SRP_gN *GN = SRP_get_default_gN(grp);
262 if (GN == NULL)
263 return -1;
264 s->srp_ctx.N = BN_dup(GN->N);
265 s->srp_ctx.g = BN_dup(GN->g);
266 if (s->srp_ctx.v != NULL) {
267 BN_clear_free(s->srp_ctx.v);
268 s->srp_ctx.v = NULL;
269 }
270 if (s->srp_ctx.s != NULL) {
271 BN_clear_free(s->srp_ctx.s);
272 s->srp_ctx.s = NULL;
273 }
274 if (!SRP_create_verifier_BN(user, pass, &s->srp_ctx.s, &s->srp_ctx.v,
275 GN->N, GN->g))
276 return -1;
277
278 return 1;
279}
280
281int
282SSL_set_srp_server_param(SSL *s, const BIGNUM *N, const BIGNUM *g,
283 BIGNUM *sa, BIGNUM *v, char *info)
284{
285 if (N != NULL) {
286 if (s->srp_ctx.N != NULL) {
287 if (!BN_copy(s->srp_ctx.N, N)) {
288 BN_free(s->srp_ctx.N);
289 s->srp_ctx.N = NULL;
290 }
291 } else
292 s->srp_ctx.N = BN_dup(N);
293 }
294 if (g != NULL) {
295 if (s->srp_ctx.g != NULL) {
296 if (!BN_copy(s->srp_ctx.g, g)) {
297 BN_free(s->srp_ctx.g);
298 s->srp_ctx.g = NULL;
299 }
300 } else
301 s->srp_ctx.g = BN_dup(g);
302 }
303 if (sa != NULL) {
304 if (s->srp_ctx.s != NULL) {
305 if (!BN_copy(s->srp_ctx.s, sa)) {
306 BN_free(s->srp_ctx.s);
307 s->srp_ctx.s = NULL;
308 }
309 } else
310 s->srp_ctx.s = BN_dup(sa);
311 }
312 if (v != NULL) {
313 if (s->srp_ctx.v != NULL) {
314 if (!BN_copy(s->srp_ctx.v, v)) {
315 BN_free(s->srp_ctx.v);
316 s->srp_ctx.v = NULL;
317 }
318 } else
319 s->srp_ctx.v = BN_dup(v);
320 }
321 s->srp_ctx.info = info;
322
323 if (!(s->srp_ctx.N) || !(s->srp_ctx.g) ||
324 !(s->srp_ctx.s) || !(s->srp_ctx.v))
325 return -1;
326
327 return 1;
328}
329
330int
331SRP_generate_server_master_secret(SSL *s, unsigned char *master_key)
332{
333 BIGNUM *K = NULL, *u = NULL;
334 int ret = -1, tmp_len;
335 unsigned char *tmp = NULL;
336
337 if (!SRP_Verify_A_mod_N(s->srp_ctx.A, s->srp_ctx.N))
338 goto err;
339 if (!(u = SRP_Calc_u(s->srp_ctx.A, s->srp_ctx.B, s->srp_ctx.N)))
340 goto err;
341 if (!(K = SRP_Calc_server_key(s->srp_ctx.A, s->srp_ctx.v, u, s->srp_ctx.b, s->srp_ctx.N)))
342 goto err;
343
344 tmp_len = BN_num_bytes(K);
345 if ((tmp = malloc(tmp_len)) == NULL)
346 goto err;
347 BN_bn2bin(K, tmp);
348 ret = s->method->ssl3_enc->generate_master_secret(s, master_key, tmp, tmp_len);
349err:
350 if (tmp) {
351 OPENSSL_cleanse(tmp, tmp_len);
352 free(tmp);
353 }
354 BN_clear_free(K);
355 BN_clear_free(u);
356 return ret;
357}
358
359/* client side */
360int
361SRP_generate_client_master_secret(SSL *s, unsigned char *master_key)
362{
363 BIGNUM *x = NULL, *u = NULL, *K = NULL;
364 int ret = -1, tmp_len;
365 char *passwd = NULL;
366 unsigned char *tmp = NULL;
367
368 /* Checks if b % n == 0
369 */
370 if (SRP_Verify_B_mod_N(s->srp_ctx.B, s->srp_ctx.N) == 0)
371 goto err;
372 if (!(u = SRP_Calc_u(s->srp_ctx.A, s->srp_ctx.B, s->srp_ctx.N)))
373 goto err;
374 if (s->srp_ctx.SRP_give_srp_client_pwd_callback == NULL)
375 goto err;
376 if (!(passwd = s->srp_ctx.SRP_give_srp_client_pwd_callback(s,
377 s->srp_ctx.SRP_cb_arg)))
378 goto err;
379 if (!(x = SRP_Calc_x(s->srp_ctx.s, s->srp_ctx.login, passwd)))
380 goto err;
381 if (!(K = SRP_Calc_client_key(s->srp_ctx.N, s->srp_ctx.B, s->srp_ctx.g,
382 x, s->srp_ctx.a, u)))
383 goto err;
384
385 tmp_len = BN_num_bytes(K);
386 if ((tmp = malloc(tmp_len)) == NULL)
387 goto err;
388 BN_bn2bin(K, tmp);
389 ret = s->method->ssl3_enc->generate_master_secret(s, master_key,
390 tmp, tmp_len);
391err:
392 if (tmp) {
393 OPENSSL_cleanse(tmp, tmp_len);
394 free(tmp);
395 }
396 BN_clear_free(K);
397 BN_clear_free(x);
398 if (passwd) {
399 OPENSSL_cleanse(passwd, strlen(passwd));
400 free(passwd);
401 }
402 BN_clear_free(u);
403 return ret;
404}
405
406int
407SRP_Calc_A_param(SSL *s)
408{
409 unsigned char rnd[SSL_MAX_MASTER_KEY_LENGTH];
410
411 if (BN_num_bits(s->srp_ctx.N) < s->srp_ctx.strength)
412 return -1;
413
414 if (s->srp_ctx.SRP_verify_param_callback ==NULL &&
415 !SRP_check_known_gN_param(s->srp_ctx.g, s->srp_ctx.N))
416 return -1;
417
418 RAND_bytes(rnd, sizeof(rnd));
419 s->srp_ctx.a = BN_bin2bn(rnd, sizeof(rnd), s->srp_ctx.a);
420 OPENSSL_cleanse(rnd, sizeof(rnd));
421
422 if (!(s->srp_ctx.A = SRP_Calc_A(s->srp_ctx.a, s->srp_ctx.N,
423 s->srp_ctx.g)))
424 return -1;
425
426 /* We can have a callback to verify SRP param!! */
427 if (s->srp_ctx.SRP_verify_param_callback !=NULL)
428 return s->srp_ctx.SRP_verify_param_callback(s,
429 s->srp_ctx.SRP_cb_arg);
430
431 return 1;
432}
433
434BIGNUM *
435SSL_get_srp_g(SSL *s)
436{
437 if (s->srp_ctx.g != NULL)
438 return s->srp_ctx.g;
439 return s->ctx->srp_ctx.g;
440}
441
442BIGNUM *
443SSL_get_srp_N(SSL *s)
444{
445 if (s->srp_ctx.N != NULL)
446 return s->srp_ctx.N;
447 return s->ctx->srp_ctx.N;
448}
449
450char *
451SSL_get_srp_username(SSL *s)
452{
453 if (s->srp_ctx.login != NULL)
454 return s->srp_ctx.login;
455 return s->ctx->srp_ctx.login;
456}
457
458char *
459SSL_get_srp_userinfo(SSL *s)
460{
461 if (s->srp_ctx.info != NULL)
462 return s->srp_ctx.info;
463 return s->ctx->srp_ctx.info;
464}
465
466#define tls1_ctx_ctrl ssl3_ctx_ctrl
467#define tls1_ctx_callback_ctrl ssl3_ctx_callback_ctrl
468
469int
470SSL_CTX_set_srp_username(SSL_CTX *ctx, char *name)
471{
472 return tls1_ctx_ctrl(ctx, SSL_CTRL_SET_TLS_EXT_SRP_USERNAME, 0, name);
473}
474
475int
476SSL_CTX_set_srp_password(SSL_CTX *ctx, char *password)
477{
478 return tls1_ctx_ctrl(ctx, SSL_CTRL_SET_TLS_EXT_SRP_PASSWORD, 0, password);
479}
480
481int
482SSL_CTX_set_srp_strength(SSL_CTX *ctx, int strength)
483{
484 return tls1_ctx_ctrl(ctx, SSL_CTRL_SET_TLS_EXT_SRP_STRENGTH, strength,
485 NULL);
486}
487
488int
489SSL_CTX_set_srp_verify_param_callback(SSL_CTX *ctx, int (*cb)(SSL *, void *))
490{
491 return tls1_ctx_callback_ctrl(ctx, SSL_CTRL_SET_SRP_VERIFY_PARAM_CB,
492 (void (*)(void))cb);
493}
494
495int
496SSL_CTX_set_srp_cb_arg(SSL_CTX *ctx, void *arg)
497{
498 return tls1_ctx_ctrl(ctx, SSL_CTRL_SET_SRP_ARG, 0, arg);
499}
500
501int
502SSL_CTX_set_srp_username_callback(SSL_CTX *ctx,
503 int (*cb)(SSL *, int *, void *))
504{
505 return tls1_ctx_callback_ctrl(ctx, SSL_CTRL_SET_TLS_EXT_SRP_USERNAME_CB,
506 (void (*)(void))cb);
507}
508
509int
510SSL_CTX_set_srp_client_pwd_callback(SSL_CTX *ctx, char *(*cb)(SSL *, void *))
511{
512 return tls1_ctx_callback_ctrl(ctx, SSL_CTRL_SET_SRP_GIVE_CLIENT_PWD_CB,
513 (void (*)(void))cb);
514}
515
516#endif
diff --git a/src/lib/libssl/ssl.h b/src/lib/libssl/ssl.h
index 0e117dbca4..dc56abaa99 100644
--- a/src/lib/libssl/ssl.h
+++ b/src/lib/libssl/ssl.h
@@ -466,10 +466,6 @@ struct ssl_session_st {
466 unsigned int sid_ctx_length; 466 unsigned int sid_ctx_length;
467 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH]; 467 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
468 468
469#ifndef OPENSSL_NO_KRB5
470 unsigned int krb5_client_princ_len;
471 unsigned char krb5_client_princ[SSL_MAX_KRB5_PRINCIPAL_LENGTH];
472#endif /* OPENSSL_NO_KRB5 */
473#ifndef OPENSSL_NO_PSK 469#ifndef OPENSSL_NO_PSK
474 char *psk_identity_hint; 470 char *psk_identity_hint;
475 char *psk_identity; 471 char *psk_identity;
@@ -522,9 +518,6 @@ struct ssl_session_st {
522 size_t tlsext_ticklen; /* Session ticket length */ 518 size_t tlsext_ticklen; /* Session ticket length */
523 long tlsext_tick_lifetime_hint; /* Session lifetime hint in seconds */ 519 long tlsext_tick_lifetime_hint; /* Session lifetime hint in seconds */
524#endif 520#endif
525#ifndef OPENSSL_NO_SRP
526 char *srp_username;
527#endif
528}; 521};
529 522
530#endif 523#endif
@@ -672,42 +665,6 @@ void SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version,
672#define SSL_CTX_set_msg_callback_arg(ctx, arg) SSL_CTX_ctrl((ctx), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg)) 665#define SSL_CTX_set_msg_callback_arg(ctx, arg) SSL_CTX_ctrl((ctx), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg))
673#define SSL_set_msg_callback_arg(ssl, arg) SSL_ctrl((ssl), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg)) 666#define SSL_set_msg_callback_arg(ssl, arg) SSL_ctrl((ssl), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg))
674 667
675#ifndef OPENSSL_NO_SRP
676
677#ifndef OPENSSL_NO_SSL_INTERN
678
679typedef struct srp_ctx_st {
680 /* param for all the callbacks */
681 void *SRP_cb_arg;
682 /* set client Hello login callback */
683 int (*TLS_ext_srp_username_callback)(SSL *, int *, void *);
684 /* set SRP N/g param callback for verification */
685 int (*SRP_verify_param_callback)(SSL *, void *);
686 /* set SRP client passwd callback */
687 char *(*SRP_give_srp_client_pwd_callback)(SSL *, void *);
688
689 char *login;
690 BIGNUM *N, *g, *s, *B, *A;
691 BIGNUM *a, *b, *v;
692 char *info;
693 int strength;
694
695 unsigned long srp_Mask;
696} SRP_CTX;
697
698#endif
699
700/* see tls_srp.c */
701int SSL_SRP_CTX_init(SSL *s);
702int SSL_CTX_SRP_CTX_init(SSL_CTX *ctx);
703int SSL_SRP_CTX_free(SSL *ctx);
704int SSL_CTX_SRP_CTX_free(SSL_CTX *ctx);
705int SSL_srp_server_param_with_username(SSL *s, int *ad);
706int SRP_generate_server_master_secret(SSL *s, unsigned char *master_key);
707int SRP_Calc_A_param(SSL *s);
708int SRP_generate_client_master_secret(SSL *s, unsigned char *master_key);
709
710#endif
711 668
712#define SSL_MAX_CERT_LIST_DEFAULT 1024*100 /* 100k max cert list :-) */ 669#define SSL_MAX_CERT_LIST_DEFAULT 1024*100 /* 100k max cert list :-) */
713 670
@@ -922,9 +879,6 @@ struct ssl_ctx_st {
922 unsigned char *psk, unsigned int max_psk_len); 879 unsigned char *psk, unsigned int max_psk_len);
923#endif 880#endif
924 881
925#ifndef OPENSSL_NO_SRP
926 SRP_CTX srp_ctx; /* ctx for SRP authentication */
927#endif
928 882
929#ifndef OPENSSL_NO_TLSEXT 883#ifndef OPENSSL_NO_TLSEXT
930 884
@@ -1213,9 +1167,6 @@ struct ssl_st {
1213 int error; /* error bytes to be written */ 1167 int error; /* error bytes to be written */
1214 int error_code; /* actual code */ 1168 int error_code; /* actual code */
1215 1169
1216#ifndef OPENSSL_NO_KRB5
1217 KSSL_CTX *kssl_ctx; /* Kerberos 5 context */
1218#endif /* OPENSSL_NO_KRB5 */
1219 1170
1220#ifndef OPENSSL_NO_PSK 1171#ifndef OPENSSL_NO_PSK
1221 unsigned int (*psk_client_callback)(SSL *ssl, const char *hint, 1172 unsigned int (*psk_client_callback)(SSL *ssl, const char *hint,
@@ -1327,9 +1278,6 @@ struct ssl_st {
1327 * 2 if we are a server and are inside a handshake 1278 * 2 if we are a server and are inside a handshake
1328 * (i.e. not just sending a HelloRequest) */ 1279 * (i.e. not just sending a HelloRequest) */
1329 1280
1330#ifndef OPENSSL_NO_SRP
1331 SRP_CTX srp_ctx; /* ctx for SRP authentication */
1332#endif
1333}; 1281};
1334 1282
1335#endif 1283#endif
@@ -1771,24 +1719,6 @@ int SSL_set_trust(SSL *s, int trust);
1771int SSL_CTX_set1_param(SSL_CTX *ctx, X509_VERIFY_PARAM *vpm); 1719int SSL_CTX_set1_param(SSL_CTX *ctx, X509_VERIFY_PARAM *vpm);
1772int SSL_set1_param(SSL *ssl, X509_VERIFY_PARAM *vpm); 1720int SSL_set1_param(SSL *ssl, X509_VERIFY_PARAM *vpm);
1773 1721
1774#ifndef OPENSSL_NO_SRP
1775int SSL_CTX_set_srp_username(SSL_CTX *ctx, char *name);
1776int SSL_CTX_set_srp_password(SSL_CTX *ctx, char *password);
1777int SSL_CTX_set_srp_strength(SSL_CTX *ctx, int strength);
1778int SSL_CTX_set_srp_client_pwd_callback(SSL_CTX *ctx, char *(*cb)(SSL *, void *));
1779int SSL_CTX_set_srp_verify_param_callback(SSL_CTX *ctx, int (*cb)(SSL *, void *));
1780int SSL_CTX_set_srp_username_callback(SSL_CTX *ctx, int (*cb)(SSL *, int *, void *));
1781int SSL_CTX_set_srp_cb_arg(SSL_CTX *ctx, void *arg);
1782
1783int SSL_set_srp_server_param(SSL *s, const BIGNUM *N, const BIGNUM *g, BIGNUM *sa, BIGNUM *v, char *info);
1784int SSL_set_srp_server_param_pw(SSL *s, const char *user, const char *pass, const char *grp);
1785
1786BIGNUM *SSL_get_srp_g(SSL *s);
1787BIGNUM *SSL_get_srp_N(SSL *s);
1788
1789char *SSL_get_srp_username(SSL *s);
1790char *SSL_get_srp_userinfo(SSL *s);
1791#endif
1792 1722
1793void SSL_free(SSL *ssl); 1723void SSL_free(SSL *ssl);
1794int SSL_accept(SSL *ssl); 1724int SSL_accept(SSL *ssl);
diff --git a/src/lib/libssl/ssl/Makefile b/src/lib/libssl/ssl/Makefile
index 64dd10bb6d..737121fce4 100644
--- a/src/lib/libssl/ssl/Makefile
+++ b/src/lib/libssl/ssl/Makefile
@@ -1,4 +1,4 @@
1# $OpenBSD: Makefile,v 1.40 2014/04/23 05:13:57 beck Exp $ 1# $OpenBSD: Makefile,v 1.41 2014/05/05 15:03:22 tedu Exp $
2 2
3LIB= ssl 3LIB= ssl
4 4
@@ -19,7 +19,7 @@ SRCS=\
19 ssl_lib.c ssl_err2.c ssl_cert.c ssl_sess.c \ 19 ssl_lib.c ssl_err2.c ssl_cert.c ssl_sess.c \
20 ssl_ciph.c ssl_stat.c ssl_rsa.c \ 20 ssl_ciph.c ssl_stat.c ssl_rsa.c \
21 ssl_asn1.c ssl_txt.c ssl_algs.c \ 21 ssl_asn1.c ssl_txt.c ssl_algs.c \
22 bio_ssl.c ssl_err.c kssl.c tls_srp.c t1_reneg.c 22 bio_ssl.c ssl_err.c t1_reneg.c
23SRCS+= s3_cbc.c 23SRCS+= s3_cbc.c
24 24
25HDRS= srtp.h ssl.h ssl2.h ssl3.h ssl23.h tls1.h dtls1.h kssl.h 25HDRS= srtp.h ssl.h ssl2.h ssl3.h ssl23.h tls1.h dtls1.h kssl.h
diff --git a/src/lib/libssl/ssl_asn1.c b/src/lib/libssl/ssl_asn1.c
index 1d2590268c..566590f171 100644
--- a/src/lib/libssl/ssl_asn1.c
+++ b/src/lib/libssl/ssl_asn1.c
@@ -97,9 +97,6 @@ typedef struct ssl_session_asn1_st {
97 ASN1_OCTET_STRING master_key; 97 ASN1_OCTET_STRING master_key;
98 ASN1_OCTET_STRING session_id; 98 ASN1_OCTET_STRING session_id;
99 ASN1_OCTET_STRING session_id_context; 99 ASN1_OCTET_STRING session_id_context;
100#ifndef OPENSSL_NO_KRB5
101 ASN1_OCTET_STRING krb5_princ;
102#endif /* OPENSSL_NO_KRB5 */
103 ASN1_INTEGER time; 100 ASN1_INTEGER time;
104 ASN1_INTEGER timeout; 101 ASN1_INTEGER timeout;
105 ASN1_INTEGER verify_result; 102 ASN1_INTEGER verify_result;
@@ -112,9 +109,6 @@ typedef struct ssl_session_asn1_st {
112 ASN1_OCTET_STRING psk_identity_hint; 109 ASN1_OCTET_STRING psk_identity_hint;
113 ASN1_OCTET_STRING psk_identity; 110 ASN1_OCTET_STRING psk_identity;
114#endif /* OPENSSL_NO_PSK */ 111#endif /* OPENSSL_NO_PSK */
115#ifndef OPENSSL_NO_SRP
116 ASN1_OCTET_STRING srp_username;
117#endif /* OPENSSL_NO_SRP */
118} SSL_SESSION_ASN1; 112} SSL_SESSION_ASN1;
119 113
120int 114int
@@ -132,9 +126,6 @@ i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
132 unsigned char cbuf; 126 unsigned char cbuf;
133 int v11 = 0; 127 int v11 = 0;
134#endif 128#endif
135#ifndef OPENSSL_NO_SRP
136 int v12 = 0;
137#endif
138 long l; 129 long l;
139 SSL_SESSION_ASN1 a; 130 SSL_SESSION_ASN1 a;
140 M_ASN1_I2D_vars(in); 131 M_ASN1_I2D_vars(in);
@@ -189,13 +180,6 @@ i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
189 a.session_id_context.type = V_ASN1_OCTET_STRING; 180 a.session_id_context.type = V_ASN1_OCTET_STRING;
190 a.session_id_context.data = in->sid_ctx; 181 a.session_id_context.data = in->sid_ctx;
191 182
192#ifndef OPENSSL_NO_KRB5
193 if (in->krb5_client_princ_len) {
194 a.krb5_princ.length = in->krb5_client_princ_len;
195 a.krb5_princ.type = V_ASN1_OCTET_STRING;
196 a.krb5_princ.data = in->krb5_client_princ;
197 }
198#endif /* OPENSSL_NO_KRB5 */
199 183
200 if (in->time != 0L) { 184 if (in->time != 0L) {
201 a.time.length = LSIZE2; 185 a.time.length = LSIZE2;
@@ -248,23 +232,12 @@ i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
248 a.psk_identity.data = (unsigned char *)(in->psk_identity); 232 a.psk_identity.data = (unsigned char *)(in->psk_identity);
249 } 233 }
250#endif /* OPENSSL_NO_PSK */ 234#endif /* OPENSSL_NO_PSK */
251#ifndef OPENSSL_NO_SRP
252 if (in->srp_username) {
253 a.srp_username.length = strlen(in->srp_username);
254 a.srp_username.type = V_ASN1_OCTET_STRING;
255 a.srp_username.data = (unsigned char *)(in->srp_username);
256 }
257#endif /* OPENSSL_NO_SRP */
258 235
259 M_ASN1_I2D_len(&(a.version), i2d_ASN1_INTEGER); 236 M_ASN1_I2D_len(&(a.version), i2d_ASN1_INTEGER);
260 M_ASN1_I2D_len(&(a.ssl_version), i2d_ASN1_INTEGER); 237 M_ASN1_I2D_len(&(a.ssl_version), i2d_ASN1_INTEGER);
261 M_ASN1_I2D_len(&(a.cipher), i2d_ASN1_OCTET_STRING); 238 M_ASN1_I2D_len(&(a.cipher), i2d_ASN1_OCTET_STRING);
262 M_ASN1_I2D_len(&(a.session_id), i2d_ASN1_OCTET_STRING); 239 M_ASN1_I2D_len(&(a.session_id), i2d_ASN1_OCTET_STRING);
263 M_ASN1_I2D_len(&(a.master_key), i2d_ASN1_OCTET_STRING); 240 M_ASN1_I2D_len(&(a.master_key), i2d_ASN1_OCTET_STRING);
264#ifndef OPENSSL_NO_KRB5
265 if (in->krb5_client_princ_len)
266 M_ASN1_I2D_len(&(a.krb5_princ), i2d_ASN1_OCTET_STRING);
267#endif /* OPENSSL_NO_KRB5 */
268 if (in->time != 0L) 241 if (in->time != 0L)
269 M_ASN1_I2D_len_EXP_opt(&(a.time), i2d_ASN1_INTEGER, 1, v1); 242 M_ASN1_I2D_len_EXP_opt(&(a.time), i2d_ASN1_INTEGER, 1, v1);
270 if (in->timeout != 0L) 243 if (in->timeout != 0L)
@@ -293,10 +266,6 @@ i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
293 if (in->psk_identity) 266 if (in->psk_identity)
294 M_ASN1_I2D_len_EXP_opt(&(a.psk_identity), i2d_ASN1_OCTET_STRING, 8, v8); 267 M_ASN1_I2D_len_EXP_opt(&(a.psk_identity), i2d_ASN1_OCTET_STRING, 8, v8);
295#endif /* OPENSSL_NO_PSK */ 268#endif /* OPENSSL_NO_PSK */
296#ifndef OPENSSL_NO_SRP
297 if (in->srp_username)
298 M_ASN1_I2D_len_EXP_opt(&(a.srp_username), i2d_ASN1_OCTET_STRING, 12, v12);
299#endif /* OPENSSL_NO_SRP */
300 269
301 M_ASN1_I2D_seq_total(); 270 M_ASN1_I2D_seq_total();
302 271
@@ -305,10 +274,6 @@ i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
305 M_ASN1_I2D_put(&(a.cipher), i2d_ASN1_OCTET_STRING); 274 M_ASN1_I2D_put(&(a.cipher), i2d_ASN1_OCTET_STRING);
306 M_ASN1_I2D_put(&(a.session_id), i2d_ASN1_OCTET_STRING); 275 M_ASN1_I2D_put(&(a.session_id), i2d_ASN1_OCTET_STRING);
307 M_ASN1_I2D_put(&(a.master_key), i2d_ASN1_OCTET_STRING); 276 M_ASN1_I2D_put(&(a.master_key), i2d_ASN1_OCTET_STRING);
308#ifndef OPENSSL_NO_KRB5
309 if (in->krb5_client_princ_len)
310 M_ASN1_I2D_put(&(a.krb5_princ), i2d_ASN1_OCTET_STRING);
311#endif /* OPENSSL_NO_KRB5 */
312 if (in->time != 0L) 277 if (in->time != 0L)
313 M_ASN1_I2D_put_EXP_opt(&(a.time), i2d_ASN1_INTEGER, 1, v1); 278 M_ASN1_I2D_put_EXP_opt(&(a.time), i2d_ASN1_INTEGER, 1, v1);
314 if (in->timeout != 0L) 279 if (in->timeout != 0L)
@@ -339,10 +304,6 @@ i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
339 if (in->compress_meth) 304 if (in->compress_meth)
340 M_ASN1_I2D_put_EXP_opt(&(a.comp_id), i2d_ASN1_OCTET_STRING, 11, v11); 305 M_ASN1_I2D_put_EXP_opt(&(a.comp_id), i2d_ASN1_OCTET_STRING, 11, v11);
341#endif 306#endif
342#ifndef OPENSSL_NO_SRP
343 if (in->srp_username)
344 M_ASN1_I2D_put_EXP_opt(&(a.srp_username), i2d_ASN1_OCTET_STRING, 12, v12);
345#endif /* OPENSSL_NO_SRP */
346 M_ASN1_I2D_finish(); 307 M_ASN1_I2D_finish();
347} 308}
348 309
@@ -420,21 +381,6 @@ d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp, long length)
420 381
421 os.length = 0; 382 os.length = 0;
422 383
423#ifndef OPENSSL_NO_KRB5
424 os.length = 0;
425 M_ASN1_D2I_get_opt(osp, d2i_ASN1_OCTET_STRING, V_ASN1_OCTET_STRING);
426 if (os.data) {
427 if (os.length > SSL_MAX_KRB5_PRINCIPAL_LENGTH)
428 ret->krb5_client_princ_len = 0;
429 else
430 ret->krb5_client_princ_len = os.length;
431 memcpy(ret->krb5_client_princ, os.data, ret->krb5_client_princ_len);
432 free(os.data);
433 os.data = NULL;
434 os.length = 0;
435 } else
436 ret->krb5_client_princ_len = 0;
437#endif /* OPENSSL_NO_KRB5 */
438 384
439 ai.length = 0; 385 ai.length = 0;
440 M_ASN1_D2I_get_EXP_opt(aip, d2i_ASN1_INTEGER, 1); /* XXX 2038 */ 386 M_ASN1_D2I_get_EXP_opt(aip, d2i_ASN1_INTEGER, 1); /* XXX 2038 */
@@ -561,18 +507,6 @@ d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp, long length)
561 } 507 }
562#endif 508#endif
563 509
564#ifndef OPENSSL_NO_SRP
565 os.length = 0;
566 os.data = NULL;
567 M_ASN1_D2I_get_EXP_opt(osp, d2i_ASN1_OCTET_STRING, 12);
568 if (os.data) {
569 ret->srp_username = BUF_strndup((char *)os.data, os.length);
570 free(os.data);
571 os.data = NULL;
572 os.length = 0;
573 } else
574 ret->srp_username = NULL;
575#endif /* OPENSSL_NO_SRP */
576 510
577 M_ASN1_D2I_Finish(a, SSL_SESSION_free, SSL_F_D2I_SSL_SESSION); 511 M_ASN1_D2I_Finish(a, SSL_SESSION_free, SSL_F_D2I_SSL_SESSION);
578} 512}
diff --git a/src/lib/libssl/ssl_ciph.c b/src/lib/libssl/ssl_ciph.c
index 00ab752de1..a1523524a1 100644
--- a/src/lib/libssl/ssl_ciph.c
+++ b/src/lib/libssl/ssl_ciph.c
@@ -702,10 +702,8 @@ ssl_cipher_get_disabled(unsigned long *mkey, unsigned long *auth, unsigned long
702 *mkey |= SSL_kDHr|SSL_kDHd|SSL_kEDH; 702 *mkey |= SSL_kDHr|SSL_kDHd|SSL_kEDH;
703 *auth |= SSL_aDH; 703 *auth |= SSL_aDH;
704#endif 704#endif
705#ifdef OPENSSL_NO_KRB5
706 *mkey |= SSL_kKRB5; 705 *mkey |= SSL_kKRB5;
707 *auth |= SSL_aKRB5; 706 *auth |= SSL_aKRB5;
708#endif
709#ifdef OPENSSL_NO_ECDSA 707#ifdef OPENSSL_NO_ECDSA
710 *auth |= SSL_aECDSA; 708 *auth |= SSL_aECDSA;
711#endif 709#endif
@@ -717,9 +715,7 @@ ssl_cipher_get_disabled(unsigned long *mkey, unsigned long *auth, unsigned long
717 *mkey |= SSL_kPSK; 715 *mkey |= SSL_kPSK;
718 *auth |= SSL_aPSK; 716 *auth |= SSL_aPSK;
719#endif 717#endif
720#ifdef OPENSSL_NO_SRP
721 *mkey |= SSL_kSRP; 718 *mkey |= SSL_kSRP;
722#endif
723 /* Check for presence of GOST 34.10 algorithms, and if they 719 /* Check for presence of GOST 34.10 algorithms, and if they
724 * do not present, disable appropriate auth and key exchange */ 720 * do not present, disable appropriate auth and key exchange */
725 if (!get_optional_pkey_id("gost94")) { 721 if (!get_optional_pkey_id("gost94")) {
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c
index 195271a554..d046480feb 100644
--- a/src/lib/libssl/ssl_lib.c
+++ b/src/lib/libssl/ssl_lib.c
@@ -284,9 +284,6 @@ SSL_new(SSL_CTX *ctx)
284 if (s == NULL) 284 if (s == NULL)
285 goto err; 285 goto err;
286 286
287#ifndef OPENSSL_NO_KRB5
288 s->kssl_ctx = kssl_ctx_new();
289#endif /* OPENSSL_NO_KRB5 */
290 287
291 s->options = ctx->options; 288 s->options = ctx->options;
292 s->mode = ctx->mode; 289 s->mode = ctx->mode;
@@ -580,10 +577,6 @@ SSL_free(SSL *s)
580 if (s->ctx) 577 if (s->ctx)
581 SSL_CTX_free(s->ctx); 578 SSL_CTX_free(s->ctx);
582 579
583#ifndef OPENSSL_NO_KRB5
584 if (s->kssl_ctx != NULL)
585 kssl_ctx_free(s->kssl_ctx);
586#endif /* OPENSSL_NO_KRB5 */
587 580
588#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG) 581#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
589 if (s->next_proto_negotiated) 582 if (s->next_proto_negotiated)
@@ -1415,9 +1408,6 @@ ssl_cipher_list_to_bytes(SSL *s, STACK_OF(SSL_CIPHER) *sk, unsigned char *p,
1415 int i, j = 0; 1408 int i, j = 0;
1416 SSL_CIPHER *c; 1409 SSL_CIPHER *c;
1417 unsigned char *q; 1410 unsigned char *q;
1418#ifndef OPENSSL_NO_KRB5
1419 int nokrb5 = !kssl_tgt_is_available(s->kssl_ctx);
1420#endif /* OPENSSL_NO_KRB5 */
1421 1411
1422 if (sk == NULL) 1412 if (sk == NULL)
1423 return (0); 1413 return (0);
@@ -1429,11 +1419,6 @@ ssl_cipher_list_to_bytes(SSL *s, STACK_OF(SSL_CIPHER) *sk, unsigned char *p,
1429 if ((c->algorithm_ssl & SSL_TLSV1_2) && 1419 if ((c->algorithm_ssl & SSL_TLSV1_2) &&
1430 (TLS1_get_client_version(s) < TLS1_2_VERSION)) 1420 (TLS1_get_client_version(s) < TLS1_2_VERSION))
1431 continue; 1421 continue;
1432#ifndef OPENSSL_NO_KRB5
1433 if (((c->algorithm_mkey & SSL_kKRB5) ||
1434 (c->algorithm_auth & SSL_aKRB5)) && nokrb5)
1435 continue;
1436#endif /* OPENSSL_NO_KRB5 */
1437#ifndef OPENSSL_NO_PSK 1422#ifndef OPENSSL_NO_PSK
1438 /* with PSK there must be client callback set */ 1423 /* with PSK there must be client callback set */
1439 if (((c->algorithm_mkey & SSL_kPSK) || 1424 if (((c->algorithm_mkey & SSL_kPSK) ||
@@ -1877,9 +1862,6 @@ SSL_CTX_new(const SSL_METHOD *meth)
1877 ret->psk_client_callback = NULL; 1862 ret->psk_client_callback = NULL;
1878 ret->psk_server_callback = NULL; 1863 ret->psk_server_callback = NULL;
1879#endif 1864#endif
1880#ifndef OPENSSL_NO_SRP
1881 SSL_CTX_SRP_CTX_init(ret);
1882#endif
1883#ifndef OPENSSL_NO_ENGINE 1865#ifndef OPENSSL_NO_ENGINE
1884 ret->client_cert_engine = NULL; 1866 ret->client_cert_engine = NULL;
1885#ifdef OPENSSL_SSL_CLIENT_ENGINE_AUTO 1867#ifdef OPENSSL_SSL_CLIENT_ENGINE_AUTO
@@ -1983,9 +1965,6 @@ SSL_CTX_free(SSL_CTX *a)
1983 if (a->psk_identity_hint) 1965 if (a->psk_identity_hint)
1984 free(a->psk_identity_hint); 1966 free(a->psk_identity_hint);
1985#endif 1967#endif
1986#ifndef OPENSSL_NO_SRP
1987 SSL_CTX_SRP_CTX_free(a);
1988#endif
1989#ifndef OPENSSL_NO_ENGINE 1968#ifndef OPENSSL_NO_ENGINE
1990 if (a->client_cert_engine) 1969 if (a->client_cert_engine)
1991 ENGINE_finish(a->client_cert_engine); 1970 ENGINE_finish(a->client_cert_engine);
@@ -2147,12 +2126,6 @@ ssl_set_cert_masks(CERT *c, const SSL_CIPHER *cipher)
2147 mask_a|=SSL_aNULL; 2126 mask_a|=SSL_aNULL;
2148 emask_a|=SSL_aNULL; 2127 emask_a|=SSL_aNULL;
2149 2128
2150#ifndef OPENSSL_NO_KRB5
2151 mask_k|=SSL_kKRB5;
2152 mask_a|=SSL_aKRB5;
2153 emask_k|=SSL_kKRB5;
2154 emask_a|=SSL_aKRB5;
2155#endif
2156 2129
2157 /* 2130 /*
2158 * An ECC certificate may be usable for ECDH and/or 2131 * An ECC certificate may be usable for ECDH and/or
diff --git a/src/lib/libssl/ssl_sess.c b/src/lib/libssl/ssl_sess.c
index 2b8da1ccae..05c6948efc 100644
--- a/src/lib/libssl/ssl_sess.c
+++ b/src/lib/libssl/ssl_sess.c
@@ -223,9 +223,6 @@ SSL_SESSION_new(void)
223 ss->psk_identity_hint = NULL; 223 ss->psk_identity_hint = NULL;
224 ss->psk_identity = NULL; 224 ss->psk_identity = NULL;
225#endif 225#endif
226#ifndef OPENSSL_NO_SRP
227 ss->srp_username = NULL;
228#endif
229 return (ss); 226 return (ss);
230} 227}
231 228
@@ -726,10 +723,6 @@ SSL_SESSION_free(SSL_SESSION *ss)
726 if (ss->psk_identity != NULL) 723 if (ss->psk_identity != NULL)
727 free(ss->psk_identity); 724 free(ss->psk_identity);
728#endif 725#endif
729#ifndef OPENSSL_NO_SRP
730 if (ss->srp_username != NULL)
731 free(ss->srp_username);
732#endif
733 OPENSSL_cleanse(ss, sizeof(*ss)); 726 OPENSSL_cleanse(ss, sizeof(*ss));
734 free(ss); 727 free(ss);
735} 728}
@@ -754,15 +747,6 @@ SSL_set_session(SSL *s, SSL_SESSION *session)
754 return (0); 747 return (0);
755 } 748 }
756 749
757#ifndef OPENSSL_NO_KRB5
758 if (s->kssl_ctx && !s->kssl_ctx->client_princ &&
759 session->krb5_client_princ_len > 0) {
760 s->kssl_ctx->client_princ = malloc(session->krb5_client_princ_len + 1);
761 memcpy(s->kssl_ctx->client_princ, session->krb5_client_princ,
762 session->krb5_client_princ_len);
763 s->kssl_ctx->client_princ[session->krb5_client_princ_len] = '\0';
764 }
765#endif /* OPENSSL_NO_KRB5 */
766 750
767 /* CRYPTO_w_lock(CRYPTO_LOCK_SSL);*/ 751 /* CRYPTO_w_lock(CRYPTO_LOCK_SSL);*/
768 CRYPTO_add(&session->references, 1, CRYPTO_LOCK_SSL_SESSION); 752 CRYPTO_add(&session->references, 1, CRYPTO_LOCK_SSL_SESSION);
diff --git a/src/lib/libssl/ssl_txt.c b/src/lib/libssl/ssl_txt.c
index c6bfd68de6..01dd846596 100644
--- a/src/lib/libssl/ssl_txt.c
+++ b/src/lib/libssl/ssl_txt.c
@@ -161,19 +161,6 @@ SSL_SESSION_print(BIO *bp, const SSL_SESSION *x)
161 if (BIO_printf(bp, "%02X", x->master_key[i]) <= 0) 161 if (BIO_printf(bp, "%02X", x->master_key[i]) <= 0)
162 goto err; 162 goto err;
163 } 163 }
164#ifndef OPENSSL_NO_KRB5
165 if (BIO_puts(bp, "\n Krb5 Principal: ") <= 0)
166 goto err;
167 if (x->krb5_client_princ_len == 0) {
168 if (BIO_puts(bp, "None") <= 0)
169 goto err;
170 } else {
171 for (i = 0; i < x->krb5_client_princ_len; i++) {
172 if (BIO_printf(bp, "%02X", x->krb5_client_princ[i]) <= 0)
173 goto err;
174 }
175 }
176#endif /* OPENSSL_NO_KRB5 */
177#ifndef OPENSSL_NO_PSK 164#ifndef OPENSSL_NO_PSK
178 if (BIO_puts(bp, "\n PSK identity: ") <= 0) 165 if (BIO_puts(bp, "\n PSK identity: ") <= 0)
179 goto err; 166 goto err;
@@ -184,12 +171,6 @@ SSL_SESSION_print(BIO *bp, const SSL_SESSION *x)
184 if (BIO_printf(bp, "%s", x->psk_identity_hint ? x->psk_identity_hint : "None") <= 0) 171 if (BIO_printf(bp, "%s", x->psk_identity_hint ? x->psk_identity_hint : "None") <= 0)
185 goto err; 172 goto err;
186#endif 173#endif
187#ifndef OPENSSL_NO_SRP
188 if (BIO_puts(bp, "\n SRP username: ") <= 0)
189 goto err;
190 if (BIO_printf(bp, "%s", x->srp_username ? x->srp_username : "None") <= 0)
191 goto err;
192#endif
193#ifndef OPENSSL_NO_TLSEXT 174#ifndef OPENSSL_NO_TLSEXT
194 if (x->tlsext_tick_lifetime_hint) { 175 if (x->tlsext_tick_lifetime_hint) {
195 if (BIO_printf(bp, 176 if (BIO_printf(bp,
diff --git a/src/lib/libssl/t1_lib.c b/src/lib/libssl/t1_lib.c
index bb33331862..2e183bb233 100644
--- a/src/lib/libssl/t1_lib.c
+++ b/src/lib/libssl/t1_lib.c
@@ -415,35 +415,6 @@ ssl_add_clienthello_tlsext(SSL *s, unsigned char *p, unsigned char *limit)
415 ret += el; 415 ret += el;
416 } 416 }
417 417
418#ifndef OPENSSL_NO_SRP
419 /* Add SRP username if there is one */
420 if (s->srp_ctx.login != NULL) {
421 /* Add TLS extension SRP username to the Client Hello message */
422
423 int login_len = strlen(s->srp_ctx.login);
424
425 if (login_len > 255 || login_len == 0) {
426 SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);
427 return NULL;
428 }
429
430 /* check for enough space.
431 4 for the srp type type and entension length
432 1 for the srp user identity
433 + srp user identity length
434 */
435 if ((limit - ret - 5 - login_len) < 0)
436 return NULL;
437
438
439 /* fill in the extension */
440 s2n(TLSEXT_TYPE_srp, ret);
441 s2n(login_len + 1, ret);
442 (*ret++) = (unsigned char) login_len;
443 memcpy(ret, s->srp_ctx.login, login_len);
444 ret += login_len;
445 }
446#endif
447 418
448#ifndef OPENSSL_NO_EC 419#ifndef OPENSSL_NO_EC
449 if (s->tlsext_ecpointformatlist != NULL && 420 if (s->tlsext_ecpointformatlist != NULL &&
@@ -1063,27 +1034,6 @@ ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d,
1063 } 1034 }
1064 1035
1065 } 1036 }
1066#ifndef OPENSSL_NO_SRP
1067 else if (type == TLSEXT_TYPE_srp) {
1068 if (size <= 0 || ((len = data[0])) != (size - 1)) {
1069 *al = SSL_AD_DECODE_ERROR;
1070 return 0;
1071 }
1072 if (s->srp_ctx.login != NULL) {
1073 *al = SSL_AD_DECODE_ERROR;
1074 return 0;
1075 }
1076 if ((s->srp_ctx.login = malloc(len + 1)) == NULL)
1077 return -1;
1078 memcpy(s->srp_ctx.login, &data[1], len);
1079 s->srp_ctx.login[len] = '\0';
1080
1081 if (strlen(s->srp_ctx.login) != len) {
1082 *al = SSL_AD_DECODE_ERROR;
1083 return 0;
1084 }
1085 }
1086#endif
1087 1037
1088#ifndef OPENSSL_NO_EC 1038#ifndef OPENSSL_NO_EC
1089 else if (type == TLSEXT_TYPE_ec_point_formats && 1039 else if (type == TLSEXT_TYPE_ec_point_formats &&