[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] branch master updated: Authorisation plugin and testin
From: |
gnunet |
Subject: |
[taler-anastasis] branch master updated: Authorisation plugin and testing |
Date: |
Tue, 27 Oct 2020 20:34:38 +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 098c5cd Authorisation plugin and testing
098c5cd is described below
commit 098c5cd24bc46c5cda9cffdbaeac440f2127ff06
Author: Dominik Meister <dominik.meister@hotmail.ch>
AuthorDate: Tue Oct 27 20:34:26 2020 +0100
Authorisation plugin and testing
---
src/backend/anastasis-httpd_truth.c | 3 +-
src/backend/anastasis_authorization_plugin_file.c | 18 +++++-
src/include/anastasis_testing_lib.h | 27 ++++++++-
src/lib/Makefile.am | 1 +
src/lib/anastasis_api_challenge_run.c | 7 ++-
src/lib/test_anastasis_api.c | 8 ++-
src/lib/testing_api_cmd_challenge_run.c | 53 +++++++++++++++-
src/lib/testing_api_cmd_keyshare_lookup.c | 45 +++++++++++++-
src/lib/testing_api_trait_code.c | 73 +++++++++++++++++++++++
9 files changed, 222 insertions(+), 13 deletions(-)
diff --git a/src/backend/anastasis-httpd_truth.c
b/src/backend/anastasis-httpd_truth.c
index 01892ce..9bb1c77 100644
--- a/src/backend/anastasis-httpd_truth.c
+++ b/src/backend/anastasis-httpd_truth.c
@@ -753,7 +753,6 @@ AH_handler_truth_get (struct MHD_Connection *connection,
struct ANASTASIS_AuthorizationPlugin *authorization;
enum GNUNET_GenericReturnValue ret;
struct ANASTASIS_AUTHORIZATION_State *as;
- uint64_t code = 42;
enum ANASTASIS_AUTHORIZATION_Result aret;
enum ANASTASIS_DB_QueryStatus qs;
struct GNUNET_TIME_Relative challenge_expiration;
@@ -789,7 +788,7 @@ AH_handler_truth_get (struct MHD_Connection *connection,
}
// FIXME:
// RANDOM! -- or from DB if recent one in DB!
-
+ uint64_t code = 42;
// FIXME TIME where to put this?
// FIXME retry counter where to put it?
qs = db->store_challenge_code (db->cls,
diff --git a/src/backend/anastasis_authorization_plugin_file.c
b/src/backend/anastasis_authorization_plugin_file.c
index 0a8d8c5..827f449 100644
--- a/src/backend/anastasis_authorization_plugin_file.c
+++ b/src/backend/anastasis_authorization_plugin_file.c
@@ -176,8 +176,22 @@ file_process (struct ANASTASIS_AUTHORIZATION_State *as,
return ANASTASIS_AUTHORIZATION_RES_FAILED;
}
fclose (f);
- resp = MHD_create_response_from_buffer (strlen (as->filename),
- as->filename,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Filename before: %s", as->filename);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "STRLEN: %ld",strlen (as->filename));
+ size_t response_size;
+ response_size = strlen (as->filename) * 5 / 8;
+ void *response = malloc (response_size);
+ GNUNET_STRINGS_string_to_data (as->filename,
+ strlen (as->filename),
+ response,
+ response_size);
+ char *test = GNUNET_STRINGS_data_to_string_alloc (response,
+ response_size);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Filename after: %s", test);
+
+
+ resp = MHD_create_response_from_buffer (response_size,
+ response,
MHD_RESPMEM_MUST_FREE);
TALER_MHD_add_global_headers (resp);
mres = MHD_queue_response (connection,
diff --git a/src/include/anastasis_testing_lib.h
b/src/include/anastasis_testing_lib.h
index 6eb1926..3fae5d5 100644
--- a/src/include/anastasis_testing_lib.h
+++ b/src/include/anastasis_testing_lib.h
@@ -187,7 +187,30 @@ ANASTASIS_TESTING_make_trait_truth_public_key (unsigned
int index,
const struct
ANASTASIS_CRYPTO_TruthPublicKeyP
*tpk);
+/**
+ * Obtain a code from @a cmd.
+ *
+ * @param cmd command to extract the number from.
+ * @param index the number's index number.
+ * @param tpk[out] set to the number coming from @a cmd.
+ * @return #GNUNET_OK on success.
+ */
+int
+ANASTASIS_TESTING_get_trait_code (const struct
+ TALER_TESTING_Command *cmd,
+ unsigned int index,
+ const char **code);
+/**
+ * Offer a filename.
+ *
+ * @param index the number's index number.
+ * @param tpk the public key to offer.
+ * @return #GNUNET_OK on success.
+ */
+struct TALER_TESTING_Trait
+ANASTASIS_TESTING_make_trait_code (unsigned int index,
+ const char *code);
/**
* Prepare the merchant execution. Create tables and check if
* the port is available.
@@ -411,6 +434,7 @@ ANASTASIS_TESTING_cmd_truth_store (const char *label,
* @param answer (response to challenge)
* @param key key to decrypt truth
* @param upload_ref reference to upload command
+ * @param lookup_mode defines the mode (0= secure question, 1 code based)
* @return the command
*/
struct TALER_TESTING_Command
@@ -420,7 +444,8 @@ ANASTASIS_TESTING_cmd_keyshare_lookup (const char *label,
char *answer,
const struct
ANASTASIS_CRYPTO_TruthKeyP key,
- const char *upload_ref);
+ const char *upload_ref,
+ int lookup_mode);
/**
* Make the "challenge run" command.
*
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 7c2d0c6..bab381d 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -74,6 +74,7 @@ libanastasistesting_la_SOURCES = \
testing_api_trait_truth_pub.c \
testing_api_trait_hash.c \
testing_api_trait_salt.c \
+ testing_api_trait_code.c \
testing_cmd_truth_upload.c \
testing_cmd_policy_create.c \
testing_cmd_secret_share.c \
diff --git a/src/lib/anastasis_api_challenge_run.c
b/src/lib/anastasis_api_challenge_run.c
index 4f12b16..d72418b 100644
--- a/src/lib/anastasis_api_challenge_run.c
+++ b/src/lib/anastasis_api_challenge_run.c
@@ -73,7 +73,9 @@ struct ANASTASIS_ChallengeRunOperation
* Key to decrypt the truth on the server
*/
const struct ANASTASIS_CRYPTO_TruthKeyP *truth_key;
-
+ /**
+ * challenge run response from server(look at number xxx, look at email xxx)
+ */
char *response_string;
};
@@ -92,6 +94,7 @@ ANASTASIS_challenge_run_cancel (
GNUNET_CURL_job_cancel (cro->job);
cro->job = NULL;
}
+ GNUNET_free (cro->response_string);
GNUNET_free (cro->url);
GNUNET_free (cro);
}
@@ -125,7 +128,7 @@ handle_challenge_run_finished (void *cls,
"Response from backend: %s",cro->response_string);
cro->cb (cro->cb_cls,
response_code,
- "run failed");
+ cro->response_string);
ANASTASIS_challenge_run_cancel (cro);
return;
}
diff --git a/src/lib/test_anastasis_api.c b/src/lib/test_anastasis_api.c
index 330736a..0cd67df 100644
--- a/src/lib/test_anastasis_api.c
+++ b/src/lib/test_anastasis_api.c
@@ -264,7 +264,8 @@ run (void *cls,
answer_str,
ANASTASIS_TESTING_make_truthkey (
"Truth-Key"),
- "truth-store-1"),
+ "truth-store-1",
+ 0),
ANASTASIS_TESTING_cmd_truth_store ("truth-store-2",
anastasis_url,
@@ -290,10 +291,11 @@ run (void *cls,
ANASTASIS_TESTING_cmd_keyshare_lookup ("keyshare-lookup-2",
anastasis_url,
MHD_HTTP_OK,
- "42",
+ "challenge-run-1",
ANASTASIS_TESTING_make_truthkey (
"Truth-Key-2"),
- "truth-store-2"),
+ "truth-store-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 6c7ac55..e59f38c 100644
--- a/src/lib/testing_api_cmd_challenge_run.c
+++ b/src/lib/testing_api_cmd_challenge_run.c
@@ -66,6 +66,10 @@ struct ChallengeRunState
* Reference to upload command we expect to lookup.
*/
const char *upload_reference;
+ /**
+ * code we read in the file generated by the plugin
+ */
+ char *code;
};
/**
@@ -80,7 +84,6 @@ challenge_run_cb (void *cls,
char *response_string)
{
struct ChallengeRunState *crs = cls;
-
crs->cro = NULL;
if (http_status != crs->http_status)
{
@@ -93,9 +96,54 @@ challenge_run_cb (void *cls,
TALER_TESTING_interpreter_fail (crs->is);
return;
}
+ FILE *file;
+ crs->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,
+ crs->is->commands[crs->is->ip].label,
+ __FILE__,
+ __LINE__);
+ TALER_TESTING_interpreter_fail (crs->is);
+ return;
+ }
+ fscanf (file, "%s", crs->code);
+
TALER_TESTING_interpreter_next (crs->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_run_create_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct ChallengeRunState *crs = cls;
+ struct TALER_TESTING_Trait traits[] = {
+ ANASTASIS_TESTING_make_trait_code (0,
+ crs->code),
+ TALER_TESTING_trait_end ()
+ };
+
+ return TALER_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
+
/**
* Run a "challenge run" CMD.
@@ -230,7 +278,8 @@ ANASTASIS_TESTING_cmd_challenge_run
.cls = crs,
.label = label,
.run = &challenge_run,
- .cleanup = &challenge_run_cleanup
+ .cleanup = &challenge_run_cleanup,
+ .traits = &challenge_run_create_traits
};
return cmd;
}
diff --git a/src/lib/testing_api_cmd_keyshare_lookup.c
b/src/lib/testing_api_cmd_keyshare_lookup.c
index 68fea91..a2d5574 100644
--- a/src/lib/testing_api_cmd_keyshare_lookup.c
+++ b/src/lib/testing_api_cmd_keyshare_lookup.c
@@ -71,6 +71,11 @@ struct KeyShareLookupState
* Reference to upload command we expect to lookup.
*/
const char *upload_reference;
+
+ /**
+ * Mode for the lookup(0 = question, 1 = code based)
+ */
+ int lookup_mode;
};
/**
@@ -153,6 +158,42 @@ keyshare_lookup_run (void *cls,
}
}
+ if (ksls->lookup_mode == 1)
+ {
+ const struct TALER_TESTING_Command *download_cmd;
+
+ download_cmd = TALER_TESTING_interpreter_lookup_command
+ (is,
+ ksls->answer);
+ if (NULL == download_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (ksls->is);
+ return;
+ }
+ {
+ if (GNUNET_OK !=
+ ANASTASIS_TESTING_get_trait_code (download_cmd,
+ 0,
+ &ksls->answer))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (ksls->is);
+ return;
+ }
+ if (NULL == ksls->answer)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (ksls->is);
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Answer from trait: %s\n",
+ ksls->answer);
+ }
+
+ }
+
ksls->kslo = ANASTASIS_keyshare_lookup (is->ctx,
ksls->anastasis_url,
ksls->truth_public_key,
@@ -235,7 +276,8 @@ ANASTASIS_TESTING_cmd_keyshare_lookup (const char *label,
char *answer,
const struct
ANASTASIS_CRYPTO_TruthKeyP key,
- const char *upload_ref)
+ const char *upload_ref,
+ int lookup_mode)
{
struct KeyShareLookupState *ksls;
@@ -253,6 +295,7 @@ ANASTASIS_TESTING_cmd_keyshare_lookup (const char *label,
ksls->upload_reference = upload_ref;
ksls->answer = answer;
ksls->truth_key = key;
+ ksls->lookup_mode = lookup_mode;
{
struct TALER_TESTING_Command cmd = {
.cls = ksls,
diff --git a/src/lib/testing_api_trait_code.c b/src/lib/testing_api_trait_code.c
new file mode 100644
index 0000000..1a43cf8
--- /dev/null
+++ b/src/lib/testing_api_trait_code.c
@@ -0,0 +1,73 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2019 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ TALER 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 TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file lib/testing_api_trait_string.c
+ * @brief traits to offers a code for a challenge
+ * @author Dominik Meister
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "anastasis_testing_lib.h"
+
+#define ANASTASIS_TESTING_TRAIT_CODE "anastasis-code"
+
+
+/**
+ * Obtain a code from @a cmd.
+ *
+ * @param cmd command to extract the number from.
+ * @param index the number's index number.
+ * @param n[out] set to the number coming from @a cmd.
+ * @return #GNUNET_OK on success.
+ */
+int
+ANASTASIS_TESTING_get_trait_code
+ (const struct TALER_TESTING_Command *cmd,
+ unsigned int index,
+ const char **code)
+{
+ return cmd->traits (cmd->cls,
+ (const void **) code,
+ ANASTASIS_TESTING_TRAIT_CODE,
+ index);
+}
+
+
+/**
+ * Offer a code.
+ *
+ * @param index the number's index number.
+ * @param code the code to offer.
+ * @return #GNUNET_OK on success.
+ */
+struct TALER_TESTING_Trait
+ANASTASIS_TESTING_make_trait_code
+ (unsigned int index,
+ const char *code)
+{
+ struct TALER_TESTING_Trait ret = {
+ .index = index,
+ .trait_name = ANASTASIS_TESTING_TRAIT_CODE,
+ .ptr = (const void *) code
+ };
+ return ret;
+}
+
+
+/* end of testing_api_trait_string.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: Authorisation plugin and testing,
gnunet <=