[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 String whitelistRejectString;
public LauncherConf launcher; public LauncherConf launcher;
public CertificateConf certificate;
public String startScript; public String startScript;
@ -269,6 +270,11 @@ public static class ExeConf {
public String txtProductVersion; public String txtProductVersion;
} }
public static class CertificateConf
{
public boolean enabled;
}
public static class NettyUpdatesBind { public static class NettyUpdatesBind {
public String url; public String url;
public boolean zip; public boolean zip;
@ -608,39 +614,41 @@ public LaunchServer(Path dir, boolean testEnv, String[] args) throws IOException
certificateManager = new CertificateManager(); certificateManager = new CertificateManager();
//Generate or set new Certificate API //Generate or set new Certificate API
certificateManager.orgName = config.projectName; certificateManager.orgName = config.projectName;
if(IOHelper.isFile(caCertFile) && IOHelper.isFile(caKeyFile)) if(config.certificate != null && config.certificate.enabled)
{ {
certificateManager.ca = certificateManager.readCertificate(caCertFile); if(IOHelper.isFile(caCertFile) && IOHelper.isFile(caKeyFile))
certificateManager.caKey = certificateManager.readPrivateKey(caKeyFile); {
} certificateManager.ca = certificateManager.readCertificate(caCertFile);
else certificateManager.caKey = certificateManager.readPrivateKey(caKeyFile);
{ }
try { else
certificateManager.generateCA(); {
certificateManager.writeCertificate(caCertFile, certificateManager.ca); try {
certificateManager.writePrivateKey(caKeyFile, certificateManager.caKey); certificateManager.generateCA();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | OperatorCreationException e) { certificateManager.writeCertificate(caCertFile, certificateManager.ca);
LogHelper.error(e); 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); GarbageManager.registerNeedGC(sessionManager);
reloadManager.registerReloadable("launchServer", this); reloadManager.registerReloadable("launchServer", this);
registerObject("permissionsHandler", config.permissionsHandler); registerObject("permissionsHandler", config.permissionsHandler);
@ -816,6 +824,9 @@ private void generateConfigIfNotExists(boolean testEnv) throws IOException {
newConfig.launcher.stripLineNumbers = true; newConfig.launcher.stripLineNumbers = true;
newConfig.launcher.proguardGenMappings = true; newConfig.launcher.proguardGenMappings = true;
newConfig.certificate = new CertificateConf();
newConfig.certificate.enabled = false;
newConfig.components = new HashMap<>(); newConfig.components = new HashMap<>();
AuthLimiterComponent authLimiterComponent = new AuthLimiterComponent(); AuthLimiterComponent authLimiterComponent = new AuthLimiterComponent();
authLimiterComponent.rateLimit = 3; authLimiterComponent.rateLimit = 3;