@@ -96,14 +96,15 @@ text without prepended symbols is the output of a command.
96
96
# following function creates an RSA key pair, where the private key is saved to
97
97
# "root_key" and the public key to "root_key.pub" (both saved to the current
98
98
# working directory).
99
- >> > generate_and_write_rsa_keypair(" root_key " , bits = 2048 , password = " password " )
99
+ >> > generate_and_write_rsa_keypair(password = " password " , filepath = " root_key " , bits = 2048 )
100
100
101
101
# If the key length is unspecified, it defaults to 3072 bits. A length of less
102
- # than 2048 bits raises an exception. A password may be supplied as an
103
- # argument, otherwise a user prompt is presented. If an empty password
104
- # is entered, the private key is saved unencrypted.
105
- >> > generate_and_write_rsa_keypair(" root_key2" )
106
- Enter a password for the RSA key (/ path/ to/ root_key2):
102
+ # than 2048 bits raises an exception. A similar function is available to supply
103
+ # a password on the prompt. If an empty password is entered, the private key
104
+ # is saved unencrypted.
105
+ >> > generate_and_write_rsa_keypair_with_prompt(filepath = " root_key2" )
106
+ enter password to encrypt private key file ' /path/to/root_key2'
107
+ (leave empty if key should not be encrypted):
107
108
Confirm:
108
109
```
109
110
The following four key files should now exist:
@@ -117,8 +118,9 @@ If a filepath is not given, the KEYID of the generated key is used as the
117
118
filename. The key files are written to the current working directory.
118
119
``` python
119
120
# Continuing from the previous section . . .
120
- >> > generate_and_write_rsa_keypair()
121
- Enter a password for the encrypted RSA key (/ path/ to/ b5b8de8aeda674bce948fbe82cab07e309d6775fc0ec299199d16746dc2bd54c):
121
+ >> > generate_and_write_rsa_keypair_with_prompt()
122
+ enter password to encrypt private key file ' /path/to/KEYID'
123
+ (leave empty if key should not be encrypted):
122
124
Confirm:
123
125
```
124
126
@@ -132,36 +134,27 @@ Confirm:
132
134
# Import an existing private key. Importing a private key requires a password,
133
135
# whereas importing a public key does not.
134
136
>> > private_root_key = import_rsa_privatekey_from_file(" root_key" )
135
- Enter a password for the encrypted RSA key (/ path/ to/ root_key):
136
- ```
137
-
138
- `import_rsa_privatekey_from_file()` raises a
139
- `securesystemslib.exceptions.CryptoError` exception if the key / password is
140
- invalid:
141
-
142
- ```
143
- securesystemslib.exceptions.CryptoError: RSA (public, private) tuple cannot be
144
- generated from the encrypted PEM string: Bad decrypt. Incorrect password?
137
+ enter password to decrypt private key file ' /path/to/root_key'
138
+ (leave empty if key not encrypted):
145
139
```
146
140
147
141
### Create and Import Ed25519 Keys ###
148
142
``` Python
149
143
# Continuing from the previous section . . .
150
144
151
- # Generate and write an Ed25519 key pair. A 'password' argument may be
152
- # supplied, otherwise a prompt is presented. The private key is saved
153
- # encrypted if a non-empty password is given, and unencrypted if the password
154
- # is empty.
155
- >> > generate_and_write_ed25519_keypair(' ed25519_key' )
156
- Enter a password for the Ed25519 key (/ path/ to/ ed25519_key):
145
+ # The same generation and import functions as for rsa keys exist for ed25519
146
+ >> > generate_and_write_ed25519_keypair_with_prompt(filepath = ' ed25519_key' )
147
+ enter password to encrypt private key file ' /path/to/ed25519_key'
148
+ (leave empty if key should not be encrypted):
157
149
Confirm:
158
150
159
151
# Import the ed25519 public key just created . . .
160
152
>> > public_ed25519_key = import_ed25519_publickey_from_file(' ed25519_key.pub' )
161
153
162
154
# and its corresponding private key.
163
155
>> > private_ed25519_key = import_ed25519_privatekey_from_file(' ed25519_key' )
164
- Enter a password for the encrypted Ed25519 key (/ path/ to/ ed25519_key):
156
+ enter password to decrypt private key file ' /path/to/ed25519_key'
157
+ (leave empty if key should not be encrypted):
165
158
```
166
159
167
160
Note: Methods are also available to generate and write keys from memory.
@@ -259,26 +252,20 @@ secure manner.
259
252
>> > import datetime
260
253
261
254
# Generate keys for the remaining top-level roles. The root keys have been set above.
262
- # The password argument may be omitted if a password prompt is needed.
263
- >> > generate_and_write_rsa_keypair(' targets_key' , password = ' password' )
264
- >> > generate_and_write_rsa_keypair(' snapshot_key' , password = ' password' )
265
- >> > generate_and_write_rsa_keypair(' timestamp_key' , password = ' password' )
255
+ >> > generate_and_write_rsa_keypair(password = ' password' , filepath = ' targets_key' )
256
+ >> > generate_and_write_rsa_keypair(password = ' password' , filepath = ' snapshot_key' )
257
+ >> > generate_and_write_rsa_keypair(password = ' password' , filepath = ' timestamp_key' )
266
258
267
259
# Add the verification keys of the remaining top-level roles.
268
260
269
261
>> > repository.targets.add_verification_key(import_rsa_publickey_from_file(' targets_key.pub' ))
270
262
>> > repository.snapshot.add_verification_key(import_rsa_publickey_from_file(' snapshot_key.pub' ))
271
263
>> > repository.timestamp.add_verification_key(import_rsa_publickey_from_file(' timestamp_key.pub' ))
272
264
273
- # Import the signing keys of the remaining top-level roles. Prompt for passwords.
274
- >> > private_targets_key = import_rsa_privatekey_from_file(' targets_key' )
275
- Enter a password for the encrypted RSA key (/ path/ to/ targets_key):
276
-
277
- >> > private_snapshot_key = import_rsa_privatekey_from_file(' snapshot_key' )
278
- Enter a password for the encrypted RSA key (/ path/ to/ snapshot_key):
279
-
280
- >> > private_timestamp_key = import_rsa_privatekey_from_file(' timestamp_key' )
281
- Enter a password for the encrypted RSA key (/ path/ to/ timestamp_key):
265
+ # Import the signing keys of the remaining top-level roles.
266
+ >> > private_targets_key = import_rsa_privatekey_from_file(' targets_key' , password = ' password' )
267
+ >> > private_snapshot_key = import_rsa_privatekey_from_file(' snapshot_key' , password = ' password' )
268
+ >> > private_timestamp_key = import_rsa_privatekey_from_file(' timestamp_key' , password = ' password' )
282
269
283
270
# Load the signing keys of the remaining roles so that valid signatures are
284
271
# generated when repository.writeall() is called.
@@ -390,18 +377,21 @@ metadata. `snapshot.json` keys must be loaded and its metadata signed because
390
377
# The private key of the updated targets metadata must be re-loaded before it
391
378
# can be signed and written (Note the load_repository() call above).
392
379
>> > private_targets_key = import_rsa_privatekey_from_file(' targets_key' )
393
- Enter a password for the encrypted RSA key (/ path/ to/ targets_key):
380
+ enter password to decrypt private key file ' /path/to/targets_key'
381
+ (leave empty if key not encrypted):
394
382
395
383
>> > repository.targets.load_signing_key(private_targets_key)
396
384
397
385
# Due to the load_repository() and new versions of metadata, we must also load
398
386
# the private keys of Snapshot and Timestamp to generate a valid set of metadata.
399
387
>> > private_snapshot_key = import_rsa_privatekey_from_file(' snapshot_key' )
400
- Enter a password for the encrypted RSA key (/ path/ to/ snapshot_key):
388
+ enter password to decrypt private key file ' /path/to/snapshot_key'
389
+ (leave empty if key not encrypted):
401
390
>> > repository.snapshot.load_signing_key(private_snapshot_key)
402
391
403
392
>> > private_timestamp_key = import_rsa_privatekey_from_file(' timestamp_key' )
404
- Enter a password for the encrypted RSA key (/ path/ to/ timestamp_key):
393
+ enter password to decrypt private key file ' /path/to/timestamp_key'
394
+ (leave empty if key not encrypted):
405
395
>> > repository.timestamp.load_signing_key(private_timestamp_key)
406
396
407
397
# Mark roles for metadata update (see #964, #958)
@@ -451,7 +441,7 @@ threshold, it needs to be added to `root.json`, e.g. via
451
441
>> > from securesystemslib.formats import encode_canonical
452
442
>> > from securesystemslib.keys import create_signature
453
443
>> > private_ed25519_key = import_ed25519_privatekey_from_file(' ed25519_key' )
454
- Enter a password for the encrypted Ed25519 key ( / path/ to/ ed25519_key):
444
+ enter password to decrypt private key file ' /path/to/ed25519_key'
455
445
>> > signature = create_signature(
456
446
... private_ed25519_key, encode_canonical(signable_content).encode())
457
447
```
@@ -489,7 +479,7 @@ targets and generate signed metadata.
489
479
# Continuing from the previous section . . .
490
480
491
481
# Generate a key for a new delegated role named "unclaimed".
492
- >> > generate_and_write_rsa_keypair(' unclaimed_key ' , bits = 2048 , password = ' password ' )
482
+ >> > generate_and_write_rsa_keypair(password = ' password ' , filepath = ' unclaimed_key ' , bits = 2048 )
493
483
>> > public_unclaimed_key = import_rsa_publickey_from_file(' unclaimed_key.pub' )
494
484
495
485
# Make a delegation (delegate trust of 'myproject/*.txt' files) from "targets"
@@ -502,8 +492,7 @@ targets and generate signed metadata.
502
492
503
493
# Load the private key of "unclaimed" so that unclaimed's metadata can be
504
494
# signed, and valid metadata created.
505
- >> > private_unclaimed_key = import_rsa_privatekey_from_file(' unclaimed_key' )
506
- Enter a password for the encrypted RSA key (/ path/ to/ unclaimed_key):
495
+ >> > private_unclaimed_key = import_rsa_privatekey_from_file(' unclaimed_key' , password = ' password' )
507
496
508
497
>> > repository.targets(" unclaimed" ).load_signing_key(private_unclaimed_key)
509
498
0 commit comments