Skip to content

Commit 75bbc8a

Browse files
authored
Merge pull request #558 from kateinoigakukun/katei/fix-no-sock-support
Undefine `OpenSSL::SSL` for no socket platforms
2 parents 1b60365 + b0cfac6 commit 75bbc8a

File tree

6 files changed

+15
-23
lines changed

6 files changed

+15
-23
lines changed

ext/openssl/ossl_ssl.c

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212
#include "ossl.h"
1313

14+
#ifndef OPENSSL_NO_SOCK
1415
#define numberof(ary) (int)(sizeof(ary)/sizeof((ary)[0]))
1516

1617
#if !defined(OPENSSL_NO_NEXTPROTONEG) && !OSSL_IS_LIBRESSL
@@ -33,7 +34,6 @@
3334
} while (0)
3435

3536
VALUE mSSL;
36-
static VALUE mSSLExtConfig;
3737
static VALUE eSSLError;
3838
VALUE cSSLContext;
3939
VALUE cSSLSocket;
@@ -1541,7 +1541,6 @@ ossl_sslctx_flush_sessions(int argc, VALUE *argv, VALUE self)
15411541
/*
15421542
* SSLSocket class
15431543
*/
1544-
#ifndef OPENSSL_NO_SOCK
15451544
static inline int
15461545
ssl_started(SSL *ssl)
15471546
{
@@ -2569,6 +2568,7 @@ Init_ossl_ssl(void)
25692568
rb_mWaitWritable = rb_define_module_under(rb_cIO, "WaitWritable");
25702569
#endif
25712570

2571+
#ifndef OPENSSL_NO_SOCK
25722572
id_call = rb_intern_const("call");
25732573
ID_callback_state = rb_intern_const("callback_state");
25742574

@@ -2591,16 +2591,6 @@ Init_ossl_ssl(void)
25912591
*/
25922592
mSSL = rb_define_module_under(mOSSL, "SSL");
25932593

2594-
/* Document-module: OpenSSL::ExtConfig
2595-
*
2596-
* This module contains configuration information about the SSL extension,
2597-
* for example if socket support is enabled, or the host name TLS extension
2598-
* is enabled. Constants in this module will always be defined, but contain
2599-
* +true+ or +false+ values depending on the configuration of your OpenSSL
2600-
* installation.
2601-
*/
2602-
mSSLExtConfig = rb_define_module_under(mOSSL, "ExtConfig");
2603-
26042594
/* Document-class: OpenSSL::SSL::SSLError
26052595
*
26062596
* Generic error class raised by SSLSocket and SSLContext.
@@ -2763,8 +2753,6 @@ Init_ossl_ssl(void)
27632753
*/
27642754
rb_attr(cSSLContext, rb_intern_const("session_remove_cb"), 1, 1, Qfalse);
27652755

2766-
rb_define_const(mSSLExtConfig, "HAVE_TLSEXT_HOST_NAME", Qtrue);
2767-
27682756
/*
27692757
* A callback invoked whenever a new handshake is initiated on an
27702758
* established connection. May be used to disable renegotiation entirely.
@@ -2955,11 +2943,6 @@ Init_ossl_ssl(void)
29552943
* Document-class: OpenSSL::SSL::SSLSocket
29562944
*/
29572945
cSSLSocket = rb_define_class_under(mSSL, "SSLSocket", rb_cObject);
2958-
#ifdef OPENSSL_NO_SOCK
2959-
rb_define_const(mSSLExtConfig, "OPENSSL_NO_SOCK", Qtrue);
2960-
rb_define_method(cSSLSocket, "initialize", rb_f_notimplement, -1);
2961-
#else
2962-
rb_define_const(mSSLExtConfig, "OPENSSL_NO_SOCK", Qfalse);
29632946
rb_define_alloc_func(cSSLSocket, ossl_ssl_s_alloc);
29642947
rb_define_method(cSSLSocket, "initialize", ossl_ssl_initialize, -1);
29652948
rb_undef_method(cSSLSocket, "initialize_copy");
@@ -2994,7 +2977,6 @@ Init_ossl_ssl(void)
29942977
# ifdef OSSL_USE_NEXTPROTONEG
29952978
rb_define_method(cSSLSocket, "npn_protocol", ossl_ssl_npn_protocol, 0);
29962979
# endif
2997-
#endif
29982980

29992981
rb_define_const(mSSL, "VERIFY_NONE", INT2NUM(SSL_VERIFY_NONE));
30002982
rb_define_const(mSSL, "VERIFY_PEER", INT2NUM(SSL_VERIFY_PEER));
@@ -3156,4 +3138,5 @@ Init_ossl_ssl(void)
31563138
DefIVarID(io);
31573139
DefIVarID(context);
31583140
DefIVarID(hostname);
3141+
#endif /* !defined(OPENSSL_NO_SOCK) */
31593142
}

ext/openssl/ossl_ssl_session.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "ossl.h"
66

7+
#ifndef OPENSSL_NO_SOCK
78
VALUE cSSLSession;
89
static VALUE eSSLSession;
910

@@ -299,6 +300,7 @@ static VALUE ossl_ssl_session_to_text(VALUE self)
299300
return ossl_membio2str(out);
300301
}
301302

303+
#endif /* !defined(OPENSSL_NO_SOCK) */
302304

303305
void Init_ossl_ssl_session(void)
304306
{
@@ -307,6 +309,7 @@ void Init_ossl_ssl_session(void)
307309
mSSL = rb_define_module_under(mOSSL, "SSL");
308310
eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
309311
#endif
312+
#ifndef OPENSSL_NO_SOCK
310313
cSSLSession = rb_define_class_under(mSSL, "Session", rb_cObject);
311314
eSSLSession = rb_define_class_under(cSSLSession, "SessionError", eOSSLError);
312315

@@ -324,4 +327,5 @@ void Init_ossl_ssl_session(void)
324327
rb_define_method(cSSLSession, "to_der", ossl_ssl_session_to_der, 0);
325328
rb_define_method(cSSLSession, "to_pem", ossl_ssl_session_to_pem, 0);
326329
rb_define_method(cSSLSession, "to_text", ossl_ssl_session_to_text, 0);
330+
#endif /* !defined(OPENSSL_NO_SOCK) */
327331
}

lib/openssl/ssl.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
=end
1212

1313
require "openssl/buffering"
14+
15+
if defined?(OpenSSL::SSL)
16+
1417
require "io/nonblock"
1518
require "ipaddr"
1619
require "socket"
@@ -540,3 +543,5 @@ def close
540543
end
541544
end
542545
end
546+
547+
end

test/openssl/test_pair.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require_relative 'utils'
33
require_relative 'ut_eof'
44

5-
if defined?(OpenSSL)
5+
if defined?(OpenSSL::SSL)
66

77
module OpenSSL::SSLPairM
88
def setup

test/openssl/test_ssl.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22
require_relative "utils"
33

4-
if defined?(OpenSSL)
4+
if defined?(OpenSSL::SSL)
55

66
class OpenSSL::TestSSL < OpenSSL::SSLTestCase
77
def test_bad_socket

test/openssl/test_ssl_session.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22
require_relative "utils"
33

4-
if defined?(OpenSSL)
4+
if defined?(OpenSSL::SSL)
55

66
class OpenSSL::TestSSLSession < OpenSSL::SSLTestCase
77
def test_session

0 commit comments

Comments
 (0)