Skip to content

Commit

Permalink
feat: added CBORTAGS_ATTR_MAP inm the settings where to map specific …
Browse files Browse the repository at this point in the history
…tags per attribute
  • Loading branch information
peppelinux committed Jul 5, 2023
1 parent 9411247 commit ad30453
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 26 deletions.
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ according to ISO 18013-5.
## Setup

````
pip install pymdlmdoc
pip install pymdoccbor
````

or

````
pip install git+https://github.com/peppelinux/pyMDL-MDOC.git
pip install git+https://github.com/peppelinux/pyMDOC-CBOR.git
````

## Usage
Expand All @@ -45,6 +45,8 @@ pip install git+https://github.com/peppelinux/pyMDL-MDOC.git
The method `.new()` gets the user attributes, devicekeyinfo and doctype.

````
import os
from pymdoccbor.mdoc.issuer import MdocCborIssuer
PKEY = {
Expand All @@ -56,12 +58,17 @@ PKEY = {
}
PID_DATA = {
"eu.europa.ec.eudiw.pid.1": {
"family_name": "Raffaello",
"given_name": "Mascetti",
"birth_date": "1922-03-13"
}
"eu.europa.ec.eudiw.pid.1": {
"family_name": "Raffaello",
"given_name": "Mascetti",
"birth_date": "1922-03-13",
"birth_place": "Rome",
"birth_country": "IT"
},
"eu.europa.ec.eudiw.pid.it.1": {
"tax_id_code": "TINIT-XXXXXXXXXXXXXXX"
}
}
mdoci = MdocCborIssuer(
private_key=PKEY
Expand All @@ -76,14 +83,11 @@ mdoc = mdoci.new(
mdoc
>> returns a python dictionay
mdoc.dump()
>> returns mdoc MSO bytes
mdoci.dump()
>> returns mdoc bytes
mdoci.dumps()
>> returns AF Binary mdoc string representation
>> returns AF Binary string representation
````

### Issue an MSO alone
Expand Down
2 changes: 1 addition & 1 deletion pymdoccbor/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.4"
__version__ = "0.5.5"
11 changes: 5 additions & 6 deletions pymdoccbor/mdoc/issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def new(

# TODO: for now just a single document, it would be trivial having
# also multiple but for now I don't have use cases for this
res = {
self.signed = {
'version': self.version,
'documents': [
{
Expand All @@ -57,15 +57,14 @@ def new(
},
"issuerAuth": mso.encode()
},
'deviceSigned': {
# TODO
}
# this is required during the presentation.
# 'deviceSigned': {
# # TODO
# }
}
],
'status': self.status
}

self.signed = res
return self.signed

def dump(self):
Expand Down
7 changes: 4 additions & 3 deletions pymdoccbor/mdoc/verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ def __init__(self):
self.documents: List[MobileDocument] = []
self.documents_invalid: list = []

def load(self, data: bytes):
data = binascii.hexlify(data)
return self.loads(data)

def loads(self, data: str):
"""
data is a AF BINARY
"""
if isinstance(data, bytes):
data = binascii.hexlify(data)

self.data_as_bytes = binascii.unhexlify(data)
self.data_as_cbor_dict = cbor2.loads(self.data_as_bytes)

Expand Down
7 changes: 6 additions & 1 deletion pymdoccbor/mso/issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ def __init__(
for k, v in shuffle_dict(values).items():

_rnd_salt = secrets.token_bytes(settings.DIGEST_SALT_LENGTH)


_value_cbortag = settings.CBORTAGS_ATTR_MAP.get(k, None)

if _value_cbortag:
v = cbor2.CBORTag(_value_cbortag, value=v)

self.disclosure_map[ns][digest_cnt] = {
'digestID': digest_cnt,
'random': _rnd_salt,
Expand Down
5 changes: 3 additions & 2 deletions pymdoccbor/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

DIGEST_SALT_LENGTH = 32


X509_DER_CERT = os.getenv('X509_DER_CERT', None)

# OR
Expand All @@ -44,5 +43,7 @@
'X509_SAN_URL', u"https://credential-issuer.oidc-federation.online"
)


CBORTAGS_ATTR_MAP = {
"birth_date": 1004
}

2 changes: 1 addition & 1 deletion pymdoccbor/tests/test_01_mdoc_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_parse_mdoc_af_binary():

# testing from export re-import
mdoc2 = MdocCbor()
mdoc2.loads(mdoc.data_as_bytes)
mdoc2.load(mdoc.data_as_bytes)
mdoc2.verify()

for i in mdoc.documents:
Expand Down
2 changes: 1 addition & 1 deletion pymdoccbor/tests/test_02_mdoc_issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_mdoc_issuer():

mdocp = MdocCbor()
aa = cbor2.dumps(mdoc)
mdocp.loads(aa)
mdocp.load(aa)
mdocp.verify()

mdoci.dump()
Expand Down

0 comments on commit ad30453

Please sign in to comment.