From db653e4451b24e9c0a285ea09cd5fc93392ca335 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Sun, 31 Dec 2017 08:04:36 -0500 Subject: [PATCH] Move salmonKey to Salmon class move the salmonKey function from Crypto to Salmon --- mod/hostxrd.php | 3 ++- mod/xrd.php | 6 +++--- src/Protocol/Salmon.php | 12 +++++++++++- src/Util/Crypto.php | 10 ---------- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/mod/hostxrd.php b/mod/hostxrd.php index a38d3ab61f..1da8fda998 100644 --- a/mod/hostxrd.php +++ b/mod/hostxrd.php @@ -5,6 +5,7 @@ use Friendica\App; use Friendica\Core\Config; use Friendica\Core\System; +use Friendica\Protocol\Salmon; use Friendica\Util\Crypto; function hostxrd_init(App $a) @@ -25,7 +26,7 @@ function hostxrd_init(App $a) '$zhost' => $a->get_hostname(), '$zroot' => System::baseUrl(), '$domain' => System::baseUrl(), - '$bigkey' => Crypto::salmonKey(Config::get('system', 'site_pubkey'))) + '$bigkey' => Salmon::salmonKey(Config::get('system', 'site_pubkey'))) ); exit(); diff --git a/mod/xrd.php b/mod/xrd.php index 599ee3794b..363994a8d4 100644 --- a/mod/xrd.php +++ b/mod/xrd.php @@ -5,7 +5,7 @@ use Friendica\App; use Friendica\Core\System; use Friendica\Database\DBM; -use Friendica\Util\Crypto; +use Friendica\Protocol\Salmon; function xrd_init(App $a) { @@ -58,7 +58,7 @@ function xrd_init(App $a) function xrd_json($a, $uri, $alias, $profile_url, $r) { - $salmon_key = Crypto::salmonKey($r['spubkey']); + $salmon_key = Salmon::salmonKey($r['spubkey']); header('Access-Control-Allow-Origin: *'); header("Content-type: application/json; charset=utf-8"); @@ -84,7 +84,7 @@ function xrd_json($a, $uri, $alias, $profile_url, $r) function xrd_xml($a, $uri, $alias, $profile_url, $r) { - $salmon_key = Crypto::salmonKey($r['spubkey']); + $salmon_key = Salmon::salmonKey($r['spubkey']); header('Access-Control-Allow-Origin: *'); header("Content-type: text/xml"); diff --git a/src/Protocol/Salmon.php b/src/Protocol/Salmon.php index 38a88c14af..bf349a6808 100644 --- a/src/Protocol/Salmon.php +++ b/src/Protocol/Salmon.php @@ -106,7 +106,7 @@ class Salmon $data_type = 'application/atom+xml'; $encoding = 'base64url'; $algorithm = 'RSA-SHA256'; - $keyhash = base64url_encode(hash('sha256', Crypto::salmonKey($owner['spubkey'])), true); + $keyhash = base64url_encode(hash('sha256', self::salmonKey($owner['spubkey'])), true); $precomputed = '.' . base64url_encode($data_type) . '.' . base64url_encode($encoding) . '.' . base64url_encode($algorithm); @@ -200,4 +200,14 @@ class Salmon return (($return_code >= 200) && ($return_code < 300)) ? 0 : 1; } + + /** + * @param string $pubkey public key + * @return string + */ + public static function salmonKey($pubkey) + { + self::pemToMe($pubkey, $m, $e); + return 'RSA' . '.' . base64url_encode($m, true) . '.' . base64url_encode($e, true); + } } diff --git a/src/Util/Crypto.php b/src/Util/Crypto.php index 677697b1ec..d6dbbd8b6b 100644 --- a/src/Util/Crypto.php +++ b/src/Util/Crypto.php @@ -215,16 +215,6 @@ class Crypto return $key; } - /** - * @param string $pubkey public key - * @return string - */ - public static function salmonKey($pubkey) - { - self::pemToMe($pubkey, $m, $e); - return 'RSA' . '.' . base64url_encode($m, true) . '.' . base64url_encode($e, true); - } - /** * @param integer $bits number of bits * @return mixed