The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

install_service_ssl_certificate certificate formatting issue?

Discussion in 'cPanel Developers' started by gwurr3, Jun 7, 2014.

  1. gwurr3

    gwurr3 Registered

    Joined:
    Jun 7, 2014
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hello y'all,

    I apologize if this is a repeat post. I haven't found anything quite like this on the web, yet.


    So I've been banging my head against the wall trying to get the install_service_ssl_certificate API call to work.
    i keep getting:

    Code:
    "This certificate cannot be parsed. It may be corrupt or in an unrecognized format."
    I've tried formatting with newline escape characters, spaces, etc etc. To no avail.

    Here is what i've got so far:

    Code:
    #!/usr/bin/perl
    use strict;
    use LWP::UserAgent;
    use LWP::Protocol::https;
     
    my $hash = qx(cat /root/.accesshash | tr -d "\n");
     
     
    my $auth = "WHM root:" . $hash;
    $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;
     
    my $ua = LWP::UserAgent->new;
    my $request =
      HTTP::Request->new( GET => "https://localhost:2087/json-api/install_service_ssl_certificate?api.version=1&service=dovecot&crt=-----BEGIN CERTIFICATE----- CERT GOES HERE -----END CERTIFICATE-----&key=-----BEGIN RSA PRIVATE KEY----- KEY GOES HERE -----END RSA PRIVATE KEY-----" );
    $request->header( Authorization => $auth );
    my $response = $ua->request($request);
    print $response->content;
    
    So, my question is, how am I supposed to format the cert/key text? For either json or xml. Either will work for me.

    Let's say for example I have a key that reads as such:

    Code:
    -----BEGIN CERTIFICATE-----
    DFGDFGDFGDFGDFGDFGDFGDFGDFGDFG
    QWEQWEQWEQWEQWEQWEQWEQWEQ
    ZXCZXCZXCZXCZXCZXCZXCZXCZXCZXC
    -----END CERTIFICATE-----
    
    How would I format this into the URL request string properly?
    If possible, I would appreciate if someone could point out where the xml vs json differences would be here, as well.


    Anyways, Thank y'all VERY much for your time and help in advance. : )
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,811
    Likes Received:
    671
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    Have you tried using the input URL directly in your browser to rule out any issues with your code? You can URI encode the key and certificate before doing so. A utility such as Url Encode/Decode might be helpful. Note that you may also find this documentation helpful:

    WHM API 1 - install_service_ssl_certificate

    Thank you.
     
  3. gwurr3

    gwurr3 Registered

    Joined:
    Jun 7, 2014
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hello Michael,

    I had tried examples as such in the docfile ( with \n newlines, etc. ) and played around with it, but couldn't get that going.

    I had put a ticket in (5066019) and Chris was an awesome help. He had URL encoded the cert, and added the " &ca= " variable to the end of the request string, and now everything is working.

    Code:
    my $ua = LWP::UserAgent->new;
    my $request =
      HTTP::Request->new( GET => "https://localhost:2087/json-api/install_service_ssl_certificate?api.version=1&service=dovecot&crt=$cert&key=$key&ca=" );
    $request->header( Authorization => $auth );
    my $response = $ua->request($request);
    print $response->content;
    
    The cert/key ended up looking as such
    Code:
    -----BEGIN%20CERTIFICATE-----%(URL ENCODED CERT)-----END%20CERTIFICATE-----
    

    Thank you cPanelMichael and Chris from tickets.cpanel.net : )
     
Loading...

Share This Page