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

Migrate Wocky to GIO-TLS #5

Merged
merged 12 commits into from
May 11, 2020
Merged

Migrate Wocky to GIO-TLS #5

merged 12 commits into from
May 11, 2020

Conversation

rufferson
Copy link
Collaborator

This contains long past due patch made by @danwinship in 2010 as https://bugs.freedesktop.org/show_bug.cgi?id=31447.

After I restricted my jabber server to TLS1.2+ telepathy stopped connecting to it, it was unable to read content via TLS1.3 stream (eg. it sent stream start, server responded with stream start, but wocky doesn't see it). The best I could do was to revive this old patch and do some cleanups to make it work. And it does work actually now.

Testing is a mess though, I've updated resolver to match latest glib spec but TLS tests are failing more often than not.

@rufferson rufferson changed the title Migrate Wocky to GIO Migrate Wocky to GIO-TLS Apr 21, 2020
@Kaffeine
Copy link
Member

@noonien-d would you mind taking a look? I have no idea what is going on, I can only press "Merge" and (optionally) tag a release.

Copy link
Member

@Kaffeine Kaffeine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK to me but I don't know this project and would like someone else to take a look.

wocky/wocky-connector.c Outdated Show resolved Hide resolved
wocky/wocky-jabber-auth.c Outdated Show resolved Hide resolved
wocky/wocky-sasl-digest-md5.c Show resolved Hide resolved
wocky/wocky-jingle-session.c Outdated Show resolved Hide resolved
wocky/wocky-tls-handler.c Outdated Show resolved Hide resolved
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>

/* DANWFIXME: allow configuring compression options */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Part of original patch :)

Copy link
Collaborator Author

@rufferson rufferson Apr 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But ok, perhaps we can replace that with more valuable comment like - use GIO_USE_TLS and G_TLS_GNUTLS_PRIORITY to set the SSL options.
On the other hand there are more places like that across the original patch, so I'd rather leave it as is for future cleanup, at the moment main question is whether we go full GIO-TLS or not. I'm reading the patches for further cleanup - like removing of direct openssl backend (it's available via GIO) so those markers are the places of potential future attention.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will test gio-tls for sailfish the next days.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had just left comments wherever the patched version didn't support everything the original did. It is entirely possible that nothing uses the functionality that is no longer there.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wocky compiles when dropping the last commit, but gabble-0.18 doesn't compile with wocky-master. Sailfish needs gabble-0.18 due to an old telepathy-glib :-/

So I guess I'll stick to openssl for my Sailfish build, that shouldn't be a hindrance for wocky-master development ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let me post my current testing branch
https://github.com/rufferson/telepathy-gabble/tree/test-merged
which includes your and mine PRs as well as other minor cleanup patches I've cherry-picked (including GIO-TLS one)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, when including Adjust callbacks to Wocky GIO-TLS changes gabble-18.4 builds with gio-tls on Sailfish SDK. I will take a deeper look these days.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to apply the callback patch to gabble master, don't we?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when we update submodule tip, yes

}

