mirror of
https://github.com/polhenarejos/pico-hsm.git
synced 2026-01-17 09:28:05 +00:00
Fixes in windows backend.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
parent
8718f55df2
commit
abf980d84e
2 changed files with 8 additions and 8 deletions
|
|
@ -2,7 +2,7 @@ import sys
|
||||||
import keyring
|
import keyring
|
||||||
|
|
||||||
DOMAIN = "PicoKeys.com"
|
DOMAIN = "PicoKeys.com"
|
||||||
USERNAME = "Pico-Fido"
|
USERNAME = "Pico-HSM"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import keyring
|
import keyring
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import os
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
DOMAIN = "PicoKeys.com"
|
DOMAIN = "PicoKeys.com"
|
||||||
USERNAME = "Pico-Fido"
|
USERNAME = "Pico-HSM"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import keyring
|
import keyring
|
||||||
|
|
@ -12,7 +12,7 @@ except:
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from cryptography.hazmat.primitives.serialization import Encoding, PrivateFormat, NoEncryption
|
from cryptography.hazmat.primitives.serialization import Encoding, PrivateFormat, NoEncryption, load_pem_private_key
|
||||||
from cryptography.hazmat.primitives.asymmetric import ec
|
from cryptography.hazmat.primitives.asymmetric import ec
|
||||||
except:
|
except:
|
||||||
print('ERROR: cryptography module not found! Install cryptography package.\nTry with `pip install cryptography`')
|
print('ERROR: cryptography module not found! Install cryptography package.\nTry with `pip install cryptography`')
|
||||||
|
|
@ -26,19 +26,19 @@ def generate_secure_key():
|
||||||
return keyring.get_password(DOMAIN, USERNAME)
|
return keyring.get_password(DOMAIN, USERNAME)
|
||||||
|
|
||||||
def get_d(key):
|
def get_d(key):
|
||||||
return key.private_numbers().private_value.to_bytes(32, 'big')
|
return load_pem_private_key(key, password=None).private_numbers().private_value.to_bytes(32, 'big')
|
||||||
|
|
||||||
def set_secure_key(pk):
|
def set_secure_key(pk):
|
||||||
try:
|
try:
|
||||||
keyring.delete_password(DOMAIN, USERNAME)
|
keyring.delete_password(DOMAIN, USERNAME)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
keyring.set_password(DOMAIN, USERNAME, pk.private_bytes(Encoding.PEM, PrivateFormat.TraditionalOpenSSL, NoEncryption()))
|
keyring.set_password(DOMAIN, USERNAME, pk.private_bytes(Encoding.PEM, PrivateFormat.PKCS8, NoEncryption()).decode())
|
||||||
|
|
||||||
def get_secure_key():
|
def get_secure_key():
|
||||||
key = None
|
key = None
|
||||||
try:
|
try:
|
||||||
key = keyring.get_password(DOMAIN, USERNAME)[0]
|
key = keyring.get_password(DOMAIN, USERNAME)
|
||||||
except keyring.errors.KeyringError:
|
except keyring.errors.KeyringError:
|
||||||
key = generate_secure_key()[0]
|
key = generate_secure_key()
|
||||||
return get_d(key)
|
return get_d(key.encode())
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue