Skip to content

Commit 6b4f756

Browse files
committed
Fix SSLContext#ciphers=
1 parent e50c04b commit 6b4f756

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,16 @@ static Collection<Def> matchingCiphers(final String cipherString, final String[]
560560

561561
private static Collection<Def> matchingExact(final String name, final String[] all,
562562
final boolean setSuite) {
563-
final Def pattern = Definitions.get(name);
563+
Def pattern = Definitions.get(name);
564564
if ( pattern != null ) {
565565
return matchingPattern(pattern, all, true, setSuite);
566566
}
567+
else {
568+
Def cipher = CipherNames.get(name);
569+
if (cipher != null) {
570+
return Collections.singleton(cipher);
571+
}
572+
}
567573
return null; // Collections.emptyList();
568574
}
569575

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,11 @@ else if ( ciphers instanceof RubyArray ) {
518518
StringBuilder cipherStr = new StringBuilder();
519519
String sep = "";
520520
for ( int i = 0; i < ciphs.size(); i++ ) {
521-
cipherStr.append(sep).append( ciphs.eltInternal(i).toString() );
521+
IRubyObject elem = ciphs.eltInternal(i);
522+
if (elem instanceof RubyArray) {
523+
elem = ((RubyArray) elem).eltInternal(0);
524+
}
525+
cipherStr.append(sep).append( elem.toString() );
522526
sep = ":";
523527
}
524528
this.ciphers = cipherStr.toString();

src/test/ruby/ssl/test_context.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,37 @@ def test_context_ciphers
184184
assert_equal [], diff
185185
end unless java7? # would need to filter out stuff such as ECDHE-RSA-AES128-GCM-SHA256
186186

187+
def test_set_ciphers_by_group_name
188+
context = OpenSSL::SSL::SSLContext.new
189+
context.ciphers = "AES"
190+
191+
actual = context.ciphers.map { |cipher| cipher[0]}
192+
assert actual.include?("ECDHE-RSA-AES128-SHA")
193+
assert actual.include?("ECDHE-ECDSA-AES128-SHA")
194+
assert actual.include?("AES128-SHA")
195+
end
196+
197+
def test_set_ciphers_by_cipher_name
198+
context = OpenSSL::SSL::SSLContext.new
199+
context.ciphers = "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384"
200+
actual = context.ciphers.map { |cipher| cipher[0]}
201+
assert actual.include?("ECDHE-ECDSA-AES128-GCM-SHA256")
202+
assert actual.include?("ECDHE-ECDSA-AES256-GCM-SHA384")
203+
end
204+
205+
def test_set_ciphers_by_array_of_names
206+
context = OpenSSL::SSL::SSLContext.new
207+
context.ciphers = ["ECDHE-ECDSA-AES128-GCM-SHA256", "ECDHE-ECDSA-AES256-GCM-SHA384"]
208+
actual = context.ciphers.map { |cipher| cipher[0]}
209+
assert actual.include?("ECDHE-ECDSA-AES128-GCM-SHA256")
210+
assert actual.include?("ECDHE-ECDSA-AES256-GCM-SHA384")
211+
end
212+
213+
def test_set_ciphers_by_array_of_name_version_bits
214+
context = OpenSSL::SSL::SSLContext.new
215+
context.ciphers = [["ECDHE-ECDSA-AES128-GCM-SHA256", "TLSv1.2", 128, 128]]
216+
actual = context.ciphers.map { |cipher| cipher[0]}
217+
assert actual.include?("ECDHE-ECDSA-AES128-GCM-SHA256")
218+
end
219+
187220
end

0 commit comments

Comments
 (0)