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!

cPanel API2 installSSL issue

Discussion in 'cPanel Developers' started by resolv_25, Aug 26, 2018.

  1. resolv_25

    resolv_25 Registered

    Joined:
    Aug 26, 2018
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Croatia
    cPanel Access Level:
    Root Administrator
    Hello,

    I need help with cpapi2 installSSL.

    I’m using CMD option described on manual:
    cPanel API 2 Functions - SSL::installssl - Developer Documentation - cPanel Documentation

    Here is my shell command as a root:
    Code:
    cpapi2 --user=cpaneluser SSL installssl cabundle=-----BEGIN CERTIFICATE-----\\nMIIEsTCCA5mgAwIBAgIQCKWiRs1LXIyD1wK0u6tTSTANBgkqhkiG9w0BAQsFADBh\\nMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\\nMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\\nQTAeFw0xNzExMDYxMjIzMzNaFw0yNzExMDYxMjIzMzNaMF4xCzAJBgNVBAYTAlVT\\nMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\\nb20xHTAbBgNVBAMTFFJhcGlkU1NMIFJTQSBDQSAyMDE4MIIBIjANBgkqhkiG9w0B\\nMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\\n+MgP5viaHLy+VpHP+ndX5D18INIuuAV8wFq26KF5U0WNIZiQp6mLtIWjUeWDPA28\\nMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\\nMFz4J4JE8N7NA1uJwUEFMUvHLs0scLoPZkKcewIRm1RV2AxmFQxJkdf7YN9Pckki\\nMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRG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h3+jyfEK0AJlvOdvRf1DT4APkWQGJY\\noyfJFbQtIH9FdTchOSgnPDKrXg3DsyqzUkh3+jyfEK0AJlvOdvRf1DT4APkWQGJY\\noyfJFbQtIH9FdTchOSgnPDKrXg3DsyqzUkh3+jyfEK0AJlvOdvRf1DT4APkWQGJY\\noyfJFbQtIH9FdTchOSgnPDKrXg3DsyqzUkh3+jyfEK0AJlvOdvRf1DT4APkWQGJY\\nV5UKq1LoGpCWZDaOHtGFAAABZWuFXhsAAAQDAEgwRgIhAPybZjDd2ONTzUBuaooh\\nDlgXIoiUdGFel5QeaTlKVD6lAiEAuKk6+Lu+LsRUcWd6uFXQDiVchGAlShQ/NhyX\\nJQKMtI8AdQCHdb/nWXz4jEOZX73zbv9WjUdWNv9KtWDBtOr/XqCDDwAAAWVrhV4R\\noyfJFbQtIH9FdTchOSgnPDKrXg3DsyqzUkh3+jyfEK0AJlvOdvRf1DT4APkWQGJY\\noyfJFbQtIH9FdTchOSgnPDKrXg3DsyqzUkh3+jyfEK0AJlvOdvRf1DT4APkWQGJY\\npoUkad5Lo+x4orm+4wuA2np4SOxIjd8rafqwQjR2JLhxXLopDSwbUcXiV7RJpjQi\\npfyRWtO2mdYHDNvyaaS33k/6I+RSzWT26Yifb4w056tfMG1jnK2pCQd4MhpDQZKa\\nynv3rIWCYKL9JPiTGsWOlo2JUxa5/7vlVqqA8L5+D3j/Mb+PTGdnKnzvnDFALctH\\nF7o8UbvVxMI+W+mVLg29eCzrBjaBAY/yeALafvleaxa2+p6JRdQf8NILfb8yXhlM\\noyfJFbQtIH9FdTchOSgnPDKrXg3DsyqzUkh3+jyfEK0AJlvOdvRf1DT4APkWQGJY\\nAAAAAAAAAAAAAAAAAAzaPw==\\n-----END CERTIFICATE----- domain=domain.tld
    
    The error from cpanel shell:
    Code:
    Odd number of elements in hash assignment at bin/apitool.pl line 137.
    
    Use of uninitialized value in list assignment at bin/apitool.pl line 137.
    
    Odd number of elements in hash assignment at bin/apitool.pl line 139.
    
    [2018-08-26 12:57:36 +0200] warn [cpanel] Encountered error in SSL::installssl: The certificate text was not valid.The system could not parse the certificate because of an error: The certificate text was not valid. at /usr/local/cpanel/Cpanel/EventHandler.pm line 112.
    
    Cpanel::EventHandler::post_event(2, "post", "SSL", "installssl", HASH(0x25e2f58), ARRAY(0x25e40d8)) called at /usr/local/cpanel/Cpanel/Api2/Exec.pm line 165
    
    Cpanel::Api2::Exec::api2_exec("SSL", "installssl", HASH(0x25e3708), HASH(0x25e2f58)) called at cpanel.pl line 1278
    
    cpanel::cpanel::docpanelaction(HASH(0x25e31f8)) called at cpanel.pl line 4227
    
    cpanel::cpanel::run_fast_json_mode() called at cpanel.pl line 840
    
    cpanel::cpanel::script("cpanel::cpanel", "--json-fast-connect", "--stdin") called at cpanel.pl line 271
    
    ---
    
    cpanelresult:
    
    apiversion: 2
    
    data:
    
    -
    
    output: "The system could not parse the certificate because of an error: The certificate text was not valid."
    
    result: 0
    
    error: "The certificate text was not valid.The system could not parse the certificate because of an error: The certificate text was not valid."
    
    event:
    
    result: 1
    
    func: installssl
    
    module: SSL
    
    postevent:
    
    result: 1
    
    preevent:
    
    result: 1
    
    (the cert above is not real, it is changed. I put a quote only for readability )

    First, on the manual, cabundle is not required, I’ve tried without, result is the same.
    I've tried to put cert in the single or double quote, doesn't work.
    However, I do parse the cert with a sed to get \\n in all spaces except in -----BEGIN CERTIFICATE----- and -----END CERTIFICATE-----
    Although it looks fine, it is possible that format of cert became irregular.
    Still, I'm stuck with this problem, maybe I do miss something else?

    It is installed Cpanel v74.0.5 , CloudLinux
    Thanks
     
    #1 resolv_25, Aug 26, 2018
    Last edited by a moderator: Aug 26, 2018
  2. cPanelLauren

    cPanelLauren Forums Analyst II Staff Member

    Joined:
    Nov 14, 2017
    Messages:
    6,502
    Likes Received:
    509
    Trophy Points:
    263
    Location:
    Houston
    cPanel Access Level:
    DataCenter Provider
    Hi @resolv_25

    First I want to suggest using the UAPI function rather than the cPapi2 function for this: UAPI Functions - SSL::install_ssl - Developer Documentation - cPanel Documentation

    I would also suggest reading the following: Tutorial - Call UAPI's SSL::install_ssl Function in Custom Code - Developer Documentation - cPanel Documentation

    I believe the method's for installing an SSL listed in the documentation for the Install SSL function in Custom Code will be helpful in this instance.

    Thanks!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. resolv_25

    resolv_25 Registered

    Joined:
    Aug 26, 2018
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Croatia
    cPanel Access Level:
    Root Administrator
    Hi, thanks for your reply.
    One thing isn't clear from manual, do I have to parse cert, cabundle and key on the same format:
    Code:
    -----BEGIN CERTIFICATE-----\\nMIIEsTCCetc
    I mean, do I have to put \\n in the space between lines.
    Probably yes as on the cpapi2.
    I would prefer to use shell instead Perl or PHP because one can use a ssh key and install it on various servers without need of further authentication.
    Well, I was hoping to use cpapi2 because it is not asking the private key. WHM GUI is also smart enough when providing the cert, it can automatically populate cabundle and key.

    However, I'll try with that.
    Regards,
     
  4. cPanelLauren

    cPanelLauren Forums Analyst II Staff Member

    Joined:
    Nov 14, 2017
    Messages:
    6,502
    Likes Received:
    509
    Trophy Points:
    263
    Location:
    Houston
    cPanel Access Level:
    DataCenter Provider
    Hi @resolv_25

    You're correct for cPapi2 it should include \\n for lines as indicated in the example the UAPI function should behave the same way as well.

    Thanks!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice