install_service_ssl_certificate certificate formatting issue?

gwurr3

Registered
Jun 7, 2014
4
0
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. : )
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,267
463
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.
 

gwurr3

Registered
Jun 7, 2014
4
0
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 : )