Skip to content

Commit 6eb48bf

Browse files
gkchptnqzh123
andauthored
[yggdrasil-connect ]implement /minecraftservices/publickeys
* [yggdrasil-api] add mojang style public key api * [yggdrasil-connect] add mojang style public key api * Update plugins/yggdrasil-connect/src/Controllers/ConfigController.php Co-authored-by: Steven Qiu <[email protected]> * Update plugins/yggdrasil-connect/src/Controllers/ConfigController.php Co-authored-by: Steven Qiu <[email protected]> * Update plugins/yggdrasil-connect/src/Controllers/ConfigController.php Co-authored-by: Steven Qiu <[email protected]> * Update plugins/yggdrasil-api/src/Controllers/ConfigController.php Co-authored-by: Steven Qiu <[email protected]> * Update plugins/yggdrasil-api/src/Controllers/ConfigController.php Co-authored-by: Steven Qiu <[email protected]> * Update plugins/yggdrasil-api/src/Controllers/ConfigController.php Co-authored-by: Steven Qiu <[email protected]> * Update plugins/yggdrasil-api/src/Controllers/ConfigController.php Co-authored-by: Steven Qiu <[email protected]> * Update plugins/yggdrasil-connect/src/Controllers/ConfigController.php Co-authored-by: Steven Qiu <[email protected]> * Update plugins/yggdrasil-connect/src/Controllers/ConfigController.php Co-authored-by: Steven Qiu <[email protected]> * Update plugins/yggdrasil-api/src/Controllers/ConfigController.php Co-authored-by: Steven Qiu <[email protected]> --------- Co-authored-by: Steven Qiu <[email protected]>
1 parent 67c5013 commit 6eb48bf

File tree

4 files changed

+78
-24
lines changed

4 files changed

+78
-24
lines changed

plugins/yggdrasil-api/routes.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@
3434
Route::put('{uuid}/{type}', 'ProfileController@uploadTexture');
3535
Route::delete('{uuid}/{type}', 'ProfileController@resetTexture');
3636
});
37+
38+
Route::get('minecraftservices/publickeys', 'ConfigController@getPublicKeys');

plugins/yggdrasil-api/src/Controllers/ConfigController.php

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,7 @@ public function hello(Request $request, PluginManager $pluginManager)
7777
$request->getHost(),
7878
]))));
7979

80-
$privateKey = openssl_pkey_get_private(option('ygg_private_key'));
81-
82-
if (!$privateKey) {
83-
throw new IllegalArgumentException(trans('Yggdrasil::config.rsa.invalid'));
84-
}
85-
86-
$keyData = openssl_pkey_get_details($privateKey);
87-
88-
if ($keyData['bits'] < 4096) {
89-
throw new IllegalArgumentException(trans('Yggdrasil::config.rsa.length'));
90-
}
80+
$signaturePublickey = $this->getPrivateKey();
9181

9282
$result = [
9383
'meta' => [
@@ -100,7 +90,7 @@ public function hello(Request $request, PluginManager $pluginManager)
10090
'feature.non_email_login' => true,
10191
],
10292
'skinDomains' => $skinDomains,
103-
'signaturePublickey' => $keyData['key'],
93+
'signaturePublickey' => $signaturePublickey,
10494
];
10595

10696
if (!optional($pluginManager->get('disable-registration'))->isEnabled()) {
@@ -129,4 +119,39 @@ public function generate()
129119
return json('Error: '.$e->getMessage(), 1);
130120
}
131121
}
122+
123+
public function getPublicKeys()
124+
{
125+
$keyData = $this->getPrivateKey();
126+
127+
$publicKeyBase64 = str_replace(
128+
array("-----BEGIN PUBLIC KEY-----", "-----END PUBLIC KEY-----", "\n"),
129+
'',
130+
$keyData
131+
);
132+
133+
$result = [
134+
'profilePropertyKeys' => [['publicKey' => $publicKeyBase64]],
135+
'playerCertificateKeys' => [['publicKey' => $publicKeyBase64]],
136+
];
137+
138+
return json($result);
139+
}
140+
141+
public function getPrivateKey(): string
142+
{
143+
$privateKey = openssl_pkey_get_private(option('ygg_private_key'));
144+
145+
if (!$privateKey) {
146+
throw new IllegalArgumentException(trans('Yggdrasil::config.rsa.invalid'));
147+
}
148+
149+
$keyData = openssl_pkey_get_details($privateKey);
150+
151+
if ($keyData['bits'] < 4096) {
152+
throw new IllegalArgumentException(trans('Yggdrasil::config.rsa.length'));
153+
}
154+
155+
return $keyData['key'];
156+
}
132157
}

plugins/yggdrasil-connect/routes.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@
4343
Route::put('{uuid}/{type}', 'ProfileController@uploadTexture');
4444
Route::delete('{uuid}/{type}', 'ProfileController@resetTexture');
4545
});
46+
47+
Route::get('minecraftservices/publickeys', 'ConfigController@getPublicKeys');

plugins/yggdrasil-connect/src/Controllers/ConfigController.php

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,7 @@ public function hello(Request $request, PluginManager $pluginManager): JsonRespo
103103
$request->getHost(),
104104
]))));
105105

106-
$privateKey = openssl_pkey_get_private(option('ygg_private_key'));
107-
108-
if (!$privateKey) {
109-
throw new IllegalArgumentException(trans('LittleSkin\\YggdrasilConnect::config.rsa.invalid'));
110-
}
111-
112-
$keyData = openssl_pkey_get_details($privateKey);
113-
114-
if ($keyData['bits'] < 4096) {
115-
throw new IllegalArgumentException(trans('LittleSkin\\YggdrasilConnect::config.rsa.length'));
116-
}
106+
$signaturePublickey = $this->getPrivateKey();
117107

118108
$result = [
119109
'meta' => [
@@ -125,7 +115,7 @@ public function hello(Request $request, PluginManager $pluginManager): JsonRespo
125115
],
126116
],
127117
'skinDomains' => $skinDomains,
128-
'signaturePublickey' => $keyData['key'],
118+
'signaturePublickey' => $signaturePublickey,
129119
];
130120

131121
if (!optional($pluginManager->get('disable-registration'))->isEnabled()) {
@@ -163,4 +153,39 @@ public function generate(): JsonResponse
163153
return json('Error: '.$e->getMessage(), 1);
164154
}
165155
}
156+
157+
public function getPublicKeys(): JsonResponse
158+
{
159+
$keyData = $this->getPrivateKey();
160+
161+
$publicKeyBase64 = str_replace(
162+
array("-----BEGIN PUBLIC KEY-----", "-----END PUBLIC KEY-----", "\n"),
163+
'',
164+
$keyData
165+
);
166+
167+
$result = [
168+
'profilePropertyKeys' => [['publicKey' => $publicKeyBase64]],
169+
'playerCertificateKeys' => [['publicKey' => $publicKeyBase64]],
170+
];
171+
172+
return json($result);
173+
}
174+
175+
public function getPrivateKey(): string
176+
{
177+
$privateKey = openssl_pkey_get_private(option('ygg_private_key'));
178+
179+
if (!$privateKey) {
180+
throw new IllegalArgumentException(trans('LittleSkin\\YggdrasilConnect::config.rsa.invalid'));
181+
}
182+
183+
$keyData = openssl_pkey_get_details($privateKey);
184+
185+
if ($keyData['bits'] < 4096) {
186+
throw new IllegalArgumentException(trans('LittleSkin\\YggdrasilConnect::config.rsa.length'));
187+
}
188+
189+
return $keyData['key'];
190+
}
166191
}

0 commit comments

Comments
 (0)