-
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Printing of Authorization bits from BSI TR 03110-4 #7
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e5c1b0f
Basic Authorization bit parsing and dummy unittest
xoryouyou 02a4b53
Pivoted AuthorizationBits dict.
xoryouyou 92f6826
moved authorization bits to cvc_print
xoryouyou 5084f75
Reverted formatter changes
xoryouyou 6d7a674
Moved decode_authorization_bits to cvc_print
xoryouyou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import sys | ||
import unittest | ||
import binascii | ||
import logging | ||
|
||
from cvc.certificates import CVC | ||
from cvc.tools.cvc_print import AuthorizationBits, decode_authorization_bits | ||
|
||
# created with --rid --read-dg1 --write-dg22 --verify-age --install-cert | ||
CERT_WITH_RID_READ_DG1_WRITE_DG22_VERIFY_AGE_INSTALL_CERT = b"7f2181e37f4e819c5f290100420d5a5a41544456434130303030317f494f060a04007f000702020202038641043eb3b230afe41d99b0e564b8673ca9f830de0c4f1a21ccfbebbb378b980d2384750751df9403878cb46f9297d5507a759e80ab463b0bb233e5dce068ddeb55665f200d5a5a41545445524d30303030317f4c12060904007f000703010202530501000001455f25060203000900095f24060203010100085f374094d5eb4162b8f38ab531b2259af0a8aaa7fdadaa126d21948e5d68a739bac4141b59ca43fb411165b7725c39ad4fa71ab548ede169616282de72860e7de9179b" | ||
# created with --rid --read-dg22 | ||
CERT_WITH_RID_READ_DG22 = b"7f2181e37f4e819c5f290100420d5a5a41544456434130303030317f494f060a04007f00070202020203864104ed9e6911b2b4c39c7571f717ca0b61b7074fb05701d90f4474ee7e314d42828eb54ec3278a4cfc14cfe83014f01b534733e42ecee9a347c9c85691226a4692665f200d5a5a41545445524d30303030317f4c12060904007f000703010202530500200000045f25060203000900085f24060203010100075f37406e7f93614c8a63bbecc05ac8765055fe81b0d8a27389a8489aaed6ae9176503693d3016d1109d2cade63d4f0b661b142d7fc3368369ac3fe9c86154659a17518" | ||
|
||
class TestAuthorizationBits(unittest.TestCase): | ||
log = logging.getLogger("AuthBits") | ||
|
||
def test_parse_authorization_bits(self): | ||
self.log.info( | ||
" Testing CERT_WITH_RID_READ_DG1_WRITE_DG22_VERIFY_AGE_INSTALL_CERT" | ||
) | ||
cvc = CVC().decode( | ||
binascii.unhexlify( | ||
CERT_WITH_RID_READ_DG1_WRITE_DG22_VERIFY_AGE_INSTALL_CERT | ||
) | ||
) | ||
self.log.info(cvc) | ||
bits = decode_authorization_bits(cvc.role().find(0x53).data()) | ||
|
||
self.log.info("Raw authorization bits:" + bits) | ||
for bit in AuthorizationBits: | ||
self.log.info( | ||
"Field '{:<32}' has value: {:^6} at offset: {:2}".format( | ||
bit, | ||
str(bits[AuthorizationBits[bit]] == "1"), | ||
AuthorizationBits[bit], | ||
) | ||
) | ||
self.assertTrue(bits[AuthorizationBits["Age Verification"]]) | ||
self.assertTrue(bits[AuthorizationBits["Restricted Identification"]]) | ||
self.assertTrue(bits[AuthorizationBits["Install Certificate"]]) | ||
self.assertTrue(bits[AuthorizationBits["Read Datagroup 01"]]) | ||
self.assertTrue(bits[AuthorizationBits["Write Datagroup 22"]]) | ||
|
||
self.log.info(" Testing CERT_WITH_RID_READ_DG22") | ||
cvc = CVC().decode(binascii.unhexlify(CERT_WITH_RID_READ_DG22)) | ||
self.log.info(cvc) | ||
bits = decode_authorization_bits(cvc.role().find(0x53).data()) | ||
|
||
self.log.info("Raw authorization bits:" + bits) | ||
for bit in AuthorizationBits: | ||
self.log.info( | ||
"Field '{:<32}' has value: {:^6} at offset: {:2}".format( | ||
bit, | ||
str(bits[AuthorizationBits[bit]] == "1"), | ||
AuthorizationBits[bit], | ||
) | ||
) | ||
self.assertTrue(bits[AuthorizationBits["Restricted Identification"]]) | ||
self.assertTrue(bits[AuthorizationBits["Read Datagroup 22"]]) | ||
|
||
|
||
if __name__ == "__main__": | ||
logging.basicConfig(stream=sys.stderr) | ||
logging.getLogger().setLevel(logging.DEBUG) | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import binascii | ||
import argparse | ||
|
||
|
||
def file_to_hex(filename): | ||
with open(filename, "rb") as f: | ||
content = f.read() | ||
print(binascii.hexlify(content)) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser( | ||
description="Helper util to convert CVCert(or any file) to hex string" | ||
) | ||
parser.add_argument("file", help="File to convert to hex") | ||
|
||
args = parser.parse_args() | ||
|
||
file_to_hex(args.file) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not necessary to have a dict, a reverse list is sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the explicit functionality to check set bits with human readable strings like
self.assertTrue(bits[AuthorizationBits["Age Verification"]])
How would you structure the code with a reverse list ?