Skip to content

Commit dd78267

Browse files
committed
[refactor] cleanup + more OP_NO_xxx filtering
1 parent 817cfed commit dd78267

File tree

4 files changed

+14
-49
lines changed

4 files changed

+14
-49
lines changed

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

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,7 @@ private static SSLEngine dummySSLEngine(final String protocol) throws GeneralSec
620620
}
621621

622622
// should keep SSLContext as a member for introducin SSLSession. later...
623-
final SSLEngine createSSLEngine(String peerHost, int peerPort)
624-
throws NoSuchAlgorithmException, KeyManagementException {
623+
final SSLEngine createSSLEngine(String peerHost, int peerPort) {
625624
final SSLEngine engine;
626625
// an empty peerHost implies no SNI (RFC 3546) support requested
627626
if ( peerHost == null || peerHost.length() == 0 ) {
@@ -639,12 +638,9 @@ final SSLEngine createSSLEngine(String peerHost, int peerPort)
639638
}
640639

641640
private String[] getCipherSuites(final String[] supported) {
642-
Collection<CipherStrings.Def> cipherDefs =
643-
CipherStrings.matchingCiphers(this.ciphers, supported, true);
641+
Collection<CipherStrings.Def> cipherDefs = CipherStrings.matchingCiphers(this.ciphers, supported, true);
644642
final String[] result = new String[ cipherDefs.size() ]; int i = 0;
645-
for ( CipherStrings.Def def : cipherDefs ) {
646-
result[ i++ ] = def.getCipherSuite();
647-
}
643+
for ( CipherStrings.Def def : cipherDefs ) result[ i++ ] = def.getCipherSuite();
648644
return result;
649645
}
650646

@@ -655,15 +651,12 @@ private String[] getEnabledProtocols(final SSLEngine engine) {
655651
final String[] engineProtocols = engine.getEnabledProtocols();
656652
final List<String> protocols = new ArrayList<String>(enabledProtocols.length);
657653
for ( final String enabled : enabledProtocols ) {
658-
if (((options & SSL.OP_NO_SSLv2) != 0) && enabled.equals("SSLv2")) {
659-
continue;
660-
}
661-
if (((options & SSL.OP_NO_SSLv3) != 0) && enabled.equals("SSLv3")) {
662-
continue;
663-
}
664-
if (((options & SSL.OP_NO_TLSv1) != 0) && enabled.equals("TLSv1")) {
665-
continue;
666-
}
654+
if (((options & OP_NO_SSLv2) != 0) && enabled.equals("SSLv2")) continue;
655+
if (((options & OP_NO_SSLv3) != 0) && enabled.equals("SSLv3")) continue;
656+
if (((options & OP_NO_TLSv1) != 0) && enabled.equals("TLSv1")) continue;
657+
if (((options & OP_NO_TLSv1_1) != 0) && enabled.equals("TLSv1.1")) continue;
658+
if (((options & OP_NO_TLSv1_2) != 0) && enabled.equals("TLSv1.2")) continue;
659+
if (((options & OP_NO_TLSv1_3) != 0) && enabled.equals("TLSv1.3")) continue;
667660
for ( final String allowed : engineProtocols ) {
668661
if ( allowed.equals(enabled) ) protocols.add(allowed);
669662
}

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

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,7 @@ private IRubyObject fallback_set_io_nonblock_checked(ThreadContext context, Ruby
208208
return context.nil;
209209
}
210210

211-
private SSLEngine ossl_ssl_setup(final ThreadContext context)
212-
throws NoSuchAlgorithmException, KeyManagementException {
211+
private SSLEngine ossl_ssl_setup(final ThreadContext context) {
213212
SSLEngine engine = this.engine;
214213
if ( engine != null ) return engine;
215214

@@ -301,16 +300,6 @@ private IRubyObject connectImpl(final ThreadContext context, final boolean block
301300
forceClose();
302301
throw newSSLErrorFromHandshake(context.runtime, e);
303302
}
304-
catch (NoSuchAlgorithmException e) {
305-
debugStackTrace(context.runtime, e);
306-
forceClose();
307-
throw newSSLError(context.runtime, e);
308-
}
309-
catch (KeyManagementException e) {
310-
debugStackTrace(context.runtime, e);
311-
forceClose();
312-
throw newSSLError(context.runtime, e);
313-
}
314303
catch (IOException e) {
315304
//debugStackTrace(context.runtime, e);
316305
forceClose();
@@ -391,14 +380,6 @@ private IRubyObject acceptImpl(final ThreadContext context, final boolean blocki
391380
}
392381
throw newSSLErrorFromHandshake(context.runtime, e);
393382
}
394-
catch (NoSuchAlgorithmException e) {
395-
debugStackTrace(context.runtime, e);
396-
throw newSSLError(context.runtime, e);
397-
}
398-
catch (KeyManagementException e) {
399-
debugStackTrace(context.runtime, e);
400-
throw newSSLError(context.runtime, e);
401-
}
402383
catch (IOException e) {
403384
debugStackTrace(context.runtime, e);
404385
throw newSSLError(context.runtime, e);

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,6 @@ static RubyString readInput(final ThreadContext context, final IRubyObject arg)
129129
static final ByteList NEW_LINE = new ByteList(new byte[] { '\n' }, false);
130130
static final ByteList COMMA_SPACE = new ByteList(new byte[] { ',',' ' }, false);
131131

132-
static void gsub(final Ruby runtime, final ByteList str, final byte match, final byte replace) {
133-
final int begin = str.getBegin();
134-
final int slen = str.getRealSize();
135-
final byte[] bytes = str.getUnsafeBytes();
136-
for ( int i = begin; i < begin + slen; i++ ) {
137-
if ( bytes[i] == match ) bytes[i] = replace;
138-
}
139-
}
140-
141132
static final char[] S20 = new char[] {
142133
' ',' ',' ',' ', ' ',' ',' ',' ',
143134
' ',' ',' ',' ', ' ',' ',' ',' ',

src/main/java/org/jruby/ext/openssl/x509store/X509Utils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,11 @@ else if (maybeCertFile != null && new File(maybeCertFile).exists()) {
421421
public static final int V_FLAG_STRICT = 0x20;
422422
public static final int V_FLAG_X509_STRICT = 0x20;
423423
public static final int V_FLAG_ALLOW_PROXY_CERTS = 0x40;
424-
public static final int V_FLAG_POLICY_CHECK = 0x80;
425-
public static final int V_FLAG_EXPLICIT_POLICY = 0x100;
424+
public static final int V_FLAG_POLICY_CHECK = 0x80;
425+
public static final int V_FLAG_EXPLICIT_POLICY = 0x100;
426426
public static final int V_FLAG_INHIBIT_ANY = 0x200;
427-
public static final int V_FLAG_INHIBIT_MAP = 0x400;
428-
public static final int V_FLAG_NOTIFY_POLICY = 0x800;
427+
public static final int V_FLAG_INHIBIT_MAP = 0x400;
428+
public static final int V_FLAG_NOTIFY_POLICY = 0x800;
429429

430430
public static final int VP_FLAG_DEFAULT = 0x1;
431431
public static final int VP_FLAG_OVERWRITE = 0x2;

0 commit comments

Comments
 (0)