Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FreeTDS with Openssl 1.1.1m fails to connect #458

Closed
5u623l20 opened this issue Feb 26, 2022 · 9 comments
Closed

FreeTDS with Openssl 1.1.1m fails to connect #458

5u623l20 opened this issue Feb 26, 2022 · 9 comments

Comments

@5u623l20
Copy link

5u623l20 commented Feb 26, 2022

I am the maintainer of the freetds port in FreeBSD and reporting a failure of connection on behalf of other users:

Command:
setenv TDSDUMP /tmp/freetds.log
tsql -S host -U username -P password

tail /tmp/freetds.log
tls.c:130:in tds_pull_func_login
tls.c:130:in tds_pull_func_login
tls.c:130:in tds_pull_func_login
tls.c:1065:handshake succeeded!!
login.c:1053:quietly sending TDS 7+ login packet
token.c:418:tds_process_login_tokens()

This is the case when we are using OpenSSL 1.1.1m. But in case we are using OpenSSL 1.1.1k or GNUTLS it works without any problems.

Here is the buildlog:
https://pdr.bofh.network/data/latest-per-pkg/freetds/1.3.9%2C1/130-default.log

And in case it's difficult to find I can find some warnings although it doesn't look like a showstopper to me:

random.c:59:6: warning: 'RAND_pseudo_bytes' is deprecated [-Wdeprecated-declarations]
        if (RAND_pseudo_bytes(out, len) >= 0)
            ^
/usr/include/openssl/rand.h:44:1: note: 'RAND_pseudo_bytes' has been explicitly marked deprecated here
DEPRECATEDIN_1_1_0(int RAND_pseudo_bytes(unsigned char *buf, int num))
^
/usr/include/openssl/opensslconf.h:153:34: note: expanded from macro 'DEPRECATEDIN_1_1_0'
# define DEPRECATEDIN_1_1_0(f)   DECLARE_DEPRECATED(f)
                                 ^
/usr/include/openssl/opensslconf.h:116:55: note: expanded from macro 'DECLARE_DEPRECATED'
#   define DECLARE_DEPRECATED(f)    f __attribute__ ((deprecated));
                                                      ^
1 warning generated.
@fziglio
Copy link

fziglio commented Mar 5, 2022

The warning should be removed surely but it's not the issue. I cannot see why a minor update could lead to this. Instead what I would check is if they removed some cipher with the update. Recently in many cases the OpenSSL requirements for cipher are not satisfied by MS.

@CyberCr33p
Copy link

On my system "OpenSSL 1.1.1k-freebsd 24 Aug 2021" and "OpenSSL 1.1.1o-freebsd 3 May 2022" have same ciphers.

@CyberCr33p
Copy link

This issue is not FreeBSD related as it exist also with Linux:

  1. FreeTDS 1.3.10 + OpenSSL 1.1.1k = SUCCESS
  2. FreeTDS 1.3.10 + OpenSSL 1.1.1l = FAIL

So the first version that doesn't work is 1.1.1l.

@fziglio
Copy link

fziglio commented May 30, 2022

Can you try this?

diff --git a/src/tds/tls.c b/src/tds/tls.c
index 64c6bba2..bc63e2cf 100644
--- a/src/tds/tls.c
+++ b/src/tds/tls.c
@@ -826,18 +826,25 @@ tds_check_wildcard_test(void)
 static int
 check_name_match(ASN1_STRING *name, const char *hostname)
 {
-       char *name_utf8 = NULL;
+       char *name_utf8 = NULL, *tmp_name;
        int ret, name_len;
 
        name_len = ASN1_STRING_to_UTF8((unsigned char **) &name_utf8, name);
        if (name_len < 0)
                return 0;
 
+       tmp_name = tds_strndup(name_utf8, name_len);
+       OPENSSL_free(name_utf8);
+       if (!tmp_name)
+               return 0;
+
+       name_utf8 = tmp_name;
+
        tdsdump_log(TDS_DBG_INFO1, "Got name %s\n", name_utf8);
        ret = 0;
        if (strlen(name_utf8) == name_len && check_wildcard(name_utf8, hostname))
                ret = 1;
-       OPENSSL_free(name_utf8);
+       free(name_utf8);
        return ret;
 }
 

@CyberCr33p
Copy link

Yes it works with 1.1.1l so I guess it will work with newer versions too. Thank you. I will ask @5u623l20 to create a patch for FreeBSD port until you release a new version with this patch.

@5u623l20
Copy link
Author

Will take care of it tomorrow.

@CyberCr33p
Copy link

Thank you both.

vishwin pushed a commit to vishwin/freebsd-ports that referenced this issue May 31, 2022
- FreeTDS fails to connect with MsSQL after the latest updates of
  OpenSSL specially after the release of 13.1 SNAPSHOTS including
  13.1-RELEASE and more specifically when openssl turned into 1.1.1l
  See the following for more details:
  FreeTDS/freetds#458
- After the upgrade to version 1.3.9 FreeTDS fails to upgrade when using
  ports tree. [1]

PR:		261967 263641 [1]
Reported by:	jsc@ntu.edu.tw eugen [1]
@fziglio
Copy link

fziglio commented May 31, 2022

Fixed in 1.3.11

@avkarenow
Copy link

Unfortunately, the problem with connection still appears with OpenSSL 1.1.1t-freebsd on FreeBSD 13.2. I temporarily switched to GnuTLS which can properly handle connections.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants