Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions plugins/yggdrasil-api/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@
Route::put('{uuid}/{type}', 'ProfileController@uploadTexture');
Route::delete('{uuid}/{type}', 'ProfileController@resetTexture');
});

Route::get('minecraftservices/publickeys', 'ConfigController@getPublicKeys');
49 changes: 37 additions & 12 deletions plugins/yggdrasil-api/src/Controllers/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,7 @@ public function hello(Request $request, PluginManager $pluginManager)
$request->getHost(),
]))));

$privateKey = openssl_pkey_get_private(option('ygg_private_key'));

if (!$privateKey) {
throw new IllegalArgumentException(trans('Yggdrasil::config.rsa.invalid'));
}

$keyData = openssl_pkey_get_details($privateKey);

if ($keyData['bits'] < 4096) {
throw new IllegalArgumentException(trans('Yggdrasil::config.rsa.length'));
}
$signaturePublickey = $this->getPrivateKey();

$result = [
'meta' => [
Expand All @@ -100,7 +90,7 @@ public function hello(Request $request, PluginManager $pluginManager)
'feature.non_email_login' => true,
],
'skinDomains' => $skinDomains,
'signaturePublickey' => $keyData['key'],
'signaturePublickey' => $signaturePublickey,
];

if (!optional($pluginManager->get('disable-registration'))->isEnabled()) {
Expand Down Expand Up @@ -129,4 +119,39 @@ public function generate()
return json('Error: '.$e->getMessage(), 1);
}
}

public function getPublicKeys()
{
$keyData = $this->getPrivateKey();

$publicKeyBase64 = str_replace(
array("-----BEGIN PUBLIC KEY-----", "-----END PUBLIC KEY-----", "\n"),
'',
$keyData
);

$result = [
'profilePropertyKeys' => [['publicKey' => $publicKeyBase64]],
'playerCertificateKeys' => [['publicKey' => $publicKeyBase64]],
];

return json($result);
}

public function getPrivateKey(): string
{
$privateKey = openssl_pkey_get_private(option('ygg_private_key'));

if (!$privateKey) {
throw new IllegalArgumentException(trans('Yggdrasil::config.rsa.invalid'));
}

$keyData = openssl_pkey_get_details($privateKey);

if ($keyData['bits'] < 4096) {
throw new IllegalArgumentException(trans('Yggdrasil::config.rsa.length'));
}

return $keyData['key'];
}
}
2 changes: 2 additions & 0 deletions plugins/yggdrasil-connect/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@
Route::put('{uuid}/{type}', 'ProfileController@uploadTexture');
Route::delete('{uuid}/{type}', 'ProfileController@resetTexture');
});

Route::get('minecraftservices/publickeys', 'ConfigController@getPublicKeys');
49 changes: 37 additions & 12 deletions plugins/yggdrasil-connect/src/Controllers/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,7 @@ public function hello(Request $request, PluginManager $pluginManager): JsonRespo
$request->getHost(),
]))));

$privateKey = openssl_pkey_get_private(option('ygg_private_key'));

if (!$privateKey) {
throw new IllegalArgumentException(trans('LittleSkin\\YggdrasilConnect::config.rsa.invalid'));
}

$keyData = openssl_pkey_get_details($privateKey);

if ($keyData['bits'] < 4096) {
throw new IllegalArgumentException(trans('LittleSkin\\YggdrasilConnect::config.rsa.length'));
}
$signaturePublickey = $this->getPrivateKey();

$result = [
'meta' => [
Expand All @@ -125,7 +115,7 @@ public function hello(Request $request, PluginManager $pluginManager): JsonRespo
],
],
'skinDomains' => $skinDomains,
'signaturePublickey' => $keyData['key'],
'signaturePublickey' => $signaturePublickey,
];

if (!optional($pluginManager->get('disable-registration'))->isEnabled()) {
Expand Down Expand Up @@ -163,4 +153,39 @@ public function generate(): JsonResponse
return json('Error: '.$e->getMessage(), 1);
}
}

public function getPublicKeys(): JsonResponse
{
$keyData = $this->getPrivateKey();

$publicKeyBase64 = str_replace(
array("-----BEGIN PUBLIC KEY-----", "-----END PUBLIC KEY-----", "\n"),
'',
$keyData
);

$result = [
'profilePropertyKeys' => [['publicKey' => $publicKeyBase64]],
'playerCertificateKeys' => [['publicKey' => $publicKeyBase64]],
];

return json($result);
}

public function getPrivateKey(): string
{
$privateKey = openssl_pkey_get_private(option('ygg_private_key'));

if (!$privateKey) {
throw new IllegalArgumentException(trans('LittleSkin\\YggdrasilConnect::config.rsa.invalid'));
}

$keyData = openssl_pkey_get_details($privateKey);

if ($keyData['bits'] < 4096) {
throw new IllegalArgumentException(trans('LittleSkin\\YggdrasilConnect::config.rsa.length'));
}

return $keyData['key'];
}
}
Loading