mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-05 13:55:44 -05:00
Improve key handling
This commit is contained in:
@@ -44,6 +44,20 @@ class UserSSHKey extends Model
|
||||
use SoftDeletes;
|
||||
|
||||
public const RESOURCE_NAME = 'ssh_key';
|
||||
public const PUBLIC_KEY_MAX_LENGTH = 16384;
|
||||
|
||||
protected const PUBLIC_KEY_PREFIXES = [
|
||||
'ssh-rsa ',
|
||||
'ssh-ed25519 ',
|
||||
'ecdsa-sha2-',
|
||||
'sk-ssh-ed25519@openssh.com ',
|
||||
'sk-ecdsa-sha2-nistp256@openssh.com ',
|
||||
'-----BEGIN PUBLIC KEY-----',
|
||||
'-----BEGIN RSA PUBLIC KEY-----',
|
||||
'-----BEGIN EC PUBLIC KEY-----',
|
||||
'-----BEGIN DSA PUBLIC KEY-----',
|
||||
'---- BEGIN SSH2 PUBLIC KEY ----',
|
||||
];
|
||||
|
||||
protected $table = 'user_ssh_keys';
|
||||
|
||||
@@ -56,9 +70,26 @@ class UserSSHKey extends Model
|
||||
public static array $validationRules = [
|
||||
'name' => ['required', 'string'],
|
||||
'fingerprint' => ['required', 'string'],
|
||||
'public_key' => ['required', 'string'],
|
||||
'public_key' => ['required', 'string', 'max:' . self::PUBLIC_KEY_MAX_LENGTH],
|
||||
];
|
||||
|
||||
public static function isSupportedPublicKeyMaterial(string $value): bool
|
||||
{
|
||||
$value = trim($value);
|
||||
|
||||
if ($value === '' || strlen($value) > self::PUBLIC_KEY_MAX_LENGTH || str_contains($value, "\0")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (self::PUBLIC_KEY_PREFIXES as $prefix) {
|
||||
if (str_starts_with($value, $prefix)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\Pterodactyl\Models\User, $this>
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user