aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2016-04-09 22:22:05 +0900
committerKazuki Yamaguchi <k@rhe.jp>2016-04-21 00:46:34 +0900
commit815dc5c450e100ec7b3ed08a0f24f0e74c363c48 (patch)
treee0471d01d0fa1124c49f774b8c0e7a15d6c7d9ba
parente434a9fd55ef69a430f46cca871da8c1197916cb (diff)
downloadruby-815dc5c450e100ec7b3ed08a0f24f0e74c363c48.tar.gz
ossl_ssl_session: move SSL_SESSION_cmp to openssl_missing.c and modified to make it work on OpenSSL 1.1.0
-rw-r--r--ext/openssl/openssl_missing.c29
-rw-r--r--ext/openssl/openssl_missing.h8
-rw-r--r--ext/openssl/ossl_ssl_session.c21
3 files changed, 37 insertions, 21 deletions
diff --git a/ext/openssl/openssl_missing.c b/ext/openssl/openssl_missing.c
index c569f1ec0a..a053cfb488 100644
--- a/ext/openssl/openssl_missing.c
+++ b/ext/openssl/openssl_missing.c
@@ -460,3 +460,32 @@ EVP_PKEY_id(const EVP_PKEY *pkey)
return pkey->type;
}
#endif
+
+#if !defined(HAVE_SSL_SESSION_GET_ID)
+const unsigned char *
+SSL_SESSION_get_id(const SSL_SESSION *s, unsigned int *len)
+{
+ if (len)
+ *len = s->session_id_length;
+ return s->session_id;
+}
+#endif
+
+#if !defined(HAVE_SSL_SESSION_CMP) /* removed in 1.0.0 */
+int
+SSL_SESSION_cmp(const SSL_SESSION *a, const SSL_SESSION *b)
+{
+ unsigned int a_len;
+ unsigned char *a_sid = SSL_SESSION_get_id(a, &a_len);
+ unsigned int b_len;
+ unsigned char *b_sid = SSL_SESSION_get_id(b, &b_len);
+
+ if (a->ssl_version != b->ssl_version || a_len != b_len)
+ return 1;
+#if defined(_WIN32)
+ return memcmp(a_sid, b_sid, a_len);
+#else
+ return CRYPTO_memcmp(a_sid, b_sid, a_len);
+#endif
+}
+#endif
diff --git a/ext/openssl/openssl_missing.h b/ext/openssl/openssl_missing.h
index e77ed979d6..90cb6f060a 100644
--- a/ext/openssl/openssl_missing.h
+++ b/ext/openssl/openssl_missing.h
@@ -204,6 +204,14 @@ int OCSP_id_get0_info(ASN1_OCTET_STRING **piNameHash, ASN1_OBJECT **pmd,
int EVP_PKEY_id(const EVP_PKEY *pkey);
#endif
+#if !defined(HAVE_SSL_SESSION_GET_ID)
+int SSL_SESSION_get_id(const SSL_SESSION *s, unsigned int *len);
+#endif
+
+#if !defined(HAVE_SSL_SESSION_CMP)
+int SSL_SESSION_cmp(const SSL_SESSION *a,const SSL_SESSION *b);
+#endif
+
#if defined(__cplusplus)
}
#endif
diff --git a/ext/openssl/ossl_ssl_session.c b/ext/openssl/ossl_ssl_session.c
index e1bbc6fb54..08a5357c10 100644
--- a/ext/openssl/ossl_ssl_session.c
+++ b/ext/openssl/ossl_ssl_session.c
@@ -73,20 +73,6 @@ static VALUE ossl_ssl_session_initialize(VALUE self, VALUE arg1)
return self;
}
-#if HAVE_SSL_SESSION_CMP == 0
-int SSL_SESSION_cmp(const SSL_SESSION *a,const SSL_SESSION *b)
-{
- if (a->ssl_version != b->ssl_version ||
- a->session_id_length != b->session_id_length)
- return 1;
-#if defined(_WIN32)
- return memcmp(a->session_id, b->session_id, a->session_id_length);
-#else
- return CRYPTO_memcmp(a->session_id, b->session_id, a->session_id_length);
-#endif
-}
-#endif
-
/*
* call-seq:
* session1 == session2 -> boolean
@@ -186,7 +172,6 @@ static VALUE ossl_ssl_session_set_timeout(VALUE self, VALUE time_v)
return ossl_ssl_session_get_timeout(self);
}
-#ifdef HAVE_SSL_SESSION_GET_ID
/*
* call-seq:
* session.id -> aString
@@ -205,7 +190,6 @@ static VALUE ossl_ssl_session_get_id(VALUE self)
return rb_str_new((const char *) p, i);
}
-#endif
/*
* call-seq:
@@ -316,12 +300,7 @@ void Init_ossl_ssl_session(void)
rb_define_method(cSSLSession, "time=", ossl_ssl_session_set_time, 1);
rb_define_method(cSSLSession, "timeout", ossl_ssl_session_get_timeout, 0);
rb_define_method(cSSLSession, "timeout=", ossl_ssl_session_set_timeout, 1);
-
-#ifdef HAVE_SSL_SESSION_GET_ID
rb_define_method(cSSLSession, "id", ossl_ssl_session_get_id, 0);
-#else
- rb_undef_method(cSSLSession, "id");
-#endif
rb_define_method(cSSLSession, "to_der", ossl_ssl_session_to_der, 0);
rb_define_method(cSSLSession, "to_pem", ossl_ssl_session_to_pem, 0);
rb_define_method(cSSLSession, "to_text", ossl_ssl_session_to_text, 0);