The Linux Page

OpenSSL and PostgreSQL conflict in PHP

All of last week I've been looking for the solution to a bug in one of my numerous websites.

The problem was that after registering, a user would get an error saying that the PostgreSQL connection was lost. I had never had that with Drupal and yet, it would be 100% consistent.

I tested the new code several times and had no problems with it, so I was really dismayed that all of a sudden it stopped working.

After quite some time, I finally decided that my new code was the culprit. Weird. It was. It does the same thing as one of the Core modules and yet it breaks the PostgreSQL connection!?

The only addition was the roles. Okay, let's remove that code. Nope... still fails.

Well! There was one other addition: the encryption of the password. Let's remove that call. You bet! That was it! I used the openssl_public_encrypt() function to encrypt the password with a 4096 bit key. Works great, I have two functions, one to encrypt and one to decrypt and they both work. Although the function is limited to about 940 bits (117 bytes), for passwords, it generally is just fine. Plus, I was testing with the genius password: 123456. (isn't that even better than Top Secret?!)

So... the OpenSSL function would be in conflict with the PostgreSQL database? Hmmm... Really I have no clue why that would be a problem. In any event, by commenting it out and replacing it with mcrypt, the new code was working again. I'm wondering if this has to do with the fact that a PostgreSQL transaction can be encoded whenever sending orders to the data and there are some confusion between OpenSSL and PostgreSQL at that level (although since all the transactions with the DB are on the same server, we do not ecrypt those...)

If someone has a good answer for this problem, please, post a comment below! Thank you.