mirror of
https://github.com/winscp/winscp.git
synced 2026-10-24 02:28:55 +03:00
Restoring functionality of BUILD_SOURCE_OPENSSL_PREBUILT
Broken probably ever since 0aa999a1
Source commit: 27c0aa7b5614bc9cea4157379303501249b662f5
This commit is contained in:
@@ -334,6 +334,7 @@ static void clean_session(auth_session *sess)
|
||||
sess->sspi_token = NULL;
|
||||
ne_sspi_destroy_context(sess->sspi_context);
|
||||
sess->sspi_context = NULL;
|
||||
Trace(L"clean_session 3");
|
||||
#endif
|
||||
#ifdef HAVE_NTLM
|
||||
if (sess->ntlm_context) {
|
||||
@@ -738,23 +739,29 @@ static int continue_sspi(auth_session *sess, int ntlm, const char *hdr)
|
||||
NE_DEBUG(NE_DBG_HTTPAUTH, "auth: SSPI challenge.\n");
|
||||
|
||||
if (!sess->sspi_context) {
|
||||
Trace(L"continue_sspi 1");
|
||||
status = ne_sspi_create_context(&sess->sspi_context, sess->sspi_host, ntlm);
|
||||
if (status) {
|
||||
Trace(L"continue_sspi 2");
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
Trace(L"continue_sspi 3");
|
||||
status = ne_sspi_authenticate(sess->sspi_context, hdr, &response);
|
||||
if (status) {
|
||||
Trace(L"continue_sspi 4");
|
||||
return status;
|
||||
}
|
||||
|
||||
if (response && *response) {
|
||||
Trace(L"continue_sspi 5");
|
||||
sess->sspi_token = response;
|
||||
|
||||
NE_DEBUG(NE_DBG_HTTPAUTH, "auth: SSPI challenge [%s]\n", sess->sspi_token);
|
||||
}
|
||||
|
||||
Trace(L"continue_sspi /");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1003,6 +1010,7 @@ static int digest_challenge(auth_session *sess, int attempt,
|
||||
NE_DEBUG_WINSCP_CONTEXT(sess->sess);
|
||||
char *p, *h_urp = NULL;
|
||||
|
||||
Trace(L"digest_challenge >");
|
||||
if (parms->alg == NULL) {
|
||||
challenge_error(errmsg, _("unknown algorithm in Digest challenge"));
|
||||
return -1;
|
||||
@@ -1034,6 +1042,7 @@ static int digest_challenge(auth_session *sess, int attempt,
|
||||
return -1;
|
||||
}
|
||||
|
||||
Trace(L"digest_challenge 2");
|
||||
p = ne_strhash(parms->alg->hash, "", NULL);
|
||||
if (p == NULL) {
|
||||
challenge_error(errmsg,
|
||||
@@ -1044,6 +1053,7 @@ static int digest_challenge(auth_session *sess, int attempt,
|
||||
ne_free(p);
|
||||
|
||||
if (!parms->stale) {
|
||||
Trace(L"digest_challenge 3");
|
||||
/* Non-stale challenge: clear session and request credentials. */
|
||||
clean_session(sess);
|
||||
|
||||
@@ -1065,11 +1075,13 @@ static int digest_challenge(auth_session *sess, int attempt,
|
||||
}
|
||||
}
|
||||
else {
|
||||
Trace(L"digest_challenge 4");
|
||||
/* Stale challenge: accept a new nonce or opaque. */
|
||||
if (sess->nonce) ne_free(sess->nonce);
|
||||
if (sess->opaque && parms->opaque) ne_free(sess->opaque);
|
||||
}
|
||||
|
||||
Trace(L"digest_challenge 5");
|
||||
sess->nonce = ne_strdup(parms->nonce);
|
||||
if (parms->opaque) {
|
||||
sess->opaque = ne_strdup(parms->opaque);
|
||||
@@ -1086,6 +1098,7 @@ static int digest_challenge(auth_session *sess, int attempt,
|
||||
}
|
||||
|
||||
if (h_urp) {
|
||||
Trace(L"digest_challenge 6");
|
||||
if (sess->alg->sess) {
|
||||
sess->h_a1 = ne_strhash(parms->alg->hash, h_urp, ":",
|
||||
sess->nonce, ":", sess->cnonce, NULL);
|
||||
@@ -1100,6 +1113,7 @@ static int digest_challenge(auth_session *sess, int attempt,
|
||||
|
||||
NE_DEBUG(NE_DBG_HTTPAUTH, "auth: Accepting digest challenge.\n");
|
||||
|
||||
Trace(L"digest_challenge /");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1143,6 +1157,7 @@ static char *request_digest(auth_session *sess, struct auth_request *req)
|
||||
ne_buffer *ret;
|
||||
unsigned int hash = sess->alg->hash;
|
||||
|
||||
Trace(L"request_digest 1");
|
||||
/* Do not submit credentials if an auth domain is defined and this
|
||||
* request-uri fails outside it. */
|
||||
if (sess->ndomains && !inside_domain(sess, req->uri)) {
|
||||
@@ -2273,15 +2288,35 @@ static void auth_register(ne_session *sess, int isproxy, unsigned protomask,
|
||||
|
||||
if (isproxy)
|
||||
{
|
||||
Trace(L"auth_register 1");
|
||||
ne_fill_proxy_uri(sess, &uri);
|
||||
}
|
||||
else
|
||||
{
|
||||
Trace(L"auth_register 2");
|
||||
ne_fill_server_uri(sess, &uri);
|
||||
}
|
||||
|
||||
ahs->sspi_host = uri.host;
|
||||
|
||||
//!CLEANBEGIN
|
||||
if (ahs->sspi_host != NULL)
|
||||
{
|
||||
wchar_t buf[1024];
|
||||
int i;
|
||||
Trace(L"auth_register 3");
|
||||
for (i = 0; i < strlen(ahs->sspi_host) + 1; i++)
|
||||
{
|
||||
buf[i] = (wchar_t)ahs->sspi_host[i];
|
||||
}
|
||||
Trace(buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
Trace(L"auth_register 4");
|
||||
}
|
||||
//!CLEANEND
|
||||
|
||||
uri.host = NULL;
|
||||
|
||||
ne_uri_free(&uri);
|
||||
|
||||
@@ -95,4 +95,30 @@ NE_PRIVATE char *ne__strhash2hex(const unsigned char *digest, size_t len, unsign
|
||||
#define ne__strzero(s, n) memset(s, 0, n)
|
||||
#endif
|
||||
|
||||
//!CLEANBEGIN
|
||||
|
||||
#ifdef WINSCP
|
||||
|
||||
// #define NEON_TRACE to enable tracing
|
||||
|
||||
#ifdef NEON_TRACE
|
||||
// BOOL is not defined in all files
|
||||
extern int IsTracing;
|
||||
void __fastcall DoTrace(const wchar_t * SourceFile, const wchar_t * Func,
|
||||
int Line, const wchar_t * Message);
|
||||
void __fastcall DoTraceA(const wchar_t * SourceFile, const wchar_t * Func,
|
||||
int Line, const char * Message);
|
||||
#define __UTEXT(S) L##S
|
||||
#define UTEXT(S) __UTEXT(S)
|
||||
#define Trace(MESSAGE) if (IsTracing) DoTrace(UTEXT(__FILE__), UTEXT(__FUNC__), __LINE__, MESSAGE)
|
||||
#define TraceA(MESSAGE) if (IsTracing) DoTraceA(UTEXT(__FILE__), UTEXT(__FUNC__), __LINE__, MESSAGE)
|
||||
#else
|
||||
#define Trace(MESSAGE)
|
||||
#define TraceA(MESSAGE)
|
||||
#endif
|
||||
|
||||
#endif /* WINSCP */
|
||||
|
||||
//!CLEANEND
|
||||
|
||||
#endif /* NE_INTERNAL_H */
|
||||
|
||||
@@ -441,11 +441,15 @@ int ne_unlock(ne_session *sess, const struct ne_lock *lock)
|
||||
|
||||
static int parse_depth(const char *depth)
|
||||
{
|
||||
Trace(L"parse_depth 1");
|
||||
if (ne_strcasecmp(depth, "infinity") == 0) {
|
||||
Trace(L"parse_depth 2");
|
||||
return NE_DEPTH_INFINITE;
|
||||
} else if (isdigit(depth[0])) {
|
||||
Trace(L"parse_depth 3");
|
||||
return atoi(depth);
|
||||
} else {
|
||||
Trace(L"parse_depth 4");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -519,8 +523,10 @@ end_element_common(struct ne_lock *l, int state, const char *cdata)
|
||||
ne_free(depth);
|
||||
}
|
||||
if (l->depth == -1) {
|
||||
Trace(L"end_element_common 1");
|
||||
return -1;
|
||||
}
|
||||
Trace(L"end_element_common 2");
|
||||
break;
|
||||
case ELM_timeout:
|
||||
NE_DEBUG(NE_DBG_LOCKS, "Got timeout: %s\n", cdata);
|
||||
@@ -548,6 +554,7 @@ end_element_common(struct ne_lock *l, int state, const char *cdata)
|
||||
}
|
||||
break;
|
||||
}
|
||||
Trace(L"end_element_common /");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -186,6 +186,7 @@ ne_session *ne_session_create(const char *scheme,
|
||||
{
|
||||
ne_session *sess = ne_calloc(sizeof *sess);
|
||||
|
||||
Trace(L"ne_session_create >");
|
||||
NE_DEBUG(NE_DBG_HTTP, "HTTP session to %s://%s:%d begins.\n",
|
||||
scheme, hostname, port);
|
||||
|
||||
|
||||
@@ -677,12 +677,15 @@ static int error_ossl(ne_socket *sock, int sret)
|
||||
int errnum = SSL_get_error(sock->ssl, sret);
|
||||
unsigned long err;
|
||||
|
||||
Trace(L"error_ossl >");
|
||||
if (errnum == SSL_ERROR_ZERO_RETURN) {
|
||||
Trace(L"error_ossl 1");
|
||||
set_error(sock, _("Connection closed"));
|
||||
NE_DEBUG(NE_DBG_SSL, "ssl: Got TLS closure.\n");
|
||||
return NE_SOCK_CLOSED;
|
||||
}
|
||||
else if (errnum == SSL_ERROR_WANT_READ) {
|
||||
Trace(L"error_ossl 2");
|
||||
set_error(sock, _("Retry operation"));
|
||||
return NE_SOCK_RETRY;
|
||||
}
|
||||
@@ -712,10 +715,12 @@ static int error_ossl(ne_socket *sock, int sret)
|
||||
/* Empty error stack, presume this is a system call error: */
|
||||
if (sret == 0) {
|
||||
/* EOF without close_notify, possible truncation */
|
||||
Trace(L"error_ossl 3");
|
||||
set_error(sock, _("Secure connection truncated"));
|
||||
return NE_SOCK_TRUNC;
|
||||
} else {
|
||||
/* Other socket error. */
|
||||
Trace(L"error_ossl 4");
|
||||
errnum = ne_errno;
|
||||
set_strerror(sock, errnum);
|
||||
return MAP_ERR(errnum);
|
||||
@@ -729,6 +734,8 @@ static int error_ossl(ne_socket *sock, int sret)
|
||||
ne_snprintf(sock->error, sizeof sock->error,
|
||||
_("SSL error code %d/%d/%lu"), sret, errnum, err);
|
||||
}
|
||||
Trace(L"error_ossl 5");
|
||||
Trace(sock->error);
|
||||
|
||||
/* make sure the error stack is now empty. */
|
||||
ERR_clear_error();
|
||||
@@ -758,6 +765,7 @@ static ssize_t read_ossl(ne_socket *sock, char *buffer, size_t len)
|
||||
static ssize_t write_ossl(ne_socket *sock, const char *data, size_t len)
|
||||
{
|
||||
int ret, ilen = CAST2INT(len);
|
||||
Trace(L"write_ossl >");
|
||||
ret = SSL_write(sock->ssl, data, ilen);
|
||||
/* ssl.h says SSL_MODE_ENABLE_PARTIAL_WRITE must be enabled to
|
||||
* have SSL_write return < length... so, SSL_write should never
|
||||
@@ -1191,6 +1199,8 @@ ne_inet_addr *ne_iaddr_parse(const char *addr, ne_iaddr_type type)
|
||||
char dst[sizeof(struct in6_addr)];
|
||||
int af = type == ne_iaddr_ipv6 ? AF_INET6 : AF_INET;
|
||||
|
||||
Trace(L"ne_iaddr_parse 1");
|
||||
Trace(addr);
|
||||
if (inet_pton(af, addr, dst) != 1) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -1200,15 +1210,19 @@ ne_inet_addr *ne_iaddr_parse(const char *addr, ne_iaddr_type type)
|
||||
/* For Windows, which lacks inet_pton(). */
|
||||
struct addrinfo *ai, *rv, hints;
|
||||
|
||||
Trace(L"ne_iaddr_parse 2");
|
||||
TraceA(addr);
|
||||
memset(&hints, 0, sizeof hints);
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_flags = AI_NUMERICHOST;
|
||||
hints.ai_family = type == ne_iaddr_ipv6 ? AF_INET6 : AF_INET;
|
||||
|
||||
if (getaddrinfo(addr, NULL, &hints, &ai)) {
|
||||
Trace(L"ne_iaddr_parse /1");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Trace(L"ne_iaddr_parse 3");
|
||||
/* Copy the returned addrinfo, since it needs to be ne_free()-able
|
||||
* later; must only call freeaddrinfo() on ai. */
|
||||
rv = ne_calloc(sizeof *rv);
|
||||
@@ -1216,6 +1230,20 @@ ne_inet_addr *ne_iaddr_parse(const char *addr, ne_iaddr_type type)
|
||||
rv->ai_next = NULL;
|
||||
rv->ai_canonname = NULL;
|
||||
rv->ai_addr = ne_calloc(ai->ai_addrlen);
|
||||
//!CLEANBEGIN
|
||||
#ifdef NEON_TRACE
|
||||
{
|
||||
char * buf = ne_calloc(ai->ai_addrlen * 4 + 1);
|
||||
int i;
|
||||
for (i = 0; i < ai->ai_addrlen; i++)
|
||||
{
|
||||
sprintf(buf + strlen(buf), "%d.", (int)(((unsigned char *)ai->ai_addr)[i]));
|
||||
}
|
||||
TraceA(buf);
|
||||
ne_free(buf);
|
||||
}
|
||||
#endif
|
||||
//!CLEANEND
|
||||
memcpy(rv->ai_addr, ai->ai_addr, ai->ai_addrlen);
|
||||
freeaddrinfo(ai);
|
||||
|
||||
@@ -1223,6 +1251,8 @@ ne_inet_addr *ne_iaddr_parse(const char *addr, ne_iaddr_type type)
|
||||
#else /* !USE_GETADDRINFO */
|
||||
struct in_addr a;
|
||||
|
||||
Trace(L"ne_iaddr_parse 4");
|
||||
Trace(addr);
|
||||
if (type == ne_iaddr_ipv6) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,12 @@
|
||||
#include "ne_socket.h"
|
||||
#include "ne_sspi.h"
|
||||
|
||||
//!CLEANBEGIN
|
||||
#ifdef WINSCP
|
||||
#include "ne_internal.h"
|
||||
#endif
|
||||
//!CLEANEND
|
||||
|
||||
#ifdef HAVE_SSPI
|
||||
|
||||
#define SEC_SUCCESS(Status) ((Status) >= 0)
|
||||
@@ -367,6 +373,7 @@ int ne_sspi_create_context(void **context, char *serverName, int ntlm)
|
||||
SSPIContext *sspiContext;
|
||||
char *canonicalName;
|
||||
|
||||
Trace(L"ne_sspi_create_context 1");
|
||||
if (initialized <= 0) {
|
||||
return -1;
|
||||
}
|
||||
@@ -375,13 +382,16 @@ int ne_sspi_create_context(void **context, char *serverName, int ntlm)
|
||||
sspiContext->continueNeeded = 0;
|
||||
|
||||
if (ntlm) {
|
||||
Trace(L"ne_sspi_create_context 2");
|
||||
sspiContext->mechanism = "NTLM";
|
||||
sspiContext->serverName = ne_strdup(serverName);
|
||||
sspiContext->maxTokenSize = ntlmMaxTokenSize;
|
||||
} else {
|
||||
Trace(L"ne_sspi_create_context 3");
|
||||
sspiContext->mechanism = "Negotiate";
|
||||
/* Canonicalize to conform to GSSAPI behavior */
|
||||
canonicalName = canonical_hostname(serverName);
|
||||
Trace(L"ne_sspi_create_context 4");
|
||||
sspiContext->serverName = ne_concat("HTTP/", canonicalName, NULL);
|
||||
ne_free(canonicalName);
|
||||
NE_DEBUG(NE_DBG_HTTPAUTH, "sspi: Created context with SPN '%s'\n",
|
||||
@@ -392,6 +402,7 @@ int ne_sspi_create_context(void **context, char *serverName, int ntlm)
|
||||
sspiContext->ntlm = ntlm;
|
||||
sspiContext->authfinished = 0;
|
||||
*context = sspiContext;
|
||||
Trace(L"ne_sspi_create_context /");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,14 +17,18 @@ int X509_STORE_set_default_paths_ex(X509_STORE *ctx, OSSL_LIB_CTX *libctx,
|
||||
{
|
||||
X509_LOOKUP *lookup;
|
||||
|
||||
Trace(L"X509_STORE_set_default_paths 1");
|
||||
lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_file());
|
||||
if (lookup == NULL)
|
||||
return 0;
|
||||
Trace(L"X509_STORE_set_default_paths 2");
|
||||
X509_LOOKUP_load_file_ex(lookup, NULL, X509_FILETYPE_DEFAULT, libctx, propq);
|
||||
|
||||
Trace(L"X509_STORE_set_default_paths 3");
|
||||
lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_hash_dir());
|
||||
if (lookup == NULL)
|
||||
return 0;
|
||||
Trace(L"X509_STORE_set_default_paths 4");
|
||||
X509_LOOKUP_add_dir(lookup, NULL, X509_FILETYPE_DEFAULT);
|
||||
|
||||
lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_store());
|
||||
@@ -35,6 +39,7 @@ int X509_STORE_set_default_paths_ex(X509_STORE *ctx, OSSL_LIB_CTX *libctx,
|
||||
/* clear any errors */
|
||||
ERR_clear_error();
|
||||
|
||||
Trace(L"X509_STORE_set_default_paths /");
|
||||
return 1;
|
||||
}
|
||||
int X509_STORE_set_default_paths(X509_STORE *ctx)
|
||||
|
||||
@@ -161,4 +161,19 @@ char *ossl_buf2hexstr_sep(const unsigned char *buf, long buflen, char sep);
|
||||
unsigned char *ossl_hexstr2buf_sep(const char *str, long *buflen,
|
||||
const char sep);
|
||||
|
||||
//!CLEANBEGIN
|
||||
|
||||
#ifdef _DEBUG
|
||||
extern int IsTracing;
|
||||
void __fastcall DoTrace(const wchar_t * SourceFile, const wchar_t * Func,
|
||||
int Line, const wchar_t * Message);
|
||||
#define __UTEXT(S) L##S
|
||||
#define UTEXT(S) __UTEXT(S)
|
||||
#define Trace(MESSAGE) if (IsTracing) DoTrace(UTEXT(__FILE__), UTEXT(__FUNC__), __LINE__, MESSAGE)
|
||||
#else
|
||||
#define Trace(MESSAGE)
|
||||
#endif
|
||||
|
||||
//!CLEANEND
|
||||
|
||||
#endif
|
||||
|
||||
@@ -842,14 +842,17 @@ void SSL_SESSION_free(SSL_SESSION *ss)
|
||||
|
||||
if (ss == NULL)
|
||||
return;
|
||||
Trace(L"SSL_SESSION_free 1");
|
||||
CRYPTO_DOWN_REF(&ss->references, &i);
|
||||
REF_PRINT_COUNT("SSL_SESSION", ss);
|
||||
if (i > 0)
|
||||
return;
|
||||
REF_ASSERT_ISNT(i < 0);
|
||||
|
||||
Trace(L"SSL_SESSION_free 2");
|
||||
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data);
|
||||
|
||||
Trace(L"SSL_SESSION_free 3");
|
||||
OPENSSL_cleanse(ss->master_key, sizeof(ss->master_key));
|
||||
OPENSSL_cleanse(ss->session_id, sizeof(ss->session_id));
|
||||
X509_free(ss->peer);
|
||||
@@ -861,6 +864,7 @@ void SSL_SESSION_free(SSL_SESSION *ss)
|
||||
OPENSSL_free(ss->psk_identity_hint);
|
||||
OPENSSL_free(ss->psk_identity);
|
||||
#endif
|
||||
Trace(L"SSL_SESSION_free 4");
|
||||
#ifndef OPENSSL_NO_SRP
|
||||
OPENSSL_free(ss->srp_username);
|
||||
#endif
|
||||
@@ -868,6 +872,7 @@ void SSL_SESSION_free(SSL_SESSION *ss)
|
||||
OPENSSL_free(ss->ticket_appdata);
|
||||
CRYPTO_FREE_REF(&ss->references);
|
||||
OPENSSL_clear_free(ss, sizeof(*ss));
|
||||
Trace(L"SSL_SESSION_free /");
|
||||
}
|
||||
|
||||
int SSL_SESSION_up_ref(SSL_SESSION *ss)
|
||||
|
||||
Reference in New Issue
Block a user