Skip to content

[zend-openid] fix TypeError when openssl rejects DH parameters - #247

Open
falkenhawk wants to merge 1 commit into
masterfrom
fix-openid-dh-key
Open

falkenhawk wants to merge 1 commit into
masterfrom
fix-openid-dh-key

Conversation

@falkenhawk

Copy link
Copy Markdown
Member

OpenID uses Diffie-Hellman (DH) keys to agree on a shared secret.
Zend_OpenId::createDhKey() creates them with openssl_pkey_new(), which returns false when OpenSSL rejects the DH parameters.
The next call, getDhKeyDetails(), then throws a TypeError on php 8.

1) The provider crashes on rejected DH parameters

Zend_OpenId_Provider takes the DH parameters from the association request.
OpenSSL 3+ rejects a modulus it considers too small ("modulus too small"), so a request with such a modulus ends with a 500 error.
The provider now answers with an association error, as for other invalid association parameters.

Zend_OpenId_Consumer always uses the default 1024-bit modulus of the OpenID spec, which all OpenSSL versions accept.
Should OpenSSL ever reject it, the association now fails like on any other error, instead of throwing.

computeDhSecret() no longer reads $ret[0] when openssl_dh_compute_key() fails, it returns false, which the provider already handles.

2) Tests on OpenSSL 3+

testCreateDhKey and testComputeDhSecret used a tiny test modulus (0x0233). OpenSSL 3+ rejects it, so the test run ended with a fatal error.
They now use the default modulus Zend_OpenId::DH_P with fixed private keys, and check the exact public keys and shared secret.
The expected values were computed with gmp and match OpenSSL 1.1, 3.5 and 4.0.
diablomedia skips these tests on OpenSSL 3 instead (diablomedia/zf1-openid#238).

A new provider test checks the error response for a modulus of 1, which every OpenSSL version rejects.

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.

1 participant