VPS and dedicated server ordering, managed panels, SSO, billing, and launcher integration — forked from hosting infrastructure with server-focused routes and dashboard. Co-authored-by: Cursor <cursoragent@cursor.com>
35 lines
886 B
PHP
35 lines
886 B
PHP
<?php
|
|
|
|
namespace App\Services\Infrastructure;
|
|
|
|
class ContaboInfrastructureSshKeyService
|
|
{
|
|
/**
|
|
* @return array{public_key: string, private_key: string}
|
|
*/
|
|
public function generate(): array
|
|
{
|
|
$resource = openssl_pkey_new([
|
|
'private_key_bits' => 4096,
|
|
'private_key_type' => OPENSSL_KEYTYPE_RSA,
|
|
]);
|
|
|
|
if ($resource === false) {
|
|
throw new \RuntimeException('Failed to generate SSH key pair.');
|
|
}
|
|
|
|
openssl_pkey_export($resource, $privateKey);
|
|
$details = openssl_pkey_get_details($resource);
|
|
$publicKey = $details['key'] ?? '';
|
|
|
|
if ($publicKey === '') {
|
|
throw new \RuntimeException('Failed to export SSH public key.');
|
|
}
|
|
|
|
return [
|
|
'public_key' => trim($publicKey)."\n",
|
|
'private_key' => $privateKey,
|
|
];
|
|
}
|
|
}
|