Move mod/modexp to src/Module/PublicRSAKey
This commit is contained in:
parent
155d541860
commit
9f0bbd96be
|
@ -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();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -139,6 +139,7 @@ class Router
|
||||||
$this->routeCollector->addRoute(['GET', 'POST'], '/logout', Module\Logout::class);
|
$this->routeCollector->addRoute(['GET', 'POST'], '/logout', Module\Logout::class);
|
||||||
$this->routeCollector->addRoute(['GET'], '/magic', Module\Magic::class);
|
$this->routeCollector->addRoute(['GET'], '/magic', Module\Magic::class);
|
||||||
$this->routeCollector->addRoute(['GET'], '/manifest', Module\Manifest::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'], '/nodeinfo/1.0', Module\NodeInfo::class);
|
||||||
$this->routeCollector->addRoute(['GET'], '/nogroup', Module\Group::class);
|
$this->routeCollector->addRoute(['GET'], '/nogroup', Module\Group::class);
|
||||||
$this->routeCollector->addRoute(['GET'], '/objects/{guid}', Module\Objects::class);
|
$this->routeCollector->addRoute(['GET'], '/objects/{guid}', Module\Objects::class);
|
||||||
|
|
47
src/Module/PublicRSAKey.php
Normal file
47
src/Module/PublicRSAKey.php
Normal file
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue