Skip to content

Commit 4f3894d

Browse files
authored
Merge pull request #222 from MariuszCwikla/issue_221_SSLContext_set_ciphers
Fix SSLContext#ciphers=
2 parents 4b1ad4a + 2047f4d commit 4f3894d

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
@@ -562,10 +562,16 @@ static Collection<Def> matchingCiphers(final String cipherString, final String[]
562562

563563
private static Collection<Def> matchingExact(final String name, final String[] all,
564564
final boolean setSuite) {
565-
final Def pattern = Definitions.get(name);
565+
Def pattern = Definitions.get(name);
566566
if ( pattern != null ) {
567567
return matchingPattern(pattern, all, true, setSuite);
568568
}
569+
else {
570+
Def cipher = CipherNames.get(name);
571+
if (cipher != null) {
572+
return Collections.singleton(cipher);
573+
}
574+
}
569575
return null; // Collections.emptyList();
570576
}
571577

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,6 +184,39 @@ 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
def test_set_ciphers_empty_array
188221
context = OpenSSL::SSL::SSLContext.new
189222
ex = assert_raise(OpenSSL::SSL::SSLError) do

0 commit comments

Comments
 (0)