- $img->scaleImageSquare(175);
-
- $hash = hash('md5',uniqid(mt_rand(),true));
-
- $r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`,
- `height`, `width`, `data`, `scale` )
- VALUES ( %d, '%s', '%s', '%s', '%s', %d, %d, '%s', 4 )",
- intval($local_uid),
- dbesc($hash),
- datetime_convert(),
- datetime_convert(),
- dbesc(basename($r[0]['photo'])),
- intval($img->getHeight()),
- intval($img->getWidth()),
- dbesc($img->imageString())
- );
- if($r === false)
- $photo_failure = true;
- $img->scaleImage(80);
- $r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`,
- `height`, `width`, `data`, `scale` )
- VALUES ( %d, '%s', '%s', '%s', '%s', %d, %d, '%s', 5 )",
- intval($local_uid),
- dbesc($hash),
- datetime_convert(),
- datetime_convert(),
- dbesc(basename($r[0]['photo'])),
- intval($img->getHeight()),
- intval($img->getWidth()),
- dbesc($img->imageString())
- );
- if($r === false)
- $photo_failure = true;
-
- $photo = $a->get_baseurl() . '/photo/' . $hash . '-4.jpg';
- $thumb = $a->get_baseurl() . '/photo/' . $hash . '-5.jpg';
-
- }
- else
- $photo_failure = true;
+ $private_key = '';
+
+ openssl_pkey_export($res, $private_key);
+
+ $pubkey = openssl_pkey_get_details($res);
+ $public_key = $pubkey["key"];
+
+ // Save the private key. Send them the public key.
+
+ $r = q("UPDATE `contact` SET `prvkey` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
+ dbesc($private_key),
+ intval($contact_id),
+ intval($uid)
+ );
+
+ $params = array();
+
+ // Per the protocol document, we will verify both ends by encrypting the dfrn_id with our
+ // site private key (person on the other end can decrypt it with our site public key).
+ // Then encrypt our profile URL with the other person's site public key. They can decrypt
+ // it with their site private key. If the decryption on the other end fails for either
+ // item, it indicates tampering or key failure on at least one site and we will not be
+ // able to provide a secure communication pathway.
+
+ // If other site is willing to accept full encryption, (aes_allow is 1 AND we have php5.3
+ // or later) then we encrypt the personal public key we send them using AES-256-CBC and a
+ // random key which is encrypted with their site public key.
+
+ $src_aes_key = random_string();
+
+ $result = '';
+ openssl_private_encrypt($dfrn_id,$result,$user[0]['prvkey']);
+
+ $params['dfrn_id'] = bin2hex($result);
+ $params['public_key'] = $public_key;
+
+
+ $my_url = $a->get_baseurl() . '/profile/' . $user[0]['nickname'];
+
+ openssl_public_encrypt($my_url, $params['source_url'], $site_pubkey);
+ $params['source_url'] = bin2hex($params['source_url']);
+
+ if($aes_allow && function_exists('openssl_encrypt')) {
+ openssl_public_encrypt($src_aes_key, $params['aes_key'], $site_pubkey);
+ $params['aes_key'] = bin2hex($params['aes_key']);
+ $params['public_key'] = bin2hex(openssl_encrypt($public_key,'AES-256-CBC',$src_aes_key));