|
@@ -4,7 +4,7 @@ export function createDkimKeyPair() {
|
|
|
const { publicKey, privateKey } = crypto.generateKeyPairSync('rsa', {
|
|
const { publicKey, privateKey } = crypto.generateKeyPairSync('rsa', {
|
|
|
modulusLength: 2048,
|
|
modulusLength: 2048,
|
|
|
publicKeyEncoding: {
|
|
publicKeyEncoding: {
|
|
|
- type: 'pkcs1',
|
|
|
|
|
|
|
+ type: 'spki',
|
|
|
format: 'pem'
|
|
format: 'pem'
|
|
|
},
|
|
},
|
|
|
privateKeyEncoding: {
|
|
privateKeyEncoding: {
|
|
@@ -28,7 +28,7 @@ export function pemToDkimPublic(pem) {
|
|
|
export function dkimPublicFromPrivateKey(privateKey) {
|
|
export function dkimPublicFromPrivateKey(privateKey) {
|
|
|
const publicKey = crypto
|
|
const publicKey = crypto
|
|
|
.createPublicKey(privateKey)
|
|
.createPublicKey(privateKey)
|
|
|
- .export({ type: 'pkcs1', format: 'pem' });
|
|
|
|
|
|
|
+ .export({ type: 'spki', format: 'pem' });
|
|
|
return pemToDkimPublic(publicKey);
|
|
return pemToDkimPublic(publicKey);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -66,7 +66,7 @@ export function signDkim(rawMessage, options) {
|
|
|
const dkimValueWithoutSignature = signatureFields.join('; ');
|
|
const dkimValueWithoutSignature = signatureFields.join('; ');
|
|
|
const signingInput = [
|
|
const signingInput = [
|
|
|
...signedHeaderNames.map((name) => canonicalizeHeader(findHeader(headers, name))),
|
|
...signedHeaderNames.map((name) => canonicalizeHeader(findHeader(headers, name))),
|
|
|
- canonicalizeHeader({ name: 'DKIM-Signature', value: dkimValueWithoutSignature })
|
|
|
|
|
|
|
+ canonicalizeHeader({ name: 'DKIM-Signature', value: dkimValueWithoutSignature }, '')
|
|
|
].join('');
|
|
].join('');
|
|
|
|
|
|
|
|
const signature = crypto
|
|
const signature = crypto
|
|
@@ -103,10 +103,10 @@ function findHeader(headers, name) {
|
|
|
return found;
|
|
return found;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function canonicalizeHeader(header) {
|
|
|
|
|
|
|
+function canonicalizeHeader(header, suffix = '\r\n') {
|
|
|
const name = header.name.toLowerCase();
|
|
const name = header.name.toLowerCase();
|
|
|
const value = header.value.replace(/\s+/g, ' ').trim();
|
|
const value = header.value.replace(/\s+/g, ' ').trim();
|
|
|
- return `${name}:${value}\r\n`;
|
|
|
|
|
|
|
+ return `${name}:${value}${suffix}`;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function canonicalizeBody(body) {
|
|
function canonicalizeBody(body) {
|