Make base64_decode relaxed mode less relaxed #365
No reviewers
Labels
No labels
bug
duplicate
enhancement
feature
help wanted
improve API
invalid
needs documentation
not-planned
rtfm
stale
support
wishlist
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-libtom/libtomcrypt!365
Loading…
Reference in a new issue
No description provided.
Delete branch "pr/base64-decode-less-relaxed"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Checklist
IMO the current super relaxed mode may be dangerous when you are decoding data from external sources (e.g. from a user request) because we are "able" to decode nearly any invalid input data. I am open to discussion what other characters should be ignored in relaxed mode.
I fully agree! ... and that's also what is said in RFC 4648 ...
But I also think that we shouldn't break existing code or at least give the possibility to enable the old behavior if required... so we've several options I guess...
base64_insane_decode()and fix the originalbase64_sane_decode()and keep the originala. globally via a global
b. globally via
base64_set_decode_sanity()c. on the API level via exporting the sanity parameter
d. at compile time
From the options above I prefer
base64_sane_decode()approach👍
base64_sane_decode()shall it beso we have now 3 possible values
enum(insane, relaxed, strict)where the defaultbase64_decode()isinsane:Dbase64_sane_decodeorbase64_relaxed_decode?I think
base64_sane_decode()is more appropriate asbase64_relaxed_decode()is basically lying becausebase64_decode()is more relaxed...@ -89,20 +95,29 @@ static int _base64_decode_internal(const char *in, unsigned long inlen,can you please add parentheses?
@ -118,7 +133,7 @@ static int _base64_decode_internal(const char *in, unsigned long inlen,here as well please
@sjaeckel please review again
👍
should we add the URL variants to the index?
@ -156,11 +171,25 @@ int base64_strict_decode(const char *in, unsigned long inlen,{Probably this (and the URL variant) comment should be changed?
@ -62,2 +71,4 @@{"\nvuiS\rPKIl8P\niR5O-rC4\tz9_xTQKZ0=\n", relaxed},{"vuiSPKIl8PiR5O-rC4z9_xTQK", invalid},};👍
@ -79,0 +106,4 @@DO(base64url_encode(tmp, l1, out, &l2));DO(do_compare_testvector(out, l2, url_cases[x].s, strlen(url_cases[x].s), "base64url_encode", x));}if(x == 1) {I already thought about it while writing the last base16 testcase... should we add this?
@ -79,0 +106,4 @@DO(base64url_encode(tmp, l1, out, &l2));DO(do_compare_testvector(out, l2, url_cases[x].s, strlen(url_cases[x].s), "base64url_encode", x));}if(x == 1) {Maybe, but perhaps as
SHOULD_FAIL(x, expected_retval)@ -156,11 +171,25 @@ int base64_strict_decode(const char *in, unsigned long inlen,{done
done
@ -79,0 +106,4 @@DO(base64url_encode(tmp, l1, out, &l2));DO(do_compare_testvector(out, l2, url_cases[x].s, strlen(url_cases[x].s), "base64url_encode", x));}if(x == 1) {I also thought about
EXPECT(x, e)but in my opinion that's another use-case.Most cases where we do negative tests shouldn't care about the error-code returned, it should just be ensured that the result is not OK.
:) well put!
Is it ok?