使用cPanel UAPI的install_ssl时,我遇到“证书文本无效”。

时间:2016-12-13 16:37:32

标签: ssl cpanel

我正在使用cPanel UAPI来调用install_ssl函数。我已经按照教程[这里] [1]:https://documentation.cpanel.net/display/SDK/Tutorial+-+Call+UAPI%27s+SSL%3A%3Ainstall_ssl+Function+in+Custom+Code#4ba262da2a5b4308828c17a2156d5dc9

但是,我在尝试读取证书时遇到了解析错误。我已从我的cPanel SSL管理UI复制了证书并将其放在一个文件中。我知道这个文件正在被正确读取。但是,当通过API发送时,我收到以下错误。

“由于错误,系统无法解析证书:证书文本无效。”

我已经尝试过编写证书和密钥的url,但没有做任何事情。这是我使用的代码。 (我在Drupal中这样做,因此使用dpm)

function _bh_site_configure_multi_add_ssl($ fulldomain){

// Declare your username and password for authentication.


$username = "myusername";
$password = "mypassword";

// Define the API call.
$cpanel_host = "myserver";
$request_uri = "https://$cpanel_host:2083/execute/SSL/install_ssl";

// Define the SSL certificate and key files.
$cert_file = realpath("/path/to/file/cert.crt");
$key_file = realpath("/path/to/file/key.key");

// Set up the payload to send to the server.
$payload = array(
    'domain' => $fulldomain,
    'cert'   => file_get_contents($cert_file),
    'key'    => file_get_contents($key_file)
);

// Set up the cURL request object.
$ch = curl_init( $request_uri );
curl_setopt( $ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
curl_setopt( $ch, CURLOPT_USERPWD, $username . ':' . $password );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );

// Set up a POST request with the payload.
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

// Make the call, and then terminate the cURL caller object.
$curl_response = curl_exec( $ch );
curl_close( $ch );

// Decode and validate output.
$response = json_decode( $curl_response );
if( empty( $response ) ) {
    dpm("The cURL call did not return valid JSON:\n");
} elseif ( !$response->status ) {
    dpm("The cURL call returned valid JSON, but reported errors:\n");
    dpm($response->errors[0] . "\n") ;
} 

dpm ($response);

1 个答案:

答案 0 :(得分:0)

我发现我的特殊证书需要有这个小屋。当我回到我从证书颁发机构获得的证书的安装说明时,它包括一个cabundle。在我加入之后,它起作用了。