Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 797673 | Differences between
and this patch

Collapse All | Expand All

(-)ruby-3.0.2-orig/ext/openssl/extconf.rb (-30 / +25 lines)
Lines 33-41 Link Here
33
  have_library("ws2_32")
33
  have_library("ws2_32")
34
end
34
end
35
35
36
Logging::message "=== Checking for required stuff... ===\n"
37
result = pkg_config("openssl") && have_header("openssl/ssl.h")
38
39
if $mingw
36
if $mingw
40
  append_cflags '-D_FORTIFY_SOURCE=2'
37
  append_cflags '-D_FORTIFY_SOURCE=2'
41
  append_ldflags '-fstack-protector'
38
  append_ldflags '-fstack-protector'
Lines 92-110 Link Here
92
  return false
89
  return false
93
end
90
end
94
91
95
unless result
92
Logging::message "=== Checking for required stuff... ===\n"
96
  unless find_openssl_library
93
pkg_config_found = pkg_config("openssl") && have_header("openssl/ssl.h")
97
    Logging::message "=== Checking for required stuff failed. ===\n"
94
98
    Logging::message "Makefile wasn't created. Fix the errors above.\n"
95
if !pkg_config_found && !find_openssl_library
99
    raise "OpenSSL library could not be found. You might want to use " \
96
  Logging::message "=== Checking for required stuff failed. ===\n"
100
      "--with-openssl-dir=<dir> option to specify the prefix where OpenSSL " \
97
  Logging::message "Makefile wasn't created. Fix the errors above.\n"
101
      "is installed."
98
  raise "OpenSSL library could not be found. You might want to use " \
102
  end
99
    "--with-openssl-dir=<dir> option to specify the prefix where OpenSSL " \
100
    "is installed."
101
end
102
103
version_ok = if have_macro("LIBRESSL_VERSION_NUMBER", "openssl/opensslv.h")
104
  is_libressl = true
105
  checking_for("LibreSSL version >= 3.1.0") {
106
    try_static_assert("LIBRESSL_VERSION_NUMBER >= 0x30100000L", "openssl/opensslv.h") }
107
else
108
  checking_for("OpenSSL version >= 1.0.2") {
109
    try_static_assert("OPENSSL_VERSION_NUMBER >= 0x10002000L", "openssl/opensslv.h") }
110
end
111
unless version_ok
112
  raise "OpenSSL >= 1.0.2 or LibreSSL >= 3.1.0 is required"
103
end
113
end
104
114
105
unless checking_for("OpenSSL version is 1.0.1 or later") {
115
# Prevent wincrypt.h from being included, which defines conflicting macro with openssl/x509.h
106
    try_static_assert("OPENSSL_VERSION_NUMBER >= 0x10001000L", "openssl/opensslv.h") }
116
if is_libressl && ($mswin || $mingw)
107
  raise "OpenSSL >= 1.0.1 or LibreSSL is required"
117
  $defs.push("-DNOCRYPT")
108
end
118
end
109
119
110
Logging::message "=== Checking for OpenSSL features... ===\n"
120
Logging::message "=== Checking for OpenSSL features... ===\n"
Lines 116-138 Link Here
116
  have_func("ENGINE_load_#{name}()", "openssl/engine.h")
126
  have_func("ENGINE_load_#{name}()", "openssl/engine.h")
117
}
127
}
118
128
119
if ($mswin || $mingw) && have_macro("LIBRESSL_VERSION_NUMBER", "openssl/opensslv.h")
120
  $defs.push("-DNOCRYPT")
121
end
122
123
# added in 1.0.2
124
have_func("EC_curve_nist2nid")
125
have_func("X509_REVOKED_dup")
126
have_func("X509_STORE_CTX_get0_store")
127
have_func("SSL_CTX_set_alpn_select_cb")
128
have_func("SSL_CTX_set1_curves_list(NULL, NULL)", "openssl/ssl.h")
129
have_func("SSL_CTX_set_ecdh_auto(NULL, 0)", "openssl/ssl.h")
130
have_func("SSL_get_server_tmp_key(NULL, NULL)", "openssl/ssl.h")
131
have_func("SSL_is_server")
132
133
# added in 1.1.0
129
# added in 1.1.0
134
if !have_struct_member("SSL", "ctx", "openssl/ssl.h") ||
130
if !have_struct_member("SSL", "ctx", "openssl/ssl.h") || is_libressl
135
    try_static_assert("LIBRESSL_VERSION_NUMBER >= 0x2070000fL", "openssl/opensslv.h")
136
  $defs.push("-DHAVE_OPAQUE_OPENSSL")
131
  $defs.push("-DHAVE_OPAQUE_OPENSSL")
137
end
132
end
138
have_func("CRYPTO_lock") || $defs.push("-DHAVE_OPENSSL_110_THREADING_API")
133
have_func("CRYPTO_lock") || $defs.push("-DHAVE_OPENSSL_110_THREADING_API")
(-)ruby-3.0.2-orig/ext/openssl/openssl_missing.c (-37 lines)
Lines 20-62 Link Here
20
20
21
#include "openssl_missing.h"
21
#include "openssl_missing.h"
22
22
23
/* added in 1.0.2 */
24
#if !defined(OPENSSL_NO_EC)
25
#if !defined(HAVE_EC_CURVE_NIST2NID)
26
static struct {
27
    const char *name;
28
    int nid;
29
} nist_curves[] = {
30
    {"B-163", NID_sect163r2},
31
    {"B-233", NID_sect233r1},
32
    {"B-283", NID_sect283r1},
33
    {"B-409", NID_sect409r1},
34
    {"B-571", NID_sect571r1},
35
    {"K-163", NID_sect163k1},
36
    {"K-233", NID_sect233k1},
37
    {"K-283", NID_sect283k1},
38
    {"K-409", NID_sect409k1},
39
    {"K-571", NID_sect571k1},
40
    {"P-192", NID_X9_62_prime192v1},
41
    {"P-224", NID_secp224r1},
42
    {"P-256", NID_X9_62_prime256v1},
43
    {"P-384", NID_secp384r1},
44
    {"P-521", NID_secp521r1}
45
};
46
47
int
48
ossl_EC_curve_nist2nid(const char *name)
49
{
50
    size_t i;
51
    for (i = 0; i < (sizeof(nist_curves) / sizeof(nist_curves[0])); i++) {
52
	if (!strcmp(nist_curves[i].name, name))
53
	    return nist_curves[i].nid;
54
    }
55
    return NID_undef;
56
}
57
#endif
58
#endif
59
60
/*** added in 1.1.0 ***/
23
/*** added in 1.1.0 ***/
61
#if !defined(HAVE_HMAC_CTX_NEW)
24
#if !defined(HAVE_HMAC_CTX_NEW)
62
HMAC_CTX *
25
HMAC_CTX *
(-)ruby-3.0.2-orig/ext/openssl/openssl_missing.h (-23 / +1 lines)
Lines 12-38 Link Here
12
12
13
#include "ruby/config.h"
13
#include "ruby/config.h"
14
14
15
/* added in 1.0.2 */
16
#if !defined(OPENSSL_NO_EC)
17
#if !defined(HAVE_EC_CURVE_NIST2NID)
18
int ossl_EC_curve_nist2nid(const char *);
19
#  define EC_curve_nist2nid ossl_EC_curve_nist2nid
20
#endif
21
#endif
22
23
#if !defined(HAVE_X509_REVOKED_DUP)
24
# define X509_REVOKED_dup(rev) (X509_REVOKED *)ASN1_dup((i2d_of_void *)i2d_X509_REVOKED, \
25
	(d2i_of_void *)d2i_X509_REVOKED, (char *)(rev))
