Laravel 5.7: openssl_cipher_iv_length(): Unknown cipher algorithm - encryption

I am developing an app in Laravel Framework 5.7.13.
I have a class called
<?php
namespace App\Library;
class Crypto{
private $cipher;
private $cstrong;
private $keylen;
private $key;
public function __Crypto(){
$this->cipher= Config::get('cipher');
$this->cstrong = true;
$this->keylen = 5;
$this->key = bin2hex(openssl_random_pseudo_bytes($keylen, $cstrong));
}
public function opensslEncrypt($value){
$ivlen = openssl_cipher_iv_length($this->cipher);
$iv = openssl_random_pseudo_bytes($ivlen);
$ciphertext_raw = openssl_encrypt($value, $this->cipher, $this->key, $options=OPENSSL_RAW_DATA, $iv);
$hmac = hash_hmac('sha256', $ciphertext_raw, $this->key, $as_binary=true);
$ciphertext = base64_encode( $iv.$hmac.$ciphertext_raw );
return $ciphertext ;
}
}
Now in my controller I did:
$crypto = new Crypto();
$encryptedValue = $crypto->opensslEncrypt($orderId);
In my Config\app.php
'cipher' => 'AES-256-CBC'
But when I run my app, I get
ErrorException (E_WARNING)
openssl_cipher_iv_length(): Unknown cipher algorithm
How to resolve this?
I tried to comment the cipher line in the Config\app.php, but then it gave some other errors.
Please help...

I ran into a similar problem with Laravel 5.7.13.
My error with Laravel and the openssl_cipher_iv_length() function was encountered when I updated my WampServer installation to PHP v7.2.x (from v7.1.10). Yes, I am running on Windows.
Switching back to php v7.1.10 would clear the error.
To solve my error with openssl_cipher_iv_length(), I compared the php.ini files from the two php versions. When comparing the files I noticed that I did not have the extension_dir set properly. This was my main issue, but there were other edits I made in the past that I also incorporated into the new PHP environment (i.e. extensions that were enabled and XDEBUG settings).
Also... I did notice that the extension names were previously defined as:
extension=php_<ext>.dll
or
extension=<ext>.so
and are now using:
extension=<ext>
So my issue with openssl_cipher_iv_length() was a result of the PHP version and not Laravel.
I hope this information helps.

Related

Fatal error - Parse error: syntax error, unexpected ':', expecting - Wordpress

I need your help.
I'm trying to install ACF plugin and give me this error:
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /home/htb/mysite/wp-content/plugins/acf-for-woocommerce/vendor/catsplugins/cp-core/src/common/class-cp-util.php on line 23
This is the line 23:
public static function pathToUrl(string $path): string {
Here's the code:
<?php
namespace CastPlugin;
if (class_exists('CpUtil')) {
return;
}
class CpUtil
{
public static function startsWith($haystack, $needle)
{
return strncmp($haystack, $needle, strlen($needle)) === 0;
}
public static function contains($haystack, $needle)
{
return strpos($haystack, $needle) !== false;
}
public static function pathToUrl(string $path): string {
$ssl = #$_SERVER['HTTPS'];
$serverName = $_SERVER['SERVER_NAME'];
$documentRoot = $_SERVER['DOCUMENT_ROOT'];
$correctPath = $path;
$uri = str_replace($documentRoot, '', $correctPath);
$protocol = $ssl === 'on' ? 'https' : 'http';
return "$protocol://$serverName$uri";
}
}
Any idea how to solve this?
Thank you. :)
The version of ACF you're using requires PHP 7.0+. The error message you're getting indicates you're using PHP 5.6 or older. You should talk to your hosting provider about allowing you to upgrade to newer version of PHP.
This error specifically is caused by a new PHP method declaration syntax introduced in PHP 7.0 that allows you to declare that the method you're defining will return an array, which you can read about here: http://php.net/manual/en/functions.returning-values.php#functions.returning-values.type-declaration
If your hosting provider won't upgrade your PHP version, I suggest you find a new hosting provider. But if you need ACF to work in the meantime, you can go to the advanced page for ACF in the repository and download an older version at the bottom of the page.
Note: Both of these practices (using an outdated PHP version and using an outdate plugin) can be detrimental to the long-term health of your WordPress installation. I'd recommend getting on to PHP 7.2 at least as soon as you're able, which will allow you to use the most recent version of ACF.

PHPUnit\Framework\Error\Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

I'm following zend's tutorial to use zend-test on my project, but I'm getting this error.
To build my project's base I did the biggest part of this book.
I'm also using PHP 7.2.
When I search google I found a lot of people having trouble using PHP 7.2 with PHP Unit, but it looks like it's ok by now. Did zend-test also being update? If no, what can I do to use zend-test by now? If yes, how do I get the last version?
EDIT
After some test I found the problem, it is on the bootstrap function:
public function onBootstrap( MvcEvent $event ) {
$application = $event->getApplication();
$serviceManager = $application->getServiceManager();
$sessionManager = $serviceManager->get(SessionManager::class);
$eventManager = $event->getApplication()->getEventManager();
$sharedEventManager = $eventManager->getSharedManager();
// Registra o método fo event listener
$sharedEventManager->attach(AbstractActionController::class,
MvcEvent::EVENT_DISPATCH, [$this, 'onDispatch'], 100);
// Caso a sessão não seja válida, esquece ela
$this->forgetInvalidSession($sessionManager);
}
To be more specific, the problem starts at this line:
$sessionManager = $serviceManager->get(SessionManager::class);
EDIT 2
Removing that line e it's uses, it kind than work, but starts to give the same error in another module in a similar line:
$authService = $container->get(\Zend\Authentication\AuthenticationService::class);

Evernote PHP sdk integration with Symfony2

I am using this documentation to set up Evernote cloud sdk php into Symfony2 :
https://github.com/evernote/evernote-cloud-sdk-php/blob/master/documentation/Getting_Started.md
As they say, I installed it first with composer.
Then I am using this code
$sandbox = true;
$oauth_handler = new \Evernote\Auth\OauthHandler($sandbox);
$key = '%key%';
$secret = '%secret%';
$callback = 'http://host/pathto/evernote-cloud-sdk-php/sample/oauth/index.php';
$oauth_data = $oauth_handler->authorize($key, $secret, $callback);
echo "\nOauth Token : " . $oauth_data['oauth_token'];
I changed the parameters with mine, but the problem is inside Evernote\Auth\OauthHandler :
https://github.com/evernote/evernote-cloud-sdk-php/blob/master/src/Evernote/Auth/OauthHandler.php
The lib is using the function header(location: ...);
And the function is not executing.
I guess Symfony2 is not allowing the usage of this function.
Is there a way to force it ?
Or how can I change it in a good way (and to be able to push on my git repository) ?
Thanks,

Channel.Security.Error...Error #2048

I recently upgraded to Flash Builder 4.5 for PHP and am trying to upload a release build to my remoteserver. When I try to make a php call from the app, I get the error:
Send failednChannel.Security.Error error Error #2048 url: 'http://localhost/my_php/public/gateway.php'
The release build works fine on my localhost machine. All of my php service calls are on my remote host. Here's the structure of my remote host:
/my_directory/html (this is the root directory)
/my_directory/html/my_php/public/release (this is where my .html wrapper and .swf files sit)
/my_directory/html/my_php/public (this is where my gateway.php and amf_config.ini files sit)
The error specifically references 'localhost', but I can't find where that gets set. When I google error #2048, the solutions point to a badly configured crossdomain file...all my services are on remotehost (where the app is hosted) so I don't think that could be the issue.
Here is my amf_config.ini file:
[zend]
webroot = "/my_directory/html"
zend_path ="/my_directory/html/ZendFramework/library"
library ="/my_directory/html/my_php/library"
services ="/my_directory/html/my_php/services"
[zendamf]
amf.production = false
amf.directories[]=/my_directory/html/my_php/services
Here is my gateway.php file:
<?php
ini_set("display_errors", 1);
$dir = dirname(__FILE__);
$webroot = $_SERVER['DOCUMENT_ROOT'];
$configfile = "$dir/amf_config.ini";
$servicesdir = $dir.'/../services';
$librarydir = $dir.'/../library';
//default zend install directory
$zenddir = $webroot.'/ZendFramework/library';
//Load ini file and locate zend directory
if (file_exists($configfile)) {
$arr = parse_ini_file($configfile, true);
if (isset($arr['zend']['webroot'])) {
$webroot = $arr['zend']['webroot'];
$zenddir = $webroot.'/ZendFramework/library';
}
if (isset($arr['zend']['zend_path'])) {
$zenddir = $arr['zend']['zend_path'];
}
if (isset($arr['zend']['library'])) {
$librarydir = $arr['zend']['library'];
}
if (isset($arr['zend']['services'])) {
$servicesdir = $arr['zend']['services'];
}
}
// Setup include path
// add zend directory, library and services to include path
set_include_path(get_include_path()
.PATH_SEPARATOR.$zenddir
.PATH_SEPARATOR.$librarydir
.PATH_SEPARATOR.$servicesdir);
// Initialize Zend Framework loader
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance()->setFallbackAutoloader(true)->suppressNotFoundWarnings(true);
// Load configuration
$default_config = new Zend_Config(array("production" => false), true);
$default_config->merge(new Zend_Config_Ini($configfile, 'zendamf'));
$default_config->setReadOnly();
$amf = $default_config->amf;
// Store configuration in the registry
Zend_Registry::set("amf-config", $amf);
// Initialize AMF Server
$server = new Zend_Amf_Server();
$server->setProduction($amf->production);
if (isset($amf->directories)) {
$dirs = $amf->directories->toArray();
foreach ($dirs as $dir) {
if ($dir == "./") {
$server->addDirectory($webroot);
} else
if (realpath("{$webroot}/{$dir}")) {
$server->addDirectory("{$webroot}/{$dir}");
} else
if (realpath($dir)) {
$server->addDirectory(realpath($dir));
}
}
}
// Initialize introspector for non-production
if (! $amf->production) {
$server->setClass('Zend_Amf_Adobe_Introspector', '',
array("config" => $default_config, "server" => $server));
$server->setClass('Zend_Amf_Adobe_DbInspector', '',
array("config" => $default_config, "server" => $server));
}
// Handle request
echo $server->handle();
i had the same problem in a flex - blaze - environment. The real Problem was the context-root in the project properties.
because you used flex 4.5, there is no input field for this setting. in flex builder 3, there was a setting in the project properties -> flex server -> context root.
i gone crazy and found after hours an article on adobes bugs-site [FB-22939].
That solve my problem. I have no idea, wich project settings you are using, try to search a string named {context.root} in your project or post a liite bit more about your project settings. i know blaze is different from php, but maybe it is a tip bringing you back on track.
Unfortunately I'm not able to reproduce my thread and setting up an php environment with more knowledge about your setup. (Server-Technology, and so one)
edit:
additional Info:
I've found a list of all compiler arguments. Try it with this argument:
-context-root <context-path>
full name -compiler.context-root
path to replace {context.root} tokens for service channel endpoints
br
Frank

Using Selenium Grid 2 with PHPUnit tests

I have recently written a lot of selenium 1 tests for a fairly complex project. They are all written in php and run smoothly on the selenium-server 1.0.7.
Obviously with firefox 5 (and 6 released today) selenium server 1.0.7 is not working anymore. I've tried, but the server is just opening blank windows.
Now I am trying to get those tests running on selenium grid. I managed to get a hub and a couple of remote-controls runnnig using grid v1, but they only open blank windows just like the old server did. So I figured i needed to upgrade to grid v2.
For some reason i can get the clients connected to the hub, but if I try running my tests against the hub it doesn't seem to be able to connect at all ("PHPUnit_Framework_Exception: Could not connect to the Selenium RC server"). I tried running them against selenium standalone server 2.4.0 and that does seem to work.
I read in a forum, that selenium grid 2 just doesn't work with phpunit (yet?).
How can i get my tests running on a grid? What is missing for phpunit to connect to the server? I appreciate any help!
I set up the hub as follows:
java -jar selenium-server-standalone-2.4.0.jar -role hub
And two slaves:
java -jar selenium-server-standalone-2.4.0.jar -role rc -hub http://127.0.0.1:4444/grid/register -port 5555
java -jar selenium-server-standalone-2.4.0.jar -role webdriver -hub http://127.0.0.1:4444/grid/register -port 5556
Everything seems to be working till here as i see two nodes in the grid console (http://localhost:4444/grid/console).
So here is all the initialization I am doing in code:
<?php
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
class Grid_Test extends PHPUnit_Extensions_SeleniumTestCase
{
public $captureScreenshotOnFailure = false;
public static $browsers = array(
'FFLinux' => array(
'name' => 'Firefox on Linux',
'browser' => '*firefox',
'host' => '127.0.0.1',
'port' => 4444,
'timeout' => 30000
));
public function setUp()
{
$this->setBrowserUrl('http://www.google.com');
}
public function testGridWorking()
{
$this->open('/');
$this->assertTrue(false);
}
}
This code still works on the standalone server 2.4.0. It fails at the last line as expected.
The Exception seems to be thrown in PHPUnit/Extentions/SeleniumTestCase/Driver.php. There seems to be the problem.
protected function doCommand($command, array $arguments = array())
{
$url = sprintf(
'http://%s:%s/selenium-server/driver/?cmd=%s',
$this->host,
$this->port,
urlencode($command)
);
[...]
$handle = #fopen($url, 'r', FALSE, $context);
if (!$handle) {
throw new PHPUnit_Framework_Exception(
'Could not connect to the Selenium RC server.'
);
}
[...]
}
When i request http://localhost:4444/selenium-driver/driver in the browser, i get:
HTTP ERROR: 500
org.openqa.grid.internal.GridException: Session not available - []
RequestURI=/selenium-server/driver
Any idea how to fix this? Do I need to change that url maybe ?
Also make sure you have setup the Grid correctly here is a small post that shows how it is done : http://opensourcetester.co.uk/2011/07/06/selenium-grid-2/
BTW I dint see code that does the driver instantiation.. Am i missing something?
Here is how it is done:
require_once "phpwebdriver/WebDriver.php";
require("phpwebdriver/LocatorStrategy.php");
$webdriver = new WebDriver("localhost", "4444");
$webdriver->connect("firefox");
$webdriver->get("http://google.com");
$element = $webdriver->findElementBy(LocatorStrategy::name, "q");
$element->sendKeys(array("selenium google code" ) );
$element->submit();
$webdriver->close();
for more: http://code.google.com/p/php-webdriver-bindings/
The problem with trying to use PHPUnit with Selenium Grid 2 has already been reported to the project owners. Have a look at the patch available here to see if it works for you.
Anyway, if I were you I would start thinking about migrating to WebDriver through one of the drivers available out there for PHP, like php-webdriver.

Resources