Skip to content

Commit

Permalink
Add uri2pem.py tool to create pkcs11-provider PEM key files
Browse files Browse the repository at this point in the history
Signed-off-by: S-P Chan <[email protected]>
  • Loading branch information
space88man committed Mar 20, 2024
1 parent 673e4fd commit bb76d56
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tools/uri2pem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
CLI tool to create pkcs11-provider pem files from a key uri
Requirements: asn1crypto
Installation:
pip install asn1crypto
dnf install python3-asn1crypto
Usage:
python keytool.py 'pkcs11:URI-goes-here'
"""

import sys
from asn1crypto.core import Sequence, VisibleString, UTF8String
from asn1crypto import pem


class Pkcs11PrivateKey(Sequence):
_fields = [("desc", VisibleString), ("uri", UTF8String)]


if __name__ == "__main__":
if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} private-key-uri")
sys.exit(1)

data = Pkcs11PrivateKey(
{
"desc": VisibleString("PKCS#11 Provider URI v1.0"),
"uri": UTF8String(sys.argv[1]),
}
)

print(pem.armor("PKCS#11 PROVIDER URI", data.dump()).decode("ascii"), end="")

0 comments on commit bb76d56

Please sign in to comment.