Use buffers for BIMI docs

This commit is contained in:
Andris Reinman 2022-07-18 23:03:56 +03:00
parent a1a77d2414
commit f7d9c75cfb
No known key found for this signature in database
GPG key ID: DC6C83F4D584D364

View file

@ -5,6 +5,7 @@ const https = require('https');
const { validateSvg } = require('mailauth/lib/bimi/validate-svg');
const { vmc } = require('@postalsys/vmc');
const { formatDomain, getAlignment } = require('mailauth/lib/tools');
const crypto = require('crypto');
class BimiHandler {
static create(options = {}) {
@ -115,6 +116,10 @@ class BimiHandler {
throw error;
}
if (bimiDocument?.content?.buffer) {
bimiDocument.content = bimiDocument.content.buffer;
}
return bimiDocument;
}
@ -283,6 +288,12 @@ class BimiHandler {
{ upsert: true, returnDocument: 'after' }
);
bimiDocument = r?.value;
if (bimiDocument?.content?.buffer) {
bimiDocument.content = bimiDocument.content.buffer;
}
return r && r.value;
}
@ -337,6 +348,28 @@ class BimiHandler {
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;
}
@ -348,7 +381,6 @@ module.exports = BimiHandler;
/*
const db = require('./db');
db.connect(() => {
let bimi = BimiHandler.create({
database: db.database