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.secure_origin_path = os.path.join(args.storage, "SECURE_ORIGIN")
 | 
				
			||||||
args.root_ca_path = os.path.join(args.storage, "root_ca.pem")
 | 
					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
 | 
					from src.args import args
 | 
				
			||||||
import src.api as api
 | 
					import src.api as api
 | 
				
			||||||
 | 
					import src.pki as pki
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
 | 
					
 | 
				
			||||||
print("Check storage")
 | 
					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:
 | 
					    with open(args.root_ca_path, "w") as f:
 | 
				
			||||||
        f.write(origin)
 | 
					        f.write(origin)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
with open(args.root_ca_path, "r") as f:
 | 
					print("Check private key")
 | 
				
			||||||
    args.root_ca = f.read()
 | 
					if not os.path.isfile(args.dev_priv_key):
 | 
				
			||||||
print(f"Root CA = {args.root_ca}")
 | 
					    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