Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Create and sign the CSR
var csr = forge.pki.createCertificationRequest();
csr.publicKey = publicKey;
csr.setSubject([{ name: 'commonName', value: names[0] }]);
var sans = [];
for (i in names) {
sans.push({ type: 2, value: names[i] });
}
csr.setAttributes([{
name: 'extensionRequest',
extensions: [{name: 'subjectAltName', altNames: sans}]
}]);
csr.sign(privateKey, forge.md.sha256.create());
// Convert CSR -> DER -> Base64
var der = forge.asn1.toDer(forge.pki.certificationRequestToAsn1(csr));
return util.b64enc(bytesToBuffer(der));
},
keyCertSign: true,
digitalSignature: true,
nonRepudiation: true,
keyEncipherment: true,
dataEncipherment: true
}, {
name: 'subjectAltName',
altNames: [{
type: 6, // URI
value: 'http://example.org/webid#me'
}]
}]);
cert.sign(keyPair.privateKey, getAlgorithm(options && options.algorithm));
const fingerprint = forge.md.sha1
.create()
.update(forge.asn1.toDer(forge.pki.certificateToAsn1(cert)).getBytes())
.digest()
.toHex()
.match(/.{2}/g)
.join(':');
var pem = {
private: forge.pki.privateKeyToPem(keyPair.privateKey),
public: forge.pki.publicKeyToPem(keyPair.publicKey),
cert: forge.pki.certificateToPem(cert),
fingerprint: fingerprint,
};
if (options && options.pkcs7) {
var p7 = forge.pkcs7.createSignedData();
cRLSign: true,
encipherOnly: true,
decipherOnly: true
}, {
name: 'subjectKeyIdentifier'
}, {
name: 'extKeyUsage',
serverAuth: true,
clientAuth: true,
codeSigning: true,
emailProtection: true,
timeStamping: true
}, {
name: 'authorityKeyIdentifier'
}]);
cert.sign(caKey, forge.md.sha256.create());
var certPem = pki.certificateToPem(cert);
var keyPem = pki.privateKeyToPem(keys.privateKey);
console.log(certPem);
console.log(keyPem);
mkdirp.sync(path.join(__dirname, '../../cert'));
fs.writeFileSync(path.join(__dirname, '../../cert/my.crt'), certPem);
fs.writeFileSync(path.join(__dirname, '../../cert/my.key.pem'), keyPem);
function getAlgorithm(key) {
switch (key) {
case 'sha256':
return forge.md.sha256.create();
default:
return forge.md.sha1.create();
}
}
},
{
name: 'subjectKeyIdentifier'
},
{
name: 'extKeyUsage',
serverAuth: true,
clientAuth: true,
codeSigning: true,
emailProtection: true,
timeStamping: true
},
{
name:'authorityKeyIdentifier'
}]);
cert.sign(caKey, forge.md.sha256.create());
return {
key: keys.privateKey,
cert: cert
};
}
function createPss() {
const md = forge.md.sha256.create();
return forge.pss.create({
md,
mgf: forge.mgf.mgf1.create(forge.md.sha256.create()),
saltLength: md.digestLength
});
}
async checkSubscription() {
const {
listId, user, token, authenticating,
} = this.props;
if (!token || authenticating) return;
const md = forge.md.md5.create();
md.update(user.email);
this.emailHash = md.digest().toHex();
await fetch(`${PROXY_ENDPOINT}/${listId}/members/${this.emailHash}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
})
.then((result) => {
if (result.status === 400) this.setState({ signupState: SIGNUP_NEWSLETTER.DEFAULT });
return result.json();
})
.then((dataResponse) => {
if (dataResponse.status === 'subscribed') {
function _md5Digest( byteString ) {
const md = forge.md.md5.create();
md.update( byteString );
return md.digest();
}
string = forge.util.encodeUtf8('' + string);
//let original = string;
if (compress && !session.disableCompress)
{
string = new forge.util.ByteBuffer(string).toHex();
string = pako.deflateRaw(string, {
level: 6,
to: 'string'
})
}
let key = forge.md.md5.create().update(rsaKey.bytes()).digest();
let iv = session.ivAES.length() ? forge.md.md5.create().update(session.ivAES.bytes()).digest() : new forge.util.ByteBuffer();
let cipher = forge.cipher.createCipher('AES-CBC', key);
cipher.start({
iv: iv
});
cipher.update(new forge.util.ByteBuffer(string));
return cipher.finish() && cipher.output.toHex();
/*let result = cipher.finish() && cipher.output.toHex();
return forge.md.md5.create().update(original).update(rsaKey.bytes()).digest().toHex().toUpperCase() + result;*/
}
passwordDigest: function(password) {
let md = forge.md.sha256.create();
md.update(password + process.env.PASSWORD_SALT);
return md.digest().toHex();
}
};