Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Commit

Permalink
Removed deprecated & redundant security code
Browse files Browse the repository at this point in the history
  • Loading branch information
BelgianDev committed Dec 6, 2023
1 parent 2a06735 commit 3bd2f64
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,4 @@ public interface SecurityManager {
* @throws CryptographyException if the encryptor could not be created.
*/
Encryptor createSecretKeyEncryptor(SecretKey key) throws CryptographyException;

/**
* Hash and salt bytes with the system settings, once your bytes has been hashed it <strong>cannot be reverted.</strong>
* <p>
* It's highly recommended to execute {@link SecurityUtils#destroy(byte[])} on your original bytes once you're finished with it.
* @param original original byte array.
* @return newly hashed byte array.
*/
byte[] hash(byte[] original) throws CryptographyException;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
import fr.atlasworld.network.api.file.configuration.ConfigurationFile;
import fr.atlasworld.network.api.file.configuration.ConfigurationSchema;
import fr.atlasworld.network.api.file.configuration.exception.UnsupportedConfigurationException;
import fr.atlasworld.network.api.security.SecurityUtils;
import org.jetbrains.annotations.NotNull;

import java.util.Base64;

public class SecurityConfiguration implements ConfigurationFile {
private final @SerializedName("hashing_salt") String hashingSalt;

// See : https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator
private final @SerializedName("key_pair_algorithm") String keyPairAlgorithm;
Expand All @@ -21,17 +19,12 @@ public class SecurityConfiguration implements ConfigurationFile {
// See : https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#KeyGenerator
private final @SerializedName("encryption_key_algorithm") String secretKeyAlgorithm;

public SecurityConfiguration(String hashingSalt, String keyPairAlgorithm, int secretKeySize, String secretKeyAlgorithm) {
this.hashingSalt = hashingSalt;
public SecurityConfiguration(String keyPairAlgorithm, int secretKeySize, String secretKeyAlgorithm) {
this.keyPairAlgorithm = keyPairAlgorithm;
this.secretKeySize = secretKeySize;
this.secretKeyAlgorithm = secretKeyAlgorithm;
}

public String getHashingSalt() {
return hashingSalt;
}

public String getKeyPairAlgorithm() {
return keyPairAlgorithm;
}
Expand Down Expand Up @@ -59,7 +52,6 @@ public int configurationVersion() {
@Override
public @NotNull SecurityConfiguration defaultConfiguration() {
return new SecurityConfiguration(
Base64.getEncoder().encodeToString(SecurityUtils.genSalt()),
"RSA",
256,
"AES");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import fr.atlasworld.network.api.security.Encryptor;
import fr.atlasworld.network.api.security.SecurityManager;
import fr.atlasworld.network.api.security.SecurityUtils;
import fr.atlasworld.network.api.security.exceptions.CryptographyException;
import fr.atlasworld.network.core.file.configuration.SecurityConfiguration;
import fr.atlasworld.network.core.security.encryptors.KeyPairEncryptor;
Expand All @@ -18,10 +17,8 @@ public class SystemSecurityManager implements SecurityManager {
private final KeyGenerator keyGen;
private final KeyPair sessionKeyPair;
private final KeyPairEncryptor encryptor;
private final byte[] saltBytes;

public SystemSecurityManager(SecurityConfiguration configuration) throws CryptographyException {
this.saltBytes = Base64.getDecoder().decode(configuration.getHashingSalt());

try {
this.pairKeyGen = KeyPairGenerator.getInstance(configuration.getKeyPairAlgorithm());
Expand Down Expand Up @@ -56,10 +53,4 @@ public PublicKey getSessionPublicKey() {
public Encryptor createSecretKeyEncryptor(SecretKey key) throws CryptographyException {
return new SecretKeyEncryptor(key);
}

@Override
public byte[] hash(byte[] original) throws CryptographyException {
char[] str = Base64.getEncoder().encodeToString(original).toCharArray();
return SecurityUtils.hash(str, this.saltBytes);
}
}

0 comments on commit 3bd2f64

Please sign in to comment.