]> git.mxchange.org Git - friendica.git/commitdiff
Move mod/modexp to src/Module/PublicRSAKey
authorPhilipp Holzer <admin@philipp.info>
Sun, 5 May 2019 17:02:19 +0000 (19:02 +0200)
committerPhilipp Holzer <admin@philipp.info>
Sun, 5 May 2019 17:02:19 +0000 (19:02 +0200)
mod/modexp.php [deleted file]
src/App/Router.php
src/Module/PublicRSAKey.php [new file with mode: 0644]

diff --git a/mod/modexp.php b/mod/modexp.php
deleted file mode 100644 (file)
index cae91c4..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-<?php
-
-use Friendica\App;
-use Friendica\Database\DBA;
-
-function modexp_init(App $a) {
-
-       if($a->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();
-
-}
-
index 1dffb6b406f0d3b22bd75880710bd56a5eee8437..88262454518d83ee3288716d20d8a51615317a0f 100644 (file)
@@ -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 (file)
index 0000000..ed09961
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+
+namespace Friendica\Module;
+
+use ASN_BASE;
+use Friendica\BaseModule;
+use Friendica\Model\User;
+use Friendica\Network\HTTPException\BadRequestException;
+
+/**
+ * prints the public RSA key of a user
+ */
+class PublicRSAKey extends BaseModule
+{
+       public static function rawContent()
+       {
+               $app = self::getApp();
+
+               // @TODO: Replace with parameter from router
+               if ($app->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();
+       }
+}