- // Stash the signature away for now. We have to find their key or it won't be good for anything.
- $signature = base64url_decode($base->sig);
-
- logger('signature: ' . bin2hex($signature));
-
- // unpack the data
-
- // strip whitespace so our data element will return to one big base64 blob
- $data = str_replace(array(" ","\t","\r","\n"),array("","","",""),$base->data);
- // Add back the 60 char linefeeds
- $lines = str_split($data,60);
- $data = implode("\n",$lines);
-
-
- // stash away some other stuff for later
-
- $type = $base->data[0]->attributes()->type[0];
- $keyhash = $base->sig[0]->attributes()->keyhash[0];
- $encoding = $base->encoding;
- $alg = $base->alg;
-
- $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');