diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2016-01-24 10:44:10 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2016-01-24 10:44:10 +0000 |
commit | 814b5e47aa0a9e154e3226539648d78d3ce2c293 (patch) | |
tree | 2d9271663bb5ecbeabc685dbe669ecd0b95f76ca /src/identity-provider/plugin_rest_identity_provider.c | |
parent | f95fe0a950bbb6e3c86ae6308c63466c77aed3e0 (diff) | |
download | gnunet-814b5e47aa0a9e154e3226539648d78d3ce2c293.tar.gz gnunet-814b5e47aa0a9e154e3226539648d78d3ce2c293.zip |
- fix
Diffstat (limited to 'src/identity-provider/plugin_rest_identity_provider.c')
-rw-r--r-- | src/identity-provider/plugin_rest_identity_provider.c | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/src/identity-provider/plugin_rest_identity_provider.c b/src/identity-provider/plugin_rest_identity_provider.c index 161d61931..0110ba024 100644 --- a/src/identity-provider/plugin_rest_identity_provider.c +++ b/src/identity-provider/plugin_rest_identity_provider.c | |||
@@ -62,6 +62,11 @@ | |||
62 | #define GNUNET_REST_JSONAPI_IDENTITY_PROVIDER_TICKET "ticket" | 62 | #define GNUNET_REST_JSONAPI_IDENTITY_PROVIDER_TICKET "ticket" |
63 | 63 | ||
64 | /** | 64 | /** |
65 | * The parameter name in which the expected nonce must be provided | ||
66 | */ | ||
67 | #define GNUNET_REST_JSONAPI_IDENTITY_PROVIDER_EXPECTED_NONCE "expected_nonce" | ||
68 | |||
69 | /** | ||
65 | * The parameter name in which the ticket must be provided | 70 | * The parameter name in which the ticket must be provided |
66 | */ | 71 | */ |
67 | #define GNUNET_REST_JSONAPI_IDENTITY_PROVIDER_TOKEN "token" | 72 | #define GNUNET_REST_JSONAPI_IDENTITY_PROVIDER_TOKEN "token" |
@@ -767,13 +772,44 @@ list_token_cont (struct RestConnectionDataHandle *con_handle, | |||
767 | */ | 772 | */ |
768 | static void | 773 | static void |
769 | exchange_cont (void *cls, | 774 | exchange_cont (void *cls, |
770 | const struct GNUNET_IDENTITY_PROVIDER_Token *token) | 775 | const struct GNUNET_IDENTITY_PROVIDER_Token *token, |
776 | uint64_t ticket_nonce) | ||
771 | { | 777 | { |
772 | json_t *root; | 778 | json_t *root; |
773 | struct RequestHandle *handle = cls; | 779 | struct RequestHandle *handle = cls; |
774 | struct MHD_Response *resp; | 780 | struct MHD_Response *resp; |
781 | struct GNUNET_HashCode key; | ||
775 | char* result; | 782 | char* result; |
776 | char* token_str; | 783 | char* token_str; |
784 | char* nonce_str; | ||
785 | uint64_t expected_nonce; | ||
786 | |||
787 | //Get nonce | ||
788 | GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_IDENTITY_PROVIDER_EXPECTED_NONCE, | ||
789 | strlen (GNUNET_REST_JSONAPI_IDENTITY_PROVIDER_EXPECTED_NONCE), | ||
790 | &key); | ||
791 | |||
792 | if ( GNUNET_NO == | ||
793 | GNUNET_CONTAINER_multihashmap_contains (handle->conndata_handle->url_param_map, | ||
794 | &key) ) | ||
795 | { | ||
796 | handle->emsg = GNUNET_strdup ("No nonce given."); | ||
797 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
798 | return; | ||
799 | } | ||
800 | nonce_str = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map, | ||
801 | &key); | ||
802 | GNUNET_assert (1 == sscanf (nonce_str, "%lu", &expected_nonce)); | ||
803 | |||
804 | if (ticket_nonce != expected_nonce) | ||
805 | { | ||
806 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
807 | "Ticket nonce %lu does not match expected nonce %lu\n", | ||
808 | ticket_nonce, expected_nonce); | ||
809 | handle->emsg = GNUNET_strdup ("Ticket nonce does not match expected nonce\n"); | ||
810 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
811 | return; | ||
812 | } | ||
777 | 813 | ||
778 | root = json_object (); | 814 | root = json_object (); |
779 | token_str = GNUNET_IDENTITY_PROVIDER_token_to_string (token); | 815 | token_str = GNUNET_IDENTITY_PROVIDER_token_to_string (token); |
@@ -820,6 +856,7 @@ exchange_token_ticket_cb (void *cls, | |||
820 | return; | 856 | return; |
821 | } | 857 | } |
822 | 858 | ||
859 | //Get ticket | ||
823 | GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_IDENTITY_PROVIDER_TICKET, | 860 | GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_IDENTITY_PROVIDER_TICKET, |
824 | strlen (GNUNET_REST_JSONAPI_IDENTITY_PROVIDER_TICKET), | 861 | strlen (GNUNET_REST_JSONAPI_IDENTITY_PROVIDER_TICKET), |
825 | &key); | 862 | &key); |
@@ -834,7 +871,6 @@ exchange_token_ticket_cb (void *cls, | |||
834 | } | 871 | } |
835 | ticket_str = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map, | 872 | ticket_str = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map, |
836 | &key); | 873 | &key); |
837 | |||
838 | handle->priv_key = GNUNET_IDENTITY_ego_get_private_key (ego); | 874 | handle->priv_key = GNUNET_IDENTITY_ego_get_private_key (ego); |
839 | GNUNET_IDENTITY_PROVIDER_string_to_ticket (ticket_str, | 875 | GNUNET_IDENTITY_PROVIDER_string_to_ticket (ticket_str, |
840 | &ticket); | 876 | &ticket); |