26
#endif
27
28
#if !defined(HAVE_X509_STORE_CTX_GET0_STORE)
29
#  define X509_STORE_CTX_get0_store(x) ((x)->ctx)
30
#endif
31
32
#if !defined(HAVE_SSL_IS_SERVER)
33
#  define SSL_is_server(s) ((s)->server)
34
#endif
35
36
/* added in 1.1.0 */
15
/* added in 1.1.0 */
37
#if !defined(HAVE_BN_GENCB_NEW)
16
#if !defined(HAVE_BN_GENCB_NEW)
38
#  define BN_GENCB_new() ((BN_GENCB *)OPENSSL_malloc(sizeof(BN_GENCB)))
17
#  define BN_GENCB_new() ((BN_GENCB *)OPENSSL_malloc(sizeof(BN_GENCB)))
Lines 147-154 Link Here
147
	CRYPTO_add(&(x)->references, 1, CRYPTO_LOCK_EVP_PKEY);
126
	CRYPTO_add(&(x)->references, 1, CRYPTO_LOCK_EVP_PKEY);
148
#endif
127
#endif
149
128
150
#if !defined(HAVE_OPAQUE_OPENSSL) && \
129
#if !defined(HAVE_OPAQUE_OPENSSL)
151
    (!defined(LIBRESSL_VERSION_NUMBER) || LIBRESSL_VERSION_NUMBER < 0x2070000fL)
152
#define IMPL_PKEY_GETTER(_type, _name) \
130
#define IMPL_PKEY_GETTER(_type, _name) \
153
static inline _type *EVP_PKEY_get0_##_type(EVP_PKEY *pkey) { \
131
static inline _type *EVP_PKEY_get0_##_type(EVP_PKEY *pkey) { \
154
	return pkey->pkey._name; }
132
	return pkey->pkey._name; }
(-)ruby-3.0.2-orig/ext/openssl/ossl_ocsp.c (-48 lines)
Lines 1069-1123 Link Here
1069
    x509st = GetX509StorePtr(store);
1069
    x509st = GetX509StorePtr(store);
1070
    flg = NIL_P(flags) ? 0 : NUM2INT(flags);
1070
    flg = NIL_P(flags) ? 0 : NUM2INT(flags);
1071
    x509s = ossl_x509_ary2sk(certs);
1071
    x509s = ossl_x509_ary2sk(certs);
1072
#if (OPENSSL_VERSION_NUMBER < 0x1000202fL) || defined(LIBRESSL_VERSION_NUMBER)
1073
    /*
1074
     * OpenSSL had a bug that it doesn't use the certificates in x509s for
1075
     * verifying the chain. This can be a problem when the response is signed by
1076
     * a certificate issued by an intermediate CA.
1077
     *
1078
     *       root_ca
1079
     *         |
1080
     *   intermediate_ca
1081
     *         |-------------|
1082
     *     end_entity    ocsp_signer
1083
     *
1084
     * When the certificate hierarchy is like this, and the response contains
1085
     * only ocsp_signer certificate, the following code wrongly fails.
1086
     *
1087
     *   store = OpenSSL::X509::Store.new; store.add_cert(root_ca)
1088
     *   basic_response.verify([intermediate_ca], store)
1089
     *
1090
     * So add the certificates in x509s to the embedded certificates list first.
1091
     *
1092
     * This is fixed in OpenSSL 0.9.8zg, 1.0.0s, 1.0.1n, 1.0.2b. But it still
1093
     * exists in LibreSSL 2.1.10, 2.2.9, 2.3.6, 2.4.1.
1094
     */
1095
    if (!(flg & (OCSP_NOCHAIN | OCSP_NOVERIFY)) &&
1096
	sk_X509_num(x509s) && sk_X509_num(bs->certs)) {
1097
	int i;
1098
1099
	bs = ASN1_item_dup(ASN1_ITEM_rptr(OCSP_BASICRESP), bs);
1100
	if (!bs) {
1101
	    sk_X509_pop_free(x509s, X509_free);
1102
	    ossl_raise(eOCSPError, "ASN1_item_dup");
1103
	}
1104
1105
	for (i = 0; i < sk_X509_num(x509s); i++) {
1106
	    if (!OCSP_basic_add1_cert(bs, sk_X509_value(x509s, i))) {
1107
		sk_X509_pop_free(x509s, X509_free);
1108
		OCSP_BASICRESP_free(bs);
1109
		ossl_raise(eOCSPError, "OCSP_basic_add1_cert");
1110
	    }
1111
	}
1112
	result = OCSP_basic_verify(bs, x509s, x509st, flg);
1113
	OCSP_BASICRESP_free(bs);
1114
    }
1115
    else {
1116
	result = OCSP_basic_verify(bs, x509s, x509st, flg);
1117
    }
1118
#else
1119
    result = OCSP_basic_verify(bs, x509s, x509st, flg);
1072
    result = OCSP_basic_verify(bs, x509s, x509st, flg);
1120
#endif
1121
    sk_X509_pop_free(x509s, X509_free);
1073
    sk_X509_pop_free(x509s, X509_free);
1122
    if (result <= 0)
1074
    if (result <= 0)
1123
	ossl_clear_error();
1075
	ossl_clear_error();
