Skip to content
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

Switch to Signature Canonicalization version 2 #282

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading