File_Get_Contents(): Ssl Operation Failed With Code 1, Failed to Enable Crypto

file_get_contents(): SSL operation failed with code 1, Failed to enable crypto

This was an enormously helpful link to find:

http://php.net/manual/en/migration56.openssl.php

An official document describing the changes made to open ssl in PHP 5.6
From here I learned of one more parameter I should have set to false: "verify_peer_name"=>false

Note: This has very significant security implications. Disabling verification potentially permits a MITM attacker to use an invalid certificate to eavesdrop on the requests. While it may be useful to do this in local development, other approaches should be used in production.

So my working code looks like this:

<?php
$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);

$response = file_get_contents("https://maps.co.weber.ut.us/arcgis/rest/services/SDE_composite_locator/GeocodeServer/findAddressCandidates?Street=&SingleLine=3042+N+1050+W&outFields=*&outSR=102100&searchExtent=&f=json", false, stream_context_create($arrContextOptions));

echo $response; ?>

PHP: file_get_contents(): SSL operation failed with code 1

This happens when your client can't establish a version. That error happens when you have an older PHP-Version and a newer openssl version. In newer version you have some braking changes and you get that error.

https://github.com/dask/gcsfs/issues/246

what you can try is to downgrade or upgrade your openssl version. That bug should appear in version 1.1.1e. So check your openssl version first and that take a look if you can upgrade it.

OpenSSL.SSL.Error: [('SSL routines', 'ssl3_read_n', 'unexpected eof while reading')] when updating / searching / installing conda packages

Here is another helpfull post for yum.

file_get_contents() ssl operation failed from my own server only

I found the reason why this is not working.

It was because of Cloudflare SSL/TLS encryption mode. My selected option was Full strict.

Cloudflare

As seen from the image the request has to hit Cloudflare request first, then Cloudflare forwards it to the origin server. However, I added my IP address and hostname to /etc/hosts file, that is why the request was not going out from my network and it causes SSL verification problems.

file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:0A000126:SSL routines::unexpected eof while reading

This is likely due to this issue: https://bugs.php.net/bug.php?id=79589

An IIS or equivalent non-compliant daemon is not following the SSL specification and OpenSSL is raising an error because of this. PHP does not provide any method to work around it and since you cannot pass the necessary SSL_OP_IGNORE_UNEXPECTED_EOF flag to OpenSSL the connection fails with an error.

For reference:

https://www.openssl.org/docs/manmaster/man3/SSL_CTX_set_options.html

SSL_OP_IGNORE_UNEXPECTED_EOF

Some TLS implementations do not send the mandatory close_notify alert on shutdown. If the application tries to wait for the

close_notify alert but the peer closes the connection without sending
it, an error is generated. When this option is enabled the peer does
not need to send the close_notify alert and a closed connection will
be treated as if the close_notify alert was received.

Simple html dom - file_get_contents(): Failed to enable crypto

You should install OpenSSL for PHP correctly. You should also verify that ssl.cafile and openssl.capath are set.

PS: But really, you should paste your code.



Related Topics



Leave a reply



Submit