Generate private key from Python client
This commit is contained in:
		@@ -11,3 +11,4 @@ args = parser.parse_args()
 | 
			
		||||
 | 
			
		||||
args.secure_origin_path = os.path.join(args.storage, "SECURE_ORIGIN")
 | 
			
		||||
args.root_ca_path = os.path.join(args.storage, "root_ca.pem")
 | 
			
		||||
args.dev_priv_key = os.path.join(args.storage, "dev.key")
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
from src.args import args
 | 
			
		||||
import src.api as api
 | 
			
		||||
import src.pki as pki
 | 
			
		||||
import os
 | 
			
		||||
 | 
			
		||||
print("Check storage")
 | 
			
		||||
@@ -26,6 +27,9 @@ if not os.path.isfile(args.root_ca_path):
 | 
			
		||||
    with open(args.root_ca_path, "w") as f:
 | 
			
		||||
        f.write(origin)
 | 
			
		||||
 | 
			
		||||
with open(args.root_ca_path, "r") as f:
 | 
			
		||||
    args.root_ca = f.read()
 | 
			
		||||
print(f"Root CA = {args.root_ca}")
 | 
			
		||||
print("Check private key")
 | 
			
		||||
if not os.path.isfile(args.dev_priv_key):
 | 
			
		||||
    print("Generate private key...")
 | 
			
		||||
    key = pki.gen_priv_key()
 | 
			
		||||
    with open(args.dev_priv_key, "w") as f:
 | 
			
		||||
        f.write(key)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										6
									
								
								python_device/src/pki.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								python_device/src/pki.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
from OpenSSL import crypto
 | 
			
		||||
 | 
			
		||||
def gen_priv_key():
 | 
			
		||||
    key = crypto.PKey()
 | 
			
		||||
    key.generate_key(crypto.TYPE_RSA, 2048)
 | 
			
		||||
    return crypto.dump_privatekey(crypto.FILETYPE_PEM, key).decode("utf-8")
 | 
			
		||||
		Reference in New Issue
	
	Block a user