(-)ruby-3.0.2-orig/ext/openssl/ossl_ssl.c (-122 / +6 lines)
Lines 49-67 Link Here
49
static int ossl_ssl_ex_vcb_idx;
49
static int ossl_ssl_ex_vcb_idx;
50
static int ossl_ssl_ex_ptr_idx;
50
static int ossl_ssl_ex_ptr_idx;
51
static int ossl_sslctx_ex_ptr_idx;
51
static int ossl_sslctx_ex_ptr_idx;
52
#if !defined(HAVE_X509_STORE_UP_REF)
53
static int ossl_sslctx_ex_store_p;
54
#endif
55
52
56
static void
53
static void
57
ossl_sslctx_free(void *ptr)
54
ossl_sslctx_free(void *ptr)
58
{
55
{
59
    SSL_CTX *ctx = ptr;
56
    SSL_CTX_free(ptr);
60
#if !defined(HAVE_X509_STORE_UP_REF)
61
    if (ctx && SSL_CTX_get_ex_data(ctx, ossl_sslctx_ex_store_p))
62
	ctx->cert_store = NULL;
63
#endif
64
    SSL_CTX_free(ctx);
65
}
57
}
66
58
67
static const rb_data_type_t ossl_sslctx_type = {
59
static const rb_data_type_t ossl_sslctx_type = {
Lines 95-101 Link Here
95
    RTYPEDDATA_DATA(obj) = ctx;
87
    RTYPEDDATA_DATA(obj) = ctx;
96
    SSL_CTX_set_ex_data(ctx, ossl_sslctx_ex_ptr_idx, (void *)obj);
88
    SSL_CTX_set_ex_data(ctx, ossl_sslctx_ex_ptr_idx, (void *)obj);
97
89
98
#if !defined(OPENSSL_NO_EC) && defined(HAVE_SSL_CTX_SET_ECDH_AUTO)
90
#if !defined(OPENSSL_NO_EC)
99
    /* We use SSL_CTX_set1_curves_list() to specify the curve used in ECDH. It
91
    /* We use SSL_CTX_set1_curves_list() to specify the curve used in ECDH. It
100
     * allows to specify multiple curve names and OpenSSL will select
92
     * allows to specify multiple curve names and OpenSSL will select
101
     * automatically from them. In OpenSSL 1.0.2, the automatic selection has to
93
     * automatically from them. In OpenSSL 1.0.2, the automatic selection has to
Lines 387-393 Link Here
387
}
379
}
388
380
389
static SSL_SESSION *
381
static SSL_SESSION *
390
#if (!defined(LIBRESSL_VERSION_NUMBER) ? OPENSSL_VERSION_NUMBER >= 0x10100000 : LIBRESSL_VERSION_NUMBER >= 0x2080000f)
382
#if defined(LIBRESSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER >= 0x10100000
391
ossl_sslctx_session_get_cb(SSL *ssl, const unsigned char *buf, int len, int *copy)
383
ossl_sslctx_session_get_cb(SSL *ssl, const unsigned char *buf, int len, int *copy)
392
#else
384
#else
393
ossl_sslctx_session_get_cb(SSL *ssl, unsigned char *buf, int len, int *copy)
385
ossl_sslctx_session_get_cb(SSL *ssl, unsigned char *buf, int len, int *copy)
Lines 596-603 Link Here
596
    rb_funcallv(cb, id_call, 1, &ssl_obj);
588
    rb_funcallv(cb, id_call, 1, &ssl_obj);
597
}
589
}
598
590
599
#if !defined(OPENSSL_NO_NEXTPROTONEG) || \
600
    defined(HAVE_SSL_CTX_SET_ALPN_SELECT_CB)
601
static VALUE
591
static VALUE
602
ssl_npn_encode_protocol_i(RB_BLOCK_CALL_FUNC_ARGLIST(cur, encoded))
592
ssl_npn_encode_protocol_i(RB_BLOCK_CALL_FUNC_ARGLIST(cur, encoded))
603
{
593
{
Lines 679-685 Link Here
679
669
680
    return SSL_TLSEXT_ERR_OK;
670
    return SSL_TLSEXT_ERR_OK;
681
}
671
}
682
#endif
683
672
684
#ifndef OPENSSL_NO_NEXTPROTONEG
673
#ifndef OPENSSL_NO_NEXTPROTONEG
685
static int
674
static int
Lines 708-714 Link Here
708
}
697
}
709
#endif
698
#endif
710
699
711
#ifdef HAVE_SSL_CTX_SET_ALPN_SELECT_CB
712
static int
700
static int
713
ssl_alpn_select_cb(SSL *ssl, const unsigned char **out, unsigned char *outlen,
701
ssl_alpn_select_cb(SSL *ssl, const unsigned char **out, unsigned char *outlen,
714
		   const unsigned char *in, unsigned int inlen, void *arg)
702
		   const unsigned char *in, unsigned int inlen, void *arg)
Lines 720-726 Link Here
720
708
721
    return ssl_npn_select_cb_common(ssl, cb, out, outlen, in, inlen);
709
    return ssl_npn_select_cb_common(ssl, cb, out, outlen, in, inlen);
722
}
710
}
723
#endif
724
711
725
/* This function may serve as the entry point to support further callbacks. */
712
/* This function may serve as the entry point to support further callbacks. */
726
static void
713
static void
Lines 825-841 Link Here
825
    if (!NIL_P(val)) {
812
    if (!NIL_P(val)) {
826
	X509_STORE *store = GetX509StorePtr(val); /* NO NEED TO DUP */
813
	X509_STORE *store = GetX509StorePtr(val); /* NO NEED TO DUP */
827
	SSL_CTX_set_cert_store(ctx, store);
814
	SSL_CTX_set_cert_store(ctx, store);
828
#if !defined(HAVE_X509_STORE_UP_REF)
829
	/*
830
         * WORKAROUND:
831
	 *   X509_STORE can count references, but
832
	 *   X509_STORE_free() doesn't care it.
833
	 *   So we won't increment it but mark it by ex_data.
834
	 */
835
        SSL_CTX_set_ex_data(ctx, ossl_sslctx_ex_store_p, ctx);
836
#else /* Fixed in OpenSSL 1.0.2; bff9ce4db38b (master), 5b4b9ce976fc (1.0.2) */
837
	X509_STORE_up_ref(store);
815
	X509_STORE_up_ref(store);
838
#endif
839
    }
816
    }
840
817
841
    val = rb_attr_get(self, id_i_extra_chain_cert);
818
    val = rb_attr_get(self, id_i_extra_chain_cert);
Lines 917-923 Link Here
917
    }
894
    }
918
#endif
895
#endif
919
896
920
#ifdef HAVE_SSL_CTX_SET_ALPN_SELECT_CB
921
    val = rb_attr_get(self, id_i_alpn_protocols);
897
    val = rb_attr_get(self, id_i_alpn_protocols);
922
    if (!NIL_P(val)) {
898
    if (!NIL_P(val)) {
923
	VALUE rprotos = ssl_encode_npn_protocols(val);
899
	VALUE rprotos = ssl_encode_npn_protocols(val);
Lines 932-938 Link Here
932
	SSL_CTX_set_alpn_select_cb(ctx, ssl_alpn_select_cb, (void *) self);
908
	SSL_CTX_set_alpn_select_cb(ctx, ssl_alpn_select_cb, (void *) self);
933
	OSSL_Debug("SSL ALPN select callback added");
909
	OSSL_Debug("SSL ALPN select callback added");
934
    }
910
    }
