Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/main/java/org/jruby/ext/openssl/X509ExtensionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ else if (id.equals("2.5.29.31")) { // crlDistributionPoints
else if (id.equals("1.3.6.1.5.5.7.1.1")) { // authorityInfoAccess
value = parseAuthorityInfoAccess(valuex);
}
else if (isNetscapeIA5StringExtension(id)) {
value = new DEROctetString(new DERIA5String(valuex).getEncoded(ASN1Encoding.DER));
}
else {
value = new DEROctetString(new DEROctetString(ByteList.plain(valuex)).getEncoded(ASN1Encoding.DER));
}
Expand Down Expand Up @@ -385,6 +388,25 @@ private DERBitString parseNsCertType(String oid, String valuex) {
return new DERBitString(new byte[]{v}, unused);
}

/**
* Returns true for Netscape extensions whose value is an IA5String.
* nsCertType (2.16.840.1.113730.1.1) is a BIT STRING handled separately.
*/
private static boolean isNetscapeIA5StringExtension(final String oid) {
switch (oid) {
case "2.16.840.1.113730.1.2": // nsBaseUrl
case "2.16.840.1.113730.1.3": // nsRevocationUrl
case "2.16.840.1.113730.1.4": // nsCaRevocationUrl
case "2.16.840.1.113730.1.7": // nsRenewalUrl
case "2.16.840.1.113730.1.8": // nsCaPolicyUrl
case "2.16.840.1.113730.1.12": // nsSslServerName
case "2.16.840.1.113730.1.13": // nsComment
return true;
default:
return false;
}
}

private static DLSequence parseBasicConstrains(final String valuex) {
final String[] val = StringHelper.split(valuex, ',');
final ASN1EncodableVector vec = new ASN1EncodableVector();
Expand Down
24 changes: 24 additions & 0 deletions src/test/ruby/x509/test_x509ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,30 @@ def test_subject_alt_name_sign_to_pem_through_cert
assert_equal "DNS:test.example.com, DNS:test2.example.com, DNS:example.com, DNS:www.example.com", ext.value
end

def test_ns_comment_der_encoding
ef = OpenSSL::X509::ExtensionFactory.new
ext = ef.create_extension("nsComment", "my test comment")

# Value round-trips correctly
assert_equal "my test comment", ext.value

# Inner encoding must be IA5String (tag 0x16), not OCTET STRING (tag 0x04)
seq = OpenSSL::ASN1.decode(ext.to_der)
inner = OpenSSL::ASN1.decode(seq.value[-1].value)
assert_instance_of OpenSSL::ASN1::IA5String, inner
assert_equal "my test comment", inner.value
end

def test_ns_base_url_der_encoding
ef = OpenSSL::X509::ExtensionFactory.new
ext = ef.create_extension("nsBaseUrl", "https://example.com/")

seq = OpenSSL::ASN1.decode(ext.to_der)
inner = OpenSSL::ASN1.decode(seq.value[-1].value)
assert_instance_of OpenSSL::ASN1::IA5String, inner
assert_equal "https://example.com/", inner.value
end

def subject_alt_name(domains)
ef = OpenSSL::X509::ExtensionFactory.new
ef.create_extension("subjectAltName", domains.split(',').map { |d| "DNS: #{d}" }.join(', '))
Expand Down
Loading