forge
forge copied to clipboard
pki.verifyCertificateChain() - TypeError: chain.shift is not a function
Hello Forge Community, :)
So, I'm trying to verify a certificate chain, right? And getting a TypeError: chain.shift is not a function
error. And after spending two days working on this, it seems time to file a ticket and get some other eyes on it. Can anybody suggest where I might be going wrong? chain.shift
just implies that it's looking for an array right? Or is there a special certificate chain object format that I need to know about? Is the issue that I've not converted to a Forge certificate? Or maybe have an encoding/decoding problem?
import { get, has } from 'lodash';
import jwt from 'jsonwebtoken';
import forge from 'node-forge';
// base certificate loaded from server
let emrDirectPem = Assets.getText('certs/EMRDirectTestCA.crt');
console.log('emrDirectPem', emrDirectPem);
var caStore = forge.pki.createCaStore([emrDirectPem]);
// we have an API that people post to
JsonRoutes.add("post", "/oauth/registration", function (req, res, next) {
// where they send in a JWT encoded software statement
let decoded = jwt.decode(req.body.software_statement, {complete: true});
// it should have an x509 certificate in the header encoded in DER format
if(has(decoded, 'header.x5c[0]')){
// if so, we grab it and convert it to PEM format
let pemString = "-----BEGIN CERTIFICATE-----\r\n";
pemString += formatPEM(decoded.header.x5c[0]);
pemString = `${pemString}\r\n-----END CERTIFICATE-----\r\n`;
console.log('pemString', pemString)
// and then try to verify the certificate chain
forge.pki.verifyCertificateChain(caStore, pemString, function(){...etc.}});
// ERROR: TypeError: chain.shift is not a function
}
Any advice would be much appreciated!!