Skip to content

Commit dc406d9

Browse files
rgee0alexellis
authored andcommitted
Update Lab11 to be more reflective of code
Issue #165 highlighted that the code block was using pseudo code which made it relate less to the codebase than one might expect. This change uses a code snippet from the sample file. It also adjusts some of the code / variabe names in an attempt to make it more intuitive to users. Signed-off-by: Richard Gee <[email protected]>
1 parent bc59033 commit dc406d9

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

hmac-protected/hmac-protected/handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ def getHash(hash):
1818

1919
def handle(req):
2020
# We receive the hashed message in form of a header
21-
messageMAC = os.getenv("Http_Hmac")
21+
receivedHMAC = os.getenv("Http_Hmac")
2222

2323
# Read secret from inside the container
2424
with open("/var/openfaas/secrets/payload-secret","r") as secretContent:
25-
payloadSecret = secretContent.read()
25+
payloadKey = secretContent.read()
2626

2727
# Function to validate the HMAC
28-
if validateHMAC(req, payloadSecret, messageMAC):
28+
if validateHMAC(req, payloadKey, receivedHMAC):
2929
return "Successfully validated: " + req
3030
return "HMAC validation failed."

lab11.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This way we close our functions from being invoked with invalid or even dangerou
3434

3535
## Using HMAC
3636

37-
We will use the `--sign` flag provided by faas-cli to send a header containing the hashed message created with the shared key which we send with the `--key` flag.
37+
We will use the `--sign` flag provided by faas-cli to include a header, which contains the hashed message created using the shared key which we provide with the `--key` flag.
3838

3939
> Note: Both `--sign` and `--key` must be present.
4040
@@ -172,9 +172,10 @@ Here we compare the generated and received hashes:
172172
173173
```python
174174
...
175-
if hmacDigest == cleanHash:
176-
return True
177-
return False
175+
# Function to validate the HMAC
176+
if validateHMAC(req, payloadKey, receivedHMAC):
177+
return "Successfully validated: " + req
178+
return "HMAC validation failed."
178179
...
179180
```
180181

0 commit comments

Comments
 (0)