Code Monkey home page Code Monkey logo

Comments (11)

wtps0n avatar wtps0n commented on August 25, 2024

I've found disscusion on Stack Overflow about openssl_encrypt:
https://stackoverflow.com/questions/52477247/trying-to-decrypt-with-aes-256-gcm-with-php

Maybe this URL will be helpful?
https://www.php.net/manual/en/function.openssl-encrypt.php

from phpldapadmin.

nick-oconnor avatar nick-oconnor commented on August 25, 2024

Same issue here with v1.2.6.5 containerized with php:8.1-apache.

from phpldapadmin.

vpushkar avatar vpushkar commented on August 25, 2024

What is your fix @wtps0n?

from phpldapadmin.

wtps0n avatar wtps0n commented on August 25, 2024

Well, I have no fix yet :-)

I have no unix box with openssl 3.x availabe so I don't know how to write checking 'openssl version' inside php (which number version will be returned).

So maybe it is much easier to define (pseudo code) config->session_cipher = ''. And inside lib/functions php set SESSION_CIPHER to aes-256-gcm as default or seeting from config.

If it is good, I will try to make patch till the end of week.

from phpldapadmin.

vpushkar avatar vpushkar commented on August 25, 2024

I made it work:

--- functions.php.bak   2023-03-01 12:14:14.142130000 +0200
+++ functions.php       2023-03-01 23:40:49.134927000 +0200
@@ -793,8 +793,10 @@
                return $data;

        if (! empty($data) && function_exists('openssl_encrypt') && in_array(SESSION_CIPHER, openssl_get_cipher_methods())) {
+               $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length(SESSION_CIPHER));
                $keylen = openssl_cipher_iv_length(SESSION_CIPHER) * 2;
-               return openssl_encrypt($data, SESSION_CIPHER, substr($secret,0,$keylen));
+               $encrypted = openssl_encrypt($data, SESSION_CIPHER, substr($secret,0,$keylen), $options=0, $iv, $tag);
+               return base64_encode($encrypted . '::' . $iv . '::' . $tag);
        }

        if (function_exists('mcrypt_module_open') && ! empty($data)) {
@@ -855,7 +857,8 @@

        if (! empty($encdata) && function_exists('openssl_encrypt') && in_array(SESSION_CIPHER, openssl_get_cipher_methods())) {
                $keylen = openssl_cipher_iv_length(SESSION_CIPHER) * 2;
-               return trim(openssl_decrypt($encdata, SESSION_CIPHER, substr($secret,0,$keylen)));
+               list($encryptedData, $iv, $tag) = explode('::', base64_decode($encdata), 3);
+               return trim(openssl_decrypt($encryptedData, SESSION_CIPHER, substr($secret,0,$keylen), $options=0, $iv, $tag));
        }

        if (function_exists('mcrypt_module_open') && ! empty($encdata)) {

from phpldapadmin.

wtps0n avatar wtps0n commented on August 25, 2024

Great work. Yes it is working with Openssl 1.1.1. I've just checked it. Thank you very much.

from phpldapadmin.

el-piewie avatar el-piewie commented on August 25, 2024

works with SLES 12SP5 (openssl-1.0.2p), too.
@vpushkar Thank you for the patch.

from phpldapadmin.

vpushkar avatar vpushkar commented on August 25, 2024

@wtps0n one more fix for php 8.1 is in #193

from phpldapadmin.

brenard avatar brenard commented on August 25, 2024

The @vpushkar solution works great. @leenooks do you need a PR for that?

from phpldapadmin.

williamdes avatar williamdes commented on August 25, 2024

The @vpushkar solution works great. @leenooks do you need a PR for that?

Please open a PR for this.
You can see my patch for Debian on https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1033163 (Fix-openssl-3-cipher-name-PHP-8.patch)

from phpldapadmin.

leenooks avatar leenooks commented on August 25, 2024

Thanks @vpushkar fixed with 85f8c61.

from phpldapadmin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.