935
#endif
936
911
937
    rb_obj_freeze(self);
912
    rb_obj_freeze(self);
938
913
Lines 1065-1073 Link Here
1065
 * Extension. For a server, the list is used by OpenSSL to determine the set of
1040
 * Extension. For a server, the list is used by OpenSSL to determine the set of
1066
 * shared curves. OpenSSL will pick the most appropriate one from it.
1041
 * shared curves. OpenSSL will pick the most appropriate one from it.
1067
 *
1042
 *
1068
 * Note that this works differently with old OpenSSL (<= 1.0.1). Only one curve
1069
 * can be set, and this has no effect for TLS clients.
1070
 *
1071
 * === Example
1043
 * === Example
1072
 *   ctx1 = OpenSSL::SSL::SSLContext.new
1044
 *   ctx1 = OpenSSL::SSL::SSLContext.new
1073
 *   ctx1.ecdh_curves = "X25519:P-256:P-224"
1045
 *   ctx1.ecdh_curves = "X25519:P-256:P-224"
Lines 1091-1138 Link Here
1091
    GetSSLCTX(self, ctx);
1063
    GetSSLCTX(self, ctx);
1092
    StringValueCStr(arg);
1064
    StringValueCStr(arg);
1093
1065
1094
#if defined(HAVE_SSL_CTX_SET1_CURVES_LIST)
1095
    if (!SSL_CTX_set1_curves_list(ctx, RSTRING_PTR(arg)))
1066
    if (!SSL_CTX_set1_curves_list(ctx, RSTRING_PTR(arg)))
1096
	ossl_raise(eSSLError, NULL);
1067
	ossl_raise(eSSLError, NULL);
1097
#else
1098
    /* OpenSSL does not have SSL_CTX_set1_curves_list()... Fallback to
1099
     * SSL_CTX_set_tmp_ecdh(). So only the first curve is used. */
1100
    {
1101
	VALUE curve, splitted;
1102
	EC_KEY *ec;
1103
	int nid;
1104
1105
	splitted = rb_str_split(arg, ":");
1106
	if (!RARRAY_LEN(splitted))
1107
	    ossl_raise(eSSLError, "invalid input format");
1108
	curve = RARRAY_AREF(splitted, 0);
1109
	StringValueCStr(curve);
1110
1111
	/* SSL_CTX_set1_curves_list() accepts NIST names */
1112
	nid = EC_curve_nist2nid(RSTRING_PTR(curve));
1113
	if (nid == NID_undef)
1114
	    nid = OBJ_txt2nid(RSTRING_PTR(curve));
1115
	if (nid == NID_undef)
1116
	    ossl_raise(eSSLError, "unknown curve name");
1117
1118
	ec = EC_KEY_new_by_curve_name(nid);
1119
	if (!ec)
1120
	    ossl_raise(eSSLError, NULL);
1121
	EC_KEY_set_asn1_flag(ec, OPENSSL_EC_NAMED_CURVE);
1122
	if (!SSL_CTX_set_tmp_ecdh(ctx, ec)) {
1123
	    EC_KEY_free(ec);
1124
	    ossl_raise(eSSLError, "SSL_CTX_set_tmp_ecdh");
1125
	}
1126
	EC_KEY_free(ec);
1127
# if defined(HAVE_SSL_CTX_SET_ECDH_AUTO)
1128
	/* tmp_ecdh and ecdh_auto conflict. tmp_ecdh is ignored when ecdh_auto
1129
	 * is enabled. So disable ecdh_auto. */
1130
	if (!SSL_CTX_set_ecdh_auto(ctx, 0))
1131
	    ossl_raise(eSSLError, "SSL_CTX_set_ecdh_auto");
1132
# endif
1133
    }
1134
#endif
1135
1136
    return arg;
1068
    return arg;
1137
}
1069
}
1138
#else
1070
#else
Lines 1255-1264 Link Here
1255
 *   ecdsa_pkey = ...
1187
 *   ecdsa_pkey = ...
1256
 *   another_ca_cert = ...
1188
 *   another_ca_cert = ...
1257
 *   ctx.add_certificate(ecdsa_cert, ecdsa_pkey, [another_ca_cert])
1189
 *   ctx.add_certificate(ecdsa_cert, ecdsa_pkey, [another_ca_cert])
1258
 *
1259
 * === Note
1260
 * OpenSSL before the version 1.0.2 could handle only one extra chain across
1261
 * all key types. Calling this method discards the chain set previously.
1262
 */
1190
 */
1263
static VALUE
1191
static VALUE
1264
ossl_sslctx_add_certificate(int argc, VALUE *argv, VALUE self)
1192
ossl_sslctx_add_certificate(int argc, VALUE *argv, VALUE self)
Lines 1297-1330 Link Here
1297
	sk_X509_pop_free(extra_chain, X509_free);
1225
	sk_X509_pop_free(extra_chain, X509_free);
1298
	ossl_raise(eSSLError, "SSL_CTX_use_PrivateKey");
1226
	ossl_raise(eSSLError, "SSL_CTX_use_PrivateKey");
1299
    }
1227
    }
1300
1228
    if (extra_chain && !SSL_CTX_set0_chain(ctx, extra_chain)) {
1301
    if (extra_chain) {
1229
        sk_X509_pop_free(extra_chain, X509_free);
1302
#if OPENSSL_VERSION_NUMBER >= 0x10002000 && !defined(LIBRESSL_VERSION_NUMBER)
1230
        ossl_raise(eSSLError, "SSL_CTX_set0_chain");
1303
	if (!SSL_CTX_set0_chain(ctx, extra_chain)) {
1304
	    sk_X509_pop_free(extra_chain, X509_free);
1305
	    ossl_raise(eSSLError, "SSL_CTX_set0_chain");
1306
	}
1307
#else
1308
	STACK_OF(X509) *orig_extra_chain;
1309
	X509 *x509_tmp;
1310
1311
	/* First, clear the existing chain */
1312
	SSL_CTX_get_extra_chain_certs(ctx, &orig_extra_chain);
1313
	if (orig_extra_chain && sk_X509_num(orig_extra_chain)) {
1314
	    rb_warning("SSL_CTX_set0_chain() is not available; " \
1315
		       "clearing previously set certificate chain");
1316
	    SSL_CTX_clear_extra_chain_certs(ctx);
1317
	}
1318
	while ((x509_tmp = sk_X509_shift(extra_chain))) {
1319
	    /* Transfers ownership */
1320
	    if (!SSL_CTX_add_extra_chain_cert(ctx, x509_tmp)) {
1321
		X509_free(x509_tmp);
1322
		sk_X509_pop_free(extra_chain, X509_free);
1323
		ossl_raise(eSSLError, "SSL_CTX_add_extra_chain_cert");
1324
	    }
1325
	}
1326
	sk_X509_free(extra_chain);
1327
#endif
1328
    }
1231
    }
