@@ -420,41 +420,50 @@ public RubyString value(final ThreadContext context) {
420420 if ( oid .equals ("2.5.29.35" ) ) { // authorityKeyIdentifier
421421 ASN1Encodable value = getRealValue ();
422422
423- if ( value instanceof ASN1OctetString ) {
423+ if (value instanceof ASN1OctetString ) {
424424 value = ASN1 .readObject ( ((ASN1OctetString ) value ).getOctets () );
425425 }
426426
427- final ByteList val = new ByteList (72 ); val . append ( keyid_ );
427+ final ByteList val = new ByteList (72 );
428428
429- if ( value instanceof ASN1Sequence ) {
429+ if (value instanceof ASN1Sequence ) {
430430 final ASN1Sequence seq = (ASN1Sequence ) value ;
431431 final int size = seq .size ();
432432 if ( size == 0 ) return RubyString .newEmptyString (runtime );
433433
434- ASN1Primitive keyid = seq .getObjectAt (0 ).toASN1Primitive ();
435- hexBytes ( keyidBytes (keyid ), val ).append ('\n' );
436-
437- for ( int i = 1 ; i < size ; i ++ ) {
438- final ASN1Encodable issuer = seq .getObjectAt (i );
439- // NOTE: blindly got OpenSSL tests passing (likely in-complete) :
440- if ( issuer instanceof ASN1TaggedObject ) {
441- ASN1Primitive obj = ((ASN1TaggedObject ) issuer ).getObject ();
442- switch ( ((ASN1TaggedObject ) issuer ).getTagNo () ) {
434+ for ( int i = 0 ; i < size ; i ++ ) {
435+ final ASN1Encodable enc = seq .getObjectAt (i );
436+ if (enc instanceof ASN1TaggedObject ) {
437+ ASN1Primitive obj = ((ASN1TaggedObject ) enc ).getObject ();
438+ switch ( ((ASN1TaggedObject ) enc ).getTagNo () ) {
439+ case 0 :
440+ ASN1Primitive keyid = obj ;
441+ val .append (keyid_ );
442+ hexBytes ( keyidBytes (keyid ), val );
443+ break ;
443444 case 1 :
444- if ( obj instanceof ASN1TaggedObject ) {
445- formatGeneralName (GeneralName .getInstance (obj ), val , true );
445+ GeneralName name ;
446+ if (obj instanceof ASN1Sequence ) { // GeneralNames -> toASN1Primitive()
447+ GeneralName [] names = GeneralNames .getInstance (obj ).getNames ();
448+ name = names .length > 0 ? names [0 ] : null ;
449+ } else {
450+ name = GeneralName .getInstance (obj );
446451 }
452+ if (name != null ) formatGeneralName (name , val , true );
447453 break ;
448454 case 2 : // serial
449455 val .append (new byte [] { 's' ,'e' ,'r' ,'i' ,'a' ,'l' ,':' });
450456 if (obj instanceof ASN1Integer ) {
451457 hexBytes ( ((ASN1Integer ) obj ).getValue ().toByteArray (), val );
452458 }
453459 else {
454- hexBytes ( ((ASN1OctetString ) obj ).getOctets (), val );
460+ hexBytes ( ((ASN1OctetString ) obj ).getOctets (), val );
455461 }
456462 break ;
457463 }
464+ } else if (size == 1 ) {
465+ ASN1Primitive keyid = enc .toASN1Primitive ();
466+ hexBytes ( keyidBytes (keyid ), val );
458467 }
459468 val .append ('\n' );
460469 }
0 commit comments