|
65 | 65 | print() |
66 | 66 |
|
67 | 67 | if (sign == "ed25519"): |
68 | | - if os.path.exists(key_file): |
69 | | - print("Loading exiting ED25519 Key") |
70 | | - wolfboot_key_buffer = kf.read(64) |
71 | | - ed = ciphers.Ed25519Private(key = wolfboot_key_buffer) |
72 | | - else: |
73 | | - print("Generating new ED25519 Key") |
74 | | - ed = ciphers.Ed25519Private.make_key(32) |
| 68 | + ed = ciphers.Ed25519Private.make_key(32) |
75 | 69 | priv,pub = ed.encode_key() |
76 | | - if not os.path.exists(key_file): |
77 | | - print("Creating file " + key_file) |
78 | | - with open(key_file, "wb") as f: |
79 | | - f.write(priv) |
80 | | - f.write(pub) |
81 | | - f.close() |
| 70 | + if os.path.exists(key_file): |
| 71 | + choice = input("** Warning: key file already exist! Are you sure you want to "+ |
| 72 | + "generate a new key and overwrite the existing key? [Type 'Yes, I am sure!']: ") |
| 73 | + if (choice != "Yes, I am sure!"): |
| 74 | + print("Operation canceled.") |
| 75 | + sys.exit(2) |
| 76 | + |
| 77 | + print() |
| 78 | + print("Creating file " + key_file) |
| 79 | + with open(key_file, "wb") as f: |
| 80 | + f.write(priv) |
| 81 | + f.write(pub) |
| 82 | + f.close() |
82 | 83 | print("Creating file " + pubkey_cfile) |
83 | 84 | with open(pubkey_cfile, "w") as f: |
84 | 85 | f.write(Cfile_Banner) |
|
95 | 96 | f.close() |
96 | 97 |
|
97 | 98 | if (sign == "ecc256"): |
98 | | - if os.path.exists(key_file): |
99 | | - print("Loading exiting ECC 256-bit Key") |
100 | | - kf = open(key_file, "rb") |
101 | | - wolfboot_key_buffer = kf.read(96) |
102 | | - ec = ciphers.EccPrivate() |
103 | | - ec.decode_key_raw(wolfboot_key_buffer[0:31], wolfboot_key_buffer[32:63], wolfboot_key_buffer[64:]) |
104 | | - else: |
105 | | - print("Generating new ECC 256-bit Key") |
106 | | - ec = ciphers.EccPrivate.make_key(32) |
| 99 | + ec = ciphers.EccPrivate.make_key(32) |
107 | 100 | qx,qy,d = ec.encode_key_raw() |
108 | | - if not os.path.exists(key_file): |
109 | | - print("Creating file " + key_file) |
110 | | - with open(key_file, "wb") as f: |
111 | | - f.write(qx) |
112 | | - f.write(qy) |
113 | | - f.write(d) |
114 | | - f.close() |
| 101 | + if os.path.exists(key_file): |
| 102 | + choice = input("** Warning: key file already exist! Are you sure you want to "+ |
| 103 | + "generate a new key and overwrite the existing key? [Type 'Yes, I am sure!']: ") |
| 104 | + if (choice != "Yes, I am sure!"): |
| 105 | + print("Operation canceled.") |
| 106 | + sys.exit(2) |
| 107 | + |
| 108 | + print() |
| 109 | + print("Creating file " + key_file) |
| 110 | + with open(key_file, "wb") as f: |
| 111 | + f.write(qx) |
| 112 | + f.write(qy) |
| 113 | + f.write(d) |
| 114 | + f.close() |
115 | 115 | print("Creating file " + pubkey_cfile) |
116 | 116 | with open(pubkey_cfile, "w") as f: |
117 | 117 | f.write(Cfile_Banner) |
|
133 | 133 | f.close() |
134 | 134 |
|
135 | 135 | if (sign == "rsa2048"): |
| 136 | + rsa = ciphers.RsaPrivate.make_key(2048) |
136 | 137 | if os.path.exists(key_file): |
137 | | - print("Loading exiting RSA 2048-bit Key") |
138 | | - kf = open(key_file, "rb") |
139 | | - wolfboot_key_buffer = kf.read(2048) |
140 | | - rsa = ciphers.RsaPrivate(wolfboot_key_buffer) |
141 | | - else: |
142 | | - print("Generating new RSA 2048-bit Key") |
143 | | - rsa = ciphers.RsaPrivate.make_key(2048) |
144 | | - if not os.path.exists(key_file): |
145 | | - print("Creating file " + key_file) |
146 | | - with open(key_file, "wb") as f: |
147 | | - f.write(priv) |
148 | | - f.close() |
| 138 | + choice = input("** Warning: key file already exist! Are you sure you want to "+ |
| 139 | + "generate a new key and overwrite the existing key? [Type 'Yes, I am sure!']: ") |
| 140 | + if (choice != "Yes, I am sure!"): |
| 141 | + print("Operation canceled.") |
| 142 | + sys.exit(2) |
| 143 | + priv,pub = rsa.encode_key() |
| 144 | + print() |
| 145 | + print("Creating file " + key_file) |
| 146 | + with open(key_file, "wb") as f: |
| 147 | + f.write(priv) |
| 148 | + f.close() |
149 | 149 | print("Creating file " + pubkey_cfile) |
150 | 150 | with open(pubkey_cfile, "w") as f: |
151 | 151 | f.write(Cfile_Banner) |
|
161 | 161 | f.close() |
162 | 162 |
|
163 | 163 | if (sign == "rsa4096"): |
| 164 | + rsa = ciphers.RsaPrivate.make_key(4096) |
164 | 165 | if os.path.exists(key_file): |
165 | | - print("Loading exiting RSA 4096-bit Key") |
166 | | - kf = open(key_file, "rb") |
167 | | - wolfboot_key_buffer = kf.read(4096) |
168 | | - rsa = ciphers.RsaPrivate(wolfboot_key_buffer) |
169 | | - else: |
170 | | - print("Generating new RSA 4096-bit Key") |
171 | | - rsa = ciphers.RsaPrivate.make_key(4096) |
| 166 | + choice = input("** Warning: key file already exist! Are you sure you want to "+ |
| 167 | + "generate a new key and overwrite the existing key? [Type 'Yes, I am sure!']: ") |
| 168 | + if (choice != "Yes, I am sure!"): |
| 169 | + print("Operation canceled.") |
| 170 | + sys.exit(2) |
172 | 171 | priv,pub = rsa.encode_key() |
173 | | - if not os.path.exists(key_file): |
174 | | - print("Creating file " + key_file) |
175 | | - with open(key_file, "wb") as f: |
176 | | - f.write(priv) |
177 | | - f.close() |
| 172 | + print() |
| 173 | + print("Creating file " + key_file) |
| 174 | + with open(key_file, "wb") as f: |
| 175 | + f.write(priv) |
| 176 | + f.close() |
178 | 177 | print("Creating file " + pubkey_cfile) |
179 | 178 | with open(pubkey_cfile, "w") as f: |
180 | 179 | f.write(Cfile_Banner) |
|
0 commit comments