SOAP and SSL in PHP - php

I've got a problem with SOAP and SSL.
When I create a SOAP client with normal wsdl (http), it runs ok. But when I connect with a SSL wsdl (https) it's got problem.
I tried the same code to connect to the https wsdl at my localhost, it's OK. But it doesn't work if that code run under my server.
My server is running Centos, PHP 5.3.8. Can you show me how to config PHP to run SOAP with SSL. Below is my current code:
<?php
// where BKTransactionAPI extends SoapClient...
$bk = new BKTransactionAPI("https://www.baokim.vn/services/transaction_api/init?wsdl");
$info_topup = new TopupToMerchantRequest();
$info_topup->card_id = $service;
$info_topup->pin_field = $pin;
$info_topup->transaction_id = $transaction_id;
$result = new TopupToMerchantResponse();
$result = $bk->DoTopupToMerchant($info_topup);
?>

Related

Is Endpoint with custom port does not supported by Guzzle?

I am trying to hit API endpoint from my Laravel 5.8.* project.
I am using Guzzle 6.0 with PHP version 7.1.3.
When I run my project in local machine, I get the API response successfully.
But after uploading the project to liver server, I could not get the API response.
I get the response "cURL error 7: Failed to connect to xx.xx.xx.xx port 3333: Connection refused (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)".
The code that I use is as follows.
$client = new GuzzleHttp\Client();
$res = $client->request('GET', 'http://xx.xx.xx.xx:3333/api/getrecords', [
'tbl' => ['user', 'activity']
]);
echo $res->getMessage();
The same code is working perfectly in local machine but not in live server.
My Server is Linux server.
Did you have any proxy configured in your server? If so, try to set a proxy in your guzzle request: Guzzle proxy docs
Basically, you have to set an array with the proxy.
$client->request('GET', '/', ['proxy' => 'tcp://localhost:8125']);
you are trying to make request using port 3333. This port 3333 needs to be open in your machine only then you will be able to make request from this port.

How Can I enforce TLS 1.2 when using nusoap?

I am using nusoap to connect Eway legacy Api. Suddenly Eway enforce TLS 1.2 on their side. So I have set open ssl 1.0 and TLS 1.2 in my server.
From that server I am connecting Eway rapid api which is working fine. As both Legacy and Rapid api needs TLS 1.2 and rapid is working fine that means our server setup i ok. But this legacy api connection is not working.
I need to enforce TLS 1.2 by code when I am connecting Eway legacy API using nusoap.
Code Example -
<?php
$client = new nusoap_client("https://www.eway.com.au/gateway/rebill/manageRebill.asmx");
$client->namespaces['man'] = 'http://www.eway.com.au/gateway/rebill/manageRebill';
$headers = "<man:eWAYHeader><man:eWAYCustomerID>****</man:eWAYCustomerID><man:Username>****</man:Username><man:Password>****</man:Password></man:eWAYHeader>";
$client->setHeaders($headers);
$requestbody = array();
$soapactionUrl = 'http://www.eway.com.au/gateway/rebill/manageRebill/';
$requestbody['man:RebillCustomerID'] = $eway_rebill_customer_id;
$requestbody['man:RebillID'] = $eway_rebill_id;
$soapaction = 'QueryRebillEvent';
$client = $this->_creatEwayRebillRequestHeader();
$result = $client->call('man:'.$soapaction, $requestbody, '', $soapactionUrl.$soapaction,true);
$err_msg = $client->getError();
echo $err_msg;
?>
The error massage what I am getting is -
wsdl error: Getting https://www.eway.com.au/gateway/rebill/manageRebill.asmx - HTTP ERROR: Unsupported HTTP response status 403 Forbidden (soapclient->response has contents of the response)
I am sure about my credentials, also eway support team also told me to enforce TLS 1.2 to solve the issue. But I don't know how to enforce TLS 1.2 in the nusoap library.
It appears you can tell NuSOAP to use CURL. So modifying the setup slightly should do the trick
$client = new nusoap_client("https://www.eway.com.au/gateway/rebill/manageRebill.asmx");
$client->setUseCURL(true);
$client->setCurlOption(CURLOPT_SSLVERSION, '6'); // TLS 1.2
I don't have a way to test this, but I based it on the NuSOAP class found in GitHub. This works for CURL so it should work here.

Elasticsearch-PHP application not working

I have an Elasticsearch-PHP application and it works locally. However, when I put it on an RHEL 6 server that only supports PHP 5.3, it does not work. When I go to the console, I get GET http://xx.x.xxx.xxx:xxxx/init.php 500 (Internal Server Error). The problem I think might be from a connection issue in the init.php. Here's the code inside init.php:
<?php
require_once 'vendor/autoload.php';
use Elasticsearch\ClientBuilder;
/*Build connection*/
$hosts = [
'xx.x.xxx.xxx', // Port
];
$es = ClientBuilder::create() // Instantiate a new ClientBuilder
->setHosts($hosts) // Set the hosts
->build(); // Build the client object
?>
This works perfect locally. I don't know why it doesn't work when I transfer it to the server.
In PHP 5.3.10 the short array syntax was not available, you can simply fix your code by using array() instead:
$hosts = array(
'xx.x.xxx.xxx', // Port
);

php soap client returns 404, when calling WSDL methods from HTTPS environment

I am running a php soap client example under https environment of my Zend Server.
I am able to list the methods in the WSDL. But when i make a call to one of those methods, i receive a 404 HTTP not found error. I also tried saving the WSDL to my local folder.
Interestingly, the same example was running successfully from the CLI (like: C:/> php abc.php). Not sure why it is failing in the browser (like: https://example.com:10022/abc.php).
This is my code:
<?php
ini_set("soap.wsdl_cache_enabled", "0");
try {
$client = new SoapClient('country.wsdl');
//$client = new SoapClient('http://www.webservicex.net/country.asmx?WSDL');
//$functions = $client->__getFunctions (); var_dump ($functions); // works
$params = array('CountryName'=> 'Australia');
$result = $client->GetISOCountryCodeByCountyName($params);
echo $result->GetISOCountryCodeByCountyNameResult;
}
catch(SoapFault $fault) {
echo $fault->getMessage();
}
?>
Note:
I have openssl enabled.
My https url is configured as a Zend server Virtual Host, running on port 10022.
My https url is not reachable from outside world (does this make any difference?)

Client side ssl certificate using Zend_Http_Client

i've been trying to set up a secure communication using client side certificate between my client application and my server application.
I've set up a the configuration in my apache web server and both in my browser just to make sure that it works and it does.
i'm using zend framework 1.12, and according to the documentation on Zend website
the following example should work:
$config = array( 'sslcert' => 'path/to/ca.crt', 'sslpassphrase' => 'p4ssw0rd');
$adapter = new Zend_Http_Adapter_Socket();
$adapter->setConfig($config);
$http_client = new Zend_Http_Client();
$http_client->setAdapter($adapter);
$http_client->setUri('https://somewhere.overtherainbow.com:1337/bluebird');
$http_client->request();
but everytime i just get the same exception
Unable to Connect to ssl://somewhere.overtherainbow.com:1337
There is no doubt that i'm using the right certificate and passphrase and there is access to the remote machine
so where could be the downfall ?
Sounds like a simple firewall issue - login to the server and stop iptables and then see if it connects. Or add an exception to the clients IP to access mysql. Also check :1337 is open

Categories