aboutsummaryrefslogtreecommitdiffstats
path: root/include/crypto.php
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2013-11-20 15:20:12 -0800
committerfriendica <info@friendica.com>2013-11-20 15:20:12 -0800
commitd7ee552c570f4fca760c3d1573f32c005cf73bb8 (patch)
treea5020a1a27472fe889d773a5e4e2b410930ceda7 /include/crypto.php
parentf6c41e61ace7260dde49125487f9ec7142f48e4f (diff)
downloadvolse-hubzilla-d7ee552c570f4fca760c3d1573f32c005cf73bb8.tar.gz
volse-hubzilla-d7ee552c570f4fca760c3d1573f32c005cf73bb8.tar.bz2
volse-hubzilla-d7ee552c570f4fca760c3d1573f32c005cf73bb8.zip
Protocol: now set data['alg'] on all encapsulated encrypted packets, so that we can more easily retire 'aes256cbc' once it is no longer viable.
Diffstat (limited to 'include/crypto.php')
-rw-r--r--include/crypto.php16
1 files changed, 16 insertions, 0 deletions
diff --git a/include/crypto.php b/include/crypto.php
index a0268ef93..ca01814da 100644
--- a/include/crypto.php
+++ b/include/crypto.php
@@ -49,6 +49,13 @@ function AES256CBC_decrypt($data,$key,$iv) {
str_pad($iv,16,"\0")));
}
+function crypto_encapsulate($data,$pubkey,$alg='aes256cbc') {
+ if($alg === 'aes256cbc')
+ return aes_encapsulate($data,$pubkey);
+
+}
+
+
function aes_encapsulate($data,$pubkey) {
if(! $pubkey)
logger('aes_encapsulate: no key. data: ' . $data);
@@ -60,12 +67,21 @@ function aes_encapsulate($data,$pubkey) {
$x = debug_backtrace();
logger('aes_encapsulate: RSA failed. ' . print_r($x[0],true));
}
+ $result['alg'] = 'aes256cbc';
$result['key'] = base64url_encode($k,true);
openssl_public_encrypt($iv,$i,$pubkey);
$result['iv'] = base64url_encode($i,true);
return $result;
}
+function crypto_unencapsulate($data,$prvkey) {
+ $alg = ((array_key_exists('alg',$data)) ? $data['alg'] : 'aes256cbc');
+ if($alg === 'aes256cbc')
+ return aes_unencapsulate($data,$prvkey);
+
+}
+
+
function aes_unencapsulate($data,$prvkey) {
openssl_private_decrypt(base64url_decode($data['key']),$k,$prvkey);
openssl_private_decrypt(base64url_decode($data['iv']),$i,$prvkey);