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

Disable verify ssl validation #32

Closed
erkinsergey opened this issue Sep 5, 2018 · 9 comments
Closed

Disable verify ssl validation #32

erkinsergey opened this issue Sep 5, 2018 · 9 comments
Assignees

Comments

@erkinsergey
Copy link

erkinsergey commented Sep 5, 2018

How can I prevent ssl from checking without changing the source code of the class Services_OpenStreetMap_Transport_HTTP?

Now I was able to achieve this only by changing the code :

class Services_OpenStreetMap_Transport_HTTP
    implements Services_OpenStreetMap_Transport
{
...
 public function getResponse(
        $url,
        $method = HTTP_Request2::METHOD_GET,
        $user = null,
        $password = null,
        $body = null,
        array $post_data = null,
        array $headers = null
    ) {
        ...
        $request = $this->getRequest();
        $request->setUrl($url);
        $request->setMethod($method);
        $request->setAdapter($this->getConfig()->getValue('adapter'));

        // my insertion
        $request->setConfig('ssl_verify_peer', FALSE);
        $request->setConfig('ssl_verify_host', FALSE);
        // the end of my insertion
        ...
@kenguest kenguest self-assigned this Sep 5, 2018
@kenguest
Copy link
Member

kenguest commented Sep 5, 2018

hi - thanks for your feedback.

I might address this shortly by introducing a new option in the Config object - until then your change looks good.

Thanks again!

@kenguest
Copy link
Member

kenguest commented Sep 5, 2018

hi @erkinsergey - I've committed some changes so that you should be able to do this now by setting the config for Services_OpenStreetMap instead of relying on your insertions.

...
$config = ['ssl_verify_peer' => false, 'ssl_verify_host' => false];
$osm = Services_OpenStreetMap($config);
...

I'll push a new release once I know this works as expected for you.

@erkinsergey
Copy link
Author

erkinsergey commented Sep 6, 2018

Yes, that's exactly what I need, Thank you!
However, after checking the work, it turned out that there was an error:

$config = [
    'ssl_verify_peer' => false, 
    'ssl_verify_host' => false
];
$osm = Services_OpenStreetMap($config);
class Services_OpenStreetMap_Transport_HTTP
    implements Services_OpenStreetMap_Transport
{
...
 public function getResponse(
        $url,
        $method = HTTP_Request2::METHOD_GET,
        $user = null,
        $password = null,
        $body = null,
        array $post_data = null,
        array $headers = null
    ) {
...
        $request->setConfig('ssl_verify_peer', $config->getValue('ssl_verify_peer'));
        $request->setConfig('ssl_verify_host', $config->getValue('ssl_verify_host'));

        $request->setConfig('ssl_cafile', $config->getValue('ssl_cafile'));
        $request->setConfig('ssl_local_cert', $config->getValue('ssl_local_cert'));
        $request->setConfig('ssl_passphrase', $config->getValue('ssl_passphrase'));
        
        // my data verification
        file_put_contents('log.txt', print_r($config, true));

Some of the data log.txt:

[config:protected] => Array
        (
            ...
            [accept-language] => en
            [oauth_token_secret] => 
            [oauth_consumer_key] => 
            [consumer_secret] => 
            [ssl_verify_peer] => 1
            [ssl_verify_host] => 1
            [ssl_cafile] => 
            [ssl_local_cert] => 
            [ssl_passphrase] => 
        )

That is, the data is taken from the default configuration. ;(

@erkinsergey
Copy link
Author

After testing, I changed the comment above.

@kenguest
Copy link
Member

kenguest commented Sep 7, 2018

I've added some unit tests and found that changing the config values in either way, does seem to propagate the new values correctly:

$config = ['ssl_verify_peer' => false, 'ssl_verify_host' => false];
$osm = new Services_OpenStreetMap($config);

shows both turned off

$osm = new Services_OpenStreetMap();
$osm->getConfig()->setValue('ssl_verify_host', 1);
$osm->getConfig()->setValue('ssl_verify_peer', 0);

shows verify_host on, but verify_peer off.

I checked these, like you, by adding print_r calls into Services/OpenStreetMap/Transport/HTTP.php after the setConfig calls.

Maybe you're not looking at the recent-most portion of your log file?

@erkinsergey
Copy link
Author

erkinsergey commented Sep 10, 2018

Unfortunately, while we do not understand each other. I'll try to explain again. Sorry for my English...
I downloaded and included in the project latest commit bfa04b9.
My source code:

require_once 'Services/OpenStreetMap.php';
  $config = [
    'adapter'         => 'HTTP_Request2_Adapter_Curl',
    'api_version'     => '0.6',
    'password'        => '*****',
    'server'          => 'https://my_local_osm_server',
    'User-Agent'      => 'Services_OpenStreetMap',
    'user'            => 'testuser',
    'ssl_verify_peer' => FALSE,
    'ssl_verify_host' => FALSE,
  ];

  $osm = new Services_OpenStreetMap($config);

I see that the constructor immediately makes a request /api/capabilities, and already at this point I get an error message:

Fatal error: Uncaught HTTP_Request2_ConnectionException: Curl error: SSL certificate problem: unable to get local issuer certificate in /var/www/html/osmapi/lib/HTTP/Request2/Adapter/Curl.php:155 Stack trace: #0 /var/www/html/osmapi/lib/HTTP/Request2/Adapter/Curl.php(184): HTTP_Request2_Adapter_Curl::wrapCurlError(Resource id #3) #1 /var/www/html/osmapi/lib/HTTP/Request2.php(946): HTTP_Request2_Adapter_Curl->sendRequest(Object(HTTP_Request2)) #2 /var/www/html/osmapi/lib/Services/OpenStreetMap/Transport/HTTP.php(160): HTTP_Request2->send() #3 /var/www/html/osmapi/lib/Services/OpenStreetMap/Config.php(377): Services_OpenStreetMap_Transport_HTTP->getResponse('https://s1.taga...') #4 /var/www/html/osmapi/lib/Services/OpenStreetMap/Config.php(266): Services_OpenStreetMap_Config->setServer('https://s1.taga...') #5 /var/www/html/osmapi/lib/Services/OpenStreetMap.php(94): Services_OpenStreetMap_Config->setValue(Array) #6 /var/www/html/osmapi/index.php(144): Services_OpenStreetMap->__construct(Array) #7 {main} Next Services_OpenS in /var/www/html/osmapi/lib/Services/OpenStreetMap/Config.php on line 379

I see that the Services_OpenStreetMap_Transport_HTTP :: getResponse method contains strings:

/* Issue 32 - SSL Config */
$request->setConfig('ssl_verify_peer', $config->getValue('ssl_verify_peer'));
$request->setConfig('ssl_verify_host', $config->getValue('ssl_verify_host'));
$request->setConfig('ssl_cafile', $config->getValue('ssl_cafile'));
$request->setConfig('ssl_local_cert', $config->getValue('ssl_local_cert'));
$request->setConfig('ssl_passphrase', $config->getValue('ssl_passphrase'));

// THIS IS MY INSERT
// from here are taken the data for the log file
file_put_contents('log.txt', print_r($config, TRUE));

Where $config created in the Services_OpenStreetMap_Transport_HTTP constructor as:

public function __construct()
    {
        $this->setConfig(new Services_OpenStreetMap_Config());
        $this->setRequest(new HTTP_Request2());
        $this->setLog(new Log_null(null, null));
    }

That is, as the default constructor with:

'ssl_verify_peer' => true,
'ssl_verify_host' => true,
'ssl_cafile' => null,
'ssl_local_cert' => null,
'ssl_passphrase' => null,

My log file:

Services_OpenStreetMap_Config Object ( [oauth_consumer_key:protected] => [oauth_token:protected] => [oauth_token_secret:protected] => [consumer_secret:protected] => [minVersion:protected] => [maxVersion:protected] => [timeout:protected] => [changesetMaximumElements:protected] => [waynodesMaximum:protected] => [tracepointsPerPage:protected] => [areaMaximum:protected] => [databaseStatus:protected] => [apiStatus:protected] => [gpxStatus:protected] => [config:protected] => Array ( [accept-language] => en [adapter] => HTTP_Request2_Adapter_Curl [api_version] => 0.6 [password] => ***** [passwordfile] => [server] => https://api.openstreetmap.org/ [User-Agent] => Services_OpenStreetMap [user] => [verbose] => [oauth_token] => [oauth_token_secret] => [oauth_consumer_key] => [consumer_secret] => [ssl_verify_peer] => 1 [ssl_verify_host] => 1 [ssl_cafile] => [ssl_local_cert] => [ssl_passphrase] => )  [api_version:protected] => 0.6 [server:protected] => https://api.openstreetmap.org/ [generator:protected] => Generator [transport] => Services_OpenStreetMap_Transport_HTTP Object ( [request:protected] => HTTP_Request2 Object ( [observers:protected] => Array ( )  [url:protected] => [method:protected] => GET [auth:protected] => [headers:protected] => Array ( [user-agent] => HTTP_Request2/2.3.0 (http://pear.php.net/package/http_request2) PHP/7.0.30-0ubuntu0.16.04.1 )  [config:protected] => Array ( [adapter] => HTTP_Request2_Adapter_Socket [connect_timeout] => 10 [timeout] => 0 [use_brackets] => 1 [protocol_version] => 1.1 [buffer_size] => 16384 [store_body] => 1 [local_ip] => [proxy_host] => [proxy_port] => [proxy_user] => [proxy_password] => [proxy_auth_scheme] => basic [proxy_type] => http [ssl_verify_peer] => 1 [ssl_verify_host] => 1 [ssl_cafile] => [ssl_capath] => [ssl_local_cert] => [ssl_passphrase] => [digest_compat_ie] => [follow_redirects] => [max_redirects] => 5 [strict_redirects] => )  [lastEvent:protected] => Array ( [name] => start [data] => )  [body:protected] => [postParams:protected] => Array ( )  [uploads:protected] => Array ( )  [adapter:protected] => [cookieJar:protected] => )  [config:protected] => Services_OpenStreetMap_Config Object *RECURSION* [log:protected] => Log_null Object ( [_opened] => [_id] => 3fb0374cf8cc187975359307538bfb83 [_ident] => [_priority] => 6 [_mask] => 255 [_listeners] => Array ( )  [_backtrace_depth] => 0 [_formatMap] => Array ( [%{timestamp}] => %1$s [%{ident}] => %2$s [%{priority}] => %3$s [%{message}] => %4$s [%{file}] => %5$s [%{line}] => %6$s [%{function}] => %7$s [%{class}] => %8$s [%\{] => %%{ )  )  )  [api] => Services_OpenStreetMap_API_V06 Object ( [elements:protected] => Array ( [0] => changeset [1] => node [2] => relation [3] => way )  [transport:protected] => [config:protected] => [newId:protected] => -1 )  ) Services_OpenStreetMap_Config Object ( [oauth_consumer_key:protected] => [oauth_token:protected] => [oauth_token_secret:protected] => [consumer_secret:protected] => [minVersion:protected] => [maxVersion:protected] => [timeout:protected] => [changesetMaximumElements:protected] => [waynodesMaximum:protected] => [tracepointsPerPage:protected] => [areaMaximum:protected] => [databaseStatus:protected] => [apiStatus:protected] => [gpxStatus:protected] => [config:protected] => Array ( [accept-language] => en [adapter] => HTTP_Request2_Adapter_Curl [api_version] => 0.6 [password] => ******** [passwordfile] => [server] => https://api.openstreetmap.org/ [User-Agent] => Services_OpenStreetMap [user] => [verbose] => [oauth_token] => [oauth_token_secret] => [oauth_consumer_key] => [consumer_secret] => [ssl_verify_peer] => 1 [ssl_verify_host] => 1 [ssl_cafile] => [ssl_local_cert] => [ssl_passphrase] => )  [api_version:protected] => 0.6 [server:protected] => https://api.openstreetmap.org/ [generator:protected] => Generator [transport] => Services_OpenStreetMap_Transport_HTTP Object ( [request:protected] => HTTP_Request2 Object ( [observers:protected] => Array ( )  [url:protected] => Net_URL2 Object ( [_options:Net_URL2:private] => Array ( [strict] => 1 [use_brackets] => 1 [drop_sequence] => 1 [encode_keys] => 1 [input_separator] => & [output_separator] => & )  [_scheme:Net_URL2:private] => https [_userinfo:Net_URL2:private] => [_host:Net_URL2:private] => my_osm_server [_port:Net_URL2:private] => [_path:Net_URL2:private] => /osm//api/capabilities [_query:Net_URL2:private] => [_fragment:Net_URL2:private] => )  [method:protected] => GET [auth:protected] => [headers:protected] => Array ( [user-agent] => HTTP_Request2/2.3.0 (http://pear.php.net/package/http_request2) PHP/7.0.30-0ubuntu0.16.04.1 )  [config:protected] => Array ( [adapter] => HTTP_Request2_Adapter_Socket [connect_timeout] => 10 [timeout] => 0 [use_brackets] => 1 [protocol_version] => 1.1 [buffer_size] => 16384 [store_body] => 1 [local_ip] => [proxy_host] => [proxy_port] => [proxy_user] => [proxy_password] => [proxy_auth_scheme] => basic [proxy_type] => http [ssl_verify_peer] => 1 [ssl_verify_host] => 1 [ssl_cafile] => [ssl_capath] => [ssl_local_cert] => [ssl_passphrase] => [digest_compat_ie] => [follow_redirects] => [max_redirects] => 5 [strict_redirects] => )  [lastEvent:protected] => Array ( [name] => start [data] => )  [body:protected] => [postParams:protected] => Array ( )  [uploads:protected] => Array ( )  [adapter:protected] => HTTP_Request2_Adapter_Curl Object ( [response:protected] => [eventSentHeaders:protected] => [eventReceivedHeaders:protected] => [eventSentBody:protected] => [position:protected] => 0 [lastInfo:protected] => [request:protected] => [requestBody:protected] => [contentLength:protected] => )  [cookieJar:protected] => )  [config:protected] => Services_OpenStreetMap_Config Object *RECURSION* [log:protected] => Log_null Object ( [_opened] => [_id] => e2add97a03d2c3be5215a298f680a8f9 [_ident] => [_priority] => 6 [_mask] => 255 [_listeners] => Array ( )  [_backtrace_depth] => 0 [_formatMap] => Array ( [%{timestamp}] => %1$s [%{ident}] => %2$s [%{priority}] => %3$s [%{message}] => %4$s [%{file}] => %5$s [%{line}] => %6$s [%{function}] => %7$s [%{class}] => %8$s [%\{] => %%{ )  )  )  [api] => Services_OpenStreetMap_API_V06 Object ( [elements:protected] => Array ( [0] => changeset [1] => node [2] => relation [3] => way )  [transport:protected] => [config:protected] => [newId:protected] => -1 )  ) Services_OpenStreetMap_Config Object ( [oauth_consumer_key:protected] => [oauth_token:protected] => [oauth_token_secret:protected] => [consumer_secret:protected] => [minVersion:protected] => [maxVersion:protected] => [timeout:protected] => [changesetMaximumElements:protected] => [waynodesMaximum:protected] => [tracepointsPerPage:protected] => [areaMaximum:protected] => [databaseStatus:protected] => [apiStatus:protected] => [gpxStatus:protected] => [config:protected] => Array ( [accept-language] => en [adapter] => HTTP_Request2_Adapter_Curl [api_version] => 0.6 [password] => *********** [passwordfile] => [server] => https://api.openstreetmap.org/ [User-Agent] => Services_OpenStreetMap [user] => [verbose] => [oauth_token] => [oauth_token_secret] => [oauth_consumer_key] => [consumer_secret] => [ssl_verify_peer] => 1 [ssl_verify_host] => 1 [ssl_cafile] => [ssl_local_cert] => [ssl_passphrase] => )  [api_version:protected] => 0.6 [server:protected] => https://api.openstreetmap.org/ [generator:protected] => Generator [transport] => Services_OpenStreetMap_Transport_HTTP Object ( [request:protected] => HTTP_Request2 Object ( [observers:protected] => Array ( )  [url:protected] => Net_URL2 Object ( [_options:Net_URL2:private] => Array ( [strict] => 1 [use_brackets] => 1 [drop_sequence] => 1 [encode_keys] => 1 [input_separator] => & [output_separator] => & )  [_scheme:Net_URL2:private] => https [_userinfo:Net_URL2:private] => [_host:Net_URL2:private] => my_osm_server [_port:Net_URL2:private] => [_path:Net_URL2:private] => /osm//api/capabilities [_query:Net_URL2:private] => [_fragment:Net_URL2:private] => )  [method:protected] => GET [auth:protected] => [headers:protected] => Array ( [user-agent] => HTTP_Request2/2.3.0 (http://pear.php.net/package/http_request2) PHP/7.0.30-0ubuntu0.16.04.1 )  [config:protected] => Array ( [adapter] => HTTP_Request2_Adapter_Socket [connect_timeout] => 10 [timeout] => 0 [use_brackets] => 1 [protocol_version] => 1.1 [buffer_size] => 16384 [store_body] => 1 [local_ip] => [proxy_host] => [proxy_port] => [proxy_user] => [proxy_password] => [proxy_auth_scheme] => basic [proxy_type] => http [ssl_verify_peer] => 1 [ssl_verify_host] => 1 [ssl_cafile] => [ssl_capath] => [ssl_local_cert] => [ssl_passphrase] => [digest_compat_ie] => [follow_redirects] => [max_redirects] => 5 [strict_redirects] => )  [lastEvent:protected] => Array ( [name] => start [data] => )  [body:protected] => [postParams:protected] => Array ( )  [uploads:protected] => Array ( )  [adapter:protected] => HTTP_Request2_Adapter_Curl Object ( [response:protected] => [eventSentHeaders:protected] => [eventReceivedHeaders:protected] => [eventSentBody:protected] => [position:protected] => 0 [lastInfo:protected] => [request:protected] => [requestBody:protected] => [contentLength:protected] => )  [cookieJar:protected] => )  [config:protected] => Services_OpenStreetMap_Config Object *RECURSION* [log:protected] => Log_null Object ( [_opened] => [_id] => 2a2fb09e4832eb3feb7cfad1b008b2c0 [_ident] => [_priority] => 6 [_mask] => 255 [_listeners] => Array ( )  [_backtrace_depth] => 0 [_formatMap] => Array ( [%{timestamp}] => %1$s [%{ident}] => %2$s [%{priority}] => %3$s [%{message}] => %4$s [%{file}] => %5$s [%{line}] => %6$s [%{function}] => %7$s [%{class}] => %8$s [%\{] => %%{ )  )  )  [api] => Services_OpenStreetMap_API_V06 Object ( [elements:protected] => Array ( [0] => changeset [1] => node [2] => relation [3] => way )  [transport:protected] => [config:protected] => [newId:protected] => -1 )  ) Services_OpenStreetMap_Config Object ( [oauth_consumer_key:protected] => [oauth_token:protected] => [oauth_token_secret:protected] => [consumer_secret:protected] => [minVersion:protected] => [maxVersion:protected] => [timeout:protected] => [changesetMaximumElements:protected] => [waynodesMaximum:protected] => [tracepointsPerPage:protected] => [areaMaximum:protected] => [databaseStatus:protected] => [apiStatus:protected] => [gpxStatus:protected] => [config:protected] => Array ( [accept-language] => en [adapter] => HTTP_Request2_Adapter_Curl [api_version] => 0.6 [password] => ************ [passwordfile] => [server] => https://api.openstreetmap.org/ [User-Agent] => Services_OpenStreetMap [user] => [verbose] => [oauth_token] => [oauth_token_secret] => [oauth_consumer_key] => [consumer_secret] => [ssl_verify_peer] => 1 [ssl_verify_host] => 1 [ssl_cafile] => [ssl_local_cert] => [ssl_passphrase] => )  [api_version:protected] => 0.6 [server:protected] => https://api.openstreetmap.org/ [generator:protected] => Generator [transport] => Services_OpenStreetMap_Transport_HTTP Object ( [request:protected] => HTTP_Request2 Object ( [observers:protected] => Array ( )  [url:protected] => Net_URL2 Object ( [_options:Net_URL2:private] => Array ( [strict] => 1 [use_brackets] => 1 [drop_sequence] => 1 [encode_keys] => 1 [input_separator] => & [output_separator] => & )  [_scheme:Net_URL2:private] => https [_userinfo:Net_URL2:private] => [_host:Net_URL2:private] => my_osm_server [_port:Net_URL2:private] => [_path:Net_URL2:private] => /osm//api/capabilities [_query:Net_URL2:private] => [_fragment:Net_URL2:private] => )  [method:protected] => GET [auth:protected] => [headers:protected] => Array ( [user-agent] => HTTP_Request2/2.3.0 (http://pear.php.net/package/http_request2) PHP/7.0.30-0ubuntu0.16.04.1 )  [config:protected] => Array ( [adapter] => HTTP_Request2_Adapter_Socket [connect_timeout] => 10 [timeout] => 0 [use_brackets] => 1 [protocol_version] => 1.1 [buffer_size] => 16384 [store_body] => 1 [local_ip] => [proxy_host] => [proxy_port] => [proxy_user] => [proxy_password] => [proxy_auth_scheme] => basic [proxy_type] => http [ssl_verify_peer] => 1 [ssl_verify_host] => 1 [ssl_cafile] => [ssl_capath] => [ssl_local_cert] => [ssl_passphrase] => [digest_compat_ie] => [follow_redirects] => [max_redirects] => 5 [strict_redirects] => )  [lastEvent:protected] => Array ( [name] => start [data] => )  [body:protected] => [postParams:protected] => Array ( )  [uploads:protected] => Array ( )  [adapter:protected] => HTTP_Request2_Adapter_Curl Object ( [response:protected] => [eventSentHeaders:protected] => [eventReceivedHeaders:protected] => [eventSentBody:protected] => [position:protected] => 0 [lastInfo:protected] => [request:protected] => [requestBody:protected] => [contentLength:protected] => )  [cookieJar:protected] => )  [config:protected] => Services_OpenStreetMap_Config Object *RECURSION* [log:protected] => Log_null Object ( [_opened] => [_id] => 3ee6e47d27cc8d823d88fa0783cacbf0 [_ident] => [_priority] => 6 [_mask] => 255 [_listeners] => Array ( )  [_backtrace_depth] => 0 [_formatMap] => Array ( [%{timestamp}] => %1$s [%{ident}] => %2$s [%{priority}] => %3$s [%{message}] => %4$s [%{file}] => %5$s [%{line}] => %6$s [%{function}] => %7$s [%{class}] => %8$s [%\{] => %%{ )  )  )  [api] => Services_OpenStreetMap_API_V06 Object ( [elements:protected] => Array ( [0] => changeset [1] => node [2] => relation [3] => way )  [transport:protected] => [config:protected] => [newId:protected] => -1 )  )

I can not avoid mistakes, because my settings do not affect the result.

@kenguest
Copy link
Member

Hi @erkinsergey, your extra details and trace of what was wrong did help.

I adjusted the code so that the library only requests capabilities information after all other configuration settings have been applied, especially settings that would need to be changed to permit access to that API endpoint.

While I don't have a test server to connect against to check that my recent changes from tonight will 100% fix this issue, I think it is fixed now.

Would you please test that the changes should now work for you?

Thanks.

@erkinsergey
Copy link
Author

Yes, now everything works correctly.
Thank you for your work.

@kenguest
Copy link
Member

You're very welcome - am happy to get this bug fixed :-)

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

No branches or pull requests

2 participants