- add signature to cred
authorSchanzenbach, Martin <mschanzenbach@posteo.de>
Mon, 5 Dec 2016 20:55:23 +0000 (21:55 +0100)
committerSchanzenbach, Martin <mschanzenbach@posteo.de>
Mon, 5 Dec 2016 20:55:23 +0000 (21:55 +0100)
src/credential/plugin_gnsrecord_credential.c
src/credential/test_credential_issue.sh

index 721e19fdb65a5b09ae22a3c56e37da9b26946776..f6aec9bccfd6a3ba6aa1c7b6d4237aa3ed970a4a 100644 (file)
@@ -77,6 +77,8 @@ credential_value_to_string (void *cls,
      char *cred_str;
      char *subject_pkey;
      char *issuer_pkey;
+     char *signature;
+     
      if (data_size < sizeof (struct GNUNET_CREDENTIAL_CredentialRecordData))
        return NULL; /* malformed */
      memcpy (&cred,
@@ -85,15 +87,18 @@ credential_value_to_string (void *cls,
      cdata = data;  
      subject_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred.subject_key);
      issuer_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred.issuer_key);
-
+     GNUNET_STRINGS_base64_encode ((char*)&cred.sig,
+                                   sizeof (struct GNUNET_CRYPTO_EcdsaSignature),
+                                   &signature);
      GNUNET_asprintf (&cred_str,
-                      "%s %s %s",
-                      subject_pkey,
+                      "%s.%s -> %s sig:%s",
                       issuer_pkey,
-                      &cdata[sizeof (cred)]);
+                      &cdata[sizeof (cred)],
+                      subject_pkey,
+                      signature);
      GNUNET_free (subject_pkey);
      GNUNET_free (issuer_pkey);
-
+     GNUNET_free (signature);
      return cred_str;
    }
    default:
@@ -135,12 +140,15 @@ credential_string_to_value (void *cls,
         char subject_pkey[enclen + 1];
         char issuer_pkey[enclen + 1];
         char name[253 + 1];
+        char signature[128]; //TODO max payload size
+        struct GNUNET_CRYPTO_EcdsaSignature *sig;
 
-        if (3 != SSCANF (s,
-                         "%52s %52s %253s",
-                         subject_pkey,
+        if (4 != SSCANF (s,
+                         "%52s.%253s -> %52s sig:%s",
                          issuer_pkey,
-                         name))
+                         name,
+                         subject_pkey,
+                         signature))
         {
           GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                       _("Unable to parse CRED record string `%s'\n"),
@@ -155,6 +163,11 @@ credential_string_to_value (void *cls,
         GNUNET_CRYPTO_ecdsa_public_key_from_string (issuer_pkey,
                                                     strlen (issuer_pkey),
                                                     &cred->issuer_key);
+        GNUNET_STRINGS_base64_decode (signature,
+                                      strlen (signature),
+                                      (char**)&sig);
+        cred->sig = *sig;
+        GNUNET_free (sig);
         GNUNET_memcpy (&cred[1],
                        name,
                        strlen (name));
index a78bde6ede0a2d896e28cade88ad8fc789b1b4aa..95eac2957147c0363480b402dd5b26ee40edc1dd 100755 (executable)
@@ -28,16 +28,9 @@ gnunet-identity -C testissuer -c test_credential_lookup.conf
 gnunet-identity -C testsubject -c test_credential_lookup.conf
 SUBJECT_KEY=$(gnunet-identity -d -c test_credential_lookup.conf | grep testsubject | awk '{print $3}')
 ISSUER_KEY=$(gnunet-identity -d -c test_credential_lookup.conf | grep testissuer | awk '{print $3}')
-EXPECTED="$SUBJECT_KEY $ISSUER_KEY $TEST_ATTR"
 #TODO1 Get credential and store it with subject (3)
-CRED=`$DO_TIMEOUT gnunet-credential --issue --ego=testissuer --subject=$SUBJECT_KEY --attribute=$TEST_ATTR -c test_credential_lookup.conf`
+$DO_TIMEOUT gnunet-credential --issue --ego=testissuer --subject=$SUBJECT_KEY --attribute=$TEST_ATTR -c test_credential_lookup.conf
+STATUS=$?
 
 gnunet-arm -e -c test_credential_lookup.conf
-
-if [ "$EXPECTED" == "$CRED" ]
-then
-  exit 0
-else
-  echo "FAIL: Failed to issue credential, got $CRED."
-  exit 1
-fi
+exit $STATUS