2017-07-06 66 views
2

我正在將證書身份驗證設置爲我的nifi服務器。錯誤讀取X.509密鑰或證書文件:解析錯誤

我已經使用nifi-tools/tls-toolkitnifi project生成密鑰庫,信任庫,客戶端證書等。

我已將p12格式的tls-toolkit生成的客戶端證書添加到我的瀏覽器並配置了我的nifi服務器屬性。一切正常。

現在我想在ruby腳本中使用客戶端證書。

要做到這一點我已經轉換從P12格式的證書PEM格式這樣的...

openssl pkcs12 -in CN=admin_DC=nifi_DC=com.p12 -passin pass:26V+Hs1qupglToDlVqO+oKW0yWR2jG3uXjuFTUus76o -out a.pem MAC verified OK Enter PEM pass phrase:

PEM密碼短語空白。

爲了測試它,我試過

curl --insecure --cert-type pem --cert "a.pem" "https://127.0.0.1:9443/nifi" curl: (35) error reading X.509 key or certificate file: Error in parsing.

錯誤解析?我還沒有找到任何有關它的信息。

讓我們來驗證...

openssl verify a.pem a.pem: DC = com, DC = nifi, CN = admin error 20 at 0 depth lookup:unable to get local issuer certificate

驗證與塔CA文件...

openssl verify -verbose -x509_strict -issuer_checks -CAfile nifi-cert.pem a.pem a.pem: OK

隨着我的Ruby腳本失敗過(明明)

require 'rest_client' 

a = RestClient::Resource.new(
    'https://127.0.0.1:9443/nifi', 
    :ssl_client_cert => OpenSSL::X509::Certificate.new(File.read("a.pem")), 
    :verify_ssl  => OpenSSL::SSL::VERIFY_NONE 
).get 

pp a 

`

我得到...

/usr/lib/ruby/2.3.0/net/http.rb:933:in `connect_nonblock': SSL_connect returned=1 errno=0 state=unknown state: sslv3 alert bad certificate (OpenSSL::SSL::SSLError) 
from /usr/lib/ruby/2.3.0/net/http.rb:933:in `connect' 
from /usr/lib/ruby/2.3.0/net/http.rb:863:in `do_start' 
from /usr/lib/ruby/2.3.0/net/http.rb:852:in `start' 
from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:715:in `transmit' 
from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:145:in `execute' 
from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:52:in `execute' 
from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/resource.rb:51:in `get' 
from test.rb:8:in `<main>' 

的哪些錯誤?

謝謝。

回答

0

我的預感是發行者證書(簽署客戶端證書的Apache NiFi CA公共證書)未捆綁在導出的PEM文件中。此外,系統上生成了NiFi CA,並將其導入到NiFi信任庫中,但它不會自動導入到OpenSSL信任庫JRE cacerts或任何瀏覽器信任庫中,因此這些工具會報告它是未驗證的CA.

您可以驗證導出的PEM是否處於預期格式?簡單的morexxd命令將以原始形式輸出它,並且您可以檢查文件結構。它應該是這樣的:

hw12203:/Users/alopresto/Workspace/nifi (master) alopresto 
1s @ 09:32:18 $ more ..//scratch/secure_nifi/client.pem 
Bag Attributes 
    friendlyName: nifi-key 
    localKeyID: 4D A3 BA 01 40 32 60 6F 84 0B 1B B7 7F 1E 50 81 C7 DF 45 96 
Key Attributes: <No Attributes> 
Removed private key 
Bag Attributes 
    friendlyName: nifi-key 
    localKeyID: 4D A3 BA 01 40 32 60 6F 84 0B 1B B7 7F 1E 50 81 C7 DF 45 96 
subject=/OU=Apache NiFi/CN=alopresto 
issuer=/OU=NIFI/CN=localhost 
-----BEGIN CERTIFICATE----- 
MIIDTTCCAjWgAwIBAgIKAVpj404fAAAAADANBgkqhkiG9w0BAQsFADAjMQ0wCwYD 
... lines removed ... 
WLvUHa29207v8ZQ6eFuTwM4OTISQIBRahxFqaluCvdQ8 
-----END CERTIFICATE----- 
Bag Attributes: <Empty Attributes> 
subject=/OU=NIFI/CN=localhost 
issuer=/OU=NIFI/CN=localhost 
-----BEGIN CERTIFICATE----- 
MIIDSTCCAjGgAwIBAgIKAVpj40jcAAAAADANBgkqhkiG9w0BAQsFADAjMQ0wCwYD 
... lines removed ... 
T7q7PHuhxvvdG4ckFMNpntxdTGIUoioZYzeijY4= 
-----END CERTIFICATE----- 

你可以看到兩個證書都包含有 - 第一是我的客戶證書,第二個是簽署它的CA證書。

此外,您可能需要使用-nodes標誌將私鑰從PKCS12導出到PEM。該標誌不是指「節點」,而是指示「無DES加密」,又名「無需密碼」。您可以在this StackOverflow answer中看到更多關於使用該標誌的信息。

相關問題