From 9f0bbd96be8b4b4995cc81ae7700e38ccb2cfadd Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sun, 5 May 2019 19:02:19 +0200 Subject: [PATCH] Move mod/modexp to src/Module/PublicRSAKey --- mod/modexp.php | 36 ---------------------------- src/App/Router.php | 1 + src/Module/PublicRSAKey.php | 47 +++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 36 deletions(-) delete mode 100644 mod/modexp.php create mode 100644 src/Module/PublicRSAKey.php diff --git a/mod/modexp.php b/mod/modexp.php deleted file mode 100644 index cae91c4648..0000000000 --- a/mod/modexp.php +++ /dev/null @@ -1,36 +0,0 @@ -argc != 2) - exit(); - - $nick = $a->argv[1]; - $r = q("SELECT `spubkey` FROM `user` WHERE `nickname` = '%s' LIMIT 1", - DBA::escape($nick) - ); - - if (! DBA::isResult($r)) { - exit(); - } - - $lines = explode("\n",$r[0]['spubkey']); - unset($lines[0]); - unset($lines[count($lines)]); - $x = base64_decode(implode('',$lines)); - - $r = ASN_BASE::parseASNString($x); - - $m = $r[0]->asnData[1]->asnData[0]->asnData[0]->asnData; - $e = $r[0]->asnData[1]->asnData[0]->asnData[1]->asnData; - - header("Content-type: application/magic-public-key"); - echo 'RSA' . '.' . $m . '.' . $e; - - exit(); - -} - diff --git a/src/App/Router.php b/src/App/Router.php index 1dffb6b406..8826245451 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -139,6 +139,7 @@ class Router $this->routeCollector->addRoute(['GET', 'POST'], '/logout', Module\Logout::class); $this->routeCollector->addRoute(['GET'], '/magic', Module\Magic::class); $this->routeCollector->addRoute(['GET'], '/manifest', Module\Manifest::class); + $this->routeCollector->addRoute(['GET'], '/modexp/{nick}', Module\PublicRSAKey::class); $this->routeCollector->addRoute(['GET'], '/nodeinfo/1.0', Module\NodeInfo::class); $this->routeCollector->addRoute(['GET'], '/nogroup', Module\Group::class); $this->routeCollector->addRoute(['GET'], '/objects/{guid}', Module\Objects::class); diff --git a/src/Module/PublicRSAKey.php b/src/Module/PublicRSAKey.php new file mode 100644 index 0000000000..ed099616ad --- /dev/null +++ b/src/Module/PublicRSAKey.php @@ -0,0 +1,47 @@ +argc !== 2) { + throw new BadRequestException(); + } + + // @TODO: Replace with parameter from router + $nick = $app->argv[1]; + + $user = User::getByNickname($nick, ['spubkey']); + if (empty($user) || empty($user['spubkey'])) { + throw new BadRequestException(); + } + + $lines = explode("\n", $user['spubkey']); + unset($lines[0]); + unset($lines[count($lines)]); + + $asnString = base64_decode(implode('', $lines)); + $asnBase = ASN_BASE::parseASNString($asnString); + + $m = $asnBase[0]->asnData[1]->asnData[0]->asnData[0]->asnData; + $e = $asnBase[0]->asnData[1]->asnData[0]->asnData[1]->asnData; + + header('Content-type: application/magic-public-key'); + echo 'RSA' . '.' . $m . '.' . $e; + + exit(); + } +} -- 2.39.5