mirror of
https://github.com/friendica/friendica
synced 2025-05-02 23:44:23 +02:00
Crypto to src
move Crypto to src and Friendica\Util namespace
This commit is contained in:
parent
6d6d83012c
commit
9e6bf79380
15 changed files with 317 additions and 230 deletions
|
@ -463,7 +463,7 @@ class DFRN
|
|||
/* get site pubkey. this could be a new installation with no site keys*/
|
||||
$pubkey = Config::get('system', 'site_pubkey');
|
||||
if (! $pubkey) {
|
||||
$res = new_keypair(1024);
|
||||
$res = Crypto::newKeypair(1024);
|
||||
Config::set('system', 'site_prvkey', $res['prvkey']);
|
||||
Config::set('system', 'site_pubkey', $res['pubkey']);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ use Friendica\Model\Group;
|
|||
use Friendica\Model\Profile;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Network\Probe;
|
||||
use Friendica\Util\Crypto;
|
||||
use Friendica\Util\XML;
|
||||
|
||||
use dba;
|
||||
|
@ -173,7 +174,7 @@ class Diaspora
|
|||
|
||||
$key = self::key($handle);
|
||||
|
||||
$verify = rsa_verify($signable_data, $sig, $key);
|
||||
$verify = Crypto::rsaVerify($signable_data, $sig, $key);
|
||||
if (!$verify) {
|
||||
logger('Message did not verify. Discarding.');
|
||||
return false;
|
||||
|
@ -273,7 +274,7 @@ class Diaspora
|
|||
$author_addr = base64_decode($key_id);
|
||||
$key = self::key($author_addr);
|
||||
|
||||
$verify = rsa_verify($signed_data, $signature, $key);
|
||||
$verify = Crypto::rsaVerify($signed_data, $signature, $key);
|
||||
if (!$verify) {
|
||||
logger('Message did not verify. Discarding.');
|
||||
http_status_exit(400);
|
||||
|
@ -406,7 +407,7 @@ class Diaspora
|
|||
http_status_exit(400);
|
||||
}
|
||||
|
||||
$verify = rsa_verify($signed_data, $signature, $key);
|
||||
$verify = Crypto::rsaVerify($signed_data, $signature, $key);
|
||||
|
||||
if (!$verify) {
|
||||
logger('Message did not verify. Discarding.');
|
||||
|
@ -699,7 +700,7 @@ class Diaspora
|
|||
|
||||
$key = self::key($msg["author"]);
|
||||
|
||||
if (!rsa_verify($signed_data, $parent_author_signature, $key, "sha256")) {
|
||||
if (!Crypto::rsaVerify($signed_data, $parent_author_signature, $key, "sha256")) {
|
||||
logger("No valid parent author signature for parent author ".$msg["author"]. " in type ".$type." - signed data: ".$signed_data." - Message: ".$msg["message"]." - Signature ".$parent_author_signature, LOGGER_DEBUG);
|
||||
return false;
|
||||
}
|
||||
|
@ -709,7 +710,7 @@ class Diaspora
|
|||
|
||||
$key = self::key($fields->author);
|
||||
|
||||
if (!rsa_verify($signed_data, $author_signature, $key, "sha256")) {
|
||||
if (!Crypto::rsaVerify($signed_data, $author_signature, $key, "sha256")) {
|
||||
logger("No valid author signature for author ".$fields->author. " in type ".$type." - signed data: ".$signed_data." - Message: ".$msg["message"]." - Signature ".$author_signature, LOGGER_DEBUG);
|
||||
return false;
|
||||
} else {
|
||||
|
@ -1432,7 +1433,7 @@ class Diaspora
|
|||
// Check signature
|
||||
$signed_text = 'AccountMigration:'.$old_handle.':'.$new_handle;
|
||||
$key = self::key($old_handle);
|
||||
if (!rsa_verify($signed_text, $signature, $key, "sha256")) {
|
||||
if (!Crypto::rsaVerify($signed_text, $signature, $key, "sha256")) {
|
||||
logger('No valid signature for migration.');
|
||||
return false;
|
||||
}
|
||||
|
@ -3032,7 +3033,7 @@ class Diaspora
|
|||
$user['uprvkey'] = $user['prvkey'];
|
||||
}
|
||||
|
||||
$signature = rsa_sign($signable_data, $user["uprvkey"]);
|
||||
$signature = Crypto::rsaSign($signable_data, $user["uprvkey"]);
|
||||
$sig = base64url_encode($signature);
|
||||
|
||||
$xmldata = array("me:env" => array("me:data" => $data,
|
||||
|
@ -3088,7 +3089,7 @@ class Diaspora
|
|||
|
||||
$signed_text = implode(";", $sigmsg);
|
||||
|
||||
return base64_encode(rsa_sign($signed_text, $owner["uprvkey"], "sha256"));
|
||||
return base64_encode(Crypto::rsaSign($signed_text, $owner["uprvkey"], "sha256"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3282,7 +3283,7 @@ class Diaspora
|
|||
$profile = self::createProfileData($uid);
|
||||
|
||||
$signed_text = 'AccountMigration:'.$old_handle.':'.$profile['author'];
|
||||
$signature = base64_encode(rsa_sign($signed_text, $owner["uprvkey"], "sha256"));
|
||||
$signature = base64_encode(Crypto::rsaSign($signed_text, $owner["uprvkey"], "sha256"));
|
||||
|
||||
$message = array("author" => $old_handle,
|
||||
"profile" => $profile,
|
||||
|
|
|
@ -5,10 +5,9 @@
|
|||
namespace Friendica\Protocol;
|
||||
|
||||
use Friendica\Network\Probe;
|
||||
use Friendica\Util\Crypto;
|
||||
use Friendica\Util\XML;
|
||||
|
||||
require_once 'include/crypto.php';
|
||||
|
||||
/**
|
||||
* @brief Salmon Protocol class
|
||||
* The Salmon Protocol is a message exchange protocol running over HTTP designed to decentralize commentary
|
||||
|
@ -107,18 +106,18 @@ class Salmon
|
|||
$data_type = 'application/atom+xml';
|
||||
$encoding = 'base64url';
|
||||
$algorithm = 'RSA-SHA256';
|
||||
$keyhash = base64url_encode(hash('sha256', salmon_key($owner['spubkey'])), true);
|
||||
$keyhash = base64url_encode(hash('sha256', Crypto::salmonKey($owner['spubkey'])), true);
|
||||
|
||||
$precomputed = '.' . base64url_encode($data_type) . '.' . base64url_encode($encoding) . '.' . base64url_encode($algorithm);
|
||||
|
||||
// GNU Social format
|
||||
$signature = base64url_encode(rsa_sign($data . $precomputed, $owner['sprvkey']));
|
||||
$signature = base64url_encode(Crypto::rsaSign($data . $precomputed, $owner['sprvkey']));
|
||||
|
||||
// Compliant format
|
||||
$signature2 = base64url_encode(rsa_sign(str_replace('=', '', $data . $precomputed), $owner['sprvkey']));
|
||||
$signature2 = base64url_encode(Crypto::rsaSign(str_replace('=', '', $data . $precomputed), $owner['sprvkey']));
|
||||
|
||||
// Old Status.net format
|
||||
$signature3 = base64url_encode(rsa_sign($data, $owner['sprvkey']));
|
||||
$signature3 = base64url_encode(Crypto::rsaSign($data, $owner['sprvkey']));
|
||||
|
||||
// At first try the non compliant method that works for GNU Social
|
||||
$xmldata = array("me:env" => array("me:data" => $data,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue