Eloy Lafuente (stronk7) 856b593796 MDL-75645 mnet: Stop caching OpenSSLAsymmetricKey keys
The mnet_environment->keypair array contains the following
elements (and more, just focussing on these):
- keypair_PEM : textual representation of the private key.
- certificate : textual representation of the public key.
- privatekey  : OpenSSLAsymmetricKey representation of the private key,
                generated from keypair_PEM. See get_private_key().
- publickey   : OpenSSLAsymmetricKey representation if the public key,
                generated from certificate. See get_public_key().

The last 2 elements in the array are only used as "caching", to avoid
having to call to openssl_pkey_get_private() and
openssl_pkey_get_public() to convert from the textual representation
to the OpenSSLAsymmetricKey representation that is the one required
by a number of openssl functions.

Problems arrive when, as part of the MNet protocol, the mnet_environment
is serialised, because, since PHP 8.0 those OpenSSLAsymmetricKey objects
aren't serialisable any more.

So, as far as they are only used for internal caching it's perfectly ok
to remove the caching bits and use the openssl_pkey_get_xxx() methods
to calculate them under demand.

The alternative to this would be to implement into the mnet_environment
some custom serialisation, skipping those OpenSSLAsymmetricKey
instances, using __sleep(), the Serializabla interface or __serialize(),
but that seems unnecessary because, as explained above, the uses are
really limited and easily replaceable.

That's what this patch does.
2022-10-18 14:30:50 +02:00
..