forked from latchset/pkcs11-provider
-
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.
Add uri2pem.py tool to create pkcs11-provider PEM key files
Signed-off-by: S-P Chan <[email protected]>
- Loading branch information
1 parent
673e4fd
commit bb76d56
Showing
1 changed file
with
34 additions
and
0 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
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="") |