|
@@ -1,3 +1,5 @@
|
|
|
|
+#!/usr/bin/env python3
|
|
|
|
+
|
|
import sys, getopt, os
|
|
import sys, getopt, os
|
|
|
|
|
|
def usage():
|
|
def usage():
|
|
@@ -12,52 +14,85 @@ def usage():
|
|
print('\t-h --help\tShows this help')
|
|
print('\t-h --help\tShows this help')
|
|
|
|
|
|
def generate_client_auth_cert():
|
|
def generate_client_auth_cert():
|
|
|
|
+ print("\n\nGénération d'un certificat client pour authentification")
|
|
|
|
+ print("=========================================================\n")
|
|
tld = input("=> TLD of your certificate :")
|
|
tld = input("=> TLD of your certificate :")
|
|
client_name = input("=> Client Name :")
|
|
client_name = input("=> Client Name :")
|
|
|
|
|
|
- # Changement du fichier de config
|
|
|
|
- os.system('sed -i "s/DNSCHANGEME/'+ tld +'/" ./config/ca.config')
|
|
|
|
- os.system('sed -i "s/Root Certificate/'+ tld +'/" ./config/ca.config')
|
|
|
|
-
|
|
|
|
|
|
+ with open('./config/ca.config', 'r') as file:
|
|
|
|
+ newText = file.read().replace('DNSCHANGEME', tld)
|
|
|
|
+ newText = newText.replace('Root Certificate', tld)
|
|
|
|
+ with open('./config/ca.config', 'w') as file:
|
|
|
|
+ file.write(newText)
|
|
|
|
|
|
print("=> Création du certificat client")
|
|
print("=> Création du certificat client")
|
|
os.system("openssl genrsa -out ./certificats/" +client_name+ "_" +tld+ ".key 4096")
|
|
os.system("openssl genrsa -out ./certificats/" +client_name+ "_" +tld+ ".key 4096")
|
|
print("[*] " +client_name+"_"+tld+".key is done")
|
|
print("[*] " +client_name+"_"+tld+".key is done")
|
|
os.system('openssl req -new -config config/ca.config -key ./certificats/'+client_name+ '_' +tld+ '.key -out ./certificats/'+ client_name +'-remote.csr')
|
|
os.system('openssl req -new -config config/ca.config -key ./certificats/'+client_name+ '_' +tld+ '.key -out ./certificats/'+ client_name +'-remote.csr')
|
|
print("[*] CSR Request completed !")
|
|
print("[*] CSR Request completed !")
|
|
- os.system('openssl x509 -req -days 3650 -in ./certificats/'+client_name+'-remote.csr -CA ./certificats/ca.crt -CAkey ./certificats/ca.key -set_serial 001 -out ./certificats/'+client_name+'-remote.pem')
|
|
|
|
|
|
+ os.system('openssl req -x509 -days 3650 -in ./certificats/'+client_name+'-remote.csr -CA ./certificats/ca.crt -CAkey ./certificats/ca.key -set_serial 001 -out ./certificats/'+client_name+'-remote.pem')
|
|
print("[*] Sign OK")
|
|
print("[*] Sign OK")
|
|
os.system("openssl pkcs12 -export -out ./"+client_name+".full.pfx -inkey ./certificats/"+client_name+'_'+tld+".key -in ./certificats/"+client_name+"-remote.pem -certfile ./certificats/ca.crt")
|
|
os.system("openssl pkcs12 -export -out ./"+client_name+".full.pfx -inkey ./certificats/"+client_name+'_'+tld+".key -in ./certificats/"+client_name+"-remote.pem -certfile ./certificats/ca.crt")
|
|
print("[*] Certificate OK")
|
|
print("[*] Certificate OK")
|
|
|
|
|
|
|
|
+ # restauration du fichier de config
|
|
|
|
+ with open('./config/ca.config', 'r') as file:
|
|
|
|
+ newText = file.read().replace(tld, 'DNSCHANGEME')
|
|
|
|
+ newText = newText.replace(tld, 'Root Certificate')
|
|
|
|
+ with open('./config/ca.config', 'w') as file:
|
|
|
|
+ file.write(newText)
|
|
|
|
+
|
|
|
|
|
|
def generate_sign():
|
|
def generate_sign():
|
|
|
|
+ print("\n\nGénération d'un certificat pour un hôte")
|
|
|
|
+ print("=====================================\n")
|
|
tld = input("=> TLD of your certificate :")
|
|
tld = input("=> TLD of your certificate :")
|
|
ip_addr = input("=> IPv4 :")
|
|
ip_addr = input("=> IPv4 :")
|
|
|
|
|
|
# Changement du fichier de config
|
|
# Changement du fichier de config
|
|
- os.system('sed -i "s/DNSCHANGEME/'+ tld +'/" ./config/ca.config')
|
|
|
|
- os.system('sed -i "s/0.0.0.0/'+ ip_addr +'/" ./config/ca.config')
|
|
|
|
- os.system('sed -i "s/Root Certificate/'+ tld +'/" ./config/ca.config')
|
|
|
|
|
|
+ with open('./config/ca.config', 'r') as file:
|
|
|
|
+ newText = file.read().replace('DNSCHANGEME', tld)
|
|
|
|
+ newText = newText.replace('0.0.0.0', ip_addr)
|
|
|
|
+ newText = newText.replace('Root Certificate', tld)
|
|
|
|
+ with open('./config/ca.config', 'w') as file:
|
|
|
|
+ file.write(newText)
|
|
|
|
|
|
# Création des certificats
|
|
# Création des certificats
|
|
|
|
+ print("=> Création du certificat pour " + tld)
|
|
os.system("openssl genrsa -out ./certificats/"+tld+".key 4096")
|
|
os.system("openssl genrsa -out ./certificats/"+tld+".key 4096")
|
|
- os.system("openssl req -days 3650 -new -config config/ca.config -key ./certificats/"+tld+".key -out certificats/"+tld+".csr")
|
|
|
|
|
|
+ print("[*] "+tld+".key is donei")
|
|
|
|
+
|
|
|
|
+ print("=> Création de la CSR")
|
|
|
|
+ os.system("openssl req -new -config config/ca.config -key ./certificats/"+tld+".key -out certificats/"+tld+".csr")
|
|
|
|
+ print("[*] CSR Request completed !")
|
|
|
|
+
|
|
|
|
+ print("=> Signature du certificat")
|
|
os.system("openssl ca -out "+tld+".crt -config config/ca.config -infiles certificats/"+tld+".csr ")
|
|
os.system("openssl ca -out "+tld+".crt -config config/ca.config -infiles certificats/"+tld+".csr ")
|
|
|
|
+ print("[*] Sign OK")
|
|
|
|
|
|
# On restaure ca.config d'origine
|
|
# On restaure ca.config d'origine
|
|
- os.system('sed -i "s/'+ tld +'/DNSCHANGEME/" ./config/ca.config')
|
|
|
|
- os.system('sed -i "s/'+ ip_addr +'/0.0.0.0/" ./config/ca.config')
|
|
|
|
- os.system('sed -i "s/'+ tld +'/Root Certificate/" ./config/ca.config')
|
|
|
|
|
|
+ with open('./config/ca.config', 'r') as file:
|
|
|
|
+ newText = file.read().replace(tld, 'DNSCHANGEME')
|
|
|
|
+ newText = newText.replace(ip_addr, '0.0.0.0')
|
|
|
|
+ newText = newText.replace(tld, 'Root Certificate')
|
|
|
|
+ with open('./config/ca.config', 'w') as file:
|
|
|
|
+ file.write(newText)
|
|
|
|
|
|
print("[*] Certificate Signed !")
|
|
print("[*] Certificate Signed !")
|
|
|
|
|
|
|
|
|
|
def generate_der():
|
|
def generate_der():
|
|
- os.system("openssl x509 -in certificats/ca.crt -outform DER -out certificats/ca.der")
|
|
|
|
- print("[*] Put public CA ./certificats/ca.der on all browser you see !")
|
|
|
|
|
|
+ print("\n\nGénération d'un certificat DER pour les navigateurs")
|
|
|
|
+ print("=================================================\n")
|
|
|
|
+ if not os.path.isfile("./certificats/ca.der"):
|
|
|
|
+ os.system("openssl x509 -in certificats/ca.crt -outform DER -out certificats/ca.der")
|
|
|
|
+ print("[*] Put public CA ./certificats/ca.der on all browser you see !")
|
|
|
|
+ else:
|
|
|
|
+ print("[x] DER Certificate already exist...")
|
|
|
|
|
|
def generate_ca():
|
|
def generate_ca():
|
|
|
|
+ print("\n\nGénération d'une autorité de certification")
|
|
|
|
+ print("========================================\n")
|
|
if not os.path.isfile("./certificats/ca.key"):
|
|
if not os.path.isfile("./certificats/ca.key"):
|
|
os.system("openssl genrsa -out ./certificats/ca.key 4096")
|
|
os.system("openssl genrsa -out ./certificats/ca.key 4096")
|
|
os.system("openssl req -utf8 -new -x509 -days 3000 -config ./config/ca.config -key ./certificats/ca.key -out ./certificats/ca.crt")
|
|
os.system("openssl req -utf8 -new -x509 -days 3000 -config ./config/ca.config -key ./certificats/ca.key -out ./certificats/ca.crt")
|
|
@@ -67,6 +102,8 @@ def generate_ca():
|
|
|
|
|
|
|
|
|
|
def init_dir():
|
|
def init_dir():
|
|
|
|
+ print("\n\nInitialisation des répertoires")
|
|
|
|
+ print("================================\n")
|
|
if not os.path.exists("./db/ca.db.certs"):
|
|
if not os.path.exists("./db/ca.db.certs"):
|
|
print("[*] Creating directories")
|
|
print("[*] Creating directories")
|
|
os.makedirs("./db/ca.db.certs")
|
|
os.makedirs("./db/ca.db.certs")
|
|
@@ -104,6 +141,9 @@ def main():
|
|
generate_der()
|
|
generate_der()
|
|
generate_sign()
|
|
generate_sign()
|
|
sys.exit()
|
|
sys.exit()
|
|
|
|
+ if not opts:
|
|
|
|
+ usage()
|
|
|
|
+ sys.exit()
|
|
|
|
|
|
except getopt.GetoptError as err:
|
|
except getopt.GetoptError as err:
|
|
sys.stderr.write(str(err))
|
|
sys.stderr.write(str(err))
|
|
@@ -111,4 +151,4 @@ def main():
|
|
sys.exit(2)
|
|
sys.exit(2)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|
|
- main()
|
|
|
|
|
|
+ main()
|