mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-01-21 15:29:58 +08:00
Use buffers for BIMI docs
This commit is contained in:
parent
a1a77d2414
commit
f7d9c75cfb
1 changed files with 33 additions and 1 deletions
|
@ -5,6 +5,7 @@ const https = require('https');
|
||||||
const { validateSvg } = require('mailauth/lib/bimi/validate-svg');
|
const { validateSvg } = require('mailauth/lib/bimi/validate-svg');
|
||||||
const { vmc } = require('@postalsys/vmc');
|
const { vmc } = require('@postalsys/vmc');
|
||||||
const { formatDomain, getAlignment } = require('mailauth/lib/tools');
|
const { formatDomain, getAlignment } = require('mailauth/lib/tools');
|
||||||
|
const crypto = require('crypto');
|
||||||
|
|
||||||
class BimiHandler {
|
class BimiHandler {
|
||||||
static create(options = {}) {
|
static create(options = {}) {
|
||||||
|
@ -115,6 +116,10 @@ class BimiHandler {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bimiDocument?.content?.buffer) {
|
||||||
|
bimiDocument.content = bimiDocument.content.buffer;
|
||||||
|
}
|
||||||
|
|
||||||
return bimiDocument;
|
return bimiDocument;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,6 +288,12 @@ class BimiHandler {
|
||||||
{ upsert: true, returnDocument: 'after' }
|
{ upsert: true, returnDocument: 'after' }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
bimiDocument = r?.value;
|
||||||
|
|
||||||
|
if (bimiDocument?.content?.buffer) {
|
||||||
|
bimiDocument.content = bimiDocument.content.buffer;
|
||||||
|
}
|
||||||
|
|
||||||
return r && r.value;
|
return r && r.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,6 +348,28 @@ class BimiHandler {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (locationStatus === 'fulfilled' && locationValue?.content && authorityValue.vmc?.hashAlgo && authorityValue.vmc?.validHash) {
|
||||||
|
console.log(locationValue.content);
|
||||||
|
let hash = crypto
|
||||||
|
.createHash(authorityValue.vmc.hashAlgo)
|
||||||
|
//sss
|
||||||
|
.update(locationValue.content)
|
||||||
|
.digest('hex');
|
||||||
|
if (hash === authorityValue.vmc.hashValue) {
|
||||||
|
// logo files match, so location URL is safe to use
|
||||||
|
authorityValue.locationUrl = bimiData.location;
|
||||||
|
} else {
|
||||||
|
let error = new Error('Logo files from l= and a= do not match');
|
||||||
|
error.details = {
|
||||||
|
locationHash: hash,
|
||||||
|
authorityHash: authorityValue.vmc.hashValue,
|
||||||
|
hashAlgo: authorityValue.vmc.hashAlgo
|
||||||
|
};
|
||||||
|
error.code = 'LOGO_HASH_MISMATCH';
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return authorityValue;
|
return authorityValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,7 +381,6 @@ module.exports = BimiHandler;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
const db = require('./db');
|
const db = require('./db');
|
||||||
|
|
||||||
db.connect(() => {
|
db.connect(() => {
|
||||||
let bimi = BimiHandler.create({
|
let bimi = BimiHandler.create({
|
||||||
database: db.database
|
database: db.database
|
||||||
|
|
Loading…
Reference in a new issue