Skip to content

sign outgoing messages #274

Description

@tomholub

part of #275

When outgoing message is encrypted, it should also be signed with the private key.

The implementation is to add a private key into the Core.composeEmail function which will cause the message to also get signed.

Currently it doesn't have any way to add private key, so we should add signingPrv: PrvKeyInfo? to it and pass that in.

func composeEmail(msg:SendableMsg, fmt:MsgFmt, pubKeys:[String]?)throws->CoreRes.ComposeEmail{letr=trycall("composeEmail", jsonDict:["text": msg.text,"to": msg.to,"cc": msg.cc,"bcc": msg.bcc,"from": msg.from,"subject": msg.subject,"replyToMimeMsg": msg.replyToMimeMsg,"atts": msg.atts.map{ att in["name": att.name,"type": att.type,"base64": att.base64]},"format": fmt.rawValue,"pubKeys": pubKeys,], data:nil)
// this call returned no useful json data, only bytes
returnCoreRes.ComposeEmail(mimeEncoded: r.data)}

On the receiving side, this has to be put into the PgpMsg.encrypt function which has a way to accept a private key.

publiccomposeEmail=async(uncheckedReq: any): Promise<Buffers>=>{constreq=ValidateInput.composeEmail(uncheckedReq);constmimeHeaders: RichHeaders={to: req.to,from: req.from,subject: req.subject,cc: req.cc,bcc: req.bcc};if(req.replyToMimeMsg){constpreviousMsg=awaitMime.decode(Buf.fromUtfStr((req.replyToMimeMsg.substr(0,10000).split('\n\n')[0]||'')+`\n\nno content`));constreplyHeaders=Mime.replyHeaders(previousMsg);mimeHeaders['in-reply-to']=replyHeaders['in-reply-to'];mimeHeaders['references']=replyHeaders['references'];}if(req.format==='plain'){constatts=(req.atts||[]).map(({ name, type, base64 })=>newAtt({ name, type,data: Buf.fromBase64Str(base64)}));returnfmtRes({},Buf.fromUtfStr(awaitMime.encode({'text/plain': req.text},mimeHeaders,atts)));}elseif(req.format==='encrypt-inline'){constencryptedAtts: Att[]=[];for(constattofreq.atts||[]){constencryptedAtt=awaitPgpMsg.encrypt({pubkeys: req.pubKeys,data: Buf.fromBase64Str(att.base64),filename: att.name,armor: false})asOpenPGP.EncryptBinaryResult;encryptedAtts.push(newAtt({name: att.name,type: 'application/pgp-encrypted',data: encryptedAtt.message.packets.write()}))}constencrypted=awaitPgpMsg.encrypt({pubkeys: req.pubKeys,data: Buf.fromUtfStr(req.text),armor: true})asOpenPGP.EncryptArmorResult;returnfmtRes({},Buf.fromUtfStr(awaitMime.encode({'text/plain': encrypted.data},mimeHeaders,encryptedAtts)));}else{thrownewError(`Unknown format: ${req.format}`);}}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions