Comments (6)
Is there a reason you have to pass the value directly to jose
? Because you could trivially pre-process the invalid value to convert it (remove '=', replace two characters).
from jose.
I'm thinking something like this:
$ echo 'ix6oO88/Qid+iPbREThqOw==' | sed -e 's|\+|-|g' -e 's|/|_|g' -e 's|=||g'
ix6oO88_Qid-iPbREThqOw
from jose.
I'm using libjose but that is essentially what I'm doing right now, I just figured I'd ask whether it's worth supporting in jose's b64 encode/decode functionality even if it isn't strictly within the JWK standard.
from jose.
I won't say no, because I suspect there are other bad producers out there. Implementations of standards should generally be liberal in what they accept and strict in what they produce. How invasive is the patch?
from jose.
The diff I've been using is:
diff --git a/lib/b64.c b/lib/b64.c
index 6223089..70f6e3a 100644
--- a/lib/b64.c
+++ b/lib/b64.c
@@ -185,11 +185,15 @@ jose_b64_dec(const json_t *i, void *o, size_t ol)
if (json_unpack((json_t *) i, "s%", &b64, &len) < 0)
return SIZE_MAX;
-
- if (!o)
- return b64_dlen(len);
-
- return jose_b64_dec_buf(b64, len, o, ol);
+ size_t padding = 0;
+ for (size_t idx = 0; idx < len; idx++) {
+ if (b64[idx] == '=')
+ padding++;
+ }
+ if (!o) {
+ return b64_dlen(len - padding);
+ }
+ return jose_b64_dec_buf(b64, len - padding, o, ol);
}
jose_io_t *
@@ -231,8 +235,24 @@ jose_b64_dec_buf(const void *i, size_t il, void *o, size_t ol)
for (size_t io = 0; io < il; io++) {
uint8_t v = 0;
-
- for (const char c = e[io]; v < len && c != map[v]; v++)
+ bool skip = false;
+
+ for (const char c = e[io]; v < len && c != map[v]; v++) {
+ if (c == '+') {
+ v=62;
+ break;
+ }
+ if (c == '/') {
+ v=63;
+ break;
+ }
+ if (c == '=') {
+ skip = true;
+ break;
+ }
+ continue;
+ }
+ if (skip)
continue;
if (v >= len)
--
I imagine we'd probably want to massage this a bit ensure the input encoding doesn't contain a mix of both b64/b64 urlsafe as this patch would happily process a broken mixture.
from jose.
I opened up a PR, I figure we could continue discussion there.
Closing.
from jose.
Related Issues (20)
- CI Github Actions: include compilation in FreeBSD HOT 1
- [minor] Replace usage of which
- [minor] Possibly probe for jq in meson.build HOT 1
- Consider increasing test timeouts
- [Question] How to correctly verify JWS for OIDC?
- [Question] How to use the library with a (software) HSM?
- 11: test suite is failing HOT 11
- Entering password (-p) in scripts HOT 4
- Dual license with MIT?
- Release v12
- Does not link against OpenSSL 3 HOT 3
- Fedora rawhide container failing due to issues on dnf.conf format HOT 2
- Github actions should be migrated so that version v3 is used
- Decrypt Error with Open SSL 3 HOT 4
- OSX build on Travis-ci is failing HOT 5
- `jose enc` generates out-of-spec JWE HOT 2
- The default Thumbprints digest is SHA-1, even though RFC 7638 recommends at least SHA256 HOT 8
- Please consider atomic --output to a file HOT 1
- Migrate CI from travis HOT 6
- Provide infra for JOSE to dump logs at different levels
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jose.