Linux
SSL 證書可以在文件的單行上(無換行符)嗎?
SSL 證書預設在 67 個字元後有換行符。我正在嘗試使用 Chef 創建 SSL 證書文件。本質上,我想從一個字元串變數創建整個證書文件,而不需要任何換行符。我已經嘗試了幾次無濟於事(Apache抱怨無法找到證書)。
我不明白為什麼 SSL 證書中的換行是必要的。如果可以在文件中沒有任何換行符的證書,有什麼想法嗎?
不,如果沒有換行符,證書將無法正確處理 - 軟體將無法解析它。
如果您嘗試將其傳遞到字元串中,為什麼不將它們包含在其中?(
\n
)
我發現這個腳本很少這樣做。
awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}' ca.pem
這將採用多行的標準 PEM 文件,將“隱藏的”換行符替換為
\n
,並將輸出列印為單行。例如,這將使以下 PEM 文件…
-----BEGIN CERTIFICATE----- MIIIPDCCBySgAwIBAgIQB2XGTnTlkdaAOcoqhHVj8DANBgkqhkiG9w0BAQsFADBw MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 d3cuZGlnaWNlcnQuY29tMS8wLQYDVQQDEyZEaWdpQ2VydCBTSEEyIEhpZ2ggQXNz dXJhbmNlIFNlcnZlciBDQTAeFw0xODEwMDUwMDAwMDBaFw0xOTA4MTQxMjAwMDBa MGoxCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJOWTERMA8GA1UEBxMITmV3IFlvcmsx HTAbBgNVBAoTFFN0YWNrIEV4Y2hhbmdlLCBJbmMuMRwwGgYDVQQDDBMqLnN0YWNr ZXhjaGFuZ2UuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA9Kk6 NXUP1ocXt89mT1cIxadBhzCL0YTqP01/DSotUHRzV70qOCT7AdMT0K1Ji6rFyapz RiqUIhAkhEseXRp0MNr21fSUw4VoCb+ImO6gnIlzolkhrpK6Iy34KyU3zyt8XYD+ mY3i8GjPZOysRJNLy3ouQBmzuOmU/2FomnmiEGF02mVgb3ev8Prcnt7dC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