Skip to content

Commit

Permalink
base64 encode raw signature in Envelope
Browse files Browse the repository at this point in the history
@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]>
  • Loading branch information
PradyumnaKrishna committed Apr 14, 2023
1 parent 85ed9ad commit 2bcf092
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions securesystemslib/dsse.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Dead Simple Signing Envelope
"""

import binascii
import logging
from typing import Any, Dict, List

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

signatures = []
for signature in data["signatures"]:
signature["sig"] = b64dec(signature["sig"]).decode("utf-8")
signature["sig"] = binascii.hexlify(
b64dec(signature["sig"])
).decode("utf-8")
signatures.append(Signature.from_dict(signature))

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

return {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dsse.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def setUpClass(cls):

cls.signature_dict = {
"keyid": "11fa391a0ed7a447",
"sig": "MzA0NjAyMjEwMDkzNDJlNDU2NjUyOGZjZWNmNmE3YTU=",
"sig": "MEYCIQCTQuRWZSj87PanpQ==",
}
cls.envelope_dict = {
"payload": "aGVsbG8gd29ybGQ=",
Expand Down

0 comments on commit 2bcf092

Please sign in to comment.