prepare for updater

This commit is contained in:
Minecon724 2024-06-13 17:20:07 +02:00
parent 8abb6cff93
commit 6ee1aa5deb
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
5 changed files with 80 additions and 68 deletions

View file

@ -1,68 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>eu.m724</groupId>
<artifactId>realweather</artifactId>
<version>0.9-SNAPSHOT</version>
<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>eu.m724:wtapi</include>
<include>org.java-websocket:Java-WebSocket</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>eu.m724:*</artifact>
<excludes>
<exclude>META-INF/MANIFEST.MF</exclude>
</excludes>
</filter>
</filters>
<minimizeJar>true</minimizeJar>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>724rocks</id>
<url>https://git.724.rocks/api/packages/Minecon724/maven</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.20.6-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
</properties>
</project>

28
pom.xml
View file

@ -7,6 +7,9 @@
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<jarsigner.keystore>${project.basedir}/testkeystore</jarsigner.keystore>
<jarsigner.alias>testkey</jarsigner.alias>
<jarsigner.storepass>123456</jarsigner.storepass>
</properties>
<repositories>
@ -68,10 +71,35 @@
</filter>
</filters>
<minimizeJar>true</minimizeJar>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>sign</id>
<goals>
<goal>sign</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<keystore>${jarsigner.keystore}</keystore>
<alias>${jarsigner.alias}</alias>
<storepass>${jarsigner.storepass}</storepass>
</configuration>
</plugin>
</plugins>
</build>

View file

@ -17,6 +17,7 @@ import eu.m724.realweather.commands.LocalTimeCommand;
import eu.m724.realweather.mapper.Mapper;
import eu.m724.realweather.mapper.MapperConfig;
import eu.m724.realweather.object.UserException;
import eu.m724.realweather.sign.SignatureValidator;
import eu.m724.realweather.thunder.ThunderConfig;
import eu.m724.realweather.thunder.ThunderMaster;
import eu.m724.realweather.time.TimeConfig;
@ -36,6 +37,17 @@ public class RealWeatherPlugin extends JavaPlugin {
public void onEnable() {
logger = getLogger();
// TODO remove these lines
SignatureValidator signatureValidator = new SignatureValidator(this);
logger.info("Signature of this JAR: " + signatureValidator.getCertificate().getSubjectX500Principal().getName());
if (!signatureValidator.isValid()) {
logger.severe("Key is not valid");
getServer().getPluginManager().disablePlugin(this);
return;
}
// TODO remove those lines
File dataFolder = getDataFolder();
File modulesFolder = new File("modules");
modulesFolder.mkdir();

View file

@ -0,0 +1,40 @@
package eu.m724.realweather.sign;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.cert.X509Certificate;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;
import java.util.Base64;
import eu.m724.realweather.RealWeatherPlugin;
// TODO rework this for updater
public class SignatureValidator {
public RealWeatherPlugin plugin;
public static final String encodedPublicKey = "MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAptv/9qIJXrs/4T1MOkY1QPU/TuLsyCsJdoA2PIO1qdS3nRJBPgkRf2sK6nG1VhOaUHLXoj8lZtQQLcY76CNLqFGFmimo7RDnJjHpxHUzI9pKZJOQ9sEVCDFtoLQiit23t6MAO7GBjJXMNFLonxyay6pTABJo3VYyjg2bE4kd1wjg73RPMQY+zykaRQBUE167PAVkmuYxJK680EYmZph9kQTS12autU2qGFTvsPbmmdhtF7Xy8u84CtEucgRT9HSh0y8MuC0esMGhZtB9gsWcGET763DHtArEMekBnjByb3k+gGiG0Y1K9ygBn+nNVKP66KJGCWFuno8xy+LNiZKX4pUnrJcTyLvZg7PvjdZTye54PKkAAOACAbcFBiat38Zes5ZOKZIBEjC2IXbhfySoOn5WAk+XPsm3gVlgO9d51iOVDDBx5MCqq802lOyIGog1BlbhnGZ2+cSvFo7ZWpF0f93uG5UKBqRF+Q9cPA36SMUAoQ2DWFEZOYXwFgCXxVvFAgMBAAE=";
public SignatureValidator(RealWeatherPlugin plugin) {
this.plugin = plugin;
}
public X509Certificate getCertificate() {
return (X509Certificate) plugin.getClass().getProtectionDomain().getCodeSource().getCertificates()[0];
}
public boolean isValid() {
PublicKey currentPublicKey = getCertificate().getPublicKey();
PublicKey expectedPublicKey = null;
try {
X509EncodedKeySpec spec = new X509EncodedKeySpec(Base64.getDecoder().decode(encodedPublicKey));
expectedPublicKey = KeyFactory.getInstance("RSA").generatePublic(spec);
} catch (InvalidKeySpecException | NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return expectedPublicKey.equals(currentPublicKey);
}
}

BIN
testkeystore Normal file

Binary file not shown.