aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2024-02-01 23:19:49 +0100
committerChristian Grothoff <christian@grothoff.org>2024-02-01 23:19:49 +0100
commitf0a05b8694fc6c65a6643e62ae309e48399d7066 (patch)
tree6f287c5b34fcc42ae845ca5ca0649642b701af93 /src/util
parent37bfb3da42186329f9cf4fa35dabc3fa5b5a2258 (diff)
add new TOTP-specfic JSON parsers
Diffstat (limited to 'src/util')
-rw-r--r--src/util/Makefile.am2
-rw-r--r--src/util/crypto_confirmation.c41
2 files changed, 21 insertions, 22 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index 478f75cfe..914ddfdf1 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -120,7 +120,7 @@ libtalerutil_la_LIBADD = \
-lm
libtalerutil_la_LDFLAGS = \
- -version-info 1:0:0 \
+ -version-info 2:0:1 \
-no-undefined
diff --git a/src/util/crypto_confirmation.c b/src/util/crypto_confirmation.c
index f19fc4a3c..204c373da 100644
--- a/src/util/crypto_confirmation.c
+++ b/src/util/crypto_confirmation.c
@@ -112,20 +112,11 @@ compute_totp (struct GNUNET_TIME_Timestamp ts,
}
-/**
- * Compute RFC 3548 base32 decoding of @a val and write
- * result to @a udata.
- *
- * @param val value to decode
- * @param val_size number of bytes in @a val
- * @param key is the val in bits
- * @param key_len is the size of @a key
- */
-static int
-base32decode (const char *val,
- size_t val_size,
- void *key,
- size_t key_len)
+int
+TALER_rfc3548_base32decode (const char *val,
+ size_t val_size,
+ void *key,
+ size_t key_len)
{
/**
* 32 characters for decoding, using RFC 3548.
@@ -142,13 +133,21 @@ base32decode (const char *val,
if ((rpos < val_size) && (vbit < 8))
{
char c = val[rpos++];
- if (c == '=') // padding character
+
+ if (c == '=')
{
- break;
+ /* padding character */
+ if (rpos == val_size)
+ break; /* Ok, 1x '=' padding is allowed */
+ if ( ('=' == val[rpos]) &&
+ (rpos + 1 == val_size) )
+ break; /* Ok, 2x '=' padding is allowed */
+ return -1; /* invalid padding */
}
const char *p = strchr (decTable__, toupper (c));
if (! p)
- { // invalid character
+ {
+ /* invalid character */
return -1;
}
bits = (bits << 5) | (p - decTable__);
@@ -226,10 +225,10 @@ TALER_build_pos_confirmation (const char *pos_key,
return NULL;
key_len = pos_key_length * 5 / 8;
key = GNUNET_malloc (key_len);
- dret = base32decode (pos_key,
- pos_key_length,
- key,
- key_len);
+ dret = TALER_rfc3548_base32decode (pos_key,
+ pos_key_length,
+ key,
+ key_len);
if (-1 == dret)
{
GNUNET_free (key);