Skip to content
Snippets Groups Projects
Commit 9ce5298c authored by Schlütter Yannik's avatar Schlütter Yannik
Browse files

Feature: Added decrypting of logindata for our current ORacleDB database and...

Feature: Added decrypting of logindata for our current ORacleDB database and our old AzureDB database
Add: CryptoUtils.java (for decrypting loginfiles)
Add: CryptoException.java (to catch multiple Exceptions from CryptoUtils.java Class)
Update: OracleDB.java, DBalt.java(added lines for decrypting and a method to get the decrypted logindata stored into variables)
Add: AzureDB_logindetails, document.encrypted and OracleDB_logindetails as a alternative to document.encrypted (These files contain the decrypted logindata for our database)
#60
parent d1f49480
No related branches found
No related tags found
4 merge requests!74V1,!73Initial commit,!71Merge DataBase into Development,!8Merge database branch into development branch
package de.hdm_stuttgart.battlearena.Persistance.Classes;
public class CryptoException extends Exception{
public CryptoException(String message, Throwable throwable) {
super(message, throwable);
}
}
package de.hdm_stuttgart.battlearena.Persistance.Classes;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
public class CryptoUtils{
private static String parts[] = new String[2];
private static final String ALGORITHM = "AES";
private static final String TRANSFORMATION = "AES";
/*public static void encrypt(String key, File inputFile, File outputFile)
throws CryptoException {
doCrypto(Cipher.ENCRYPT_MODE, key, inputFile);
}*/
public static String[] decrypt(String key, File inputFile)
throws CryptoException {
doCrypto(Cipher.DECRYPT_MODE, key, inputFile);
return parts;
}
public static String[] doCrypto(int cipherMode, String key, File inputFile) throws CryptoException {
try {
Key secretKey = new SecretKeySpec(key.getBytes(), ALGORITHM);
Cipher cipher = Cipher.getInstance(TRANSFORMATION);
cipher.init(cipherMode, secretKey);
FileInputStream inputStream = new FileInputStream(inputFile);
byte[] inputBytes = new byte[(int) inputFile.length()];
inputStream.read(inputBytes);
byte[] outputBytes = cipher.doFinal(inputBytes);
String completeString = new String(outputBytes, StandardCharsets.UTF_8);
System.out.println(completeString);
parts = completeString.split(";");
inputStream.close();
} catch (NoSuchPaddingException | NoSuchAlgorithmException
| InvalidKeyException | BadPaddingException
| IllegalBlockSizeException | IOException ex) {
throw new CryptoException("Error encrypting/decrypting file", ex);
}
return parts;
}
}
...@@ -4,6 +4,7 @@ import org.apache.logging.log4j.Logger; ...@@ -4,6 +4,7 @@ import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Properties; import java.util.Properties;
...@@ -11,6 +12,26 @@ import java.sql.*; ...@@ -11,6 +12,26 @@ import java.sql.*;
public class DBalt implements IDataBasealt { public class DBalt implements IDataBasealt {
static String key = "Peters Olivenöl";
private static String user="";
private static String password="";
private static String[] parts= new String[2];
//static File inputFile = new File("src\\main\\resources\\database\\OracleDB_logindetails");
static File encryptedFile = new File("src\\main\\resources\\database\\AzureDB_logindetails");
//static File decryptedFile = new File("src\\main\\resources\\database\\document.decrypted");
protected static void getlogindata() throws CryptoException {
parts = CryptoUtils.decrypt(key, encryptedFile);
String completeString = parts[0] + parts[1];
parts = completeString.split("=");
user = parts[1];
password = parts[2];
user = user.replace("password", "");
log.info("AzureDB_logindetails: user: " + user +" password: " + password);
}
private static final Logger log = LogManager.getLogger(DBalt.class); private static final Logger log = LogManager.getLogger(DBalt.class);
...@@ -22,7 +43,7 @@ public class DBalt implements IDataBasealt { ...@@ -22,7 +43,7 @@ public class DBalt implements IDataBasealt {
properties.load(getClass().getClassLoader().getResourceAsStream("config.properties")); properties.load(getClass().getClassLoader().getResourceAsStream("config.properties"));
log.info("Connecting to the database!"); log.info("Connecting to the database!");
Connection connection = DriverManager.getConnection(properties.getProperty("url"), properties.getProperty("user"), properties.getProperty("password")); Connection connection = DriverManager.getConnection(properties.getProperty("url"), properties.getProperty(user), properties.getProperty(password));
log.info("Database connection test" + connection.getCatalog()); log.info("Database connection test" + connection.getCatalog());
connection.setAutoCommit(true); connection.setAutoCommit(true);
......
...@@ -7,7 +7,7 @@ import java.util.ArrayList; ...@@ -7,7 +7,7 @@ import java.util.ArrayList;
public interface ISQLDataBase { public interface ISQLDataBase {
Connection connect() throws DatabaseError; Connection connect() throws DatabaseError, CryptoException;
ArrayList<MapData> getCoreMaps() throws DatabaseError; ArrayList<MapData> getCoreMaps() throws DatabaseError;
......
...@@ -4,21 +4,39 @@ import de.hdm_stuttgart.battlearena.Exceptions.DatabaseError; ...@@ -4,21 +4,39 @@ import de.hdm_stuttgart.battlearena.Exceptions.DatabaseError;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import java.io.File;
import java.sql.*; import java.sql.*;
import java.util.ArrayList; import java.util.ArrayList;
import oracle.jdbc.pool.OracleDataSource; import oracle.jdbc.pool.OracleDataSource;
public class OracleDB implements ISQLDataBase { public class OracleDB implements ISQLDataBase {
static String key = "Peters Olivenöl";
private static String user="";
private static String password="";
private static String[] parts= new String[2];
static File encryptedFile = new File("src\\main\\resources\\database\\document.encrypted");
//static File encryptedFile = new File("src\\main\\resources\\database\\document.encrypted");
//static File decryptedFile = new File("src\\main\\resources\\database\\document.decrypted");
private static final Logger log = LogManager.getLogger(OracleDB.class); private static final Logger log = LogManager.getLogger(OracleDB.class);
public void getlogindata() throws CryptoException {
parts = CryptoUtils.decrypt(key, encryptedFile);
user = parts[0];
password = parts[1];
log.info("OracleDB_logindetails: user: " + user + " password: " + password);
}
@Override @Override
public Connection connect() throws DatabaseError{ public Connection connect() throws DatabaseError, CryptoException {
getlogindata();
try { try {
OracleDataSource ods = new OracleDataSource(); OracleDataSource ods = new OracleDataSource();
ods.setURL("jdbc:oracle:thin:@(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1521)(host=adb.eu-frankfurt-1.oraclecloud.com))(connect_data=(service_name=g093caf2cf1fea4_battlearena_high.adb.oraclecloud.com))(security=(ssl_server_dn_match=yes)))"); ods.setURL("jdbc:oracle:thin:@(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1521)(host=adb.eu-frankfurt-1.oraclecloud.com))(connect_data=(service_name=g093caf2cf1fea4_battlearena_high.adb.oraclecloud.com))(security=(ssl_server_dn_match=yes)))");
ods.setUser("battlearenaplayer"); ods.setUser(user);
ods.setPassword("jo3+++w3rw+s##AA"); ods.setPassword(password);
Connection conn = ods.getConnection(); Connection conn = ods.getConnection();
log.info("Connecting to the database!"); log.info("Connecting to the database!");
...@@ -100,7 +118,7 @@ public class OracleDB implements ISQLDataBase { ...@@ -100,7 +118,7 @@ public class OracleDB implements ISQLDataBase {
} }
} }
public void uploadCommunityMap(MapData map) throws DatabaseError{ public void uploadCommunityMapByID(MapData map) throws DatabaseError{
try(Connection connection = connect()) { try(Connection connection = connect()) {
String sql = "INSERT INTO battlearenadata.communitymaps (map_id, map_name, map_width, map_height, map_data) VALUES (?, ?, ?, ?, ?)"; String sql = "INSERT INTO battlearenadata.communitymaps (map_id, map_name, map_width, map_height, map_data) VALUES (?, ?, ?, ?, ?)";
PreparedStatement stmt = connection.prepareStatement(sql); PreparedStatement stmt = connection.prepareStatement(sql);
......
File added
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment