aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2017-11-04 03:50:40 +0900
committerGitHub <noreply@github.com>2017-11-04 03:50:40 +0900
commit819d7e5bed8695183607345f32092218e7e54194 (patch)
tree356ad0baa5bdd4ad85c39887dfd4ff9e28b1a264
parentd834e8614b9847c442c4ccd2cd7db322aa25a0d1 (diff)
parent7c4028a6ceb864df6392881b2e4a21b3200b0b77 (diff)
downloadruby-openssl-819d7e5bed8695183607345f32092218e7e54194.tar.gz
Merge pull request #165 from aeris/scsv
TLS Fallback Signaling Cipher Suite Value
-rw-r--r--ext/openssl/ossl_ssl.c23
-rw-r--r--test/test_ssl.rb53
2 files changed, 76 insertions, 0 deletions
diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c
index 59723dc6..8e3c0c42 100644
--- a/ext/openssl/ossl_ssl.c
+++ b/ext/openssl/ossl_ssl.c
@@ -1193,6 +1193,26 @@ ossl_sslctx_set_security_level(VALUE self, VALUE value)
return value;
}
+#ifdef SSL_MODE_SEND_FALLBACK_SCSV
+/*
+ * call-seq:
+ * ctx.enable_fallback_scsv() => nil
+ *
+ * Activate TLS_FALLBACK_SCSV for this context.
+ * See RFC 7507.
+ */
+static VALUE
+ossl_sslctx_enable_fallback_scsv(VALUE self)
+{
+ SSL_CTX *ctx;
+
+ GetSSLCTX(self, ctx);
+ SSL_CTX_set_mode(ctx, SSL_MODE_SEND_FALLBACK_SCSV);
+
+ return Qnil;
+}
+#endif
+
/*
* call-seq:
* ctx.session_add(session) -> true | false
@@ -2558,6 +2578,9 @@ Init_ossl_ssl(void)
rb_define_method(cSSLContext, "ecdh_curves=", ossl_sslctx_set_ecdh_curves, 1);
rb_define_method(cSSLContext, "security_level", ossl_sslctx_get_security_level, 0);
rb_define_method(cSSLContext, "security_level=", ossl_sslctx_set_security_level, 1);
+#ifdef SSL_MODE_SEND_FALLBACK_SCSV
+ rb_define_method(cSSLContext, "enable_fallback_scsv", ossl_sslctx_enable_fallback_scsv, 0);
+#endif
rb_define_method(cSSLContext, "setup", ossl_sslctx_setup, 0);
rb_define_alias(cSSLContext, "freeze", "setup");
diff --git a/test/test_ssl.rb b/test/test_ssl.rb
index 4f3df9dd..07b87259 100644
--- a/test/test_ssl.rb
+++ b/test/test_ssl.rb
@@ -1222,6 +1222,59 @@ end
end
end
+ def test_fallback_scsv
+ pend "Fallback SCSV is not supported" unless OpenSSL::SSL::SSLContext.method_defined?( :enable_fallback_scsv)
+
+ start_server do |port|
+ ctx = OpenSSL::SSL::SSLContext.new
+ ctx.max_version = OpenSSL::SSL::TLS1_2_VERSION
+ # Here is OK
+ # TLS1.2 supported and this is what we ask the first time
+ server_connect(port, ctx)
+ end
+
+ ctx_proc = proc { |ctx|
+ ctx.max_version = OpenSSL::SSL::TLS1_1_VERSION
+ }
+ start_server(ctx_proc: ctx_proc) do |port|
+ ctx = OpenSSL::SSL::SSLContext.new
+ ctx.enable_fallback_scsv
+ ctx.max_version = OpenSSL::SSL::TLS1_1_VERSION
+ # Here is OK too
+ # TLS1.2 not supported, fallback to TLS1.1 and signaling the fallback
+ # Server doesn't support better, so connection OK
+ server_connect(port, ctx)
+ end
+
+ # Here is not OK
+ # TLS1.2 is supported, fallback to TLS1.1 (downgrade attack) and signaling the fallback
+ # Server support better, so refuse the connection
+ sock1, sock2 = socketpair
+ begin
+ ctx1 = OpenSSL::SSL::SSLContext.new
+ s1 = OpenSSL::SSL::SSLSocket.new(sock1, ctx1)
+
+ ctx2 = OpenSSL::SSL::SSLContext.new
+ ctx2.enable_fallback_scsv
+ ctx2.max_version = OpenSSL::SSL::TLS1_1_VERSION
+ s2 = OpenSSL::SSL::SSLSocket.new(sock2, ctx2)
+ t = Thread.new {
+ assert_raise_with_message(OpenSSL::SSL::SSLError, /inappropriate fallback/) {
+ s2.connect
+ }
+ }
+
+ assert_raise_with_message(OpenSSL::SSL::SSLError, /inappropriate fallback/) {
+ s1.accept
+ }
+
+ assert t.join
+ ensure
+ sock1.close
+ sock2.close
+ end
+ end
+
def test_dh_callback
pend "TLS 1.2 is not supported" unless tls12_supported?