mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
[FIX] Функциональность сертификатов обернута
This commit is contained in:
parent
d0c16f2835
commit
ed239cc3c2
1 changed files with 41 additions and 30 deletions
|
@ -157,6 +157,7 @@ public AuthProviderPair getAuthProviderPair() {
|
|||
|
||||
public String whitelistRejectString;
|
||||
public LauncherConf launcher;
|
||||
public CertificateConf certificate;
|
||||
|
||||
public String startScript;
|
||||
|
||||
|
@ -269,6 +270,11 @@ public static class ExeConf {
|
|||
public String txtProductVersion;
|
||||
}
|
||||
|
||||
public static class CertificateConf
|
||||
{
|
||||
public boolean enabled;
|
||||
}
|
||||
|
||||
public static class NettyUpdatesBind {
|
||||
public String url;
|
||||
public boolean zip;
|
||||
|
@ -608,39 +614,41 @@ public LaunchServer(Path dir, boolean testEnv, String[] args) throws IOException
|
|||
certificateManager = new CertificateManager();
|
||||
//Generate or set new Certificate API
|
||||
certificateManager.orgName = config.projectName;
|
||||
if(IOHelper.isFile(caCertFile) && IOHelper.isFile(caKeyFile))
|
||||
if(config.certificate != null && config.certificate.enabled)
|
||||
{
|
||||
certificateManager.ca = certificateManager.readCertificate(caCertFile);
|
||||
certificateManager.caKey = certificateManager.readPrivateKey(caKeyFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
try {
|
||||
certificateManager.generateCA();
|
||||
certificateManager.writeCertificate(caCertFile, certificateManager.ca);
|
||||
certificateManager.writePrivateKey(caKeyFile, certificateManager.caKey);
|
||||
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | OperatorCreationException e) {
|
||||
LogHelper.error(e);
|
||||
if(IOHelper.isFile(caCertFile) && IOHelper.isFile(caKeyFile))
|
||||
{
|
||||
certificateManager.ca = certificateManager.readCertificate(caCertFile);
|
||||
certificateManager.caKey = certificateManager.readPrivateKey(caKeyFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
try {
|
||||
certificateManager.generateCA();
|
||||
certificateManager.writeCertificate(caCertFile, certificateManager.ca);
|
||||
certificateManager.writePrivateKey(caKeyFile, certificateManager.caKey);
|
||||
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | OperatorCreationException e) {
|
||||
LogHelper.error(e);
|
||||
}
|
||||
}
|
||||
if(IOHelper.isFile(serverCertFile) && IOHelper.isFile(serverKeyFile))
|
||||
{
|
||||
certificateManager.server = certificateManager.readCertificate(serverCertFile);
|
||||
certificateManager.serverKey = certificateManager.readPrivateKey(serverKeyFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
try {
|
||||
KeyPair pair = certificateManager.generateKeyPair();
|
||||
certificateManager.server = certificateManager.generateCertificate(config.projectName.concat(" Server"), pair.getPublic());
|
||||
certificateManager.serverKey = PrivateKeyFactory.createKey(pair.getPrivate().getEncoded());
|
||||
certificateManager.writePrivateKey(serverKeyFile, pair.getPrivate());
|
||||
certificateManager.writeCertificate(serverCertFile, certificateManager.server);
|
||||
} catch (InvalidAlgorithmParameterException | NoSuchAlgorithmException | OperatorCreationException e) {
|
||||
LogHelper.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(IOHelper.isFile(serverCertFile) && IOHelper.isFile(serverKeyFile))
|
||||
{
|
||||
certificateManager.server = certificateManager.readCertificate(serverCertFile);
|
||||
certificateManager.serverKey = certificateManager.readPrivateKey(serverKeyFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
try {
|
||||
KeyPair pair = certificateManager.generateKeyPair();
|
||||
certificateManager.server = certificateManager.generateCertificate(config.projectName.concat(" Server"), pair.getPublic());
|
||||
certificateManager.serverKey = PrivateKeyFactory.createKey(pair.getPrivate().getEncoded());
|
||||
certificateManager.writePrivateKey(serverKeyFile, pair.getPrivate());
|
||||
certificateManager.writeCertificate(serverCertFile, certificateManager.server);
|
||||
} catch (InvalidAlgorithmParameterException | NoSuchAlgorithmException | OperatorCreationException e) {
|
||||
LogHelper.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
GarbageManager.registerNeedGC(sessionManager);
|
||||
reloadManager.registerReloadable("launchServer", this);
|
||||
registerObject("permissionsHandler", config.permissionsHandler);
|
||||
|
@ -816,6 +824,9 @@ private void generateConfigIfNotExists(boolean testEnv) throws IOException {
|
|||
newConfig.launcher.stripLineNumbers = true;
|
||||
newConfig.launcher.proguardGenMappings = true;
|
||||
|
||||
newConfig.certificate = new CertificateConf();
|
||||
newConfig.certificate.enabled = false;
|
||||
|
||||
newConfig.components = new HashMap<>();
|
||||
AuthLimiterComponent authLimiterComponent = new AuthLimiterComponent();
|
||||
authLimiterComponent.rateLimit = 3;
|
||||
|
|
Loading…
Reference in a new issue