@@ -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}
0 commit comments