@@ -263,89 +263,8 @@ public static void main(final String[] args) throws Exception {
263263 attestationConn .exec ("INSERT OR IGNORE INTO Configuration " +
264264 "(key, value) VALUES ('backups', 0)" );
265265
266- // drop old indices
267- attestationConn .exec ("DROP INDEX IF EXISTS Attestations_fingerprint_time" );
268- attestationConn .exec ("DROP INDEX IF EXISTS Devices_userId_verifiedTimeLast" );
269-
270- // add loginTime column to Accounts table
271- if (userVersion == 0 ) {
272- attestationConn .exec ("PRAGMA foreign_keys = OFF" );
273- attestationConn .exec ("BEGIN IMMEDIATE TRANSACTION" );
274- attestationConn .exec ("ALTER TABLE Accounts RENAME TO AccountsOld" );
275- createAccountsTable (attestationConn );
276- attestationConn .exec ("INSERT INTO Accounts " +
277- "(userId, username, passwordHash, passwordSalt, subscribeKey, creationTime, loginTime, verifyInterval, alertDelay) " +
278- "SELECT " +
279- "userId, username, passwordHash, passwordSalt, subscribeKey, creationTime, creationTime, verifyInterval, alertDelay " +
280- "FROM AccountsOld" );
281- attestationConn .exec ("DROP TABLE AccountsOld" );
282- createAccountsIndices (attestationConn );
283- attestationConn .exec ("PRAGMA user_version = 1" );
284- userVersion = 1 ;
285- attestationConn .exec ("END TRANSACTION" );
286- attestationConn .exec ("PRAGMA foreign_keys = ON" );
287- }
288-
289- // add pinnedCertificate3 column to Devices table and set it to the original attestation root certificate
290- if (userVersion == 1 ) {
291- attestationConn .exec ("PRAGMA foreign_keys = OFF" );
292- attestationConn .exec ("BEGIN IMMEDIATE TRANSACTION" );
293- attestationConn .exec ("ALTER TABLE Devices RENAME TO DevicesOld" );
294- createDevicesTable (attestationConn );
295- attestationConn .exec ("INSERT INTO Devices " +
296- "(fingerprint, pinnedCertificate0, pinnedCertificate1, pinnedCertificate2, pinnedCertificate3, pinnedVerifiedBootKey, verifiedBootHash, pinnedOsVersion, pinnedOsPatchLevel, pinnedVendorPatchLevel, pinnedBootPatchLevel, pinnedAppVersion, pinnedSecurityLevel, userProfileSecure, enrolledFingerprints, accessibility, deviceAdmin, adbEnabled, addUsersWhenLocked, denyNewUsb, oemUnlockAllowed, systemUser, verifiedTimeFirst, verifiedTimeLast, expiredTimeLast, failureTimeLast, userId, deletionTime) " +
297- "SELECT " +
298- "fingerprint, pinnedCertificate0, pinnedCertificate1, pinnedCertificate2, pinnedCertificate2, pinnedVerifiedBootKey, verifiedBootHash, pinnedOsVersion, pinnedOsPatchLevel, pinnedVendorPatchLevel, pinnedBootPatchLevel, pinnedAppVersion, pinnedSecurityLevel, userProfileSecure, enrolledFingerprints, accessibility, deviceAdmin, adbEnabled, addUsersWhenLocked, denyNewUsb, oemUnlockAllowed, systemUser, verifiedTimeFirst, verifiedTimeLast, expiredTimeLast, failureTimeLast, userId, deletionTime " +
299- "FROM DevicesOld" );
300- final SQLiteStatement updatePinnedCertificate3 = attestationConn .prepare ("UPDATE Devices SET pinnedCertificate3 = ?" );
301- updatePinnedCertificate3 .bind (1 ,
302- AttestationProtocol .generateCertificate (new ByteArrayInputStream (AttestationProtocol .GOOGLE_ROOT_CERTIFICATE .getBytes ())).getEncoded ());
303- updatePinnedCertificate3 .step ();
304- updatePinnedCertificate3 .dispose ();
305- attestationConn .exec ("DROP TABLE DevicesOld" );
306- createDevicesIndices (attestationConn );
307- attestationConn .exec ("PRAGMA user_version = 2" );
308- userVersion = 2 ;
309- attestationConn .exec ("END TRANSACTION" );
310- attestationConn .exec ("PRAGMA foreign_keys = ON" );
311- }
312-
313- // add id column to track insertion order rather than relying on ordering by time
314- if (userVersion == 2 ) {
315- attestationConn .exec ("PRAGMA foreign_keys = OFF" );
316- attestationConn .exec ("BEGIN IMMEDIATE TRANSACTION" );
317- attestationConn .exec ("ALTER TABLE Attestations RENAME TO AttestationsOld" );
318- createAttestationsTable (attestationConn );
319- attestationConn .exec ("INSERT INTO Attestations " +
320- "(fingerprint, time, strong, teeEnforced, osEnforced) " +
321- "SELECT " +
322- "fingerprint, time, strong, teeEnforced, osEnforced " +
323- "FROM AttestationsOld" );
324- attestationConn .exec ("DROP TABLE AttestationsOld" );
325- createAttestationsIndices (attestationConn );
326- attestationConn .exec ("PRAGMA user_version = 3" );
327- userVersion = 3 ;
328- attestationConn .exec ("END TRANSACTION" );
329- attestationConn .exec ("PRAGMA foreign_keys = ON" );
330- }
331-
332- // rename enrolledFingerprints to enrolledBiometrics
333- if (userVersion == 3 ) {
334- attestationConn .exec ("PRAGMA foreign_keys = OFF" );
335- attestationConn .exec ("BEGIN IMMEDIATE TRANSACTION" );
336- attestationConn .exec ("ALTER TABLE Devices RENAME TO DevicesOld" );
337- createDevicesTable (attestationConn );
338- attestationConn .exec ("INSERT INTO Devices " +
339- "(fingerprint, pinnedCertificate0, pinnedCertificate1, pinnedCertificate2, pinnedCertificate3, pinnedVerifiedBootKey, verifiedBootHash, pinnedOsVersion, pinnedOsPatchLevel, pinnedVendorPatchLevel, pinnedBootPatchLevel, pinnedAppVersion, pinnedSecurityLevel, userProfileSecure, enrolledBiometrics, accessibility, deviceAdmin, adbEnabled, addUsersWhenLocked, denyNewUsb, oemUnlockAllowed, systemUser, verifiedTimeFirst, verifiedTimeLast, expiredTimeLast, failureTimeLast, userId, deletionTime) " +
340- "SELECT " +
341- "fingerprint, pinnedCertificate0, pinnedCertificate1, pinnedCertificate2, pinnedCertificate3, pinnedVerifiedBootKey, verifiedBootHash, pinnedOsVersion, pinnedOsPatchLevel, pinnedVendorPatchLevel, pinnedBootPatchLevel, pinnedAppVersion, pinnedSecurityLevel, userProfileSecure, enrolledFingerprints, accessibility, deviceAdmin, adbEnabled, addUsersWhenLocked, denyNewUsb, oemUnlockAllowed, systemUser, verifiedTimeFirst, verifiedTimeLast, expiredTimeLast, failureTimeLast, userId, deletionTime " +
342- "FROM DevicesOld" );
343- attestationConn .exec ("DROP TABLE DevicesOld" );
344- createDevicesIndices (attestationConn );
345- attestationConn .exec ("PRAGMA user_version = 4" );
346- userVersion = 4 ;
347- attestationConn .exec ("END TRANSACTION" );
348- attestationConn .exec ("PRAGMA foreign_keys = ON" );
266+ if (userVersion < 4 ) {
267+ throw new RuntimeException ("Database schema versions earlier than 4 no longer supported. Use an older revision to migrate." );
349268 }
350269
351270 logger .info ("New schema version: " + userVersion );
0 commit comments