diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gns/gnunet-gns-proxy.c | 255 |
1 files changed, 99 insertions, 156 deletions
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c index 5146eb0d7..3e70bd3ca 100644 --- a/src/gns/gnunet-gns-proxy.c +++ b/src/gns/gnunet-gns-proxy.c | |||
@@ -690,11 +690,6 @@ static struct Socks5Request *s5r_head; | |||
690 | static struct Socks5Request *s5r_tail; | 690 | static struct Socks5Request *s5r_tail; |
691 | 691 | ||
692 | /** | 692 | /** |
693 | * The users local GNS master zone | ||
694 | */ | ||
695 | static struct GNUNET_CRYPTO_EcdsaPublicKey local_gns_zone; | ||
696 | |||
697 | /** | ||
698 | * The CA for SSL certificate generation | 693 | * The CA for SSL certificate generation |
699 | */ | 694 | */ |
700 | static struct ProxyCA proxy_ca; | 695 | static struct ProxyCA proxy_ca; |
@@ -705,16 +700,6 @@ static struct ProxyCA proxy_ca; | |||
705 | static struct MHD_Response *curl_failure_response; | 700 | static struct MHD_Response *curl_failure_response; |
706 | 701 | ||
707 | /** | 702 | /** |
708 | * Connection to identity service. | ||
709 | */ | ||
710 | static struct GNUNET_IDENTITY_Handle *identity; | ||
711 | |||
712 | /** | ||
713 | * Request for our ego. | ||
714 | */ | ||
715 | static struct GNUNET_IDENTITY_Operation *id_op; | ||
716 | |||
717 | /** | ||
718 | * Our configuration. | 703 | * Our configuration. |
719 | */ | 704 | */ |
720 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 705 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
@@ -2962,16 +2947,6 @@ do_shutdown (void *cls) | |||
2962 | GNUNET_NETWORK_socket_close (lsock6); | 2947 | GNUNET_NETWORK_socket_close (lsock6); |
2963 | lsock6 = NULL; | 2948 | lsock6 = NULL; |
2964 | } | 2949 | } |
2965 | if (NULL != id_op) | ||
2966 | { | ||
2967 | GNUNET_IDENTITY_cancel (id_op); | ||
2968 | id_op = NULL; | ||
2969 | } | ||
2970 | if (NULL != identity) | ||
2971 | { | ||
2972 | GNUNET_IDENTITY_disconnect (identity); | ||
2973 | identity = NULL; | ||
2974 | } | ||
2975 | if (NULL != curl_multi) | 2950 | if (NULL != curl_multi) |
2976 | { | 2951 | { |
2977 | curl_multi_cleanup (curl_multi); | 2952 | curl_multi_cleanup (curl_multi); |
@@ -3076,46 +3051,132 @@ bind_v6 () | |||
3076 | 3051 | ||
3077 | 3052 | ||
3078 | /** | 3053 | /** |
3079 | * Continue initialization after we have our zone information. | 3054 | * Main function that will be run |
3055 | * | ||
3056 | * @param cls closure | ||
3057 | * @param args remaining command-line arguments | ||
3058 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
3059 | * @param c configuration | ||
3080 | */ | 3060 | */ |
3081 | static void | 3061 | static void |
3082 | run_cont () | 3062 | run (void *cls, |
3063 | char *const *args, | ||
3064 | const char *cfgfile, | ||
3065 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
3083 | { | 3066 | { |
3067 | char* cafile_cfg = NULL; | ||
3068 | char* cafile; | ||
3084 | struct MhdHttpList *hd; | 3069 | struct MhdHttpList *hd; |
3085 | 3070 | ||
3071 | cfg = c; | ||
3072 | |||
3073 | if (NULL == (curl_multi = curl_multi_init ())) | ||
3074 | { | ||
3075 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
3076 | "Failed to create cURL multi handle!\n"); | ||
3077 | return; | ||
3078 | } | ||
3079 | cafile = cafile_opt; | ||
3080 | if (NULL == cafile) | ||
3081 | { | ||
3082 | if (GNUNET_OK != | ||
3083 | GNUNET_CONFIGURATION_get_value_filename (cfg, | ||
3084 | "gns-proxy", | ||
3085 | "PROXY_CACERT", | ||
3086 | &cafile_cfg)) | ||
3087 | { | ||
3088 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | ||
3089 | "gns-proxy", | ||
3090 | "PROXY_CACERT"); | ||
3091 | return; | ||
3092 | } | ||
3093 | cafile = cafile_cfg; | ||
3094 | } | ||
3095 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3096 | "Using %s as CA\n", cafile); | ||
3097 | |||
3098 | gnutls_global_init (); | ||
3099 | gnutls_x509_crt_init (&proxy_ca.cert); | ||
3100 | gnutls_x509_privkey_init (&proxy_ca.key); | ||
3101 | |||
3102 | if ( (GNUNET_OK != | ||
3103 | load_cert_from_file (proxy_ca.cert, | ||
3104 | cafile)) || | ||
3105 | (GNUNET_OK != | ||
3106 | load_key_from_file (proxy_ca.key, | ||
3107 | cafile)) ) | ||
3108 | { | ||
3109 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
3110 | _("Failed to load SSL/TLS key and certificate from `%s'\n"), | ||
3111 | cafile); | ||
3112 | gnutls_x509_crt_deinit (proxy_ca.cert); | ||
3113 | gnutls_x509_privkey_deinit (proxy_ca.key); | ||
3114 | gnutls_global_deinit (); | ||
3115 | GNUNET_free_non_null (cafile_cfg); | ||
3116 | return; | ||
3117 | } | ||
3118 | GNUNET_free_non_null (cafile_cfg); | ||
3119 | if (NULL == (gns_handle = GNUNET_GNS_connect (cfg))) | ||
3120 | { | ||
3121 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
3122 | "Unable to connect to GNS!\n"); | ||
3123 | gnutls_x509_crt_deinit (proxy_ca.cert); | ||
3124 | gnutls_x509_privkey_deinit (proxy_ca.key); | ||
3125 | gnutls_global_deinit (); | ||
3126 | return; | ||
3127 | } | ||
3128 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | ||
3129 | NULL); | ||
3130 | |||
3086 | /* Open listen socket for socks proxy */ | 3131 | /* Open listen socket for socks proxy */ |
3087 | lsock6 = bind_v6 (); | 3132 | lsock6 = bind_v6 (); |
3088 | if (NULL == lsock6) | 3133 | if (NULL == lsock6) |
3089 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); | 3134 | { |
3135 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | ||
3136 | "bind"); | ||
3137 | } | ||
3090 | else | 3138 | else |
3091 | { | 3139 | { |
3092 | if (GNUNET_OK != GNUNET_NETWORK_socket_listen (lsock6, 5)) | 3140 | if (GNUNET_OK != |
3141 | GNUNET_NETWORK_socket_listen (lsock6, | ||
3142 | 5)) | ||
3093 | { | 3143 | { |
3094 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "listen"); | 3144 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, |
3145 | "listen"); | ||
3095 | GNUNET_NETWORK_socket_close (lsock6); | 3146 | GNUNET_NETWORK_socket_close (lsock6); |
3096 | lsock6 = NULL; | 3147 | lsock6 = NULL; |
3097 | } | 3148 | } |
3098 | else | 3149 | else |
3099 | { | 3150 | { |
3100 | ltask6 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 3151 | ltask6 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
3101 | lsock6, &do_accept, lsock6); | 3152 | lsock6, |
3153 | &do_accept, | ||
3154 | lsock6); | ||
3102 | } | 3155 | } |
3103 | } | 3156 | } |
3104 | lsock4 = bind_v4 (); | 3157 | lsock4 = bind_v4 (); |
3105 | if (NULL == lsock4) | 3158 | if (NULL == lsock4) |
3106 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); | 3159 | { |
3160 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | ||
3161 | "bind"); | ||
3162 | } | ||
3107 | else | 3163 | else |
3108 | { | 3164 | { |
3109 | if (GNUNET_OK != GNUNET_NETWORK_socket_listen (lsock4, 5)) | 3165 | if (GNUNET_OK != |
3166 | GNUNET_NETWORK_socket_listen (lsock4, | ||
3167 | 5)) | ||
3110 | { | 3168 | { |
3111 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "listen"); | 3169 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, |
3170 | "listen"); | ||
3112 | GNUNET_NETWORK_socket_close (lsock4); | 3171 | GNUNET_NETWORK_socket_close (lsock4); |
3113 | lsock4 = NULL; | 3172 | lsock4 = NULL; |
3114 | } | 3173 | } |
3115 | else | 3174 | else |
3116 | { | 3175 | { |
3117 | ltask4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 3176 | ltask4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
3118 | lsock4, &do_accept, lsock4); | 3177 | lsock4, |
3178 | &do_accept, | ||
3179 | lsock4); | ||
3119 | } | 3180 | } |
3120 | } | 3181 | } |
3121 | if ( (NULL == lsock4) && | 3182 | if ( (NULL == lsock4) && |
@@ -3153,125 +3214,9 @@ run_cont () | |||
3153 | return; | 3214 | return; |
3154 | } | 3215 | } |
3155 | httpd = hd; | 3216 | httpd = hd; |
3156 | GNUNET_CONTAINER_DLL_insert (mhd_httpd_head, mhd_httpd_tail, hd); | 3217 | GNUNET_CONTAINER_DLL_insert (mhd_httpd_head, |
3157 | } | 3218 | mhd_httpd_tail, |
3158 | 3219 | hd); | |
3159 | |||
3160 | /** | ||
3161 | * Method called to inform about the egos of the master zone of this peer. | ||
3162 | * | ||
3163 | * When used with #GNUNET_IDENTITY_create or #GNUNET_IDENTITY_get, | ||
3164 | * this function is only called ONCE, and 'NULL' being passed in | ||
3165 | * @a ego does indicate an error (i.e. name is taken or no default | ||
3166 | * value is known). If @a ego is non-NULL and if '*ctx' | ||
3167 | * is set in those callbacks, the value WILL be passed to a subsequent | ||
3168 | * call to the identity callback of #GNUNET_IDENTITY_connect (if | ||
3169 | * that one was not NULL). | ||
3170 | * | ||
3171 | * @param cls closure, NULL | ||
3172 | * @param ego ego handle | ||
3173 | * @param ctx context for application to store data for this ego | ||
3174 | * (during the lifetime of this process, initially NULL) | ||
3175 | * @param name name assigned by the user for this ego, | ||
3176 | * NULL if the user just deleted the ego and it | ||
3177 | * must thus no longer be used | ||
3178 | */ | ||
3179 | static void | ||
3180 | identity_master_cb (void *cls, | ||
3181 | struct GNUNET_IDENTITY_Ego *ego, | ||
3182 | void **ctx, | ||
3183 | const char *name) | ||
3184 | { | ||
3185 | id_op = NULL; | ||
3186 | if (NULL == ego) | ||
3187 | { | ||
3188 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
3189 | _("No ego configured for `%s`\n"), | ||
3190 | "gns-proxy"); | ||
3191 | GNUNET_SCHEDULER_shutdown (); | ||
3192 | return; | ||
3193 | } | ||
3194 | GNUNET_IDENTITY_ego_get_public_key (ego, | ||
3195 | &local_gns_zone); | ||
3196 | run_cont (); | ||
3197 | } | ||
3198 | |||
3199 | |||
3200 | /** | ||
3201 | * Main function that will be run | ||
3202 | * | ||
3203 | * @param cls closure | ||
3204 | * @param args remaining command-line arguments | ||
3205 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
3206 | * @param c configuration | ||
3207 | */ | ||
3208 | static void | ||
3209 | run (void *cls, | ||
3210 | char *const *args, | ||
3211 | const char *cfgfile, | ||
3212 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
3213 | { | ||
3214 | char* cafile_cfg = NULL; | ||
3215 | char* cafile; | ||
3216 | |||
3217 | cfg = c; | ||
3218 | |||
3219 | if (NULL == (curl_multi = curl_multi_init ())) | ||
3220 | { | ||
3221 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
3222 | "Failed to create cURL multi handle!\n"); | ||
3223 | return; | ||
3224 | } | ||
3225 | cafile = cafile_opt; | ||
3226 | if (NULL == cafile) | ||
3227 | { | ||
3228 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns-proxy", | ||
3229 | "PROXY_CACERT", | ||
3230 | &cafile_cfg)) | ||
3231 | { | ||
3232 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | ||
3233 | "gns-proxy", | ||
3234 | "PROXY_CACERT"); | ||
3235 | return; | ||
3236 | } | ||
3237 | cafile = cafile_cfg; | ||
3238 | } | ||
3239 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3240 | "Using %s as CA\n", cafile); | ||
3241 | |||
3242 | gnutls_global_init (); | ||
3243 | gnutls_x509_crt_init (&proxy_ca.cert); | ||
3244 | gnutls_x509_privkey_init (&proxy_ca.key); | ||
3245 | |||
3246 | if ( (GNUNET_OK != load_cert_from_file (proxy_ca.cert, cafile)) || | ||
3247 | (GNUNET_OK != load_key_from_file (proxy_ca.key, cafile)) ) | ||
3248 | { | ||
3249 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
3250 | _("Failed to load SSL/TLS key and certificate from `%s'\n"), | ||
3251 | cafile); | ||
3252 | gnutls_x509_crt_deinit (proxy_ca.cert); | ||
3253 | gnutls_x509_privkey_deinit (proxy_ca.key); | ||
3254 | gnutls_global_deinit (); | ||
3255 | GNUNET_free_non_null (cafile_cfg); | ||
3256 | return; | ||
3257 | } | ||
3258 | GNUNET_free_non_null (cafile_cfg); | ||
3259 | if (NULL == (gns_handle = GNUNET_GNS_connect (cfg))) | ||
3260 | { | ||
3261 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
3262 | "Unable to connect to GNS!\n"); | ||
3263 | gnutls_x509_crt_deinit (proxy_ca.cert); | ||
3264 | gnutls_x509_privkey_deinit (proxy_ca.key); | ||
3265 | gnutls_global_deinit (); | ||
3266 | return; | ||
3267 | } | ||
3268 | identity = GNUNET_IDENTITY_connect (cfg, | ||
3269 | NULL, NULL); | ||
3270 | id_op = GNUNET_IDENTITY_get (identity, | ||
3271 | "gns-proxy", | ||
3272 | &identity_master_cb, | ||
3273 | NULL); | ||
3274 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | ||
3275 | } | 3220 | } |
3276 | 3221 | ||
3277 | 3222 | ||
@@ -3286,13 +3231,11 @@ int | |||
3286 | main (int argc, char *const *argv) | 3231 | main (int argc, char *const *argv) |
3287 | { | 3232 | { |
3288 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 3233 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
3289 | |||
3290 | GNUNET_GETOPT_option_ulong ('p', | 3234 | GNUNET_GETOPT_option_ulong ('p', |
3291 | "port", | 3235 | "port", |
3292 | NULL, | 3236 | NULL, |
3293 | gettext_noop ("listen on specified port (default: 7777)"), | 3237 | gettext_noop ("listen on specified port (default: 7777)"), |
3294 | &port), | 3238 | &port), |
3295 | |||
3296 | GNUNET_GETOPT_option_string ('a', | 3239 | GNUNET_GETOPT_option_string ('a', |
3297 | "authority", | 3240 | "authority", |
3298 | NULL, | 3241 | NULL, |