Commit e9bac34b56aea6eea4b4168054cd25aef86d0cc7
1 parent
3be44a48
Exists in
master
and in
3 other branches
Removing unused code.
Showing
28 changed files
with
24 additions
and
3654 deletions
Show diff stats
lib3270.cbp
| ... | ... | @@ -366,44 +366,8 @@ |
| 366 | 366 | <Unit filename="src/selection/selection.c"> |
| 367 | 367 | <Option compilerVar="CC" /> |
| 368 | 368 | </Unit> |
| 369 | - <Unit filename="src/ssl/crl.c"> | |
| 370 | - <Option compilerVar="CC" /> | |
| 371 | - </Unit> | |
| 372 | 369 | <Unit filename="src/ssl/crl.h" /> |
| 373 | - <Unit filename="src/ssl/linux/getcrl.c"> | |
| 374 | - <Option compilerVar="CC" /> | |
| 375 | - </Unit> | |
| 376 | - <Unit filename="src/ssl/linux/init.c"> | |
| 377 | - <Option compilerVar="CC" /> | |
| 378 | - </Unit> | |
| 379 | - <Unit filename="src/ssl/linux/ldap.c"> | |
| 380 | - <Option compilerVar="CC" /> | |
| 381 | - </Unit> | |
| 382 | 370 | <Unit filename="src/ssl/linux/private.h" /> |
| 383 | - <Unit filename="src/ssl/linux/url.c"> | |
| 384 | - <Option compilerVar="CC" /> | |
| 385 | - </Unit> | |
| 386 | - <Unit filename="src/ssl/negotiate.c"> | |
| 387 | - <Option compilerVar="CC" /> | |
| 388 | - </Unit> | |
| 389 | - <Unit filename="src/ssl/notify.c"> | |
| 390 | - <Option compilerVar="CC" /> | |
| 391 | - </Unit> | |
| 392 | - <Unit filename="src/ssl/properties.c"> | |
| 393 | - <Option compilerVar="CC" /> | |
| 394 | - </Unit> | |
| 395 | - <Unit filename="src/ssl/windows/getcrl.c"> | |
| 396 | - <Option compilerVar="CC" /> | |
| 397 | - </Unit> | |
| 398 | - <Unit filename="src/ssl/windows/http.c"> | |
| 399 | - <Option compilerVar="CC" /> | |
| 400 | - </Unit> | |
| 401 | - <Unit filename="src/ssl/windows/init.c"> | |
| 402 | - <Option compilerVar="CC" /> | |
| 403 | - </Unit> | |
| 404 | - <Unit filename="src/ssl/windows/ldap.c"> | |
| 405 | - <Option compilerVar="CC" /> | |
| 406 | - </Unit> | |
| 407 | 371 | <Unit filename="src/ssl/windows/private.h" /> |
| 408 | 372 | <Unit filename="src/testprogram/testprogram.c"> |
| 409 | 373 | <Option compilerVar="CC" /> | ... | ... |
src/core/host.c
| ... | ... | @@ -52,7 +52,6 @@ |
| 52 | 52 | #include "trace_dsc.h" |
| 53 | 53 | #include "utilc.h" |
| 54 | 54 | #include "xioc.h" |
| 55 | -#include "../ssl/crl.h" | |
| 56 | 55 | #include "screenc.h" |
| 57 | 56 | |
| 58 | 57 | #include <errno.h> |
| ... | ... | @@ -293,13 +292,10 @@ static void update_url(H3270 *hSession) |
| 293 | 292 | lib3270_write_event_trace(hSession,"Host URL was changed\nFrom: %s\nTo: %s\n",hSession->host.url,url); |
| 294 | 293 | lib3270_free(hSession->host.url); |
| 295 | 294 | hSession->host.url = url; |
| 296 | - | |
| 297 | -#if defined(HAVE_LIBSSLx) && defined(SSL_ENABLE_CRL_CHECK) | |
| 298 | - lib3270_crl_free(hSession); | |
| 299 | -#endif // SSL_ENABLE_CRL_CHECK | |
| 300 | - | |
| 301 | 295 | hSession->cbk.update_url(hSession, hSession->host.url); |
| 302 | 296 | |
| 297 | + hSession->network.module->reset(hSession); | |
| 298 | + | |
| 303 | 299 | } |
| 304 | 300 | |
| 305 | 301 | LIB3270_EXPORT const char * lib3270_get_associated_luname(const H3270 *hSession) | ... | ... |
src/core/linux/connect.c
| ... | ... | @@ -307,16 +307,6 @@ |
| 307 | 307 | // |
| 308 | 308 | hSession->ever_3270 = False; |
| 309 | 309 | |
| 310 | -#if defined(HAVE_LIBSSLx) | |
| 311 | - if(hSession->ssl.enabled) | |
| 312 | - { | |
| 313 | - hSession->ssl.host = 1; | |
| 314 | - if(ssl_init(hSession)) | |
| 315 | - return errno = ENOTCONN; | |
| 316 | - | |
| 317 | - } | |
| 318 | -#endif // HAVE_LIBSSL | |
| 319 | - | |
| 320 | 310 | // set options for inline out-of-band data and keepalives |
| 321 | 311 | int optval = 1; |
| 322 | 312 | if(hSession->network.module->setsockopt(hSession, SOL_SOCKET, SO_OOBINLINE, &optval, sizeof(optval)) < 0) | ... | ... |
src/core/properties/signed.c
| ... | ... | @@ -49,48 +49,6 @@ |
| 49 | 49 | return (int) lib3270_get_ssl_state(hSession); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - static int lib3270_set_ssl_minimum_protocol_version(H3270 *hSession, int value) | |
| 53 | - { | |
| 54 | -#ifdef HAVE_LIBSSLx | |
| 55 | - FAIL_IF_ONLINE(hSession); | |
| 56 | - hSession->ssl.protocol.min_version = value; | |
| 57 | - return 0; | |
| 58 | -#else | |
| 59 | - return ENOTSUP; | |
| 60 | -#endif // HAVE_LIBSSL | |
| 61 | - } | |
| 62 | - | |
| 63 | - static int lib3270_set_ssl_maximum_protocol_version(H3270 *hSession, int value) | |
| 64 | - { | |
| 65 | -#ifdef HAVE_LIBSSLx | |
| 66 | - FAIL_IF_ONLINE(hSession); | |
| 67 | - hSession->ssl.protocol.max_version = value; | |
| 68 | - return 0; | |
| 69 | -#else | |
| 70 | - return ENOTSUP; | |
| 71 | -#endif // HAVE_LIBSSL | |
| 72 | - } | |
| 73 | - | |
| 74 | - static int lib3270_get_ssl_minimum_protocol_version(const H3270 *hSession) | |
| 75 | - { | |
| 76 | -#ifdef HAVE_LIBSSLx | |
| 77 | - return hSession->ssl.protocol.min_version; | |
| 78 | -#else | |
| 79 | - errno = ENOTSUP; | |
| 80 | - return 0; | |
| 81 | -#endif // HAVE_LIBSSL | |
| 82 | - } | |
| 83 | - | |
| 84 | - static int lib3270_get_ssl_maximum_protocol_version(const H3270 *hSession) | |
| 85 | - { | |
| 86 | -#ifdef HAVE_LIBSSLx | |
| 87 | - return hSession->ssl.protocol.max_version; | |
| 88 | -#else | |
| 89 | - errno = ENOTSUP; | |
| 90 | - return 0; | |
| 91 | -#endif // HAVE_LIBSSL | |
| 92 | - } | |
| 93 | - | |
| 94 | 52 | const LIB3270_INT_PROPERTY * lib3270_get_int_properties_list(void) |
| 95 | 53 | { |
| 96 | 54 | |
| ... | ... | @@ -117,22 +75,6 @@ |
| 117 | 75 | .set = NULL // Set value. |
| 118 | 76 | }, |
| 119 | 77 | |
| 120 | - { | |
| 121 | - .name = "ssl_min_protocol_version", // Property name. | |
| 122 | - .description = N_( "ID of the minimum supported SSL protocol version" ), // Property description. | |
| 123 | - .default_value = 0, | |
| 124 | - .get = lib3270_get_ssl_minimum_protocol_version, // Get value. | |
| 125 | - .set = lib3270_set_ssl_minimum_protocol_version // Set value. | |
| 126 | - }, | |
| 127 | - | |
| 128 | - { | |
| 129 | - .name = "ssl_max_protocol_version", // Property name. | |
| 130 | - .description = N_( "ID of the maximum supported SSL protocol version" ), // Property description. | |
| 131 | - .default_value = 0, | |
| 132 | - .get = lib3270_get_ssl_maximum_protocol_version, // Get value. | |
| 133 | - .set = lib3270_set_ssl_maximum_protocol_version // Set value. | |
| 134 | - }, | |
| 135 | - | |
| 136 | 78 | { |
| 137 | 79 | .name = NULL, |
| 138 | 80 | .description = NULL, | ... | ... |
src/core/session.c
| ... | ... | @@ -42,7 +42,6 @@ |
| 42 | 42 | #include "kybdc.h" |
| 43 | 43 | #include "3270ds.h" |
| 44 | 44 | #include "popupsc.h" |
| 45 | -#include "../ssl/crl.h" | |
| 46 | 45 | #include <lib3270/trace.h> |
| 47 | 46 | #include <lib3270/log.h> |
| 48 | 47 | #include <lib3270/properties.h> |
| ... | ... | @@ -74,16 +73,6 @@ void lib3270_session_free(H3270 *h) |
| 74 | 73 | |
| 75 | 74 | shutdown_toggles(h); |
| 76 | 75 | |
| 77 | -#if defined(SSL_ENABLE_CRL_CHECK) && defined(HAVE_LIBSSLx) | |
| 78 | - if(h->ssl.crl.prefer) | |
| 79 | - { | |
| 80 | - free(h->ssl.crl.prefer); | |
| 81 | - h->ssl.crl.prefer = NULL; | |
| 82 | - } | |
| 83 | - | |
| 84 | - lib3270_crl_free(h); | |
| 85 | -#endif // SSL_ENABLE_CRL_CHECK | |
| 86 | - | |
| 87 | 76 | // Release network module |
| 88 | 77 | if(h->network.module) |
| 89 | 78 | { | ... | ... |
src/include/networking.h
| ... | ... | @@ -166,6 +166,11 @@ |
| 166 | 166 | /// @return String with the CRL certificate (release it with lib3270_free); NULL if not available. |
| 167 | 167 | char * (*getcrl)(const H3270 *hSession); |
| 168 | 168 | |
| 169 | + /// @brief Reset. | |
| 170 | + /// | |
| 171 | + /// Clear network module state (used when URL changes). | |
| 172 | + void (*reset)(H3270 *hSession); | |
| 173 | + | |
| 169 | 174 | } LIB3270_NET_MODULE; |
| 170 | 175 | |
| 171 | 176 | /** | ... | ... |
src/network_modules/default/main.c
| ... | ... | @@ -62,6 +62,9 @@ |
| 62 | 62 | return 0; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | + static void unsecure_network_reset(H3270 GNUC_UNUSED(*hSession)) { | |
| 66 | + } | |
| 67 | + | |
| 65 | 68 | ssize_t unsecure_network_send(H3270 *hSession, const void *buffer, size_t length) { |
| 66 | 69 | |
| 67 | 70 | ssize_t bytes = send(hSession->network.context->sock,buffer,length,0); |
| ... | ... | @@ -164,7 +167,8 @@ void lib3270_set_default_network_module(H3270 *hSession) { |
| 164 | 167 | .is_connected = unsecure_network_is_connected, |
| 165 | 168 | .getsockname = unsecure_network_getsockname, |
| 166 | 169 | .setsockopt = unsecure_network_setsockopt, |
| 167 | - .getsockopt = unsecure_network_getsockopt | |
| 170 | + .getsockopt = unsecure_network_getsockopt, | |
| 171 | + .reset = unsecure_network_reset | |
| 168 | 172 | }; |
| 169 | 173 | |
| 170 | 174 | debug("%s",__FUNCTION__); | ... | ... |
src/network_modules/openssl/main.c
| ... | ... | @@ -35,18 +35,21 @@ |
| 35 | 35 | #include "private.h" |
| 36 | 36 | |
| 37 | 37 | |
| 38 | -static void openssl_network_finalize(H3270 *hSession) { | |
| 39 | - | |
| 40 | - debug("%s",__FUNCTION__); | |
| 38 | +static void openssl_network_reset(H3270 *hSession) { | |
| 41 | 39 | |
| 42 | 40 | if(hSession->network.context) { |
| 41 | + lib3270_openssl_crl_free(hSession->network.context); | |
| 42 | + } | |
| 43 | + | |
| 44 | +} | |
| 43 | 45 | |
| 44 | - // Cleanupp | |
| 45 | - LIB3270_NET_CONTEXT *context = hSession->network.context; | |
| 46 | +static void openssl_network_finalize(H3270 *hSession) { | |
| 46 | 47 | |
| 47 | - lib3270_openssl_crl_free(context); | |
| 48 | + debug("%s",__FUNCTION__); | |
| 48 | 49 | |
| 49 | - // Release network context. | |
| 50 | + openssl_network_reset(hSession); | |
| 51 | + | |
| 52 | + if(hSession->network.context) { | |
| 50 | 53 | lib3270_free(hSession->network.context); |
| 51 | 54 | hSession->network.context = NULL; |
| 52 | 55 | } |
| ... | ... | @@ -346,7 +349,8 @@ void lib3270_set_libssl_network_module(H3270 *hSession) { |
| 346 | 349 | .setsockopt = openssl_network_setsockopt, |
| 347 | 350 | .getsockopt = openssl_network_getsockopt, |
| 348 | 351 | .getcert = openssl_network_getcert, |
| 349 | - .getcrl = openssl_network_getcrl | |
| 352 | + .getcrl = openssl_network_getcrl, | |
| 353 | + .reset = openssl_network_reset | |
| 350 | 354 | }; |
| 351 | 355 | |
| 352 | 356 | debug("%s",__FUNCTION__); | ... | ... |
src/network_modules/state.c
| ... | ... | @@ -50,15 +50,6 @@ LIB3270_EXPORT int lib3270_is_secure(const H3270 *hSession) |
| 50 | 50 | return lib3270_get_ssl_state(hSession) == LIB3270_SSL_SECURE; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | -#if defined(HAVE_LIBSSLx) | |
| 54 | -LIB3270_EXPORT long lib3270_get_SSL_verify_result(const H3270 *hSession) | |
| 55 | -{ | |
| 56 | - if(hSession->ssl.con) | |
| 57 | - return SSL_get_verify_result(hSession->ssl.con); | |
| 58 | - return -1; | |
| 59 | -} | |
| 60 | -#endif // HAVE_LIBSSL | |
| 61 | - | |
| 62 | 53 | LIB3270_EXPORT LIB3270_SSL_STATE lib3270_get_ssl_state(const H3270 *hSession) |
| 63 | 54 | { |
| 64 | 55 | return hSession->ssl.state; | ... | ... |
src/ssl/crl.c
| ... | ... | @@ -1,292 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | - * | |
| 28 | - */ | |
| 29 | - | |
| 30 | -#include <config.h> | |
| 31 | - | |
| 32 | -#include <internals.h> | |
| 33 | -#include <lib3270/log.h> | |
| 34 | -#include <lib3270/trace.h> | |
| 35 | -#include <lib3270/toggle.h> | |
| 36 | -#include <trace_dsc.h> | |
| 37 | -#include <array.h> | |
| 38 | - | |
| 39 | -#include "crl.h" | |
| 40 | - | |
| 41 | -/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 42 | - | |
| 43 | -#if defined(SSL_ENABLE_CRL_CHECK) && defined(HAVE_LIBSSL) | |
| 44 | - | |
| 45 | -void lib3270_crl_free(H3270 *hSession) | |
| 46 | -{ | |
| 47 | - if(hSession->ssl.crl.cert) | |
| 48 | - { | |
| 49 | - X509_CRL_free(hSession->ssl.crl.cert); | |
| 50 | - hSession->ssl.crl.cert = NULL; | |
| 51 | - } | |
| 52 | - | |
| 53 | - if(hSession->ssl.crl.url) | |
| 54 | - { | |
| 55 | - free(hSession->ssl.crl.url); | |
| 56 | - hSession->ssl.crl.url = NULL; | |
| 57 | - } | |
| 58 | - | |
| 59 | -} | |
| 60 | - | |
| 61 | -void lib3270_crl_free_if_expired(H3270 *hSession) | |
| 62 | -{ | |
| 63 | - if(!hSession->ssl.crl.cert) | |
| 64 | - return; | |
| 65 | - | |
| 66 | - // https://stackoverflow.com/questions/23407376/testing-x509-certificate-expiry-date-with-c | |
| 67 | - // X509_CRL_get_nextUpdate is deprecated in openssl 1.1.0 | |
| 68 | - #if OPENSSL_VERSION_NUMBER < 0x10100000L | |
| 69 | - const ASN1_TIME * next_update = X509_CRL_get_nextUpdate(hSession->ssl.crl.cert); | |
| 70 | - #else | |
| 71 | - const ASN1_TIME * next_update = X509_CRL_get0_nextUpdate(hSession->ssl.crl.cert); | |
| 72 | - #endif | |
| 73 | - | |
| 74 | - if(X509_cmp_current_time(next_update) == 1) | |
| 75 | - { | |
| 76 | - int day, sec; | |
| 77 | - if(ASN1_TIME_diff(&day, &sec, NULL, next_update)) | |
| 78 | - { | |
| 79 | - trace_ssl(hSession,"CRL is valid for %d day(s) and %d second(s)\n",day,sec); | |
| 80 | - return; | |
| 81 | - } | |
| 82 | - | |
| 83 | - trace_ssl(hSession,"Can't get CRL next update, discarding it\n"); | |
| 84 | - | |
| 85 | - } | |
| 86 | - else | |
| 87 | - { | |
| 88 | - trace_ssl(hSession,"CRL is no longer valid\n"); | |
| 89 | - } | |
| 90 | - | |
| 91 | - // Certificate is no longer valid, release it. | |
| 92 | - X509_CRL_free(hSession->ssl.crl.cert); | |
| 93 | - hSession->ssl.crl.cert = NULL; | |
| 94 | - | |
| 95 | -} | |
| 96 | - | |
| 97 | -int lib3270_crl_new_from_url(H3270 *hSession, void *ssl_error, const char *url) | |
| 98 | -{ | |
| 99 | - if(!(url && *url)) | |
| 100 | - return -1; | |
| 101 | - | |
| 102 | - lib3270_crl_free(hSession); // Just in case! | |
| 103 | - | |
| 104 | - // | |
| 105 | - // Get the new CRL | |
| 106 | - // | |
| 107 | - // https://stackoverflow.com/questions/10510850/how-to-verify-the-certificate-for-the-ongoing-ssl-session | |
| 108 | - // | |
| 109 | - trace_ssl(hSession,"Getting CRL from %s\n",url); | |
| 110 | - | |
| 111 | - hSession->ssl.crl.cert = lib3270_download_crl(hSession,(SSL_ERROR_MESSAGE *) ssl_error, url); | |
| 112 | - | |
| 113 | - if(hSession->ssl.crl.cert) | |
| 114 | - { | |
| 115 | - // Got CRL! | |
| 116 | - | |
| 117 | - // Update URL | |
| 118 | - if(hSession->ssl.crl.url) | |
| 119 | - lib3270_free(hSession->ssl.crl.url); | |
| 120 | - | |
| 121 | - hSession->ssl.crl.url = lib3270_strdup(url); | |
| 122 | - | |
| 123 | - // Add it to ssl store | |
| 124 | - if(lib3270_get_toggle(hSession,LIB3270_TOGGLE_SSL_TRACE)) | |
| 125 | - { | |
| 126 | - lib3270_autoptr(char) text = lib3270_get_ssl_crl_text(hSession); | |
| 127 | - | |
| 128 | - if(text) | |
| 129 | - trace_ssl(hSession,"\n%s\n",text); | |
| 130 | - | |
| 131 | - } | |
| 132 | - | |
| 133 | - // Add CRL in the store. | |
| 134 | - X509_STORE *store = SSL_CTX_get_cert_store(ssl_ctx); | |
| 135 | - if(X509_STORE_add_crl(store, hSession->ssl.crl.cert)) | |
| 136 | - { | |
| 137 | - trace_ssl(hSession,"CRL was added to context cert store\n"); | |
| 138 | - } | |
| 139 | - else | |
| 140 | - { | |
| 141 | - trace_ssl(hSession,"CRL was not added to context cert store\n"); | |
| 142 | - } | |
| 143 | - | |
| 144 | - return 0; | |
| 145 | - } | |
| 146 | - | |
| 147 | - trace_ssl(hSession,"Can't get CRL using %s\n",url); | |
| 148 | - | |
| 149 | - return -1; | |
| 150 | - | |
| 151 | -} | |
| 152 | - | |
| 153 | -/// @brief Load CRL from X509 certificate. | |
| 154 | -int lib3270_crl_new_from_x509(H3270 *hSession, void *ssl_error, X509 *cert) | |
| 155 | -{ | |
| 156 | - // References: | |
| 157 | - // | |
| 158 | - // http://www.zedwood.com/article/cpp-check-crl-for-revocation | |
| 159 | - // | |
| 160 | - lib3270_autoptr(CRL_DIST_POINTS) dist_points = (CRL_DIST_POINTS *) X509_get_ext_d2i(cert, NID_crl_distribution_points, NULL, NULL); | |
| 161 | - | |
| 162 | - if(!dist_points) | |
| 163 | - { | |
| 164 | - static const LIB3270_POPUP popup = { | |
| 165 | - .name = "SSL-NoDistPoints", | |
| 166 | - .type = LIB3270_NOTIFY_SECURE, | |
| 167 | - .summary = N_("Can't verify"), | |
| 168 | - .body = N_( "The host certificate doesn't have CRL distribution points" ) | |
| 169 | - }; | |
| 170 | - | |
| 171 | - ((SSL_ERROR_MESSAGE *) ssl_error)->popup = &popup; | |
| 172 | - return EACCES; | |
| 173 | - } | |
| 174 | - | |
| 175 | - if(lib3270_crl_new_from_dist_points(hSession, ssl_error, dist_points)) | |
| 176 | - return EACCES; | |
| 177 | - | |
| 178 | - return 0; | |
| 179 | -} | |
| 180 | - | |
| 181 | -int lib3270_crl_new_from_dist_points(H3270 *hSession, void *ssl_error, CRL_DIST_POINTS * dist_points) | |
| 182 | -{ | |
| 183 | - // | |
| 184 | - // Reference: | |
| 185 | - // | |
| 186 | - // https://nougat.cablelabs.com/DLNA-RUI/openssl/commit/57912ed329f870b237f2fd9f2de8dec3477d1729 | |
| 187 | - // | |
| 188 | - size_t ix; | |
| 189 | - int i; | |
| 190 | - | |
| 191 | - lib3270_autoptr(LIB3270_STRING_ARRAY) uris = lib3270_string_array_new(); | |
| 192 | - | |
| 193 | - for(ix = 0; ix < (size_t) sk_DIST_POINT_num(dist_points); ix++) { | |
| 194 | - | |
| 195 | - DIST_POINT *dp = sk_DIST_POINT_value(dist_points, ix); | |
| 196 | - | |
| 197 | - if(!dp->distpoint || dp->distpoint->type != 0) | |
| 198 | - continue; | |
| 199 | - | |
| 200 | - GENERAL_NAMES *gens = dp->distpoint->name.fullname; | |
| 201 | - | |
| 202 | - for (i = 0; i < sk_GENERAL_NAME_num(gens); i++) | |
| 203 | - { | |
| 204 | - int gtype; | |
| 205 | - GENERAL_NAME *gen = sk_GENERAL_NAME_value(gens, i); | |
| 206 | - ASN1_STRING *uri = GENERAL_NAME_get0_value(gen, >ype); | |
| 207 | - | |
| 208 | - if(uri && gtype == GEN_URI) | |
| 209 | - { | |
| 210 | - int length = ASN1_STRING_length(uri); | |
| 211 | - | |
| 212 | -#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) // OpenSSL 1.1.0+ | |
| 213 | - const unsigned char * data = ASN1_STRING_get0_data(uri); | |
| 214 | -#else | |
| 215 | - const unsigned char * data = ASN1_STRING_data(uri); | |
| 216 | -#endif // OpenSSL 1.1.0+ | |
| 217 | - | |
| 218 | - if(data && length > 0) | |
| 219 | - lib3270_string_array_append_with_length(uris,(char *) data, (size_t) length); | |
| 220 | - | |
| 221 | - } | |
| 222 | - | |
| 223 | - } | |
| 224 | - | |
| 225 | - } | |
| 226 | - | |
| 227 | -#ifdef DEBUG | |
| 228 | - { | |
| 229 | - for(ix = 0; ix < uris->length; ix++) | |
| 230 | - { | |
| 231 | - debug("%u: %s", (unsigned int) ix, uris->str[ix]); | |
| 232 | - } | |
| 233 | - } | |
| 234 | -#endif // DEBUG | |
| 235 | - | |
| 236 | - if(hSession->ssl.crl.url) | |
| 237 | - { | |
| 238 | - // Check if the current URL is still valid. | |
| 239 | - for(ix = 0; ix < uris->length; ix++) | |
| 240 | - { | |
| 241 | - if(!strcmp(hSession->ssl.crl.url,uris->str[ix])) | |
| 242 | - { | |
| 243 | - trace_ssl(hSession,"Keeping CRL from %s\n",hSession->ssl.crl.url); | |
| 244 | - return 0; | |
| 245 | - } | |
| 246 | - } | |
| 247 | - | |
| 248 | - trace_ssl(hSession,"Discarding invalid CRL from %s\n",hSession->ssl.crl.url); | |
| 249 | - | |
| 250 | - // The URL is invalid or not to this cert, remove it! | |
| 251 | - lib3270_free(hSession->ssl.crl.url); | |
| 252 | - hSession->ssl.crl.url = NULL; | |
| 253 | - } | |
| 254 | - | |
| 255 | - // | |
| 256 | - // Downloading CRLs | |
| 257 | - // | |
| 258 | - if(hSession->ssl.crl.download) | |
| 259 | - { | |
| 260 | - if(hSession->ssl.crl.prefer && *hSession->ssl.crl.prefer) | |
| 261 | - { | |
| 262 | - size_t length = strlen(hSession->ssl.crl.prefer); | |
| 263 | - | |
| 264 | - for(ix = 0; ix < uris->length; ix++) | |
| 265 | - { | |
| 266 | - if(!strncmp(uris->str[ix],hSession->ssl.crl.prefer,length)) | |
| 267 | - { | |
| 268 | - trace_ssl(hSession,"Trying preferred URL %s\n",uris->str[ix]); | |
| 269 | - if(lib3270_crl_new_from_url(hSession, ssl_error, uris->str[ix]) == 0) | |
| 270 | - return 0; | |
| 271 | - } | |
| 272 | - | |
| 273 | - } | |
| 274 | - | |
| 275 | - } | |
| 276 | - | |
| 277 | - // Can't load, try all of them. | |
| 278 | - for(ix = 0; ix < uris->length; ix++) | |
| 279 | - { | |
| 280 | - trace_ssl(hSession,"Trying CRL from %s\n",uris->str[ix]); | |
| 281 | - if(lib3270_crl_new_from_url(hSession, ssl_error, uris->str[ix]) == 0) | |
| 282 | - return 0; | |
| 283 | - } | |
| 284 | - | |
| 285 | - return -1; | |
| 286 | - } | |
| 287 | - | |
| 288 | - return 0; | |
| 289 | - | |
| 290 | -} | |
| 291 | - | |
| 292 | -#endif // SSL_ENABLE_CRL_CHECK && HAVE_LIBSSL |
src/ssl/crl.h
| ... | ... | @@ -1,84 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software G3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral ', conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como private.h e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas de Mendonça) | |
| 27 | - * | |
| 28 | - */ | |
| 29 | - | |
| 30 | -#ifdef WIN32 | |
| 31 | - #include <winsock2.h> | |
| 32 | - #include <windows.h> | |
| 33 | -#endif // WIN32 | |
| 34 | - | |
| 35 | -#include <config.h> /* autoconf settings */ | |
| 36 | -#include <lib3270.h> /* lib3270 API calls and defs */ | |
| 37 | - | |
| 38 | -#if defined(HAVE_LIBSSLx) | |
| 39 | - | |
| 40 | - #include <openssl/ssl.h> | |
| 41 | - #include <openssl/err.h> | |
| 42 | - | |
| 43 | - /** | |
| 44 | - * @brief X509 auto-cleanup. | |
| 45 | - */ | |
| 46 | - static inline void lib3270_autoptr_cleanup_X509(X509 **ptr) | |
| 47 | - { | |
| 48 | - if(*ptr) | |
| 49 | - X509_free(*ptr); | |
| 50 | - } | |
| 51 | - | |
| 52 | - /** | |
| 53 | - * @brief Dist points auto-cleanup. | |
| 54 | - */ | |
| 55 | - static inline void lib3270_autoptr_cleanup_CRL_DIST_POINTS(CRL_DIST_POINTS **ptr) | |
| 56 | - { | |
| 57 | - if(*ptr) | |
| 58 | - CRL_DIST_POINTS_free(*ptr); | |
| 59 | - } | |
| 60 | - | |
| 61 | - | |
| 62 | -#endif // HAVE_LIBSSL | |
| 63 | - | |
| 64 | -#if defined(SSL_ENABLE_CRL_CHECK) && defined(HAVE_LIBSSLx) | |
| 65 | - | |
| 66 | - /// @brief Unconditional release of the session CRL. | |
| 67 | - LIB3270_INTERNAL void lib3270_crl_free(H3270 *hSession); | |
| 68 | - | |
| 69 | - /// @brief Load CRL from URL. | |
| 70 | - LIB3270_INTERNAL int lib3270_crl_new_from_url(H3270 *hSession, void *ssl_error, const char *url); | |
| 71 | - | |
| 72 | - /// @brief Load CRL from X509 certificate. | |
| 73 | - LIB3270_INTERNAL int lib3270_crl_new_from_x509(H3270 *hSession, void *ssl_error, X509 *cert); | |
| 74 | - | |
| 75 | - /// @brief Load CRL from distribution points. | |
| 76 | - LIB3270_INTERNAL int lib3270_crl_new_from_dist_points(H3270 *hSession, void *ssl_error, CRL_DIST_POINTS * dist_points); | |
| 77 | - | |
| 78 | - LIB3270_INTERNAL X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, const char *url); | |
| 79 | - | |
| 80 | - | |
| 81 | -#endif // SSL_ENABLE_CRL_CHECK && HAVE_LIBSSL | |
| 82 | - | |
| 83 | - | |
| 84 | - |
src/ssl/linux/getcrl.c
| ... | ... | @@ -1,144 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | - * | |
| 28 | - * | |
| 29 | - * References: | |
| 30 | - * | |
| 31 | - * http://www.openssl.org/docs/ssl/ | |
| 32 | - * https://stackoverflow.com/questions/4389954/does-openssl-automatically-handle-crls-certificate-revocation-lists-now | |
| 33 | - * | |
| 34 | - */ | |
| 35 | - | |
| 36 | -#include "private.h" | |
| 37 | - | |
| 38 | -#if defined(HAVE_LIBSSL) && defined(SSL_ENABLE_CRL_CHECK) | |
| 39 | - | |
| 40 | -/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 41 | - | |
| 42 | -static inline void lib3270_autoptr_cleanup_FILE(FILE **file) | |
| 43 | -{ | |
| 44 | - if(*file) | |
| 45 | - fclose(*file); | |
| 46 | -} | |
| 47 | - | |
| 48 | -X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, const char *consturl) | |
| 49 | -{ | |
| 50 | - X509_CRL * x509_crl = NULL; | |
| 51 | - | |
| 52 | - if(!(consturl && *consturl)) | |
| 53 | - { | |
| 54 | - static const LIB3270_POPUP popup = { | |
| 55 | - .type = LIB3270_NOTIFY_SECURE, | |
| 56 | - .name = "SSL-INVCRLURL", | |
| 57 | - .summary = N_( "Can't open CRL File" ), | |
| 58 | - .body = N_("The URL for the CRL is undefined or empty") | |
| 59 | - }; | |
| 60 | - | |
| 61 | - message->code = hSession->ssl.error = 0; | |
| 62 | - message->popup = &popup; | |
| 63 | - errno = ENOENT; | |
| 64 | - return NULL; | |
| 65 | - } | |
| 66 | - | |
| 67 | - if(strncasecmp(consturl,"file://",7) == 0) | |
| 68 | - { | |
| 69 | - lib3270_autoptr(FILE) hCRL = fopen(consturl+7,"r"); | |
| 70 | - | |
| 71 | - if(!hCRL) | |
| 72 | - { | |
| 73 | - // Can't open CRL File. | |
| 74 | - int err = errno; | |
| 75 | - | |
| 76 | - static const LIB3270_POPUP popup = { | |
| 77 | - .type = LIB3270_NOTIFY_SECURE, | |
| 78 | - .name = "SSL-CRLOPEN", | |
| 79 | - .summary = N_( "Can't open CRL File" ) | |
| 80 | - }; | |
| 81 | - | |
| 82 | - message->code = hSession->ssl.error = 0; | |
| 83 | - message->popup = &popup; | |
| 84 | - | |
| 85 | - trace_ssl(hSession,"Can't open %s: %s\n",consturl,strerror(err)); | |
| 86 | - | |
| 87 | - return NULL; | |
| 88 | - | |
| 89 | - } | |
| 90 | - | |
| 91 | - trace_ssl(hSession,"Loading CRL from %s\n",consturl+7); | |
| 92 | - if(d2i_X509_CRL_fp(hCRL, &x509_crl)) | |
| 93 | - { | |
| 94 | - static const LIB3270_POPUP popup = { | |
| 95 | - .type = LIB3270_NOTIFY_SECURE, | |
| 96 | - .name = "SSL-CRLDECODE", | |
| 97 | - .summary = N_( "Can't decode CRL" ) | |
| 98 | - }; | |
| 99 | - message->code = hSession->ssl.error = ERR_get_error(); | |
| 100 | - message->popup = &popup; | |
| 101 | - lib3270_write_log(hSession,"ssl","%s: %s",consturl, popup.summary); | |
| 102 | - return NULL; | |
| 103 | - } | |
| 104 | - | |
| 105 | - } | |
| 106 | -#ifdef HAVE_LDAP | |
| 107 | - else if(strncasecmp(consturl,"ldap://",7) == 0 && strlen(consturl) > 8) | |
| 108 | - { | |
| 109 | - return get_crl_using_ldap(hSession, message, consturl); | |
| 110 | - | |
| 111 | - } | |
| 112 | -#endif // HAVE_LDAP | |
| 113 | - else | |
| 114 | - { | |
| 115 | -#ifdef HAVE_LIBCURL | |
| 116 | - | |
| 117 | - return get_crl_using_url(hSession, message, consturl); | |
| 118 | - | |
| 119 | -#else | |
| 120 | - // Can't get CRL. | |
| 121 | - | |
| 122 | - message->error = hSession->ssl.error = 0; | |
| 123 | - | |
| 124 | - if(!(message->text && message->description)) | |
| 125 | - message->title = _( "Security error" ); | |
| 126 | - | |
| 127 | - if(!message->text) | |
| 128 | - message->text = _( "Unexpected or invalid CRL URL" ); | |
| 129 | - | |
| 130 | - if(!message->description) | |
| 131 | - message->description = _("The URL scheme is unknown"); | |
| 132 | - | |
| 133 | - trace_ssl(hSession,"%s: The URL scheme is unknown",consturl); | |
| 134 | - | |
| 135 | - errno = EINVAL; | |
| 136 | - return NULL; | |
| 137 | -#endif // HAVE_LIBCURL | |
| 138 | - } | |
| 139 | - | |
| 140 | - return x509_crl; | |
| 141 | - | |
| 142 | -} | |
| 143 | - | |
| 144 | -#endif // HAVE_LIBSSL && SSL_ENABLE_CRL_CHECK |
src/ssl/linux/ldap.c
| ... | ... | @@ -1,241 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | - * | |
| 28 | - * | |
| 29 | - * References: | |
| 30 | - * | |
| 31 | - * http://www.openssl.org/docs/ssl/ | |
| 32 | - * https://stackoverflow.com/questions/4389954/does-openssl-automatically-handle-crls-certificate-revocation-lists-now | |
| 33 | - * | |
| 34 | - */ | |
| 35 | - | |
| 36 | -#include <config.h> | |
| 37 | -#include <internals.h> | |
| 38 | -#include <lib3270/log.h> | |
| 39 | -#include <lib3270/trace.h> | |
| 40 | -#include <lib3270/toggle.h> | |
| 41 | - | |
| 42 | -#include "utilc.h" | |
| 43 | - | |
| 44 | -#if defined(HAVE_LIBSSL) && defined(SSL_ENABLE_CRL_CHECK) && defined(HAVE_LDAP) | |
| 45 | - | |
| 46 | -#include <openssl/ssl.h> | |
| 47 | -#include <openssl/err.h> | |
| 48 | -#include <openssl/x509_vfy.h> | |
| 49 | -#include <openssl/x509.h> | |
| 50 | - | |
| 51 | -#define LDAP_DEPRECATED 1 | |
| 52 | -#include <ldap.h> | |
| 53 | - | |
| 54 | -/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 55 | - | |
| 56 | -static inline void lib3270_autoptr_cleanup_LDAPMessage(LDAPMessage **message) | |
| 57 | -{ | |
| 58 | - debug("%s(%p)",__FUNCTION__,*message); | |
| 59 | - if(message) | |
| 60 | - ldap_msgfree(*message); | |
| 61 | - *message = NULL; | |
| 62 | -} | |
| 63 | - | |
| 64 | -static inline void lib3270_autoptr_cleanup_LDAP(LDAP **ld) | |
| 65 | -{ | |
| 66 | - debug("%s(%p)",__FUNCTION__,*ld); | |
| 67 | - if(*ld) | |
| 68 | - ldap_unbind_ext(*ld, NULL, NULL); | |
| 69 | - *ld = NULL; | |
| 70 | -} | |
| 71 | - | |
| 72 | -static inline void lib3270_autoptr_cleanup_BerElement(BerElement **ber) | |
| 73 | -{ | |
| 74 | - debug("%s(%p)",__FUNCTION__,*ber); | |
| 75 | - if(*ber) | |
| 76 | - ber_free(*ber, 0); | |
| 77 | - *ber = NULL; | |
| 78 | -} | |
| 79 | - | |
| 80 | -static inline void lib3270_autoptr_cleanup_LDAPPTR(char **ptr) | |
| 81 | -{ | |
| 82 | - debug("%s(%p)",__FUNCTION__,*ptr); | |
| 83 | - if(*ptr) | |
| 84 | - ldap_memfree(*ptr); | |
| 85 | - *ptr = NULL; | |
| 86 | -} | |
| 87 | - | |
| 88 | -LIB3270_INTERNAL X509_CRL * get_crl_using_ldap(H3270 *hSession, SSL_ERROR_MESSAGE * message, const char *consturl) | |
| 89 | -{ | |
| 90 | - X509_CRL * x509_crl = NULL; | |
| 91 | - | |
| 92 | - int rc; | |
| 93 | - lib3270_autoptr(char) url = lib3270_unescape(consturl); | |
| 94 | - char * base = strchr(url+7,'/'); | |
| 95 | - char * attrs[] = { NULL, NULL }; | |
| 96 | - | |
| 97 | - if(!base) | |
| 98 | - { | |
| 99 | - message->error = hSession->ssl.error = 0; | |
| 100 | - message->title = _( "Security error" ); | |
| 101 | - message->text = _( "No DN of the entry at which to start the search on the URL" ); | |
| 102 | - message->description = _( "The URL argument should be in the format ldap://[HOST]/[DN]?attribute" ); | |
| 103 | - errno = EINVAL; | |
| 104 | - return NULL; | |
| 105 | - } | |
| 106 | - | |
| 107 | - *(base++) = 0; | |
| 108 | - attrs[0] = strchr(base,'?'); | |
| 109 | - | |
| 110 | - if(!base) | |
| 111 | - { | |
| 112 | - message->error = hSession->ssl.error = 0; | |
| 113 | - message->title = _( "Security error" ); | |
| 114 | - message->text = _( "No LDAP attribute on the URL" ); | |
| 115 | - message->description = _( "The URL argument should be in the format ldap://[HOST]/[DN]?attribute" ); | |
| 116 | - errno = EINVAL; | |
| 117 | - return NULL; | |
| 118 | - } | |
| 119 | - | |
| 120 | - *(attrs[0]++) = 0; | |
| 121 | - | |
| 122 | - debug("host: \"%s\"",url); | |
| 123 | - debug("Base: \"%s\"",base); | |
| 124 | - debug("Attr: \"%s\"",attrs[0]); | |
| 125 | - | |
| 126 | - // Do LDAP Query | |
| 127 | - LDAP __attribute__ ((__cleanup__(lib3270_autoptr_cleanup_LDAP))) *ld = NULL; | |
| 128 | - BerElement __attribute__ ((__cleanup__(lib3270_autoptr_cleanup_BerElement))) * ber = NULL; | |
| 129 | - | |
| 130 | - rc = ldap_initialize(&ld, url); | |
| 131 | - if(rc != LDAP_SUCCESS) | |
| 132 | - { | |
| 133 | - message->error = hSession->ssl.error = 0; | |
| 134 | - message->title = _( "Security error" ); | |
| 135 | - message->text = _( "Can't initialize LDAP" ); | |
| 136 | - message->description = ldap_err2string(rc); | |
| 137 | - lib3270_write_log(hSession,"ssl","%s: %s",url, message->description); | |
| 138 | - return NULL; | |
| 139 | - } | |
| 140 | - | |
| 141 | - unsigned long version = LDAP_VERSION3; | |
| 142 | - rc = ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION,(void *) &version); | |
| 143 | - if(rc != LDAP_SUCCESS) { | |
| 144 | - message->error = hSession->ssl.error = 0; | |
| 145 | - message->title = _( "Security error" ); | |
| 146 | - message->text = _( "Can't set LDAP protocol version" ); | |
| 147 | - message->description = ldap_err2string(rc); | |
| 148 | - lib3270_write_log(hSession,"ssl","%s: %s",url, message->description); | |
| 149 | - return NULL; | |
| 150 | - } | |
| 151 | - | |
| 152 | - rc = ldap_simple_bind_s(ld, "", ""); | |
| 153 | - if(rc != LDAP_SUCCESS) | |
| 154 | - { | |
| 155 | - message->error = hSession->ssl.error = 0; | |
| 156 | - message->title = _( "Security error" ); | |
| 157 | - message->text = _( "Can't bind to LDAP server" ); | |
| 158 | - message->description = ldap_err2string(rc); | |
| 159 | - lib3270_write_log(hSession,"ssl","%s: %s",url, message->description); | |
| 160 | - return NULL; | |
| 161 | - } | |
| 162 | - | |
| 163 | - lib3270_autoptr(LDAPMessage) results = NULL; | |
| 164 | - rc = ldap_search_ext_s( | |
| 165 | - ld, // Specifies the LDAP pointer returned by a previous call to ldap_init(), ldap_ssl_init(), or ldap_open(). | |
| 166 | - base, // Specifies the DN of the entry at which to start the search. | |
| 167 | - LDAP_SCOPE_BASE, // Specifies the scope of the search. | |
| 168 | - NULL, // Specifies a string representation of the filter to apply in the search. | |
| 169 | - (char **) &attrs, // Specifies a null-terminated array of character string attribute types to return from entries that match filter. | |
| 170 | - 0, // Should be set to 1 to request attribute types only. Set to 0 to request both attributes types and attribute values. | |
| 171 | - NULL, | |
| 172 | - NULL, | |
| 173 | - NULL, | |
| 174 | - 0, | |
| 175 | - &results | |
| 176 | - ); | |
| 177 | - | |
| 178 | - if(rc != LDAP_SUCCESS) | |
| 179 | - { | |
| 180 | - message->error = hSession->ssl.error = 0; | |
| 181 | - message->title = _( "Security error" ); | |
| 182 | - message->text = _( "Can't search LDAP server" ); | |
| 183 | - message->description = ldap_err2string(rc); | |
| 184 | - lib3270_write_log(hSession,"ssl","%s: %s",url, message->description); | |
| 185 | - return NULL; | |
| 186 | - } | |
| 187 | - | |
| 188 | - char __attribute__ ((__cleanup__(lib3270_autoptr_cleanup_LDAPPTR))) *attr = ldap_first_attribute(ld, results, &ber); | |
| 189 | - if(!attr) | |
| 190 | - { | |
| 191 | - message->error = hSession->ssl.error = 0; | |
| 192 | - message->title = _( "Security error" ); | |
| 193 | - message->text = _( "Can't get LDAP attribute" ); | |
| 194 | - message->description = _("Search did not produce any attributes."); | |
| 195 | - lib3270_write_log(hSession,"ssl","%s: %s",url, message->description); | |
| 196 | - errno = ENOENT; | |
| 197 | - return NULL; | |
| 198 | - } | |
| 199 | - | |
| 200 | - struct berval ** value = ldap_get_values_len(ld, results, attr); | |
| 201 | - if(!value) | |
| 202 | - { | |
| 203 | - message->error = hSession->ssl.error = 0; | |
| 204 | - message->title = _( "Security error" ); | |
| 205 | - message->text = _( "Can't get LDAP attribute" ); | |
| 206 | - message->description = _("Search did not produce any values."); | |
| 207 | - lib3270_write_log(hSession,"ssl","%s: %s",url, message->description); | |
| 208 | - errno = ENOENT; | |
| 209 | - return NULL; | |
| 210 | - } | |
| 211 | - | |
| 212 | - if(lib3270_get_toggle(hSession,LIB3270_TOGGLE_SSL_TRACE)) | |
| 213 | - { | |
| 214 | - lib3270_trace_data( | |
| 215 | - hSession, | |
| 216 | - "CRL Data received from LDAP server", | |
| 217 | - (const unsigned char *) value[0]->bv_val, | |
| 218 | - value[0]->bv_len | |
| 219 | - ); | |
| 220 | - } | |
| 221 | - | |
| 222 | - // Precisa salvar uma cópia porque d2i_X509_CRL modifica o ponteiro. | |
| 223 | - const unsigned char *crl_data = (const unsigned char *) value[0]->bv_val; | |
| 224 | - | |
| 225 | - if(!d2i_X509_CRL(&x509_crl, &crl_data, value[0]->bv_len)) | |
| 226 | - { | |
| 227 | - message->error = hSession->ssl.error = ERR_get_error(); | |
| 228 | - message->title = _( "Security error" ); | |
| 229 | - message->text = _( "Can't decode certificate revocation list" ); | |
| 230 | - lib3270_write_log(hSession,"ssl","%s: %s",url, message->text); | |
| 231 | - ldap_value_free_len(value); | |
| 232 | - return NULL; | |
| 233 | - } | |
| 234 | - | |
| 235 | - ldap_value_free_len(value); | |
| 236 | - | |
| 237 | - return x509_crl; | |
| 238 | - | |
| 239 | -} | |
| 240 | - | |
| 241 | -#endif // HAVE_LIBSSL && SSL_ENABLE_CRL_CHECK && HAVE_LDAP |
src/ssl/linux/private.h
| ... | ... | @@ -1,63 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software G3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral ', conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como private.h e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas de Mendonça) | |
| 27 | - * | |
| 28 | - */ | |
| 29 | - | |
| 30 | -#ifndef LIB3270_LINUX_SSL_PRIVATE_H_INCLUDED | |
| 31 | - | |
| 32 | - #define LIB3270_LINUX_SSL_PRIVATE_H_INCLUDED | |
| 33 | - | |
| 34 | - #include <config.h> | |
| 35 | - | |
| 36 | - #include <openssl/ssl.h> | |
| 37 | - #include <openssl/err.h> | |
| 38 | - #include <openssl/x509_vfy.h> | |
| 39 | - #include <openssl/x509.h> | |
| 40 | - | |
| 41 | - #include <internals.h> | |
| 42 | - #include <trace_dsc.h> | |
| 43 | - #include <errno.h> | |
| 44 | - #include <lib3270.h> | |
| 45 | - #include <lib3270/trace.h> | |
| 46 | - #include <lib3270/log.h> | |
| 47 | - | |
| 48 | - #if defined(HAVE_LIBSSL) && defined(HAVE_LDAP) | |
| 49 | - | |
| 50 | - /// @brief Use libldap to get CRL. | |
| 51 | - LIB3270_INTERNAL X509_CRL * get_crl_using_ldap(H3270 *hSession, SSL_ERROR_MESSAGE * message, const char *consturl); | |
| 52 | - | |
| 53 | - #endif // HAVE_LDAP | |
| 54 | - | |
| 55 | - #if defined (HAVE_LIBSSLx) && defined(HAVE_LIBCURL) | |
| 56 | - | |
| 57 | - /// @brief Use libcurl to get CRL. | |
| 58 | - LIB3270_INTERNAL X509_CRL * get_crl_using_url(H3270 *hSession, SSL_ERROR_MESSAGE * message, const char *consturl); | |
| 59 | - | |
| 60 | - #endif // HAVE_LIBCURL | |
| 61 | - | |
| 62 | - | |
| 63 | -#endif // !LIB3270_LINUX_SSL_PRIVATE_H_INCLUDED |
src/ssl/linux/url.c
| ... | ... | @@ -1,146 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | - * | |
| 28 | - * | |
| 29 | - * References: | |
| 30 | - * | |
| 31 | - * http://www.openssl.org/docs/ssl/ | |
| 32 | - * https://stackoverflow.com/questions/4389954/does-openssl-automatically-handle-crls-certificate-revocation-lists-now | |
| 33 | - * | |
| 34 | - */ | |
| 35 | - | |
| 36 | -#include <config.h> | |
| 37 | - | |
| 38 | -#if defined(HAVE_LIBSSL) && defined(SSL_ENABLE_CRL_CHECK) && defined(HAVE_LIBCURL) | |
| 39 | - | |
| 40 | -#include "private.h" | |
| 41 | -#include <curl/curl.h> | |
| 42 | -#include <lib3270/toggle.h> | |
| 43 | - | |
| 44 | -#define CRL_DATA_LENGTH 2048 | |
| 45 | - | |
| 46 | -/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 47 | - | |
| 48 | -static inline void lib3270_autoptr_cleanup_BIO(BIO **ptr) | |
| 49 | -{ | |
| 50 | - debug("%s(%p)",__FUNCTION__,*ptr); | |
| 51 | - if(*ptr) | |
| 52 | - BIO_free_all(*ptr); | |
| 53 | - *ptr = NULL; | |
| 54 | -} | |
| 55 | - | |
| 56 | -LIB3270_INTERNAL X509_CRL * get_crl_using_url(H3270 *hSession, SSL_ERROR_MESSAGE * message, const char *consturl) | |
| 57 | -{ | |
| 58 | - X509_CRL * x509_crl = NULL; | |
| 59 | - | |
| 60 | - size_t szText = 0; | |
| 61 | - const char * error_message = NULL; | |
| 62 | - lib3270_autoptr(char) httpText = lib3270_get_from_url(hSession, consturl, &szText, &error_message); | |
| 63 | - | |
| 64 | - if(!httpText) | |
| 65 | - { | |
| 66 | - LIB3270_POPUP popup = { | |
| 67 | - .type = LIB3270_NOTIFY_SECURE, | |
| 68 | - .name = "SSL-CantGetCRL", | |
| 69 | - .summary = N_( "Error getting certificate revocation list" ), | |
| 70 | - .body = error_message | |
| 71 | - }; | |
| 72 | - message->popup = &popup; | |
| 73 | - return NULL; | |
| 74 | - } | |
| 75 | - | |
| 76 | - if(lib3270_get_toggle(hSession,LIB3270_TOGGLE_SSL_TRACE)) | |
| 77 | - lib3270_trace_data(hSession,"CRL Data",(const unsigned char *) httpText, (unsigned int) szText); | |
| 78 | - | |
| 79 | - if(strncasecmp(consturl,"ldap://",7) == 0) | |
| 80 | - { | |
| 81 | - // It's an LDAP query, assumes a base64 data. | |
| 82 | - char * data = strstr((char *) httpText,":: "); | |
| 83 | - if(!data) | |
| 84 | - { | |
| 85 | - static const LIB3270_POPUP popup = { | |
| 86 | - .type = LIB3270_NOTIFY_SECURE, | |
| 87 | - .summary = N_( "Got a bad formatted certificate revocation list from LDAP server" ) | |
| 88 | - }; | |
| 89 | - | |
| 90 | - message->code = hSession->ssl.error = ERR_get_error(); | |
| 91 | - message->popup = &popup; | |
| 92 | - lib3270_write_log(hSession,"ssl","%s: invalid format:\n%s\n", consturl, httpText); | |
| 93 | - errno = EINVAL; | |
| 94 | - return NULL; | |
| 95 | - } | |
| 96 | - data += 3; | |
| 97 | - | |
| 98 | - lib3270_autoptr(BIO) bio = BIO_new_mem_buf(httpText,-1); | |
| 99 | - | |
| 100 | - BIO * b64 = BIO_new(BIO_f_base64()); | |
| 101 | - bio = BIO_push(b64, bio); | |
| 102 | - | |
| 103 | - BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); | |
| 104 | - | |
| 105 | - if(!d2i_X509_CRL_bio(bio, &x509_crl)) | |
| 106 | - { | |
| 107 | - static const LIB3270_POPUP popup = { | |
| 108 | - .type = LIB3270_NOTIFY_SECURE, | |
| 109 | - .summary = N_( "Can't decode certificate revocation list got from LDAP server" ) | |
| 110 | - }; | |
| 111 | - | |
| 112 | - message->code = hSession->ssl.error = ERR_get_error(); | |
| 113 | - message->popup = &popup; | |
| 114 | - | |
| 115 | - lib3270_write_log(hSession,"ssl","%s: %s",consturl, popup.summary); | |
| 116 | - errno = EINVAL; | |
| 117 | - return NULL; | |
| 118 | - } | |
| 119 | - | |
| 120 | - } | |
| 121 | - else | |
| 122 | - { | |
| 123 | - // CRL File, convert it | |
| 124 | - // Copy the pointer because d2i_X509_CRL changes the value!!! | |
| 125 | - const unsigned char *crl_data = (const unsigned char *) httpText; | |
| 126 | - | |
| 127 | - if(!d2i_X509_CRL(&x509_crl, &crl_data, szText)) | |
| 128 | - { | |
| 129 | - static const LIB3270_POPUP popup = { | |
| 130 | - .type = LIB3270_NOTIFY_SECURE, | |
| 131 | - .summary = N_( "Can't decode certificate revocation list" ) | |
| 132 | - }; | |
| 133 | - | |
| 134 | - message->code = hSession->ssl.error = ERR_get_error(); | |
| 135 | - message->popup = &popup; | |
| 136 | - lib3270_write_log(hSession,"ssl","%s: %s",consturl, popup.summary); | |
| 137 | - return NULL; | |
| 138 | - } | |
| 139 | - | |
| 140 | - } | |
| 141 | - | |
| 142 | - return x509_crl; | |
| 143 | - | |
| 144 | -} | |
| 145 | - | |
| 146 | -#endif // HAVE_LIBSSL && SSL_ENABLE_CRL_CHECK && HAVE_LIBCURL |
src/ssl/macos/getcrl.c
| ... | ... | @@ -1,131 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | - * | |
| 28 | - * | |
| 29 | - * References: | |
| 30 | - * | |
| 31 | - * http://www.openssl.org/docs/ssl/ | |
| 32 | - * https://stackoverflow.com/questions/4389954/does-openssl-automatically-handle-crls-certificate-revocation-lists-now | |
| 33 | - * | |
| 34 | - */ | |
| 35 | - | |
| 36 | -#include "private.h" | |
| 37 | - | |
| 38 | -#if defined(HAVE_LIBSSL) && defined(SSL_ENABLE_CRL_CHECK) | |
| 39 | - | |
| 40 | -/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 41 | - | |
| 42 | -static inline void lib3270_autoptr_cleanup_FILE(FILE **file) | |
| 43 | -{ | |
| 44 | - if(*file) | |
| 45 | - fclose(*file); | |
| 46 | -} | |
| 47 | - | |
| 48 | -X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, const char *consturl) | |
| 49 | -{ | |
| 50 | - X509_CRL * x509_crl = NULL; | |
| 51 | - | |
| 52 | - if(!(consturl && *consturl)) | |
| 53 | - { | |
| 54 | - message->error = hSession->ssl.error = 0; | |
| 55 | - message->title = _( "Security error" ); | |
| 56 | - message->text = _( "Can't open CRL File" ); | |
| 57 | - message->description = _("The URL for the CRL is undefined or empty"); | |
| 58 | - errno = ENOENT; | |
| 59 | - return NULL; | |
| 60 | - } | |
| 61 | - | |
| 62 | - if(strncasecmp(consturl,"file://",7) == 0) | |
| 63 | - { | |
| 64 | - lib3270_autoptr(FILE) hCRL = fopen(consturl+7,"r"); | |
| 65 | - | |
| 66 | - if(!hCRL) | |
| 67 | - { | |
| 68 | - // Can't open CRL File. | |
| 69 | - int err = errno; | |
| 70 | - | |
| 71 | - message->error = hSession->ssl.error = 0; | |
| 72 | - message->title = _( "Security error" ); | |
| 73 | - message->text = _( "Can't open CRL File" ); | |
| 74 | - message->description = strerror(err); | |
| 75 | - trace_ssl(hSession,"Can't open %s: %s\n",consturl,message->description); | |
| 76 | - return NULL; | |
| 77 | - | |
| 78 | - } | |
| 79 | - | |
| 80 | - trace_ssl(hSession,"Loading CRL from %s\n",consturl+7); | |
| 81 | - if(d2i_X509_CRL_fp(hCRL, &x509_crl)) | |
| 82 | - { | |
| 83 | - message->error = hSession->ssl.error = ERR_get_error(); | |
| 84 | - message->title = _( "Security error" ); | |
| 85 | - message->text = _( "Can't decode CRL" ); | |
| 86 | - lib3270_write_log(hSession,"ssl","%s: %s",consturl, message->text); | |
| 87 | - return NULL; | |
| 88 | - } | |
| 89 | - | |
| 90 | - | |
| 91 | - | |
| 92 | - } | |
| 93 | -#ifdef HAVE_LDAP | |
| 94 | - else if(strncasecmp(consturl,"ldap://",7) == 0 && strlen(consturl) > 8) | |
| 95 | - { | |
| 96 | - return get_crl_using_ldap(hSession, message, consturl); | |
| 97 | - | |
| 98 | - } | |
| 99 | -#endif // HAVE_LDAP | |
| 100 | - else | |
| 101 | - { | |
| 102 | -#ifdef HAVE_LIBCURL | |
| 103 | - | |
| 104 | - return get_crl_using_url(hSession, message, consturl); | |
| 105 | - | |
| 106 | -#else | |
| 107 | - // Can't get CRL. | |
| 108 | - | |
| 109 | - message->error = hSession->ssl.error = 0; | |
| 110 | - | |
| 111 | - if(!(message->text && message->description)) | |
| 112 | - message->title = _( "Security error" ); | |
| 113 | - | |
| 114 | - if(!message->text) | |
| 115 | - message->text = _( "Unexpected or invalid CRL URL" ); | |
| 116 | - | |
| 117 | - if(!message->description) | |
| 118 | - message->description = _("The URL scheme is unknown"); | |
| 119 | - | |
| 120 | - trace_ssl(hSession,"%s: The URL scheme is unknown",consturl); | |
| 121 | - | |
| 122 | - errno = EINVAL; | |
| 123 | - return NULL; | |
| 124 | -#endif // HAVE_LIBCURL | |
| 125 | - } | |
| 126 | - | |
| 127 | - return x509_crl; | |
| 128 | - | |
| 129 | -} | |
| 130 | - | |
| 131 | -#endif // HAVE_LIBSSL && SSL_ENABLE_CRL_CHECK |
src/ssl/macos/init.c
| ... | ... | @@ -1,118 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | - * | |
| 28 | - * | |
| 29 | - * References: | |
| 30 | - * | |
| 31 | - * http://www.openssl.org/docs/ssl/ | |
| 32 | - * https://stackoverflow.com/questions/4389954/does-openssl-automatically-handle-crls-certificate-revocation-lists-now | |
| 33 | - * | |
| 34 | - */ | |
| 35 | - | |
| 36 | -/** | |
| 37 | - * @brief OpenSSL initialization for linux. | |
| 38 | - * | |
| 39 | - */ | |
| 40 | - | |
| 41 | -#include <config.h> | |
| 42 | - | |
| 43 | -#if defined(HAVE_LIBSSL) | |
| 44 | - | |
| 45 | -#include <openssl/ssl.h> | |
| 46 | -#include <openssl/err.h> | |
| 47 | -#include <openssl/x509_vfy.h> | |
| 48 | - | |
| 49 | -#ifndef SSL_ST_OK | |
| 50 | - #define SSL_ST_OK 3 | |
| 51 | -#endif // !SSL_ST_OK | |
| 52 | - | |
| 53 | -#include <internals.h> | |
| 54 | -#include <errno.h> | |
| 55 | -#include <lib3270.h> | |
| 56 | -#include <lib3270/internals.h> | |
| 57 | -#include <lib3270/trace.h> | |
| 58 | -#include <lib3270/log.h> | |
| 59 | -#include "trace_dsc.h" | |
| 60 | - | |
| 61 | -#ifdef SSL_ENABLE_CRL_CHECK | |
| 62 | - #include <openssl/x509.h> | |
| 63 | -#endif // SSL_ENABLE_CRL_CHECK | |
| 64 | - | |
| 65 | -/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 66 | - | |
| 67 | -/** | |
| 68 | - * @brief Initialize openssl library. | |
| 69 | - * | |
| 70 | - * @return 0 if ok, non zero if fails. | |
| 71 | - * | |
| 72 | - */ | |
| 73 | -int ssl_ctx_init(H3270 *hSession, SSL_ERROR_MESSAGE * message) | |
| 74 | -{ | |
| 75 | - debug("%s ssl_ctx=%p",__FUNCTION__,ssl_ctx); | |
| 76 | - | |
| 77 | - if(ssl_ctx) | |
| 78 | - return 0; | |
| 79 | - | |
| 80 | - trace_ssl(hSession,"Initializing SSL context.\n"); | |
| 81 | - | |
| 82 | - SSL_load_error_strings(); | |
| 83 | - SSL_library_init(); | |
| 84 | - | |
| 85 | - ssl_ctx = SSL_CTX_new(SSLv23_method()); | |
| 86 | - if(ssl_ctx == NULL) | |
| 87 | - { | |
| 88 | - message->error = hSession->ssl.error = ERR_get_error(); | |
| 89 | - message->title = _( "Security error" ); | |
| 90 | - message->text = _( "Cant initialize the SSL context." ); | |
| 91 | - return -1; | |
| 92 | - } | |
| 93 | - | |
| 94 | - SSL_CTX_set_options(ssl_ctx, SSL_OP_ALL); | |
| 95 | - SSL_CTX_set_info_callback(ssl_ctx, ssl_info_callback); | |
| 96 | - | |
| 97 | - SSL_CTX_set_default_verify_paths(ssl_ctx); | |
| 98 | - | |
| 99 | - ssl_3270_ex_index = SSL_get_ex_new_index(0,NULL,NULL,NULL,NULL); | |
| 100 | - | |
| 101 | -#ifdef SSL_ENABLE_CRL_CHECK | |
| 102 | - | |
| 103 | - // Enable CRL check | |
| 104 | - X509_STORE *store = SSL_CTX_get_cert_store(ssl_ctx); | |
| 105 | - X509_VERIFY_PARAM *param = X509_VERIFY_PARAM_new(); | |
| 106 | - X509_VERIFY_PARAM_set_flags(param, X509_V_FLAG_CRL_CHECK); | |
| 107 | - X509_STORE_set1_param(store, param); | |
| 108 | - X509_VERIFY_PARAM_free(param); | |
| 109 | - | |
| 110 | - trace_ssl(hSession,"CRL CHECK was enabled\n"); | |
| 111 | - | |
| 112 | -#endif // SSL_ENABLE_CRL_CHECK | |
| 113 | - | |
| 114 | - return 0; | |
| 115 | - | |
| 116 | -} | |
| 117 | - | |
| 118 | -#endif // HAVE_LIBSSL |
src/ssl/macos/ldap.c
| ... | ... | @@ -1,241 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | - * | |
| 28 | - * | |
| 29 | - * References: | |
| 30 | - * | |
| 31 | - * http://www.openssl.org/docs/ssl/ | |
| 32 | - * https://stackoverflow.com/questions/4389954/does-openssl-automatically-handle-crls-certificate-revocation-lists-now | |
| 33 | - * | |
| 34 | - */ | |
| 35 | - | |
| 36 | -#include <config.h> | |
| 37 | -#include <internals.h> | |
| 38 | -#include <lib3270/log.h> | |
| 39 | -#include <lib3270/trace.h> | |
| 40 | -#include <lib3270/toggle.h> | |
| 41 | - | |
| 42 | -#include "utilc.h" | |
| 43 | - | |
| 44 | -#if defined(HAVE_LIBSSL) && defined(SSL_ENABLE_CRL_CHECK) && defined(HAVE_LDAP) | |
| 45 | - | |
| 46 | -#include <openssl/ssl.h> | |
| 47 | -#include <openssl/err.h> | |
| 48 | -#include <openssl/x509_vfy.h> | |
| 49 | -#include <openssl/x509.h> | |
| 50 | - | |
| 51 | -#define LDAP_DEPRECATED 1 | |
| 52 | -#include <ldap.h> | |
| 53 | - | |
| 54 | -/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 55 | - | |
| 56 | -static inline void lib3270_autoptr_cleanup_LDAPMessage(LDAPMessage **message) | |
| 57 | -{ | |
| 58 | - debug("%s(%p)",__FUNCTION__,*message); | |
| 59 | - if(message) | |
| 60 | - ldap_msgfree(*message); | |
| 61 | - *message = NULL; | |
| 62 | -} | |
| 63 | - | |
| 64 | -static inline void lib3270_autoptr_cleanup_LDAP(LDAP **ld) | |
| 65 | -{ | |
| 66 | - debug("%s(%p)",__FUNCTION__,*ld); | |
| 67 | - if(*ld) | |
| 68 | - ldap_unbind_ext(*ld, NULL, NULL); | |
| 69 | - *ld = NULL; | |
| 70 | -} | |
| 71 | - | |
| 72 | -static inline void lib3270_autoptr_cleanup_BerElement(BerElement **ber) | |
| 73 | -{ | |
| 74 | - debug("%s(%p)",__FUNCTION__,*ber); | |
| 75 | - if(*ber) | |
| 76 | - ber_free(*ber, 0); | |
| 77 | - *ber = NULL; | |
| 78 | -} | |
| 79 | - | |
| 80 | -static inline void lib3270_autoptr_cleanup_LDAPPTR(char **ptr) | |
| 81 | -{ | |
| 82 | - debug("%s(%p)",__FUNCTION__,*ptr); | |
| 83 | - if(*ptr) | |
| 84 | - ldap_memfree(*ptr); | |
| 85 | - *ptr = NULL; | |
| 86 | -} | |
| 87 | - | |
| 88 | -LIB3270_INTERNAL X509_CRL * get_crl_using_ldap(H3270 *hSession, SSL_ERROR_MESSAGE * message, const char *consturl) | |
| 89 | -{ | |
| 90 | - X509_CRL * x509_crl = NULL; | |
| 91 | - | |
| 92 | - int rc; | |
| 93 | - lib3270_autoptr(char) url = lib3270_unescape(consturl); | |
| 94 | - char * base = strchr(url+7,'/'); | |
| 95 | - char * attrs[] = { NULL, NULL }; | |
| 96 | - | |
| 97 | - if(!base) | |
| 98 | - { | |
| 99 | - message->error = hSession->ssl.error = 0; | |
| 100 | - message->title = _( "Security error" ); | |
| 101 | - message->text = _( "No DN of the entry at which to start the search on the URL" ); | |
| 102 | - message->description = _( "The URL argument should be in the format ldap://[HOST]/[DN]?attribute" ); | |
| 103 | - errno = EINVAL; | |
| 104 | - return NULL; | |
| 105 | - } | |
| 106 | - | |
| 107 | - *(base++) = 0; | |
| 108 | - attrs[0] = strchr(base,'?'); | |
| 109 | - | |
| 110 | - if(!base) | |
| 111 | - { | |
| 112 | - message->error = hSession->ssl.error = 0; | |
| 113 | - message->title = _( "Security error" ); | |
| 114 | - message->text = _( "No LDAP attribute on the URL" ); | |
| 115 | - message->description = _( "The URL argument should be in the format ldap://[HOST]/[DN]?attribute" ); | |
| 116 | - errno = EINVAL; | |
| 117 | - return NULL; | |
| 118 | - } | |
| 119 | - | |
| 120 | - *(attrs[0]++) = 0; | |
| 121 | - | |
| 122 | - debug("host: \"%s\"",url); | |
| 123 | - debug("Base: \"%s\"",base); | |
| 124 | - debug("Attr: \"%s\"",attrs[0]); | |
| 125 | - | |
| 126 | - // Do LDAP Query | |
| 127 | - LDAP __attribute__ ((__cleanup__(lib3270_autoptr_cleanup_LDAP))) *ld = NULL; | |
| 128 | - BerElement __attribute__ ((__cleanup__(lib3270_autoptr_cleanup_BerElement))) * ber = NULL; | |
| 129 | - | |
| 130 | - rc = ldap_initialize(&ld, url); | |
| 131 | - if(rc != LDAP_SUCCESS) | |
| 132 | - { | |
| 133 | - message->error = hSession->ssl.error = 0; | |
| 134 | - message->title = _( "Security error" ); | |
| 135 | - message->text = _( "Can't initialize LDAP" ); | |
| 136 | - message->description = ldap_err2string(rc); | |
| 137 | - lib3270_write_log(hSession,"ssl","%s: %s",url, message->description); | |
| 138 | - return NULL; | |
| 139 | - } | |
| 140 | - | |
| 141 | - unsigned long version = LDAP_VERSION3; | |
| 142 | - rc = ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION,(void *) &version); | |
| 143 | - if(rc != LDAP_SUCCESS) { | |
| 144 | - message->error = hSession->ssl.error = 0; | |
| 145 | - message->title = _( "Security error" ); | |
| 146 | - message->text = _( "Can't set LDAP protocol version" ); | |
| 147 | - message->description = ldap_err2string(rc); | |
| 148 | - lib3270_write_log(hSession,"ssl","%s: %s",url, message->description); | |
| 149 | - return NULL; | |
| 150 | - } | |
| 151 | - | |
| 152 | - rc = ldap_simple_bind_s(ld, "", ""); | |
| 153 | - if(rc != LDAP_SUCCESS) | |
| 154 | - { | |
| 155 | - message->error = hSession->ssl.error = 0; | |
| 156 | - message->title = _( "Security error" ); | |
| 157 | - message->text = _( "Can't bind to LDAP server" ); | |
| 158 | - message->description = ldap_err2string(rc); | |
| 159 | - lib3270_write_log(hSession,"ssl","%s: %s",url, message->description); | |
| 160 | - return NULL; | |
| 161 | - } | |
| 162 | - | |
| 163 | - lib3270_autoptr(LDAPMessage) results = NULL; | |
| 164 | - rc = ldap_search_ext_s( | |
| 165 | - ld, // Specifies the LDAP pointer returned by a previous call to ldap_init(), ldap_ssl_init(), or ldap_open(). | |
| 166 | - base, // Specifies the DN of the entry at which to start the search. | |
| 167 | - LDAP_SCOPE_BASE, // Specifies the scope of the search. | |
| 168 | - NULL, // Specifies a string representation of the filter to apply in the search. | |
| 169 | - (char **) &attrs, // Specifies a null-terminated array of character string attribute types to return from entries that match filter. | |
| 170 | - 0, // Should be set to 1 to request attribute types only. Set to 0 to request both attributes types and attribute values. | |
| 171 | - NULL, | |
| 172 | - NULL, | |
| 173 | - NULL, | |
| 174 | - 0, | |
| 175 | - &results | |
| 176 | - ); | |
| 177 | - | |
| 178 | - if(rc != LDAP_SUCCESS) | |
| 179 | - { | |
| 180 | - message->error = hSession->ssl.error = 0; | |
| 181 | - message->title = _( "Security error" ); | |
| 182 | - message->text = _( "Can't search LDAP server" ); | |
| 183 | - message->description = ldap_err2string(rc); | |
| 184 | - lib3270_write_log(hSession,"ssl","%s: %s",url, message->description); | |
| 185 | - return NULL; | |
| 186 | - } | |
| 187 | - | |
| 188 | - char __attribute__ ((__cleanup__(lib3270_autoptr_cleanup_LDAPPTR))) *attr = ldap_first_attribute(ld, results, &ber); | |
| 189 | - if(!attr) | |
| 190 | - { | |
| 191 | - message->error = hSession->ssl.error = 0; | |
| 192 | - message->title = _( "Security error" ); | |
| 193 | - message->text = _( "Can't get LDAP attribute" ); | |
| 194 | - message->description = _("Search did not produce any attributes."); | |
| 195 | - lib3270_write_log(hSession,"ssl","%s: %s",url, message->description); | |
| 196 | - errno = ENOENT; | |
| 197 | - return NULL; | |
| 198 | - } | |
| 199 | - | |
| 200 | - struct berval ** value = ldap_get_values_len(ld, results, attr); | |
| 201 | - if(!value) | |
| 202 | - { | |
| 203 | - message->error = hSession->ssl.error = 0; | |
| 204 | - message->title = _( "Security error" ); | |
| 205 | - message->text = _( "Can't get LDAP attribute" ); | |
| 206 | - message->description = _("Search did not produce any values."); | |
| 207 | - lib3270_write_log(hSession,"ssl","%s: %s",url, message->description); | |
| 208 | - errno = ENOENT; | |
| 209 | - return NULL; | |
| 210 | - } | |
| 211 | - | |
| 212 | - if(lib3270_get_toggle(hSession,LIB3270_TOGGLE_SSL_TRACE)) | |
| 213 | - { | |
| 214 | - lib3270_trace_data( | |
| 215 | - hSession, | |
| 216 | - "CRL Data received from LDAP server", | |
| 217 | - (const unsigned char *) value[0]->bv_val, | |
| 218 | - value[0]->bv_len | |
| 219 | - ); | |
| 220 | - } | |
| 221 | - | |
| 222 | - // Precisa salvar uma cópia porque d2i_X509_CRL modifica o ponteiro. | |
| 223 | - const unsigned char *crl_data = (const unsigned char *) value[0]->bv_val; | |
| 224 | - | |
| 225 | - if(!d2i_X509_CRL(&x509_crl, &crl_data, value[0]->bv_len)) | |
| 226 | - { | |
| 227 | - message->error = hSession->ssl.error = ERR_get_error(); | |
| 228 | - message->title = _( "Security error" ); | |
| 229 | - message->text = _( "Can't decode certificate revocation list" ); | |
| 230 | - lib3270_write_log(hSession,"ssl","%s: %s",url, message->text); | |
| 231 | - ldap_value_free_len(value); | |
| 232 | - return NULL; | |
| 233 | - } | |
| 234 | - | |
| 235 | - ldap_value_free_len(value); | |
| 236 | - | |
| 237 | - return x509_crl; | |
| 238 | - | |
| 239 | -} | |
| 240 | - | |
| 241 | -#endif // HAVE_LIBSSL && SSL_ENABLE_CRL_CHECK && HAVE_LDAP |
src/ssl/macos/private.h
| ... | ... | @@ -1,63 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software G3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral ', conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como private.h e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas de Mendonça) | |
| 27 | - * | |
| 28 | - */ | |
| 29 | - | |
| 30 | -#ifndef LIB3270_LINUX_SSL_PRIVATE_H_INCLUDED | |
| 31 | - | |
| 32 | - #define LIB3270_LINUX_SSL_PRIVATE_H_INCLUDED | |
| 33 | - | |
| 34 | - #include <config.h> | |
| 35 | - | |
| 36 | - #include <openssl/ssl.h> | |
| 37 | - #include <openssl/err.h> | |
| 38 | - #include <openssl/x509_vfy.h> | |
| 39 | - #include <openssl/x509.h> | |
| 40 | - | |
| 41 | - #include <internals.h> | |
| 42 | - #include <trace_dsc.h> | |
| 43 | - #include <errno.h> | |
| 44 | - #include <lib3270.h> | |
| 45 | - #include <lib3270/trace.h> | |
| 46 | - #include <lib3270/log.h> | |
| 47 | - | |
| 48 | - #ifdef HAVE_LDAP | |
| 49 | - | |
| 50 | - /// @brief Use libldap to get CRL. | |
| 51 | - LIB3270_INTERNAL X509_CRL * get_crl_using_ldap(H3270 *hSession, SSL_ERROR_MESSAGE * message, const char *consturl); | |
| 52 | - | |
| 53 | - #endif // HAVE_LDAP | |
| 54 | - | |
| 55 | - #ifdef HAVE_LIBCURL | |
| 56 | - | |
| 57 | - /// @brief Use libcurl to get CRL. | |
| 58 | - LIB3270_INTERNAL X509_CRL * get_crl_using_url(H3270 *hSession, SSL_ERROR_MESSAGE * message, const char *consturl); | |
| 59 | - | |
| 60 | - #endif // HAVE_LIBCURL | |
| 61 | - | |
| 62 | - | |
| 63 | -#endif // !LIB3270_LINUX_SSL_PRIVATE_H_INCLUDED |
src/ssl/macos/url.c
| ... | ... | @@ -1,127 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | - * | |
| 28 | - * | |
| 29 | - * References: | |
| 30 | - * | |
| 31 | - * http://www.openssl.org/docs/ssl/ | |
| 32 | - * https://stackoverflow.com/questions/4389954/does-openssl-automatically-handle-crls-certificate-revocation-lists-now | |
| 33 | - * | |
| 34 | - */ | |
| 35 | - | |
| 36 | -#include <config.h> | |
| 37 | - | |
| 38 | -#if defined(HAVE_LIBSSL) && defined(SSL_ENABLE_CRL_CHECK) && defined(HAVE_LIBCURL) | |
| 39 | - | |
| 40 | -#include "private.h" | |
| 41 | -#include <curl/curl.h> | |
| 42 | -#include <lib3270/toggle.h> | |
| 43 | - | |
| 44 | -#define CRL_DATA_LENGTH 2048 | |
| 45 | - | |
| 46 | -/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 47 | - | |
| 48 | -static inline void lib3270_autoptr_cleanup_BIO(BIO **ptr) | |
| 49 | -{ | |
| 50 | - debug("%s(%p)",__FUNCTION__,*ptr); | |
| 51 | - if(*ptr) | |
| 52 | - BIO_free_all(*ptr); | |
| 53 | - *ptr = NULL; | |
| 54 | -} | |
| 55 | - | |
| 56 | -LIB3270_INTERNAL X509_CRL * get_crl_using_url(H3270 *hSession, SSL_ERROR_MESSAGE * message, const char *consturl) | |
| 57 | -{ | |
| 58 | - X509_CRL * x509_crl = NULL; | |
| 59 | - | |
| 60 | - size_t szText = 0; | |
| 61 | - lib3270_autoptr(char) httpText = lib3270_get_from_url(hSession, consturl, &szText, &message->description); | |
| 62 | - | |
| 63 | - if(!httpText) | |
| 64 | - { | |
| 65 | - message->title = _( "Security error" ); | |
| 66 | - message->text = _( "Error getting certificate revocation list" ); | |
| 67 | - return NULL; | |
| 68 | - } | |
| 69 | - | |
| 70 | - if(lib3270_get_toggle(hSession,LIB3270_TOGGLE_SSL_TRACE)) | |
| 71 | - lib3270_trace_data(hSession,"CRL Data",(const unsigned char *) httpText, (unsigned int) szText); | |
| 72 | - | |
| 73 | - if(strncasecmp(consturl,"ldap://",7) == 0) | |
| 74 | - { | |
| 75 | - // It's an LDAP query, assumes a base64 data. | |
| 76 | - char * data = strstr((char *) httpText,":: "); | |
| 77 | - if(!data) | |
| 78 | - { | |
| 79 | - message->error = hSession->ssl.error = ERR_get_error(); | |
| 80 | - message->title = _( "Security error" ); | |
| 81 | - message->text = _( "Got a bad formatted certificate revocation list from LDAP server" ); | |
| 82 | - lib3270_write_log(hSession,"ssl","%s: invalid format:\n%s\n", consturl, httpText); | |
| 83 | - errno = EINVAL; | |
| 84 | - return NULL; | |
| 85 | - } | |
| 86 | - data += 3; | |
| 87 | - | |
| 88 | - lib3270_autoptr(BIO) bio = BIO_new_mem_buf(httpText,-1); | |
| 89 | - | |
| 90 | - BIO * b64 = BIO_new(BIO_f_base64()); | |
| 91 | - bio = BIO_push(b64, bio); | |
| 92 | - | |
| 93 | - BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); | |
| 94 | - | |
| 95 | - if(!d2i_X509_CRL_bio(bio, &x509_crl)) | |
| 96 | - { | |
| 97 | - message->error = hSession->ssl.error = ERR_get_error(); | |
| 98 | - message->title = _( "Security error" ); | |
| 99 | - message->text = _( "Can't decode certificate revocation list got from LDAP server" ); | |
| 100 | - lib3270_write_log(hSession,"ssl","%s: %s",consturl, message->text); | |
| 101 | - errno = EINVAL; | |
| 102 | - return NULL; | |
| 103 | - } | |
| 104 | - | |
| 105 | - } | |
| 106 | - else | |
| 107 | - { | |
| 108 | - // CRL File, convert it | |
| 109 | - // Copy the pointer because d2i_X509_CRL changes the value!!! | |
| 110 | - const unsigned char *crl_data = (const unsigned char *) httpText; | |
| 111 | - | |
| 112 | - if(!d2i_X509_CRL(&x509_crl, &crl_data, szText)) | |
| 113 | - { | |
| 114 | - message->error = hSession->ssl.error = ERR_get_error(); | |
| 115 | - message->title = _( "Security error" ); | |
| 116 | - message->text = _( "Can't decode certificate revocation list" ); | |
| 117 | - lib3270_write_log(hSession,"ssl","%s: %s",consturl, message->text); | |
| 118 | - return NULL; | |
| 119 | - } | |
| 120 | - | |
| 121 | - } | |
| 122 | - | |
| 123 | - return x509_crl; | |
| 124 | - | |
| 125 | -} | |
| 126 | - | |
| 127 | -#endif // HAVE_LIBSSL && SSL_ENABLE_CRL_CHECK && HAVE_LIBCURL |
src/ssl/negotiate.c
| ... | ... | @@ -1,556 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | - * | |
| 28 | - * | |
| 29 | - * References: | |
| 30 | - * | |
| 31 | - * http://www.openssl.org/docs/ssl/ | |
| 32 | - * | |
| 33 | - */ | |
| 34 | - | |
| 35 | - | |
| 36 | -#include <config.h> | |
| 37 | -#include <internals.h> | |
| 38 | - | |
| 39 | -#if defined(HAVE_LIBSSL) | |
| 40 | - | |
| 41 | - #include <openssl/ssl.h> | |
| 42 | - #include <openssl/err.h> | |
| 43 | - #include <openssl/x509_vfy.h> | |
| 44 | - #include <openssl/x509v3.h> | |
| 45 | - | |
| 46 | - #ifndef SSL_ST_OK | |
| 47 | - #define SSL_ST_OK 3 | |
| 48 | - #endif // !SSL_ST_OK | |
| 49 | - | |
| 50 | - #include "crl.h" | |
| 51 | - | |
| 52 | -#endif | |
| 53 | - | |
| 54 | -#include <errno.h> | |
| 55 | -#include <lib3270.h> | |
| 56 | -#include <lib3270/internals.h> | |
| 57 | -#include <lib3270/trace.h> | |
| 58 | -#include <lib3270/log.h> | |
| 59 | -#include <lib3270/toggle.h> | |
| 60 | -#include <lib3270/properties.h> | |
| 61 | -#include "hostc.h" // host_disconnect | |
| 62 | -#include "trace_dsc.h" | |
| 63 | - | |
| 64 | -/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 65 | - | |
| 66 | -#if defined(HAVE_LIBSSLx) | |
| 67 | - | |
| 68 | - /** | |
| 69 | - * @brief Index of h3270 handle in SSL session. | |
| 70 | - * | |
| 71 | - */ | |
| 72 | - int ssl_3270_ex_index = -1; | |
| 73 | - | |
| 74 | -/** | |
| 75 | - * @brief Global SSL_CTX object as framework to establish TLS/SSL or DTLS enabled connections. | |
| 76 | - * | |
| 77 | - */ | |
| 78 | - SSL_CTX * ssl_ctx = NULL; | |
| 79 | - | |
| 80 | -/** | |
| 81 | - * @brief Initialize openssl session. | |
| 82 | - * | |
| 83 | - * @param hSession lib3270 session handle. | |
| 84 | - * | |
| 85 | - * @return 0 if ok, non zero if fails. | |
| 86 | - * | |
| 87 | - */ | |
| 88 | -static int background_ssl_init(H3270 *hSession, void *message) | |
| 89 | -{ | |
| 90 | - set_ssl_state(hSession,LIB3270_SSL_UNDEFINED); | |
| 91 | - hSession->ssl.error = 0; | |
| 92 | - hSession->ssl.host = False; | |
| 93 | - | |
| 94 | - if(ssl_ctx_init(hSession, (SSL_ERROR_MESSAGE *) message)) { | |
| 95 | - debug("%s has failed","ssl_ctx_init"); | |
| 96 | - set_ssl_state(hSession,LIB3270_SSL_UNDEFINED); | |
| 97 | - hSession->ssl.host = False; | |
| 98 | - return -1; | |
| 99 | - } | |
| 100 | - | |
| 101 | - if(hSession->ssl.con) | |
| 102 | - SSL_free(hSession->ssl.con); | |
| 103 | - | |
| 104 | - hSession->ssl.con = SSL_new(ssl_ctx); | |
| 105 | - if(hSession->ssl.con == NULL) | |
| 106 | - { | |
| 107 | - static const LIB3270_POPUP popup = { | |
| 108 | - .type = LIB3270_NOTIFY_SECURE, | |
| 109 | - .summary = N_( "Cant create a new SSL structure for current connection." ) | |
| 110 | - }; | |
| 111 | - | |
| 112 | - ((SSL_ERROR_MESSAGE *) message)->code = hSession->ssl.error = ERR_get_error(); | |
| 113 | - ((SSL_ERROR_MESSAGE *) message)->popup = &popup; | |
| 114 | - return -1; | |
| 115 | - } | |
| 116 | - | |
| 117 | - SSL_set_ex_data(hSession->ssl.con,ssl_3270_ex_index,(char *) hSession); | |
| 118 | -// SSL_set_verify(session->ssl_con, SSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); | |
| 119 | - SSL_set_verify(hSession->ssl.con, 0, NULL); | |
| 120 | - | |
| 121 | - return 0; | |
| 122 | -} | |
| 123 | - | |
| 124 | -#if defined(SSL_ENABLE_CRL_CHECK) | |
| 125 | -int x509_store_ctx_error_callback(int ok, X509_STORE_CTX GNUC_UNUSED(*ctx)) | |
| 126 | -{ | |
| 127 | - debug("%s(%d)",__FUNCTION__,ok); | |
| 128 | - | |
| 129 | -/* | |
| 130 | - 55 { | |
| 131 | - 56 if (!ok) { | |
| 132 | - 57 Category::getInstance("OpenSSL").error( | |
| 133 | - 58 "path validation failure at depth(%d): %s", | |
| 134 | - 59 X509_STORE_CTX_get_error_depth(ctx), | |
| 135 | - 60 X509_verify_cert_error_string(X509_STORE_CTX_get_error(ctx)) | |
| 136 | - 61 ); | |
| 137 | - 62 } | |
| 138 | - 63 return ok; | |
| 139 | - 64 } | |
| 140 | -*/ | |
| 141 | - return ok; | |
| 142 | -} | |
| 143 | -#endif // SSL_ENABLE_CRL_CHECK | |
| 144 | - | |
| 145 | -static const struct ssl_protocol { | |
| 146 | - int id; | |
| 147 | - const char * description; | |
| 148 | -} ssl_protocols[] = { | |
| 149 | - | |
| 150 | - { | |
| 151 | - .id = SSL3_VERSION, | |
| 152 | - .description = SSL_TXT_SSLV3 | |
| 153 | - }, | |
| 154 | - { | |
| 155 | - .id = TLS1_VERSION, | |
| 156 | - .description = SSL_TXT_TLSV1 | |
| 157 | - }, | |
| 158 | - { | |
| 159 | - .id = TLS1_1_VERSION, | |
| 160 | - .description = SSL_TXT_TLSV1_1 | |
| 161 | - }, | |
| 162 | - { | |
| 163 | - .id = TLS1_2_VERSION, | |
| 164 | - .description = SSL_TXT_TLSV1_2 | |
| 165 | - }, | |
| 166 | -#ifdef DTLS1_VERSION | |
| 167 | - { | |
| 168 | - .id = DTLS1_VERSION, | |
| 169 | - .description = "DTLSv1" | |
| 170 | - }, | |
| 171 | -#endif // DTLS1_VERSION | |
| 172 | -#ifdef DTLS1_2_VERSION | |
| 173 | - { | |
| 174 | - .id = DTLS1_2_VERSION, | |
| 175 | - .description = "DTLSv2" | |
| 176 | - }, | |
| 177 | -#endif // DTLS1_2_VERSION | |
| 178 | - | |
| 179 | -}; | |
| 180 | - | |
| 181 | -static const struct ssl_protocol * get_protocol_from_id(int id) { | |
| 182 | - | |
| 183 | - if(id < 1) | |
| 184 | - return NULL; | |
| 185 | - | |
| 186 | - id--; | |
| 187 | - | |
| 188 | - if( ((size_t) id) > (sizeof(ssl_protocols)/sizeof(ssl_protocols[0]))) | |
| 189 | - return NULL; | |
| 190 | - | |
| 191 | - return ssl_protocols + id; | |
| 192 | - | |
| 193 | -} | |
| 194 | - | |
| 195 | -static int background_ssl_negotiation(H3270 *hSession, void *message) | |
| 196 | -{ | |
| 197 | - int rv; | |
| 198 | - | |
| 199 | - trace("%s",__FUNCTION__); | |
| 200 | - | |
| 201 | - /* Initialize the SSL library. */ | |
| 202 | - if(background_ssl_init(hSession,message)) | |
| 203 | - { | |
| 204 | - return -1; | |
| 205 | - } | |
| 206 | - | |
| 207 | - /* Set up the TLS/SSL connection. */ | |
| 208 | - const struct ssl_protocol * protocol; | |
| 209 | - | |
| 210 | - if( (protocol = get_protocol_from_id(hSession->ssl.protocol.min_version)) != NULL ) | |
| 211 | - { | |
| 212 | -#if (OPENSSL_VERSION_NUMBER >= 0x1010009fL) | |
| 213 | - if(SSL_set_min_proto_version(hSession->ssl.con,protocol->id) == 1) | |
| 214 | - { | |
| 215 | - trace_ssl(hSession,"Minimum protocol version set to %s\n",protocol->description); | |
| 216 | - } | |
| 217 | - else | |
| 218 | - { | |
| 219 | - lib3270_write_log(hSession,"ssl","Can't set minimum protocol version to %s",protocol->description); | |
| 220 | - } | |
| 221 | -#else | |
| 222 | - trace_ssl(hSession,"Can't set minimum protocol version to %s\n",protocol->description); | |
| 223 | -#endif // OPENSSL_VERSION_NUMBER | |
| 224 | - } | |
| 225 | - | |
| 226 | - if( (protocol = get_protocol_from_id(hSession->ssl.protocol.max_version)) != NULL ) | |
| 227 | - { | |
| 228 | -#if (OPENSSL_VERSION_NUMBER >= 0x1010009fL) | |
| 229 | - if(SSL_set_max_proto_version(hSession->ssl.con,protocol->id) == 1) | |
| 230 | - { | |
| 231 | - trace_ssl(hSession,"Maximum protocol version set to %s\n",protocol->description); | |
| 232 | - } | |
| 233 | - else | |
| 234 | - { | |
| 235 | - lib3270_write_log(hSession,"ssl","Can't set maximum protocol version to %s",protocol->description); | |
| 236 | - } | |
| 237 | -#else | |
| 238 | - trace_ssl(hSession,"Can't set maximum protocol version to %s\n",protocol->description); | |
| 239 | -#endif // OPENSSL_VERSION_NUMBER | |
| 240 | - } | |
| 241 | - | |
| 242 | - if(SSL_set_fd(hSession->ssl.con, hSession->connection.sock) != 1) | |
| 243 | - { | |
| 244 | - trace_ssl(hSession,"%s","SSL_set_fd failed!\n"); | |
| 245 | - | |
| 246 | - static const LIB3270_POPUP popup = { | |
| 247 | - .summary = N_( "SSL negotiation failed" ), | |
| 248 | - .body = N_( "Cant set the file descriptor for the input/output facility for the TLS/SSL (encrypted) side of ssl." ) | |
| 249 | - }; | |
| 250 | - | |
| 251 | - ((SSL_ERROR_MESSAGE *) message)->popup = &popup; | |
| 252 | - | |
| 253 | - return -1; | |
| 254 | - } | |
| 255 | - | |
| 256 | -#ifdef SSL_CRL_URL | |
| 257 | - | |
| 258 | - // Load CRL from pre-defined URL | |
| 259 | - if(!hSession->ssl.crl.cert) | |
| 260 | - { | |
| 261 | - if(lib3270_crl_new_from_url(hSession, message, SSL_CRL_URL)) | |
| 262 | - return EACCES; | |
| 263 | - } | |
| 264 | - | |
| 265 | -#endif // SSL_CRL_URL | |
| 266 | - | |
| 267 | - trace_ssl(hSession, "%s","Running SSL_connect\n"); | |
| 268 | - rv = SSL_connect(hSession->ssl.con); | |
| 269 | - trace_ssl(hSession, "SSL_connect exits with rc=%d\n",rv); | |
| 270 | - | |
| 271 | - if (rv != 1) | |
| 272 | - { | |
| 273 | - ((SSL_ERROR_MESSAGE *) message)->code = SSL_get_error(hSession->ssl.con,rv); | |
| 274 | - if(((SSL_ERROR_MESSAGE *) message)->code == SSL_ERROR_SYSCALL && hSession->ssl.error) | |
| 275 | - ((SSL_ERROR_MESSAGE *) message)->code = hSession->ssl.error; | |
| 276 | - | |
| 277 | - const char * msg = ERR_lib_error_string(((SSL_ERROR_MESSAGE *) message)->code); | |
| 278 | - | |
| 279 | - trace_ssl(hSession,"SSL_connect failed: %s %s\n",msg,ERR_reason_error_string(hSession->ssl.error)); | |
| 280 | - | |
| 281 | - static const LIB3270_POPUP popup = { | |
| 282 | - .type = LIB3270_NOTIFY_ERROR, | |
| 283 | - .summary = N_( "SSL Connect failed" ), | |
| 284 | - }; | |
| 285 | - | |
| 286 | - ((SSL_ERROR_MESSAGE *) message)->popup = &popup; | |
| 287 | - | |
| 288 | - return -1; | |
| 289 | - | |
| 290 | - } | |
| 291 | - | |
| 292 | - // | |
| 293 | - // Success. | |
| 294 | - // | |
| 295 | - | |
| 296 | - // Get peer certificate, notify application before validation. | |
| 297 | - lib3270_autoptr(X509) peer = SSL_get_peer_certificate(hSession->ssl.con); | |
| 298 | - | |
| 299 | - if(peer) | |
| 300 | - { | |
| 301 | - if(lib3270_get_toggle(hSession,LIB3270_TOGGLE_SSL_TRACE)) | |
| 302 | - { | |
| 303 | - BIO * out = BIO_new(BIO_s_mem()); | |
| 304 | - unsigned char * data; | |
| 305 | - unsigned char * text; | |
| 306 | - int n; | |
| 307 | - | |
| 308 | - X509_print(out,peer); | |
| 309 | - | |
| 310 | - n = BIO_get_mem_data(out, &data); | |
| 311 | - text = (unsigned char *) malloc (n+1); | |
| 312 | - text[n] ='\0'; | |
| 313 | - memcpy(text,data,n); | |
| 314 | - | |
| 315 | - trace_ssl(hSession,"TLS/SSL peer certificate:\n%s\n",text); | |
| 316 | - | |
| 317 | - free(text); | |
| 318 | - BIO_free(out); | |
| 319 | - | |
| 320 | - } | |
| 321 | - | |
| 322 | - hSession->cbk.set_peer_certificate(peer); | |
| 323 | - | |
| 324 | -#ifdef SSL_ENABLE_CRL_CHECK | |
| 325 | - | |
| 326 | - if(!hSession->ssl.crl.cert) | |
| 327 | - { | |
| 328 | - if(lib3270_crl_new_from_x509(hSession, message, peer)) | |
| 329 | - return EACCES; | |
| 330 | - } | |
| 331 | - | |
| 332 | -#endif // SSL_ENABLE_CRL_CHECK | |
| 333 | - | |
| 334 | - } | |
| 335 | - | |
| 336 | -#ifdef SSL_ENABLE_CRL_CHECK | |
| 337 | - if(SSL_get_verify_result(hSession->ssl.con) == X509_V_ERR_UNABLE_TO_GET_CRL && hSession->ssl.crl.cert && peer) | |
| 338 | - { | |
| 339 | - // | |
| 340 | - // Verify CRL | |
| 341 | - // | |
| 342 | - // References: | |
| 343 | - // | |
| 344 | - // http://www.zedwood.com/article/cpp-check-crl-for-revocation | |
| 345 | - // | |
| 346 | - | |
| 347 | - trace_ssl(hSession,"Doing CRL check using %s\n",hSession->ssl.crl.url); | |
| 348 | - | |
| 349 | - // Got CRL, verify it! | |
| 350 | - // Reference: https://stackoverflow.com/questions/10510850/how-to-verify-the-certificate-for-the-ongoing-ssl-session | |
| 351 | - X509_STORE_CTX *csc = X509_STORE_CTX_new(); | |
| 352 | - X509_STORE_CTX_set_verify_cb(csc, x509_store_ctx_error_callback); | |
| 353 | - X509_STORE_CTX_init(csc, SSL_CTX_get_cert_store(ssl_ctx), peer, NULL); | |
| 354 | - | |
| 355 | - if(X509_verify_cert(csc) != 1) | |
| 356 | - rv = X509_STORE_CTX_get_error(csc); | |
| 357 | - else | |
| 358 | - rv = X509_V_OK; | |
| 359 | - | |
| 360 | - trace_ssl(hSession, "X509_verify_cert error code was %d", rv); | |
| 361 | - | |
| 362 | - SSL_set_verify_result(hSession->ssl.con, rv); | |
| 363 | - | |
| 364 | - X509_STORE_CTX_free(csc); | |
| 365 | - | |
| 366 | - } | |
| 367 | -#endif // SSL_ENABLE_CRL_CHECK | |
| 368 | - | |
| 369 | - // Check validation state. | |
| 370 | - rv = SSL_get_verify_result(hSession->ssl.con); | |
| 371 | - debug("SSL Verify result was %d", rv); | |
| 372 | - const struct ssl_status_msg * msg = ssl_get_status_from_error_code((long) rv); | |
| 373 | - | |
| 374 | - if(!msg) | |
| 375 | - { | |
| 376 | - trace_ssl(hSession,"Unexpected or invalid TLS/SSL verify result %d\n",rv); | |
| 377 | - set_ssl_state(hSession,LIB3270_SSL_UNSECURE); | |
| 378 | - | |
| 379 | - static LIB3270_POPUP popup = { | |
| 380 | - .summary = N_( "Can't verify." ), | |
| 381 | - .body = N_( "Unexpected or invalid TLS/SSL verify result" ) | |
| 382 | - }; | |
| 383 | - | |
| 384 | - ((SSL_ERROR_MESSAGE *) message)->popup = &popup; | |
| 385 | - return EACCES; | |
| 386 | - | |
| 387 | - } | |
| 388 | - else | |
| 389 | - { | |
| 390 | - switch(rv) | |
| 391 | - { | |
| 392 | - case X509_V_OK: | |
| 393 | - trace_ssl(hSession,"TLS/SSL negotiated connection complete. Peer certificate %s presented.\n", peer ? "was" : "was not"); | |
| 394 | - set_ssl_state(hSession,LIB3270_SSL_SECURE); | |
| 395 | - break; | |
| 396 | - | |
| 397 | - case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN: | |
| 398 | - | |
| 399 | - trace_ssl(hSession,"TLS/SSL negotiated connection complete with self signed certificate in certificate chain (rc=%d)\n",rv); | |
| 400 | - | |
| 401 | - set_ssl_state(hSession,LIB3270_SSL_NEGOTIATED); | |
| 402 | - | |
| 403 | -#ifdef SSL_ENABLE_SELF_SIGNED_CERT_CHECK | |
| 404 | - static const LIB3270_POPUP popup = { | |
| 405 | - .type = LIB3270_NOTIFY_SECURE, | |
| 406 | - .summary = N_( "The SSL certificate for this host is not trusted." ), | |
| 407 | - .body = N_( "The security certificate presented by this host was not issued by a trusted certificate authority." ) | |
| 408 | - }; | |
| 409 | - | |
| 410 | - ((SSL_ERROR_MESSAGE *) message)->popup = &popup; | |
| 411 | - return EACCES; | |
| 412 | -#else | |
| 413 | - break; | |
| 414 | -#endif // SSL_ENABLE_SELF_SIGNED_CERT_CHECK | |
| 415 | - | |
| 416 | - case X509_V_ERR_UNABLE_TO_GET_CRL: | |
| 417 | - | |
| 418 | - trace_ssl(hSession,"TLS/SSL verify result was %d (%s)\n", rv, msg->body); | |
| 419 | - | |
| 420 | - ((SSL_ERROR_MESSAGE *) message)->popup = (LIB3270_POPUP *) msg; | |
| 421 | - | |
| 422 | - debug("message: %s",((SSL_ERROR_MESSAGE *) message)->popup->summary); | |
| 423 | - debug("description: %s",((SSL_ERROR_MESSAGE *) message)->popup->body); | |
| 424 | - | |
| 425 | - set_ssl_state(hSession,LIB3270_SSL_NEGOTIATED); | |
| 426 | - | |
| 427 | - if(msg->type == LIB3270_NOTIFY_ERROR && lib3270_ssl_get_crl_download(hSession)) | |
| 428 | - return EACCES; | |
| 429 | - | |
| 430 | - break; | |
| 431 | - | |
| 432 | - default: | |
| 433 | - trace_ssl(hSession,"TLS/SSL verify result was %d (%s)\n", rv, msg->body); | |
| 434 | - | |
| 435 | - ((SSL_ERROR_MESSAGE *) message)->popup = (LIB3270_POPUP *) msg; | |
| 436 | - | |
| 437 | - debug("message: %s",((SSL_ERROR_MESSAGE *) message)->popup->summary); | |
| 438 | - debug("description: %s",((SSL_ERROR_MESSAGE *) message)->popup->body); | |
| 439 | - | |
| 440 | - set_ssl_state(hSession,LIB3270_SSL_NEGOTIATED); | |
| 441 | - | |
| 442 | - if(msg->type == LIB3270_NOTIFY_ERROR) | |
| 443 | - return EACCES; | |
| 444 | - | |
| 445 | - } | |
| 446 | - | |
| 447 | - } | |
| 448 | - | |
| 449 | - if(lib3270_get_toggle(hSession,LIB3270_TOGGLE_SSL_TRACE)) | |
| 450 | - { | |
| 451 | - char buffer[4096]; | |
| 452 | - int alg_bits = 0; | |
| 453 | - const SSL_CIPHER * cipher = SSL_get_current_cipher(hSession->ssl.con); | |
| 454 | - | |
| 455 | - trace_ssl(hSession,"TLS/SSL cipher description: %s",SSL_CIPHER_description((SSL_CIPHER *) cipher, buffer, 4095)); | |
| 456 | - SSL_CIPHER_get_bits(cipher, &alg_bits); | |
| 457 | - trace_ssl(hSession,"%s version %s with %d bits\n", | |
| 458 | - SSL_CIPHER_get_name(cipher), | |
| 459 | - SSL_CIPHER_get_version(cipher), | |
| 460 | - alg_bits); | |
| 461 | - } | |
| 462 | - | |
| 463 | - return 0; | |
| 464 | -} | |
| 465 | - | |
| 466 | -int ssl_negotiate(H3270 *hSession) | |
| 467 | -{ | |
| 468 | - int rc; | |
| 469 | - SSL_ERROR_MESSAGE msg; | |
| 470 | - | |
| 471 | - memset(&msg,0,sizeof(msg)); | |
| 472 | - | |
| 473 | - set_ssl_state(hSession,LIB3270_SSL_NEGOTIATING); | |
| 474 | - non_blocking(hSession,False); | |
| 475 | - | |
| 476 | - rc = lib3270_run_task(hSession, background_ssl_negotiation, &msg); | |
| 477 | - | |
| 478 | - debug("background_ssl_negotiation exits with rc=%d",rc); | |
| 479 | - if(rc && msg.popup) | |
| 480 | - { | |
| 481 | - // SSL Negotiation has failed. | |
| 482 | - if(popup_ssl_error(hSession,rc,&msg)) | |
| 483 | - { | |
| 484 | - host_disconnect(hSession,1); // Disconnect with "failed" status. | |
| 485 | - return rc; | |
| 486 | - } | |
| 487 | - | |
| 488 | - } else if(rc) { | |
| 489 | - | |
| 490 | - // SSL Negotiation has failed, no popup to present. | |
| 491 | - const LIB3270_POPUP popup = { | |
| 492 | - .summary = N_("SSL negotiation has failed") | |
| 493 | - }; | |
| 494 | - | |
| 495 | - msg.popup = &popup; | |
| 496 | - if(popup_ssl_error(hSession,rc,&msg)) | |
| 497 | - { | |
| 498 | - host_disconnect(hSession,1); // Disconnect with "failed" status. | |
| 499 | - return rc; | |
| 500 | - } | |
| 501 | - | |
| 502 | - } | |
| 503 | - | |
| 504 | - // Tell the world that we are (still) connected, now in secure mode. | |
| 505 | - lib3270_set_connected_initial(hSession); | |
| 506 | - non_blocking(hSession,True); | |
| 507 | - | |
| 508 | - return 0; | |
| 509 | -} | |
| 510 | - | |
| 511 | - | |
| 512 | -int ssl_init(H3270 *hSession) { | |
| 513 | - | |
| 514 | - int rc; | |
| 515 | - SSL_ERROR_MESSAGE msg; | |
| 516 | - | |
| 517 | - memset(&msg,0,sizeof(msg)); | |
| 518 | - | |
| 519 | - non_blocking(hSession,False); | |
| 520 | - | |
| 521 | - rc = lib3270_run_task(hSession, background_ssl_init, &msg); | |
| 522 | - if(rc) | |
| 523 | - { | |
| 524 | - // SSL init has failed. | |
| 525 | - host_disconnect(hSession,1); // Disconnect with "failed" status. | |
| 526 | - | |
| 527 | - if(msg.popup) | |
| 528 | - { | |
| 529 | - ssl_popup_message(hSession,&msg); | |
| 530 | - } | |
| 531 | - else | |
| 532 | - { | |
| 533 | - LIB3270_POPUP popup = { | |
| 534 | - .summary = N_("Unexpected error on SSL initialization") | |
| 535 | - }; | |
| 536 | - | |
| 537 | - lib3270_autoptr(char) body = lib3270_strdup_printf("%s (rc=%d)",strerror(rc),rc); | |
| 538 | - popup.body = body; | |
| 539 | - | |
| 540 | - msg.popup = &popup; | |
| 541 | - ssl_popup_message(hSession,&msg); | |
| 542 | - msg.popup = NULL; | |
| 543 | - | |
| 544 | - } | |
| 545 | - | |
| 546 | - | |
| 547 | - } | |
| 548 | - | |
| 549 | - non_blocking(hSession,True); | |
| 550 | - | |
| 551 | - return rc; | |
| 552 | - | |
| 553 | -} | |
| 554 | - | |
| 555 | -#endif /*]*/ | |
| 556 | - |
src/ssl/notify.c
| ... | ... | @@ -1,216 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | - * | |
| 28 | - * | |
| 29 | - * References: | |
| 30 | - * | |
| 31 | - * http://www.openssl.org/docs/ssl/ | |
| 32 | - * | |
| 33 | - */ | |
| 34 | - | |
| 35 | - | |
| 36 | -#include <config.h> | |
| 37 | -#include <internals.h> | |
| 38 | -#include <lib3270/log.h> | |
| 39 | -#include <lib3270/popup.h> | |
| 40 | -#include <lib3270/win32.h> | |
| 41 | - | |
| 42 | -/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 43 | - | |
| 44 | -#if defined(HAVE_LIBSSLx) | |
| 45 | - | |
| 46 | -#include <openssl/err.h> | |
| 47 | - | |
| 48 | -/** | |
| 49 | - * @brief Translate strings from ssl error message. | |
| 50 | - * | |
| 51 | - * @param msg SSL error message descriptor. | |
| 52 | - * @param rc Value of errno. | |
| 53 | - * | |
| 54 | - * @return Dynamically allocated popup description. | |
| 55 | - * | |
| 56 | - */ | |
| 57 | -static LIB3270_POPUP * translate_ssl_error_message(const SSL_ERROR_MESSAGE *msg, int rc) | |
| 58 | -{ | |
| 59 | - LIB3270_POPUP * popup; | |
| 60 | - | |
| 61 | - printf("\n\nMSG-CODE=%d\n\n",msg->code); | |
| 62 | - | |
| 63 | - const char *body = (msg->body ? msg->body : msg->popup->body); | |
| 64 | - | |
| 65 | - if(msg->code) | |
| 66 | - { | |
| 67 | - if(body) | |
| 68 | - { | |
| 69 | - popup = lib3270_popup_clone_printf( | |
| 70 | - msg->popup, | |
| 71 | - _( "%s\nThe SSL error message was \"%s\"(%d)" ), | |
| 72 | - dgettext(GETTEXT_PACKAGE,body), | |
| 73 | - ERR_reason_error_string(msg->code), | |
| 74 | - msg->code | |
| 75 | - ); | |
| 76 | - } | |
| 77 | - else | |
| 78 | - { | |
| 79 | - popup = lib3270_popup_clone_printf( | |
| 80 | - msg->popup, | |
| 81 | - _( "The SSL error message was \"%s\" (%d)" ), | |
| 82 | - ERR_reason_error_string(msg->code), | |
| 83 | - msg->code | |
| 84 | - ); | |
| 85 | - } | |
| 86 | - | |
| 87 | - } | |
| 88 | -#ifdef _WIN32 | |
| 89 | - else if(msg->lasterror) | |
| 90 | - { | |
| 91 | - lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(msg->lasterror); | |
| 92 | - | |
| 93 | - if(body) | |
| 94 | - { | |
| 95 | - popup = lib3270_popup_clone_printf( | |
| 96 | - msg->popup, | |
| 97 | - _( "%s\nThe windows error was \"%s\" (%u)" ), | |
| 98 | - dgettext(GETTEXT_PACKAGE,body), | |
| 99 | - windows_error, | |
| 100 | - (unsigned int) msg->lasterror | |
| 101 | - ); | |
| 102 | - } | |
| 103 | - else | |
| 104 | - { | |
| 105 | - popup = lib3270_popup_clone_printf( | |
| 106 | - msg->popup, | |
| 107 | - _( "Windows error was \"%s\" (%u)" ), | |
| 108 | - windows_error, | |
| 109 | - (unsigned int) msg->lasterror | |
| 110 | - ); | |
| 111 | - } | |
| 112 | - | |
| 113 | - } | |
| 114 | -#endif // _WIN32 | |
| 115 | - else if(rc) | |
| 116 | - { | |
| 117 | - if(body) | |
| 118 | - { | |
| 119 | - popup = lib3270_popup_clone_printf( | |
| 120 | - msg->popup, | |
| 121 | - _( "%s\nThe operating system error was \"%s\" (%u)" ), | |
| 122 | - dgettext(GETTEXT_PACKAGE,body), | |
| 123 | - strerror(rc), | |
| 124 | - rc | |
| 125 | - ); | |
| 126 | - } | |
| 127 | - else | |
| 128 | - { | |
| 129 | - popup = lib3270_popup_clone_printf( | |
| 130 | - msg->popup, | |
| 131 | - _( "The operating system error was \"%s\" (%u)" ), | |
| 132 | - strerror(rc), | |
| 133 | - rc | |
| 134 | - ); | |
| 135 | - } | |
| 136 | - | |
| 137 | - } | |
| 138 | - else | |
| 139 | - { | |
| 140 | - popup = lib3270_malloc(sizeof(LIB3270_POPUP)); | |
| 141 | - *popup = *msg->popup; | |
| 142 | - | |
| 143 | - if(body) | |
| 144 | - popup->body = dgettext(GETTEXT_PACKAGE,body); | |
| 145 | - | |
| 146 | - } | |
| 147 | - | |
| 148 | - popup->summary = dgettext(GETTEXT_PACKAGE,msg->popup->summary); | |
| 149 | - | |
| 150 | - debug("%s: names[\"%s\",\"%s\"]",__FUNCTION__,popup->name, msg->popup->name); | |
| 151 | - | |
| 152 | - if(popup->title) | |
| 153 | - popup->title = dgettext(GETTEXT_PACKAGE,popup->title); | |
| 154 | - else | |
| 155 | - popup->title = _("Your connection is not safe"); | |
| 156 | - | |
| 157 | - popup->label = _("Continue"); | |
| 158 | - return popup; | |
| 159 | -} | |
| 160 | - | |
| 161 | - | |
| 162 | -int popup_ssl_error(H3270 GNUC_UNUSED(*hSession), int rc, const SSL_ERROR_MESSAGE *msg) | |
| 163 | -{ | |
| 164 | - int response = 0; | |
| 165 | - | |
| 166 | - LIB3270_POPUP * popup = translate_ssl_error_message(msg,0); | |
| 167 | - | |
| 168 | -#ifdef _WIN32 | |
| 169 | - | |
| 170 | - lib3270_autoptr(char) rcMessage = lib3270_strdup_printf("The error code was %d",rc); | |
| 171 | - | |
| 172 | - const char *outMsg[] = { | |
| 173 | - popup->title, | |
| 174 | - popup->summary, | |
| 175 | - (popup->body ? popup->body : ""), | |
| 176 | - rcMessage | |
| 177 | - }; | |
| 178 | - | |
| 179 | - ReportEvent( | |
| 180 | - hEventLog, | |
| 181 | - EVENTLOG_ERROR_TYPE, | |
| 182 | - 1, | |
| 183 | - 0, | |
| 184 | - NULL, | |
| 185 | - (sizeof(outMsg)/sizeof(outMsg[0])), | |
| 186 | - 0, | |
| 187 | - outMsg, | |
| 188 | - NULL | |
| 189 | - ); | |
| 190 | - | |
| 191 | -#else | |
| 192 | - | |
| 193 | - lib3270_write_log(hSession, "SSL", "%s %s (rc=%d)", popup->summary, (popup->body ? popup->body : ""), rc); | |
| 194 | - | |
| 195 | -#endif // _WIN32 | |
| 196 | - | |
| 197 | -#ifdef SSL_ENABLE_NOTIFICATION_WHEN_FAILED | |
| 198 | - | |
| 199 | - response = hSession->cbk.popup(hSession,popup,1); | |
| 200 | - | |
| 201 | -#endif // SSL_ENABLE_NOTIFICATION_WHEN_FAILED | |
| 202 | - | |
| 203 | - lib3270_free(popup); | |
| 204 | - return response; | |
| 205 | - | |
| 206 | -} | |
| 207 | - | |
| 208 | -void ssl_popup_message(H3270 *hSession, const SSL_ERROR_MESSAGE *msg) { | |
| 209 | - | |
| 210 | - LIB3270_POPUP * popup = translate_ssl_error_message(msg,0); | |
| 211 | - hSession->cbk.popup(hSession,popup,0); | |
| 212 | - lib3270_free(popup); | |
| 213 | - | |
| 214 | -} | |
| 215 | - | |
| 216 | -#endif // defined(HAVE_LIBSSL) |
src/ssl/properties.c
| ... | ... | @@ -1,199 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | - * | |
| 28 | - */ | |
| 29 | - | |
| 30 | -#include <internals.h> | |
| 31 | -#include <lib3270/properties.h> | |
| 32 | - | |
| 33 | -#if defined(HAVE_LIBSSL) | |
| 34 | - #include <openssl/ssl.h> | |
| 35 | -#endif | |
| 36 | - | |
| 37 | - | |
| 38 | -/** | |
| 39 | - * @brief Get SSL host option. | |
| 40 | - * | |
| 41 | - * @return Non zero if the host URL has SSL scheme. | |
| 42 | - * | |
| 43 | - */ | |
| 44 | -#ifdef HAVE_LIBSSLx | |
| 45 | -LIB3270_EXPORT int lib3270_get_secure_host(const H3270 *hSession) | |
| 46 | -{ | |
| 47 | - return hSession->ssl.enabled ? 1 : 0; | |
| 48 | -} | |
| 49 | -#else | |
| 50 | -LIB3270_EXPORT int lib3270_get_secure_host(const H3270 GNUC_UNUSED(*hSession)) | |
| 51 | -{ | |
| 52 | - errno = ENOTSUP; | |
| 53 | - return 0; | |
| 54 | -} | |
| 55 | -#endif // HAVE_LIBSSL | |
| 56 | - | |
| 57 | - | |
| 58 | -#if defined(HAVE_LIBSSL) && defined(SSL_ENABLE_CRL_CHECK) | |
| 59 | -LIB3270_EXPORT char * lib3270_get_ssl_crl_text(const H3270 *hSession) | |
| 60 | -{ | |
| 61 | - | |
| 62 | - if(hSession->ssl.crl.cert) | |
| 63 | - { | |
| 64 | - | |
| 65 | - BIO * out = BIO_new(BIO_s_mem()); | |
| 66 | - unsigned char * data; | |
| 67 | - unsigned char * text; | |
| 68 | - int n; | |
| 69 | - | |
| 70 | - X509_CRL_print(out,hSession->ssl.crl.cert); | |
| 71 | - | |
| 72 | - n = BIO_get_mem_data(out, &data); | |
| 73 | - text = (unsigned char *) lib3270_malloc(n+1); | |
| 74 | - text[n] ='\0'; | |
| 75 | - | |
| 76 | - memcpy(text,data,n); | |
| 77 | - BIO_free(out); | |
| 78 | - | |
| 79 | - return (char *) text; | |
| 80 | - | |
| 81 | - } | |
| 82 | - | |
| 83 | - return NULL; | |
| 84 | - | |
| 85 | -} | |
| 86 | -#else | |
| 87 | -LIB3270_EXPORT char * lib3270_get_ssl_crl_text(const H3270 GNUC_UNUSED(*hSession)) | |
| 88 | -{ | |
| 89 | - return NULL; | |
| 90 | -} | |
| 91 | -#endif // SSL_ENABLE_CRL_CHECK | |
| 92 | - | |
| 93 | - | |
| 94 | -LIB3270_EXPORT char * lib3270_get_ssl_peer_certificate_text(const H3270 *hSession) | |
| 95 | -{ | |
| 96 | -#ifdef HAVE_LIBSSLx | |
| 97 | - if(hSession->ssl.con) | |
| 98 | - { | |
| 99 | - X509 * peer = SSL_get_peer_certificate(hSession->ssl.con); | |
| 100 | - if(peer) | |
| 101 | - { | |
| 102 | - BIO * out = BIO_new(BIO_s_mem()); | |
| 103 | - unsigned char * data; | |
| 104 | - unsigned char * text; | |
| 105 | - int n; | |
| 106 | - | |
| 107 | - X509_print(out,peer); | |
| 108 | - | |
| 109 | - n = BIO_get_mem_data(out, &data); | |
| 110 | - text = (unsigned char *) lib3270_malloc(n+1); | |
| 111 | - text[n] ='\0'; | |
| 112 | - memcpy(text,data,n); | |
| 113 | - BIO_free(out); | |
| 114 | - | |
| 115 | - return (char *) text; | |
| 116 | - } | |
| 117 | - } | |
| 118 | -#endif // HAVE_LIBSSL | |
| 119 | - | |
| 120 | - return NULL; | |
| 121 | -} | |
| 122 | - | |
| 123 | - #pragma GCC diagnostic push | |
| 124 | - #pragma GCC diagnostic ignored "-Wunused-parameter" | |
| 125 | - const char * lib3270_crl_get_url(const H3270 *hSession) | |
| 126 | - { | |
| 127 | -#if defined(HAVE_LIBSSL) && defined(SSL_ENABLE_CRL_CHECK) | |
| 128 | - if(hSession->ssl.crl.url) | |
| 129 | - return hSession->ssl.crl.url; | |
| 130 | - | |
| 131 | -#ifdef SSL_CRL_URL | |
| 132 | - return SSL_CRL_URL; | |
| 133 | -#else | |
| 134 | - return getenv("LIB3270_DEFAULT_CRL"); | |
| 135 | -#endif // SSL_CRL_URL | |
| 136 | - | |
| 137 | -#else | |
| 138 | - errno = ENOTSUP; | |
| 139 | - return ""; | |
| 140 | -#endif | |
| 141 | - } | |
| 142 | - #pragma GCC diagnostic pop | |
| 143 | - | |
| 144 | - #pragma GCC diagnostic push | |
| 145 | - #pragma GCC diagnostic ignored "-Wunused-parameter" | |
| 146 | - int lib3270_crl_set_url(H3270 *hSession, const char *crl) | |
| 147 | - { | |
| 148 | - | |
| 149 | - FAIL_IF_ONLINE(hSession); | |
| 150 | - | |
| 151 | -#if defined(HAVE_LIBSSLx) && defined(SSL_ENABLE_CRL_CHECK) | |
| 152 | - | |
| 153 | - if(hSession->ssl.crl.url) | |
| 154 | - { | |
| 155 | - free(hSession->ssl.crl.url); | |
| 156 | - hSession->ssl.crl.url = NULL; | |
| 157 | - } | |
| 158 | - | |
| 159 | - if(hSession->ssl.crl.cert) | |
| 160 | - { | |
| 161 | - X509_CRL_free(hSession->ssl.crl.cert); | |
| 162 | - hSession->ssl.crl.cert = NULL; | |
| 163 | - } | |
| 164 | - | |
| 165 | - if(crl) | |
| 166 | - { | |
| 167 | - hSession->ssl.crl.url = strdup(crl); | |
| 168 | - } | |
| 169 | - | |
| 170 | - return 0; | |
| 171 | - | |
| 172 | -#else | |
| 173 | - | |
| 174 | - return errno = ENOTSUP; | |
| 175 | - | |
| 176 | -#endif // SSL_ENABLE_CRL_CHECK | |
| 177 | - | |
| 178 | - } | |
| 179 | - #pragma GCC diagnostic pop | |
| 180 | - | |
| 181 | - const char ** lib3270_crl_get_available_protocols(void) | |
| 182 | - { | |
| 183 | - static const char * protocols[] = | |
| 184 | - { | |
| 185 | -#ifdef HAVE_LDAP | |
| 186 | - "ldap", | |
| 187 | -#endif // HAVE_LDAP | |
| 188 | - | |
| 189 | -#if defined(_WIN32) || defined(HAVE_LIBCURL) | |
| 190 | - "http", | |
| 191 | -#endif // _WIN32 || LIBCURL | |
| 192 | - | |
| 193 | - NULL | |
| 194 | - }; | |
| 195 | - | |
| 196 | - return protocols; | |
| 197 | - } | |
| 198 | - | |
| 199 | - |
src/ssl/windows/curl.c
| ... | ... | @@ -1,382 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | - * | |
| 28 | - * References: | |
| 29 | - * | |
| 30 | - * http://www.openssl.org/docs/ssl/ | |
| 31 | - * https://stackoverflow.com/questions/4389954/does-openssl-automatically-handle-crls-certificate-revocation-lists-now | |
| 32 | - * | |
| 33 | - */ | |
| 34 | - | |
| 35 | -#include <config.h> | |
| 36 | - | |
| 37 | -#if defined(HAVE_LIBSSL) && defined(SSL_ENABLE_CRL_CHECK) && defined(HAVE_LIBCURL) | |
| 38 | - | |
| 39 | -#include "private.h" | |
| 40 | -#include <curl/curl.h> | |
| 41 | -#include <lib3270/toggle.h> | |
| 42 | - | |
| 43 | -#define CRL_DATA_LENGTH 2048 | |
| 44 | - | |
| 45 | -/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 46 | - | |
| 47 | -static inline void lib3270_autoptr_cleanup_CURL(CURL **ptr) | |
| 48 | -{ | |
| 49 | - debug("%s(%p)",__FUNCTION__,*ptr); | |
| 50 | - if(*ptr) | |
| 51 | - curl_easy_cleanup(*ptr); | |
| 52 | - *ptr = NULL; | |
| 53 | -} | |
| 54 | - | |
| 55 | -typedef struct _curldata | |
| 56 | -{ | |
| 57 | - size_t length; | |
| 58 | - H3270 * hSession; | |
| 59 | - SSL_ERROR_MESSAGE * message; | |
| 60 | - char errbuf[CURL_ERROR_SIZE]; | |
| 61 | - struct { | |
| 62 | - size_t length; | |
| 63 | - unsigned char * contents; | |
| 64 | - } data; | |
| 65 | -} CURLDATA; | |
| 66 | - | |
| 67 | -static inline void lib3270_autoptr_cleanup_CURLDATA(CURLDATA **ptr) | |
| 68 | -{ | |
| 69 | - debug("%s(%p)",__FUNCTION__,*ptr); | |
| 70 | - if(*ptr) | |
| 71 | - { | |
| 72 | - CURLDATA *cdata = *ptr; | |
| 73 | - | |
| 74 | - if(cdata->data.contents) { | |
| 75 | - lib3270_free(cdata->data.contents); | |
| 76 | - cdata->data.contents = NULL; | |
| 77 | - } | |
| 78 | - lib3270_free(cdata); | |
| 79 | - } | |
| 80 | - *ptr = NULL; | |
| 81 | -} | |
| 82 | - | |
| 83 | -static inline void lib3270_autoptr_cleanup_BIO(BIO **ptr) | |
| 84 | -{ | |
| 85 | - debug("%s(%p)",__FUNCTION__,*ptr); | |
| 86 | - if(*ptr) | |
| 87 | - BIO_free_all(*ptr); | |
| 88 | - *ptr = NULL; | |
| 89 | -} | |
| 90 | - | |
| 91 | -static size_t internal_curl_write_callback(void *contents, size_t size, size_t nmemb, void *userp) | |
| 92 | -{ | |
| 93 | - CURLDATA * data = (CURLDATA *) userp; | |
| 94 | - | |
| 95 | - size_t realsize = size * nmemb; | |
| 96 | - size_t ix; | |
| 97 | - | |
| 98 | - debug("Received %u bytes (datablock is %p)", (unsigned int) realsize, data); | |
| 99 | - | |
| 100 | - unsigned char *ptr = (unsigned char *) contents; | |
| 101 | - | |
| 102 | - if(lib3270_get_toggle(data->hSession,LIB3270_TOGGLE_SSL_TRACE)) | |
| 103 | - lib3270_trace_data(data->hSession,"curl_write:",(const char *) contents, realsize); | |
| 104 | - | |
| 105 | - if((realsize + data->length) > data->data.length) | |
| 106 | - { | |
| 107 | - data->data.length += (CRL_DATA_LENGTH + realsize); | |
| 108 | - data->data.contents = lib3270_realloc(data->data.contents,data->data.length); | |
| 109 | - | |
| 110 | - for(ix = data->length; ix < data->data.length; ix++) | |
| 111 | - { | |
| 112 | - data->data.contents[ix] = 0; | |
| 113 | - } | |
| 114 | - | |
| 115 | - } | |
| 116 | - | |
| 117 | - for(ix = 0; ix < realsize; ix++) | |
| 118 | - { | |
| 119 | - data->data.contents[data->length++] = *(ptr++); | |
| 120 | - } | |
| 121 | - | |
| 122 | - return realsize; | |
| 123 | -} | |
| 124 | - | |
| 125 | -static int internal_curl_trace_callback(CURL GNUC_UNUSED(*handle), curl_infotype type, char *data, size_t size, void *userp) | |
| 126 | -{ | |
| 127 | - const char * text = NULL; | |
| 128 | - | |
| 129 | - switch (type) { | |
| 130 | - case CURLINFO_TEXT: | |
| 131 | - lib3270_write_log(((CURLDATA *) userp)->hSession,"curl","%s",data); | |
| 132 | - return 0; | |
| 133 | - | |
| 134 | - case CURLINFO_HEADER_OUT: | |
| 135 | - text = "=> Send header"; | |
| 136 | - break; | |
| 137 | - | |
| 138 | - case CURLINFO_DATA_OUT: | |
| 139 | - text = "=> Send data"; | |
| 140 | - break; | |
| 141 | - | |
| 142 | - case CURLINFO_SSL_DATA_OUT: | |
| 143 | - text = "=> Send SSL data"; | |
| 144 | - break; | |
| 145 | - | |
| 146 | - case CURLINFO_HEADER_IN: | |
| 147 | - text = "<= Recv header"; | |
| 148 | - break; | |
| 149 | - | |
| 150 | - case CURLINFO_DATA_IN: | |
| 151 | - text = "<= Recv data"; | |
| 152 | - break; | |
| 153 | - | |
| 154 | - case CURLINFO_SSL_DATA_IN: | |
| 155 | - text = "<= Recv SSL data"; | |
| 156 | - break; | |
| 157 | - | |
| 158 | - default: | |
| 159 | - return 0; | |
| 160 | - | |
| 161 | - } | |
| 162 | - | |
| 163 | - lib3270_trace_data( | |
| 164 | - ((CURLDATA *) userp)->hSession, | |
| 165 | - text, | |
| 166 | - data, | |
| 167 | - size | |
| 168 | - ); | |
| 169 | - | |
| 170 | - return 0; | |
| 171 | -} | |
| 172 | - | |
| 173 | -X509_CRL * get_crl_using_curl(H3270 *hSession, SSL_ERROR_MESSAGE * message, const char *consturl) | |
| 174 | -{ | |
| 175 | - X509_CRL * x509_crl = NULL; | |
| 176 | - | |
| 177 | - lib3270_autoptr(CURLDATA) crl_data = lib3270_malloc(sizeof(CURLDATA)); | |
| 178 | - lib3270_autoptr(CURL) hCurl = curl_easy_init(); | |
| 179 | - | |
| 180 | - memset(crl_data,0,sizeof(CURLDATA)); | |
| 181 | - crl_data->message = message; | |
| 182 | - crl_data->hSession = hSession; | |
| 183 | - crl_data->data.length = CRL_DATA_LENGTH; | |
| 184 | - crl_data->data.contents = lib3270_malloc(crl_data->data.length); | |
| 185 | - | |
| 186 | - if(!hCurl) | |
| 187 | - { | |
| 188 | - message->title = _( "Security error" ); | |
| 189 | - message->text = _( "Error loading certificate revocation list" ); | |
| 190 | - message->description = _( "Can't initialize curl operation" ); | |
| 191 | - return NULL; | |
| 192 | - } | |
| 193 | - | |
| 194 | - CURLcode res; | |
| 195 | - | |
| 196 | - curl_easy_setopt(hCurl, CURLOPT_URL, consturl); | |
| 197 | - curl_easy_setopt(hCurl, CURLOPT_FOLLOWLOCATION, 1L); | |
| 198 | - | |
| 199 | - curl_easy_setopt(hCurl, CURLOPT_ERRORBUFFER, crl_data->errbuf); | |
| 200 | - | |
| 201 | - curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, internal_curl_write_callback); | |
| 202 | - curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void *) crl_data); | |
| 203 | - | |
| 204 | - curl_easy_setopt(hCurl, CURLOPT_USERNAME, ""); | |
| 205 | - | |
| 206 | - if(lib3270_get_toggle(hSession,LIB3270_TOGGLE_SSL_TRACE)) | |
| 207 | - { | |
| 208 | - curl_easy_setopt(hCurl, CURLOPT_VERBOSE, 1L); | |
| 209 | - curl_easy_setopt(hCurl, CURLOPT_DEBUGFUNCTION, internal_curl_trace_callback); | |
| 210 | - curl_easy_setopt(hCurl, CURLOPT_DEBUGDATA, (void *) crl_data); | |
| 211 | - } | |
| 212 | - | |
| 213 | - res = curl_easy_perform(hCurl); | |
| 214 | - | |
| 215 | - if(res != CURLE_OK) | |
| 216 | - { | |
| 217 | - message->error = hSession->ssl.error = 0; | |
| 218 | - message->title = _( "Security error" ); | |
| 219 | - | |
| 220 | - if(crl_data->errbuf[0]) | |
| 221 | - { | |
| 222 | - message->text = curl_easy_strerror(res); | |
| 223 | - message->description = crl_data->errbuf; | |
| 224 | - } | |
| 225 | - else | |
| 226 | - { | |
| 227 | - message->text = _( "Error loading certificate revocation list" ); | |
| 228 | - message->description = curl_easy_strerror(res); | |
| 229 | - } | |
| 230 | - | |
| 231 | - lib3270_write_log(hSession,"ssl","%s: %s",consturl, message->description); | |
| 232 | - errno = EINVAL; | |
| 233 | - return NULL; | |
| 234 | - | |
| 235 | - } | |
| 236 | - | |
| 237 | - char *ct = NULL; | |
| 238 | - res = curl_easy_getinfo(hCurl, CURLINFO_CONTENT_TYPE, &ct); | |
| 239 | - if(res != CURLE_OK) | |
| 240 | - { | |
| 241 | - message->error = hSession->ssl.error = 0; | |
| 242 | - message->title = _( "Security error" ); | |
| 243 | - message->text = _( "Error loading certificate revocation list" ); | |
| 244 | - message->description = curl_easy_strerror(res); | |
| 245 | - lib3270_write_log(hSession,"ssl","%s: %s",consturl, message->description); | |
| 246 | - errno = EINVAL; | |
| 247 | - return NULL; | |
| 248 | - } | |
| 249 | - | |
| 250 | - if(lib3270_get_toggle(crl_data->hSession,LIB3270_TOGGLE_SSL_TRACE)) | |
| 251 | - lib3270_trace_data(crl_data->hSession,"CRL Data",(const char *) crl_data->data.contents, (unsigned int) crl_data->length); | |
| 252 | - | |
| 253 | - if(ct) | |
| 254 | - { | |
| 255 | - const unsigned char * data = crl_data->data.contents; | |
| 256 | - | |
| 257 | - if(strcasecmp(ct,"application/pkix-crl") == 0) | |
| 258 | - { | |
| 259 | - // CRL File, convert it | |
| 260 | - if(!d2i_X509_CRL(&x509_crl, &data, crl_data->length)) | |
| 261 | - { | |
| 262 | - message->error = hSession->ssl.error = ERR_get_error(); | |
| 263 | - message->title = _( "Security error" ); | |
| 264 | - message->text = _( "Can't decode certificate revocation list" ); | |
| 265 | - lib3270_write_log(hSession,"ssl","%s: %s",consturl, message->text); | |
| 266 | - return NULL; | |
| 267 | - } | |
| 268 | - } | |
| 269 | - else | |
| 270 | - { | |
| 271 | - message->error = hSession->ssl.error = ERR_get_error(); | |
| 272 | - message->title = _( "Security error" ); | |
| 273 | - message->text = _( "Got an invalid certificate revocation list from server" ); | |
| 274 | - lib3270_write_log(hSession,"ssl","%s: content-type unexpected: \"%s\"",consturl, ct); | |
| 275 | - errno = EINVAL; | |
| 276 | - return NULL; | |
| 277 | - } | |
| 278 | - } | |
| 279 | - else if(strncasecmp(consturl,"ldap://",7) == 0) | |
| 280 | - { | |
| 281 | - // | |
| 282 | - // curl's LDAP query on windows returns diferently. Working with it. | |
| 283 | - // | |
| 284 | -#ifdef DEBUG | |
| 285 | - { | |
| 286 | - FILE *out = fopen("downloaded.crl","w"); | |
| 287 | - if(out) | |
| 288 | - { | |
| 289 | - fwrite(crl_data->data.contents,crl_data->length,1,out); | |
| 290 | - fclose(out); | |
| 291 | - } | |
| 292 | - | |
| 293 | - } | |
| 294 | -#endif | |
| 295 | - | |
| 296 | - char * attr = strchr(consturl,'?'); | |
| 297 | - if(!attr) | |
| 298 | - { | |
| 299 | - message->error = hSession->ssl.error = 0; | |
| 300 | - message->title = _( "Security error" ); | |
| 301 | - message->text = _( "No attribute in LDAP search URL" ); | |
| 302 | - errno = ENOENT; | |
| 303 | - return NULL; | |
| 304 | - } | |
| 305 | - | |
| 306 | - attr++; | |
| 307 | - | |
| 308 | - lib3270_autoptr(char) text = lib3270_strdup_printf("No mime-type, extracting \"%s\" directly from LDAP response\n",attr); | |
| 309 | - trace_ssl(crl_data->hSession, text); | |
| 310 | - | |
| 311 | - lib3270_autoptr(char) key = lib3270_strdup_printf("%s: ",attr); | |
| 312 | - | |
| 313 | - | |
| 314 | -// char *ptr = strcasestr((char *) crl_data->data.contents, key); | |
| 315 | - | |
| 316 | - size_t ix; | |
| 317 | - unsigned char *from = NULL; | |
| 318 | - size_t keylength = strlen(key); | |
| 319 | - for(ix = 0; ix < (crl_data->length - keylength); ix++) | |
| 320 | - { | |
| 321 | - if(!strncasecmp( (char *) (crl_data->data.contents+ix),key,keylength)) | |
| 322 | - { | |
| 323 | - from = crl_data->data.contents+ix; | |
| 324 | - break; | |
| 325 | - } | |
| 326 | - } | |
| 327 | - | |
| 328 | - debug("strstr(%s): %p", key, from); | |
| 329 | - | |
| 330 | - if(!from) | |
| 331 | - { | |
| 332 | - message->error = hSession->ssl.error = 0; | |
| 333 | - message->title = _( "Security error" ); | |
| 334 | - message->text = _( "Can't find certificate revocation list in LDAP response" ); | |
| 335 | - errno = ENOENT; | |
| 336 | - return NULL; | |
| 337 | - } | |
| 338 | - | |
| 339 | - from += strlen(key); | |
| 340 | - size_t length = crl_data->length - (from - crl_data->data.contents); | |
| 341 | - | |
| 342 | - static const char terminator[] = { 0x0a, 0x0a, 0x09 }; | |
| 343 | - unsigned char *to = from+length; | |
| 344 | - | |
| 345 | - for(ix = 0; ix < (length - sizeof(terminator)); ix++) | |
| 346 | - { | |
| 347 | - if(!memcmp(from+ix,terminator,sizeof(terminator))) | |
| 348 | - { | |
| 349 | - to = from+ix; | |
| 350 | - break; | |
| 351 | - } | |
| 352 | - } | |
| 353 | - | |
| 354 | - length = to - from; | |
| 355 | - | |
| 356 | - if(lib3270_get_toggle(hSession,LIB3270_TOGGLE_SSL_TRACE)) | |
| 357 | - { | |
| 358 | - lib3270_trace_data( | |
| 359 | - hSession, | |
| 360 | - "CRL Data received from LDAP server", | |
| 361 | - (const char *) from, | |
| 362 | - length | |
| 363 | - ); | |
| 364 | - } | |
| 365 | - | |
| 366 | - if(!d2i_X509_CRL(&x509_crl, (const unsigned char **) &from, length)) | |
| 367 | - { | |
| 368 | - message->error = hSession->ssl.error = ERR_get_error(); | |
| 369 | - message->title = _( "Security error" ); | |
| 370 | - message->text = _( "Can't decode certificate revocation list got from LDAP Search" ); | |
| 371 | - lib3270_write_log(hSession,"ssl","%s: %s",consturl, message->text); | |
| 372 | - errno = EINVAL; | |
| 373 | - return NULL; | |
| 374 | - } | |
| 375 | - | |
| 376 | - } | |
| 377 | - | |
| 378 | - return x509_crl; | |
| 379 | - | |
| 380 | -} | |
| 381 | - | |
| 382 | -#endif // defined(HAVE_LIBSSL) && defined(SSL_ENABLE_CRL_CHECK) && defined(HAVE_LIBCURL) |
src/ssl/windows/getcrl.c
| ... | ... | @@ -1,145 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | - * | |
| 28 | - * | |
| 29 | - * References: | |
| 30 | - * | |
| 31 | - * http://www.openssl.org/docs/ssl/ | |
| 32 | - * https://stackoverflow.com/questions/4389954/does-openssl-automatically-handle-crls-certificate-revocation-lists-now | |
| 33 | - * | |
| 34 | - */ | |
| 35 | - | |
| 36 | -#include <config.h> | |
| 37 | - | |
| 38 | -#if defined(HAVE_LIBSSL) && defined(SSL_ENABLE_CRL_CHECK) | |
| 39 | - | |
| 40 | -#include "private.h" | |
| 41 | - | |
| 42 | -/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 43 | - | |
| 44 | -static inline void lib3270_autoptr_cleanup_FILE(FILE **file) | |
| 45 | -{ | |
| 46 | - if(*file) | |
| 47 | - fclose(*file); | |
| 48 | -} | |
| 49 | - | |
| 50 | -X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, const char *consturl) | |
| 51 | -{ | |
| 52 | - X509_CRL * x509_crl = NULL; | |
| 53 | - | |
| 54 | - if(!(consturl && *consturl)) | |
| 55 | - { | |
| 56 | - static const LIB3270_POPUP popup = { | |
| 57 | - .name = "CantOpenCRL", | |
| 58 | - .summary = N_("Can´t open CRL file"), | |
| 59 | - .body = N_("The URL for the CRL is undefined or empty") | |
| 60 | - }; | |
| 61 | - | |
| 62 | - message->code = hSession->ssl.error = 0; | |
| 63 | - message->popup = &popup; | |
| 64 | - errno = ENOENT; | |
| 65 | - return NULL; | |
| 66 | - } | |
| 67 | - | |
| 68 | - if(strncasecmp(consturl,"file://",7) == 0) | |
| 69 | - { | |
| 70 | - lib3270_autoptr(FILE) hCRL = fopen(consturl+7,"r"); | |
| 71 | - | |
| 72 | - if(!hCRL) | |
| 73 | - { | |
| 74 | - // Can't open CRL File. | |
| 75 | - static const LIB3270_POPUP popup = { | |
| 76 | - .summary = N_("Can´t open CRL file"), | |
| 77 | - .body = N_("Unable to open the defined CRL file") | |
| 78 | - }; | |
| 79 | - | |
| 80 | - message->code = errno; | |
| 81 | - message->popup = &popup; | |
| 82 | - hSession->ssl.error = 0; | |
| 83 | - trace_ssl(hSession,"Can't open %s: %s\n",consturl,strerror(errno)); | |
| 84 | - return NULL; | |
| 85 | - | |
| 86 | - } | |
| 87 | - | |
| 88 | - trace_ssl(hSession,"Loading CRL from %s\n",consturl+7); | |
| 89 | - if(d2i_X509_CRL_fp(hCRL, &x509_crl)) | |
| 90 | - { | |
| 91 | - static const LIB3270_POPUP popup = { | |
| 92 | - .summary = N_("Unable to decode CRL") | |
| 93 | - }; | |
| 94 | - | |
| 95 | - message->code = hSession->ssl.error = ERR_get_error(); | |
| 96 | - message->popup = &popup; | |
| 97 | - lib3270_write_log(hSession,"ssl","%s: %s",consturl, popup.summary); | |
| 98 | - return NULL; | |
| 99 | - } | |
| 100 | - | |
| 101 | - | |
| 102 | - | |
| 103 | - } | |
| 104 | -#ifdef HAVE_LDAP | |
| 105 | - else if(strncasecmp(consturl,"ldap://",7) == 0 && strlen(consturl) > 8) | |
| 106 | - { | |
| 107 | - return get_crl_using_ldap(hSession, message, consturl); | |
| 108 | - | |
| 109 | - } | |
| 110 | -#endif // HAVE_LDAP | |
| 111 | - else if(strncasecmp(consturl,"http://",7) == 0 && strlen(consturl) > 8) | |
| 112 | - { | |
| 113 | - return get_crl_using_http(hSession, message, consturl); | |
| 114 | - } | |
| 115 | - else | |
| 116 | - { | |
| 117 | -#ifdef HAVE_LIBCURL | |
| 118 | - | |
| 119 | - return get_crl_using_url(hSession, message, consturl); | |
| 120 | - | |
| 121 | -#else | |
| 122 | - // Can't get CRL. | |
| 123 | - | |
| 124 | - message->code = hSession->ssl.error = 0; | |
| 125 | - if(!message->popup) { | |
| 126 | - static const LIB3270_POPUP popup = { | |
| 127 | - .summary = N_( "Unexpected or invalid CRL URL" ), | |
| 128 | - .body = N_("The URL scheme is unknown") | |
| 129 | - }; | |
| 130 | - message->popup = &popup; | |
| 131 | - } | |
| 132 | - | |
| 133 | - trace_ssl(hSession,"%s: The URL scheme is unknown",consturl); | |
| 134 | - | |
| 135 | - errno = EINVAL; | |
| 136 | - return NULL; | |
| 137 | - | |
| 138 | -#endif // HAVE_LIBCURL | |
| 139 | - } | |
| 140 | - | |
| 141 | - return x509_crl; | |
| 142 | - | |
| 143 | -} | |
| 144 | - | |
| 145 | -#endif // HAVE_LIBSSL && SSL_ENABLE_CRL_CHECK |
src/ssl/windows/http.c
| ... | ... | @@ -1,101 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | - * | |
| 28 | - * References: | |
| 29 | - * | |
| 30 | - * https://docs.microsoft.com/en-us/windows/win32/winhttp/winhttp-autoproxy-api | |
| 31 | - * | |
| 32 | - */ | |
| 33 | - | |
| 34 | -/** | |
| 35 | - * @brief Implements CRL download using winhttp. | |
| 36 | - * | |
| 37 | - */ | |
| 38 | - | |
| 39 | -#include <config.h> | |
| 40 | -#include "private.h" | |
| 41 | - | |
| 42 | -#if defined(HAVE_LIBSSL) && defined(SSL_ENABLE_CRL_CHECK) | |
| 43 | - | |
| 44 | -#include <winhttp.h> | |
| 45 | -#include <utilc.h> | |
| 46 | - | |
| 47 | -/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 48 | - | |
| 49 | -X509_CRL * get_crl_using_http(H3270 *hSession, SSL_ERROR_MESSAGE * message, const char *consturl) | |
| 50 | -{ | |
| 51 | - size_t szResponse = 0; | |
| 52 | - const char * error_message = NULL; | |
| 53 | - lib3270_autoptr(char) httpText = lib3270_get_from_url(hSession, consturl, &szResponse, &error_message); | |
| 54 | - | |
| 55 | - if(!httpText) | |
| 56 | - { | |
| 57 | - static LIB3270_POPUP popup = { | |
| 58 | - .summary = N_("Can´t get CRL"), | |
| 59 | - }; | |
| 60 | - | |
| 61 | - popup.body = error_message; | |
| 62 | - message->popup = &popup; | |
| 63 | - message->code = hSession->ssl.error = 0; | |
| 64 | - trace_ssl( | |
| 65 | - hSession,"Can't get %s: %s\n", | |
| 66 | - consturl, | |
| 67 | - popup.body ? popup.body : "Undefined message" | |
| 68 | - ); | |
| 69 | - return NULL; | |
| 70 | - } | |
| 71 | - | |
| 72 | - // Copy the pointer because d2i_X509_CRL changes the value!!! | |
| 73 | - const unsigned char *crl_data = (const unsigned char *) httpText; | |
| 74 | - | |
| 75 | - X509_CRL * x509_crl = NULL; | |
| 76 | - | |
| 77 | - if(!d2i_X509_CRL(&x509_crl,&crl_data, (DWORD) szResponse)) | |
| 78 | - { | |
| 79 | - static const LIB3270_POPUP popup = { | |
| 80 | - .summary = N_( "Can't decode certificate revocation list" ) | |
| 81 | - }; | |
| 82 | - message->code = hSession->ssl.error = ERR_get_error(); | |
| 83 | - message->popup = &popup; | |
| 84 | - lib3270_write_log(hSession,"ssl","%s: %s",consturl, popup.summary); | |
| 85 | - | |
| 86 | - trace_ssl( | |
| 87 | - hSession,"%s: %s\n", | |
| 88 | - consturl, | |
| 89 | - popup.summary | |
| 90 | - ); | |
| 91 | - | |
| 92 | - return NULL; | |
| 93 | - } | |
| 94 | - | |
| 95 | - trace_ssl(hSession,"Got CRL from %s\n",consturl); | |
| 96 | - | |
| 97 | - return x509_crl; | |
| 98 | - | |
| 99 | -} | |
| 100 | - | |
| 101 | -#endif // defined(HAVE_LIBSSL) && defined(SSL_ENABLE_CRL_CHECK) |
src/ssl/windows/init.c
| ... | ... | @@ -1,195 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | - * | |
| 28 | - * | |
| 29 | - * References: | |
| 30 | - * | |
| 31 | - * http://www.openssl.org/docs/ssl/ | |
| 32 | - * https://stackoverflow.com/questions/4389954/does-openssl-automatically-handle-crls-certificate-revocation-lists-now | |
| 33 | - * | |
| 34 | - */ | |
| 35 | - | |
| 36 | -/** | |
| 37 | - * @brief OpenSSL initialization for linux. | |
| 38 | - * | |
| 39 | - */ | |
| 40 | - | |
| 41 | -#include <winsock2.h> | |
| 42 | -#include <windows.h> | |
| 43 | -#include <config.h> | |
| 44 | - | |
| 45 | -#if defined(HAVE_LIBSSL) | |
| 46 | - | |
| 47 | -#include <openssl/ssl.h> | |
| 48 | -#include <openssl/err.h> | |
| 49 | -#include <openssl/x509_vfy.h> | |
| 50 | - | |
| 51 | -#ifndef SSL_ST_OK | |
| 52 | - #define SSL_ST_OK 3 | |
| 53 | -#endif // !SSL_ST_OK | |
| 54 | - | |
| 55 | -#include <internals.h> | |
| 56 | -#include <errno.h> | |
| 57 | -#include <lib3270.h> | |
| 58 | -#include <lib3270/internals.h> | |
| 59 | -#include <lib3270/trace.h> | |
| 60 | -#include <lib3270/log.h> | |
| 61 | -#include <dirent.h> | |
| 62 | - | |
| 63 | -#include "trace_dsc.h" | |
| 64 | - | |
| 65 | -#include <openssl/x509.h> | |
| 66 | - | |
| 67 | -/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 68 | - | |
| 69 | -/** | |
| 70 | - * @brief Initialize openssl library. | |
| 71 | - * | |
| 72 | - * @return 0 if ok, non zero if fails. | |
| 73 | - * | |
| 74 | - */ | |
| 75 | -int ssl_ctx_init(H3270 *hSession, SSL_ERROR_MESSAGE * message) | |
| 76 | -{ | |
| 77 | - debug("%s ssl_ctx=%p",__FUNCTION__,ssl_ctx); | |
| 78 | - | |
| 79 | - if(ssl_ctx) | |
| 80 | - return 0; | |
| 81 | - | |
| 82 | - trace_ssl(hSession,"Initializing SSL context.\n"); | |
| 83 | - | |
| 84 | - SSL_load_error_strings(); | |
| 85 | - SSL_library_init(); | |
| 86 | - | |
| 87 | - ssl_ctx = SSL_CTX_new(SSLv23_method()); | |
| 88 | - if(ssl_ctx == NULL) | |
| 89 | - { | |
| 90 | - static const LIB3270_POPUP popup = { | |
| 91 | - .summary = N_( "Cant initialize the SSL context." ) | |
| 92 | - }; | |
| 93 | - | |
| 94 | - message->code = hSession->ssl.error = ERR_get_error(); | |
| 95 | - message->popup = &popup; | |
| 96 | - return -1; | |
| 97 | - } | |
| 98 | - | |
| 99 | - SSL_CTX_set_options(ssl_ctx, SSL_OP_ALL); | |
| 100 | - SSL_CTX_set_info_callback(ssl_ctx, ssl_info_callback); | |
| 101 | - | |
| 102 | - // SSL_CTX_set_default_verify_paths(ssl_ctx); | |
| 103 | - | |
| 104 | - // Load certs | |
| 105 | - // https://stackoverflow.com/questions/9507184/can-openssl-on-windows-use-the-system-certificate-store | |
| 106 | - X509_STORE * store = SSL_CTX_get_cert_store(ssl_ctx); | |
| 107 | - | |
| 108 | - lib3270_autoptr(char) certpath = lib3270_build_data_filename("certs","*.der",NULL); | |
| 109 | - | |
| 110 | - WIN32_FIND_DATA ffd; | |
| 111 | - HANDLE hFind = FindFirstFile(certpath, &ffd); | |
| 112 | - | |
| 113 | - if(hFind == INVALID_HANDLE_VALUE) | |
| 114 | - { | |
| 115 | - static const LIB3270_POPUP popup = { | |
| 116 | - .summary = N_( "Cant open custom certificate directory." ) | |
| 117 | - }; | |
| 118 | - | |
| 119 | - message->popup = &popup; | |
| 120 | - | |
| 121 | - trace_ssl(hSession, _( "Can't open \"%s\" (The Windows error code was %ld)\n" ), certpath, (long) GetLastError()); | |
| 122 | - } | |
| 123 | - else | |
| 124 | - { | |
| 125 | - do | |
| 126 | - { | |
| 127 | - char * filename = lib3270_build_data_filename("certs", ffd.cFileName, NULL); | |
| 128 | - | |
| 129 | - debug("Loading \"%s\"",filename); | |
| 130 | - | |
| 131 | - FILE *fp = fopen(filename,"r"); | |
| 132 | - if(!fp) { | |
| 133 | - | |
| 134 | - trace_ssl(hSession, _( "Can't open \"%s\": %s" ), filename, strerror(errno)); | |
| 135 | - | |
| 136 | - } | |
| 137 | - else | |
| 138 | - { | |
| 139 | - X509 * cert = d2i_X509_fp(fp, NULL); | |
| 140 | - | |
| 141 | - if(!cert) | |
| 142 | - { | |
| 143 | - static const LIB3270_POPUP popup = { | |
| 144 | - .summary = N_( "Cant read custom certificate file." ) | |
| 145 | - }; | |
| 146 | - message->code = hSession->ssl.error = ERR_get_error(); | |
| 147 | - message->popup = &popup; | |
| 148 | - | |
| 149 | - trace_ssl(hSession, _( "Can't read \"%s\": %s" ), filename, ERR_lib_error_string(hSession->ssl.error)); | |
| 150 | - } | |
| 151 | - else | |
| 152 | - { | |
| 153 | - | |
| 154 | - if(X509_STORE_add_cert(store, cert) != 1) | |
| 155 | - { | |
| 156 | - static const LIB3270_POPUP popup = { | |
| 157 | - .summary = N_( "Cant load custom certificate file." ) | |
| 158 | - }; | |
| 159 | - message->code = hSession->ssl.error = ERR_get_error(); | |
| 160 | - message->popup = &popup; | |
| 161 | - | |
| 162 | - trace_ssl(hSession, _( "Can't load \"%s\": %s" ), filename, ERR_lib_error_string(hSession->ssl.error)); | |
| 163 | - } | |
| 164 | - | |
| 165 | - X509_free(cert); | |
| 166 | - } | |
| 167 | - | |
| 168 | - fclose(fp); | |
| 169 | - } | |
| 170 | - | |
| 171 | - lib3270_free(filename); | |
| 172 | - | |
| 173 | - } | |
| 174 | - while (FindNextFile(hFind, &ffd) != 0); | |
| 175 | - | |
| 176 | - } | |
| 177 | - | |
| 178 | - ssl_3270_ex_index = SSL_get_ex_new_index(0,NULL,NULL,NULL,NULL); | |
| 179 | - | |
| 180 | -#ifdef SSL_ENABLE_CRL_CHECK | |
| 181 | - | |
| 182 | - // Enable CRL check | |
| 183 | - X509_VERIFY_PARAM *param = X509_VERIFY_PARAM_new(); | |
| 184 | - X509_VERIFY_PARAM_set_flags(param, X509_V_FLAG_CRL_CHECK); | |
| 185 | - X509_STORE_set1_param(store, param); | |
| 186 | - X509_VERIFY_PARAM_free(param); | |
| 187 | - trace_ssl(hSession,"CRL CHECK was enabled\n"); | |
| 188 | - | |
| 189 | -#endif // SSL_ENABLE_CRL_CHECK | |
| 190 | - | |
| 191 | - return 0; | |
| 192 | - | |
| 193 | -} | |
| 194 | - | |
| 195 | -#endif // HAVE_LIBSSL |
src/ssl/windows/private.h
| ... | ... | @@ -1,71 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software G3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral ', conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como private.h e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas de Mendonça) | |
| 27 | - * | |
| 28 | - */ | |
| 29 | - | |
| 30 | -#ifndef LIB3270_WIN32_SSL_PRIVATE_H_INCLUDED | |
| 31 | - | |
| 32 | - #define LIB3270_WIN32_SSL_PRIVATE_H_INCLUDED | |
| 33 | - | |
| 34 | - #include <config.h> | |
| 35 | - | |
| 36 | - #include <winsock2.h> | |
| 37 | - #include <windows.h> | |
| 38 | - | |
| 39 | - #include <openssl/ssl.h> | |
| 40 | - #include <openssl/err.h> | |
| 41 | - #include <openssl/x509_vfy.h> | |
| 42 | - #include <openssl/x509.h> | |
| 43 | - | |
| 44 | - #include <internals.h> | |
| 45 | - #include <trace_dsc.h> | |
| 46 | - #include <errno.h> | |
| 47 | - #include <lib3270.h> | |
| 48 | - #include <lib3270/trace.h> | |
| 49 | - #include <lib3270/log.h> | |
| 50 | - | |
| 51 | - #ifdef HAVE_LIBCURL | |
| 52 | - | |
| 53 | - #include <curl/curl.h> | |
| 54 | - | |
| 55 | - /// @brief Use libcurl to get CRL. | |
| 56 | - LIB3270_INTERNAL X509_CRL * get_crl_using_url(H3270 *hSession, SSL_ERROR_MESSAGE * message, const char *consturl); | |
| 57 | - | |
| 58 | - #endif // HAVE_LIBCURL | |
| 59 | - | |
| 60 | - #ifdef HAVE_LDAP | |
| 61 | - | |
| 62 | - /// @brief Use winldap to get CRL. | |
| 63 | - LIB3270_INTERNAL X509_CRL * get_crl_using_ldap(H3270 *hSession, SSL_ERROR_MESSAGE * message, const char *consturl); | |
| 64 | - | |
| 65 | - #endif // HAVE_LDAP | |
| 66 | - | |
| 67 | - /// @brief Use winhttp to get CRL. | |
| 68 | - LIB3270_INTERNAL X509_CRL * get_crl_using_http(H3270 *hSession, SSL_ERROR_MESSAGE * message, const char *consturl); | |
| 69 | - | |
| 70 | - | |
| 71 | -#endif // !LIB3270_WIN32_SSL_PRIVATE_H_INCLUDED |