|
|
|
@ -35,7 +35,7 @@ from calculate.core.datavars import DataVarsCore
|
|
|
|
|
|
|
|
|
|
from client_class import HTTPSClientCertTransport
|
|
|
|
|
from methods_func import call_method, get_method_argparser, parse
|
|
|
|
|
from calculate.lib.utils.files import makeDirectory
|
|
|
|
|
from calculate.lib.utils.files import makeDirectory, readLinesFile
|
|
|
|
|
from calculate.lib.cl_lang import setLocalTranslate
|
|
|
|
|
setLocalTranslate('calculate_console',sys.modules[__name__])
|
|
|
|
|
|
|
|
|
@ -196,6 +196,85 @@ class StoppableThread(threading.Thread):
|
|
|
|
|
def stopped(self):
|
|
|
|
|
return self._stop.isSet()
|
|
|
|
|
|
|
|
|
|
def connect_with_cert(cert, path_to_cert, url, args, wait_thread, clVarsCore,
|
|
|
|
|
crypto_Error, Connect_Error):
|
|
|
|
|
cert_name = cert
|
|
|
|
|
CERT_FILE = os.path.join(path_to_cert, cert_name + '.crt')
|
|
|
|
|
CERT_KEY = os.path.join(path_to_cert, cert_name + '.key')
|
|
|
|
|
client = None
|
|
|
|
|
|
|
|
|
|
bio = M2Crypto.BIO.openfile(CERT_KEY)
|
|
|
|
|
rsa = M2Crypto.m2.rsa_read_key(bio._ptr(),lambda *unused: None)
|
|
|
|
|
if not rsa:
|
|
|
|
|
store_passwd = get_password_from_daemon(args.host, args.port,
|
|
|
|
|
wait_thread)
|
|
|
|
|
if not wait_thread.isAlive():
|
|
|
|
|
wait_thread = StoppableThread()
|
|
|
|
|
wait_thread.start()
|
|
|
|
|
if 'store_passwd' in locals():
|
|
|
|
|
key_passwd = store_passwd
|
|
|
|
|
else:
|
|
|
|
|
key_passwd = None
|
|
|
|
|
try:
|
|
|
|
|
client = Client_suds(url, transport=HTTPSClientCertTransport \
|
|
|
|
|
(CERT_KEY, CERT_FILE, path_to_cert, password=key_passwd,
|
|
|
|
|
wait_thread = wait_thread))
|
|
|
|
|
if not wait_thread.isAlive():
|
|
|
|
|
wait_thread = StoppableThread()
|
|
|
|
|
wait_thread.start()
|
|
|
|
|
client.wsdl.services[0].setlocation(url)
|
|
|
|
|
client.set_parameters (path_to_cert, CERT_FILE, CERT_KEY)
|
|
|
|
|
client_post_cert(client, clVarsCore)
|
|
|
|
|
Connect_Error = 0
|
|
|
|
|
except VerifyError, e:
|
|
|
|
|
Connect_Error = 1
|
|
|
|
|
except OpenSSL.crypto.Error, e:
|
|
|
|
|
Connect_Error = 1
|
|
|
|
|
crypto_Error = 1
|
|
|
|
|
except urllib2.URLError, e:
|
|
|
|
|
Connect_Error = 1
|
|
|
|
|
except Exception, e:
|
|
|
|
|
Connect_Error = 1
|
|
|
|
|
return (client, Connect_Error, crypto_Error,
|
|
|
|
|
True if 'store_passwd' in locals() else False,
|
|
|
|
|
e if 'e' in locals() else None)
|
|
|
|
|
|
|
|
|
|
def get_server_hostname(host, path_to_cert):
|
|
|
|
|
compliance_file = os.path.join(path_to_cert, 'compliance_server_names')
|
|
|
|
|
if not os.path.isfile(compliance_file):
|
|
|
|
|
fd = open(compliance_file, 'w')
|
|
|
|
|
fd.close()
|
|
|
|
|
for line in readLinesFile(compliance_file):
|
|
|
|
|
adress, server_hostname = line.split(' ',1)
|
|
|
|
|
if adress == host:
|
|
|
|
|
return server_hostname
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
def add_server_hostname(host, path_to_cert, server_hostname):
|
|
|
|
|
try:
|
|
|
|
|
compliance_file = os.path.join(path_to_cert, 'compliance_server_names')
|
|
|
|
|
if not os.path.isfile(compliance_file):
|
|
|
|
|
fd = open(compliance_file, 'w')
|
|
|
|
|
fd.close()
|
|
|
|
|
temp_file = ''
|
|
|
|
|
find_flag = False
|
|
|
|
|
for line in readLinesFile(compliance_file):
|
|
|
|
|
adress, server_hostname = line.split(' ',1)
|
|
|
|
|
if adress == host:
|
|
|
|
|
temp_file += "%s %s\n" %(adress, server_hostname)
|
|
|
|
|
find_flag = True
|
|
|
|
|
else:
|
|
|
|
|
temp_file += line+'\n'
|
|
|
|
|
if not find_flag:
|
|
|
|
|
temp_file += "%s %s\n" %(host, server_hostname)
|
|
|
|
|
fd = open(compliance_file, 'w')
|
|
|
|
|
fd.write(temp_file)
|
|
|
|
|
fd.close()
|
|
|
|
|
return True
|
|
|
|
|
except Exception, e:
|
|
|
|
|
print e
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
# now = datetime.datetime.now()
|
|
|
|
|
# print '1 ===> %ds %dms' %(now.second, now.microsecond)
|
|
|
|
@ -235,10 +314,6 @@ def main():
|
|
|
|
|
|
|
|
|
|
homePath = clVarsCore.Get('ur_home_path')
|
|
|
|
|
|
|
|
|
|
# translate
|
|
|
|
|
# if args.lang:
|
|
|
|
|
# print 'code not found!!!!'
|
|
|
|
|
|
|
|
|
|
port = args.port
|
|
|
|
|
host = args.host
|
|
|
|
|
path_to_cert = args.path_to_cert
|
|
|
|
@ -274,28 +349,74 @@ def main():
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
url = "https://%s:%d/?wsdl" %(host, port)
|
|
|
|
|
# print "url = %s" %url
|
|
|
|
|
|
|
|
|
|
clear()
|
|
|
|
|
|
|
|
|
|
serv_hostname = get_server_hostname(host, path_to_cert)
|
|
|
|
|
get_name_flag = False
|
|
|
|
|
if serv_hostname:
|
|
|
|
|
Connect_Error = 1
|
|
|
|
|
crypto_Error = 0
|
|
|
|
|
client, Connect_Error, crypto_Error, passwd_flag, e = \
|
|
|
|
|
connect_with_cert (serv_hostname, path_to_cert, url, args,
|
|
|
|
|
wait_thread, clVarsCore, crypto_Error, Connect_Error)
|
|
|
|
|
get_name_flag = True
|
|
|
|
|
if Connect_Error:
|
|
|
|
|
if crypto_Error and passwd_flag:
|
|
|
|
|
wait_thread.stop()
|
|
|
|
|
print _('Password is invalid')
|
|
|
|
|
# delete password from daemon list
|
|
|
|
|
clear_password(host, port)
|
|
|
|
|
get_name_flag = False
|
|
|
|
|
# return 1
|
|
|
|
|
if e:
|
|
|
|
|
wait_thread.stop()
|
|
|
|
|
print _('Error: '), e
|
|
|
|
|
get_name_flag = False
|
|
|
|
|
# return 1
|
|
|
|
|
|
|
|
|
|
if get_name_flag:
|
|
|
|
|
try:
|
|
|
|
|
client.port = port
|
|
|
|
|
return_val = 1
|
|
|
|
|
try:
|
|
|
|
|
return_val = https_server(client, args, unknown_args, url, \
|
|
|
|
|
clVarsCore, wait_thread)
|
|
|
|
|
except urllib2.URLError, e:
|
|
|
|
|
print _('Error: '), e
|
|
|
|
|
except Exception, e:
|
|
|
|
|
wait_thread.stop()
|
|
|
|
|
if type(e.message) != int:
|
|
|
|
|
if e.message:
|
|
|
|
|
print e.message
|
|
|
|
|
else:
|
|
|
|
|
print e
|
|
|
|
|
return 1
|
|
|
|
|
wait_thread.stop()
|
|
|
|
|
return return_val
|
|
|
|
|
except WebFault, f:
|
|
|
|
|
print _("Exception: %s") %f
|
|
|
|
|
_print (f.fault)
|
|
|
|
|
except TransportError, te:
|
|
|
|
|
print _("Exception: %s") %te
|
|
|
|
|
except Exception, e:
|
|
|
|
|
print _("Exception: %s") %e
|
|
|
|
|
tb.print_exc()
|
|
|
|
|
wait_thread.stop()
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
# now = datetime.datetime.now()
|
|
|
|
|
# print '2 ===> %ds %dms' %(now.second, now.microsecond)
|
|
|
|
|
client = Client_suds(url, \
|
|
|
|
|
transport = HTTPSClientCertTransport(None,None, path_to_cert))
|
|
|
|
|
transport = HTTPSClientCertTransport(None,None, path_to_cert))
|
|
|
|
|
client.wsdl.services[0].setlocation(url)
|
|
|
|
|
# now = datetime.datetime.now()
|
|
|
|
|
# print '2/1 ===> %ds %dms' %(now.second, now.microsecond)
|
|
|
|
|
server_host_name = client.service.get_server_host_name()
|
|
|
|
|
# print server_host_name
|
|
|
|
|
# now = datetime.datetime.now()
|
|
|
|
|
# print '2/2 ===> %ds %dms' %(now.second, now.microsecond)
|
|
|
|
|
if not add_server_hostname(host, path_to_cert, server_host_name):
|
|
|
|
|
print 'compliance_file write error!'
|
|
|
|
|
del (client)
|
|
|
|
|
except urllib2.URLError, e:
|
|
|
|
|
wait_thread.stop()
|
|
|
|
|
print '\b' + _('Failed to connect')+':', e
|
|
|
|
|
return 1
|
|
|
|
|
# server_host_name = 'dspiridonov.local.calculate.ru'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
import glob
|
|
|
|
|
all_cert_list = glob.glob(os.path.join(path_to_cert, '*.crt'))
|
|
|
|
@ -311,72 +432,27 @@ def main():
|
|
|
|
|
# now = datetime.datetime.now()
|
|
|
|
|
# print '3 ===> %ds %dms' %(now.second, now.microsecond)
|
|
|
|
|
for i in range (0, len(fit_cert_list)):
|
|
|
|
|
#print 'fit_cert_list = ',fit_cert_list
|
|
|
|
|
cert_name = fit_cert_list.pop()
|
|
|
|
|
CERT_FILE = path_to_cert + cert_name + '.crt'
|
|
|
|
|
CERT_KEY = path_to_cert + cert_name + '.key'
|
|
|
|
|
|
|
|
|
|
bio = M2Crypto.BIO.openfile(CERT_KEY)
|
|
|
|
|
rsa = M2Crypto.m2.rsa_read_key(bio._ptr(),lambda *unused: None)
|
|
|
|
|
if not rsa:
|
|
|
|
|
store_passwd = get_password_from_daemon(host,port,wait_thread)
|
|
|
|
|
if not wait_thread.isAlive():
|
|
|
|
|
wait_thread = StoppableThread()
|
|
|
|
|
wait_thread.start()
|
|
|
|
|
# if not rsa and not 'store_passwd' in locals():
|
|
|
|
|
# store_passwd = getpass.getpass(_('Password: '))
|
|
|
|
|
# if not store_passwd:
|
|
|
|
|
# store_passwd = None
|
|
|
|
|
if 'store_passwd' in locals():
|
|
|
|
|
key_passwd = store_passwd
|
|
|
|
|
else:
|
|
|
|
|
key_passwd = None
|
|
|
|
|
try:
|
|
|
|
|
# now = datetime.datetime.now()
|
|
|
|
|
# print '3/1 ===> %ds %dms' %(now.second, now.microsecond)
|
|
|
|
|
client = Client_suds(url, transport=HTTPSClientCertTransport \
|
|
|
|
|
(CERT_KEY, CERT_FILE, path_to_cert, password=key_passwd,
|
|
|
|
|
wait_thread = wait_thread))
|
|
|
|
|
if not wait_thread.isAlive():
|
|
|
|
|
wait_thread = StoppableThread()
|
|
|
|
|
wait_thread.start()
|
|
|
|
|
# now = datetime.datetime.now()
|
|
|
|
|
# print '3/2 ===> %ds %dms' %(now.second, now.microsecond)
|
|
|
|
|
client.wsdl.services[0].setlocation(url)
|
|
|
|
|
client.set_parameters (path_to_cert, CERT_FILE, CERT_KEY)
|
|
|
|
|
# now = datetime.datetime.now()
|
|
|
|
|
# print '3/3 ===> %ds %dms' %(now.second, now.microsecond)
|
|
|
|
|
client_post_cert(client, clVarsCore)
|
|
|
|
|
# now = datetime.datetime.now()
|
|
|
|
|
# print '3/4 ===> %ds %dms' %(now.second, now.microsecond)
|
|
|
|
|
Connect_Error = 0
|
|
|
|
|
except VerifyError, e:
|
|
|
|
|
# print e.value
|
|
|
|
|
Connect_Error = 1
|
|
|
|
|
except OpenSSL.crypto.Error, e:
|
|
|
|
|
Connect_Error = 1
|
|
|
|
|
crypto_Error = 1
|
|
|
|
|
except urllib2.URLError, e:
|
|
|
|
|
Connect_Error = 1
|
|
|
|
|
except Exception, e:
|
|
|
|
|
Connect_Error = 1
|
|
|
|
|
client, Connect_Error, crypto_Error, passwd_flag, e = \
|
|
|
|
|
connect_with_cert (cert_name, path_to_cert, url, args,
|
|
|
|
|
wait_thread, clVarsCore, crypto_Error, Connect_Error)
|
|
|
|
|
|
|
|
|
|
if Connect_Error == 0:
|
|
|
|
|
break
|
|
|
|
|
# now = datetime.datetime.now()
|
|
|
|
|
# print '4 ===> %ds %dms' %(now.second, now.microsecond)
|
|
|
|
|
|
|
|
|
|
#If the certificate file misses
|
|
|
|
|
if Connect_Error:
|
|
|
|
|
if crypto_Error and 'store_passwd' in locals():
|
|
|
|
|
if crypto_Error and passwd_flag:
|
|
|
|
|
wait_thread.stop()
|
|
|
|
|
print _('Password is invalid')
|
|
|
|
|
# delete password from daemon list
|
|
|
|
|
clear_password(host, port)
|
|
|
|
|
return 1
|
|
|
|
|
if 'e' in locals():
|
|
|
|
|
if e:
|
|
|
|
|
wait_thread.stop()
|
|
|
|
|
print _('Error: '), e
|
|
|
|
|
return 1
|
|
|
|
|
# print 'Connect Error'
|
|
|
|
|
|
|
|
|
|
CERT_FILE = None
|
|
|
|
|
CERT_KEY = None
|
|
|
|
|
client = Client_suds(url, transport = HTTPSClientCertTransport \
|
|
|
|
|