]> git.mxchange.org Git - friendica.git/commitdiff
Merge branch 'pull'
authorFriendika <info@friendika.com>
Sun, 28 Aug 2011 12:05:32 +0000 (05:05 -0700)
committerFriendika <info@friendika.com>
Sun, 28 Aug 2011 12:05:32 +0000 (05:05 -0700)
boot.php
include/crypto.php
include/diaspora.php
mod/network.php

index cb18b0560489deabb425a13bbb3c496394486a29..58d6cc8394f9db3b2f91536953ceebc550a967c8 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -7,7 +7,7 @@ require_once('include/text.php');
 require_once("include/pgettext.php");
 
 
-define ( 'FRIENDIKA_VERSION',      '2.2.1084' );
+define ( 'FRIENDIKA_VERSION',      '2.2.1085' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.21'    );
 define ( 'DB_UPDATE_VERSION',      1083      );
 
index a20606db540a5313b67b7dcb67e147df74e33a62..88e05b9eb0e34a75a2a2eff9beadfe866cf8c364 100644 (file)
@@ -225,3 +225,68 @@ function pkcs5_unpad($text)
     if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) return false;
     return substr($text, 0, -1 * $pad);
 } 
+
+function AES256CBC_encrypt($data,$key,$iv) {
+       return mcrypt_encrypt(
+               MCRYPT_RIJNDAEL_128, 
+               str_pad($key,32,"\0"), 
+               pkcs5_pad($data,16), 
+               MCRYPT_MODE_CBC, 
+               str_pad($iv,16,"\0"));
+}
+
+function AES256CBC_decrypt($data,$key,$iv) {
+       return pkcs5_unpad(mcrypt_decrypt(
+               MCRYPT_RIJNDAEL_128, 
+               str_pad($key,32,"\0"), 
+               $data, 
+               MCRYPT_MODE_CBC, 
+               str_pad($iv,16,"\0")));
+}
+
+function aes_encapsulate($data,$pubkey) {
+       $key = random_string(32,RANDOM_STRING_TEXT);
+       $iv  = random_string(16,RANDOM_STRING_TEXT);
+       $result['data'] = base64url_encode(AES256CBC_encrypt($data,$key,$iv),true);
+       openssl_public_encrypt($key,$k,$pubkey);
+       $result['key'] = base64url_encode($k,true);
+       openssl_public_encrypt($iv,$i,$pubkey);
+       $result['iv'] = base64url_encode($i,true);
+       return $result;
+}
+
+function aes_unencapsulate($data,$prvkey) {
+       openssl_private_decrypt(base64url_decode($data['key']),$k,$prvkey);
+       openssl_private_decrypt(base64url_decode($data['iv']),$i,$prvkey);
+       return AES256CBC_decrypt(base64url_decode($data['data']),$k,$i);
+}
+
+
+function zot_encapsulate($data,$sender,$pubkey) {
+$res = aes_encapsulate($data,$pubkey);
+openssl_public_encrypt($sender,$s,$pubkey);
+$s1 = base64url_encode($s,true);
+
+return <<< EOT
+<?xml version='1.0' encoding='UTF-8'?>
+<zot:env xmlns:zot='http://purl.org/zot/1.0'>
+ <zot:key>{$res['key']}</zot:key>
+ <zot:iv>{$res['iv']}</zot:iv>
+ <zot:sender>$s1</zot:sender>
+ <zot:alg>AES-256-CBC</zot:alg>
+ <zot:data type='application/magic-envelope+xml'>{$res['data']}</zot:data>
+</zot:env>
+EOT;
+
+}
+
+function zot_unencapsulate($data,$prvkey) {
+       $ret = array();
+       $c = array();
+       $x = parse_xml_string($data);
+       $c = array('key' => $x->key,'iv' => $x->iv,'data' => $x->data);
+       openssl_private_decrypt(base64url_decode($x->sender),$s,$prvkey);
+       $ret['sender'] = $s;
+       $ret['data'] = aes_unencapsulate($x,$prvkey);
+       return $ret;
+}
\ No newline at end of file
index e3ab9458d2c49626d50a63f95bc84274de9c0b8d..10b342289719789bb13ed1aa643b88ca81151e55 100644 (file)
@@ -3,6 +3,7 @@
 require_once('include/crypto.php');
 require_once('include/items.php');
 require_once('include/bb2diaspora.php');
+require_once('include/contact_selectors.php');
 
 function diaspora_dispatch($importer,$msg) {
 
@@ -1060,10 +1061,24 @@ function diaspora_send_relay($item,$owner,$contact) {
                $like = false;
        }
 
-       $text = html_entity_decode(bb2diaspora($item['body']));
+       $body = $item['body'];
+
+       $itemcontact = q("select * from contact where `id` = %d limit 1",
+               intval($item['contact-id'])
+       );
+       if(count($itemcontact)) {
+               if(! $itemcontact[0]['self']) {
+                       $prefix = sprintf( t('[Relayed] Comment authored by %s from network %s'),
+                               '['. $item['author-name'] . ']' . '(' . $item['author-link'] . ')',  
+                               network_to_name($itemcontact['network'])) . "\n";
+                       $body = $prefix . $body;
+               }
+       }
+
+       $text = html_entity_decode(bb2diaspora($body));
 
        // fetch the original signature if somebody sent the post to us to relay
-       // if we are relaying for a reply originating here, there wasn't a 'send to relay'
+       // If we are relaying for a reply originating here, there wasn't a 'send to relay'
        // action. It wasn't needed. In that case create the original signature and the 
        // owner (parent author) signature
 
@@ -1076,6 +1091,10 @@ function diaspora_send_relay($item,$owner,$contact) {
                $authorsig = $orig_sign['signature'];
        }
        else {
+
+
+
+
                if($like)
                        $signed_text = $item['guid'] . ';' . $target_type . ';' . $parent_guid . ';' . $positive . ';' . $myaddr;
                else
index 05b74b50a4252782c7a9c410ea97cdfae4c46bea..54fb2a0a4ce490b080649fcff7296fcc4552ec73 100644 (file)
@@ -188,7 +188,7 @@ function network_content(&$a, $update = 0) {
                if(count($r)) {
                        $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $star_sql AND `contact-id` IN ( " . intval($cid) . " )) ";
                        $o = '<h2>' . t('Contact: ') . $r[0]['name'] . '</h2>' . $o;
-                       if($r[0]['network'] !== NETWORK_MAIL && $r[0]['network'] !== NETWORK_DFRN && $r[0]['network'] !== NETWORK_FACEBOOK && $r[0]['writable'] && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
+                       if($r[0]['network'] !== NETWORK_MAIL && $r[0]['network'] !== NETWORK_DFRN && $r[0]['network'] !== NETWORK_FACEBOOK && $r[0]['network'] !== NETWORK_DIASPORA && $r[0]['writable'] && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
                                notice( t('Private messages to this person are at risk of public disclosure.') . EOL);
                        }