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

OpenSSL v3 invalid token #641

Closed
gene-git opened this issue Nov 8, 2022 · 33 comments
Closed

OpenSSL v3 invalid token #641

gene-git opened this issue Nov 8, 2022 · 33 comments
Labels
bug Something isn't working

Comments

@gene-git
Copy link

gene-git commented Nov 8, 2022

The new release tar asset has different url than earlier ones - it was under ../releases/downloads/.. .now its ../refs/tags/ and doesn't look like release.php was run - maybe I'm wrong. Version file is 0.0.0 which usually gets the release version after release.php is run.

Anyway - I ran release.php - and installed - but it fails to let me login - i get 'invalid token'

Maybe its me but any suggestions to fix the invalid token thing would be appreciated.

@gene-git
Copy link
Author

gene-git commented Nov 8, 2022

Come to think of it - between the last snappymail test (2.20.2) and now dovecot has been rebuilt against openssl 3 - so thats another change - could that have anything to do with it you think?

All the usual mail apps don't seem to care so didn't think it mattered but thought best to mention for completeness.

php is vers is 8.1.12 (as of oct 29)

thanks for any guidance

@yasuhirokimura
Copy link

Probably author forgot to provide release archive files (snappymail-2.20.5.{tar.gz,zip}).

@the-djmaze
Copy link
Owner

I improved token error handling but forgot to test and remove param.
Is fixed by #642

@the-djmaze
Copy link
Owner

Should work now with v2.20.6

@gene-git
Copy link
Author

gene-git commented Nov 8, 2022

Just tried 2.20.6 - still have same problem being unable to login - same user/pass as always - I still get 'invalid token' popup over login auth screen.
dovecot log just shows user login followed immediately by Disconnected: Logged out

@relikd
Copy link

relikd commented Nov 8, 2022

I get invalid directory when I try to logout. (with 2.20.6). Deactivating Snappy solves the issue

@dertinger
Copy link

I've also been getting "invalid token" for the last couple of days. It might be a coincidence, but the behaviour started when I updated OpenSSL from 1.1.1 to 3.0.7 on my Arch Linux system.

Updating snappymail to 2.20.6 did not help.

When trying to log in to the admin panel, I'm seeing the same behaviour that @alabre describes in #632 (comment)_

This is what appears in my snappymail logs after a failed login as a regular user:

