Skip to content

Commit 56f887f

Browse files
committed
[refactor] drop security restriction JCE work-around
1 parent f4e3850 commit 56f887f

File tree

9 files changed

+12
-191
lines changed

9 files changed

+12
-191
lines changed

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

+10-8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.jruby.*;
3131
import org.jruby.anno.JRubyMethod;
3232
import org.jruby.anno.JRubyModule;
33+
import org.jruby.common.IRubyWarnings;
3334
import org.jruby.runtime.ThreadContext;
3435
import org.jruby.runtime.Visibility;
3536
import org.jruby.runtime.builtin.IRubyObject;
@@ -194,18 +195,14 @@ public static IRubyObject set_fips_mode(ThreadContext context, IRubyObject self,
194195
// internal (package-level) helpers :
195196

196197
/**
197-
* PRIMARILY MEANT FOR TESTING ONLY, USAGE IS DISCOURAGED!
198-
* @see org.jruby.ext.openssl.util.CryptoSecurity
198+
* @deprecated
199199
*/
200200
@JRubyMethod(name = "_disable_security_restrictions!", visibility = Visibility.PRIVATE, meta = true)
201201
public static IRubyObject _disable_security_restrictions(ThreadContext context, IRubyObject self) {
202-
Boolean unrestrict = org.jruby.ext.openssl.util.CryptoSecurity.unrestrictSecurity();
203-
Boolean allPerm = org.jruby.ext.openssl.util.CryptoSecurity.setAllPermissionPolicy();
204-
if ( unrestrict == null || allPerm == null ) return context.nil;
205-
return context.runtime.newBoolean( unrestrict && allPerm );
202+
warnDeprecated(context, "OpenSSL._disable_security_restrictions! is deprecated for removal");
203+
return context.nil;
206204
}
207205

208-
209206
private static boolean debug;
210207

211208
// on by default, warnings can be disabled using -Djruby.openssl.warn=false
@@ -251,7 +248,6 @@ public static void debugStackTrace(final Ruby runtime, final CharSequence msg, f
251248
}
252249
}
253250
}
254-
255251
static void warn(final ThreadContext context, final CharSequence msg) {
256252
if ( warn ) warn(context, RubyString.newString(context.runtime, msg));
257253
}
@@ -264,6 +260,12 @@ static void warn(final ThreadContext context, final IRubyObject msg) {
264260
if ( warn ) context.runtime.getModule("OpenSSL").callMethod(context, "warn", msg);
265261
}
266262

263+
public static void warnDeprecated(final ThreadContext context, final CharSequence msg) {
264+
if ( warn ) {
265+
context.runtime.getWarnings().warn(IRubyWarnings.ID.DEPRECATED_METHOD, msg.toString());
266+
}
267+
}
268+
267269
private static String javaVersion(final String def, final int len) {
268270
String javaVersion = SafePropertyAccessor.getProperty("java.version", def);
269271
if ( "0".equals(javaVersion) ) javaVersion = "1.7.0"; // Android

src/main/java/org/jruby/ext/openssl/util/CryptoSecurity.java

-151
This file was deleted.

src/test/ruby/dsa/test_dsa.rb

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ class TestDSA < TestCase
55

66
def setup
77
super
8-
self.class.disable_security_restrictions!
9-
require 'base64'
108
end
119

1210
def test_dsa_param_accessors

src/test/ruby/ec/test_ec.rb

-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ def convert16bit(key)
250250

251251
def setup
252252
super
253-
self.class.disable_security_restrictions!
254253

255254
@groups = []; @keys = []
256255

src/test/ruby/oaep/test_oaep.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class TestOaep < TestCase
55

66
def setup
77
super
8-
self.class.disable_security_restrictions!
8+
99
require 'base64'
1010
end
1111

src/test/ruby/rsa/test_rsa.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class TestRSA < TestCase
55

66
def setup
77
super
8-
self.class.disable_security_restrictions!
8+
99
require 'base64'
1010
end
1111

src/test/ruby/ssl/test_context.rb

-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ def test_context_minmax_version
110110
end if RUBY_VERSION > '2.3'
111111

112112
def test_context_ciphers
113-
self.class.disable_security_restrictions
114-
115113
context = OpenSSL::SSL::SSLContext.new
116114
context.ciphers = "ALL"
117115

src/test/ruby/test_cipher.rb

-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33

44
class TestCipher < TestCase
55

6-
def setup
7-
super
8-
self.class.disable_security_restrictions!
9-
end
10-
116
def test_cipher_new
127
OpenSSL::Cipher.new 'AES-256-CBC'
138
# NOTE: MRI 1.9.3 raises RuntimeError :

src/test/ruby/test_helper.rb

-20
Original file line numberDiff line numberDiff line change
@@ -101,26 +101,6 @@ def assert_not_same(expected, actual)
101101
end
102102
end
103103

104-
def self.disable_security_restrictions!; end # do nothing on MRI
105-
106-
@@security_restrictions = ''
107-
108-
def self.disable_security_restrictions!
109-
debug = OpenSSL.debug
110-
begin
111-
OpenSSL.debug = true
112-
#org.jruby.ext.openssl.util.CryptoSecurity.unrestrictSecurity
113-
#org.jruby.ext.openssl.util.CryptoSecurity.setAllPermissionPolicy
114-
@@security_restrictions = OpenSSL.send :_disable_security_restrictions!
115-
ensure
116-
OpenSSL.debug = debug
117-
end
118-
end if defined? JRUBY_VERSION
119-
120-
def self.disable_security_restrictions
121-
disable_security_restrictions! if @@security_restrictions.eql?('')
122-
end
123-
124104
def self.java8?; java_version.last.to_i == 8 end
125105

126106
def self.java_version

0 commit comments

Comments
 (0)