From d49cf1a8857cead4548858572bc619824142eceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Gon=C3=A7alves?= Date: Mon, 9 Oct 2023 23:24:42 +0200 Subject: [PATCH] Handle error responses from tsa by using local machine time. --- R/tsp.R | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/R/tsp.R b/R/tsp.R index dd19d59..93dbb9f 100644 --- a/R/tsp.R +++ b/R/tsp.R @@ -12,14 +12,21 @@ get_timestamp_secure <- function(tsq) { if(resp$status_code == 200L) { tsr <- PKI::ASN1.decode(resp$body) - ts <- PKI::ASN1.decode(PKI::ASN1.decode(PKI::ASN1.decode(tsr[[2]][[2]])[[3]][[2]]))[[5]] - ts <- as.POSIXct(rawToChar(ts), format = "%Y%m%d%H%M%SZ", tz="UTC") + if (tsr[[1]][[1]] == 0) { + # PKIStatus ::= INTEGER { granted (0), grantedWithMods (1), rejection (2), waiting (3), + # revocationWarning (4), revocationNotification (5) } + ts <- PKI::ASN1.decode(PKI::ASN1.decode(PKI::ASN1.decode(tsr[[2]][[2]])[[3]][[2]]))[[5]] + ts <- as.POSIXct(rawToChar(ts), format = "%Y%m%d%H%M%SZ", tz="UTC") - out <- list(ts = structure(strftime(ts, "%Y-%m-%dT%H:%M:%SZ", tz="UTC"), - unix_ts = as.integer(ts), - class = "pqcrypto_timestamp"), - tsr = structure(resp$body, - class = "pqcrypto_tsp_tsr")) + out <- list(ts = structure(strftime(ts, "%Y-%m-%dT%H:%M:%SZ", tz="UTC"), + unix_ts = as.integer(ts), + class = "pqcrypto_timestamp"), + tsr = structure(resp$body, + class = "pqcrypto_tsp_tsr")) + } else { + out <- list(ts = get_timestamp(), + tsr = NULL) + } } else { out <- list(ts = get_timestamp(), tsr = NULL)