[2022-11-08 20:33:18.423][73913a68] PHP-USER[NOTICE]: SnappyMail\Crypt::opensslDecrypt(): Control character error, possibly incorrectly encoded /usr/share/snappymail/snappymail/v/2.20.6/app/libraries/snappymail/crypt.php [line:63, code:1024]
[2022-11-08 20:33:18.425][73913a68] PHP-USER[NOTICE]: SnappyMail\Crypt::opensslDecrypt(): Control character error, possibly incorrectly encoded /usr/share/snappymail/snappymail/v/2.20.6/app/libraries/snappymail/crypt.php [line:63, code:1024]
[2022-11-08 20:33:19.587][effaa307] PHP-USER[NOTICE]: SnappyMail\Crypt::opensslDecrypt(): $data or $iv is empty string /usr/share/snappymail/snappymail/v/2.20.6/app/libraries/snappymail/crypt.php [line:63, code:1024]
[2022-11-08 20:33:19.588][effaa307] SERVICE[WARNING]: InvalidToken[101]
#0 /usr/share/snappymail/snappymail/v/2.20.6/app/libraries/RainLoop/Actions/UserAuth.php(202): RainLoop\Actions->getMainAccountFromToken()
#1 /usr/share/snappymail/snappymail/v/2.20.6/app/libraries/RainLoop/Actions.php(1175): RainLoop\Actions->getAccountFromToken()
#2 /usr/share/snappymail/snappymail/v/2.20.6/app/libraries/RainLoop/Actions/Folders.php(55): RainLoop\Actions->initMailClientConnection()
#3 /usr/share/snappymail/snappymail/v/2.20.6/app/libraries/RainLoop/ServiceActions.php(155): RainLoop\Actions->DoFolders()
#4 /usr/share/snappymail/snappymail/v/2.20.6/app/libraries/RainLoop/Service.php(123): RainLoop\ServiceActions->ServiceJson()
#5 /usr/share/snappymail/snappymail/v/2.20.6/app/libraries/RainLoop/Service.php(15): RainLoop\Service::RunResult()
#6 /usr/share/snappymail/snappymail/v/2.20.6/include.php(167): RainLoop\Service::Handle()
#7 /usr/share/snappymail/index.php(11): include('...')
#8 {main}
[2022-11-08 20:33:19.588][effaa307] [NOTICE]: RainLoop\Exceptions\ClientException: InvalidToken[101] in /usr/share/snappymail/snappymail/v/2.20.6/app/libraries/RainLoop/Actions/UserAuth.php:288
Stack trace:
#0 /usr/share/snappymail/snappymail/v/2.20.6/app/libraries/RainLoop/Actions/UserAuth.php(202): RainLoop\Actions->getMainAccountFromToken()
#1 /usr/share/snappymail/snappymail/v/2.20.6/app/libraries/RainLoop/Actions.php(1175): RainLoop\Actions->getAccountFromToken()
#2 /usr/share/snappymail/snappymail/v/2.20.6/app/libraries/RainLoop/Actions/Folders.php(55): RainLoop\Actions->initMailClientConnection()
#3 /usr/share/snappymail/snappymail/v/2.20.6/app/libraries/RainLoop/ServiceActions.php(155): RainLoop\Actions->DoFolders()
#4 /usr/share/snappymail/snappymail/v/2.20.6/app/libraries/RainLoop/Service.php(123): RainLoop\ServiceActions->ServiceJson()
#5 /usr/share/snappymail/snappymail/v/2.20.6/app/libraries/RainLoop/Service.php(15): RainLoop\Service::RunResult()
#6 /usr/share/snappymail/snappymail/v/2.20.6/include.php(167): RainLoop\Service::Handle()
#7 /usr/share/snappymail/index.php(11): include('...')
#8 {main}
[2022-11-08 20:33:19.588][effaa307] [ERROR]: RainLoop\Exceptions\ClientException: InvalidToken[101] in /usr/share/snappymail/snappymail/v/2.20.6/app/libraries/RainLoop/Actions/UserAuth.php:288
Stack trace:
#0 /usr/share/snappymail/snappymail/v/2.20.6/app/libraries/RainLoop/Actions/UserAuth.php(202): RainLoop\Actions->getMainAccountFromToken()
#1 /usr/share/snappymail/snappymail/v/2.20.6/app/libraries/RainLoop/Actions.php(1175): RainLoop\Actions->getAccountFromToken()
#2 /usr/share/snappymail/snappymail/v/2.20.6/app/libraries/RainLoop/Actions/Folders.php(55): RainLoop\Actions->initMailClientConnection()
#3 /usr/share/snappymail/snappymail/v/2.20.6/app/libraries/RainLoop/ServiceActions.php(155): RainLoop\Actions->DoFolders()
#4 /usr/share/snappymail/snappymail/v/2.20.6/app/libraries/RainLoop/Service.php(123): RainLoop\ServiceActions->ServiceJson()
#5 /usr/share/snappymail/snappymail/v/2.20.6/app/libraries/RainLoop/Service.php(15): RainLoop\Service::RunResult()
#6 /usr/share/snappymail/snappymail/v/2.20.6/include.php(167): RainLoop\Service::Handle()
#7 /usr/share/snappymail/index.php(11): include('...')
#8 {main}

@the-djmaze
Copy link
Owner

Json decoder throws error, because the data contains control character.
It looks like decode fails due to mismatch with encoded data.

When you install sodium in php, does that solve the issue?

@dertinger
Copy link

Yes indeed, enabling sodium did the trick. It was already installed but not enabled in my php.ini. Thank you!

@the-djmaze
Copy link
Owner

Good workaround!

I will wrap up some code for OpenSSL testing because more people with OpenSSL 3 will get errors.

@gene-git
Copy link
Author

gene-git commented Nov 8, 2022

I enabled it in php.ini and still see this error:

SnappyMail\Crypt::opensslDecrypt(): $data or $iv is empty string in /usr/share/webapps/snappymail/snappymail/v/2.20.6/app/libraries/snappymail/crypt.php on line 63"

I have libsodium installed but not php-sodium .. maybe I need that too?

@the-djmaze
Copy link
Owner

yes you need that too

@gene-git
Copy link
Author

gene-git commented Nov 8, 2022

yah ok that did it ... (and restarting php-fm).

@the-djmaze
Copy link
Owner

Could you also tell your value of encrypt_cipher in application.ini

@gene-git
Copy link
Author

gene-git commented Nov 8, 2022

where is application.init?

@gene-git
Copy link
Author

gene-git commented Nov 8, 2022

If its this one: snappymail/data/data/default/configs/application.ini
i have no encrypt_cipher in that ... maybe its somewhere else?
edit - that is in /var/lib/

