Skip to content

parsing of several keys at a time in Kotlin + expect potentially encrypted keys #1053

Description

@tomholub

as a part of #1051 but only after #1052

In our Pgp.kt implementation https://github.com/FlowCrypt/flowcrypt-email-key-manager/blob/2f62df069eee4e6b229d5faef21944696d332068/shared-lib/src/main/kotlin/com/flowcrypt/shared/crypto/Pgp.kt#L187 we assume that we are parsing a single key each time, and the key - if it's a private key - must be decrypted.

However here on client side we may encounter many keys in a single armored block, or many keys in a single byte array stream (unarmored) so we need a way to parse and return an array.

The current implementation is at https://github.com/FlowCrypt/flowcrypt-mobile-core/blob/f80d5491451b61dcf8e539932b693fb28e84217f/source/mobile-interface/endpoints.ts#L229 :

publicparseKeys=async(_uncheckedReq: any,data: Buffers)=>{constkeyDetails: KeyDetails[]=[];constallData=Buf.concat(data);constpgpType=awaitPgpMsg.type({data: allData});if(!pgpType){returnfmtRes({format: 'unknown', keyDetails });}if(pgpType.armored){// armoredconst{ blocks }=MsgBlockParser.detectBlocks(allData.toString());for(constblockofblocks){const{ keys }=awaitPgpKey.parse(block.content.toString());keyDetails.push(...keys);}returnfmtRes({format: 'armored', keyDetails });}// binaryconst{keys: openPgpKeys}=awaitopenpgp.key.read(allData);for(constopenPgpKeyofopenPgpKeys){keyDetails.push(awaitPgpKey.details(openPgpKey))}returnfmtRes({format: 'binary',keyDetails: keyDetails});}

It tries to infer the type of the message key it starts parsing, and then it parses either armored keys or binary keys flexibly, and returns a list of parsed keys.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions