Reputation: 13588
New to typescript, and I am working with nodeforge to generate CA and I do not know how to resolve this error.
PS: Vscode did not show red underline, but nextjs throws the error.
const cert = pki.createCertificate();
const attrs = [
{ name: 'commonName', value: 'My First CA' },
{ name: 'organizationUnitName', value: 'Organization Unit' },
{ name: 'organizationName', value: 'My Organization' },
] //this is returned by buildSubjectFromOptions
cert.setSubject(attrs as pki.CertificateField[]);
cert.setIssuer(attrs as pki.CertificateField[]);
At the last 2 lines, I am getting the error Attribute type is not specified, even though I followed vs code instructions as below
Upvotes: 0
Views: 727
Reputation: 26
I had this similar issue as well. I looked at the X509.js and oids.js library files of node-forge.
oids.js:
_IN('2.5.4.10', 'organizationName')
_IN('2.5.4.10', 'organizationName')
X509.js:
_shortNames['OU'] = oids['organizationalUnitName'];
_shortNames['organizationalUnitName'] = 'OU';
It seems that your attribute "organizationUnitName" is actually stored in pki.oids/x509.js as "organizationalUnitName". If you fix your typo from "organizationUnitName" to "organizationalUnitName" should hopefully resolve the issue.
Hope this helps
Upvotes: 1
Reputation: 13588
So I went to code of node-forge where the error was called, as follows
// populate missing type (OID)
if(typeof attr.type === 'undefined') {
if(attr.name && attr.name in pki.oids) {
attr.type = pki.oids[attr.name];
} else {
var error = new Error('Attribute type not specified.');
error.attribute = attr;
throw error;
}
}
Even though my attributes exists in pki.oids, i don't know why it still throws the error.
I amended my attributes format to as follows,adding the key type
and now error goes away.
const attrs = [
{ name: 'commonName', value: 'My First CA', type: 'commonName' },
{ name: 'organizationUnitName', value: 'Organization Unit', type: 'organizationUnitName' },
{ name: 'organizationName', value: 'My Organization', type: 'organizationName' },
]
Upvotes: 0