-
Notifications
You must be signed in to change notification settings - Fork 27
Some steps towards PACE support #37
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
Open
qistoph
wants to merge
23
commits into
bettse:main
Choose a base branch
from
qistoph:pace
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
e907444
Fix some buffer size issues, preventing crashes
qistoph 9e77a02
Add initial auth menu
qistoph 823d5a2
Back to adv.menu after error on reading advanced
qistoph faa6443
Add type codes
qistoph 22754c8
Save DG2 and DG7 to document specific file
qistoph 2979e39
Delay reading progress update for readability
qistoph e01d7f8
Use tx_buffer for wrapping
qistoph 9607156
Wrap/Unwrap secure messaging in single function
qistoph 7743291
Rename passy_reader_authenticate to passy_reader_external_authenticate
qistoph bf3de88
Make buffer const
qistoph c6cc6bd
Move AuthMethod consts+helper to passy_common. Store/use auth method …
qistoph bf75a32
Add TODO: fix still not showing progress
qistoph 53fc893
Read EF.CardAccess
qistoph 05cfcbf
Add SecurityInfos to ASN1 (for CardAccess)
qistoph c943f54
Hack - Disable missing qsort
qistoph 720c59e
WIP: Parsing CardAccess
qistoph 5ee1a70
Add qsort circumvention
qistoph 7087f69
Fix line endings
qistoph a24c8a5
bsearch testing
qistoph fb220c4
bsearch oid test
qistoph f7d1932
Format code remove test program
qistoph f259767
Fix typo in PACE GM NID
qistoph 3d239f8
Add warning to generated .h files
qistoph 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 hidden or 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 |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| dist | ||
| .vscode | ||
| .aider* | ||
| lib/oid/test | ||
| *.swp | ||
| application.fam | ||
| bsearch_test | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,159 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| #TODO: read and parse these OIDs from eMRTD.asn1 | ||
|
|
||
| oids = { | ||
| 'itu_t': [0], | ||
| 'iso': [1], | ||
| 'joint_iso_itu_t': [2], | ||
| 'member_body': ['iso', 2], | ||
| 'identified_organization': ['iso', 3], | ||
| 'etsi': ['itu_t', 4, 0], | ||
| 'etsi_identified_organization': ['etsi', 127, 0], | ||
| 'bsi_de': [0, 4, 0, 127, 0, 7], | ||
| 'id_PACE': ['bsi_de', 2, 2, 4], | ||
| 'id_PACE_DH_GM': ['id_PACE', 1], | ||
| 'id_PACE_DH_GM_3DES_CBC_CBC': ['id_PACE_DH_GM', 1], | ||
| 'id_PACE_DH_GM_AES_CBC_CMAC_128': ['id_PACE_DH_GM', 2], | ||
| 'id_PACE_DH_GM_AES_CBC_CMAC_192': ['id_PACE_DH_GM', 3], | ||
| 'id_PACE_DH_GM_AES_CBC_CMAC_256': ['id_PACE_DH_GM', 4], | ||
| 'id_PACE_ECDH_GM': ['id_PACE', 2], | ||
| 'id_PACE_ECDH_GM_3DES_CBC_CBC': ['id_PACE_ECDH_GM', 1], | ||
| 'id_PACE_ECDH_GM_AES_CBC_CMAC_128': ['id_PACE_ECDH_GM', 2], | ||
| 'id_PACE_ECDH_GM_AES_CBC_CMAC_192': ['id_PACE_ECDH_GM', 3], | ||
| 'id_PACE_ECDH_GM_AES_CBC_CMAC_256': ['id_PACE_ECDH_GM', 4], | ||
| 'id_PACE_DH_IM': ['id_PACE', 3], | ||
| 'id_PACE_DH_IM_3DES_CBC_CBC': ['id_PACE_DH_IM', 1], | ||
| 'id_PACE_DH_IM_AES_CBC_CMAC_128': ['id_PACE_DH_IM', 2], | ||
| 'id_PACE_DH_IM_AES_CBC_CMAC_192': ['id_PACE_DH_IM', 3], | ||
| 'id_PACE_DH_IM_AES_CBC_CMAC_256': ['id_PACE_DH_IM', 4], | ||
| 'id_PACE_ECDH_IM': ['id_PACE', 4], | ||
| 'id_PACE_ECDH_IM_3DES_CBC_CBC': ['id_PACE_ECDH_IM', 1], | ||
| 'id_PACE_ECDH_IM_AES_CBC_CMAC_128': ['id_PACE_ECDH_IM', 2], | ||
| 'id_PACE_ECDH_IM_AES_CBC_CMAC_192': ['id_PACE_ECDH_IM', 3], | ||
| 'id_PACE_ECDH_IM_AES_CBC_CMAC_256': ['id_PACE_ECDH_IM', 4], | ||
| 'id_PACE_ECDH_CAM': ['id_PACE', 6], | ||
| 'id_PACE_ECDH_CAM_AES_CBC_CMAC_128': ['id_PACE_ECDH_CAM', 2], | ||
| 'id_PACE_ECDH_CAM_AES_CBC_CMAC_192': ['id_PACE_ECDH_CAM', 3], | ||
| 'id_PACE_ECDH_CAM_AES_CBC_CMAC_256': ['id_PACE_ECDH_CAM', 4], | ||
| } | ||
|
|
||
| import re | ||
| re_numeric = re.compile(r'\d+') | ||
|
|
||
| def numeric_arcs(oids, arcs): | ||
| ret = [] | ||
|
|
||
| offset = 0 | ||
| if isinstance(arcs[0], str): | ||
| base_oid = oids[arcs[0]] | ||
| ret.extend(numeric_arcs(oids, base_oid)) | ||
| offset = 1 | ||
|
|
||
| ret.extend(arcs[offset:]) | ||
| return ret | ||
|
|
||
| def oid_bytes(arcs): | ||
| ret = b'' | ||
|
|
||
| if len(arcs) == 0: | ||
| return ret | ||
|
|
||
| if len(arcs) == 1: | ||
| ret += bytes([40*arcs[0]]) | ||
| return ret | ||
|
|
||
| ret += bytes([40*arcs[0] + arcs[1]]) | ||
|
|
||
| ret += bytes(arcs[2:]) | ||
|
|
||
| return ret | ||
|
|
||
| def bytes_to_c_array(data): | ||
| return [format(b, '#04x') for b in data] | ||
|
|
||
| def cmp_arcs(a, b): | ||
| a = a[1] | ||
| b = b[1] | ||
| if len(a) != len(b): | ||
| return len(a) - len(b) | ||
|
|
||
| for (va, vb) in zip(a, b): | ||
| if va != vb: | ||
| return va - vb | ||
|
|
||
| return 0 | ||
|
|
||
| oids = {k: numeric_arcs(oids, v) for k, v in oids.items()} | ||
|
|
||
| from functools import cmp_to_key | ||
| sorted_oids = {k: v for k, v in sorted(oids.items(), key=cmp_to_key(cmp_arcs))} | ||
|
|
||
| c_offset = 0 | ||
| nid_count = 0 | ||
| so_data = '' | ||
| defines = '#define NID_undef 0\n' | ||
| c_offsets = {} | ||
| c_lengths = {} | ||
| for name, value in oids.items(): | ||
| #print(name, value) | ||
| #print(num_arcs) | ||
| #print(oid_bytes(num_arcs)) | ||
|
|
||
| if len(value) < 2: continue | ||
|
|
||
| arc_bytes = oid_bytes(value) | ||
|
|
||
| c_offsets[name] = c_offset | ||
| c_lengths[name] = len(arc_bytes) | ||
|
|
||
| nid_count += 1 | ||
| defines += f'#define NID_{name} {nid_count}\n'; | ||
|
|
||
| c_data = ', '.join(bytes_to_c_array(arc_bytes)) + ',' | ||
| so_data += f' {c_data.ljust(60)} /* [{str(c_offset).rjust(5)}] NID_{name} = {nid_count} */\n' | ||
| c_offset += len(arc_bytes) | ||
|
|
||
| with open('oid_nids.h', 'w') as f: | ||
| f.write('''#ifndef PASSY_OID_NIDS_H | ||
| #define PASSY_OID_NIDS_H | ||
|
|
||
| /* DO NOT MODIFY THIS FILE | ||
| * This file was generated by gen_oid_nid_list.py | ||
| */ | ||
|
|
||
| #include <OBJECT_IDENTIFIER.h> | ||
|
|
||
| typedef struct OID_NID_s { | ||
| OBJECT_IDENTIFIER_t oid; | ||
| int nid; | ||
| } OID_NID_t; | ||
|
|
||
| ''') | ||
| f.write(f'#define NUM_NID {nid_count}\n\n') | ||
| f.write(defines) | ||
| f.write(''' | ||
| #endif''') | ||
|
|
||
| with open('oid_data.h', 'w') as f: | ||
|
|
||
| f.write(''' | ||
| /* DO NOT MODIFY THIS FILE | ||
| * This file was generated by gen_oid_nid_list.py | ||
| */ | ||
|
|
||
| #include "oid_nids.h" | ||
|
|
||
| ''') | ||
|
|
||
| #TODO: make const, but conflicts with non const in OBJECT_IDENTIFIER_t | ||
| f.write(f'static unsigned char so[{c_offset}] = {{\n{so_data}}};\n') | ||
| f.write('\n\n') | ||
|
|
||
| f.write('static const OID_NID_t obj_nids[NUM_NID] = {\n') | ||
| for name, value in sorted_oids.items(): | ||
| if len(value) < 2: continue | ||
| offset = c_offsets[name] | ||
| length = c_lengths[name] | ||
| f.write(f' {{{{&so[{offset}], {length}}}, NID_{name}}},\n') | ||
| f.write('};\n') |
This file contains hidden or 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,21 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| import sys | ||
| import re | ||
|
|
||
| r_qsort = re.compile('(\s*)([^/]*qsort.*)') | ||
|
|
||
| data = [] | ||
| with open(sys.argv[1], 'r+') as f: | ||
| for line in f: | ||
| m = r_qsort.match(line) | ||
| if m: | ||
| data.append(m.group(1) + "assert(false);\n") | ||
| data.append(m.group(1) + "//" + m.group(2) + "\n") | ||
| else: | ||
| data.append(line) | ||
|
|
||
| f.seek(0) | ||
| for d in data: | ||
| f.write(d) | ||
| f.truncate() |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.