Skip to content

Commit 5c41991

Browse files
authored
Merge pull request #1577 from bigomics/devel-two-cookies
fix: different encryption key for email and cookie
2 parents f9eb5b2 + 9e4636d commit 5c41991

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

components/modules/AuthenticationModule.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ LoginCodeAuthenticationModule <- function(id,
950950
if (!is.null(query_email) & !is.null(decrypted_cookie)) {
951951
if (opt$ENCRYPTED_EMAIL) {
952952
query_email_nonce <- shiny::isolate(shiny::getQueryString()$email_nonce)
953-
query_email <- decrypt_cookie(query_email, query_email_nonce)
953+
query_email <- decrypt_cookie(query_email, query_email_nonce, key_file = "cookie.txt")
954954
if (is.null(query_email)) {
955955
query_email <- ""
956956
}
@@ -1106,7 +1106,7 @@ LoginCodeAuthenticationModule <- function(id,
11061106
query_email <- shiny::getQueryString()$email
11071107
if (opt$ENCRYPTED_EMAIL) {
11081108
query_email_nonce <- shiny::getQueryString()$email_nonce
1109-
query_email <- decrypt_cookie(query_email, query_email_nonce)
1109+
query_email <- decrypt_cookie(query_email, query_email_nonce, key_file = "cookie.txt")
11101110
}
11111111
query_email
11121112
})

components/modules/CookiesModule.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ extract_cookie_value <- function(session, cookie_name) {
1414
}
1515

1616
# Decrypt cookie
17-
decrypt_cookie <- function(cookie, nonce) {
18-
key_base64 <- readLines(file.path(OPG, "etc/keys/cookie.txt"))[1]
17+
decrypt_cookie <- function(cookie, nonce, key_file = "cookie.txt") {
18+
key_base64 <- readLines(file.path(OPG, "etc/keys", key_file))[1]
1919
email_nonce_raw <- tryCatch(
2020
{
2121
sodium::hex2bin(nonce)
@@ -54,7 +54,7 @@ get_and_decrypt_cookie <- function(session) {
5454
cookie <- extract_cookie_value(session, "persistentOPG")
5555
nonce <- extract_cookie_value(session, "persistentOPG_nonce")
5656
if (!is.null(cookie) & !is.null(nonce)) {
57-
decrypted_cookie <- decrypt_cookie(cookie, nonce)
57+
decrypted_cookie <- decrypt_cookie(cookie, nonce, key_file = "cookie2.txt")
5858
return(decrypted_cookie)
5959
} else {
6060
return(NULL)
@@ -63,7 +63,7 @@ get_and_decrypt_cookie <- function(session) {
6363

6464
# Save encrypted session cookie
6565
save_session_cookie <- function(session, cred) {
66-
key_base64 <- readLines(paste0(OPG, "/etc/keys/cookie.txt"))[1]
66+
key_base64 <- readLines(paste0(OPG, "/etc/keys/cookie2.txt"))[1]
6767
passkey <- sodium::sha256(charToRaw(key_base64))
6868
plaintext <- isolate(cred$email)
6969
plaintext.raw <- serialize(plaintext, NULL)

etc/keys/cookie2.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
++E+d7OhM1UueAPOhAYEukRXIzAQvD+gkN8uWwNN+EiY=

0 commit comments

Comments
 (0)