feat: able to make rsa/ed ssh keys
This commit is contained in:
parent
82f74e2264
commit
22a1d3882e
@ -26,7 +26,7 @@ class Create extends Component
|
|||||||
'value' => 'private Key',
|
'value' => 'private Key',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function generateNewKey()
|
public function generateNewRSAKey()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->rateLimit(10);
|
$this->rateLimit(10);
|
||||||
@ -37,6 +37,17 @@ class Create extends Component
|
|||||||
return handleError($e, $this);
|
return handleError($e, $this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public function generateNewEDKey()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$this->rateLimit(10);
|
||||||
|
$this->name = generate_random_name();
|
||||||
|
$this->description = 'Created by Coolify';
|
||||||
|
['private' => $this->value, 'public' => $this->publicKey] = generateSSHKey('ed25519');
|
||||||
|
} catch(\Throwable $e) {
|
||||||
|
return handleError($e, $this);
|
||||||
|
}
|
||||||
|
}
|
||||||
public function updated($updateProperty)
|
public function updated($updateProperty)
|
||||||
{
|
{
|
||||||
if ($updateProperty === 'value') {
|
if ($updateProperty === 'value') {
|
||||||
|
@ -39,6 +39,7 @@ use Lcobucci\JWT\Encoding\JoseEncoder;
|
|||||||
use Lcobucci\JWT\Signer\Key\InMemory;
|
use Lcobucci\JWT\Signer\Key\InMemory;
|
||||||
use Lcobucci\JWT\Signer\Hmac\Sha256;
|
use Lcobucci\JWT\Signer\Hmac\Sha256;
|
||||||
use Lcobucci\JWT\Token\Builder;
|
use Lcobucci\JWT\Token\Builder;
|
||||||
|
use phpseclib3\Crypt\EC;
|
||||||
use Poliander\Cron\CronExpression;
|
use Poliander\Cron\CronExpression;
|
||||||
use Visus\Cuid2\Cuid2;
|
use Visus\Cuid2\Cuid2;
|
||||||
use phpseclib3\Crypt\RSA;
|
use phpseclib3\Crypt\RSA;
|
||||||
@ -165,13 +166,22 @@ function generate_random_name(?string $cuid = null): string
|
|||||||
}
|
}
|
||||||
return Str::kebab("{$generator->getName()}-$cuid");
|
return Str::kebab("{$generator->getName()}-$cuid");
|
||||||
}
|
}
|
||||||
function generateSSHKey()
|
function generateSSHKey(string $type = 'rsa')
|
||||||
{
|
{
|
||||||
$key = RSA::createKey();
|
if ($type === 'rsa') {
|
||||||
return [
|
$key = RSA::createKey();
|
||||||
'private' => $key->toString('PKCS1'),
|
return [
|
||||||
'public' => $key->getPublicKey()->toString('OpenSSH', ['comment' => 'coolify-generated-ssh-key'])
|
'private' => $key->toString('PKCS1'),
|
||||||
];
|
'public' => $key->getPublicKey()->toString('OpenSSH', ['comment' => 'coolify-generated-ssh-key'])
|
||||||
|
];
|
||||||
|
} else if ($type === 'ed25519') {
|
||||||
|
$key = EC::createKey('Ed25519');
|
||||||
|
return [
|
||||||
|
'private' => $key->toString('OpenSSH'),
|
||||||
|
'public' => $key->getPublicKey()->toString('OpenSSH', ['comment' => 'coolify-generated-ssh-key'])
|
||||||
|
];
|
||||||
|
}
|
||||||
|
throw new Exception('Invalid key type');
|
||||||
}
|
}
|
||||||
function formatPrivateKey(string $privateKey)
|
function formatPrivateKey(string $privateKey)
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
<div>
|
<div>
|
||||||
{{-- <div class="subtitle">Private Keys are used to connect to your servers without passwords.</div> --}}
|
<div class="pb-0 subtitle">
|
||||||
<x-forms.button class="mb-4" wire:click="generateNewKey">Generate new SSH key for me</x-forms.button>
|
<div >Private Keys are used to connect to your servers without passwords.</div>
|
||||||
|
<div class="font-bold">You should not use passphrase protected keys.</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex gap-2 mb-4">
|
||||||
|
<x-forms.button wire:click="generateNewRSAKey">Generate new RSA SSH Key</x-forms.button>
|
||||||
|
<x-forms.button wire:click="generateNewEDKey">Generate new ED25519 SSH Key</x-forms.button>
|
||||||
|
</div>
|
||||||
<form class="flex flex-col gap-2" wire:submit='createPrivateKey'>
|
<form class="flex flex-col gap-2" wire:submit='createPrivateKey'>
|
||||||
<div class="flex gap-2">
|
<div class="flex gap-2">
|
||||||
<x-forms.input id="name" label="Name" required />
|
<x-forms.input id="name" label="Name" required />
|
||||||
|
@ -26,12 +26,12 @@
|
|||||||
<h3 class="pb-4">Choose another Key</h3>
|
<h3 class="pb-4">Choose another Key</h3>
|
||||||
<div class="grid grid-cols-3 gap-2">
|
<div class="grid grid-cols-3 gap-2">
|
||||||
@forelse ($privateKeys as $private_key)
|
@forelse ($privateKeys as $private_key)
|
||||||
<div class="box group">
|
<div class="box group" wire:click='setPrivateKey({{ $private_key->id }})'>
|
||||||
<div class="flex flex-col " wire:click='setPrivateKey({{ $private_key->id }})'>
|
<div class="flex flex-col ">
|
||||||
<div class="box-title">{{ $private_key->name }}</div>
|
<div class="box-title">{{ $private_key->name }}</div>
|
||||||
<div class="box-description">{{ $private_key->description }}</div>
|
<div class="box-description">{{ $private_key->description }}</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
@empty
|
@empty
|
||||||
<div>No private keys found. </div>
|
<div>No private keys found. </div>
|
||||||
@endforelse
|
@endforelse
|
||||||
|
Loading…
x
Reference in New Issue
Block a user