1329
    return self;
1232
    return self;
1330
}
1233
}
Lines 2410-2416 Link Here
2410
}
2313
}
2411
# endif
2314
# endif
2412
2315
2413
# ifdef HAVE_SSL_CTX_SET_ALPN_SELECT_CB
2414
/*
2316
/*
2415
 * call-seq:
2317
 * call-seq:
2416
 *    ssl.alpn_protocol => String | nil
2318
 *    ssl.alpn_protocol => String | nil
Lines 2433-2441 Link Here
2433
    else
2335
    else
2434
	return rb_str_new((const char *) out, outlen);
2336
	return rb_str_new((const char *) out, outlen);
2435
}
2337
}
2436
# endif
2437
2338
2438
# ifdef HAVE_SSL_GET_SERVER_TMP_KEY
2439
/*
2339
/*
2440
 * call-seq:
2340
 * call-seq:
2441
 *    ssl.tmp_key => PKey or nil
2341
 *    ssl.tmp_key => PKey or nil
Lines 2453-2459 Link Here
2453
	return Qnil;
2353
	return Qnil;
2454
    return ossl_pkey_new(key);
2354
    return ossl_pkey_new(key);
2455
}
2355
}
2456
# endif /* defined(HAVE_SSL_GET_SERVER_TMP_KEY) */
2457
#endif /* !defined(OPENSSL_NO_SOCK) */
2356
#endif /* !defined(OPENSSL_NO_SOCK) */
2458
2357
2459
void
2358
void
Lines 2478-2488 Link Here
2478
    ossl_sslctx_ex_ptr_idx = SSL_CTX_get_ex_new_index(0, (void *)"ossl_sslctx_ex_ptr_idx", 0, 0, 0);
2377
    ossl_sslctx_ex_ptr_idx = SSL_CTX_get_ex_new_index(0, (void *)"ossl_sslctx_ex_ptr_idx", 0, 0, 0);
2479
    if (ossl_sslctx_ex_ptr_idx < 0)
2378
    if (ossl_sslctx_ex_ptr_idx < 0)
2480
	ossl_raise(rb_eRuntimeError, "SSL_CTX_get_ex_new_index");
2379
	ossl_raise(rb_eRuntimeError, "SSL_CTX_get_ex_new_index");
2481
#if !defined(HAVE_X509_STORE_UP_REF)
2482
    ossl_sslctx_ex_store_p = SSL_CTX_get_ex_new_index(0, (void *)"ossl_sslctx_ex_store_p", 0, 0, 0);
2483
    if (ossl_sslctx_ex_store_p < 0)
2484
	ossl_raise(rb_eRuntimeError, "SSL_CTX_get_ex_new_index");
2485
#endif
2486
2380
2487
    /* Document-module: OpenSSL::SSL
2381
    /* Document-module: OpenSSL::SSL
2488
     *
2382
     *
Lines 2733-2739 Link Here
2733
    rb_attr(cSSLContext, rb_intern_const("npn_select_cb"), 1, 1, Qfalse);
2627
    rb_attr(cSSLContext, rb_intern_const("npn_select_cb"), 1, 1, Qfalse);
2734
#endif
2628
#endif
2735
2629
2736
#ifdef HAVE_SSL_CTX_SET_ALPN_SELECT_CB
2737
    /*
2630
    /*
2738
     * An Enumerable of Strings. Each String represents a protocol to be
2631
     * An Enumerable of Strings. Each String represents a protocol to be
2739
     * advertised as the list of supported protocols for Application-Layer
2632
     * advertised as the list of supported protocols for Application-Layer
Lines 2763-2769 Link Here
2763
     *   end
2656
     *   end
2764
     */
2657
     */
2765
    rb_attr(cSSLContext, rb_intern_const("alpn_select_cb"), 1, 1, Qfalse);
2658
    rb_attr(cSSLContext, rb_intern_const("alpn_select_cb"), 1, 1, Qfalse);
2766
#endif
2767
2659
2768
    rb_define_alias(cSSLContext, "ssl_timeout", "timeout");
2660
    rb_define_alias(cSSLContext, "ssl_timeout", "timeout");
2769
    rb_define_alias(cSSLContext, "ssl_timeout=", "timeout=");
2661
    rb_define_alias(cSSLContext, "ssl_timeout=", "timeout=");
Lines 2877-2888 Link Here
2877
    rb_define_method(cSSLSocket, "hostname=", ossl_ssl_set_hostname, 1);
2769
    rb_define_method(cSSLSocket, "hostname=", ossl_ssl_set_hostname, 1);
2878
    rb_define_method(cSSLSocket, "finished_message", ossl_ssl_get_finished, 0);
2770
    rb_define_method(cSSLSocket, "finished_message", ossl_ssl_get_finished, 0);
2879
    rb_define_method(cSSLSocket, "peer_finished_message", ossl_ssl_get_peer_finished, 0);
2771
    rb_define_method(cSSLSocket, "peer_finished_message", ossl_ssl_get_peer_finished, 0);
2880
# ifdef HAVE_SSL_GET_SERVER_TMP_KEY
2881
    rb_define_method(cSSLSocket, "tmp_key", ossl_ssl_tmp_key, 0);
2772
    rb_define_method(cSSLSocket, "tmp_key", ossl_ssl_tmp_key, 0);
2882
# endif
2883
# ifdef HAVE_SSL_CTX_SET_ALPN_SELECT_CB
2884
    rb_define_method(cSSLSocket, "alpn_protocol", ossl_ssl_alpn_protocol, 0);
2773
    rb_define_method(cSSLSocket, "alpn_protocol", ossl_ssl_alpn_protocol, 0);
2885
# endif
2886
# ifndef OPENSSL_NO_NEXTPROTONEG
2774
# ifndef OPENSSL_NO_NEXTPROTONEG
2887
    rb_define_method(cSSLSocket, "npn_protocol", ossl_ssl_npn_protocol, 0);
2775
    rb_define_method(cSSLSocket, "npn_protocol", ossl_ssl_npn_protocol, 0);
2888
# endif
2776
# endif
Lines 2895-2906 Link Here
2895
2783
2896
    rb_define_const(mSSL, "OP_ALL", ULONG2NUM(SSL_OP_ALL));
2784
    rb_define_const(mSSL, "OP_ALL", ULONG2NUM(SSL_OP_ALL));
2897
    rb_define_const(mSSL, "OP_LEGACY_SERVER_CONNECT", ULONG2NUM(SSL_OP_LEGACY_SERVER_CONNECT));
2785
    rb_define_const(mSSL, "OP_LEGACY_SERVER_CONNECT", ULONG2NUM(SSL_OP_LEGACY_SERVER_CONNECT));
