|
1 | | -import board |
2 | | -import busio |
3 | | -import time |
4 | | -import adafruit_ssd1306 |
5 | | -from adafruit_atecc.adafruit_atecc import ATECC, _WAKE_CLK_FREQ, CFG_TLS |
6 | | - |
7 | | -import adafruit_atecc.adafruit_atecc_cert_util as cert_utils |
8 | | - |
9 | | -# -- Enter your configuration below -- # |
10 | | - |
11 | | -# Lock the ATECC module when the code is run? |
12 | | -LOCK_ATECC = True |
13 | | -# 2-letter country code |
14 | | -MY_COUNTRY = "US" |
15 | | -# State or Province Name |
16 | | -MY_STATE = "New York" |
17 | | -# City Name |
18 | | -MY_CITY = "New York" |
19 | | -# Organization Name |
20 | | -MY_ORG = "Adafruit" |
21 | | -# Organizational Unit Name |
22 | | -MY_SECTION = "Crypto" |
23 | | -# Which ATECC slot (0-4) to use |
24 | | -ATECC_SLOT = 0 |
25 | | -# Generate new private key, or use existing key |
26 | | -GENERATE_PRIVATE_KEY = False |
27 | | - |
28 | | -# -- END Configuration, code below -- # |
29 | | - |
30 | | -# Initialize the i2c bus |
31 | | -i2c = busio.I2C(board.SCL, board.SDA, |
32 | | - frequency=_WAKE_CLK_FREQ) |
33 | | - |
34 | | -# Initialize a new atecc object |
35 | | -atecc = ATECC(i2c) |
36 | | - |
37 | | -print("ATECC Serial Number: ", atecc.serial_number) |
38 | | - |
39 | | -if not atecc.locked: |
40 | | - if not LOCK_ATECC: |
41 | | - raise RuntimeError("The ATECC is not locked, set LOCK_ATECC to True in your code.py to unlock it.") |
42 | | - print("Writing default configuration to the device...") |
43 | | - atecc.write_config(CFG_TLS) |
44 | | - print("Wrote configuration, locking ATECC module...") |
45 | | - # Lock ATECC config, data, and otp zones |
46 | | - atecc.lock_all_zones() |
47 | | - print("ATECC locked!") |
48 | | - |
49 | | -print("Generating Certificate Signing Request...") |
50 | | -# Initialize a certificate signing request with provided info |
51 | | -csr = cert_utils.CSR(atecc, ATECC_SLOT, GENERATE_PRIVATE_KEY, MY_COUNTRY, MY_STATE, |
52 | | - MY_CITY, MY_ORG, MY_SECTION) |
53 | | -# Generate CSR |
54 | | -my_csr = csr.generate_csr() |
55 | | -print("-----BEGIN CERTIFICATE REQUEST-----\n") |
56 | | -print(my_csr.decode('utf-8')) |
57 | | -print("-----END CERTIFICATE REQUEST-----") |
| 1 | +import board |
| 2 | +import busio |
| 3 | +from adafruit_atecc.adafruit_atecc import ATECC, _WAKE_CLK_FREQ, CFG_TLS |
| 4 | + |
| 5 | +import adafruit_atecc.adafruit_atecc_cert_util as cert_utils |
| 6 | + |
| 7 | +# -- Enter your configuration below -- # |
| 8 | + |
| 9 | +# Lock the ATECC module when the code is run? |
| 10 | +LOCK_ATECC = True |
| 11 | +# 2-letter country code |
| 12 | +MY_COUNTRY = "US" |
| 13 | +# State or Province Name |
| 14 | +MY_STATE = "New York" |
| 15 | +# City Name |
| 16 | +MY_CITY = "New York" |
| 17 | +# Organization Name |
| 18 | +MY_ORG = "Adafruit" |
| 19 | +# Organizational Unit Name |
| 20 | +MY_SECTION = "Crypto" |
| 21 | +# Which ATECC slot (0-4) to use |
| 22 | +ATECC_SLOT = 0 |
| 23 | +# Generate new private key, or use existing key |
| 24 | +GENERATE_PRIVATE_KEY = False |
| 25 | + |
| 26 | +# -- END Configuration, code below -- # |
| 27 | + |
| 28 | +# Initialize the i2c bus |
| 29 | +i2c = busio.I2C(board.SCL, board.SDA, |
| 30 | + frequency=_WAKE_CLK_FREQ) |
| 31 | + |
| 32 | +# Initialize a new atecc object |
| 33 | +atecc = ATECC(i2c) |
| 34 | + |
| 35 | +print("ATECC Serial Number: ", atecc.serial_number) |
| 36 | + |
| 37 | +if not atecc.locked: |
| 38 | + if not LOCK_ATECC: |
| 39 | + raise RuntimeError("The ATECC is not locked, set LOCK_ATECC to True in code.py.") |
| 40 | + print("Writing default configuration to the device...") |
| 41 | + atecc.write_config(CFG_TLS) |
| 42 | + print("Wrote configuration, locking ATECC module...") |
| 43 | + # Lock ATECC config, data, and otp zones |
| 44 | + atecc.lock_all_zones() |
| 45 | + print("ATECC locked!") |
| 46 | + |
| 47 | +print("Generating Certificate Signing Request...") |
| 48 | +# Initialize a certificate signing request with provided info |
| 49 | +csr = cert_utils.CSR(atecc, ATECC_SLOT, GENERATE_PRIVATE_KEY, MY_COUNTRY, MY_STATE, |
| 50 | + MY_CITY, MY_ORG, MY_SECTION) |
| 51 | +# Generate CSR |
| 52 | +my_csr = csr.generate_csr() |
| 53 | +print("-----BEGIN CERTIFICATE REQUEST-----\n") |
| 54 | +print(my_csr.decode('utf-8')) |
| 55 | +print("-----END CERTIFICATE REQUEST-----") |
0 commit comments