Skip to content

Commit d88b4ac

Browse files
Brice Figureauheadius
authored andcommitted
Fix PEM format parsing of CSR
Signed-off-by: Charles Oliver Nutter <[email protected]>
1 parent 3e2ba30 commit d88b4ac

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/java/org/jruby/ext/openssl/Request.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,26 @@ public Object call() throws GeneralSecurityException {
138138
}
139139
ASN1Set in_attrs = req.getCertificationRequestInfo().getAttributes();
140140
for(Enumeration enm = in_attrs.getObjects();enm.hasMoreElements();) {
141-
DERSet obj = (DERSet)enm.nextElement();
142-
for(Enumeration enm2 = obj.getObjects();enm2.hasMoreElements();) {
143-
DERSequence val = (DERSequence)enm2.nextElement();
144-
DERObjectIdentifier v0 = (DERObjectIdentifier)val.getObjectAt(0);
145-
DERObject v1 = (DERObject)val.getObjectAt(1);
146-
IRubyObject a1 = getRuntime().newString(ASN1.getSymLookup(getRuntime()).get(v0));
147-
IRubyObject a2 = ASN1.decode(getRuntime().getClassFromPath("OpenSSL::ASN1"), RubyString.newString(getRuntime(), v1.getDEREncoded()));
148-
add_attribute(Utils.newRubyInstance(getRuntime(), "OpenSSL::X509::Attribute", new IRubyObject[] { a1, a2 }));
149-
}
141+
Object o = enm.nextElement();
142+
System.out.println("enm: " + o.getClass());
143+
if (o instanceof DERSequence) {
144+
DERSequence val = (DERSequence)o;
145+
DERObjectIdentifier v0 = (DERObjectIdentifier)val.getObjectAt(0);
146+
DERObject v1 = (DERObject)val.getObjectAt(1);
147+
IRubyObject a1 = getRuntime().newString(ASN1.getSymLookup(getRuntime()).get(v0));
148+
IRubyObject a2 = ASN1.decode(getRuntime().getClassFromPath("OpenSSL::ASN1"), RubyString.newString(getRuntime(), v1.getDEREncoded()));
149+
add_attribute(Utils.newRubyInstance(getRuntime(), "OpenSSL::X509::Attribute", new IRubyObject[] { a1, a2 }));
150+
} else {
151+
DERSet obj = (DERSet)o;
152+
for(Enumeration enm2 = obj.getObjects();enm2.hasMoreElements();) {
153+
DERSequence val = (DERSequence)enm2.nextElement();
154+
DERObjectIdentifier v0 = (DERObjectIdentifier)val.getObjectAt(0);
155+
DERObject v1 = (DERObject)val.getObjectAt(1);
156+
IRubyObject a1 = getRuntime().newString(ASN1.getSymLookup(getRuntime()).get(v0));
157+
IRubyObject a2 = ASN1.decode(getRuntime().getClassFromPath("OpenSSL::ASN1"), RubyString.newString(getRuntime(), v1.getDEREncoded()));
158+
add_attribute(Utils.newRubyInstance(getRuntime(), "OpenSSL::X509::Attribute", new IRubyObject[] { a1, a2 }));
159+
}
160+
}
150161
}
151162
this.valid = true;
152163
return this;

0 commit comments

Comments
 (0)