2898
#ifdef SSL_OP_TLSEXT_PADDING /* OpenSSL 1.0.1h and OpenSSL 1.0.2 */
2899
    rb_define_const(mSSL, "OP_TLSEXT_PADDING", ULONG2NUM(SSL_OP_TLSEXT_PADDING));
2786
    rb_define_const(mSSL, "OP_TLSEXT_PADDING", ULONG2NUM(SSL_OP_TLSEXT_PADDING));
2900
#endif
2901
#ifdef SSL_OP_SAFARI_ECDHE_ECDSA_BUG /* OpenSSL 1.0.1f and OpenSSL 1.0.2 */
2902
    rb_define_const(mSSL, "OP_SAFARI_ECDHE_ECDSA_BUG", ULONG2NUM(SSL_OP_SAFARI_ECDHE_ECDSA_BUG));
2787
    rb_define_const(mSSL, "OP_SAFARI_ECDHE_ECDSA_BUG", ULONG2NUM(SSL_OP_SAFARI_ECDHE_ECDSA_BUG));
2903
#endif
2904
#ifdef SSL_OP_ALLOW_NO_DHE_KEX /* OpenSSL 1.1.1 */
2788
#ifdef SSL_OP_ALLOW_NO_DHE_KEX /* OpenSSL 1.1.1 */
2905
    rb_define_const(mSSL, "OP_ALLOW_NO_DHE_KEX", ULONG2NUM(SSL_OP_ALLOW_NO_DHE_KEX));
2789
    rb_define_const(mSSL, "OP_ALLOW_NO_DHE_KEX", ULONG2NUM(SSL_OP_ALLOW_NO_DHE_KEX));
2906
#endif
2790
#endif
(-)ruby-3.0.2-orig/ext/openssl/ossl_ts.c (-6 / +3 lines)
Lines 821-832 Link Here
821
    TS_VERIFY_CTX_set_store(ctx, x509st);
821
    TS_VERIFY_CTX_set_store(ctx, x509st);
822
822
823
    ok = TS_RESP_verify_response(ctx, resp);
823
    ok = TS_RESP_verify_response(ctx, resp);
824
824
    /*
825
    /* WORKAROUND:
825
     * TS_VERIFY_CTX_set_store() call above does not increment the reference
826
     *   X509_STORE can count references, but X509_STORE_free() doesn't check
826
     * counter, so it must be unset before TS_VERIFY_CTX_free() is called.
827
     *   this. To prevent our X509_STORE from being freed with our
828
     *   TS_VERIFY_CTX we set the store to NULL first.
829
     *   Fixed in OpenSSL 1.0.2; bff9ce4db38b (master), 5b4b9ce976fc (1.0.2)
830
     */
827
     */
831
    TS_VERIFY_CTX_set_store(ctx, NULL);
828
    TS_VERIFY_CTX_set_store(ctx, NULL);
832
    TS_VERIFY_CTX_free(ctx);
829
    TS_VERIFY_CTX_free(ctx);
(-)ruby-3.0.2-orig/ext/openssl/ossl_x509.c (-6 lines)
Lines 115-125 Link Here
115
    DefX509Const(V_ERR_SUITE_B_LOS_NOT_ALLOWED);
115
    DefX509Const(V_ERR_SUITE_B_LOS_NOT_ALLOWED);
116
    DefX509Const(V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256);
116
    DefX509Const(V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256);
117
#endif
117
#endif
118
#if defined(X509_V_ERR_HOSTNAME_MISMATCH)
119
    DefX509Const(V_ERR_HOSTNAME_MISMATCH);
118
    DefX509Const(V_ERR_HOSTNAME_MISMATCH);
120
    DefX509Const(V_ERR_EMAIL_MISMATCH);
119
    DefX509Const(V_ERR_EMAIL_MISMATCH);
121
    DefX509Const(V_ERR_IP_ADDRESS_MISMATCH);
120
    DefX509Const(V_ERR_IP_ADDRESS_MISMATCH);
122
#endif
123
#if defined(X509_V_ERR_DANE_NO_MATCH)
121
#if defined(X509_V_ERR_DANE_NO_MATCH)
124
    DefX509Const(V_ERR_DANE_NO_MATCH);
122
    DefX509Const(V_ERR_DANE_NO_MATCH);
125
#endif
123
#endif
Lines 187-198 Link Here
187
    /* Set by Store#flags= and StoreContext#flags=. Enables checking of the
185
    /* Set by Store#flags= and StoreContext#flags=. Enables checking of the
188
     * signature of the root self-signed CA. */
186
     * signature of the root self-signed CA. */
189
    DefX509Const(V_FLAG_CHECK_SS_SIGNATURE);
187
    DefX509Const(V_FLAG_CHECK_SS_SIGNATURE);
190
#if defined(X509_V_FLAG_TRUSTED_FIRST)
191
    /* Set by Store#flags= and StoreContext#flags=. When constructing a
188
    /* Set by Store#flags= and StoreContext#flags=. When constructing a
192
     * certificate chain, search the Store first for the issuer certificate.
189
     * certificate chain, search the Store first for the issuer certificate.
193
     * Enabled by default in OpenSSL >= 1.1.0. */
190
     * Enabled by default in OpenSSL >= 1.1.0. */
194
    DefX509Const(V_FLAG_TRUSTED_FIRST);
191
    DefX509Const(V_FLAG_TRUSTED_FIRST);
195
#endif
196
#if defined(X509_V_FLAG_SUITEB_128_LOS_ONLY)
192
#if defined(X509_V_FLAG_SUITEB_128_LOS_ONLY)
197
    /* Set by Store#flags= and StoreContext#flags=.
193
    /* Set by Store#flags= and StoreContext#flags=.
198
     * Enables Suite B 128 bit only mode. */
194
     * Enables Suite B 128 bit only mode. */
Lines 208-218 Link Here
208
     * Enables Suite B 128 bit mode allowing 192 bit algorithms. */
204
     * Enables Suite B 128 bit mode allowing 192 bit algorithms. */
209
    DefX509Const(V_FLAG_SUITEB_128_LOS);
205
    DefX509Const(V_FLAG_SUITEB_128_LOS);
210
#endif
206
#endif
211
#if defined(X509_V_FLAG_PARTIAL_CHAIN)
212
    /* Set by Store#flags= and StoreContext#flags=.
207
    /* Set by Store#flags= and StoreContext#flags=.
213
     * Allows partial chains if at least one certificate is in trusted store. */
208
     * Allows partial chains if at least one certificate is in trusted store. */
214
    DefX509Const(V_FLAG_PARTIAL_CHAIN);
209
    DefX509Const(V_FLAG_PARTIAL_CHAIN);
215
#endif
216
#if defined(X509_V_FLAG_NO_ALT_CHAINS)
210
#if defined(X509_V_FLAG_NO_ALT_CHAINS)
217
    /* Set by Store#flags= and StoreContext#flags=. Suppresses searching for
211
    /* Set by Store#flags= and StoreContext#flags=. Suppresses searching for
218
     * a alternative chain. No effect in OpenSSL >= 1.1.0. */
212
     * a alternative chain. No effect in OpenSSL >= 1.1.0. */
(-)ruby-3.0.2-orig/test/openssl/test_asn1.rb (-4 / +3 lines)
Lines 265-274 Link Here
265
    assert_raise(OpenSSL::ASN1::ASN1Error) {
265
    assert_raise(OpenSSL::ASN1::ASN1Error) {
266
      OpenSSL::ASN1.decode(B(%w{ 03 00 }))
266
      OpenSSL::ASN1.decode(B(%w{ 03 00 }))
267
    }
267
    }
268
    # OpenSSL < OpenSSL_1_0_1k and LibreSSL ignore the error
268
    assert_raise(OpenSSL::ASN1::ASN1Error) {
269
    # assert_raise(OpenSSL::ASN1::ASN1Error) {
269
      OpenSSL::ASN1.decode(B(%w{ 03 03 08 FF 00 }))
270
    #   OpenSSL::ASN1.decode(B(%w{ 03 03 08 FF 00 }))
270
    }
271
    # }
272
    # OpenSSL does not seem to prohibit this, though X.690 8.6.2.3 (15/08) does
271
    # OpenSSL does not seem to prohibit this, though X.690 8.6.2.3 (15/08) does
273
    # assert_raise(OpenSSL::ASN1::ASN1Error) {
272
    # assert_raise(OpenSSL::ASN1::ASN1Error) {
274
    #   OpenSSL::ASN1.decode(B(%w{ 03 01 04 }))
273
    #   OpenSSL::ASN1.decode(B(%w{ 03 01 04 }))
(-)ruby-3.0.2-orig/test/openssl/test_ocsp.rb (-8 / +1 lines)
Lines 123-136 Link Here
123
123
124
    assert_equal true, req.verify([@cert], store, OpenSSL::OCSP::NOINTERN)
124
    assert_equal true, req.verify([@cert], store, OpenSSL::OCSP::NOINTERN)
125
    ret = req.verify([@cert], store)
125
    ret = req.verify([@cert], store)
126
    if ret || openssl?(1, 0, 2)
126
    assert_equal true, ret
127
      assert_equal true, ret
128
    else
129
      # RT2560; OCSP_request_verify() does not find signer cert from 'certs' when
130
      # OCSP_NOINTERN is not specified.
131
      # fixed by OpenSSL 1.0.1j, 1.0.2
132
      pend "RT2560: ocsp_req_find_signer"
133
    end
134
127
135
    # not signed
128
    # not signed
136
    req = OpenSSL::OCSP::Request.new.add_certid(cid)
129
    req = OpenSSL::OCSP::Request.new.add_certid(cid)
(-)ruby-3.0.2-orig/test/openssl/test_ssl.rb (-60 / +26 lines)
Lines 1-3 Link Here
1
# coding: utf-8
1
# frozen_string_literal: true
2
# frozen_string_literal: true
2
require_relative "utils"
3
require_relative "utils"
3
4
Lines 127-147 Link Here
127
    pend "EC is not supported" unless defined?(OpenSSL::PKey::EC)
128
    pend "EC is not supported" unless defined?(OpenSSL::PKey::EC)
128
    pend "TLS 1.2 is not supported" unless tls12_supported?
129
    pend "TLS 1.2 is not supported" unless tls12_supported?
129
130
130
    # SSL_CTX_set0_chain() is needed for setting multiple certificate chains
131
    ca2_key = Fixtures.pkey("rsa-3")
131
    add0_chain_supported = openssl?(1, 0, 2)
132
    ca2_exts = [
132
133
      ["basicConstraints", "CA:TRUE", true],
133
    if add0_chain_supported
134
      ["keyUsage", "cRLSign, keyCertSign", true],
134
      ca2_key = Fixtures.pkey("rsa-3")
135
    ]
135
      ca2_exts = [
136
    ca2_dn = OpenSSL::X509::Name.parse_rfc2253("CN=CA2")
136
        ["basicConstraints", "CA:TRUE", true],
137
    ca2_cert = issue_cert(ca2_dn, ca2_key, 123, ca2_exts, nil, nil)
137
        ["keyUsage", "cRLSign, keyCertSign", true],
138
      ]
139
      ca2_dn = OpenSSL::X509::Name.parse_rfc2253("CN=CA2")
140
      ca2_cert = issue_cert(ca2_dn, ca2_key, 123, ca2_exts, nil, nil)
141
    else
142
      # Use the same CA as @svr_cert
143
      ca2_key = @ca_key; ca2_cert = @ca_cert
144
    end
145
138
146
    ecdsa_key = Fixtures.pkey("p256")
139
    ecdsa_key = Fixtures.pkey("p256")
147
    exts = [
140
    exts = [
Lines 150-172 Link Here
150
    ecdsa_dn = OpenSSL::X509::Name.parse_rfc2253("CN=localhost2")
143
    ecdsa_dn = OpenSSL::X509::Name.parse_rfc2253("CN=localhost2")
151
    ecdsa_cert = issue_cert(ecdsa_dn, ecdsa_key, 456, exts, ca2_cert, ca2_key)
144
    ecdsa_cert = issue_cert(ecdsa_dn, ecdsa_key, 456, exts, ca2_cert, ca2_key)
152
145
153
    if !add0_chain_supported
154
      # Testing the warning emitted when 'extra' chain is replaced
155
      tctx = OpenSSL::SSL::SSLContext.new
156
      tctx.add_certificate(@svr_cert, @svr_key, [@ca_cert])
157
      assert_warning(/set0_chain/) {
158
        tctx.add_certificate(ecdsa_cert, ecdsa_key, [ca2_cert])
159
      }
160
    end
161
162
    ctx_proc = -> ctx {
146
    ctx_proc = -> ctx {
163
      # Unset values set by start_server
147
      # Unset values set by start_server
164
      ctx.cert = ctx.key = ctx.extra_chain_cert = nil
148
      ctx.cert = ctx.key = ctx.extra_chain_cert = nil
165
      ctx.ecdh_curves = "P-256" unless openssl?(1, 0, 2)
166
      ctx.add_certificate(@svr_cert, @svr_key, [@ca_cert]) # RSA
149
      ctx.add_certificate(@svr_cert, @svr_key, [@ca_cert]) # RSA
167
      EnvUtil.suppress_warning do # !add0_chain_supported
150
      ctx.add_certificate(ecdsa_cert, ecdsa_key, [ca2_cert])
168
        ctx.add_certificate(ecdsa_cert, ecdsa_key, [ca2_cert])
169
      end
170
    }
151
    }
171
    start_server(ctx_proc: ctx_proc) do |port|
152
    start_server(ctx_proc: ctx_proc) do |port|
172
      ctx = OpenSSL::SSL::SSLContext.new
153
      ctx = OpenSSL::SSL::SSLContext.new
Lines 941-950 Link Here
941
        ssl.hostname = "b.example.com"
922
        ssl.hostname = "b.example.com"
942
        assert_handshake_error { ssl.connect }
923
        assert_handshake_error { ssl.connect }
943
        assert_equal false, verify_callback_ok
924
        assert_equal false, verify_callback_ok
944
        code_expected = openssl?(1, 0, 2) || defined?(OpenSSL::X509::V_ERR_HOSTNAME_MISMATCH) ?
925
        assert_equal OpenSSL::X509::V_ERR_HOSTNAME_MISMATCH, verify_callback_err
945
          OpenSSL::X509::V_ERR_HOSTNAME_MISMATCH :
946
          OpenSSL::X509::V_ERR_CERT_REJECTED
947
        assert_equal code_expected, verify_callback_err
948
      ensure
926
      ensure
949
        sock&.close
927
        sock&.close
950
      end
928
      end
Lines 1234-1240 Link Here
1234
    }
1212
    }
