Skip to content

Commit b0cfac6

Browse files
kateinoigakukunrhenium
authored andcommitted
Undefine OpenSSL::SSL for no socket platforms
This fixes a linkage error about `ossl_ssl_type` on platforms which do not have socket, like WASI. Even before this patch, some items are disabled under `OPENSSL_NO_SOCK` since ruby/ruby@ee22fad However, due to some new use of OpenSSL::SSL::Socket over the past few years, the build under `OPENSSL_NO_SOCK` had been broken. This patch guards whole `OpenSSL::SSL` items by `OPENSSL_NO_SOCK`. [ky: adjusted to apply on top of my previous commit that removed the OpenSSL::ExtConfig, and added a guard to lib/openssl/ssl.rb.]
1 parent eed3894 commit b0cfac6

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

ext/openssl/ossl_ssl.c

Lines changed: 3 additions & 5 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(TLS1_3_VERSION) && \
@@ -1537,7 +1538,6 @@ ossl_sslctx_flush_sessions(int argc, VALUE *argv, VALUE self)
15371538
/*
15381539
* SSLSocket class
15391540
*/
1540-
#ifndef OPENSSL_NO_SOCK
15411541
static inline int
15421542
ssl_started(SSL *ssl)
15431543
{
@@ -2565,6 +2565,7 @@ Init_ossl_ssl(void)
25652565
rb_mWaitWritable = rb_define_module_under(rb_cIO, "WaitWritable");
25662566
#endif
25672567

2568+
#ifndef OPENSSL_NO_SOCK
25682569
id_call = rb_intern_const("call");
25692570
ID_callback_state = rb_intern_const("callback_state");
25702571

@@ -2939,9 +2940,6 @@ Init_ossl_ssl(void)
29392940
* Document-class: OpenSSL::SSL::SSLSocket
29402941
*/
29412942
cSSLSocket = rb_define_class_under(mSSL, "SSLSocket", rb_cObject);
2942-
#ifdef OPENSSL_NO_SOCK
2943-
rb_define_method(cSSLSocket, "initialize", rb_f_notimplement, -1);
2944-
#else
29452943
rb_define_alloc_func(cSSLSocket, ossl_ssl_s_alloc);
29462944
rb_define_method(cSSLSocket, "initialize", ossl_ssl_initialize, -1);
29472945
rb_undef_method(cSSLSocket, "initialize_copy");
@@ -2976,7 +2974,6 @@ Init_ossl_ssl(void)
29762974
# ifndef OPENSSL_NO_NEXTPROTONEG
29772975
rb_define_method(cSSLSocket, "npn_protocol", ossl_ssl_npn_protocol, 0);
29782976
# endif
2979-
#endif
29802977

29812978
rb_define_const(mSSL, "VERIFY_NONE", INT2NUM(SSL_VERIFY_NONE));
29822979
rb_define_const(mSSL, "VERIFY_PEER", INT2NUM(SSL_VERIFY_PEER));
@@ -3138,4 +3135,5 @@ Init_ossl_ssl(void)
31383135
DefIVarID(io);
31393136
DefIVarID(context);
31403137
DefIVarID(hostname);
3138+
#endif /* !defined(OPENSSL_NO_SOCK) */
31413139
}

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

0 commit comments

Comments
 (0)