diff --git a/src/main/java/app/attestation/server/AttestationServer.java b/src/main/java/app/attestation/server/AttestationServer.java index cfc4a82c..589bfd45 100644 --- a/src/main/java/app/attestation/server/AttestationServer.java +++ b/src/main/java/app/attestation/server/AttestationServer.java @@ -284,7 +284,8 @@ public static void main(final String[] args) throws Exception { final SQLiteConnection samplesConn = open(SAMPLES_DATABASE); try { - final SQLiteStatement selectCreated = samplesConn.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='Samples'"); + final SQLiteStatement selectCreated = samplesConn.prepare( + "SELECT 1 FROM sqlite_master WHERE type='table' AND name='Samples'"); if (!selectCreated.step()) { samplesConn.exec("PRAGMA user_version = 1"); } @@ -306,7 +307,8 @@ public static void main(final String[] args) throws Exception { final SQLiteConnection attestationConn = open(ATTESTATION_DATABASE); try { - final SQLiteStatement selectCreated = attestationConn.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='Configuration'"); + final SQLiteStatement selectCreated = attestationConn.prepare( + "SELECT 1 FROM sqlite_master WHERE type='table' AND name='Configuration'"); if (!selectCreated.step()) { attestationConn.exec("PRAGMA user_version = 11"); } @@ -493,9 +495,10 @@ private static void createAccount(final String username, final String password) final SQLiteConnection conn = getLocalAttestationConn(); try { - final SQLiteStatement insert = conn.prepare("INSERT INTO Accounts " + - "(username, passwordHash, passwordSalt, subscribeKey, creationTime, loginTime, verifyInterval, alertDelay) " + - "VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); + final SQLiteStatement insert = conn.prepare(""" + INSERT INTO Accounts + (username, passwordHash, passwordSalt, subscribeKey, creationTime, loginTime, verifyInterval, alertDelay) + VALUES (?, ?, ?, ?, ?, ?, ?, ?)"""); try { insert.bind(1, username); insert.bind(2, passwordHash); @@ -528,8 +531,8 @@ private static void changePassword(final long userId, final String currentPasswo try { conn.exec("BEGIN IMMEDIATE TRANSACTION"); - final SQLiteStatement select = conn.prepare("SELECT passwordHash, passwordSalt " + - "FROM Accounts WHERE userId = ?"); + final SQLiteStatement select = conn.prepare( + "SELECT passwordHash, passwordSalt FROM Accounts WHERE userId = ?"); final byte[] currentPasswordHash; final byte[] currentPasswordSalt; try { @@ -547,8 +550,8 @@ private static void changePassword(final long userId, final String currentPasswo final byte[] newPasswordSalt = generateRandomToken(); final byte[] newPasswordHash = hash(newPassword.getBytes(), newPasswordSalt); - final SQLiteStatement update = conn.prepare("UPDATE Accounts " + - "SET passwordHash = ?, passwordSalt = ? WHERE userId = ?"); + final SQLiteStatement update = conn.prepare( + "UPDATE Accounts SET passwordHash = ?, passwordSalt = ? WHERE userId = ?"); try { update.bind(1, newPasswordHash); update.bind(2, newPasswordSalt); @@ -583,8 +586,8 @@ private static Session login(final String username, final String password) try { conn.exec("BEGIN IMMEDIATE TRANSACTION"); - final SQLiteStatement select = conn.prepare("SELECT userId, passwordHash, " + - "passwordSalt FROM Accounts WHERE username = ?"); + final SQLiteStatement select = conn.prepare( + "SELECT userId, passwordHash, passwordSalt FROM Accounts WHERE username = ?"); final long userId; final byte[] passwordHash; final byte[] passwordSalt; @@ -604,7 +607,8 @@ private static Session login(final String username, final String password) } final long now = System.currentTimeMillis(); - final SQLiteStatement deleteExpiredSessions = conn.prepare("DELETE FROM Sessions WHERE expiryTime < ?"); + final SQLiteStatement deleteExpiredSessions = conn.prepare( + "DELETE FROM Sessions WHERE expiryTime < ?"); try { deleteExpiredSessions.bind(1, now); deleteExpiredSessions.step(); @@ -614,8 +618,8 @@ private static Session login(final String username, final String password) final byte[] token = generateRandomToken(); - final SQLiteStatement insert = conn.prepare("INSERT INTO Sessions " + - "(userId, token, expiryTime) VALUES (?, ?, ?)"); + final SQLiteStatement insert = conn.prepare( + "INSERT INTO Sessions (userId, token, expiryTime) VALUES (?, ?, ?)"); try { insert.bind(1, userId); insert.bind(2, token); @@ -625,8 +629,8 @@ private static Session login(final String username, final String password) insert.dispose(); } - final SQLiteStatement updateLoginTime = conn.prepare("UPDATE Accounts SET " + - "loginTime = ? WHERE userId = ?"); + final SQLiteStatement updateLoginTime = conn.prepare( + "UPDATE Accounts SET loginTime = ? WHERE userId = ?"); try { updateLoginTime.bind(1, now); updateLoginTime.bind(2, userId); @@ -783,8 +787,8 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx final SQLiteConnection conn = getLocalAttestationConn(); final byte[] subscribeKey = generateRandomToken(); - final SQLiteStatement select = conn.prepare("UPDATE Accounts SET " + - "subscribeKey = ? WHERE userId = ?"); + final SQLiteStatement select = conn.prepare( + "UPDATE Accounts SET subscribeKey = ? WHERE userId = ?"); try { select.bind(1, subscribeKey); select.bind(2, account.userId); @@ -875,8 +879,8 @@ private static Account verifySession(final HttpExchange exchange, final boolean } if (end) { - final SQLiteStatement delete = conn.prepare("DELETE FROM Sessions " + - "WHERE sessionId = ?"); + final SQLiteStatement delete = conn.prepare( + "DELETE FROM Sessions WHERE sessionId = ?"); try { delete.bind(1, sessionId); delete.step(); @@ -905,8 +909,8 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx accountJson.add("alertDelay", account.alertDelay); final SQLiteConnection conn = getLocalAttestationConn(); - final SQLiteStatement select = conn.prepare("SELECT address FROM EmailAddresses " + - "WHERE userId = ?"); + final SQLiteStatement select = conn.prepare( + "SELECT address FROM EmailAddresses WHERE userId = ?"); try { select.bind(1, account.userId); if (select.step()) { @@ -1008,8 +1012,8 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx try { conn.exec("BEGIN IMMEDIATE TRANSACTION"); - final SQLiteStatement update = conn.prepare("UPDATE Accounts SET " + - "verifyInterval = ?, alertDelay = ? WHERE userId = ?"); + final SQLiteStatement update = conn.prepare( + "UPDATE Accounts SET verifyInterval = ?, alertDelay = ? WHERE userId = ?"); try { update.bind(1, verifyInterval); update.bind(2, alertDelay); @@ -1019,8 +1023,8 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx update.dispose(); } - final SQLiteStatement delete = conn.prepare("DELETE FROM EmailAddresses " + - "WHERE userId = ?"); + final SQLiteStatement delete = conn.prepare( + "DELETE FROM EmailAddresses WHERE userId = ?"); try { delete.bind(1, account.userId); delete.step(); @@ -1029,8 +1033,8 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx } if (!email.isEmpty()) { - final SQLiteStatement insert = conn.prepare("INSERT INTO EmailAddresses " + - "(userId, address) VALUES (?, ?)"); + final SQLiteStatement insert = conn.prepare( + "INSERT INTO EmailAddresses (userId, address) VALUES (?, ?)"); try { insert.bind(1, account.userId); insert.bind(2, email); @@ -1067,8 +1071,8 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx } final SQLiteConnection conn = getLocalAttestationConn(); - final SQLiteStatement update = conn.prepare("UPDATE Devices SET " + - "deletionTime = ? WHERE userId = ? AND fingerprint = ?"); + final SQLiteStatement update = conn.prepare( + "UPDATE Devices SET deletionTime = ? WHERE userId = ? AND fingerprint = ?"); try { update.bind(1, System.currentTimeMillis()); update.bind(2, account.userId); @@ -1325,8 +1329,8 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx final byte[] currentSubscribeKey; final int verifyInterval; final SQLiteConnection conn = getLocalAttestationConn(); - final SQLiteStatement select = conn.prepare("SELECT subscribeKey, verifyInterval " + - "FROM Accounts WHERE userId = ?"); + final SQLiteStatement select = conn.prepare( + "SELECT subscribeKey, verifyInterval FROM Accounts WHERE userId = ?"); try { select.bind(1, userId); if (!select.step()) { @@ -1406,8 +1410,8 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx final SQLiteConnection conn = open(SAMPLES_DATABASE); try { - final SQLiteStatement insert = conn.prepare("INSERT INTO Samples " + - "(sample, time) VALUES (?, ?)"); + final SQLiteStatement insert = conn.prepare( + "INSERT INTO Samples (sample, time) VALUES (?, ?)"); try { insert.bind(1, sample.toByteArray()); insert.bind(2, System.currentTimeMillis());