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

#2815 don't require ssl_key and ssl_cert to use ssl_ca #2816

Merged

Conversation

gauauu
Copy link
Contributor

@gauauu gauauu commented Aug 11, 2017

See #2815 -- you should be able to use ssl_ca for mysqli connections without specifying ssl_key and ssl_cert.

@Ocramius
Copy link
Member

@gauauu any way to test this effectively?

Also, the CI tests disagree with you here...

@Ocramius Ocramius changed the title don't require ssl_key and ssl_cert to use ssl_ca #2815 don't require ssl_key and ssl_cert to use ssl_ca Aug 11, 2017
@gauauu
Copy link
Contributor Author

gauauu commented Aug 11, 2017

Ah, I missed that unit test. That test is testing for those "mandatory" parameters to be present, but they aren't mandatory. I can remove that test.

Really, all I'm suggesting is REMOVING functionality, so I'm not sure there's a good way to test that (other than me removing the code (which I did) and a unit test that tests that code (Which I'll do)).

@nvanheuverzwijn
Copy link

I support this PR. ssl_key and ssl_cert are not mandatory.

Only the ssl_ca parameter is needed to establish a secure connection.

@nvanheuverzwijn
Copy link

Is there anything missing here for the merge to happen ?

@lcobucci
Copy link
Member

@nvanheuverzwijn time, unfortunately all maintainers are quite busy nowadays with paid work. I'll be working this weekend on trying to merge most of stuff.

/**
* @dataProvider secureMissingParamsProvider
*/
public function testThrowsExceptionWhenMissingMandatorySecureParams(array $secureParams)
Copy link
Member

Choose a reason for hiding this comment

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

Could you please modify this test to make it work in the new behaviour (with the proper assertions), instead of simply removing it? Without that we don't have anything testing that setSecureConnection() works correctly.

Choose a reason for hiding this comment

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

@lcobucci

There are two path to this block of code. The first is the parameter validation

        if (! isset($params['ssl_key']) &&
            ! isset($params['ssl_cert']) &&
            ! isset($params['ssl_ca']) &&
            ! isset($params['ssl_capath']) &&
            ! isset($params['ssl_cipher'])
        ) {
            return;
        }

Which translate to "don't do anything to the connection if there are missing parameters". Because this modify the connection, I am not sure how this can be tested with the actual state of the code. We would need to test that ssl_set function is not called on _conn variable .

The other block has the same problem (make sure that ssl_set is called). To properly test the code, we either need a mysql server or rewrite this code so that the _conn is somehow mockable.

$this->_conn->ssl_set(
            $params['ssl_key']    ?? null,
            $params['ssl_cert']   ?? null,
            $params['ssl_ca']     ?? null,
            $params['ssl_capath'] ?? null,
            $params['ssl_cipher'] ?? null
        );

While I highly encourage unit-testing, there are some problem that are not easily testable like this one. It highly depends on a third party program (mysql) and the code is not written for easy unit-testing. Also, the setSecureConnection is a private function which renders testing even more harder. We might consider mocking mysqli_init but this seems hackish to me, I don't know.

The actual state of the code makes unit-testing very hard. A rewrite would be required to test everything this class does. Integrated test would be more suitable (test against a real mysql server).

Copy link
Member

Choose a reason for hiding this comment

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

@nvanheuverzwijn you're correct, thanks! Let's ship it, then 😄

Choose a reason for hiding this comment

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

Thank you for your time ! Cheers !

@lcobucci
Copy link
Member

I support this PR. ssl_key and ssl_cert are not mandatory.

Only the ssl_ca parameter is needed to establish a secure connection.

@gauauu @nvanheuverzwijn is this correct?

According to the new code all the parameters are NOT mandatory, so maybe we have to adjust something?

@nvanheuverzwijn
Copy link

@lcobucci I confirm you that only ssl_ca is needed to establish a secure connection to a remote mysql server.

The ssl_key and ssl_cert parameter are needed when the remote mysql server requires the client to provide a ssl certificate for authentication however, this is not mandatory when doing ssl with mysql.

@lcobucci lcobucci force-pushed the fix/#2815-mysqli-ssl-key-should-not-be-reqd branch 7 times, most recently from ff4cada to 9ff2d21 Compare November 19, 2017 03:45
@lcobucci lcobucci force-pushed the fix/#2815-mysqli-ssl-key-should-not-be-reqd branch 2 times, most recently from 038712c to 6793dc7 Compare November 19, 2017 04:09
@lcobucci lcobucci force-pushed the fix/#2815-mysqli-ssl-key-should-not-be-reqd branch from 6793dc7 to c9f50b9 Compare November 19, 2017 04:16
@lcobucci
Copy link
Member

@lcobucci I confirm you that only ssl_ca is needed to establish a secure connection to a remote mysql server.

The ssl_key and ssl_cert parameter are needed when the remote mysql server requires the client to provide a ssl certificate for authentication however, this is not mandatory when doing ssl with mysql.

@nvanheuverzwijn thanks, I've managed to test that with functional test but for some weird reason that test was not working fine in travis 😭. Anyway, let's get it merged (for real this time HAHAHA)

@lcobucci lcobucci added this to the 2.6.3 milestone Nov 19, 2017
@lcobucci lcobucci merged commit edfbda1 into doctrine:master Nov 19, 2017
lcobucci added a commit to lcobucci/dbal that referenced this pull request Nov 19, 2017
@lcobucci
Copy link
Member

@gauauu @nvanheuverzwijn merged and backported, thanks for your contribution!

@lcobucci lcobucci self-assigned this Nov 19, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants