Closed jefjos closed 4 years ago
We don’t write code on demand for other peoples applications.
Do you have a concrete issue with the library trying to do something we can help with?
Have you seen: https://pkijs.org/examples/X509_cert_complex_example.html
Which shows adding extensions?
Thank you for the pointers. Here is what I have tried.
const attr= "{\"a\":\"b\"}";
cert.extensions.push(new Extension({
extnID: "1.2.3.4.5.6.7.8",
critical: false,
extnValue: (new asn1js.OctetString({ valueHex: toArrayBuffer(Buffer.from(attr)) })).toBER(false)
}));
function toArrayBuffer(buf) {
var ab = new ArrayBuffer(buf.length);
var view = new Uint8Array(ab);
for (var i = 0; i < buf.length; ++i) {
view[i] = buf[i];
}
return ab;
}
The resulting certificate shows the following
X509v3 extensions:
X509v3 Basic Constraints: critical
CA:FALSE
1.2.3.4.5.6.7.8:
..{"a":"b"}
The ".." before the {"a";"b"} is unexpected.
@jefjos Please search closed issues for “extension” tag. I remember I had such question before. Also check issue #166 - probably it would help.
Thanks for the pointer. I figured it out! The Extension constructor wraps the octetstring under another octetstring, which is the reason why the decoded certificate does not show the string as is. This worked for me
cert.extensions.push(new Extension({
extnID: "1.2.3.4.5.6.7.8.1",
critical: false,
extnValue: toArrayBuffer(Buffer.from(attr))
}));
Closing this issue now.
Hello
Could you provide an example of adding custom extension to x509 certificate? So that the extensions section in certificate would look something like this
Thanks!