Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Add openssl example for registration hmac
Browse files Browse the repository at this point in the history
  • Loading branch information
neodon committed Aug 10, 2022
1 parent 51c01d4 commit 04b56b5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/13472.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add openssl example for generating registration hmac digest.
21 changes: 19 additions & 2 deletions docs/admin_api/register_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,24 @@ As an example:
The MAC is the hex digest output of the HMAC-SHA1 algorithm, with the key being
the shared secret and the content being the nonce, user, password, either the
string "admin" or "notadmin", and optionally the user_type
each separated by NULs. For an example of generation in Python:
each separated by NULs.

Here is an easy way to generate the HMAC digest if you have Bash and OpenSSL:

```bash
# Update these values and then paste this code block into a bash terminal
nonce='thisisanonce'
username='pepper_roni'
password='pizza'
admin='admin'
secret='shared_secret'

printf '%s\0%s\0%s\0%s' "$nonce" "$username" "$password" "$admin" |
openssl sha1 -hmac "$secret" |
awk '{print $2}'
```

For an example of generation in Python:

```python
import hmac, hashlib
Expand All @@ -70,4 +87,4 @@ def generate_mac(nonce, user, password, admin=False, user_type=None):
mac.update(user_type.encode('utf8'))

return mac.hexdigest()
```
```

0 comments on commit 04b56b5

Please sign in to comment.