Skip to content

Commit 2bcf092

Browse files
base64 encode raw signature in Envelope
@adityasaky found that we are encoding hex representation of signatures into base64, that would be incompatible with other DSSE envelope signing libraries. This commit changes the direct base64 encoding in Envelope to decoding hex signature and then encode the bytes into base64. Signed-off-by: Pradyumna Krishna <[email protected]>
1 parent 85ed9ad commit 2bcf092

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

securesystemslib/dsse.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Dead Simple Signing Envelope
22
"""
33

4+
import binascii
45
import logging
56
from typing import Any, Dict, List
67

@@ -60,7 +61,9 @@ def from_dict(cls, data: dict) -> "Envelope":
6061

6162
signatures = []
6263
for signature in data["signatures"]:
63-
signature["sig"] = b64dec(signature["sig"]).decode("utf-8")
64+
signature["sig"] = binascii.hexlify(
65+
b64dec(signature["sig"])
66+
).decode("utf-8")
6467
signatures.append(Signature.from_dict(signature))
6568

6669
return cls(payload, payload_type, signatures)
@@ -71,7 +74,7 @@ def to_dict(self) -> dict:
7174
signatures = []
7275
for signature in self.signatures:
7376
sig_dict = signature.to_dict()
74-
sig_dict["sig"] = b64enc(sig_dict["sig"].encode("utf-8"))
77+
sig_dict["sig"] = b64enc(binascii.unhexlify(sig_dict["sig"]))
7578
signatures.append(sig_dict)
7679

7780
return {

tests/test_dsse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def setUpClass(cls):
2626

2727
cls.signature_dict = {
2828
"keyid": "11fa391a0ed7a447",
29-
"sig": "MzA0NjAyMjEwMDkzNDJlNDU2NjUyOGZjZWNmNmE3YTU=",
29+
"sig": "MEYCIQCTQuRWZSj87PanpQ==",
3030
}
3131
cls.envelope_dict = {
3232
"payload": "aGVsbG8gd29ybGQ=",

0 commit comments

Comments
 (0)