-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from Nookure/dev
Dev
- Loading branch information
Showing
36 changed files
with
541 additions
and
316 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
NookureStaff-API/src/main/java/com/nookure/staff/api/annotation/PluginMessageSecretKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.nookure.staff.api.annotation; | ||
|
||
import com.google.inject.BindingAnnotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target({ElementType.FIELD, ElementType.PARAMETER}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@BindingAnnotation | ||
public @interface PluginMessageSecretKey { | ||
} |
82 changes: 82 additions & 0 deletions
82
NookureStaff-API/src/main/java/com/nookure/staff/api/config/common/PluginMessageConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.nookure.staff.api.config.common; | ||
|
||
import org.spongepowered.configurate.objectmapping.ConfigSerializable; | ||
import org.spongepowered.configurate.objectmapping.meta.Comment; | ||
import org.spongepowered.configurate.objectmapping.meta.Setting; | ||
|
||
import javax.crypto.KeyGenerator; | ||
import javax.crypto.SecretKey; | ||
import java.security.NoSuchAlgorithmException; | ||
|
||
import javax.crypto.spec.SecretKeySpec; | ||
import java.util.Base64; | ||
|
||
@ConfigSerializable | ||
public class PluginMessageConfig { | ||
@Setting | ||
public boolean enabled = false; | ||
|
||
@Setting | ||
@Comment(""" | ||
Base64-encoded encryption key for plugin messages, generated if not present, must be 128, 192, or 256 bits | ||
You should have the same key on all servers in the network | ||
""") | ||
public String encryptionKey; | ||
|
||
@Setting | ||
@Comment(""" | ||
It's a security feature to prevent players from tampering with the plugin messages | ||
if the plugin detects tampering, it will disconnect the player | ||
""") | ||
public boolean playerTamperingDetection = true; | ||
|
||
@Setting | ||
@Comment(""" | ||
The message to send to the player when tampering is detected | ||
""") | ||
public String playerTamperingDetectionMessage = "<red>Plugin message tampering detected!"; | ||
|
||
public PluginMessageConfig() { | ||
ensureEncryptionKey(256); | ||
} | ||
|
||
/** | ||
* Generates a new encryption key with the specified length. | ||
* | ||
* @param length Key length in bits (must be 128, 192, or 256) | ||
* @return Base64-encoded encryption key | ||
*/ | ||
private String generateEncryptionKey(final int length) { | ||
try { | ||
KeyGenerator keyGen = KeyGenerator.getInstance("AES"); | ||
keyGen.init(length); | ||
SecretKey secretKey = keyGen.generateKey(); | ||
return Base64.getEncoder().encodeToString(secretKey.getEncoded()); | ||
} catch (NoSuchAlgorithmException e) { | ||
throw new RuntimeException("AES algorithm is not available", e); | ||
} | ||
} | ||
|
||
/** | ||
* Retrieves the SecretKey from the stored encryption key. | ||
* | ||
* @return A SecretKey instance | ||
*/ | ||
public SecretKey getSecretKey() { | ||
if (encryptionKey == null || encryptionKey.isEmpty()) { | ||
throw new IllegalStateException("Encryption key is not set"); | ||
} | ||
|
||
byte[] decodedKey = Base64.getDecoder().decode(encryptionKey); | ||
return new SecretKeySpec(decodedKey, 0, decodedKey.length, "AES"); | ||
} | ||
|
||
/** | ||
* Generates and sets a new encryption key if none is present. | ||
*/ | ||
public void ensureEncryptionKey(final int length) { | ||
if (encryptionKey == null || encryptionKey.isEmpty()) { | ||
encryptionKey = generateEncryptionKey(length); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...-API/src/main/java/com/nookure/staff/api/exception/DataIntegrityCheckFailedException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.nookure.staff.api.exception; | ||
|
||
public class DataIntegrityCheckFailedException extends RuntimeException { | ||
public DataIntegrityCheckFailedException(String message) { | ||
super(message); | ||
} | ||
|
||
public DataIntegrityCheckFailedException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
NookureStaff-API/src/main/java/com/nookure/staff/api/service/EncryptService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.nookure.staff.api.service; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.crypto.SecretKey; | ||
|
||
public interface EncryptService { | ||
/** | ||
* Encrypts the given data with the given secret key. | ||
* | ||
* @param data The data to encrypt. | ||
* @param secretKey The secret key to encrypt the data with. | ||
* @return The encrypted data. | ||
*/ | ||
byte @NotNull [] encrypt(byte @NotNull [] data, @NotNull final SecretKey secretKey); | ||
|
||
/** | ||
* Decrypts the given data with the given secret key. | ||
* | ||
* @param data The data to decrypt. | ||
* @param secretKey The secret key to decrypt the data with. | ||
* @return The decrypted data. | ||
*/ | ||
byte @NotNull [] decrypt(byte @NotNull [] data, @NotNull final SecretKey secretKey); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
82 changes: 0 additions & 82 deletions
82
NookureStaff-BungeeCord/src/main/java/com/nookure/staff/bungeecord/NookureStaff.java
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
...ungeeCord/src/main/java/com/nookure/staff/bungeecord/listener/BackendCommandListener.java
This file was deleted.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions
37
...-BungeeCord/src/main/java/com/nookure/staff/bungeecord/messaging/PluginMessageRouter.java
This file was deleted.
Oops, something went wrong.
35 changes: 0 additions & 35 deletions
35
...eStaff-BungeeCord/src/main/java/com/nookure/staff/bungeecord/module/BungeeCordLogger.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.