Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

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.

curl_exec threw error SSL read

Discussion in 'cPanel Developers' started by speckados, Oct 25, 2016.

Tags:
  1. speckados

    speckados Well-Known Member

    Joined:
    May 21, 2003
    Messages:
    305
    Likes Received:
    0
    Trophy Points:
    166
    Location:
    Acequias :: Granada :: España
    cPanel Access Level:
    DataCenter Provider
    Twitter:
    Hi.

    After days working with code for connect to remote WHM, with hash, get this error

    PHP:
    curl_exec threw error "SSL read: error:00000000:lib(0):func(0):reason(0), errno 104" for https://myhost.com:2087/json-api/listaccts?api.version=1
    PHP:
    $whmuser 'root';
            
    $hash    $this->hash// correct has one line
            
    $host    $this->host;  // myhost.com
            
    $query   "https://".$host.":2087/json-api/listaccts?api.version=1";

            
    $curl curl_init();
            
    curl_setopt($curlCURLOPT_SSL_VERIFYHOST,0);
            
    curl_setopt($curlCURLOPT_SSL_VERIFYPEER,0);
            
    curl_setopt($curlCURLOPT_RETURNTRANSFER,1);

            
    $header[0] = "Authorization: WHM $whmuser:" preg_replace("'(\r|\n)'","",$hash);
            
    curl_setopt($curl,CURLOPT_HTTPHEADER,$header);
            
    curl_setopt($curlCURLOPT_URL$query);

            
    $result curl_exec($curl);
            if (
    $result == false) {
                
    $msg "curl_exec threw error \"" curl_error($curl) . "\" for $query";
                
    Log::critical($msg);
                exit(
    $msg);
            }
            
    curl_close($curl);
    If try debug connection

    Code:
    openssl s_client -connect  "myhost.com:2087"
    CONNECTED(00000003)
    depth=3 C = SE, O = AddTrust AB, OU = AddTrust External TTP Network, CN = AddTrust External CA Root
    verify return:1
    depth=2 C = GB, ST = Greater Manchester, L = Salford, O = COMODO CA Limited, CN = COMODO RSA Certification Authority
    verify return:1
    depth=1 C = US, ST = TX, L = Houston, O = "cPanel, Inc.", CN = "cPanel, Inc. Certification Authority"
    verify return:1
    depth=0 OU = Domain Control Validated, OU = PositiveSSL, CN = myhost.com
    verify return:1
    ---
    Certificate chain
    0 s:/OU=Domain Control Validated/OU=PositiveSSL/CN=myhost.com
       i:/C=US/ST=TX/L=Houston/O=cPanel, Inc./CN=cPanel, Inc. Certification Authority
    1 s:/C=US/ST=TX/L=Houston/O=cPanel, Inc./CN=cPanel, Inc. Certification Authority
       i:/C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Certification Authority
    2 s:/C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Certification Authority
       i:/C=SE/O=AddTrust AB/OU=AddTrust External TTP Network/CN=AddTrust External CA Root
    ---
    Server certificate
    -----BEGIN CERTIFICATE-----
    MIIFIjCCBAqgAwIBAgIRAJOGf5WM8tcI8ZCGtRJrgKkwDQYJKoZIhvcNAQELBQAw
    cjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAlRYMRAwDgYDVQQHEwdIb3VzdG9uMRUw
    ...
    VKzpPon19yK1P1cMTn2Ngq7fu6CjTFpuXrisqfC6lEiEikWSVWdsIKTpoyIgCRKp
    mGXvtyD98u1tX9kIsl2Xmz0/KTvAwA==
    -----END CERTIFICATE-----
    subject=/OU=Domain Control Validated/OU=PositiveSSL/CN=myhost.com
    issuer=/C=US/ST=TX/L=Houston/O=cPanel, Inc./CN=cPanel, Inc. Certification Authority
    ---
    No client certificate CA names sent
    Peer signing digest: SHA512
    Server Temp Key: ECDH, P-256, 256 bits
    ---
    SSL handshake has read 4908 bytes and written 431 bytes
    ---
    New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES128-GCM-SHA256
    Server public key is 2048 bit
    Secure Renegotiation IS supported
    Compression: NONE
    Expansion: NONE
    No ALPN negotiated
    SSL-Session:
        Protocol  : TLSv1.2
        Cipher    : ECDHE-RSA-AES128-GCM-SHA256
        Session-ID: 9A955F47CE2WWWWWDSASSS275FAF70AD1DECE3FB282AFB995560C6E8D114
        Session-ID-ctx:
        Master-Key: 4D1AB53CEA341EKSAKSKSK8B71826B01C9B2D9106A3AD353D92637727D0326A5476AEEAAD8E0932CE40879D9199DE51BB
        Key-Arg   : None
        PSK identity: None
        PSK identity hint: None
        SRP username: None
        TLS session ticket lifetime hint: 300 (seconds)
        TLS session ticket:
        0000 - 45 22 00 80 dd 85 95 88-8e 7c ae d3 27 a5 f2 ba   E".......|..'...
        0010 - 3f a8 85 50 e2 8b da 20-21 2a 62 87 10 ef 75 11   ?..P... !*b...u.
        0020 - e1 0d e9 34 15 1b 0c 8a-12 f6 cf 49 6b c4 a2 f7   ... .......Ik...
        0030 - 77 26 e8 b0 4f a4 12 e8-f7 c1 e7 68 65 9f dc 7d   w&..O......he..}
        0040 - b0 6b 70 a6 f3 43 13 38-75 f7 73 ae 2a 50 80 29   .kp....8u.s.*P.)
        0050 - f7 8d 4c 9a d6 0e 00 4b-8a 49 8d e2 c8 d3 b2 8a   ..L....K.I......
        0060 - 28 78 a1 1c 4f b7 3c a5-b7 c5 84 19 a0 c1 03 f4   (x..O.<.........
        0070 - 76 1b 05 e5 2a 4e cd 73-09 f1 99 69 06 c6 a8 bb   v...*N.s...i....
        0080 - 64 92 78 76 61 3f 7d c0-13 95 d4 78 1a d0 32 bc   d.xva?}....x..2.
        0090 - 99 7d 5a f2 b0 06 66 57-6c 00 d2 ef 32 82 cb f6   .}Z...fWl...2...
    
        Start Time: 1477417001
        Timeout   : 300 (sec)
        Verify return code: 0 (ok)
    
    Some ideas?
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,658
    Likes Received:
    1,419
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    Could you let us know if the example from the Guide to API Authentication document works? Here's how it would look:

    PHP:
    <?
    $whmusername "root";

    # The contents of /root/.accesshash
    $hash "accesshashhere";

    $query "https://127.0.0.1:2087/json-api/listaccts?api.version=1";

    $curl curl_init();
    curl_setopt($curlCURLOPT_SSL_VERIFYHOST,0);
    curl_setopt($curlCURLOPT_SSL_VERIFYPEER,0);
    curl_setopt($curlCURLOPT_RETURNTRANSFER,1);

    $header[0] = "Authorization: WHM $whmusername:" preg_replace("'(\r|\n)'","",$hash);
    curl_setopt($curl,CURLOPT_HTTPHEADER,$header);
    curl_setopt($curlCURLOPT_URL$query);

    $result curl_exec($curl);
    if (
    $result == false) {
        
    error_log("curl_exec threw error \"" curl_error($curl) . "\" for $query");
    }
    curl_close($curl);

    print 
    $result;
    ?>
    Also, how are you calling the PHP script?

    Thank you.
     
Loading...

Share This Page