Skip to content

Commit

Permalink
Support converting to/from textual IP for subjectAltName extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlongley committed Sep 18, 2013
1 parent 42d1107 commit a09c0a6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,9 @@ cert.setExtensions([{
altNames: [{
type: 6, // URI
value: 'http://example.org/webid#me'
}, {
type: 7, // IP
ip: '127.0.0.1'
}]
}, {
name: 'subjectKeyIdentifier'
Expand Down
24 changes: 21 additions & 3 deletions js/x509.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,8 @@ var _parseExtensions = function(exts) {
break;
// IPAddress
case 7:
// FIXME: convert to IPv4 dotted string/IPv6
// convert to IPv4/IPv6 string representation
altName.ip = forge.util.bytesToIP(gn.value);
break;
// registeredID
case 8:
Expand Down Expand Up @@ -1320,9 +1321,26 @@ pki.createCertificate = function() {
for(var n = 0; n < e.altNames.length; ++n) {
altName = e.altNames[n];
var value = altName.value;
// handle IP
if(altName.type === 7 && altName.ip) {
value = forge.util.bytesFromIP(altName.ip);
if(value === null) {
throw {
message: 'Extension "ip" value is not a valid IPv4 ' +
'or IPv6 address.',
extension: e
};
}
}
// handle OID
if(altName.type === 8) {
value = asn1.oidToDer(value);
else if(altName.type === 8) {
if(altName.oid) {
value = asn1.oidToDer(asn1.oidToDer(altName.oid));
}
// deprecated ... convert value to OID
else {
value = asn1.oidToDer(value);
}
}
e.value.value.push(asn1.create(
asn1.Class.CONTEXT_SPECIFIC, altName.type, false,
Expand Down
3 changes: 3 additions & 0 deletions tests/nodejs-create-cert.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ cert.setExtensions([{
altNames: [{
type: 6, // URI
value: 'http://example.org/webid#me'
}, {
type: 7, // IP
ip: '127.0.0.1'
}]
}, {
name: 'subjectKeyIdentifier'
Expand Down

0 comments on commit a09c0a6

Please sign in to comment.