Improve key handling

This commit is contained in:
robert dennis
2026-06-28 17:52:22 -04:00
parent ace8effd07
commit ea3b492dd5
6 changed files with 132 additions and 12 deletions
@@ -8,6 +8,7 @@ use Pterodactyl\Models\Server;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Facades\Activity;
use Pterodactyl\Models\Permission;
use Pterodactyl\Models\UserSSHKey;
use phpseclib3\Crypt\PublicKeyLoader;
use Pterodactyl\Http\Controllers\Controller;
use phpseclib3\Exception\NoKeyLoadedException;
@@ -55,10 +56,14 @@ class SftpAuthenticationController extends Controller
}
} else {
$key = null;
try {
$key = PublicKeyLoader::loadPublicKey(trim($request->input('password')));
} catch (NoKeyLoadedException) {
// do nothing
$publicKey = trim($request->input('password'));
if (UserSSHKey::isSupportedPublicKeyMaterial($publicKey)) {
try {
$key = PublicKeyLoader::loadPublicKey($publicKey);
} catch (NoKeyLoadedException) {
// do nothing
}
}
if (!$key || !$user->sshKeys()->where('fingerprint', $key->getFingerprint('sha256'))->exists()) {