1235
  end
1213
  end
1236
1214
1237
if openssl?(1, 0, 2) || libressl?
1238
  def test_alpn_protocol_selection_ary
1215
  def test_alpn_protocol_selection_ary
1239
    advertised = ["http/1.1", "spdy/2"]
1216
    advertised = ["http/1.1", "spdy/2"]
1240
    ctx_proc = Proc.new { |ctx|
1217
    ctx_proc = Proc.new { |ctx|
Lines 1280-1286 Link Here
1280
    t&.kill
1257
    t&.kill
1281
    t&.join
1258
    t&.join
1282
  end
1259
  end
1283
end
1284
1260
1285
  def test_npn_protocol_selection_ary
1261
  def test_npn_protocol_selection_ary
1286
    pend "TLS 1.2 is not supported" unless tls12_supported?
1262
    pend "TLS 1.2 is not supported" unless tls12_supported?
Lines 1398-1408 Link Here
1398
  end
1374
  end
1399
1375
1400
  def test_get_ephemeral_key
1376
  def test_get_ephemeral_key
1401
    # OpenSSL >= 1.0.2
1402
    unless OpenSSL::SSL::SSLSocket.method_defined?(:tmp_key)
1403
      pend "SSL_get_server_tmp_key() is not supported"
1404
    end
1405
1406
    if tls12_supported?
1377
    if tls12_supported?
1407
      # kRSA
1378
      # kRSA
1408
      ctx_proc1 = proc { |ctx|
1379
      ctx_proc1 = proc { |ctx|
Lines 1533-1541 Link Here
1533
    start_server(ctx_proc: ctx_proc) do |port|
1504
    start_server(ctx_proc: ctx_proc) do |port|
1534
      server_connect(port) { |ssl|
1505
      server_connect(port) { |ssl|
1535
        assert called, "dh callback should be called"
1506
        assert called, "dh callback should be called"
1536
        if ssl.respond_to?(:tmp_key)
1507
        assert_equal dh.to_der, ssl.tmp_key.to_der
1537
          assert_equal dh.to_der, ssl.tmp_key.to_der
1538
        end
1539
      }
1508
      }
1540
    end
1509
    end
1541
  end
1510
  end
Lines 1590-1595 Link Here
1590
      ctx.ecdh_curves = "P-384:P-521"
1559
      ctx.ecdh_curves = "P-384:P-521"
1591
    }
1560
    }
1592
    start_server(ctx_proc: ctx_proc, ignore_listener_error: true) do |port|
1561
    start_server(ctx_proc: ctx_proc, ignore_listener_error: true) do |port|
1562
      # Test 1: Client=P-256:P-384, Server=P-384:P-521 --> P-384
1593
      ctx = OpenSSL::SSL::SSLContext.new
1563
      ctx = OpenSSL::SSL::SSLContext.new
1594
      ctx.ecdh_curves = "P-256:P-384" # disable P-521 for OpenSSL >= 1.0.2
1564
      ctx.ecdh_curves = "P-256:P-384" # disable P-521 for OpenSSL >= 1.0.2
1595
1565
Lines 1599-1627 Link Here
1599
          assert_equal "secp384r1", ssl.tmp_key.group.curve_name
1569
          assert_equal "secp384r1", ssl.tmp_key.group.curve_name
1600
        else
1570
        else
1601
          assert_match (/\AECDH/), cs
1571
          assert_match (/\AECDH/), cs
1602
          if ssl.respond_to?(:tmp_key)
1572
        assert_equal "secp384r1", ssl.tmp_key.group.curve_name
1603
            assert_equal "secp384r1", ssl.tmp_key.group.curve_name
1604
          end
1605
        end
1573
        end
1606
        ssl.puts "abc"; assert_equal "abc\n", ssl.gets
1574
        ssl.puts "abc"; assert_equal "abc\n", ssl.gets
1607
      }
1575
      }
1608
1576
1609
      if openssl?(1, 0, 2) || libressl?(2, 5, 1)
1577
      # Test 2: Client=P-256, Server=P-521:P-384 --> Fail
1610
        ctx = OpenSSL::SSL::SSLContext.new
1578
      ctx = OpenSSL::SSL::SSLContext.new
1611
        ctx.ecdh_curves = "P-256"
1579
      ctx.ecdh_curves = "P-256"
1612
1580
      assert_raise(OpenSSL::SSL::SSLError) {
1613
        assert_raise(OpenSSL::SSL::SSLError) {
1581
        server_connect(port, ctx) { }
1614
          server_connect(port, ctx) { }
1582
      }
1615
        }
1616
1617
        ctx = OpenSSL::SSL::SSLContext.new
1618
        ctx.ecdh_curves = "P-521:P-384"
1619
1583
1620
        server_connect(port, ctx) { |ssl|
1584
      # Test 3: Client=P-521:P-384, Server=P-521:P-384 --> P-521
1621
          assert_equal "secp521r1", ssl.tmp_key.group.curve_name
1585
      ctx = OpenSSL::SSL::SSLContext.new
1622
          ssl.puts "abc"; assert_equal "abc\n", ssl.gets
1586
      ctx.ecdh_curves = "P-521:P-384"
1623
        }
1587
      server_connect(port, ctx) { |ssl|
1624
      end
1588
        assert_equal "secp521r1", ssl.tmp_key.group.curve_name
1589
        ssl.puts "abc"; assert_equal "abc\n", ssl.gets
1590
      }
1625
    end
1591
    end
1626
  end
1592
  end
1627
1593

Return to bug 797673