<error>[an error occurred while processing this directive]</error>[2014-04-29 15:56:53 -0500] warn [xml-api] The system could not parse the certificate because o
f an error: A critical error occurred while parsing the ASN.1 data: Cpanel::CPAN::Encoding::BER: corrupt data? data appears truncated
at /usr/local/cpanel/Cpanel/SSL/Utils.pm line 724
at /usr/local/cpanel/Cpanel/SSLInfo.pm line 72
This is my call:
my $status = make_request($auth, "installssl?user=$user&domain=$domain&cert=#cert&key=#key&ip=$dedicated_ip");
sub make_request {
my $auth = shift;
my $params = shift;
my $url = "https://127.0.0.1:2087/xml-api/" . $params;
my $ua = LWP::UserAgent->new();
my $request = HTTP::Request->new( POST => $url );
$request->header( Authorization => $auth );
my $response = $ua->request($request);
my $data = $response->content;
my $xml = XML::Simple->new;
$data = $xml->XMLin($data);
if ( $data->{'status'} ) {
return $data;
} else {
print "[!] Cpanel API returned an error: " . $data->{'statusmsg'} . "\n";
exit;
}
}
Statusmsg: [!] Cpanel API returned an error: The certificate appears to be invalid.
This issue was caused by the XML-API support of InstallSSL being deprecated. I have resolved this by using API2 through XML-API:
sub make_api2_request {
my $auth = shift;
my $user = shift;
my $domain = shift;
my $cert = shift;
my $key = shift;
my $bundle = shift;
my $url = "https://127.0.0.1:2087/xml-api/cpanel";
my $ua = LWP::UserAgent->new();
my $response = $ua->request(
POST $url,
Authorization => $auth,
Content_Type => 'application/x-www-form-urlencoded',
Content => [
'crt' => $cert,
'domain' => $domain,
'key' => $key,
'cpanel_xmlapi_user' => $user,
'cpanel_xmlapi_module' => 'SSL',
'cpanel_xmlapi_func' => 'installssl',
'cpanel_xmlapi_apiversion' => 2,
],
);
my $data = $response->content;
$data = XMLin($data);
if ( $data->{'error'} ) {
$data->{'error'} =~ s/[^[:ascii:]]+//g;
print "[!] " . $data->{'error'} . "\n";
return 0;
}
else {
return 1;
}
}
Sounds like you're missing some PERL dependencies. Run through this list to start, once you're done, go into WHM's SSL Storage Manager, delete any unused self-signed certs, regenerate (or run /usr/local/cpanel/scripts/gencrt from the CLI) and then see if any errors were thrown during the cert generation process. Good luck!
/scripts/perlinstaller Config::Crontab
/scripts/perlinstaller Date::Simple
/scripts/perlinstaller Digest::MD5
/scripts/perlinstaller HTTP::Request::Common
/scripts/perlinstaller IO::Handle
/scripts/perlinstaller IPC::Open3
/scripts/perlinstaller JSON::Syck
/scripts/perlinstaller LWP::UserAgent
/scripts/perlinstaller Mozilla::CA
/scripts/perlinstaller Template
/scripts/perlinstaller XML::Simple
/scripts/perlinstaller YAML::Syck
Related
Do you know how via a web page usind the IPB APi allowinfg to doynload a file. Until now I can the see the files but it's not possible to download it. My result myfile:zip.3313213213
Thank you
Below my approach :
public function getFilesInformations(int $id)
{
$curl = curl_init( $this->communityUrl . 'api/downloads/files?id=' . $id . '&download&perPage=300');
$array = [
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_USERPWD => "{$this->apiKey}:",
CURLOPT_USERAGENT => "MyUserAgent/1.0"
];
curl_setopt_array( $curl, $array);
$response = curl_exec( $curl );
return $response;
}
My other function to get the file info
public function insertFilesInformations(int $id): bool
{
$json_result = $this->getFilesInformations($id);
$result = json_decode($json_result, true);
$i = 1;
if (is_array($result)) {
foreach ($result as $value) {
if (is_array($value)) {
foreach ($value as $file) {
$download = $file['files'][0]['url'];
var_dum($download);
}
}
}
}
return $download
}
the result is something like that : https://localhost/forum/uploads/monthly_2019_12/myfile_zip.a1fb44a2cb001aa6f3596ec4c6dfba16
I'm not an expert in API development or using signed messages in PHP.
I have however tried to get the GATE.IO v4 API working in my PHP implementation but keep getting "Signature mismatch". I have followed the API documentation for CREATE ORDER available at Gate.io's website here: https://www.gate.tv/docs/developers/apiv4/#create-an-order
I have managed to get the /spot/accounts working, so I know that the key and secret are correct.
Based on the code below I seem to missing something. Probably a tiny error but those are the hardest, right?
Does anyone have any idea what could be the cause of this issue? Would really appreciate your help after having spent 8+ hours trying to get this to work.
<?php
$accessToken = ''; // Access token for OAuth/Bearer authentication
$key = "XXXXXXXXXXXXXXXXXXXXXXX";
$secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$username = ''; // Username for HTTP basic authentication
$password = ''; // Password for HTTP basic authentication
$host = 'https://api.gateio.ws/api/v4'; // The host
$userAgent = 'OpenAPI-Generator/5.26.0/PHP'; // User agent of the HTTP request, set to "OpenAPI-Generator/{version}/PHP" by default
$sResourcePath = "/spot/orders";
$sMethod = "POST"; // POST or GET
$aPayload['currency_pair'] = "DOT_USDT";
$aPayload['price'] = "6.330033";
$aPayload['account'] = "spot";
$aPayload['side'] = "buy";
$aPayload['amount'] = "1";
$aPayload['time_in_force'] = "gtc";
$sBody = json_encode($aPayload);
$aQueryParams = $aPayload;
$aFullPath = parse_url($host . $sResourcePath);
$fullPath = $aFullPath['path'];
$timestamp = time();
$hashedPayload = hash("sha512", ($payload !== null) ? $payload : "");
$fmt = "%s\n%s\n%s\n%s\n%s";
$sQuery = http_build_query($aQueryParams, false);
$signatureString = sprintf($fmt, $sMethod, $fullPath, $sQuery, $hashedPayload, $timestamp);
$signature = hash_hmac("sha512", $signatureString, $secret);
$aSignHeaders = array(
"KEY" => $key,
"SIGN" => $signature,
"Timestamp" => $timestamp);
$aHeaders[] = "KEY: " . $aSignHeaders['KEY'];
$aHeaders[] = "SIGN: " . $aSignHeaders['SIGN'];
$aHeaders[] = "Timestamp: " . $aSignHeaders['Timestamp'];
$aExtraParams['sHttpHeaders'] = $aHeaders;
if ($sMethod == "POST")
{
$sParams = "?" . http_build_query($aQueryParams, false);
}
else
{
$sQuery = "";
}
$sSubmitUrl = $host . $sResourcePath . $sParams;
$sPage = CURL::doRequest($sMethod, $sSubmitUrl, $sParams, $aExtraParams);
$aPage = json_decode($sPage, true);
if ($aPage)
{
$iPage = count($aPage);
}
echo "<pre>";
print_r($aPage);
echo "</pre>";
?>
based on that example request, you should be doing something like this
//path & urls
$host = 'https://api.gateio.ws';
$prefix = '/api/v4';
$path = '/spot/orders';
$fullPath = "$prefix$path";
$method = 'POST';
//your API keys
$api = [
'secret' => 'xxxx'
];
// Your actual data you can easily modify
$payload = [
'currency_pair' => 'DOT_USDT',
'price' => '6.330033',
'account' => 'spot',
'side' => 'buy',
'amount' => '1',
'time_in_force' => 'gtc'
];
//Convert your data to JSON FORMAT
$jsonPayload = json_encode( $payload );
//Hash your JSON DATA
$hashJsonPayload = hash('sha512', $jsonPayload);
$timeStamp = time();
// dunno if this is required
$queryParam = '';
//Create your signature string
$signString="$method\n$fullPath\n$queryParam\n$hashJsonPayload\n$timeStamp";
//Generate the signature
$signHash = hash_hmac('sha512', $signString, $api['secret']);
// Your Actual headers
$headers = [
'Content-Type: application/json',
'Timestamp: '.$timeStamp,
'Key: '.$api['secret'],
'SIGN: '.$signHash
];
Example request using php curl
$ch = curl_init( "$host$fullPath" ); // URL to POST https://api.gateio.ws/api/v4/spot/orders
curl_setopt( $ch, CURLOPT_POSTFIELDS, $jsonPayload ); // set json payload as body here
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers ); //define header here
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$result = curl_exec($ch);
curl_close($ch)
echo '<pre>', print_r($result, 1), '</pre>';
I'm calling the API to get a list of shipments but I can't seem to page through the results.
The API call is successful with only one query parameter but when I call it with two query parameters, I get the error "The signature is invalid. Verify and try again". I'm including my test code below.
<?php
function sign($method, $url, $data, $consumerSecret, $tokenSecret)
{
$url = urlEncodeAsZend($url);
$data = urlEncodeAsZend(http_build_query($data, '', '&'));
$data = implode('&', [$method, $url, $data]);
$secret = implode('&', [$consumerSecret, $tokenSecret]);
return base64_encode(hash_hmac('sha1', $data, $secret, true));
}
function urlEncodeAsZend($value)
{
$encoded = rawurlencode($value);
$encoded = str_replace('%7E', '~', $encoded);
return $encoded;
}
// REPLACE WITH YOUR ACTUAL DATA OBTAINED WHILE CREATING NEW INTEGRATION
$consumerKey = 'htj8ze6ntr0mz1s4hjxrqeicia8rxgt4';
$consumerSecret = 'djjzdwfgbbr7ganlkv01qr6p3l7ptvfe';
$accessToken = '60o0mfrvqnjvin7tjuqsv37arijrqe9e';
$accessTokenSecret = 'caq9wfdx99zaygwgbhw91i9imj89p4zb';
$method = 'GET';
/* test 1 PASS */
//$url = 'http://localhost/rest/V1/shipments/';
//$qs = ['searchCriteria'=>'all'];
/* test 2 PASS */
//$url = 'http://localhost/rest/V1/shipments/';
//$qs = ['searchCriteria[pageSize]'=>'10'];
/* test 3 FAIL "The signature is invalid. Verify and try again" */
$url = 'http://localhost/rest/V1/shipments/';
$qs = ['searchCriteria[pageSize]'=>'10', 'searchCriteria[currentPage]'=>'1'];
$data = [
'oauth_consumer_key' => $consumerKey,
'oauth_nonce' => md5(uniqid(rand(), true)),
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_timestamp' => time(),
'oauth_token' => $accessToken,
'oauth_version' => '1.0',
];
$data = array_merge($data, $qs);
$data['oauth_signature'] = sign($method, $url, $data, $consumerSecret, $accessTokenSecret);
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url .'?' .http_build_query($qs),
CURLOPT_HTTPHEADER => [
'Authorization: OAuth ' . http_build_query($data, '', ',')
]
]);
$result = curl_exec($curl);
curl_close($curl);
echo($result);
The code includes three tests.
If I uncomment test 1 and comment test 2 and 3, the code works properly and I get a list of shipments.
If I uncomment test 2 and comment test 1 and 3, the code works properly and I get a list of shipments.
If I run the code as is, I get the the message "The signature is invalid. Verify and try again."
I'm running Magento ver. 2.3.2
The trick is to sort the parameters. I have some client code anyone is interested.
<?php
function sign($method, $url, $data, $consumerSecret, $tokenSecret)
{
$url = urlEncodeAsZend($url);
$data = urlEncodeAsZend(http_build_query($data, '', '&'));
$data = implode('&', [$method, $url, $data]);
$secret = implode('&', [$consumerSecret, $tokenSecret]);
return base64_encode(hash_hmac('sha1', $data, $secret, true));
}
function urlEncodeAsZend($value)
{
$encoded = rawurlencode($value);
$encoded = str_replace('%7E', '~', $encoded);
return $encoded;
}
function recursive_sort(&$array) {
foreach ($array as &$value) {
if (is_array($value)) recursive_sort($value);
}
return ksort($array);
}
// REPLACE WITH YOUR ACTUAL DATA OBTAINED WHILE CREATING NEW INTEGRATION
$consumerKey = 'htj8ze6ntr0mz1s4hjxrqeicia8rxgt4';
$consumerSecret = 'djjzdwfgbbr7ganlkv01qr6p3l7ptvfe';
$accessToken = '60o0mfrvqnjvin7tjuqsv37arijrqe9e';
$accessTokenSecret = 'caq9wfdx99zaygwgbhw91i9imj89p4zb';
$method = 'GET';
/* test 1 PASS */
//$url = 'http://localhost/rest/V1/shipments/';
//$qs = ['searchCriteria'=>'all'];
/* test 2 PASS */
//$url = 'http://localhost/rest/V1/shipments/';
//$qs = ['searchCriteria[pageSize]'=>'10'];
/* test 3 FAIL "The signature is invalid. Verify and try again" */
$url = 'http://localhost/rest/V1/shipments/';
$qs = ['searchCriteria'=>['pageSize'=>10,'currentPage'=>1]];
$data = [
'oauth_consumer_key' => $consumerKey,
'oauth_nonce' => md5(uniqid(rand(), true)),
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_timestamp' => time(),
'oauth_token' => $accessToken,
'oauth_version' => '1.0',
];
$data = array_merge($data, $qs);
recursive_sort($data);
$data['oauth_signature'] = sign($method, $url, $data, $consumerSecret, $accessTokenSecret);
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url .'?' .http_build_query($qs),
CURLOPT_HTTPHEADER => [
'Authorization: OAuth ' . http_build_query($data, '', ',')
]
]);
$result = curl_exec($curl);
curl_close($curl);
echo($result);
Though this question is old, I want to post the answer for future cases.
The code in the question is good, and it helped me a lot.
It is needed to sort parameters by key. Also, please consider that the searchCriteria is a multidimensional array. So, the array must be sorted by key recursively.
This is the code I have right now:
public static function listProducts() {
require_once('inc/config/config.php');
try {
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
$opt = array('resource' => 'products', 'display' => 'full');
$xml = $webService->get($opt);
$resources = $xml->products->children();
}
catch (PrestaShopWebserviceException $e) {
$trace = $e->getTrace();
if($trace[0]['args'][0] = 404) echo "BAD ID";
else if ($trace[0]['args'][0] = 401) echo "BAD AUTH KEY";
else echo 'OTHER ERROR';
}
$output = json_encode($resources, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
echo $output;
}
How can I output specific resources/details about my products?
Right now this outputs everything.
Thank you!
I can suggest you to use webservices documentation for 1.5 version, in 1.6 lack of details.
$opt = array(
'resource' =>'customers',
'display' => '[birthday]',
'filter[firstname]' => '[John]',
'filter[lastname]' => '[DOE]'
);
http://doc.prestashop.com/display/PS15/Chapter+8+-+Advanced+Use#Chapter8-AdvancedUse-SortingFilters
After the update from API 1 to 1.1 my code doesn't show any results anymore.
On this forum I found a new code (below) for user_timeline results.
Change te link to https://api.twitter.com/1.1/search/tweets.json?q=test, results in the message: Could not authenticate you. What do I wrong?
function buildBaseString($baseURI, $method, $params) {
$r = array();
ksort($params);
foreach($params as $key=>$value){
$r[] = "$key=" . rawurlencode($value);
}
return $method."&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $r));
}
function buildAuthorizationHeader($oauth) {
$r = 'Authorization: OAuth ';
$values = array();
foreach($oauth as $key=>$value)
$values[] = "$key=\"" . rawurlencode($value) . "\"";
$r .= implode(', ', $values);
return $r;
}
$url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
$oauth_access_token = "YOURVALUE";
$oauth_access_token_secret = "YOURVALUE";
$consumer_key = "YOURVALUE";
$consumer_secret = "YOURVALUE";
$oauth = array( 'oauth_consumer_key' => $consumer_key,
'oauth_nonce' => time(),
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_token' => $oauth_access_token,
'oauth_timestamp' => time(),
'oauth_version' => '1.0');
$base_info = buildBaseString($url, 'GET', $oauth);
$composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
$oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
$oauth['oauth_signature'] = $oauth_signature;
// Make Requests
$header = array(buildAuthorizationHeader($oauth), 'Expect:');
$options = array( CURLOPT_HTTPHEADER => $header,
//CURLOPT_POSTFIELDS => $postfields,
CURLOPT_HEADER => false,
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false);
$feed = curl_init();
curl_setopt_array($feed, $options);
$json = curl_exec($feed);
curl_close($feed);
$twitter_data = json_decode($json);
You need to provide auth data. look at this page page. it says Authentication required. Using the OAuth tool, select your app and generate signature to properly call the resource.