我寫了一個bash腳本,它向服務器發送POST請求。該請求包含證書籤名請求,服務器簽名並返回證書。 當我將CSR文本複製並粘貼到POST正文中時,POST請求成功。但是當我從變量中讀取CSR時,POST請求失敗。我附上了下面的程序片段。包含CSR的POST請求在Bash中失敗
程序 - 巴什
openssl req -new -newkey rsa:2048 -nodes -out cert.csr -keyout priv.key -subj "/C=MyCountry/ST=MyState/L=MyCity/O=MyCompany/OU=MyDept/CN=MyComp"
if [ $? == 0 ]; then
csr=$(<cert.csr)
fi
response=$(curl -o - -s -w "%{http_code}\n" -X POST \
https://xxx.xxx.com/URI-END-POINT \
-H "authorization: $token" \
-H "content-type: application/json" \
-d '{
"digicert": {
"csr": "'$csr'",
"profileName": "pn123",
"signatureHash": "sh123",
"userPrincipalName": "pn123",
"validationScopeId": "vsi123"
},
"IccId": "sim123",
"MacAddress": "mac123"
}')
if [ $?==0 ]; then
status=$(echo $response | tail -c 4)
if [ "$status" == "$http_success" ]; then
echo -e "Request for certificate SUCCESS"
else
echo -e "Request for certificate FAILED with return code $status"
fi
else
echo -e "Request for certificate FAILED"
fi
輸出 - 巴什
curl: option -----END: is unknown
curl: try 'curl --help' or 'curl --manual' for more information
在上面的腳本,如果我更換線「企業社會責任」: 「 '$企業社會責任'」,與「csr」:「---- BEGIN CERTIFICATE REQUEST ---- XXXXXXX ---- END CERTIFICATE REQUEST ----」,那麼這將工作正常。
你能幫我調試嗎?
謝謝!
嗨Klemen 見@ chepner的答案是一個有效方法。 –