@dertinger
Copy link

For me it's encrypt_cipher = "aes-256-cbc-hmac-sha1"

@gene-git
Copy link
Author

gene-git commented Nov 8, 2022

which file is that @dertinger

@gene-git
Copy link
Author

gene-git commented Nov 8, 2022

sounds like a weak one to me ...

@dertinger
Copy link

@gene-git

which file is that @dertinger

It's the one from the path you mentioned

@gene-git
Copy link
Author

gene-git commented Nov 8, 2022

thanks - something I should add perhaps

@gene-git
Copy link
Author

gene-git commented Nov 8, 2022

should we close this one or do you want to keep it open while you tweak openssl bits?

@the-djmaze
Copy link
Owner

the-djmaze commented Nov 8, 2022

Keep open as the OpenSSL issue is not solved yet.

I now do have a test script to use with SnappyMail root index.php
Now we might get the solution.

<?php
$_ENV['SNAPPYMAIL_INCLUDE_AS_API'] = true;
require __DIR__ . '/index.php';

header('Content-Type: text/plain');

$data = \random_bytes(2048);
$key = \random_bytes(16);
foreach (\SnappyMail\Crypt::listCiphers() as $cipher) {
	echo "{$cipher} = ";
	try {
		\SnappyMail\Crypt::setCipher($cipher);
		$iv = \random_bytes(\openssl_cipher_iv_length($cipher));
		$encrypted = \SnappyMail\Crypt::OpenSSLEncrypt($data, $iv, $key);
		$decrypted = $encrypted ? \SnappyMail\Crypt::OpenSSLDecrypt($encrypted, $iv, $key) : '';
	} catch (\Throwable $e) {
		$decrypted = '';
	}
	echo (0 === \strcmp($data, $decrypted) ? 'ok' : 'FAILED') . "\n";
}

archlinux-github pushed a commit to archlinux/aur that referenced this issue Nov 9, 2022
Ref: the-djmaze/snappymail#641

The sodium extension must be enabled in php.ini or similar configuraton
file.
@grawlinson
Copy link

Yo, package maintainer for AUR package of snappymail here. I've just pushed a fix adding php-sodium as a hard dependency. Will also pin a comment on the AUR page referencing this issue.

@the-djmaze the-djmaze changed the title 2.20.5 / invalid token OpenSSL v3 invalid token Nov 9, 2022
the-djmaze pushed a commit that referenced this issue Nov 9, 2022
@the-djmaze
Copy link
Owner

the-djmaze commented Nov 9, 2022

I've made changes to the handling of the OpenSSL cipher setting.
It should forcefully set a cipher when the current value of encrypt_cipher is unsupported.

This does have impact when switching from OpenSSL v1 to v3, but the login should work.
Only problem is additional login accounts that can't be decrypted and you must enter password of those accounts again.

I've also added additional logging when encryption fails.

@the-djmaze the-djmaze added the bug Something isn't working label Nov 9, 2022
@the-djmaze
Copy link
Owner

Can someone with OpenSSL v3 run above script and provide the output so that i can compare it?

As I don't have OpenSSL v3 anywhere at the moment.

@gene-git
Copy link
Author

gene-git commented Nov 9, 2022

Sure
2 parts - part 1 is stderr

PHP Warning: openssl_cipher_iv_length(): Unknown cipher algorithm in /usr/share/webapps/snappymail/test.php on line 13
PHP Warning: openssl_encrypt(): A tag should be provided when using AEAD mode in /usr/share/webapps/snappymail/snappymail/v/2.20.6/app/libraries/snappymail/crypt.php on line 182
PHP Warning: openssl_cipher_iv_length(): Unknown cipher algorithm in /usr/share/webapps/snappymail/test.php on line 13
PHP Warning: openssl_cipher_iv_length(): Unknown cipher algorithm in /usr/share/webapps/snappymail/test.php on line 13
PHP Warning: openssl_cipher_iv_length(): Unknown cipher algorithm in /usr/share/webapps/snappymail/test.php on line 13
PHP Warning: openssl_cipher_iv_length(): Unknown cipher algorithm in /usr/share/webapps/snappymail/test.php on line 13
PHP Warning: openssl_encrypt(): A tag should be provided when using AEAD mode in /usr/share/webapps/snappymail/snappymail/v/2.20.6/app/libraries/snappymail/crypt.php on line 182
PHP Warning: openssl_cipher_iv_length(): Unknown cipher algorithm in /usr/share/webapps/snappymail/test.php on line 13
PHP Warning: openssl_cipher_iv_length(): Unknown cipher algorithm in /usr/share/webapps/snappymail/test.php on line 13
PHP Warning: openssl_cipher_iv_length(): Unknown cipher algorithm in /usr/share/webapps/snappymail/test.php on line 13
PHP Warning: openssl_cipher_iv_length(): Unknown cipher algorithm in /usr/share/webapps/snappymail/test.php on line 13
PHP Warning: openssl_encrypt(): A tag should be provided when using AEAD mode in /usr/share/webapps/snappymail/snappymail/v/2.20.6/app/libraries/snappymail/crypt.php on line 182
PHP Warning: openssl_cipher_iv_length(): Unknown cipher algorithm in /usr/share/webapps/snappymail/test.php on line 13
PHP Warning: openssl_cipher_iv_length(): Unknown cipher algorithm in /usr/share/webapps/snappymail/test.php on line 13
PHP Warning: openssl_cipher_iv_length(): Unknown cipher algorithm in /usr/share/webapps/snappymail/test.php on line 13
PHP Warning: openssl_cipher_iv_length(): Unknown cipher algorithm in /usr/share/webapps/snappymail/test.php on line 13
PHP Warning: openssl_cipher_iv_length(): Unknown cipher algorithm in /usr/share/webapps/snappymail/test.php on line 13
PHP Warning: openssl_cipher_iv_length(): Unknown cipher algorithm in /usr/share/webapps/snappymail/test.php on line 13
PHP Warning: openssl_cipher_iv_length(): Unknown cipher algorithm in /usr/share/webapps/snappymail/test.php on line 13

@gene-git
Copy link
Author

gene-git commented Nov 9, 2022

part 2 is stdout

aes-128-cbc-cts = FAILED
aes-128-cbc-hmac-sha1 = ok
aes-128-cbc-hmac-sha256 = ok
aes-128-cfb = ok
aes-128-cfb1 = ok
aes-128-cfb8 = ok
aes-128-ctr = ok
aes-128-ocb = FAILED
aes-128-ofb = ok
aes-128-siv = FAILED
aes-128-wrap = ok
aes-128-wrap-inv = FAILED
aes-128-wrap-pad = ok
aes-128-wrap-pad-inv = FAILED
aes-128-xts = ok
aes-192-cbc = ok
aes-192-cbc-cts = FAILED
aes-192-cfb = ok
aes-192-cfb1 = ok
aes-192-cfb8 = ok
aes-192-ctr = ok
aes-192-ocb = FAILED
aes-192-ofb = ok
aes-192-siv = FAILED
aes-192-wrap = ok
aes-192-wrap-inv = FAILED
aes-192-wrap-pad = ok
aes-192-wrap-pad-inv = FAILED
aes-256-cbc = ok
aes-256-cbc-cts = FAILED
aes-256-cbc-hmac-sha1 = ok
aes-256-cbc-hmac-sha256 = ok
aes-256-cfb = ok
aes-256-cfb1 = ok
aes-256-cfb8 = ok
aes-256-ctr = ok
aes-256-ocb = FAILED
aes-256-ofb = ok
aes-256-siv = FAILED
aes-256-wrap = ok
aes-256-wrap-inv = FAILED
aes-256-wrap-pad = ok
aes-256-wrap-pad-inv = FAILED
aes-256-xts = ok
aria-128-cbc = ok
aria-128-cfb = ok
aria-128-cfb1 = ok
aria-128-cfb8 = ok
aria-128-ctr = ok
aria-128-ofb = ok
aria-192-cbc = ok
aria-192-cfb = ok
aria-192-cfb1 = ok
aria-192-cfb8 = ok
aria-192-ctr = ok
aria-192-ofb = ok
aria-256-cbc = ok
aria-256-cfb = ok
aria-256-cfb1 = ok
aria-256-cfb8 = ok
aria-256-ctr = ok
aria-256-ofb = ok
camellia-128-cbc = ok
camellia-128-cbc-cts = FAILED
camellia-128-cfb = ok
camellia-128-cfb1 = ok
camellia-128-cfb8 = ok
camellia-128-ctr = ok
camellia-128-ofb = ok
camellia-192-cbc = ok
camellia-192-cbc-cts = FAILED
camellia-192-cfb = ok
camellia-192-cfb1 = ok
camellia-192-cfb8 = ok
camellia-192-ctr = ok
camellia-192-ofb = ok
camellia-256-cbc = ok
camellia-256-cbc-cts = FAILED
camellia-256-cfb = ok
camellia-256-cfb1 = ok
camellia-256-cfb8 = ok
camellia-256-ctr = ok
camellia-256-ofb = ok
chacha20 = ok
chacha20-poly1305 = ok
null = FAILED
sm4-cbc = ok
sm4-cfb = ok
sm4-ctr = ok
sm4-ofb = ok

