- Community Home
- >
- Software
- >
- HPE OneView
- >
- REST API upload CA chain
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11 hours ago
11 hours ago
REST API upload CA chain
I recently updated the server certificate for one of our OneView instances. When I tried to upload the signed certificate via the REST API it was rejected because the intermdiate certificate it was signed by was not in OneView. So, I tried to upload that intermediate certificate, but it was rejected because the root certificate it was signed by was not in OneView. We have an internal CA with several intermediate and root certificates. So, I downloaded all of those. I read that I can upload the entire chain to /rest/certificates/ca. So, I wrote build-cert-chain.sh to build the cert chain.
#!/bin/bash
for VAR in OneView currentVersion sessionID DATA; do
if [[ -z ${!VAR+x} ]]; then echo "${VAR} is not set! You need to source the get-session-credentials.sh script.";return 1 2>/dev/null || exit 1;fi
done
declare -i NUM=2
OPTIND=1
OPTARG=
OPTERR=1
while getopts 'c:a:n:' flag; do
case "${flag}" in
a) ALIAS=${OPTARG};;
c) SCRT=${OPTARG};;
n) NUM=${OPTARG};if ! [[ "${NUM}" =~ ^[0-9]+$ ]]; then echo "The value for -n must be a number." >&2;return 2 || exit 2;fi;;
esac
done
if [[ "${NUM}" == "" ]]; then echo "NUM was not set. Setting it to 1";NUM=1;fi
SCRTN=$(awk 'NF {sub(/\r/, ""); printf "%s\\n", $0}' "$SCRT")
if [[ ${NUM} -eq 1 ]]; then
DATA=$(jq -n --arg cert "${SCRTN}" --arg alias "${ALIAS}" '{members:[{certificateDetails:{base64Data:$cert,aliasName:$alias}}]}')
else
DATA=$(jq --arg cert "${SCRTN}" --arg alias "${ALIAS}" '.members += [{certificateDetails:{base64Data:$cert,aliasName:$alias}}]' <<<"${DATA}")
fi
export DATAI then ran echo ${DATA} > chain.cer. I wrote upload-ca-cert.sh to upload it:
#!/bin/bash
for VAR in OneView currentVersion sessionID DATA; do
if [[ -z ${!VAR+x} ]]; then echo "${VAR} is not set! You need to source the get-session-credentials.sh script.";return 1 2>/dev/null || exit 1;fi
done
OPTIND=1
OPTARG=
OPTERR=1
while getopts 'c::' flag; do
case "${flag}" in
c) SCRT=${OPTARG};;
esac
done
CERTURI=$(curl --insecure --include --silent \
--header "content-type: application/json" \
--header "X-API-Version: ${currentVersion}" \
--header "auth: ${sessionID}" \
--data @SCRT \
--request POST ${OneView}/rest/certificates/ca | grep '^Location:' | awk '{ print $2 }')
echo "Waiting 30 seconds for the process to complete"
sleep 29
echo "Checking the status of the upload process:"
curl --insecure --silent \
--header "X-API-Version: ${currentVersion}" \
--header "auth: ${sessionID}" \
--request GET ${OneView}${CERTURI} | jq -r '.'
export CERTURIWhen I try to upload it, I get INVALID JSON MAPPING, JSON cannot be parsed. Oh! I think I might have one too many backslashes before n for the linefeeds. I have: \\n. I think it is supposed to be \n. Let me try to rectify that and see how it goes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10 hours ago - last edited 9 hours ago
10 hours ago - last edited 9 hours ago
Re: REST API upload CA chain
Unfortunately removing that extra backslash did not do it. Any ideas? My JSON looks just like the example:
{
"members": [
{
"certificateDetails": {
"base64Data": "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----",
"aliasName": "ca Alias Name1"
}
},
{
"certificateDetails":{
"base64Data":"-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----",
"aliasName":"ca Alias Name2"
}
}
]
}The alias names have spaces in them. Does that matter?
Just FYI, I also tried just uploading a single intermediate certificate and got the same response.