- $signed_data = $data . (($data[-1] != "\n") ? "\n" : '') . '.' . base64url_encode($type) . "\n" . '.' . base64url_encode($encoding) . "\n" . '.' . base64url_encode($alg) . "\n";
-
- logger('signed data: ' . $signed_data);
-
- // decode the data
- $data = base64url_decode($data);
-
- // Now pull out the inner encrypted blob
-
- $inner_encrypted = base64_decode($data);
-
- $inner_decrypted =
- $inner_decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $inner_aes_key, $inner_encrypted, MCRYPT_MODE_CBC, $inner_iv);
-
- $inner_decrypted = pkcs5_unpad($inner_decrypted);
-
- logger('inner_decrypted: ' . $inner_decrypted);
-
-
-
- if(! $author_link) {
- logger('mod-diaspora: Could not retrieve author URI.');
- receive_return(400);
- }
-
- // Once we have the author URI, go to the web and try to find their public key
- // *** or look it up locally ***
-
- logger('mod-diaspora: Fetching key for ' . $author_link );
-
- // Get diaspora public key (pkcs#1) and convert to pkcs#8
- $key = get_diaspora_key($author_link);
-
- if(! $key) {
- logger('mod-salmon: Could not retrieve author key.');
- receive_return(400);
- }
-
- $verify = false;
-
- if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
- $verify = openssl_verify($signed_data,$signature,$key,'sha256');
- }
- else {
- // fallback sha256 verify for PHP < 5.3
- $rawsig = '';
- $hash = hash('sha256',$signed_data,true);
- openssl_public_decrypt($signature,$rawsig,$key);
- $verify = (($rawsig && substr($rawsig,-32) === $hash) ? true : false);
- }
-
- if(! $verify) {
- logger('mod-diaspora: Message did not verify. Discarding.');
- receive_return(400);
- }
-
- logger('mod-diaspora: Message verified.');
-
- // If we reached this point, the message is good.
- // Now let's figure out if the author is allowed to send us stuff.
-
- $r = q("SELECT * FROM `contact` WHERE `network` = 'dspr' AND ( `url` = '%s' OR `alias` = '%s')
- AND `uid` = %d LIMIT 1",
- dbesc($author_link),
- dbesc($author_link),
- intval($importer['uid'])
- );
- if(! count($r)) {
- logger('mod-diaspora: Author unknown to us.');
- }
-
- // is this a follower? Or have we ignored the person?
- // If so we can not accept this post.
-
- if((count($r)) && (($r[0]['readonly']) || ($r[0]['rel'] == CONTACT_IS_FOLLOWER) || ($r[0]['blocked']))) {
- logger('mod-diaspora: Ignoring this author.');
- receive_return(202);
- // NOTREACHED
- }
-
- require_once('include/items.php');
-
- // Placeholder for hub discovery. We shouldn't find any hubs
- // since we supplied the fake feed header - and it doesn't have any.
-
- $hub = '';
-
- /**
- *
- * anti-spam measure: consume_feed will accept a follow activity from
- * this person (and nothing else) if there is no existing contact record.
- *
- */
-
- $contact_rec = ((count($r)) ? $r[0] : null);
-
-
-
-
-// figure out what kind of diaspora message we have, and process accordingly.
-
-
-
-
-
- receive_return(200);