This repository has been archived by the owner on Feb 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'uzipoc_q4_2024' into feature/pkcs-check
- Loading branch information
Showing
9 changed files
with
295 additions
and
108 deletions.
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import logging | ||
from app.bootstrap import ApplicationBootstrapper | ||
from dotenv import load_dotenv | ||
|
||
|
||
if __name__ == "__main__": | ||
logging.basicConfig(level=logging.INFO) | ||
load_dotenv() | ||
|
||
ApplicationBootstrapper().start() |
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,76 @@ | ||
import PyKCS11 | ||
|
||
from app.yubikey_details import YubikeyDetails | ||
from app.pkcs import pkcs as PKCSWrapper | ||
|
||
|
||
class YubikeyContentChecker: | ||
HEADERS = [ | ||
"X.509 Certificate", | ||
"Public key", | ||
"Private key", | ||
"PIV Attestation", | ||
"UZI Certificate", | ||
] | ||
|
||
LABEL_MAPPING = { | ||
"PIV Authentication": " 9a", | ||
"Digital Signature": " 9c", | ||
"Key Management": "9d", | ||
"Card Authentication": " 9e", | ||
} | ||
_pkcs: PKCSWrapper | ||
|
||
def __init__(self, pkcs_wrapper: PKCSWrapper): | ||
self._pkcs = pkcs_wrapper | ||
|
||
def _find_objects(self, session: PyKCS11.Session): | ||
# This creates an dictionary of 4 items, with inside a dictionary of 3 items, all values to False | ||
# { | ||
# 0: {0: False, 1: False, 2: False}, | ||
# 1: {0: False, 1: False, 2: False}, | ||
# 2: {0: False, 1: False, 2: False}, | ||
# 3: {0: False, 1: False, 2: False}, | ||
# } | ||
finds = {index: {row: False for row in range(3)} for index in range(4)} | ||
|
||
cko_types_to_check = [ | ||
PyKCS11.CKO_CERTIFICATE, | ||
PyKCS11.CKO_PUBLIC_KEY, | ||
PyKCS11.CKO_PRIVATE_KEY, | ||
PyKCS11.CKO_CERTIFICATE, | ||
] | ||
# Iterate through the cryptographic objects to check and save the index | ||
for index, cko_type in enumerate(cko_types_to_check): | ||
# Find the objects in the session matching the selected CKO type | ||
# https://pkcs11wrap.sourceforge.io/api/api.html#PyKCS11.Session.findObjects | ||
all_objects = session.findObjects( | ||
[(PyKCS11.CKA_CLASS, cko_type)], | ||
) | ||
|
||
# Loop through every mapping with each key and value and save the index | ||
for row, (label_key, label_value) in enumerate(self.LABEL_MAPPING.items()): | ||
for obj in all_objects: | ||
# For each found object, retrieve the CKA_LABEL | ||
label = session.getAttributeValue(obj, [PyKCS11.CKA_LABEL])[0] | ||
|
||
if label == self.HEADERS[index] + " for " + label_key and index < 3: | ||
finds[index][row] = True | ||
break | ||
|
||
if label == "X.509 Certificate for PIV Attestation" + label_value and index == 3: | ||
finds[index][row] = True | ||
break | ||
|
||
return finds | ||
|
||
def check(self, yubikey: YubikeyDetails): | ||
session = self._pkcs.getsession( | ||
yubikey.slot, | ||
) | ||
finds = self._find_objects(session) | ||
|
||
self._pkcs.delsession(yubikey.slot) | ||
|
||
# Check if any of the finds are true | ||
return any(value for inner_dict in finds.values() for value in inner_dict.values()) |
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,8 @@ | ||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class YubikeyDetails: | ||
slot: str | ||
serial: str | ||
name: str |
Oops, something went wrong.