Only request and upload the device certificate if needed.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos 2024-11-08 17:45:48 +01:00
parent 9b9ea7cae5
commit f1410bbf04
No known key found for this signature in database
GPG key ID: C0095B7870A4CCD3

View file

@ -217,24 +217,27 @@ def initialize(picohsm, args):
so_pin = '57621880' so_pin = '57621880'
picohsm.initialize(pin=pin, sopin=so_pin) picohsm.initialize(pin=pin, sopin=so_pin)
response = picohsm.get_contents(DOPrefixes.EE_CERTIFICATE_PREFIX, 0x00) try:
picohsm.select_file(0x2f02)
except APDUResponse:
response = picohsm.get_contents(DOPrefixes.EE_CERTIFICATE_PREFIX, 0x00)
cert = bytearray(response) cert = bytearray(response)
Y = CVC().decode(cert).pubkey().find(0x86).data() Y = CVC().decode(cert).pubkey().find(0x86).data()
print(f'Public Point: {hexlify(Y).decode()}') print(f'Public Point: {hexlify(Y).decode()}')
pbk = base64.urlsafe_b64encode(Y) pbk = base64.urlsafe_b64encode(Y)
data = urllib.parse.urlencode({'pubkey': pbk}).encode() data = urllib.parse.urlencode({'pubkey': pbk}).encode()
j = get_pki_data('cvc', data=data) j = get_pki_data('cvc', data=data)
print('Device name: '+j['devname']) print('Device name: '+j['devname'])
dataef = base64.urlsafe_b64decode( dataef = base64.urlsafe_b64decode(
j['cvcert']) + base64.urlsafe_b64decode(j['dvcert']) + base64.urlsafe_b64decode(j['cacert']) j['cvcert']) + base64.urlsafe_b64decode(j['dvcert']) + base64.urlsafe_b64decode(j['cacert'])
picohsm.select_file(0x2f02) picohsm.select_file(0x2f02)
response = picohsm.put_contents(0x0000, data=dataef) response = picohsm.put_contents(0x0000, data=dataef)
print('Certificate uploaded successfully!') print('Certificate uploaded successfully!')
print('') print('')
print('Note that the device is initialized with a default PIN and ' print('Note that the device is initialized with a default PIN and '
'configuration.') 'configuration.')
print('Now you can initialize the device as usual with your chosen PIN ' print('Now you can initialize the device as usual with your chosen PIN '