|
|
|
@ -47,20 +47,31 @@ class Server extends Main
|
|
|
|
|
/** @var CA $ca */
|
|
|
|
|
$ca = $this->get('ca');
|
|
|
|
|
|
|
|
|
|
$data['signature'] = $ca->signWithCA($server->getFingerprint());
|
|
|
|
|
$data['signature'] = bin2hex($ca->signWithCA($server->getFingerprint()));
|
|
|
|
|
|
|
|
|
|
$json = json_encode($data);
|
|
|
|
|
|
|
|
|
|
$password = bin2hex(openssl_random_pseudo_bytes(32));
|
|
|
|
|
$pubKey = openssl_get_publickey($server->getPublicKey());
|
|
|
|
|
|
|
|
|
|
$success = openssl_public_encrypt($json, $crypted, $pubKey, OPENSSL_NO_PADDING);
|
|
|
|
|
$success = openssl_public_encrypt($password, $crypted, $pubKey, OPENSSL_PKCS1_PADDING);
|
|
|
|
|
|
|
|
|
|
if (!$success) {
|
|
|
|
|
throw new \Exception('Encrypting data failed: ' . openssl_error_string() . openssl_error_string());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->get('logger')->addDebug('Password: ' . $password);
|
|
|
|
|
|
|
|
|
|
$body = [
|
|
|
|
|
bin2hex($crypted),
|
|
|
|
|
bin2hex(openssl_encrypt($server->getCertificate(), 'aes-256-cbc', $password, 'help'))
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$this->get('logger')->addDebug('Help: ' . var_export([$json, $body], true));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $client->post('http://' . $server->getExternalIp() . ':' . static::MANAGEMENT_PORT . $path, [
|
|
|
|
|
'body' => $crypted
|
|
|
|
|
'json' => $body
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|