fix create path

develop
Спиридонов Денис 12 years ago
parent d1df78f246
commit a94d6e71e9

@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import os, pwd
import sys
import urllib2
from sid_func import client_sid
@ -59,7 +59,6 @@ def client_post_cert (client, clVars, show_info = False):
except:
pass
#Creation of secret key of the client
def new_key_req(key, cert_path, server_host_name, private_key_passwd = None, \
auto = False):
@ -73,14 +72,24 @@ def new_key_req(key, cert_path, server_host_name, private_key_passwd = None, \
pkey.save_key(key, cipher = None, callback = lambda *unused: None)
else:
pkey.save_key(key, callback= lambda *unused: str(private_key_passwd))
req = makeRequest(rsa, pkey, server_host_name, auto)
crtreq = req.as_pem()
req_file = cert_path + '/%s.csr' %server_host_name
crtfile = open(req_file, 'w')
crtfile.write(crtreq)
crtfile.close()
user_name = pwd.getpwuid(os.getuid()).pw_name
try:
pwdObj = pwd.getpwnam(user_name)
except KeyError, e:
print e
return None
os.chown(key, pwdObj.pw_uid, pwdObj.pw_gid)
os.chmod(key, 0600)
return req_file
def delete_old_cert(client):
@ -124,8 +133,8 @@ def client_post_request (cert_path, args):
server_host_name = client.service.get_server_host_name()
key = cert_path + server_host_name + '.key'
csr_file = cert_path + server_host_name +'.csr'
key = os.path.join(cert_path, server_host_name + '.key')
csr_file = os.path.join(cert_path, server_host_name +'.csr')
if os.path.exists(key) and os.path.exists(csr_file):
print _('secret key and request exists')
ask = raw_input(_("Create new secret key and request? y/[n]: "))
@ -145,18 +154,18 @@ def client_post_request (cert_path, args):
if int(res) < 0:
print _("This server can not sign certificate!")
return 1
fc = open(cert_path + 'req_id', 'w')
fc = open(os.path.join(cert_path, 'req_id'), 'w')
fc.write(res)
fc.close()
print _("Your request id = %s") %res
return 0
def client_get_cert(cert_path, args):
if not os.path.exists(cert_path + 'req_id'):
if not os.path.exists(os.path.join(cert_path, 'req_id')):
print _("request was not sent or deleted file %s") \
%(cert_path + 'req_id')
%(os.path.join(cert_path, 'req_id'))
return 1
fc = open(cert_path + 'req_id', 'r')
fc = open(os.path.join(cert_path, 'req_id'), 'r')
req_id = fc.read()
fc.close()
@ -172,11 +181,11 @@ def client_get_cert(cert_path, args):
server_host_name = client.service.get_server_host_name()
if not os.path.exists(cert_path + server_host_name + '.csr'):
if not os.path.exists(os.path.join(cert_path, server_host_name + '.csr')):
print _('Request %s not found on client side') \
%(cert_path + server_host_name + '.csr')
%(os.path.join(cert_path, server_host_name + '.csr'))
return 1
request = open(cert_path + server_host_name + '.csr').read()
request = open(os.path.join(cert_path, server_host_name + '.csr')).read()
md5 = hashlib.md5()
md5.update(request)
md5sum = md5.hexdigest()
@ -197,11 +206,20 @@ def client_get_cert(cert_path, args):
elif cert == '4':
print _("Request was sent from another ip.")
return 1
fc = open(cert_path + server_host_name + '.crt', 'w')
cert_file = os.path.join(cert_path, server_host_name + '.crt')
fc = open(cert_file, 'w')
fc.write(cert)
fc.close()
os.unlink(cert_path + 'req_id')
print 'OK. Certificate save. Your certificate id = %s' %req_id
user_name = pwd.getpwuid(os.getuid()).pw_name
try:
pwdObj = pwd.getpwnam(user_name)
except KeyError, e:
print e
return None
os.chown(cert_file, pwdObj.pw_uid, pwdObj.pw_gid)
os.chmod(cert_file, 0600)
if ca_root:
clVars = DataVarsCore()
@ -216,7 +234,7 @@ def client_get_cert(cert_path, args):
homePath = clVars.Get('ur_home_path')
cl_client_cert_dir = cl_client_cert_dir.replace("~",homePath)
root_cert_md5 = cl_client_cert_dir + "/ca/cert_list"
root_cert_md5 = os.path.join(cl_client_cert_dir, "ca/cert_list")
md5 = hashlib.md5()
md5.update(ca_root)
@ -253,7 +271,7 @@ def client_get_cert(cert_path, args):
print _('Not found field "CN" in certificate!')
return 1
fd = open(cl_client_cert_dir + '/ca/' + filename, 'w')
fd = open(os.path.join(cl_client_cert_dir, 'ca', filename), 'w')
fd.write(ca_root)
fd.close()

@ -292,5 +292,4 @@ def rm_ca_from_trusted(ca_cert):
for cert in new_system_ca_certs:
fd.write(cert)
fd.close()
return 0

@ -37,6 +37,7 @@ from calculate.core.datavars import DataVarsCore
from client_class import HTTPSClientCertTransport
from methods_func import call_method, get_method_argparser
from calculate.lib.cl_lang import setLocalTranslate
from calculate.lib.utils.files import makeDirectory
from calculate.lib.utils.common import getpass
setLocalTranslate('calculate_console',sys.modules[__name__])
@ -279,6 +280,13 @@ def main():
path_to_cert = clVarsCore.Get('cl_client_cert_dir')
path_to_cert = path_to_cert.replace("~",homePath)
for dirs in ['', 'ca', 'trusted']:
dir_path = os.path.join(path_to_cert, dirs)
if not os.path.isdir(dir_path):
if not makeDirectory(dir_path):
print _("cannot create directory %s") %dir_path
return 1
if args.update_crl:
getCRL = threading.Thread(target=get_CRL, args = (path_to_cert, ))
getCRL.start()
@ -375,7 +383,7 @@ def main():
if 'e' in locals():
print _('Error: '), e
return 1
print 'CONNECT ERROR'
# print 'Connect Error'
CERT_FILE = None
CERT_KEY = None
client = Client_suds(url,\
@ -388,7 +396,8 @@ def main():
# now = datetime.datetime.now()
# print '5 ===> %ds %dms' %(now.second, now.microsecond)
try:
return_val = https_server(client, args, unknown_args, url, clVarsCore)
return_val = https_server(client, args, unknown_args, url, \
clVarsCore)
except urllib2.URLError, e:
print _('Error: '), e
# now = datetime.datetime.now()

@ -17,7 +17,7 @@
import urllib2 as u2
import os, sys
import socket, ssl
import OpenSSL, hashlib
import OpenSSL, hashlib, M2Crypto
from calculate.core.datavars import DataVarsCore
from calculate.lib.datavars import DataVars
from sudsds.client import Client
@ -117,7 +117,7 @@ class CheckingClientHTTPSConnection(CheckingHTTPSConnection):
homePath = clVars.Get('ur_home_path')
cl_client_cert_dir = clVarsCore.Get('cl_client_cert_dir')
cl_client_cert_dir = cl_client_cert_dir.replace("~",homePath)
root_cert_md5 = cl_client_cert_dir + "/ca/cert_list"
root_cert_md5 = os.path.join(cl_client_cert_dir, "ca/cert_list")
user_root_cert = clVarsCore.Get('cl_user_root_cert')
user_root_cert = user_root_cert.replace("~",homePath)
@ -272,7 +272,7 @@ class CheckingClientHTTPSConnection(CheckingHTTPSConnection):
cl_client_cert_dir = clVars.Get('cl_client_cert_dir')
homePath = clVars.Get('ur_home_path')
cl_client_cert_dir = cl_client_cert_dir.replace("~",homePath)
root_cert_dir = cl_client_cert_dir + "/ca"
root_cert_dir = os.path.join(cl_client_cert_dir, "ca")
if not os.path.exists(root_cert_dir):
try:
@ -458,12 +458,11 @@ class HTTPSClientCertTransport(HttpTransport):
(OpenSSL.SSL.FILETYPE_PEM, file(cert).read())
if password:
client_keyobj = OpenSSL.crypto.load_privatekey \
(OpenSSL.SSL.FILETYPE_PEM, file(key).read(),
str(password))
(OpenSSL.SSL.FILETYPE_PEM, file(key).read(),
str(password))
else:
import M2Crypto
bio = M2Crypto.BIO.openfile(key)
rsa = M2Crypto.m2.rsa_read_key(bio._ptr(),lambda *unused: None)
rsa = M2Crypto.m2.rsa_read_key(bio._ptr(),lambda *unused:None)
if not rsa:
raise OpenSSL.crypto.Error
client_keyobj = OpenSSL.crypto.load_privatekey \
@ -481,12 +480,10 @@ class HTTPSClientCertTransport(HttpTransport):
if ca_certs or (client_keyfile and client_certfile) \
or (client_keyobj and client_certobj):
https_handler = CheckingClientHTTPSHandler(cert_path=path_to_cert,
ca_certs=ca_certs,
cert_verifier=cert_verifier,
client_keyfile=client_keyfile,
client_certfile=client_certfile,
client_keyobj=client_keyobj,
client_certobj=client_certobj)
ca_certs=ca_certs, cert_verifier=cert_verifier,
client_keyfile=client_keyfile, client_certfile = \
client_certfile, client_keyobj=client_keyobj,
client_certobj=client_certobj)
else:
https_handler = u2.HTTPSHandler()
self.urlopener = u2.build_opener(SUDSHTTPRedirectHandler(),

Loading…
Cancel
Save