zoukankan      html  css  js  c++  java
  • curl-users unable to set private key file ?

    转自:https://curl.haxx.se/mail/archive-2005-09/0138.html

    Greetings CURL users!

    I just subscribed to the list and would like to share a problem and it's
    solution, after a couple of hours working around it... I was going to write
    to the list for help ;)

    I was having problems using Curl to connect to a https server using a client
    certificate. I believe i was doing everything by the book, but somehow Curl
    kept complaining about the private key file.

    1) I had a PKCS#12 file which contained the CA and Client certificates and
    the private key: "MULTICERT.p12"

    2) I convert it to PEM format with:
    openssl pkcs12 -in MULTICERT.p12 -out cert.pem
    Enter Import Password:
    MAC verified OK
    Enter PEM pass phrase:
    Verifying - Enter PEM pass phrase:

    and the file cert.pem was created with all the certificates and the private
    key (i used "xxxxxx" for the PEM pass phrase).

    3) However when i used Curl to connect to the https server

    curl -d "var1=value1&var2=value2&..." -G -v --cert cert.pem:xxxxxx
    https://www.somesite.com/page
    * About to connect() to www.somesite.com port 443
    * Trying 123.123.123.123... * connected
    * Connected to www.somesite.com (123.123.123.123) port 443
    * unable to set private key file: 'cert.pem' type PEM

    * Closing connection #0
    curl: (58) unable to set private key file: 'cert.pem' type PEM

    4) So then i tried to put the CA certificate, Client Certificate and Private
    Key in separate files:
    openssl pkcs12 -in MULTICERT.p12 -out ca.pem -cacerts -nokeys
    openssl pkcs12 -in MULTICERT.p12 -out client.pem -clcerts -nokeys
    openssl pkcs12 -in MULTICERT.p12 -out key.pem -nocerts

    and then i tried Curl again:

    curl -d "var1=value1&var2=value2&..." -G -v --key key.pem --cacert
    ca.pem --cert client.pem:xxxxxx https://www.somesite.com/page

    and it worked!!! :)

    Still don't know why the first method - having everything in one cert file -
    didn't work...!?
    Maybe the proivate key was'nt on the right order...

    Well, anyway, hope this helps anyone

    Cheers!

  • 相关阅读:
    Java开发环境搭建
    MySQL优化
    js正则表达式,验证身份证
    获取urlc参数
    Oracle解锁
    Qt 常用类 (4)—— QPoint
    Qt 常用类——QStandardItemModel
    Qt QTableWidget用法总结
    Qt 随机数
    C++ static类成员,static类成员函数
  • 原文地址:https://www.cnblogs.com/z1500592/p/10338180.html
Copyright © 2011-2022 走看看