[FIX] Функциональность сертификатов обернута

This commit is contained in:
Gravit 2019-08-13 21:13:51 +07:00
parent d0c16f2835
commit ed239cc3c2
No known key found for this signature in database
GPG key ID: 061981E1E85D3216

View file

@ -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;