gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [gnunet] branch master updated: fix base64urlencode for JWT


From: gnunet
Subject: [GNUnet-SVN] [gnunet] branch master updated: fix base64urlencode for JWT to adhere to RFC4648
Date: Sat, 21 Jul 2018 10:10:26 +0200

This is an automated email from the git hooks/post-receive script.

martin-schanzenbach pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 51ace4c06 fix base64urlencode for JWT to adhere to RFC4648
51ace4c06 is described below

commit 51ace4c06634efe9fd7edbb39f91f754befccd5e
Author: Schanzenbach, Martin <address@hidden>
AuthorDate: Sat Jul 21 10:10:22 2018 +0200

    fix base64urlencode for JWT to adhere to RFC4648
---
 src/reclaim/jwt.c | 44 +++++++++++++++++++++++++++++---------------
 1 file changed, 29 insertions(+), 15 deletions(-)

diff --git a/src/reclaim/jwt.c b/src/reclaim/jwt.c
index d9c2447bc..9885bf467 100644
--- a/src/reclaim/jwt.c
+++ b/src/reclaim/jwt.c
@@ -54,6 +54,32 @@ create_jwt_header(void)
   return json_str;
 }
 
+static void
+replace_char(char* str, char find, char replace){
+  char *current_pos = strchr(str,find);
+  while (current_pos){
+    *current_pos = replace;
+    current_pos = strchr(current_pos,find);
+  }
+}
+
+//RFC4648
+static void
+fix_base64(char* str) {
+  char *padding;
+  //First, remove trailing padding '='
+  padding = strtok(str, "=");
+  while (NULL != padding)
+    padding = strtok(NULL, "=");
+
+  //Replace + with -
+  replace_char (str, '+', '-');
+
+  //Replace / with _
+  replace_char (str, '/', '_');
+
+}
+
 /**
  * Create a JWT from attributes
  *
@@ -73,7 +99,6 @@ jwt_create_from_list (const struct 
GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
   char* audience;
   char* subject;
   char* header;
-  char* padding;
   char* body_str;
   char* result;
   char* header_base64;
@@ -121,19 +146,12 @@ jwt_create_from_list (const struct 
GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
   GNUNET_STRINGS_base64_encode (header,
                                 strlen (header),
                                 &header_base64);
-  //Remove GNUNET padding of base64
-  padding = strtok(header_base64, "=");
-  while (NULL != padding)
-    padding = strtok(NULL, "=");
+  fix_base64(header_base64);
 
   GNUNET_STRINGS_base64_encode (body_str,
                                 strlen (body_str),
                                 &body_base64);
-
-  //Remove GNUNET padding of base64
-  padding = strtok(body_base64, "=");
-  while (NULL != padding)
-    padding = strtok(NULL, "=");
+  fix_base64(body_base64);
 
   GNUNET_free (subject);
   GNUNET_free (audience);
@@ -147,11 +165,7 @@ jwt_create_from_list (const struct 
GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
   GNUNET_STRINGS_base64_encode ((const char*)&signature,
                                 sizeof (struct GNUNET_HashCode),
                                 &signature_base64);
-  
-  //Remove GNUNET padding of base64
-  padding = strtok(signature_base64, "=");
-  while (NULL != padding)
-    padding = strtok(NULL, "=");
+  fix_base64(signature_base64);
 
   GNUNET_asprintf (&result, "%s.%s.%s",
                    header_base64, body_base64, signature_base64);

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]