- // 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));
-
- openssl_public_encrypt('test',$rrr,$ryanpubkey);
- logger('rrr: ' . $rrr);
-
- $pubdecsig = '';
- openssl_public_decrypt($signature,$pubdecsig,$ryanpubkey);
- logger('decsig: ' . bin2hex($pubdecsig));
-
- // 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);
-
- // 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 . "\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);
-
-// $key = get_salmon_key($author_link,$keyhash);
-
- if(! $key) {
- logger('mod-salmon: Could not retrieve author key.');
- receive_return(400);
- }
-
-// FIXME
-// Use non salmon compliant signature
-
-/*
-
- // Setup RSA stuff to verify the signature
-
- set_include_path(get_include_path() . PATH_SEPARATOR . 'library' . PATH_SEPARATOR . 'phpsec');
-
- require_once('library/phpsec/Crypt/RSA.php');
-
- $key_info = explode('.',$key);
-
- $m = base64url_decode($key_info[1]);
- $e = base64url_decode($key_info[2]);
-
- logger('mod-salmon: key details: ' . print_r($key_info,true));
-
- $rsa = new CRYPT_RSA();
- $rsa->signatureMode = CRYPT_RSA_SIGNATURE_PKCS1;
- $rsa->setHash('sha256');
-
- $rsa->modulus = new Math_BigInteger($m, 256);
- $rsa->k = strlen($rsa->modulus->toBytes());
- $rsa->exponent = new Math_BigInteger($e, 256);
-
- $verify = $rsa->verify($signed_data,$signature);
-
- if(! $verify) {
- logger('mod-diaspora: Message did not verify. Discarding.');
- receive_return(400);