Exemple #1
0
def client_post_request (cert_path, by_host):
    if os.path.exists(cert_path + 'req_id'):
        print _("You already sent a certificate signature request.")
        print _("Request ID = %s") %open(cert_path + 'req_id', 'r').read()
        ans = raw_input (_("Send a new request? y/[n]: "))
        if not ans.lower() in ['y','yes']:
            return 0
    
    port = raw_input (_("Enter the port number: "))
    try:
        port = int(port)
    except:
        print _('The port number must be int')
        return 1
    url = "https://%s:%d/?wsdl" %(by_host, port)
    print url + '\n' + _("connecting...")
    from sudsds.client import Client
    #try:
    client = Client(url, transport = HTTPSClientCertTransport(None, None,
                                                              cert_path))
    #except (KeyboardInterrupt, urllib2.URLError), e:
        #print '\n'+_("Closed. Connection error.")
        #print _("Error code: %s") %e
        #return 0
    
    server_host_name = client.service.get_server_host_name()
    
    key = cert_path + server_host_name + '.key'
    csr_file = cert_path + server_host_name +'.csr'
    if os.path.exists(key) and os.path.exists(csr_file):
        print _("the private key and request now exist")
        ask = raw_input(_("Create a new private key and request? y/[n]: "))
        if ask.lower() in ['y','yes']:
            new_key_req(key, cert_path, server_host_name)
    else:
        new_key_req(key, cert_path, server_host_name)

    ip, mac, client_type = get_ip_mac_type()
    data = open(csr_file).read()
    res = client.service.post_client_request(request = data, ip = ip,\
                                    mac = mac, client_type = client_type)
    if int(res) < 0:
        print _("This server is not enabled to sign certificates!")
        return 1
    fc = open(cert_path + 'req_id', 'w')
    fc.write(res)
    fc.close()
    print _("Your request ID = %s") %res
    return 0
    
    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 _("the private key and request now exist")
        ask = raw_input(_("Create a new private key and request? y/[n]: "))
        if ask.lower() in ['y','yes']:
            passwd = get_password()
            new_key_req(key, cert_path, server_host_name, 
                        private_key_passwd = passwd)
    else:
        passwd = get_password()
        new_key_req(key, cert_path, server_host_name,
                    private_key_passwd = passwd)

    ip, mac, client_type = get_ip_mac_type()
    data = open(csr_file).read()
    res = client.service.post_client_request(request = data, ip = ip,\
                                    mac = mac, client_type = client_type)
    if int(res) < 0:
        print _("The server has not signed the certificate!")
        return 1
    fc = open(os.path.join(cert_path, 'req_id'), 'w')
    fc.write(res)
    fc.close()
    _print (_("Your request ID = %s") %res + '.\n',
            _("To submit the certificate request on the server use command") + \
           '\n'+'cl-core --sign-client ID_CLIENT_REQUEST')
    return 0
    
def client_get_cert(cert_path, args):