Skip to content

Commit

Permalink
Added logic for Bastillion-EC2 Upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
skavanagh committed Jan 9, 2022
1 parent 34d30b9 commit 4ce5771
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
7 changes: 1 addition & 6 deletions src/main/java/Upgrade.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void main(String[] args) {
password = "filepwd " + password;
}
assert connectionURL != null;
connectionURL = connectionURL.replaceAll("keydb/bastillion", DBUtils.DB_PATH + "keydb/bastillion");
connectionURL = connectionURL.replaceAll("jdbc:h2:", "jdbc:h2:" + DBUtils.DB_PATH);
System.out.println("connectionURL : " + connectionURL);

Properties info = new Properties();
Expand All @@ -52,7 +52,6 @@ public static void main(String[] args) {
try {
H2Upgrade.upgrade(connectionURL, info, 200);
} catch (Exception ignore) {
ignore.printStackTrace();
}

Connection con = DBUtils.getConn();
Expand All @@ -65,31 +64,27 @@ public static void main(String[] args) {
stmt.executeUpdate("ALTER TABLE system RENAME COLUMN \"USER\" to USERNAME");
DBUtils.closeStmt(stmt);
} catch (Exception ignore) {
ignore.printStackTrace();
}

try {
stmt = con.createStatement();
stmt.executeUpdate("ALTER TABLE system RENAME COLUMN \"user\" to USERNAME");
DBUtils.closeStmt(stmt);
} catch (Exception ignore) {
ignore.printStackTrace();
}

try {
stmt = con.createStatement();
stmt.executeUpdate("ALTER TABLE terminal_log RENAME COLUMN \"USER\" to USERNAME");
DBUtils.closeStmt(stmt);
} catch (Exception ignore) {
ignore.printStackTrace();
}

try {
stmt = con.createStatement();
stmt.executeUpdate("ALTER TABLE terminal_log RENAME COLUMN \"user\" to USERNAME");
DBUtils.closeStmt(stmt);
} catch (Exception ignore) {
ignore.printStackTrace();
}

DBUtils.closeConn(con);
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/io/bastillion/manage/util/EncryptionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,22 @@
import org.apache.commons.lang3.StringUtils;

public class EncryptionUtil {
private static final byte[] key = KeyStoreUtil.getSecretBytes("KEYBOX-ENCRYPTION_KEY");
public static final String CRYPT_ALGORITHM = "AES";
public static final String HASH_ALGORITHM = "SHA-256";
public static final String ENCRYPTION_KEY_NM;
public static final String KEYBOX_ENCRYPTION_KEY = "KEYBOX-ENCRYPTION_KEY";
public static final String EC2BOX_ENCRYPTION_KEY = "EC2BOX-ENCRYPTION_KEY";
private static final byte[] keybox = KeyStoreUtil.getSecretBytes(KEYBOX_ENCRYPTION_KEY);
private static final byte[] ec2box = KeyStoreUtil.getSecretBytes(EC2BOX_ENCRYPTION_KEY);
private static final byte[] key;

static {
if(keybox != null && keybox.length > 0) {
key = keybox;
ENCRYPTION_KEY_NM = KEYBOX_ENCRYPTION_KEY;
} else {
key = ec2box;
ENCRYPTION_KEY_NM = EC2BOX_ENCRYPTION_KEY;
}
}
private EncryptionUtil() {
}

Expand Down
20 changes: 15 additions & 5 deletions src/main/java/io/bastillion/manage/util/KeyStoreUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public class KeyStoreUtil {
private static KeyStore keyStore = null;
private static final String keyStoreFile;
private static final char[] KEYSTORE_PASS;
private static final byte[] key;
public static final String ENCRYPTION_KEY_ALIAS = "KEYBOX-ENCRYPTION_KEY";

public KeyStoreUtil() {
}
Expand All @@ -41,7 +39,7 @@ public static byte[] getSecretBytes(String alias) {
SecretKeyEntry entry = (SecretKeyEntry) keyStore.getEntry(alias, new PasswordProtection(KEYSTORE_PASS));
value = entry.getSecretKey().getEncoded();
} catch (Exception ex) {
ex.printStackTrace();
//ex.printStackTrace();
}

return value;
Expand Down Expand Up @@ -81,7 +79,7 @@ public static void initializeKeyStore() {
try {
keyStore = KeyStore.getInstance("JCEKS");
keyStore.load((InputStream) null, KEYSTORE_PASS);
setSecret("KEYBOX-ENCRYPTION_KEY", key);
setSecret(EncryptionUtil.ENCRYPTION_KEY_NM, getKey());
FileOutputStream fos = new FileOutputStream(keyStoreFile);
keyStore.store(fos, KEYSTORE_PASS);
fos.close();
Expand All @@ -91,10 +89,22 @@ public static void initializeKeyStore() {

}

private static byte[] getKey() {
byte[] key;
if (EncryptionUtil.ENCRYPTION_KEY_NM.equals(EncryptionUtil.KEYBOX_ENCRYPTION_KEY)) {
key = new byte[]{100, 51, 50, 116, 112, 100, 77, 111, 73, 56, 120, 122, 97, 80, 111, 100};
} else {
key = new byte[]{'t', '3', '2', 'm', 'p', 'd', 'M', 'O', 'i', '8', 'x', 'z', 'a', 'P', 'o', 'd'};
}
return key;
}


static {
keyStoreFile = DBUtils.DB_PATH + "bastillion.jceks";
KEYSTORE_PASS = new char[]{'G', '~', 'r', 'x', 'Z', 'E', 'w', 'f', 'a', '[', '!', 'f', 'Z', 'd', '*', 'L', '8', 'm', 'h', 'u', '#', 'j', '9', ':', '~', ';', 'U', '>', 'O', 'i', '8', 'r', 'C', '}', 'f', 't', '%', '[', 'H', 'h', 'M', '&', 'K', ':', 'l', '5', 'c', 'H', '6', 'r', 'A', 'E', '.', 'F', 'Y', 'W', '}', '{', '*', '8', 'd', 'E', 'C', 'A', '6', 'F', 'm', 'j', 'u', 'A', 'Q', '%', '{', '/', '@', 'm', '&', '5', 'S', 'q', '4', 'Q', '+', 'Y', '|', 'X', 'W', 'z', '8', '<', 'j', 'd', 'a', '}', '`', '0', 'N', 'B', '3', 'i', 'v', '5', 'U', ' ', '2', 'd', 'd', '(', '&', 'J', '_', '9', 'o', '(', '2', 'I', '`', ';', '>', '#', '$', 'X', 'j', '&', '&', '%', '>', '#', '7', 'q', '>', ')', 'L', 'A', 'v', 'h', 'j', 'i', '8', '~', ')', 'a', '~', 'W', '/', 'l', 'H', 'L', 'R', '+', '\\', 'i', 'R', '_', '+', 'y', 's', '0', 'n', '\'', '=', '{', 'B', ':', 'l', '1', '%', '^', 'd', 'n', 'H', 'X', 'B', '$', 'f', '"', '#', ')', '{', 'L', '/', 'q', '\'', 'O', '%', 's', 'M', 'Q', ']', 'D', 'v', ';', 'L', 'C', 'd', '?', 'D', 'l', 'h', 'd', 'i', 'N', '4', 'R', '>', 'O', ';', '$', '(', '4', '-', '0', '^', 'Y', ')', '5', 'V', 'M', '7', 'S', 'a', 'c', 'D', 'C', 'w', 'A', 'o', 'n', 's', 'r', '*', 'G', '[', 'l', 'h', '$', 'U', 's', '_', 'D', 'f', 'X', '~', '.', '7', 'B', 'A', 'E', '(', '#', ']', ':', '`', ',', 'k', 'y'};
key = new byte[]{100, 51, 50, 116, 112, 100, 77, 111, 73, 56, 120, 122, 97, 80, 111, 100};


File f = new File(keyStoreFile);
if (f.isFile() && f.canRead()) {
try {
Expand Down

0 comments on commit 4ce5771

Please sign in to comment.