[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] branch master updated: client library update and tests
From: |
gnunet |
Subject: |
[taler-anastasis] branch master updated: client library update and tests |
Date: |
Wed, 25 Nov 2020 15:48:36 +0100 |
This is an automated email from the git hooks/post-receive script.
ds-meister pushed a commit to branch master
in repository anastasis.
The following commit(s) were added to refs/heads/master by this push:
new c21a333 client library update and tests
c21a333 is described below
commit c21a3338d362ee19bd70d3dd6a5415eaddce0dc4
Author: Dominik Meister <dominik.meister@hotmail.ch>
AuthorDate: Wed Nov 25 15:48:26 2020 +0100
client library update and tests
---
src/include/anastasis.h | 40 ++--
src/include/anastasis_testing_lib.h | 9 +-
src/lib/Makefile.am | 1 +
src/lib/anastasis.c | 128 +++++++++++--
src/lib/test_anastasis.c | 39 +++-
src/lib/testing_api_cmd_challenge_run.c | 1 +
src/lib/testing_cmd_challenge_answer.c | 32 +++-
src/lib/testing_cmd_challenge_start.c | 325 ++++++++++++++++++++++++++++++++
8 files changed, 546 insertions(+), 29 deletions(-)
diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index 395c4ea..5541f4a 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -189,27 +189,45 @@ ANASTASIS_get_challenge (struct ANASTASIS_Challenge
*challenge,
* and a status code.
*
* @param cls handle to the request
- * @param order_url payment url is passed to the user (taler://pay/Foo)
- * @param ec Status code for the request e.g (truth ID unknown to provider)
+ * @param response_string response from the challenge start(instructions look
at email etc..)
+ * @param http_status Status code for the request
*/
typedef void
+(*ANASTASIS_ChallengeStartCallback)(void *cls,
+ const char *response_string,
+ unsigned int http_status);
+/**
+* Callback for a payment process for uploading a policy
+*
+* @param cls closure for the callback
+* @param taler_pay_url url for the payment (taler://pay/Foo)
+* @param server_url url of the server to pay for
+* @param ec status of the request
+*/
+typedef void
(*ANASTASIS_ChallengePaymentCallback)(void *cls,
- const char *order_url,
- enum TALER_ErrorCode ec);
+ const char *taler_pay_url,
+ const char *server_url,
+ unsigned int http_status);
/**
- * User decides which method is to be used, and wants to pay for the
authentication
- * this is only needed if the cost for the authentication is not zero. Opens a
Challenge Payment Callback
- * which passes back the payment information.
+ * User starts a challenge which reponds out of bounds (E-Mail, SMS, Postal..)
+ * If the challenge is zero cost, the challenge instructions will be sent
+ * to the client. If the challenge needs payment a payment link is sent
+ * to the client. After payment the challenge start method has to be
+ * called again with the same challenge reference.
*
- * @param challenge reference to the escrow challenge which is paid
+ * @param c reference to the escrow challenge which is started
* @param cc opens a ChallengePaymentCallback for the requested information
* @param cc_cls handle for the request
*/
void
-ANASTASIS_challenge_select_to_pay (struct ANASTASIS_Challenge *challenge,
- ANASTASIS_ChallengePaymentCallback cc,
- void *cc_cls);
+ANASTASIS_challenge_start (struct GNUNET_CURL_Context *ctx,
+ struct ANASTASIS_Challenge *c,
+ ANASTASIS_ChallengePaymentCallback cpc,
+ void *cpc_cls,
+ ANASTASIS_ChallengeStartCallback csc,
+ void *csc_cls);
/**
* Callback which passes back the recovery document and its possible policies.
Also passes
diff --git a/src/include/anastasis_testing_lib.h
b/src/include/anastasis_testing_lib.h
index 3ba7673..85334d5 100644
--- a/src/include/anastasis_testing_lib.h
+++ b/src/include/anastasis_testing_lib.h
@@ -472,6 +472,12 @@ ANASTASIS_TESTING_cmd_challenge_run (const char *label,
const char *upload_ref,
const char *payment_ref);
+struct TALER_TESTING_Command
+ANASTASIS_TESTING_cmd_challenge_start (const char *label,
+ unsigned int http_status,
+ const char *challenge_ref,
+ unsigned int challenge_index);
+
/**
* Obtain a salt from @a cmd.
*
@@ -783,6 +789,7 @@ ANASTASIS_TESTING_cmd_challenge_answer (const char *label,
unsigned int http_status,
const char *challenge_ref,
unsigned int challenge_index,
- const char *answer);
+ const char *answer,
+ unsigned int mode);
#endif
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 15f448e..c254cae 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -80,6 +80,7 @@ libanastasistesting_la_SOURCES = \
testing_cmd_secret_share.c \
testing_cmd_recover_secret.c \
testing_cmd_challenge_answer.c \
+ testing_cmd_challenge_start.c \
testing_trait_truth.c \
testing_trait_policy.c \
testing_trait_core_secret.c \
diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index 9484d6f..a9702d9 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -228,7 +228,27 @@ struct ANASTASIS_Challenge
* Cost for authentication
*/
struct TALER_Amount cost;
+ /**
+ * Passes back the payment information for the current challenge
+ */
+ ANASTASIS_ChallengePaymentCallback cpc;
+ /**
+ * Closure for the payment callback
+ */
+ void *cpc_cls;
+ /**
+ * The /truth GET operation handle.
+ */
+ struct ANASTASIS_ChallengeRunOperation *cro;
+ /**
+ * Sends back the status and the instructions of the challenge start
+ */
+ ANASTASIS_ChallengeStartCallback csc;
+ /**
+ * Closure for the Challenge Start
+ */
+ void *csc_cls;
/**
* Payment identifier.
*/
@@ -244,7 +264,7 @@ struct ANASTASIS_Challenge
*/
const char *payment_order_req;
- int payment_requested;
+ bool payment_requested;
};
/**
@@ -470,20 +490,106 @@ ANASTASIS_get_challenge (struct ANASTASIS_Challenge
*challenge,
/**
- * User decides which method is to be used, and wants to pay for the
authentication
- * this is only needed if the cost for the authentication is not zero. Opens a
Challenge Payment Callback
- * which passes back the payment information.
+ * Function called with the results of a #ANASTASIS_challenge_run().
*
- * @param challenge reference to the escrow challenge which is paid
- * @param cc opens a ChallengePaymentCallback for the requested information
- * @param cc_cls handle for the request
+ * @param cls closure
+ * @param http_status HTTP status of the request
+ * @param response_string payment request or instructions
*/
+static void
+challenge_run_cb (void *cls,
+ unsigned int http_status,
+ char *response_string)
+{
+ struct ANASTASIS_Challenge *c = cls;
+ c->cro = NULL;
+
+ if (http_status == MHD_HTTP_PAYMENT_REQUIRED)
+ {
+ const char *m;
+
+ if (0 != strncmp (response_string,
+ "taler://pay/http",
+ strlen ("taler://pay/http")))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Did not find `%s' in `%s'\n",
+ "/-/-/",
+ response_string);
+ /*FIXME ERROR*/
+ return;
+ }
+ m = strstr (response_string, "/-/-/");
+ if (NULL == m)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Did not find `%s' in `%s'\n",
+ "/-/-/",
+ response_string);
+ /*FIXME ERROR*/
+
+ /* NOTE: The above is a simplifying assumption for the
+ test-logic, hitting this code merely means that
+ the assumptions for the test (i.e. no instance) are
+ not satisfied, it is not inherently the case that
+ the above token must appear in the payment request!
+
+ So if you hit this, you might just want to modify
+ the code here to handle this better! */
+ return;
+ }
+ c->payment_order_id = GNUNET_strdup (&m[strlen ("/-/-/")]);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Order ID from Anastasis service is `%s'\n",
+ c->payment_order_id);
+ c->cpc (c->cpc_cls,
+ response_string,
+ c->url,
+ http_status);
+ return;
+ }
+ c->csc (c->csc_cls,
+ response_string,
+ http_status);
+ return;
+}
+
+
void
-ANASTASIS_challenge_select_to_pay (struct ANASTASIS_Challenge *challenge,
- ANASTASIS_ChallengePaymentCallback cc,
- void *cc_cls)
+ANASTASIS_challenge_start (struct GNUNET_CURL_Context *ctx,
+ struct ANASTASIS_Challenge *c,
+ ANASTASIS_ChallengePaymentCallback cpc,
+ void *cpc_cls,
+ ANASTASIS_ChallengeStartCallback csc,
+ void *csc_cls)
{
- // FIXME
+ c->ctx = ctx;
+ c->csc = csc;
+ c->csc_cls = csc_cls;
+ c->cpc = cpc;
+ c->cpc_cls = cpc_cls;
+ c->payment_requested = false;
+
+ if (c->payment_order_id != NULL)
+ {
+ GNUNET_STRINGS_string_to_data (c->payment_order_id,
+ strlen (c->payment_order_id),
+ &c->payment_secret,
+ sizeof (struct
+ ANASTASIS_PaymentSecretP));
+ c->payment_requested = true;
+ }
+
+ c->cro = ANASTASIS_challenge_run (c->ctx,
+ c->url,
+ &c->truth_public_key,
+ &c->truth_key,
+ c->payment_requested
+ ? &c->payment_secret
+ : NULL,
+ c->payment_requested,
+ &challenge_run_cb,
+ c);
}
diff --git a/src/lib/test_anastasis.c b/src/lib/test_anastasis.c
index 9e047bf..c1534b0 100644
--- a/src/lib/test_anastasis.c
+++ b/src/lib/test_anastasis.c
@@ -234,8 +234,8 @@ run (void *cls,
anastasis_url,
ANASTASIS_TESTING_make_id_data_example
(
"MaxMuster123456789"),
- "question",
- "You have to answer the secure
question.",
+ "file",
+ "TESTING FILE PLUGIN INTEGRATION",
"string",
"HashOfSomeTruth3",
strlen ("HashOfSomeTruth3"),
@@ -303,17 +303,46 @@ run (void *cls,
MHD_HTTP_OK,
"recover-secret-1",
0,
- "HashOfSomeTruth1"),
+ "HashOfSomeTruth1",
+ 0),
ANASTASIS_TESTING_cmd_challenge_answer ("challenge-answer-2",
MHD_HTTP_OK,
"recover-secret-1",
1,
- "HashOfSomeTruth2"),
+ "HashOfSomeTruth2",
+ 0),
+
+ ANASTASIS_TESTING_cmd_challenge_start ("challenge-start-1",
+ MHD_HTTP_PAYMENT_REQUIRED,
+ "recover-secret-1",
+ 2),
+ /* what would we have to pay? */
+ TALER_TESTING_cmd_merchant_claim_order ("fetch-proposal",
+ merchant_url,
+ MHD_HTTP_OK,
+ "challenge-start-1",
+ NULL),
+ /* make the payment */
+ TALER_TESTING_cmd_merchant_pay_order ("pay-challenge",
+ merchant_url,
+ MHD_HTTP_OK,
+ "fetch-proposal",
+ "withdraw-coin-2",
+ "EUR:1.01",
+ "EUR:1", /* must match ANNUAL_FEE in
config! */
+ NULL),
+
+ ANASTASIS_TESTING_cmd_challenge_start ("challenge-start-2",
+ MHD_HTTP_OK,
+ "recover-secret-1",
+ 2),
+
ANASTASIS_TESTING_cmd_challenge_answer ("challenge-answer-3",
MHD_HTTP_OK,
"recover-secret-1",
2,
- "HashOfSomeTruth3"),
+ "challenge-start-2",
+ 1),
TALER_TESTING_cmd_end ()
};
diff --git a/src/lib/testing_api_cmd_challenge_run.c
b/src/lib/testing_api_cmd_challenge_run.c
index f6bd0ce..50e0e86 100644
--- a/src/lib/testing_api_cmd_challenge_run.c
+++ b/src/lib/testing_api_cmd_challenge_run.c
@@ -105,6 +105,7 @@ struct ChallengeRunState
*
* @param cls closure
* @param http_status HTTP status of the request
+ * @param response_string payment request or instructions
*/
static void
challenge_run_cb (void *cls,
diff --git a/src/lib/testing_cmd_challenge_answer.c
b/src/lib/testing_cmd_challenge_answer.c
index e4ae796..4abca36 100644
--- a/src/lib/testing_cmd_challenge_answer.c
+++ b/src/lib/testing_cmd_challenge_answer.c
@@ -61,6 +61,11 @@ struct ChallengeState
* Index of the challenge we are solving
*/
unsigned int challenge_index;
+
+ /**
+ * 0 for no plugin needed 1 for plugin needed to authenticate
+ */
+ unsigned int mode;
};
@@ -116,6 +121,29 @@ challenge_answer_run (void *cls,
return;
}
}
+ if (cs->mode == 1)
+ {
+ const char *code;
+ ref = TALER_TESTING_interpreter_lookup_command (
+ is,
+ cs->answer);
+ if (NULL == ref)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (cs->is);
+ return;
+ }
+ if (GNUNET_OK !=
+ ANASTASIS_TESTING_get_trait_code (ref,
+ 0,
+ &code))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (cs->is);
+ return;
+ }
+ cs->answer = code;
+ }
ANASTASIS_challenge_answer (is->ctx,
(struct ANASTASIS_Challenge *) c,
@@ -157,7 +185,8 @@ ANASTASIS_TESTING_cmd_challenge_answer (const char *label,
unsigned int http_status,
const char *challenge_ref,
unsigned int challenge_index,
- const char *answer)
+ const char *answer,
+ unsigned int mode)
{
struct ChallengeState *cs;
@@ -166,6 +195,7 @@ ANASTASIS_TESTING_cmd_challenge_answer (const char *label,
cs->challenge_ref = challenge_ref;
cs->answer = answer;
cs->challenge_index = challenge_index;
+ cs->mode = mode;
{
struct TALER_TESTING_Command cmd = {
.cls = cs,
diff --git a/src/lib/testing_cmd_challenge_start.c
b/src/lib/testing_cmd_challenge_start.c
new file mode 100644
index 0000000..4bc2826
--- /dev/null
+++ b/src/lib/testing_cmd_challenge_start.c
@@ -0,0 +1,325 @@
+/*
+ This file is part of Anastasis
+ Copyright (C) 2020 Taler Systems SA
+
+ Anastasis is free software; you can redistribute it and/or modify it under
the
+ terms of the GNU Lesser General Public License as published by the Free
Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ Anastasis; see the file COPYING.GPL. If not, see
<http://www.gnu.org/licenses/>
+*/
+/**
+ * @file lib/testing_cmd_challenge_answer.c
+ * @brief command to execute the anastasis recovery service
+ * @author Christian Grothoff
+ * @author Dennis Neufeld
+ * @author Dominik Meister
+ */
+
+#include "platform.h"
+#include "anastasis_testing_lib.h"
+#include <taler/taler_util.h>
+#include <taler/taler_testing_lib.h>
+
+
+/**
+ * State for a "challenge answer" CMD.
+ */
+struct ChallengeState
+{
+ /**
+ * Claim token we got back, if any. Otherwise all zeros.
+ */
+ struct TALER_ClaimTokenP token;
+ /**
+ * 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 char *answer;
+
+ /**
+ * Reference to the recovery process
+ */
+ const char *challenge_ref;
+
+ /**
+ * Index of the challenge we are solving
+ */
+ unsigned int challenge_index;
+ /**
+ * Reference to the payment
+ */
+ const char *payment_ref;
+ /**
+ * Payment order ID we got back, if any. Otherwise NULL.
+ */
+ char *payment_order_id;
+
+ /**
+ * Payment order ID we are to provide in the request, may be NULL.
+ */
+ struct ANASTASIS_PaymentSecretP payment_order_req;
+ /**
+ * True if @e payment_order_req is initialized.
+ */
+ bool payment_order_set;
+ /**
+ * code we read in the file generated by the plugin
+ */
+ char *code;
+};
+
+static void
+challenge_start_cb (void *cls,
+ const char *response_string,
+ unsigned int http_status)
+{
+ struct ChallengeState *cs = cls;
+ FILE *file;
+ cs->code = malloc (sizeof(char) * 22);
+ file = fopen (response_string, "r");
+
+ if (file == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "could not find file: %s to command %s in %s:%u\n",
+ response_string,
+ cs->is->commands[cs->is->ip].label,
+ __FILE__,
+ __LINE__);
+ TALER_TESTING_interpreter_fail (cs->is);
+ return;
+ }
+ if (0 == fscanf (file, "%s", cs->code))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "could not read file: %s to command %s in %s:%u\n",
+ response_string,
+ cs->is->commands[cs->is->ip].label,
+ __FILE__,
+ __LINE__);
+ TALER_TESTING_interpreter_fail (cs->is);
+ return;
+ }
+ TALER_TESTING_interpreter_next (cs->is);
+}
+
+
+static void
+challenge_payment_cb (void *cls,
+ const char *taler_pay_url,
+ const char *server_url,
+ unsigned int http_status)
+{
+ const char *m;
+ struct ChallengeState *cs = cls;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "At %s:%d the taler pay url is %s\n",
+ __FILE__, __LINE__,
+ taler_pay_url);
+ if (cs->http_status != http_status)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u/%d to command %s in %s:%u\n",
+ cs->http_status,
+ http_status,
+ cs->is->commands[cs->is->ip].label,
+ __FILE__,
+ __LINE__);
+ TALER_TESTING_interpreter_fail (cs->is);
+ return;
+ }
+
+ if (0 != strncmp (taler_pay_url,
+ "taler://pay/http",
+ strlen ("taler://pay/http")))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Did not find `%s' in `%s'\n",
+ "/-/-/",
+ taler_pay_url);
+ TALER_TESTING_interpreter_fail (cs->is);
+ return;
+ }
+ m = strstr (taler_pay_url, "/-/-/");
+ if (NULL == m)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Did not find `%s' in `%s'\n",
+ "/-/-/",
+ taler_pay_url);
+ TALER_TESTING_interpreter_fail (cs->is);
+ /* NOTE: The above is a simplifying assumption for the
+ test-logic, hitting this code merely means that
+ the assumptions for the test (i.e. no instance) are
+ not satisfied, it is not inherently the case that
+ the above token must appear in the payment request!
+
+ So if you hit this, you might just want to modify
+ the code here to handle this better! */
+ return;
+ }
+ cs->payment_order_id = GNUNET_strdup (&m[strlen ("/-/-/")]);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "At %s:%d Order ID from Anastasis service is %s\n",
+ __FILE__, __LINE__,
+ cs->payment_order_id);
+
+ TALER_TESTING_interpreter_next (cs->is);
+}
+
+
+/**
+ * Offer internal data to other commands.
+ *
+ * @param cls closure
+ * @param ret[out] result (could be anything)
+ * @param trait name of the trait
+ * @param index index number of the object to extract.
+ * @return #GNUNET_OK on success
+ */
+static int
+challenge_start_create_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct ChallengeState *cs = cls;
+ struct TALER_TESTING_Trait traits[] = {
+ ANASTASIS_TESTING_make_trait_code (0,
+ cs->code),
+ TALER_TESTING_make_trait_order_id (0,
+ cs->payment_order_id),
+ TALER_TESTING_make_trait_claim_token (0,
+ &cs->token),
+
+ TALER_TESTING_trait_end ()
+ };
+
+ return TALER_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
+
+
+/**
+ * Run a "recover secret" CMD.
+ *
+ * @param cls closure.
+ * @param cmd command currently being run.
+ * @param is interpreter state.
+ */
+static void
+challenge_start_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct ChallengeState *cs = cls;
+ const struct TALER_TESTING_Command *ref;
+ const struct ANASTASIS_Challenge *c;
+
+ cs->is = is;
+ if (NULL != cs->challenge_ref)
+ {
+ ref = TALER_TESTING_interpreter_lookup_command (
+ is,
+ cs->challenge_ref);
+ if (NULL == ref)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (cs->is);
+ return;
+ }
+ if (GNUNET_OK !=
+ ANASTASIS_TESTING_get_trait_challenge (ref,
+ cs->challenge_index,
+ &c))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (cs->is);
+ return;
+ }
+ }
+ ANASTASIS_challenge_start (is->ctx,
+ (struct ANASTASIS_Challenge *) c,
+ &challenge_payment_cb,
+ cs,
+ &challenge_start_cb,
+ cs);
+}
+
+
+/**
+ * Free the state of a "recover secret" CMD, and possibly
+ * cancel it if it did not complete.
+ *
+ * @param cls closure.
+ * @param cmd command being freed.
+ */
+static void
+challenge_start_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct ChallengeState *cs = cls;
+ GNUNET_free (cs);
+}
+
+
+/**
+ * Make the "challenge answer" command.
+ *
+ * @param label command label
+ * @param http_status expected HTTP status.
+ * @param challenge_ref reference to the recovery process
+ * @param challenge_index defines the index of the trait to solve
+ * @param answer to the challenge
+ * @param answer_size size of the answer
+ * @return the command
+ */
+struct TALER_TESTING_Command
+ANASTASIS_TESTING_cmd_challenge_start (const char *label,
+ unsigned int http_status,
+ const char *challenge_ref,
+ unsigned int challenge_index)
+{
+ struct ChallengeState *cs;
+
+ cs = GNUNET_new (struct ChallengeState);
+ cs->http_status = http_status;
+ cs->challenge_ref = challenge_ref;
+ cs->challenge_index = challenge_index;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = cs,
+ .label = label,
+ .run = &challenge_start_run,
+ .cleanup = &challenge_start_cleanup,
+ .traits = &challenge_start_create_traits
+ };
+
+ return cmd;
+ }
+}
+
+
+/* end of testing_cmd_challenge_answer.c */
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-anastasis] branch master updated: client library update and tests,
gnunet <=