<oembed><type>rich</type><version>1.0</version><author_name>npub10vqyu8x3f0lfttk98xc28ppuyufaz4df8x4aspa9w9xz5z05snzq7t058y</author_name><author_url>https://nostr.ae/npub10vqyu8x3f0lfttk98xc28ppuyufaz4df8x4aspa9w9xz5z05snzq7t058y</author_url><provider_name>njump</provider_name><provider_url>https://nostr.ae</provider_url><html>📅 Original date posted:2020-01-11&#xA;📝 Original message:## Background&#xA;&#xA;PSBT files in transit are at risk of MiTM changes. This isn&#39;t&#xA;supposed to matter, but as another layer of defence, I would like&#xA;to add two signatures to PSBT files when they are processed by the&#xA;PSBT Signer. These additional fields would be optional, and should&#xA;pass through existing PSBT processors transparently, assuming they&#xA;pass unknown key/values as BIP-174 specifies.&#xA;&#xA;## Additional Key/Values&#xA;&#xA;1) In the PSBT globals section, a signature over the &#34;source&#34; PSBT&#xA;file. It would cover all the bytes of the original PSBT file, as&#xA;it was received by the Signer. The key used for the signature may&#xA;be any one the keys that the Signer applied during its transaction&#xA;signing process. (This is flexible so that the Signer can make the&#xA;signature at any point in the signing process. On the Coldcard, we&#xA;would probably use the first key that we used for signing, so the&#xA;first key involved in the first input.)&#xA;&#xA;The &#34;key&#34; of the global value will be pubkey value of the key which&#xA;was selected by the Signer.  If its BIP32 derivation is needed for&#xA;some reason, that is documented in the input section already.&#xA;&#xA;The &#34;value&#34; will be 65(?) bytes of a standard Bitcoin signature.&#xA;The digest (hash) of the source PSBT is not provided, so any tool&#xA;that wants to verify this signature will need to have a copy of the&#xA;original PSBT. (I see that as a critical feature, not a limitation).&#xA;&#xA;2) In the output section, specifically, the last key/value pair of&#xA;the last output of the transaction, I want to add a similar signature,&#xA;again signed by one of the keys used in the signing process. This&#xA;signature will cover all the bytes of the resulting (signed) PSBT&#xA;up to that point. Because it is the last output of the output&#xA;section, that signature will be the last few bytes of the PSBT file.&#xA;By &#34;appending&#34; the signature in this way, it&#39;s easier to validate&#xA;and create the signature, without blanking the signature area during&#xA;digest step.&#xA;&#xA;## Role-Based View&#xA;&#xA;The above additions can only be made by a PSBT processor in the Signer&#xA;role. No-one else has the keys needed. As for the other PSBT roles:&#xA;&#xA;- Any tool that reads in a PSBT and finds a signature in the final output&#xA;  section can and should verify it:&#xA;    - check signature over a digest of the PSBT file up to the last X bytes&#xA;    - file must end at that point, with only the signature following it&#xA;    - also check the key used for signature is one of the input&#39;s keys&#xA;&#xA;- PSBT processors in the &#34;combining&#34; role, should preserve the&#xA;signatures in the global section, accumulating them into the next&#xA;PSBT. (Of course they should validate them, if they have the original&#xA;PSBT on hand as well, but that&#39;s optional and could be done later&#xA;in the flow.) The Combiner should always check a signed PSBT was&#xA;not modified in transit via the signature in the final output&#xA;section, and then strip it out of the combined PSBT.&#xA;&#xA;- At the end of the signing process, the Finalizer should check all&#xA;the Signers have worked from the same PSBT file (assuming that&#39;s&#xA;the flow expected), or the appropriate PSBT if it&#39;s a more complex&#xA;case. If the Finalizer is working on a file directly from a Signer,&#xA;then it can verify the signature in the output section as well.&#xA;&#xA;## Open Questions&#xA;&#xA;For the message digest, I propose simple SHA256(SHA256(bytes of PSBT)).&#xA;I&#39;m not sure of the best way to serialize the signature, but to be&#xA;consistent with the rest of the file, it should probably be DER-encoded&#xA;and variable length.&#xA;&#xA;## Next Steps&#xA;&#xA;I&#39;d like to get two officially-assigned BIP-174 key numbers assigned&#xA;for these two signatures, and then I will see that it gets added&#xA;into Coldcard&#39;s firmware immediately. In time, other tools are&#xA;welcome to take advantage of these checks. I will also write a BIP&#xA;for this, and/or make an addition to BIP-174.&#xA;&#xA;I think with these changes, and assuming all the tools are verifying&#xA;properly, we can shutdown undetectable MiTM changes to PSBT contents.&#xA;&#xA;---&#xA;Peter D. Gray  ||  Founder, Coinkite  ||  Twitter: @dochex  ||  GPG: A3A31BAD 5A2A5B10&#xA;&#xA;-------------- next part --------------&#xA;A non-text attachment was scrubbed...&#xA;Name: signature.asc&#xA;Type: application/pgp-signature&#xA;Size: 529 bytes&#xA;Desc: not available&#xA;URL: &lt;http://lists.linuxfoundation.org/pipermail/bitcoin-dev/attachments/20200111/51fab912/attachment.sig&gt;</html></oembed>