Skip to content

Instantly share code, notes, and snippets.

@piotr-zuralski
Last active November 1, 2021 22:49
Show Gist options
  • Save piotr-zuralski/c4e63a2e1d74efc9ccc4e81b4e7232e3 to your computer and use it in GitHub Desktop.
Save piotr-zuralski/c4e63a2e1d74efc9ccc4e81b4e7232e3 to your computer and use it in GitHub Desktop.
curl_https.php
wget "https://gist.github.com/piotr-zuralski/c4e63a2e1d74efc9ccc4e81b4e7232e3/raw/curl_https-no-ssl_verifyhost.php" -O curl_https-no-ssl_verifyhost.php
wget "https://gist.github.com/piotr-zuralski/c4e63a2e1d74efc9ccc4e81b4e7232e3/raw/curl_https-no-ssl_verifypeer-no_ssl_verifyhost.php" -O curl_https-no-ssl_verifypeer-no_ssl_verifyhost.php
wget "https://gist.github.com/piotr-zuralski/c4e63a2e1d74efc9ccc4e81b4e7232e3/raw/curl_https-no-ssl_verifypeer.php" -O curl_https-no-ssl_verifypeer.php
wget "https://gist.github.com/piotr-zuralski/c4e63a2e1d74efc9ccc4e81b4e7232e3/raw/curl_https-ssl_verifypeer-ssl_verifyhost.php" -O curl_https-ssl_verifypeer-ssl_verifyhost.php
wget "https://gist.github.com/piotr-zuralski/c4e63a2e1d74efc9ccc4e81b4e7232e3/raw/curl_https.php" -O curl_https.php
wget "https://gist.github.com/piotr-zuralski/c4e63a2e1d74efc9ccc4e81b4e7232e3/raw/file_get_contents-https.php" -O file_get_contents-https.php
wget "https://gist.github.com/piotr-zuralski/c4e63a2e1d74efc9ccc4e81b4e7232e3/raw/openssl-verify.php" -O openssl-verify.php
<?php
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://api.wordpress.org/secret-key/1.1/salt/',
CURLOPT_ENCODING => '',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_HEADER => true,
CURLOPT_CERTINFO => true,
CURLOPT_VERBOSE => true,
]);
echo '<pre>';
var_export([
'result' => curl_exec($ch),
'info ' => curl_getinfo($ch),
'errno ' => curl_errno($ch),
'error ' => curl_error($ch),
]);
curl_close($ch);
<?php
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://api.wordpress.org/secret-key/1.1/salt/',
CURLOPT_ENCODING => '',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_HEADER => true,
CURLOPT_CERTINFO => true,
CURLOPT_VERBOSE => true,
]);
echo '<pre>';
var_export([
'result' => curl_exec($ch),
'info ' => curl_getinfo($ch),
'errno ' => curl_errno($ch),
'error ' => curl_error($ch),
]);
curl_close($ch);
<?php
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://api.wordpress.org/secret-key/1.1/salt/',
CURLOPT_ENCODING => '',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => true,
CURLOPT_HEADER => true,
CURLOPT_CERTINFO => true,
CURLOPT_VERBOSE => true,
]);
echo '<pre>';
var_export([
'result' => curl_exec($ch),
'info ' => curl_getinfo($ch),
'errno ' => curl_errno($ch),
'error ' => curl_error($ch),
]);
curl_close($ch);
<?php
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://api.wordpress.org/secret-key/1.1/salt/',
CURLOPT_ENCODING => '',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => true,
CURLOPT_HEADER => true,
CURLOPT_CERTINFO => true,
CURLOPT_VERBOSE => true,
]);
echo '<pre>';
var_export([
'result' => curl_exec($ch),
'info ' => curl_getinfo($ch),
'errno ' => curl_errno($ch),
'error ' => curl_error($ch),
]);
curl_close($ch);
<?php
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://api.wordpress.org/secret-key/1.1/salt/',
CURLOPT_ENCODING => '',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HEADER => true,
CURLOPT_CERTINFO => true,
CURLOPT_VERBOSE => true,
]);
echo '<pre>';
var_export([
'result' => curl_exec($ch),
'info ' => curl_getinfo($ch),
'errno ' => curl_errno($ch),
'error ' => curl_error($ch),
]);
curl_close($ch);
<?php
$opts = [
'http' => [
'method' => 'GET',
'header' => '',
],
];
$context = stream_context_create($opts);
echo '<pre>';
var_export([
'file_get_contents' => file_get_contents('https://api.wordpress.org/secret-key/1.1/salt/', false, $context),
]);
<?php
$data = 'test data';
$private_key_res = openssl_pkey_new(array(
"private_key_bits" => 2048,
"private_key_type" => OPENSSL_KEYTYPE_RSA,
));
$details = openssl_pkey_get_details($private_key_res);
$public_key_res = openssl_pkey_get_public($details['key']);
openssl_sign($data, $signature, $private_key_res, "sha256WithRSAEncryption");
$ok = openssl_verify($data, $signature, $public_key_res, OPENSSL_ALGO_SHA256);
if ($ok == 1) {
echo "valid";
} elseif ($ok == 0) {
echo "invalid";
} else {
echo "error: ".openssl_error_string();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment