@@ -99,46 +99,28 @@ def assert_not_same(expected, actual)
99
99
end
100
100
end
101
101
102
- def self . disable_security_restrictions! ; end # do nothing on MRI
102
+ def self . disable_security_restrictions! ; @@security_restrictions = nil end # do nothing on MRI
103
103
104
- @@security_restrictions = nil
104
+ @@security_restrictions = ''
105
105
106
106
def self . disable_security_restrictions!
107
- jce_security_class = java . lang . Class . for_name ( 'javax.crypto.JceSecurity' )
108
- restricted_field = jce_security_class . getDeclaredField ( 'isRestricted' )
109
- restricted_field . accessible = true
110
- @@security_restrictions = restricted_field . getBoolean ( nil )
111
- return false unless @@security_restrictions
112
-
113
- if java . lang . reflect . Modifier . isFinal restricted_field . modifiers
114
- field_class = java . lang . Class . for_name ( 'java.lang.reflect.Field' )
115
- # NOTE: this no longer works since 8u111 as it's using unsafe :
116
- # Can not set static final boolean field javax.crypto.JceSecurity.isRestricted to (boolean)false
117
- # sun.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(sun/reflect/UnsafeFieldAccessorImpl.java:76)
118
- # sun.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(sun/reflect/UnsafeFieldAccessorImpl.java:84)
119
- # sun.reflect.UnsafeQualifiedStaticBooleanFieldAccessorImpl.setBoolean(sun/reflect/UnsafeQualifiedStaticBooleanFieldAccessorImpl.java:93)
120
- # java.lang.reflect.Field.setBoolean(java/lang/reflect/Field.java:801)
121
- mods_field = field_class . getDeclaredField ( 'modifiers' )
122
- mods_field . accessible = true
123
-
124
- # restricted_field = jce_security_class.getDeclaredField('isRestricted')
125
- # restricted_field.accessible = true
126
- mods_field . setInt restricted_field , ( ~java . lang . reflect . Modifier ::FINAL & restricted_field . modifiers )
107
+ debug = OpenSSL . debug
108
+ begin
109
+ OpenSSL . debug = true
110
+ #org.jruby.ext.openssl.util.CryptoSecurity.unrestrictSecurity
111
+ #org.jruby.ext.openssl.util.CryptoSecurity.setAllPermissionPolicy
112
+ @@security_restrictions = OpenSSL . send :_disable_security_restrictions!
113
+ ensure
114
+ OpenSSL . debug = debug
127
115
end
128
- restricted_field . setBoolean nil , false ; return true
129
- rescue Java ::JavaLang ::ClassNotFoundException => e
130
- warn "failed to disable JCE security restrictions: #{ e . inspect } " ; nil
131
- rescue Java ::JavaLang ::NoSuchFieldException => e # Java 6
132
- warn "failed to disable JCE security restrictions: #{ e . inspect } " ; nil
133
- rescue Java ::JavaLang ::IllegalAccessException => e
134
- warn "failed to disable JCE security restrictions: #{ e . inspect } " ; nil
135
- rescue NameError => e
136
- warn "failed to disable JCE security restrictions: #{ e . inspect } " ; nil
137
116
end if defined? JRUBY_VERSION
138
117
118
+ def self . disable_security_restrictions
119
+ disable_security_restrictions! if @@security_restrictions . eql? ( '' )
120
+ end
121
+
139
122
def self . security_restrictions?
140
- disable_security_restrictions! if @@security_restrictions . nil?
141
- @@security_restrictions
123
+ disable_security_restrictions ; return @@security_restrictions
142
124
end
143
125
144
126
def self . java6? ; java_version . last . to_i == 6 end
@@ -155,8 +137,7 @@ def jruby?; self.class.jruby? end
155
137
156
138
private
157
139
158
- def issue_cert ( dn , key , serial , not_before , not_after , extensions ,
159
- issuer , issuer_key , digest )
140
+ def issue_cert ( dn , key , serial , not_before , not_after , extensions , issuer , issuer_key , digest )
160
141
cert = OpenSSL ::X509 ::Certificate . new
161
142
issuer = cert unless issuer
162
143
issuer_key = key unless issuer_key
0 commit comments