Skip to content

Commit acbfa26

Browse files
committed
setup OpenSSL::ExtConfig emulation - mostly (conservative) guesses
1 parent dcc9543 commit acbfa26

File tree

3 files changed

+47
-8
lines changed

3 files changed

+47
-8
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2017 Karol Bucek.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*/
8+
package org.jruby.ext.openssl;
9+
10+
import org.jruby.Ruby;
11+
import org.jruby.RubyModule;
12+
13+
/**
14+
* OpenSSL::ExtConfig (emulation)
15+
*
16+
* @author kares
17+
*/
18+
public class ExtConfig {
19+
20+
static void create(Ruby runtime, RubyModule OpenSSL) {
21+
RubyModule ExtConfig = OpenSSL.defineModuleUnder("ExtConfig");
22+
ExtConfig.defineAnnotatedMethods(ExtConfig.class);
23+
24+
ExtConfig.setConstant("OPENSSL_NO_SOCK", runtime.getNil()); // true/false (default) on MRI
25+
// TODO: we really should attempt to detect whether we support this :
26+
ExtConfig.setConstant("TLS_DH_anon_WITH_AES_256_GCM_SHA384", runtime.getFalse());
27+
ExtConfig.setConstant("HAVE_TLSEXT_HOST_NAME", runtime.getTrue());
28+
}
29+
30+
}

src/main/java/org/jruby/ext/openssl/OpenSSL.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,14 @@ public static void createOpenSSL(final Ruby runtime) {
6767
final String warn = SafePropertyAccessor.getProperty("jruby.openssl.warn");
6868
if ( warn != null ) OpenSSL.warn = Boolean.parseBoolean(warn);
6969

70+
Config.createConfig(runtime, _OpenSSL);
71+
ExtConfig.create(runtime, _OpenSSL);
7072
PKey.createPKey(runtime, _OpenSSL);
7173
BN.createBN(runtime, _OpenSSL);
7274
Digest.createDigest(runtime, _OpenSSL);
7375
Cipher.createCipher(runtime, _OpenSSL);
7476
Random.createRandom(runtime, _OpenSSL);
7577
HMAC.createHMAC(runtime, _OpenSSL);
76-
Config.createConfig(runtime, _OpenSSL);
7778
ASN1.createASN1(runtime, _OpenSSL);
7879
X509.createX509(runtime, _OpenSSL);
7980
NetscapeSPKI.createNetscapeSPKI(runtime, _OpenSSL);
@@ -96,8 +97,6 @@ public static void createOpenSSL(final Ruby runtime) {
9697
// OpenSSL::FIPS: false
9798

9899
final byte[] version = { '1','.','1','.','0' };
99-
final boolean ruby18 = runtime.getInstanceConfig().getCompatVersion() == CompatVersion.RUBY1_8;
100-
if ( ruby18 ) version[2] = '0'; // 1.0.0 compatible on 1.8
101100

102101
_OpenSSL.setConstant("VERSION", StringHelper.newString(runtime, version));
103102

@@ -115,11 +114,9 @@ public static void createOpenSSL(final Ruby runtime) {
115114
final RubyString VERSION;
116115
_OpenSSL.setConstant("OPENSSL_VERSION", VERSION = runtime.newString(OPENSSL_VERSION));
117116
_OpenSSL.setConstant("OPENSSL_VERSION_NUMBER", runtime.newFixnum(OPENSSL_VERSION_NUMBER));
118-
if ( ! ruby18 ) {
119-
// MRI 2.3 tests do: /\AOpenSSL +0\./ !~ OpenSSL::OPENSSL_LIBRARY_VERSION
120-
_OpenSSL.setConstant("OPENSSL_LIBRARY_VERSION", VERSION);
121-
_OpenSSL.setConstant("OPENSSL_FIPS", runtime.getFalse());
122-
}
117+
// MRI 2.3 tests do: /\AOpenSSL +0\./ !~ OpenSSL::OPENSSL_LIBRARY_VERSION
118+
_OpenSSL.setConstant("OPENSSL_LIBRARY_VERSION", VERSION);
119+
_OpenSSL.setConstant("OPENSSL_FIPS", runtime.getFalse());
123120
}
124121

125122
static RubyClass _OpenSSLError(final Ruby runtime) {

src/test/ruby/ssl/test_ssl.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ def test_post_connection_check
8282
end
8383
end
8484

85+
def test_post_connect_check_with_anon_ciphers
86+
start_server(OpenSSL::SSL::VERIFY_NONE, true, { use_anon_cipher: true }) { |server, port|
87+
ctx = OpenSSL::SSL::SSLContext.new
88+
ctx.ciphers = "aNULL"
89+
server_connect(port, ctx) { |ssl|
90+
msg = "Peer verification enabled, but no certificate received. Anonymous cipher suite " \
91+
"ADH-AES256-GCM-SHA384 was negotiated. Anonymous suites must be disabled to use peer verification."
92+
assert_raise_with_message(OpenSSL::SSL::SSLError, msg){ssl.post_connection_check("localhost.localdomain")}
93+
}
94+
}
95+
end if OpenSSL::ExtConfig::TLS_DH_anon_WITH_AES_256_GCM_SHA384
96+
8597
def test_ssl_version_tlsv1
8698
ctx_proc = Proc.new do |ctx|
8799
ctx.ssl_version = "TLSv1"

0 commit comments

Comments
 (0)