Skip to content

Fix SSLContext#ciphers= #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/main/java/org/jruby/ext/openssl/CipherStrings.java
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,16 @@ static Collection<Def> matchingCiphers(final String cipherString, final String[]

private static Collection<Def> matchingExact(final String name, final String[] all,
final boolean setSuite) {
final Def pattern = Definitions.get(name);
Def pattern = Definitions.get(name);
if ( pattern != null ) {
return matchingPattern(pattern, all, true, setSuite);
}
else {
Def cipher = CipherNames.get(name);
if (cipher != null) {
return Collections.singleton(cipher);
}
}
return null; // Collections.emptyList();
}

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/jruby/ext/openssl/SSLContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,11 @@ else if ( ciphers instanceof RubyArray ) {
StringBuilder cipherStr = new StringBuilder();
String sep = "";
for ( int i = 0; i < ciphs.size(); i++ ) {
cipherStr.append(sep).append( ciphs.eltInternal(i).toString() );
IRubyObject elem = ciphs.eltInternal(i);
if (elem instanceof RubyArray) {
elem = ((RubyArray) elem).eltInternal(0);
}
cipherStr.append(sep).append( elem.toString() );
sep = ":";
}
this.ciphers = cipherStr.toString();
Expand Down
33 changes: 33 additions & 0 deletions src/test/ruby/ssl/test_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,39 @@ def test_context_ciphers
assert_equal [], diff
end unless java7? # would need to filter out stuff such as ECDHE-RSA-AES128-GCM-SHA256

def test_set_ciphers_by_group_name
context = OpenSSL::SSL::SSLContext.new
context.ciphers = "AES"

actual = context.ciphers.map { |cipher| cipher[0]}
assert actual.include?("ECDHE-RSA-AES128-SHA")
assert actual.include?("ECDHE-ECDSA-AES128-SHA")
assert actual.include?("AES128-SHA")
end

def test_set_ciphers_by_cipher_name
context = OpenSSL::SSL::SSLContext.new
context.ciphers = "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384"
actual = context.ciphers.map { |cipher| cipher[0]}
assert actual.include?("ECDHE-ECDSA-AES128-GCM-SHA256")
assert actual.include?("ECDHE-ECDSA-AES256-GCM-SHA384")
end

def test_set_ciphers_by_array_of_names
context = OpenSSL::SSL::SSLContext.new
context.ciphers = ["ECDHE-ECDSA-AES128-GCM-SHA256", "ECDHE-ECDSA-AES256-GCM-SHA384"]
actual = context.ciphers.map { |cipher| cipher[0]}
assert actual.include?("ECDHE-ECDSA-AES128-GCM-SHA256")
assert actual.include?("ECDHE-ECDSA-AES256-GCM-SHA384")
end

def test_set_ciphers_by_array_of_name_version_bits
context = OpenSSL::SSL::SSLContext.new
context.ciphers = [["ECDHE-ECDSA-AES128-GCM-SHA256", "TLSv1.2", 128, 128]]
actual = context.ciphers.map { |cipher| cipher[0]}
assert actual.include?("ECDHE-ECDSA-AES128-GCM-SHA256")
end

def test_set_ciphers_empty_array
context = OpenSSL::SSL::SSLContext.new
ex = assert_raise(OpenSSL::SSL::SSLError) do
Expand Down