-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to invoke the authsign api #864
Comments
Read the API docs again. You need to wrap the inner request in an outer request. This is the ruby code I use. def authsign(authkey, csr, options = {})
inner_request = {
:certificate_request => csr
}.merge(options)
inner_request_json = JSON.generate(inner_request)
token = OpenSSL::HMAC.digest("SHA256", hexdecode(authkey), inner_request_json)
outer_request = {
:token => Base64.strict_encode64(token),
:request => Base64.strict_encode64(inner_request_json)
}
response = @conn.post('/api/v1/cfssl/authsign', JSON.generate(outer_request))
process_response(response)
end |
@annakz The key in your example is already a hex-encoded string. Try to decode it instead of encode it, before doing the b64 encoded HMAC. This is how I do it in Python 2.7:
|
To generate the token in bash: cat request.json | openssl dgst -sha256 -mac HMAC -macopt hexkey:$auth_key -binary | base64 |
Here's bit by bit instructions, just in case. Also includes using SANs. Create a keypair and the corresponding CSR$ openssl req -new -newkey rsa:2048 -nodes \
-out example.csr \
-keyout example.key Generate the authenticated request$ onboarding_key="XXXXX"
$ cn=example.com
$ csr=$(cat "example.csr")
$ sans=""
$ certificate_req=$(jq -n -c -j \
--arg csr "${csr}" \
--arg cn "${cn}" \
--arg sans "${sans}" \
'{"certificate_request":($csr+"\n"),"profile":"self-signed-ca","hosts":([ $cn ] + ($sans | split(" ")))}')
$ base64_certificate_req=$(printf '%s' "${certificate_req}" | base64 | tr -d '\n')
$ hex_encoded_onboarding_key="$(echo -n "${onboarding_key}" \
| od -tx1 -An -v \
| tr -d ' ' \
| tr -d '\n' )"
$ base64_token=$(printf '%s' "${certificate_req}" | \
openssl dgst -sha256 -binary -mac HMAC -macopt "hexkey:${hex_encoded_onboarding_key}" | \
base64 | tr -d '\n')
$ auth_req=$(jq -n -c -j \
--arg token "${base64_token}" \
--arg req "${base64_certificate_req}" \
'{"token":$token,"request":$req}')
$ echo "$auth_req" > example_authsign_request.json Send request to the self-signed CA$ curl -k -X POST -d @example_authsign_request.json \
-H "Content-Type: application/json" \
"https://self.signed.ca.com:8088/api/v1/cfssl/authsign" \
| jq -r '.result.certificate' > example.crt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@kisom @anniephan Following this issue- #460 , I'm unable to generate a valid authsign request, and keep getting the 'invalid token' response: {"success":false,"result":null,"errors":[{"code":400,"message":"invalid token"}],"messages":[]} .
I attempted to write a java program that creates an authsign request: I used the auth test config for the cfssl server, and the code:
And then used the printed token and request for authsign request, and got "invalid token" for different signReq requests- the signReq is String loaded from file:
{
"request": "-----BEGIN CERTIFICATE REQUEST----- ... -----END CERTIFICATE REQUEST-----\n",
"profile": "CA"
}
@krish7919 In addition, as mentioned- the testdata does not work with the API.
Can someone suggest what is not correct in my authsign request generation? Or reference to an example of generating json for an authsign request?
Thanks!
The text was updated successfully, but these errors were encountered: