Browse Source

cmd_tls: implemented file_type non zero

- if file type is not 0, then database field has the content of the
file, instead of path to file (for certificaet, private key, ca list and
crl)
- content will be written in files inside the folder specified by -d,
of, if this is missing, in the same folder with tls cfg file
Daniel-Constantin Mierla 7 years ago
parent
commit
e8cc1af32c
1 changed files with 41 additions and 11 deletions
  1. 41 11
      kamcli/commands/cmd_tls.py

+ 41 - 11
kamcli/commands/cmd_tls.py

@@ -84,17 +84,46 @@ def tls_cfgprint(ctx, odir, cfgpath):
             print("verify_depth={0:d}".format(row["verify_depth"]))
             print("require_certificate={0:d}".format(row["require_certificate"]))
 
-            if row["certificate"] and row["certificate"].strip():
-                print("certificate={0:s}".format(row["certificate"]))
-
-            if row["private_key"] and row["private_key"].strip():
-                print("private_key={0:s}".format(row["private_key"]))
-
-            if row["ca_list"] and row["ca_list"].strip():
-                print("ca_list={0:s}".format(row["ca_list"]))
-
-            if row["crl"] and row["crl"].strip():
-                print("crl={0:s}".format(row["crl"]))
+            if row["file_type"] == 0:
+                if row["certificate"] and row["certificate"].strip():
+                    print("certificate={0:s}".format(row["certificate"]))
+
+                if row["private_key"] and row["private_key"].strip():
+                    print("private_key={0:s}".format(row["private_key"]))
+
+                if row["ca_list"] and row["ca_list"].strip():
+                    print("ca_list={0:s}".format(row["ca_list"]))
+
+                if row["crl"] and row["crl"].strip():
+                    print("crl={0:s}".format(row["crl"]))
+            else:
+                if row["certificate"] and row["certificate"].strip():
+                    fpath = os.path.join(odir, "certificate_"+str(row["id"])+".pem")
+                    fout = open(fpath, 'w')
+                    fout.write(row["certificate"])
+                    fout.close()
+                    print("certificate={0:s}".format(fpath))
+
+                if row["private_key"] and row["private_key"].strip():
+                    fpath = os.path.join(odir, "private_key_"+str(row["id"])+".pem")
+                    fout = open(fpath, 'w')
+                    fout.write(row["private_key"])
+                    fout.close()
+                    print("private_key={0:s}".format(fpath))
+
+                if row["ca_list"] and row["ca_list"].strip():
+                    fpath = os.path.join(odir, "ca_list_"+str(row["id"])+".pem")
+                    fout = open(fpath, 'w')
+                    fout.write(row["ca_list"])
+                    fout.close()
+                    print("ca_list={0:s}".format(fpath))
+
+                if row["crl"] and row["crl"].strip():
+                    fpath = os.path.join(odir, "crl_"+str(row["id"])+".pem")
+                    fout = open(fpath, 'w')
+                    fout.write(row["crl"])
+                    fout.close()
+                    print("crl={0:s}".format(fpath))
 
             if row["cipher_list"] and row["cipher_list"].strip():
                 print("cipher_list={0:s}".format(row["cipher_list"]))
@@ -111,6 +140,7 @@ def tls_cfgprint(ctx, odir, cfgpath):
     if cfgpath:
         sys.stdout = bstdout
         cfgsock.close()
+        print("done")