27
27
***** END LICENSE BLOCK *****/
28
28
package org .jruby .ext .openssl ;
29
29
30
- import java .io .ByteArrayInputStream ;
31
30
import java .io .Console ;
32
31
import java .io .IOException ;
33
- import java .io .InputStreamReader ;
34
32
import java .io .StringReader ;
35
33
import java .math .BigInteger ;
36
34
import java .security .*;
57
55
import org .jruby .runtime .ThreadContext ;
58
56
import org .jruby .runtime .builtin .IRubyObject ;
59
57
import org .jruby .runtime .Visibility ;
58
+ import org .jruby .util .ByteList ;
60
59
60
+ import org .jruby .ext .openssl .impl .CipherSpec ;
61
61
import org .jruby .ext .openssl .x509store .PEMInputOutput ;
62
+
62
63
import static org .jruby .ext .openssl .OpenSSL .*;
63
- import org .jruby .ext .openssl .impl .CipherSpec ;
64
- import org .jruby .util .ByteList ;
65
64
66
65
/**
67
66
* @author <a href="mailto:[email protected] ">Ola Bini</a>
@@ -111,14 +110,16 @@ public static IRubyObject read(final ThreadContext context, IRubyObject recv, IR
111
110
}
112
111
113
112
final RubyString str = readInitArg (context , data );
114
- Object key = null ;
113
+ KeyPair keyPair ;
115
114
// d2i_PrivateKey_bio
116
115
try {
117
- key = readPrivateKey (str , pass );
118
- } catch (IOException e ) { /* ignore */ }
116
+ keyPair = readPrivateKey (str , pass );
117
+ } catch (IOException e ) {
118
+ debugStackTrace (runtime , "PKey readPrivateKey" , e ); /* ignore */
119
+ keyPair = null ;
120
+ }
119
121
// PEM_read_bio_PrivateKey
120
- if (key != null ) {
121
- final KeyPair keyPair = (KeyPair ) key ;
122
+ if (keyPair != null ) {
122
123
final String alg = getAlgorithm (keyPair );
123
124
if ( "RSA" .equals (alg ) ) {
124
125
return new PKeyRSA (runtime , _PKey (runtime ).getClass ("RSA" ),
@@ -141,17 +142,23 @@ public static IRubyObject read(final ThreadContext context, IRubyObject recv, IR
141
142
try {
142
143
pubKey = PEMInputOutput .readRSAPublicKey (new StringReader (str .toString ()), null );
143
144
return new PKeyRSA (runtime , (RSAPublicKey ) pubKey );
144
- } catch (IOException e ) { /* ignore */ }
145
+ } catch (IOException e ) {
146
+ debugStackTrace (runtime , "PKey readRSAPublicKey" , e ); /* ignore */
147
+ }
145
148
try {
146
149
pubKey = PEMInputOutput .readDSAPublicKey (new StringReader (str .toString ()), null );
147
150
return new PKeyDSA (runtime , (DSAPublicKey ) pubKey );
148
- } catch (IOException e ) { /* ignore */ }
151
+ } catch (IOException e ) {
152
+ debugStackTrace (runtime , "PKey readDSAPublicKey" , e ); /* ignore */
153
+ }
149
154
150
155
final byte [] input = StringHelper .readX509PEM (context , str );
151
156
// d2i_PUBKEY_bio
152
157
try {
153
158
pubKey = org .jruby .ext .openssl .impl .PKey .readPublicKey (input );
154
- } catch (IOException |GeneralSecurityException e ) { /* ignore */ }
159
+ } catch (IOException |GeneralSecurityException e ) {
160
+ debugStackTrace (runtime , "PKey readPublicKey" , e ); /* ignore */
161
+ }
155
162
// PEM_read_bio_PUBKEY
156
163
if (pubKey == null ) {
157
164
try {
0 commit comments