]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/PublicRSAKey.php
Use rawContent for Special Options to avoid a protected options() method
[friendica.git] / src / Module / PublicRSAKey.php
index 3d0423688f3d68803f04dbb65d2147b440c208f5..d803de754ea2c06a012125e73e236d4a87b39ab9 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
 
 namespace Friendica\Module;
 
-use ASN_BASE;
 use Friendica\BaseModule;
 use Friendica\DI;
 use Friendica\Model\User;
 use Friendica\Network\HTTPException\BadRequestException;
+use Friendica\Util\Crypto;
+use Friendica\Util\Strings;
 
 /**
  * prints the public RSA key of a user
  */
 class PublicRSAKey extends BaseModule
 {
-       public static function rawContent(array $parameters = [])
+       protected function rawContent(array $request = [])
        {
-               $app = DI::app();
-
-               // @TODO: Replace with parameter from router
-               if ($app->argc !== 2) {
+               if (empty($this->parameters['nick'])) {
                        throw new BadRequestException();
                }
 
-               // @TODO: Replace with parameter from router
-               $nick = $app->argv[1];
+               $nick = $this->parameters['nick'];
 
                $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;
+               Crypto::pemToMe($user['spubkey'], $modulus, $exponent);
 
                header('Content-type: application/magic-public-key');
-               echo 'RSA' . '.' . $m . '.' . $e;
+               echo 'RSA' . '.' . Strings::base64UrlEncode($modulus, true) . '.' . Strings::base64UrlEncode($exponent, true);
 
                exit();
        }