@the-djmaze
Copy link
Owner

Awesome, i've added them to filter out the FAILED options.

@gene-git
Copy link
Author

gene-git commented Nov 9, 2022

quick question - for some reason I can no longer login to admin panel - I want to change from starttls to SSL - (imap on 993, smtp on 465) - in the domain ini file - i currently use "TLS" - what do I change it to to get SSL ?

@gene-git
Copy link
Author

gene-git commented Nov 9, 2022

I meant the 2 settings: imap_secure nd smtp_secure
I glanced at code but wasn't obvious - i found TLS but nothing obvious like SSL

@dertinger
Copy link

I just realized that CardDAV sync is still broken for OpenSSL reasons even after the fix for the login issue. Syncing used to work until the OpenSSL update.

This is what the log says after an attempt to sync contacts with my Radicale server:

[2022-11-13 21:12:34.521][5589861f] PHP-USER[NOTICE]: SnappyMail\Crypt::opensslDecrypt(): Control character error, possibly incorrectly encoded /usr/share/snappymail/snappymail/v/2.21.0/app/libraries/snappymail/crypt.php [line:66, code:1024]
[2022-11-13 21:12:34.523][5589861f] PdoAddressBook[WARNING]: Sync() invalid DavClient
[2022-11-13 21:12:34.523][5589861f] SERVICE[WARNING]: ContactsSyncError[140]
#0 /usr/share/snappymail/snappymail/v/2.21.0/app/libraries/RainLoop/ServiceActions.php(155): RainLoop\Actions->DoContactsSync()
#1 /usr/share/snappymail/snappymail/v/2.21.0/app/libraries/RainLoop/Service.php(123): RainLoop\ServiceActions->ServiceJson()
#2 /usr/share/snappymail/snappymail/v/2.21.0/app/libraries/RainLoop/Service.php(15): RainLoop\Service::RunResult()
#3 /usr/share/snappymail/snappymail/v/2.21.0/include.php(167): RainLoop\Service::Handle()
#4 /usr/share/snappymail/index.php(11): include('...')
#5 {main}
[2022-11-13 21:12:34.523][5589861f] [NOTICE]: RainLoop\Exceptions\ClientException: ContactsSyncError[140] in /usr/share/snappymail/snappymail/v/2.21.0/app/libraries/RainLoop/Actions/Contacts.php:44
Stack trace:
#0 /usr/share/snappymail/snappymail/v/2.21.0/app/libraries/RainLoop/ServiceActions.php(155): RainLoop\Actions->DoContactsSync()
#1 /usr/share/snappymail/snappymail/v/2.21.0/app/libraries/RainLoop/Service.php(123): RainLoop\ServiceActions->ServiceJson()
#2 /usr/share/snappymail/snappymail/v/2.21.0/app/libraries/RainLoop/Service.php(15): RainLoop\Service::RunResult()
#3 /usr/share/snappymail/snappymail/v/2.21.0/include.php(167): RainLoop\Service::Handle()
#4 /usr/share/snappymail/index.php(11): include('...')
#5 {main}
[2022-11-13 21:12:34.523][5589861f] [ERROR]: RainLoop\Exceptions\ClientException: ContactsSyncError[140] in /usr/share/snappymail/snappymail/v/2.21.0/app/libraries/RainLoop/Actions/Contacts.php:44
Stack trace:
#0 /usr/share/snappymail/snappymail/v/2.21.0/app/libraries/RainLoop/ServiceActions.php(155): RainLoop\Actions->DoContactsSync()
#1 /usr/share/snappymail/snappymail/v/2.21.0/app/libraries/RainLoop/Service.php(123): RainLoop\ServiceActions->ServiceJson()
#2 /usr/share/snappymail/snappymail/v/2.21.0/app/libraries/RainLoop/Service.php(15): RainLoop\Service::RunResult()
#3 /usr/share/snappymail/snappymail/v/2.21.0/include.php(167): RainLoop\Service::Handle()
#4 /usr/share/snappymail/index.php(11): include('...')
#5 {main}

@dertinger
Copy link

I've moved my last comment regarding CardDAV to a new issue #674 so we can leave this one closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants