File tree Expand file tree Collapse file tree
main/java/org/jruby/ext/openssl Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -202,19 +202,25 @@ public IRubyObject set_default_paths(final ThreadContext context) {
202202 }
203203
204204 @ JRubyMethod
205- public X509Store add_cert (final IRubyObject cert ) {
206- X509AuxCertificate auxCert = cert instanceof X509Cert ? ((X509Cert ) cert ).getAuxCert () : null ;
205+ public X509Store add_cert (final ThreadContext context , final IRubyObject cert ) {
206+ if (!(cert instanceof X509Cert )) {
207+ throw context .runtime .newTypeError (cert , _X509 (context .runtime ).getClass ("Certificate" ));
208+ }
209+ X509AuxCertificate auxCert = ((X509Cert ) cert ).getAuxCert ();
207210 if ( store .addCertificate (auxCert ) != 1 ) {
208- throw newStoreError (getRuntime () , X509Error .getLastErrorMessage ());
211+ throw newStoreError (context . runtime , X509Error .getLastErrorMessage ());
209212 }
210213 return this ;
211214 }
212215
213216 @ JRubyMethod
214- public X509Store add_crl (final IRubyObject crl ) {
215- java .security .cert .X509CRL jCRL = (crl instanceof X509CRL ) ? ((X509CRL ) crl ).getCRL () : null ;
217+ public X509Store add_crl (final ThreadContext context , final IRubyObject crl ) {
218+ if (!(crl instanceof X509CRL )) {
219+ throw context .runtime .newTypeError (crl , _X509 (context .runtime ).getClass ("CRL" ));
220+ }
221+ java .security .cert .X509CRL jCRL = ((X509CRL ) crl ).getCRL ();
216222 if ( store .addCRL (jCRL ) != 1 ) {
217- throw newStoreError (getRuntime () , X509Error .getLastErrorMessage ());
223+ throw newStoreError (context . runtime , X509Error .getLastErrorMessage ());
218224 }
219225 return this ;
220226 }
Original file line number Diff line number Diff line change @@ -121,6 +121,19 @@ def test_store_context_verify_raises_on_reuse
121121 assert_raise ( OpenSSL ::X509 ::StoreError ) { ctx . verify }
122122 end
123123
124+ # CRuby raises TypeError (not StoreError) for wrong argument types
125+ def test_add_cert_type_check
126+ store = OpenSSL ::X509 ::Store . new
127+ assert_raise ( TypeError ) { store . add_cert ( "not a cert" ) }
128+ assert_raise ( TypeError ) { store . add_cert ( nil ) }
129+ end
130+
131+ def test_add_crl_type_check
132+ store = OpenSSL ::X509 ::Store . new
133+ assert_raise ( TypeError ) { store . add_crl ( "not a crl" ) }
134+ assert_raise ( TypeError ) { store . add_crl ( nil ) }
135+ end
136+
124137 def test_use_non_existing_cert_file
125138 ENV [ 'SSL_CERT_FILE' ] = 'non-existing-file.crt'
126139 store = OpenSSL ::X509 ::Store . new
You can’t perform that action at this time.
0 commit comments