def get_certificate(cert_path,data_path,certbase,client_cert_path,user_name): req_id_file = os.path.join(client_cert_path, 'req_id') if not os.path.exists(req_id_file): print _("request not sent or file %s deleted") %req_id_file return 1 fc = open(req_id_file, 'r') req_id = fc.read() fc.close() server_host_name = socket.getfqdn() req_file = os.path.join(client_cert_path, server_host_name + '.csr') if not os.path.exists(req_file): print _('Request %s not found') %req_file return 1 request = open(req_file).read() md5 = hashlib.md5() md5.update(request) md5sum = md5.hexdigest() result = post_request.serv_get_client_cert (req_id, md5sum, data_path, \ certbase, cert_path) cert = result[0] if len (result) > 1: ca_root = result[1] else: None if cert == '1': print _('The signature request was rejected!') return 1 elif cert == '2': print _("The signature request has not been examined yet.") print _("Your request ID = %s") %req_id return 1 elif cert == '3': print _("The signature request does not match earlier data.") return 1 elif cert == '4': print _("The request was sent from another IP.") return 1 cert_file = os.path.join(client_cert_path, server_host_name + '.crt') fc = open(cert_file, 'w') fc.write(cert) fc.close() try: pwdObj = pwd.getpwnam(user_name) except KeyError, e: print e return None
def get_client_cert (self, req_id, request) : res = post_request.serv_get_client_cert (req_id, request,\ self.data_path, self.certbase, self.cert_path) return res