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

Add configuration to disable peer verification #62

Closed
wants to merge 2 commits into from
Closed

Add configuration to disable peer verification #62

wants to merge 2 commits into from

Conversation

jeromegamez
Copy link
Contributor

Sometimes, one might want (or have) to connect to an SSL host with a self-signed certificate.

This PR adds the possibility to disable the peer certificate verification (the default remains true). The naming of the variable and methods follow the naming in the curl_setopt() specification (CURLOPT_SSL_VERIFYPEER).

Cheers
:octocat: Jérôme

@egeloen
Copy link
Owner

egeloen commented Jan 8, 2015

👍 but you need to add the feature on all adapters. Additionally, I would add two tests, one with a valid ssl certificate and one with an invalid ssl certificate.

@jeromegamez
Copy link
Contributor Author

Ok, but I don't know when I will get to to that, but I will!

On another note - I noticed a dependency `"phpunit/phpunit-mock-objects": "dev-matcher-verify as 2.3.x-dev" in the composer.json, but I couldn't find this branch/tag anywhere - what's about that?

@egeloen
Copy link
Owner

egeloen commented Jan 8, 2015

Thsi is related to sebastianbergmann/phpunit-mock-objects#191 I use my fork since this bug is not fixed.

@jeromegamez
Copy link
Contributor Author

Ah, thanks for the info!

@jeromegamez
Copy link
Contributor Author

I just updated most of the adapters, but I am currently hanging at React - could you have a look at it? From what I see, it seems not possible to pass context options when creating a socket (see reactphp-legacy/socket-client#4), and you have had a similar request as well, as I just saw (reactphp-legacy/socket-client#17 (comment)).

React will have a problem with insecure Certificates starting with PHP 5.6, where the verification has been set to true by default.

'allow_self_signed' => !$this->getConfiguration()->getSSLVerifyPeer(),
);

$context = stream_context_create(array(), $contextOptions);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what would be needed to be set for React as well.

Copy link
Owner

Choose a reason for hiding this comment

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

If react is not able to do it, please open an issue if there is none and document it as not usable with this adapter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue is already there: reactphp-legacy/socket-client#4.

Copy link
Owner

Choose a reason for hiding this comment

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

👍

@egeloen
Copy link
Owner

egeloen commented Jan 11, 2015

Can you add a test with an ssl verification? Thanks

@jeromegamez
Copy link
Contributor Author

How do you envision such a test with ssl verification - in which TestCase would you see it and what should it include? I must admit, I wasn't able to setup a fully working test environment yet and was performing my local test suite exclusively with --filter arguments :)

Except the mentioned test, everything should be in and as you wished, though. Perhaps you would be able to add those tests more quickly than I would be?

@egeloen
Copy link
Owner

egeloen commented Jan 12, 2015

I know the test suite is not so easy to setup but at the same time, what it does is not easy as well :) Anyway, I understand your issues and will play with your code. Unfortunatelly, I should not be able to do it before the end of the week.

If I forget, don't hesitate to ping me :)

@egeloen
Copy link
Owner

egeloen commented Jan 12, 2015

Btw, thanks for your work! 👍 ❤️

@jeromegamez
Copy link
Contributor Author

Thank you! The HTTP adapter is a wonderful library, I am happy to be able to participate and appreciate you letting me!

@jeromegamez
Copy link
Contributor Author

Is this issue PR the one that is standing between the release of 0.6? If yes, I would try to work out how to to an SSL test this evening.

@egeloen
Copy link
Owner

egeloen commented Jan 20, 2015

No, the 0.6 bloker is #61.

@egeloen
Copy link
Owner

egeloen commented Feb 3, 2015

I will try to add some tests on this one

@egeloen
Copy link
Owner

egeloen commented Feb 3, 2015

I have added two tests called testSendWithSelfSignedSslCertificate which check if a self signed certificated is trusted when we disable the peer verification and testSendWithInvalidSslCertificate which verifies if an exception is well thrown when the feature is enabled.

Unfortunatelly, it seems there is only the curl adapter which works :s Would you like I submit them as PR on your fork? I need first to set up it on travis...

Here the output of my tests:

There were 4 errors:

1) Ivory\Tests\HttpAdapter\BuzzCurlHttpAdapterTest::testSendWithSelfSignedSslCertificate
Ivory\HttpAdapter\HttpAdapterException: An error occurred when fetching the URL "https://127.0.0.1:11000/server.php" with the adapter "buzz" ("SSL: unable to obtain common name from peer certificate").

/home/gelo/Workspace/Ivory/http-adapter/src/HttpAdapterException.php:101
/home/gelo/Workspace/Ivory/http-adapter/src/BuzzHttpAdapter.php:89
/home/gelo/Workspace/Ivory/http-adapter/src/AbstractHttpAdapter.php:292
/home/gelo/Workspace/Ivory/http-adapter/src/AbstractHttpAdapter.php:74
/home/gelo/Workspace/Ivory/http-adapter/src/AbstractHttpAdapterTemplate.php:28
/home/gelo/Workspace/Ivory/http-adapter/tests/AbstractHttpAdapterTest.php:305

2) Ivory\Tests\HttpAdapter\CakeHttpAdapterTest::testSendWithSelfSignedSslCertificate
Ivory\HttpAdapter\HttpAdapterException: An error occurred when fetching the URL "https://127.0.0.1:11000/server.php" with the adapter "cake" ("stream_socket_client(): Unable to locate peer certificate CN
stream_socket_client(): Failed to enable crypto
stream_socket_client(): unable to connect to ssl://127.0.0.1:11000 (Unknown error)").

/home/gelo/Workspace/Ivory/http-adapter/src/HttpAdapterException.php:101
/home/gelo/Workspace/Ivory/http-adapter/src/CakeHttpAdapter.php:69
/home/gelo/Workspace/Ivory/http-adapter/src/AbstractHttpAdapter.php:292
/home/gelo/Workspace/Ivory/http-adapter/src/AbstractHttpAdapter.php:74
/home/gelo/Workspace/Ivory/http-adapter/src/AbstractHttpAdapterTemplate.php:28
/home/gelo/Workspace/Ivory/http-adapter/tests/AbstractHttpAdapterTest.php:305

3) Ivory\Tests\HttpAdapter\Zend1CurlHttpAdapterTest::testSendWithSelfSignedSslCertificate
Ivory\HttpAdapter\HttpAdapterException: An error occurred when fetching the URL "https://127.0.0.1:11000/server.php" with the adapter "zend1" ("Error in cURL request: SSL certificate problem: self signed certificate").

/home/gelo/Workspace/Ivory/http-adapter/src/HttpAdapterException.php:101
/home/gelo/Workspace/Ivory/http-adapter/src/Zend1HttpAdapter.php:71
/home/gelo/Workspace/Ivory/http-adapter/src/AbstractHttpAdapter.php:292
/home/gelo/Workspace/Ivory/http-adapter/src/AbstractHttpAdapter.php:74
/home/gelo/Workspace/Ivory/http-adapter/src/AbstractHttpAdapterTemplate.php:28
/home/gelo/Workspace/Ivory/http-adapter/tests/AbstractHttpAdapterTest.php:305

4) Ivory\Tests\HttpAdapter\Zend2CurlHttpAdapterTest::testSendWithSelfSignedSslCertificate
Ivory\HttpAdapter\HttpAdapterException: An error occurred when fetching the URL "https://127.0.0.1:11000/server.php" with the adapter "zend2" ("Error in cURL request: SSL certificate problem: self signed certificate").

/home/gelo/Workspace/Ivory/http-adapter/src/HttpAdapterException.php:101
/home/gelo/Workspace/Ivory/http-adapter/src/Zend2HttpAdapter.php:71
/home/gelo/Workspace/Ivory/http-adapter/src/AbstractHttpAdapter.php:292
/home/gelo/Workspace/Ivory/http-adapter/src/AbstractHttpAdapter.php:74
/home/gelo/Workspace/Ivory/http-adapter/src/AbstractHttpAdapterTemplate.php:28
/home/gelo/Workspace/Ivory/http-adapter/tests/AbstractHttpAdapterTest.php:305

--

There were 9 failures:

1) Ivory\Tests\HttpAdapter\FileGetContentsHttpAdapterTest::testSendWithInvalidSslCertificate
Failed asserting that exception of type "\Ivory\HttpAdapter\HttpAdapterException" is thrown.

2) Ivory\Tests\HttpAdapter\FopenHttpAdapterTest::testSendWithInvalidSslCertificate
Failed asserting that exception of type "\Ivory\HttpAdapter\HttpAdapterException" is thrown.

3) Ivory\Tests\HttpAdapter\GuzzleHttpStreamHttpAdapterTest::testSendWithInvalidSslCertificate
Failed asserting that exception of type "\Ivory\HttpAdapter\HttpAdapterException" is thrown.

4) Ivory\Tests\HttpAdapter\ReactHttpAdapterTest::testSendWithInvalidSslCertificate
Failed asserting that exception of type "\Ivory\HttpAdapter\HttpAdapterException" is thrown.

5) Ivory\Tests\HttpAdapter\SocketHttpAdapterTest::testSendWithInvalidSslCertificate
Failed asserting that exception of type "\Ivory\HttpAdapter\HttpAdapterException" is thrown.

6) Ivory\Tests\HttpAdapter\Zend1ProxyHttpAdapterTest::testSendWithInvalidSslCertificate
Failed asserting that exception of type "\Ivory\HttpAdapter\HttpAdapterException" is thrown.

7) Ivory\Tests\HttpAdapter\Zend1SocketHttpAdapterTest::testSendWithInvalidSslCertificate
Failed asserting that exception of type "\Ivory\HttpAdapter\HttpAdapterException" is thrown.

8) Ivory\Tests\HttpAdapter\Zend2ProxyHttpAdapterTest::testSendWithInvalidSslCertificate
Failed asserting that exception of type "\Ivory\HttpAdapter\HttpAdapterException" is thrown.

9) Ivory\Tests\HttpAdapter\Zend2SocketHttpAdapterTest::testSendWithInvalidSslCertificate
Failed asserting that exception of type "\Ivory\HttpAdapter\HttpAdapterException" is thrown.

FAILURES!                                                          
Tests: 2581, Assertions: 40737, Failures: 9, Errors: 4, Skipped: 6.

@jeromegamez
Copy link
Contributor Author

Of course, please feel free to add them to my fork - starting there, I can learn from what you did and perhaps continue the research on the topic.

@jeromegamez
Copy link
Contributor Author

I think you also can push them to "my" branch directly if you add my fork as a remote, or just send me the code as a Gist and I will work it in.

@egeloen
Copy link
Owner

egeloen commented Feb 3, 2015

Then, can you give me push permission to your fork?

@jeromegamez
Copy link
Contributor Author

Oops, done!

@egeloen
Copy link
Owner

egeloen commented Feb 4, 2015

Thanks! I'm still not able to make it working on travis. It seems I need to generate a new signed certificate according to the hostname used... I can't do it right now but I will be on week-end tomorrow afternoom so, I will work on it tomorrow night and I will release the 0.6 on the same time. Then, I will be able to resync the lib with the latest PSR-7 version and fix other issues related to the event dispatcher :)

Btw, have you been able to make the tests running on your laptop?

@jeromegamez
Copy link
Contributor Author

How do you know I'm using a Laptop? ARE YOU STALKING ME!

I haven't had the opportunity to even have a look at it yet, but I will try this evening. What would you think about having a dedicated Webserver somewhere to run the tests against? We could hide it by using dotenv with an encrypted .env file - or find a service like http://httpstat.us ... or create one :).

@jeromegamez
Copy link
Contributor Author

If you were okay with using httpstat.us as a test server, this would greatly simplify the travis workflow, and we could use it to test:

at least for simple tests... what do you think?

@jeromegamez
Copy link
Contributor Author

Have you pushed the new tests already? I haven't found them yet on one of my branches...

@egeloen
Copy link
Owner

egeloen commented Feb 5, 2015

I will push them later on the night. I still need to make them running on travis... I'm not familiar with the service you pointed out. My only concern is performance. I don't want tests to run during more than 10 minutes, it will become insane. Currently, there is lot of requests which are send (sometime more than 60 in parallel...), so if the service does not decrease too much performance and if it simplifies tests, I'm 👍

@egeloen
Copy link
Owner

egeloen commented Feb 5, 2015

@jeromegamez I just added tests which are not fully complete (some travis steps are missing).

@egeloen egeloen added this to the 0.7.1 release milestone Mar 8, 2015
@egeloen
Copy link
Owner

egeloen commented Mar 8, 2015

@jeromegamez I just rebase this PR and rework a little bit the patch in order to make it working on travis + make tests passing for some adapters. The remaining failling ones will need more investigation in order to be solved...

The broken one are:

  • Guzzle http: The stream sub adapter (only) does not pass the tests (I suspect an issue in Guzzle as it works for other sub adapters).
  • Zend2: All sub adapters does not pass the tests whereas I have added the same code than for Zend1. It seems an sslcafile is required but I would like to not introduce it if possible...
  • React: I have not tried to fix it...

For other adapters, tests are green!

@jeromegamez
Copy link
Contributor Author

Phew, this is tough...

Guzzle 3.x is deprecated anyways - I know, this would be quite a "workaround", but do you really want to continue to support it when the library itself is two versions behind and not supported anymore?

As for the other two... unfortunately, I still am not able to setup the same development environment as you have to perform the tests with the test server that is also used on travis. Do you perhaps have a vagrant Dev-VM that we don't know about yet, that you could share? :)

@egeloen
Copy link
Owner

egeloen commented Apr 21, 2015

For the record, I'm on this one again. I must admit it is a pain due to the buggy adapters which require a lot of debug...

@egeloen
Copy link
Owner

egeloen commented Apr 21, 2015

The remaining ones which need to be fixed are Zend 1 & 2.

@jeromegamez
Copy link
Contributor Author

How about not doing anything on clients that don't support it and adding a E_NOTICE or something similar to them? For the unit tests, they could be marked as skipped so that they don't get forgotten and can be re-tested at later times when new versions of the clients have been released?

@egeloen
Copy link
Owner

egeloen commented Apr 22, 2015

Yeah, for the adapter which does not support a feature, I explicitely mark the related tests as skipped. I like the idea of E_NOTICE but I wouldn't be able to do it for all unsupported feature... If you have an idea, I would like to see it :) So, for now, I prefer document it to let end user be aware of this missing feature.

@egeloen
Copy link
Owner

egeloen commented Apr 22, 2015

Here, I am! Everything is fine except for React 🤘

@@ -48,6 +48,18 @@ public function testSendWithTimeoutExceeded($timeout)
$this->markTestSkipped();
}

public function testSendWithSelfSignedSslCertificate()
Copy link
Owner

Choose a reason for hiding this comment

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

Note to myself, this test shouldn't be skipped but for a reason I don't understand for now, React fails for PHP >= 5.6 only.

Choose a reason for hiding this comment

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

Probably due to missconfiguration of php.

@egeloen
Copy link
Owner

egeloen commented Apr 22, 2015

The build is probably broken due to the usage of my fork of guzzle/RingPHP which is not compatible with the lowest deps... I will need to refine the guzzlehttp deps...

@sagikazarmark
Copy link
Contributor

I think this should be reimplemented after the migration.

@jeromegamez do you mind that?

@egeloen
Copy link
Owner

egeloen commented May 2, 2015

Personally, I'm fine with that! I will keep the code anyway. And I have still an issue to open on react as I have different behaviors on different PHP versions.

@jeromegamez
Copy link
Contributor Author

I don't mind at all - ping me when the migration is finished and I will get to it 👍

@egeloen
Copy link
Owner

egeloen commented Dec 13, 2015

This is a known limitation of the library and will not be fixed as this repository is deprecated in favor of https://github.com/php-http The good fix is to upgrade following http://docs.httplug.io/en/latest/httplug/migrating/

@egeloen egeloen closed this Dec 13, 2015
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.

None yet

5 participants