Private Message Encryption

Discussion forum for MOD Writers regarding MOD Development.
Locked
virus-hc
Registered User
Posts: 2
Joined: Fri Dec 02, 2011 7:36 pm

Private Message Encryption

Post by virus-hc »

Hello good folks of the phpbb community.

I really hope i'm able to describe what i'm looking for.

A friend of mine wants the private messages in his community to be encrypted, so nobody who has access to the database can "just read them like they are".

Now don't worry, i don't want anybody to write me a mod for that, writing it is actually the easy part.

I just can't figure out where to look for the message text.
Could anybody give me some pointers where i got too look for the message text just before it gets placed in the database? And on the other side, also where it is directly read from the database?
Maybe even the variables/array-elements i need to look for?


So i need to find the section where the messagetext is placed in the Database, so i can run the encryption over it just before it is actually stored, so after phpBB "is done with it".

And also where it is read from the database, so i can decrypt it before any other phpBB function tries to parse it.
User avatar
Sajaki
Registered User
Posts: 1390
Joined: Mon Mar 02, 2009 1:41 pm
Location: Amsterdam
Contact:

Re: Private Message Encryption

Post by Sajaki »

to encrypt the pm :


Open /includes/functions_privmsgs.php
find line 1447 :

Code: Select all

$query = '';
add after :

Code: Select all

		$key = 'sdijfnvzdv5431zei';
		$encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $sql_data['message_text'], MCRYPT_MODE_CBC, md5(md5($key))));
		$sql_data['message_text'] = $encrypted;
Then, to decrypt the pm :

open /includes/ucp/ucp_pm_viewmessage.php
find line 65 :

Code: Select all

	$user_info = get_user_information($author_id, $message_row);
add after :

Code: Select all

	// decrypt
	$key = 'sdijfnvzdv5431zei';
	$decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($message_row['message_text']), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
	$message_row['message_text'] = $decrypted; 
it's a quick hack, it works but maybe there are side effects, i haven't checked that.

if you check the database, in the table phpbb_privmsg, the message_text field will now be encrypted.

You might also want to change $key = 'sdijfnvzdv5431zei'; to something not hardcoded.

have fun ;)
virus-hc
Registered User
Posts: 2
Joined: Fri Dec 02, 2011 7:36 pm

Re: Private Message Encryption

Post by virus-hc »

Wow thank you so much that was fast :)

Edit: It shows the Message in the "Message History" under the Message not decrypted. :(

Edit2: I found it. You also need to make this change in the line 1826 of the functions_privmsgs.php

after

Code: Select all

		$message	= $row['message_text'];
add

Code: Select all

 // decrypt
   $key = 'sdijfnvzdv5431zei';
   $decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($message_row['message_text']), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
   $message_row['message_text'] = $decrypted; 
Locked

Return to “[3.0.x] MOD Writers Discussion”