Skip to content

Commit 8d096a3

Browse files
committed
adjust cwt payload to be encoded properly
1 parent 3186331 commit 8d096a3

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def statusListCWT():
115115
subject="https://example.com/statuslists/1",
116116
list=status_list,
117117
key=key,
118+
alg=-7,
118119
)
119120
status_cwt = cwt.buildCWT(iat=iat, exp=exp)
120121
hex_encoded = status_cwt.hex()

src/status_token.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from jwcrypto import jwk, jwt
2-
from cwt import COSE, COSEKey
2+
from cwt import COSE, COSEKey, CWTClaims
33
from status_list import StatusList
44
from datetime import datetime
55
from typing import Dict
6+
from cbor2 import dumps
67
import json
78

89
DEFAULT_ALG = "ES256"
@@ -119,11 +120,11 @@ def buildCWT(
119120
claims = optional_claims
120121
else:
121122
claims = {}
122-
claims[2] = self.subject
123-
claims[1] = self.issuer
124-
claims[6] = int(iat.timestamp())
123+
claims[CWTClaims.SUB] = self.subject
124+
claims[CWTClaims.ISS] = self.issuer
125+
claims[CWTClaims.IAT] = int(iat.timestamp())
125126
if exp is not None:
126-
claims[4] = int(exp.timestamp())
127+
claims[CWTClaims.EXP] = int(exp.timestamp())
127128
claims[65534] = self.list.encodeAsCBOR() # no CWT claim key assigned yet by IANA
128129

129130
# build header
@@ -138,15 +139,16 @@ def buildCWT(
138139
unprotected_header = {}
139140

140141
if self._key.key_id:
141-
unprotected_header["kid"] = self._key.key_id
142-
protected_header["alg"] = self._alg
142+
unprotected_header[4] = self._key.key_id
143+
protected_header[1] = self._alg
144+
protected_header[16] = STATUS_LIST_TYP_CWT
143145

144146
key = COSEKey.from_jwk(self._key)
145147

146148
# The sender side:
147149
sender = COSE.new()
148150
encoded = sender.encode(
149-
claims,
151+
dumps(claims),
150152
key,
151153
protected=protected_header,
152154
unprotected=unprotected_header

0 commit comments

Comments
 (0)