void
wocky_tls_session_add_crl (WockyTLSSession *session, const gchar *crl_path)
{
int n = 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This (now empty function) seems to be used in wocky-connector-test only, otherwise it could be an security issue. Might be a reason for the test failing, though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, that was also called out in original patch here https://bugs.freedesktop.org/show_bug.cgi?id=31447#c15

@noonien-d
Copy link

So besides the todos/comments and failing tests it seems okay for me. It would be nice of you keep on working to finish this code.

There are also some tab/whitespace errors introduced in wocky-jingle-session.c, wocky-jabber-auth.c and wocky-connector.c, found by make check. They should get fixed before merging.

@rufferson
Copy link
Collaborator Author

rufferson commented Apr 29, 2020

interesting results, I'm still working on failing tests and so far following observations:

  • SASL is heavily outdated in tests - requires certain tweaking to even start working somehow.
  • GnuTLS backend doesn't work with tests entirely - fails with
    Error: wocky-connector-error.7: TLS handshake error: Peer failed to perform TLS handshake: The TLS connection was non-properly terminated.
  • Switching to OpenSSL backend starts progressing the tests and by uplifting SASL tests here and there I've managed to hit already ok 51 /connector/tls+auth/insecure/tlsplain/tls/digest

Upd: Actually with openssl almost all tests succeed now, with exception of several remaining SASL failures and several error mismatch (woky/gio tls error mapping). With gnutls server implementation for some reason cannot support tls1.2

rufferson added 3 commits May 9, 2020 15:40
 * Localize variables in wocky-connector.c and wocky-jabber-auth.c
 * Add fallthrough marker to wocky-jingle-session.c
 * remove double const in wocky-data-form.c
 * fix pointer dereference in wocky-sasl-digest-md5.c
danwinship and others added 8 commits May 9, 2020 15:51
This is how gio TLS does it, among other reasons because it lets you
use the SNI extension to tell the server which certificate it should
present.

https://bugs.freedesktop.org/show_bug.cgi?id=31447
to match gio TLS, and because there's not much use in the separation
anyway

https://bugs.freedesktop.org/show_bug.cgi?id=31447
GTlsConnection can only wrap pollable input/output streams, so
implement that here to make some of the test cases work.

https://bugs.freedesktop.org/show_bug.cgi?id=31447
A few minor things, marked DANWFIXME, are unimplemented

https://bugs.freedesktop.org/show_bug.cgi?id=31447
@rufferson
Copy link
Collaborator Author

Ok se eventually gnutls server implementation does not support properly TLSv1.3 and that's what GIO forces it to use on client side.

$ gnutls-serv --x509certfile certs/tls-cert.pem --x509keyfile certs/tls-key.pem 
HTTP Server listening on IPv4 0.0.0.0 port 5556...done
HTTP Server listening on IPv6 :: port 5556...done

* Accepted connection from IPv4 127.0.0.1 port 38550 on Sun May 10 10:10:14 202
Error in handshake: No supported cipher suites have been found.

while it does work with openssl:

$ openssl s_server -port 5556 -cert certs/tls-cert.pem -key certs/tls-key.pem 
Using default temp DH parameters
ACCEPT
-----BEGIN SSL SESSION PARAMETERS-----
MH0CAQECAgMEBAITAgQgt6XQPfdj282lkBVw1AyZOYLYdQDGFw0NLXNBR6mxvDwE
MAYZU/01Y9Dc3tJL9KsxlgrEy3DHrvjuA2JjGgP4jUGL4Z0h3H4JNY9nCHjvRdjZ
IaEGAgRet7fZogQCAhwgpAYEBAEAAACuBgIETwzQ1w==
-----END SSL SESSION PARAMETERS-----
Shared ciphers:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256
Signature Algorithms: ECDSA+SHA256:ECDSA+SHA384:ECDSA+SHA512:Ed25519:Ed448:RSA-PSS+SHA256:RSA-PSS+SHA384:RSA-PSS+SHA512:RSA-PSS+SHA256:RSA-PSS+SHA384:RSA-PSS+SHA512:RSA+SHA256:RSA+SHA384:RSA+SHA512
Shared Signature Algorithms: ECDSA+SHA256:ECDSA+SHA384:ECDSA+SHA512:Ed25519:Ed448:RSA-PSS+SHA256:RSA-PSS+SHA384:RSA-PSS+SHA512:RSA-PSS+SHA256:RSA-PSS+SHA384:RSA-PSS+SHA512:RSA+SHA256:RSA+SHA384:RSA+SHA512
Supported Elliptic Groups: X25519:P-256:X448:P-521:P-384
Shared Elliptic groups: X25519:P-256:X448:P-521:P-384
CIPHER is TLS_AES_256_GCM_SHA384
Secure Renegotiation IS supported

Interestingly the chosen cipher (TLS_AES_256_GCM_SHA384) was also advertised by gnutls-serv in debug as available but it was unable to select it.

|<2>| checking 13.02 (GNUTLS_AES_256_GCM_SHA384) for compatibility
|<2>| checking 13.03 (GNUTLS_CHACHA20_POLY1305_SHA256) for compatibility
|<2>| checking 13.01 (GNUTLS_AES_128_GCM_SHA256) for compatibility
|<3>| ASSERT: ciphersuites.c[_gnutls_figure_common_ciphersuite]:1591
|<3>| ASSERT: handshake.c[_gnutls_server_select_suite]:1093
|<3>| ASSERT: handshake.c[read_client_hello]:807
|<3>| ASSERT: handshake.c[_gnutls_recv_handshake]:1577
|<3>| ASSERT: handshake.c[handshake_server]:3358
|<13>| BUF[HSK]: Emptied buffer
Error in handshake: No supported cipher suites have been found.

It does work with TLS1.2 though - and indeed if I disable TLS1.3 gnutls backend behaves identically to openssl (sasl fails ob both, still trying to figure why):


$   G_TLS_GNUTLS_PRIORITY='NORMAL:%COMPAT:-VERS-TLS1.3' gtester --verbose ./wocky-connector-test 

** (gtester:457797): WARNING **: 10:28:46.569: Deprecated: Since GLib 2.62, gtester and gtester-report are deprecated. Port to TAP.
TEST: ./wocky-connector-test... (pid=457798)
  /connector/see-other-host:                                           OK
  /connector/basic/internals:                                          OK
  /connector/basic/facebook-chat-srv-workaround:                       OK
  /connector/basic/noserv/nohost/noport:                               OK
  /connector/basic/noserv/nohost/port:                                 OK
  /connector/basic/noserv/nohost/duffport:                             OK
  /connector/basic/noserv/host/noport:                                 OK
  /connector/basic/noserv/host/port:                                   OK
  /connector/basic/noserv/host/duffport:                               OK
  /connector/basic/noserv/duffhost/noport:                             OK
  /connector/basic/noserv/duffhost/port:                               OK
  /connector/basic/serv/nohost/noport:                                 OK
  /connector/basic/serv/nohost/port:                                   OK
  /connector/basic/serv/nohost/duffport:                               OK
  /connector/basic/serv/host/noport:                                   OK
  /connector/basic/serv/host/port:                                     OK
  /connector/basic/serv/host/duffport:                                 OK
  /connector/basic/serv/duffhost/noport:                               OK
  /connector/basic/serv/duffhost/port:                                 OK
  /connector/basic/duffserv/nohost/noport:                             OK
  /connector/basic/duffserv/nohost/port:                               OK
  /connector/basic/duffserv/nohost/duffport:                           OK
  /connector/basic/duffserv/host/noport:                               OK
  /connector/basic/duffserv/host/port:                                 OK
  /connector/basic/duffserv/host/duffport:                             OK
  /connector/basic/duffserv/duffhost/noport:                           OK
  /connector/basic/duffserv/duffhost/port:                             OK
  /connector/auth/secure/no-tlsplain/notls/nodigest:                   OK
  /connector/auth/secure/no-tlsplain/notls/digest:                     OK
  /connector/auth/secure/no-tlsplain/notls/any:                        OK
  /connector/auth/secure/no-tlsplain/tls/plain:                        OK
  /connector/auth/secure/no-tlsplain/tls/digest:                       OK
  /connector/auth/secure/tlsplain/notls/any:                           OK
  /connector/auth/secure/tlsplain/tls/plain:                           OK
  /connector/auth/secure/tlsplain/tls/digest:                          OK
  /connector/auth/insecure/no-tlsplain/notls/nodigest:                 OK
  /connector/auth/insecure/no-tlsplain/notls/digest:                   OK
  /connector/auth/insecure/no-tlsplain/notls/any:                      OK
  /connector/auth/insecure/no-tlsplain/tls/plain:                      OK
  /connector/auth/insecure/no-tlsplain/tls/digest:                     OK
  /connector/auth/insecure/tlsplain/notls/any:                         OK
  /connector/auth/insecure/tlsplain/tls/plain:                         OK
  /connector/auth/insecure/tlsplain/tls/digest:                        OK
  /connector/tls+auth/secure/no-tlsplain/tls/plain:                    OK
  /connector/tls+auth/secure/no-tlsplain/tls/digest:                   OK
  /connector/tls+auth/secure/tlsplain/tls/plain:                       OK
  /connector/tls+auth/secure/tlsplain/tls/digest:                      OK
  /connector/tls+auth/insecure/no-tlsplain/tls/plain:                  OK
  /connector/tls+auth/insecure/no-tlsplain/tls/digest:                 OK
  /connector/tls+auth/insecure/tlsplain/tls/plain:                     OK
  /connector/tls+auth/insecure/tlsplain/tls/digest:                    OK
  /connector/problem/sasl/bad-pass:                                    sasl error (-5): SASL(-5): bad protocol / cancel: StoredKey mismatch
**
ERROR:wocky-test-sasl-auth-server.c:504:check_sasl_return: code should not be reached
FAIL
GTester: last random seed: R02Sced9e5af0c22c93a892d5e4d38da9641
Beendet
$ GIO_USE_TLS=openssl gtester --verbose ./wocky-connector-test 

** (gtester:457833): WARNING **: 10:29:02.774: Deprecated: Since GLib 2.62, gtester and gtester-report are deprecated. Port to TAP.
TEST: ./wocky-connector-test... (pid=457834)
  /connector/see-other-host:                                           OK
  /connector/basic/internals:                                          OK
  /connector/basic/facebook-chat-srv-workaround:                       OK
  /connector/basic/noserv/nohost/noport:                               OK
  /connector/basic/noserv/nohost/port:                                 OK
  /connector/basic/noserv/nohost/duffport:                             OK
  /connector/basic/noserv/host/noport:                                 OK
  /connector/basic/noserv/host/port:                                   OK
  /connector/basic/noserv/host/duffport:                               OK
  /connector/basic/noserv/duffhost/noport:                             OK
  /connector/basic/noserv/duffhost/port:                               OK
  /connector/basic/serv/nohost/noport:                                 OK
  /connector/basic/serv/nohost/port:                                   OK
  /connector/basic/serv/nohost/duffport:                               OK
  /connector/basic/serv/host/noport:                                   OK
  /connector/basic/serv/host/port:                                     OK
  /connector/basic/serv/host/duffport:                                 OK
  /connector/basic/serv/duffhost/noport:                               OK
  /connector/basic/serv/duffhost/port:                                 OK
  /connector/basic/duffserv/nohost/noport:                             OK
  /connector/basic/duffserv/nohost/port:                               OK
  /connector/basic/duffserv/nohost/duffport:                           OK
  /connector/basic/duffserv/host/noport:                               OK
  /connector/basic/duffserv/host/port:                                 OK
  /connector/basic/duffserv/host/duffport:                             OK
  /connector/basic/duffserv/duffhost/noport:                           OK
  /connector/basic/duffserv/duffhost/port:                             OK
  /connector/auth/secure/no-tlsplain/notls/nodigest:                   OK
  /connector/auth/secure/no-tlsplain/notls/digest:                     OK
  /connector/auth/secure/no-tlsplain/notls/any:                        OK
  /connector/auth/secure/no-tlsplain/tls/plain:                        OK
  /connector/auth/secure/no-tlsplain/tls/digest:                       OK
  /connector/auth/secure/tlsplain/notls/any:                           OK
  /connector/auth/secure/tlsplain/tls/plain:                           OK
  /connector/auth/secure/tlsplain/tls/digest:                          OK
  /connector/auth/insecure/no-tlsplain/notls/nodigest:                 OK
  /connector/auth/insecure/no-tlsplain/notls/digest:                   OK
  /connector/auth/insecure/no-tlsplain/notls/any:                      OK
  /connector/auth/insecure/no-tlsplain/tls/plain:                      OK
  /connector/auth/insecure/no-tlsplain/tls/digest:                     OK
  /connector/auth/insecure/tlsplain/notls/any:                         OK
  /connector/auth/insecure/tlsplain/tls/plain:                         OK
  /connector/auth/insecure/tlsplain/tls/digest:                        OK
  /connector/tls+auth/secure/no-tlsplain/tls/plain:                    OK
  /connector/tls+auth/secure/no-tlsplain/tls/digest:                   OK
  /connector/tls+auth/secure/tlsplain/tls/plain:                       OK
  /connector/tls+auth/secure/tlsplain/tls/digest:                      OK
  /connector/tls+auth/insecure/no-tlsplain/tls/plain:                  OK
  /connector/tls+auth/insecure/no-tlsplain/tls/digest:                 OK
  /connector/tls+auth/insecure/tlsplain/tls/plain:                     OK
  /connector/tls+auth/insecure/tlsplain/tls/digest:                    OK
  /connector/problem/sasl/bad-pass:                                    sasl error (-5): SASL(-5): bad protocol / cancel: StoredKey mismatch
**
ERROR:wocky-test-sasl-auth-server.c:504:check_sasl_return: code should not be reached
FAIL
GTester: last random seed: R02Sc3da0fbcefe6cb871d85ebb2f4b6b767
Beendet

@rufferson
Copy link
Collaborator Author

and here's why sasl test fails. Apart of this only CRL fails - for known reason (no support for custom CRL in GIO)

 * Update test certificate to use SHA2 to avoid INSECURE error
 * Add certificate refresh dependency to Makefile
 * Add SASL SCRAM worng password test workaround
 * Suppress CRL verification tests as not supported by GIO-TLS
 * Fix summarise-tests.py to handle deprecations and new syntax
@rufferson
Copy link
Collaborator Author

PASS: wocky-test-sasl-auth
PASS: wocky-bare-contact-test: 7/7 tests passed
PASS: wocky-caps-hash-test: 11/11 tests passed
PASS: wocky-connector-test: 225/225 tests passed
PASS: wocky-contact-factory-test: 5/5 tests passed
PASS: wocky-data-form-test: 7/7 tests passed
PASS: wocky-jid-validation-test: 14/14 tests passed
PASS: wocky-loopback-test: 1/1 tests passed
PASS: wocky-node-tree-test: 3/3 tests passed
PASS: wocky-pep-service-test: 4/4 tests passed
PASS: wocky-ping-test: 2/2 tests passed
PASS: wocky-porter-test: 47/47 tests passed
PASS: wocky-pubsub-node-test: 12/12 tests passed
PASS: wocky-pubsub-service-test: 13/13 tests passed
PASS: wocky-resource-contact-test: 4/4 tests passed
PASS: wocky-roster-test: 21/21 tests passed
PASS: wocky-sasl-utils-test: 7/7 tests passed
PASS: wocky-scram-sha1-test: 2/2 tests passed
PASS: wocky-session-test: 3/3 tests passed
PASS: wocky-stanza-test: 21/21 tests passed
PASS: wocky-tls-test: 1/1 tests passed
PASS: wocky-utils-test: 1/1 tests passed
PASS: wocky-xmpp-connection-test: 9/9 tests passed
PASS: wocky-xmpp-node-test: 8/8 tests passed
PASS: wocky-xmpp-reader-test: 13/13 tests passed
PASS: wocky-xmpp-readwrite-test: 2/2 tests passed
PASS: wocky-test-sasl-auth: 17/17 tests passed

@rufferson
Copy link
Collaborator Author

So I think I'm good with this one, I've already started stockpiling next MR on top to cleanup/address Dan's spotlights, remove remnants of old code (openssl) and add additional test case (weak hash algo)

Copy link

@noonien-d noonien-d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I'm looking forward to your cleanups :-)

@Kaffeine
Copy link
Member

Kaffeine commented May 11, 2020

Are you done with this one? @noonien-d can I consider this PR as reviewed?

Edit: I just noticed noonien-d reviewed 20 minutes ago. OK, thank you, I'm going to merge this 👍 . I expected GitHub to show an appropriate icon at reviewers list (on the right top).

@Kaffeine Kaffeine merged commit aa31ef0 into TelepathyIM:master May 11, 2020
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

Successfully merging this pull request may close these issues.

4 participants