%! make_login_cookie(+UName:atom, -Cookie:string) is semidet
%
% Make the contents (a string of hex) of a persistent login cookie
% using:
%
% * the passed in user name
% * the rememberme_duration
% * a secret generated and stored in file
make_login_cookie(UName, Cookie) :-
www_form_encode(URLEncodedUName, UName),
get_time(Now),
setting(identity:rememberme_duration, DurSecs),
Expires is floor(Now + DurSecs),
get_crypto_key(Key),
atomics_to_string([URLEncodedUName, "/", Expires], PlainText),
crypto_n_random_bytes(12, Nonce),
% next line throws
crypto_data_encrypt(PlainText, 'chacha20-poly1305',
Key, Nonce, CipherText, []),
string_codes(CipherText, CipherTextCodes),
append(Nonce, CipherTextCodes, TokenList),
hex_bytes(Cookie, TokenList).
crypto:'_crypto_data_encrypt'/8: Domain error: `cipher' expected, found `'chacha20-poly1305''
I presume the correct thing to pass is in the foreign library crypto4pl, but I’m reluctant to select randomly, as this has security implications.
Works fine here (Ubuntu 20.04. Note that you need to have compiled against a version of OpenSSL that supports this algorithm. That probably requires the right OpenSSL version (range) and possibly the right flags.
I don’t know. I did a quick grep for chacha on the source and only found hits in the comments so I suspect crypto_data_encrypt/6 simply passes strings to OpenSSL to select he algorithm. Most likely the openssl command has some option to check which algorithms it supports. Make sure Prolog and openssl bind to the same library though. An old library or header in the wrong place is another common cause for issues like this.
The pyswipl FFI uses hard coded constants that are copied from SWI-Prolog.h. A number of these values have changed. This is a very rare situation, but was necessary to accommodate rational numbers.
The best route is probably to resync these constants in the Python interface. Ideally such an upgrade would also support the new SWI-Prolog rational numbers …
Ooof. PL_STRING changed from 5 to 6.
I also found REP_UTF8 was incorrect in pyswip (I don’t think it has changed in SWI for some time).
Thank @jan . This saved me a lot of hunting.
This could have used a major version number increment since its a breaking API change.
We went from 8.0 to 8.2, which in SWI-Prolog’s versioning is a new release cycle. The project is less suitable for the common major.minor.patch semantics. On the stable release we want to maintain the patch level semantics. On the development cycle things just develop and may break. As is, major releases are landmarks that indicate major changes of functionality. I agree this is all a bit fuzzy