Skip to content

Commit 0045ab7

Browse files
MSNexploderkares
authored andcommitted
move "DEFAULT" handling right into CipherStrings (#136)
move "DEFAULT" special case handling further down and match OpenSSL behaviour fixes jruby/jruby#2193
1 parent 2b883bd commit 0045ab7

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,22 @@ static Collection<Def> matchingCiphers(final String cipherString, final String[]
488488
final List<Def> matchedList = new LinkedList<Def>();
489489
Set<Def> removed = null;
490490

491-
for ( final String part : cipherString.split("[:, ]+") ) {
491+
/*
492+
* If the rule_string begins with DEFAULT, apply the default rule
493+
* before using the (possibly available) additional rules.
494+
* (Matching OpenSSL behaviour)
495+
*/
496+
int offset = 0;
497+
final String[] parts = cipherString.split("[:, ]+");
498+
if ( parts.length >= 1 && "DEFAULT".equals(parts[0]) ) {
499+
final Collection<Def> matching = matchingCiphers(SSL_DEFAULT_CIPHER_LIST, all, setSuite);
500+
matchedList.addAll(matching);
501+
offset = offset + 1;
502+
}
503+
504+
for ( int i = offset; i < parts.length; i++ ) {
505+
final String part = parts[i];
506+
492507
if ( part.equals("@STRENGTH") ) {
493508
Collections.sort(matchedList); continue;
494509
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,6 @@ else if ( ciphers instanceof RubyArray ) {
499499
}
500500
else {
501501
this.ciphers = ciphers.asString().toString();
502-
if ( "DEFAULT".equals( this.ciphers ) ) {
503-
this.ciphers = CipherStrings.SSL_DEFAULT_CIPHER_LIST;
504-
}
505502
}
506503
if ( matchedCiphers(context).isEmpty() ) {
507504
throw newSSLError(context.runtime, "no cipher match");

src/test/ruby/ssl/test_context.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ def test_setup
4747
assert ex.message =~ /\u{ff33 ff33 ff2c}/
4848
end
4949

50+
def test_default_handling # GH-2193 JRuby
51+
ctx = OpenSSL::SSL::SSLContext.new
52+
assert_nothing_raised { ctx.ciphers = "DEFAULT:!aNULL" }
53+
end
54+
5055
def test_verify_mode
5156
context = OpenSSL::SSL::SSLContext.new
5257
assert_nil context.verify_mode

0 commit comments

Comments
 (0)