File tree Expand file tree Collapse file tree 6 files changed +73
-319
lines changed Expand file tree Collapse file tree 6 files changed +73
-319
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ CFLAGS += -I $(OPENSSL) -g -std=gnu99 -O3
77LDFLAGS += $(OPENSSL_LIB ) -lcrypto -lpthread
88
99NAME = jwtcrack
10- SRCS = main.c base64 .c
10+ SRCS = main.c base64url .c
1111OBJS = $(SRCS:.c=.o )
1212
1313all : $(NAME )
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ #include <stdlib.h>
2+ #include <string.h>
3+ #include <openssl/evp.h>
4+
5+ // Convert base64url to base64
6+ // Fix b64 alignement
7+ // Replace '-' by '+' and '_' by '/'
8+ static unsigned char * base64url_to_base64 (const unsigned char * base64 ) {
9+ size_t base64len = strlen (base64 );
10+ // \0 + possible padding
11+ unsigned char * nbase64 = malloc (base64len + 3 );
12+
13+ memset (nbase64 , 0 , base64len + 3 );
14+ strcat (nbase64 , base64 );
15+
16+ // Fix b64 alignement
17+ while (base64len % 4 != 0 ) {
18+ nbase64 [base64len ++ ] = '=' ;
19+ }
20+ for (int i = 0 ; i < base64len ; ++ i ) {
21+ if (nbase64 [i ] == '-' )
22+ nbase64 [i ] = '+' ;
23+ if (nbase64 [i ] == '_' )
24+ nbase64 [i ] = '/' ;
25+ }
26+ return nbase64 ;
27+ }
28+
29+ int base64url_decode (const unsigned char * in , unsigned char * * out )
30+ {
31+ size_t inlen , outlen ;
32+
33+ unsigned char * outbuf ;
34+ unsigned char * base64 = base64url_to_base64 (in );
35+
36+ inlen = strlen (base64 );
37+ outlen = (inlen / 4 ) * 3 ;
38+ outbuf = malloc (outlen );
39+ if (outbuf == NULL ) {
40+ goto err ;
41+ }
42+
43+ outlen = EVP_DecodeBlock (outbuf , (unsigned char * )base64 , inlen );
44+ if (outlen < 0 ) {
45+ goto err ;
46+ }
47+
48+ * out = outbuf ;
49+ free (base64 );
50+ return outlen ;
51+ err :
52+ free (base64 );
53+ free (outbuf );
54+ return -1 ;
55+ }
Original file line number Diff line number Diff line change 1+ #ifndef _BASE64_H_
2+ #define _BASE64_H_
3+
4+ #ifdef __cplusplus
5+ extern "C" {
6+ #endif
7+
8+ int base64url_decode (const unsigned char * in , unsigned char * * out );
9+
10+ #ifdef __cplusplus
11+ }
12+ #endif
13+
14+ #endif //_BASE64_H_
You can’t perform that action at this time.
0 commit comments