-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathinfo.py
More file actions
95 lines (77 loc) · 3.38 KB
/
info.py
File metadata and controls
95 lines (77 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"""
Device Info Retrieval Example
"""
# (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.
#
# Subject to your compliance with these terms, you may use Microchip software
# and any derivatives exclusively with Microchip products. It is your
# responsibility to comply with third party license terms applicable to your
# use of third party software (including open source software) that may
# accompany Microchip software.
#
# THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
# EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
# WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
# PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT,
# SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE
# OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
# MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
# FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL
# LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED
# THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR
# THIS SOFTWARE.
from cryptoauthlib import *
from common import *
def info(iface='hid', device='ecc', **kwargs):
ATCA_SUCCESS = 0x00
# Get the target default config
cfg = eval('cfg_at{}a_{}_default()'.format(atca_names_map.get(device), atca_names_map.get(iface)))
# Set interface parameters
if kwargs is not None:
for k, v in kwargs.items():
icfg = getattr(cfg.cfg, 'atca{}'.format(iface))
setattr(icfg, k, int(v, 16))
# Basic Raspberry Pi I2C check
if 'bus' not in kwargs:
if 'i2c' == iface and check_if_rpi():
cfg.cfg.atcai2c.bus = 1
# Initialize the stack
assert atcab_init(cfg) == ATCA_SUCCESS
print('')
# Request the Revision Number
info = bytearray(4)
assert atcab_info(info) == ATCA_SUCCESS
print('\nDevice Part:')
print(' ' + get_device_name(info))
# Request the Serial Number
serial_number = bytearray(9)
assert atcab_read_serial_number(serial_number) == ATCA_SUCCESS
print('\nSerial number: ')
print(pretty_print_hex(serial_number, indent=' '))
# Read the configuration zone
config_zone = bytearray(128)
assert atcab_read_config_zone(config_zone) == ATCA_SUCCESS
print('\nConfiguration Zone:')
print(pretty_print_hex(config_zone, indent=' '))
# Check the device locks
print('\nCheck Device Locks')
is_locked = AtcaReference(False)
assert atcab_is_locked(0, is_locked) == ATCA_SUCCESS
config_zone_locked = bool(is_locked.value)
print(' Config Zone is %s' % ('locked' if config_zone_locked else 'unlocked'))
assert atcab_is_locked(1, is_locked) == ATCA_SUCCESS
data_zone_locked = bool(is_locked.value)
print(' Data Zone is %s' % ('locked' if data_zone_locked else 'unlocked'))
# Load the public key
if data_zone_locked:
print('\nLoading Public key\n')
public_key = bytearray(64)
assert atcab_get_pubkey(0, public_key) == ATCA_SUCCESS
print(convert_ec_pub_to_pem(public_key))
# Free the library
atcab_release()
if __name__ == '__main__':
parser = setup_example_runner(__file__)
args = parser.parse_args()
info(args.iface, args.device, **parse_interface_params(args.params))
print('\nDone')