diff options
author | jospaeth <spaethj@in.tum.de> | 2020-05-25 21:38:58 +0200 |
---|---|---|
committer | jospaeth <spaethj@in.tum.de> | 2020-05-25 21:38:58 +0200 |
commit | a32de45ceffeb69038ecfa7b963f30b7fed83a41 (patch) | |
tree | 76a39adcf7163c71e470b7c5bf4357dd5471cf9c /src/identity/plugin_rest_identity.c | |
parent | 19cd0e6d0eca5192a9c8f4f005abd85d531949f1 (diff) | |
download | gnunet-spaeth/import_identity.tar.gz gnunet-spaeth/import_identity.zip |
add option to create identity from private keyspaeth/import_identity
Diffstat (limited to 'src/identity/plugin_rest_identity.c')
-rw-r--r-- | src/identity/plugin_rest_identity.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c index ef01cc578..009a01f16 100644 --- a/src/identity/plugin_rest_identity.c +++ b/src/identity/plugin_rest_identity.c | |||
@@ -57,7 +57,7 @@ | |||
57 | #define GNUNET_REST_IDENTITY_PARAM_PUBKEY "pubkey" | 57 | #define GNUNET_REST_IDENTITY_PARAM_PUBKEY "pubkey" |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * Parameter public key | 60 | * Parameter private key |
61 | */ | 61 | */ |
62 | #define GNUNET_REST_IDENTITY_PARAM_PRIVKEY "privkey" | 62 | #define GNUNET_REST_IDENTITY_PARAM_PRIVKEY "privkey" |
63 | 63 | ||
@@ -990,6 +990,9 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
990 | json_t *data_js; | 990 | json_t *data_js; |
991 | json_error_t err; | 991 | json_error_t err; |
992 | char *egoname; | 992 | char *egoname; |
993 | char *privkey; | ||
994 | struct GNUNET_CRYPTO_EcdsaPrivateKey pk; | ||
995 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pk_ptr; | ||
993 | int json_unpack_state; | 996 | int json_unpack_state; |
994 | char term_data[handle->data_size + 1]; | 997 | char term_data[handle->data_size + 1]; |
995 | 998 | ||
@@ -1016,8 +1019,11 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
1016 | return; | 1019 | return; |
1017 | } | 1020 | } |
1018 | json_unpack_state = 0; | 1021 | json_unpack_state = 0; |
1022 | privkey = NULL; | ||
1019 | json_unpack_state = | 1023 | json_unpack_state = |
1020 | json_unpack (data_js, "{s:s!}", GNUNET_REST_IDENTITY_PARAM_NAME, &egoname); | 1024 | json_unpack (data_js, "{s:s, s?:s!}", |
1025 | GNUNET_REST_IDENTITY_PARAM_NAME, &egoname, | ||
1026 | GNUNET_REST_IDENTITY_PARAM_PRIVKEY, &privkey); | ||
1021 | if (0 != json_unpack_state) | 1027 | if (0 != json_unpack_state) |
1022 | { | 1028 | { |
1023 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | 1029 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); |
@@ -1054,10 +1060,21 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
1054 | } | 1060 | } |
1055 | } | 1061 | } |
1056 | handle->name = GNUNET_strdup (egoname); | 1062 | handle->name = GNUNET_strdup (egoname); |
1063 | if (NULL != privkey) | ||
1064 | { | ||
1065 | GNUNET_STRINGS_string_to_data (privkey, | ||
1066 | strlen (privkey), | ||
1067 | &pk, | ||
1068 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)); | ||
1069 | pk_ptr = &pk; | ||
1070 | } | ||
1071 | else | ||
1072 | pk_ptr = NULL; | ||
1057 | json_decref (data_js); | 1073 | json_decref (data_js); |
1058 | handle->response_code = MHD_HTTP_CREATED; | 1074 | handle->response_code = MHD_HTTP_CREATED; |
1059 | handle->op = GNUNET_IDENTITY_create (handle->identity_handle, | 1075 | handle->op = GNUNET_IDENTITY_create (handle->identity_handle, |
1060 | handle->name, | 1076 | handle->name, |
1077 | pk_ptr, | ||
1061 | &do_finished_create, | 1078 | &do_finished_create, |
1062 | handle); | 1079 | handle); |
1063 | } | 1080 | } |