Skip to content

Commit

Permalink
Switch to Signature Canonicalization version 2
Browse files Browse the repository at this point in the history
  • Loading branch information
ysyrota authored and AaronAtDuo committed Aug 20, 2024
1 parent 91513cd commit 14bf169
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lib/https.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,14 +660,18 @@ https_send(struct https_request *req, const char *method, const char *uri,
BIO *b64;
HMAC_CTX *hmac;
unsigned char MD[SHA512_DIGEST_LENGTH];
char *qs, *p;
char *qs, *p, date[128];
int i, n, is_get;
time_t t;

req->done = 0;

t = time(NULL);
strftime(date, sizeof date, "%a, %d %b %Y %T %z", localtime(&t));

/* Generate query string and canonical request to sign */
if ((qs = _argv_to_qs(argc, argv)) == NULL ||
(asprintf(&p, "%s\n%s\n%s\n%s", method, req->host, uri, qs)) < 0) {
(asprintf(&p, "%s\n%s\n%s\n%s\n%s", date, method, req->host, uri, qs)) < 0) {
free(qs);
ctx.errstr = strerror(errno);
return (HTTPS_ERR_LIB);
Expand All @@ -688,6 +692,7 @@ https_send(struct https_request *req, const char *method, const char *uri,
"User-Agent: %s\r\n",
useragent);
/* Add signature */
BIO_printf(req->cbio, "X-Duo-Date: %s\r\n", date);
BIO_puts(req->cbio, "Authorization: Basic ");

if ((hmac = HMAC_CTX_new()) == NULL) {
Expand Down
8 changes: 7 additions & 1 deletion tests/mockduo.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ def _verify_sig(self):
if ikey != IKEY:
return False

canon = [self.method, self.headers["Host"].split(":")[0].lower(), self.path]
# first look for x-duo-date header
datestring = self.headers.get("x-duo-date")
if datestring is None:
# if it doesn't exist, try looking for Date header
datestring = self.headers.get("Date")

canon = [datestring, self.method, self.headers["Host"].split(":")[0].lower(), self.path]
l = []
for k in sorted(self.args.keys()):
l.append(
Expand Down

0 comments on commit 14bf169

Please sign in to comment.