|
|
|
@ -17,7 +17,7 @@
|
|
|
|
|
|
|
|
|
|
import cert_cmd
|
|
|
|
|
import post_request
|
|
|
|
|
import datetime, subprocess
|
|
|
|
|
import datetime, subprocess, shutil
|
|
|
|
|
|
|
|
|
|
from calculate.core.client.cert_func import new_key_req
|
|
|
|
|
from calculate.core.client.function import get_ip_mac_type
|
|
|
|
@ -78,12 +78,7 @@ def check(cert, key, cert_path, data_path, certbase, args):
|
|
|
|
|
def init(cert, key, cert_path, data_path, certbase, args, port, user_name):
|
|
|
|
|
if args.force:
|
|
|
|
|
key_force(cert_path, data_path)
|
|
|
|
|
return
|
|
|
|
|
try:
|
|
|
|
|
pwdObj = pwd.getpwnam(user_name)
|
|
|
|
|
except KeyError, e:
|
|
|
|
|
print e
|
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
new_serv_cert = False
|
|
|
|
|
if not check_serv_cert(cert_path):
|
|
|
|
|
print 'Generate Server Certificate'
|
|
|
|
@ -97,6 +92,12 @@ def init(cert, key, cert_path, data_path, certbase, args, port, user_name):
|
|
|
|
|
if new_serv_cert or not check_client_cert(user_name):
|
|
|
|
|
print 'Generate Client Certificate'
|
|
|
|
|
create_client_cert(cert, cert_path, data_path, certbase, user_name)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
pwdObj = pwd.getpwnam(user_name)
|
|
|
|
|
except KeyError, e:
|
|
|
|
|
print e
|
|
|
|
|
return 1
|
|
|
|
|
change_owner(pwdObj, user_name)
|
|
|
|
|
else:
|
|
|
|
|
print 'Client certificate already exists'
|
|
|
|
@ -304,4 +305,18 @@ def change_owner(pwdObj, user_name):
|
|
|
|
|
os.chown('/'.join([path[0], file]), pwdObj.pw_uid, pwdObj.pw_gid)
|
|
|
|
|
|
|
|
|
|
def key_force(cert_path, data_path):
|
|
|
|
|
pass
|
|
|
|
|
import ipdb
|
|
|
|
|
ipdb.set_trace()
|
|
|
|
|
if os.path.isdir(cert_path):
|
|
|
|
|
shutil.rmtree(cert_path)
|
|
|
|
|
remove_dirs = ['conf', 'server_certs','client_certs','pids','sids']
|
|
|
|
|
for rm_dir in remove_dirs:
|
|
|
|
|
remove_dir = os.path.join(data_path, rm_dir)
|
|
|
|
|
if os.path.isdir(remove_dir):
|
|
|
|
|
shutil.rmtree(remove_dir)
|
|
|
|
|
|
|
|
|
|
remove_files = ['sid.db', 'sid_pid']
|
|
|
|
|
for rm_file in remove_files:
|
|
|
|
|
remove_file = os.path.join(data_path, rm_file)
|
|
|
|
|
if os.path.isfile(remove_file):
|
|
|
|
|
os.unlink(remove_file)
|
|
|
|
|