Skip to content

Commit

Permalink
openssl::signature_create() -> digest() + PKI.sign()
Browse files Browse the repository at this point in the history
  • Loading branch information
jonkeane committed Mar 18, 2024
1 parent e6be95b commit 17f2eff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Imports:
jsonlite,
lifecycle,
openssl (>= 2.0.0),
PKI,
packrat (>= 0.6),
renv (>= 1.0.0),
rlang (>= 1.0.0),
Expand Down
10 changes: 8 additions & 2 deletions R/http.R
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,14 @@ signatureHeaders <- function(authInfo, method, path, file = NULL) {
der = TRUE
)

# OpenSSL defaults to sha1 hash function (which is what we need)
rawsig <- openssl::signature_create(charToRaw(canonicalRequest), key = private_key)
# convert key into PKI format for signing, note this only accepts RSA, but
# that's what rsconnect generates already
pki_key <- PKI::PKI.load.key(strsplit(openssl::write_pem(private_key), "\n")[[1]], format = "PEM")

# use sha1 digest and then sign. digest and PKI avoid using system openssl which
# can be problematic in strict FIPS environments
digested <- digest::digest(charToRaw(canonicalRequest), "sha1", serialize = FALSE, raw = TRUE)
rawsig <- PKI::PKI.sign(key = pki_key, digest = digested)
signature <- openssl::base64_encode(rawsig)
} else {
stop("can't sign request: no shared secret or private key")
Expand Down

0 comments on commit 17f2eff

Please sign in to comment.