[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] 01/02: worked on assembler cli command 'answer'
From: |
gnunet |
Subject: |
[taler-anastasis] 01/02: worked on assembler cli command 'answer' |
Date: |
Wed, 17 Jun 2020 12:47:30 +0200 |
This is an automated email from the git hooks/post-receive script.
dennis-neufeld pushed a commit to branch master
in repository anastasis.
commit 7efae46add5319c1a794f9f8a7d1deab34754321
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Wed Jun 17 09:44:46 2020 +0000
worked on assembler cli command 'answer'
---
src/cli/anastasis-cli-assembler.c | 124 +++++++++++++++++++++-----------------
src/cli/anastasis-cli-splitter.c | 17 +++---
src/include/anastasis.h | 4 ++
src/lib/anastasis.c | 55 ++++++++++++++---
src/lib/test_anastasis_api.conf | 4 +-
src/util/anastasis_crypto.c | 10 +++
6 files changed, 141 insertions(+), 73 deletions(-)
diff --git a/src/cli/anastasis-cli-assembler.c
b/src/cli/anastasis-cli-assembler.c
index eff360a..794c5fb 100644
--- a/src/cli/anastasis-cli-assembler.c
+++ b/src/cli/anastasis-cli-assembler.c
@@ -175,10 +175,60 @@ struct RecoverSecretState
* The /salt GET operation handle.
*/
struct ANASTASIS_SaltOperation *so;
+};
+/**
+ * State for a "challenge answer" CMD.
+ */
+struct ChallengeState
+{
+ /**
+ * Reference to the challenge we are solving
+ */
+ struct ANASTASIS_Challenge *c;
+
+ /**
+ * Expected status code.
+ */
+ unsigned int http_status;
+
+ /**
+ * Answer to the challenge we are solving
+ */
+ const void *answer;
+
+ /**
+ * Size of the answer we are solving
+ */
+ size_t answer_size;
+
+ /**
+ * Referenece to the recovery process
+ */
+ const char *challenge_ref;
+
+ /**
+ * Index of the challenge we are solving
+ */
+ unsigned int challenge_index;
};
+static void
+challenge_answer_cb (void *af_cls,
+ enum TALER_ErrorCode ec)
+{
+ struct ChallengeState *cs = af_cls;
+ if (ec != MHD_HTTP_OK)
+ {
+ printf ("Failed truth#%u\n", cs->challenge_index);
+ return;
+ }
+ printf ("Success truth#%u\n", cs->challenge_index);
+ challenges[cs->challenge_index].solved = 1;
+}
+
+
/**
* @brief Read the character from stdin and activate the selected task
*
@@ -319,6 +369,7 @@ read_keyboard_command (void *cls)
buffer,
strlen ("answer")))
{
+ struct ChallengeState *cs = GNUNET_new (struct ChallengeState);
char *token_start = &buffer[strlen ("answer ")];
char *token = strtok (token_start, " ");
@@ -334,6 +385,10 @@ read_keyboard_command (void *cls)
}
truth_index = (int) token[strlen ("truth#")] - 48;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "At %s:%d truth index is %u\n", __FILE__, __LINE__,
+ truth_index);
+
if (0 == strcmp (challenges[truth_index].method, "question"))
token = strtok (NULL, "\"");
@@ -344,19 +399,19 @@ read_keyboard_command (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"At %s:%d challenge answer is %s\n", __FILE__, __LINE__,
challenge_answer);
- struct GNUNET_HashCode hash_answer;
- GNUNET_CRYPTO_hash (challenge_answer,
- strlen (challenge_answer),
- &hash_answer);
- /**
+ cs->http_status = MHD_HTTP_OK;
+ cs->answer = challenge_answer;
+ cs->answer_size = strlen (challenge_answer);
+ cs->challenge_index = truth_index;
+
ANASTASIS_challenge_answer (ctx,
challenges[truth_index].challenge,
- &hash_answer,
- sizeof (struct GNUNET_HashCode),
- challenge_answer_cb,
+ cs->answer,
+ cs->answer_size,
+ &challenge_answer_cb,
cs);
- */
+
start_read_keyboard ();
GNUNET_free (buffer);
buffer = NULL;
@@ -496,63 +551,22 @@ policy_lookup_cb (void *cls,
return;
}
+
static void
core_secret_cb (void *cls,
const void *secret,
size_t secret_size)
{
- // FIXME
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"At %s:%d arrived at core secret cb \n", __FILE__, __LINE__);
struct RecoverSecretState *rss = cls;
+ printf ("Secret was: \"%s\" Size: %lu b\n",
+ (char *) secret,
+ secret_size);
+
return;
}
-/**
- * State for a "challenge answer" CMD.
- */
-struct ChallengeState
-{
- /**
- * The interpreter state.
- */
- struct TALER_TESTING_Interpreter *is;
- /**
- * Reference to the challenge we are solving
- */
- struct ANASTASIS_Challenge *c;
- /**
- * Expected status code.
- */
- unsigned int http_status;
- /**
- * Answer to the challenge we are solving
- */
- const void *answer;
- /**
- * Size of the answer we are solving
- */
- size_t answer_size;
- /**
- * Referenece to the recovery process
- */
- const char *challenge_ref;
- /**
- * Index of the challenge we are solving
- */
- unsigned int challenge_index;
-};
-
-static void
-challenge_answer_cb (void *af_cls,
- enum TALER_ErrorCode ec)
-{
- struct ChallengeState *cs = af_cls;
- if (ec != MHD_HTTP_OK)
- {
- GNUNET_break (0);
- }
-}
/**
* Function called with the results of a #ANASTASIS_salt().
diff --git a/src/cli/anastasis-cli-splitter.c b/src/cli/anastasis-cli-splitter.c
index ab8c7fe..0fa7b7e 100644
--- a/src/cli/anastasis-cli-splitter.c
+++ b/src/cli/anastasis-cli-splitter.c
@@ -488,7 +488,7 @@ secret_share_result_cb (void *cls,
return;
}
}
- printf ("Thank you for using Anastasis");
+ printf ("Thank you for using Anastasis\n");
keyboard_task = NULL;
start_read_keyboard ();
return;
@@ -871,12 +871,8 @@ read_keyboard_command (void *cls)
tus->secret_answer);
tus->instructions = tus->secret_question;
tus->mime_type = "text/plain";
- struct GNUNET_HashCode truth_data;
- GNUNET_CRYPTO_hash (tus->secret_answer,
- strlen (tus->secret_answer),
- &truth_data);
- tus->truth_data = &truth_data;
- tus->truth_data_size = sizeof (truth_data);
+ tus->truth_data = tus->secret_answer;
+ tus->truth_data_size = strlen (tus->secret_answer);
}
if (0 == strcmp ("sms", tus->method))
{
@@ -1093,11 +1089,16 @@ read_keyboard_command (void *cls)
char *token = strtok (token_start, "\"");
sss->core_secret = GNUNET_malloc (strlen (token) + 1);
sss->core_secret_size = strlen (token) + 1;
- GNUNET_strlcpy (sss->core_secret,
+ GNUNET_strlcpy ((char *) sss->core_secret,
token,
sss->core_secret_size);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "At %s:%d core secret is %s\n", __FILE__, __LINE__,
+ (char *) sss->core_secret);
sss->http_status = MHD_HTTP_NO_CONTENT;
}
+
+ // FIXME: avoid uploading recovery document like this
if (characters == strlen ("publish"))
{
sss->core_secret = "test_payment";
diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index f57fde7..ef6702d 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -88,6 +88,10 @@ struct ANASTASIS_RecoveryInformation
unsigned int version; // actual version obtained
+ void *enc_core_secret;
+
+ size_t enc_core_secret_size;
+
};
/**
diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index ade28ba..431876c 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -384,7 +384,7 @@ keyshare_lookup_cb (void *cls,
{
key_shares[l] = *c->recovery->solved_challenges[m].key_share;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "At %s:%d keyshare added %s-%llu at position %x b\n",
+ "At %s:%d keyshare added %s-%llu b at position %x\n",
__FILE__, __LINE__,
TALER_B2S (&key_shares[l]),
(unsigned long long) sizeof (c->key_share),
@@ -403,12 +403,27 @@ keyshare_lookup_cb (void *cls,
TALER_B2S (&policy_key),
(unsigned long long) sizeof (policy_key));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "At %s:%d encrypted core secret is %s-%llu b\n", __FILE__,
+ __LINE__,
+ TALER_b2s (c->recovery->ri->enc_core_secret,
+ c->recovery->ri->enc_core_secret_size),
+ (unsigned long long) c->recovery->ri->enc_core_secret_size);
+
ANASTASIS_CRYPTO_core_secret_recover (&c->recovery->ri->dps[success].emk,
policy_key,
- c->recovery->enc_core_secret,
- c->recovery->enc_core_secret_size,
+ c->recovery->ri->enc_core_secret,
+
c->recovery->ri->enc_core_secret_size,
&core_secret,
&core_secret_size);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "At %s:%d decrypted core secret is %s-%llu b\n", __FILE__,
+ __LINE__,
+ TALER_b2s (core_secret,
+ core_secret_size),
+ (unsigned long long) core_secret_size);
+
c->recovery->csc (c->recovery->csc_cls,
core_secret,
core_secret_size);
@@ -437,7 +452,9 @@ ANASTASIS_challenge_answer (struct GNUNET_CURL_Context *ctx,
c->af = af;
c->ctx = ctx;
c->af_cls = af_cls;
-
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "At %s:%d challenge answer is %s\n", __FILE__, __LINE__,
+ (char *) answer);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"At %s:%d challenge %s-%llu is solved with url %s \n", __FILE__,
@@ -579,7 +596,7 @@ policy_lookup_cb (void *cls,
"Recovery_document after json_loadb %s\n",
json_dumps (recovery_document, JSON_COMPACT));
-
+ const char *enc_core_secret;
GNUNET_assert (0 ==
json_unpack ((json_t *) recovery_document,
"{s:o," /* policies */
@@ -587,7 +604,7 @@ policy_lookup_cb (void *cls,
" s:o}", /* encrypted core secret */
"policies", &dec_policies,
"escrow_methods", &esc_methods,
- "core_secret", &r->enc_core_secret));
+ "core_secret", &enc_core_secret));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -601,6 +618,18 @@ policy_lookup_cb (void *cls,
r->ri->dps_len = json_array_size (dec_policies);
r->ri->dps = GNUNET_new_array (r->ri->dps_len, struct
ANASTASIS_DecryptionPolicy);
+ r->ri->enc_core_secret_size = strlen (enc_core_secret);
+ GNUNET_STRINGS_string_to_data (enc_core_secret,
+ strlen (enc_core_secret),
+ r->ri->enc_core_secret,
+ r->ri->enc_core_secret_size);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "At %s:%d encrypted core secret is %s-%llu b\n", __FILE__,
+ __LINE__,
+ TALER_b2s (r->ri->enc_core_secret,
+ r->ri->enc_core_secret_size),
+ (unsigned long long) r->ri->enc_core_secret_size);
+
r->solved_challenges = GNUNET_new_array (r->ri->cs_len,
struct ANASTASIS_Challenge);
@@ -1668,8 +1697,6 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
unsigned int pss_length = ANASTASIS_get_num_urls (policies,
policies_len);
struct PolicyStoreState *pss[pss_length];
- // struct GNUNET_HashCode current_etags[pss_length];
- // enum TALER_ErrorCode ecs[pss_length];
struct ANASTASIS_CRYPTO_EncryptedMasterKeyP
encrypted_master_keys[policies_len];
struct ANASTASIS_CRYPTO_PolicyKeyP policy_keys[policies_len];
@@ -1716,12 +1743,24 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
policy_keys[i] = policies[i]->policy_key;
}
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "At %s:%d core secret is %s-%llu b\n", __FILE__, __LINE__,
+ TALER_b2s (core_secret,
+ core_secret_size),
+ (unsigned long long) core_secret_size);
+
ANASTASIS_CRYPTO_core_secret_encrypt (policy_keys,
policies_len,
core_secret,
core_secret_size,
&encrypted_core_secret,
encrypted_master_keys);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "At %s:%d encrypted core secret is %s-%llu b\n", __FILE__,
+ __LINE__,
+ TALER_b2s (encrypted_core_secret,
+ core_secret_size),
+ (unsigned long long) core_secret_size);
dec_policies = json_array ();
esc_methods = json_array ();
diff --git a/src/lib/test_anastasis_api.conf b/src/lib/test_anastasis_api.conf
index 560b005..32935e7 100644
--- a/src/lib/test_anastasis_api.conf
+++ b/src/lib/test_anastasis_api.conf
@@ -37,8 +37,8 @@ DB = postgres
PAYMENT_BACKEND_URL = http://localhost:8080/
# Annual fee we charge.
-ANNUAL_FEE = EUR:4.99
-#ANNUAL_FEE = EUR:0
+#ANNUAL_FEE = EUR:4.99
+ANNUAL_FEE = EUR:0
# Cost of authentication by question
QUESTION_COST = EUR:0
diff --git a/src/util/anastasis_crypto.c b/src/util/anastasis_crypto.c
index 6a8ab14..7626987 100644
--- a/src/util/anastasis_crypto.c
+++ b/src/util/anastasis_crypto.c
@@ -716,11 +716,21 @@ ANASTASIS_CRYPTO_core_secret_recover (
GNUNET_CRYPTO_hash_to_aes_key (&master_key,
&core_sk,
&core_iv);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "At %s:%d encrypted core secret is %s-%llu b\n", __FILE__,
+ __LINE__,
+ TALER_b2s (encrypted_core_secret, encrypted_core_secret_size),
+ (unsigned long long) encrypted_core_secret_size);
*core_secret_size = GNUNET_CRYPTO_symmetric_decrypt (encrypted_core_secret,
encrypted_core_secret_size,
&core_sk,
&core_iv,
*core_secret);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "At %s:%d decrypted core secret is %s-%llu b\n", __FILE__,
+ __LINE__,
+ TALER_b2s (*core_secret, *core_secret_size),
+ (unsigned long long) *core_secret_size);
GNUNET_assert (GNUNET_SYSERR != *core_secret_size);
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.