44
44
import org .bouncycastle .asn1 .ASN1ObjectIdentifier ;
45
45
import org .bouncycastle .asn1 .pkcs .Attribute ;
46
46
import org .bouncycastle .asn1 .x500 .X500Name ;
47
+ import org .bouncycastle .asn1 .x509 .AlgorithmIdentifier ;
48
+ import org .bouncycastle .operator .DefaultSignatureNameFinder ;
47
49
48
50
import org .jruby .Ruby ;
49
51
import org .jruby .RubyArray ;
53
55
import org .jruby .RubyString ;
54
56
import org .jruby .anno .JRubyMethod ;
55
57
import org .jruby .exceptions .RaiseException ;
58
+ import org .jruby .ext .openssl .impl .ASN1Registry ;
56
59
import org .jruby .ext .openssl .x509store .PEMInputOutput ;
57
60
import org .jruby .runtime .Arity ;
58
61
import org .jruby .runtime .ThreadContext ;
@@ -91,7 +94,7 @@ static RubyClass _RequestError(final Ruby runtime) {
91
94
92
95
public X509Request (Ruby runtime , RubyClass type ) {
93
96
super (runtime , type );
94
- attributes = new ArrayList <X509Attribute >(4 );
97
+ attributes = new ArrayList <>(4 );
95
98
}
96
99
97
100
@ JRubyMethod (name = "initialize" , rest = true , visibility = Visibility .PRIVATE )
@@ -286,8 +289,10 @@ public IRubyObject set_subject(final IRubyObject val) {
286
289
287
290
@ JRubyMethod
288
291
public IRubyObject signature_algorithm (final ThreadContext context ) {
289
- warn (context , "WARNING: unimplemented method called: OpenSSL::X509::Request#signature_algorithm" );
290
- return context .runtime .getNil ();
292
+ AlgorithmIdentifier signatureAlgId = request == null ? null : request .getSignatureAlgorithm ();
293
+ if (signatureAlgId == null ) return context .runtime .newString ("NULL" );
294
+ final String name = ASN1Registry .o2a (signatureAlgId .getAlgorithm ());
295
+ return context .runtime .newString (name == null ? "" : name );
291
296
}
292
297
293
298
@ JRubyMethod
@@ -316,7 +321,8 @@ public IRubyObject sign(final ThreadContext context,
316
321
317
322
final String digAlg = ((Digest ) digest ).getShortAlgorithm ();
318
323
try {
319
- request = null ; getRequest ().sign ( privateKey , digAlg );
324
+ request = null ;
325
+ getRequest ().sign ( privateKey , digAlg );
320
326
}
321
327
catch (InvalidKeyException e ) {
322
328
debug (runtime , "X509Request#sign invalid key:" , e );
@@ -330,15 +336,14 @@ public IRubyObject sign(final ThreadContext context,
330
336
}
331
337
332
338
private List <Attribute > newAttributesImpl (final ThreadContext context ) {
333
- ArrayList <Attribute > attrs = new ArrayList <Attribute >(attributes .size ());
339
+ ArrayList <Attribute > attrs = new ArrayList <>(attributes .size ());
334
340
for ( X509Attribute attribute : attributes ) {
335
341
attrs .add ( newAttributeImpl (context , attribute ) );
336
342
}
337
343
return attrs ;
338
344
}
339
345
340
- private Attribute newAttributeImpl (final ThreadContext context ,
341
- final X509Attribute attribute ) {
346
+ private static Attribute newAttributeImpl (final ThreadContext context , final X509Attribute attribute ) {
342
347
return Attribute .getInstance ( attribute .toASN1 ( context ) );
343
348
}
344
349
@@ -372,7 +377,7 @@ public IRubyObject attributes() {
372
377
return getRuntime ().newArray (attributes );
373
378
}
374
379
375
- @ JRubyMethod (name = "attributes=" )
380
+ @ JRubyMethod (name = "attributes=" )
376
381
public IRubyObject set_attributes (final ThreadContext context ,final IRubyObject attributes ) {
377
382
this .attributes .clear ();
378
383
final RubyArray attrs = (RubyArray ) attributes ;
0 commit comments