public void NoteIsAlwaysEncryptedWithSameKey() { string first_key; var note = DbStorageTests.GetSampleNotes()[0]; // save for first time using (var storage = new DbEncryptedStorage(connFactory, testUser, key)) { storage.SaveNote(note); } using (var db = connFactory.OpenDbConnection()) { var db_note = db.First <DBNote> (n => n.Guid == note.Guid); first_key = db_note.EncryptedKey; Assert.That(!string.IsNullOrEmpty(first_key)); } // change the text and store note again note.Text = "Foobar"; // save for first time using (var storage = new DbEncryptedStorage(connFactory, testUser, key)) { storage.SaveNote(note); } using (var db = connFactory.OpenDbConnection()) { var db_note = db.First <DBNote> (n => n.Guid == note.Guid); Assert.AreEqual(first_key, db_note.EncryptedKey); } }
public void ReEncryptNotes() { DbEncryptedStorage storage = new DbEncryptedStorage(this.connFactory, this.testUser, key); var sample_notes = DbStorageTests.GetSampleNotes(); foreach (var note in sample_notes) { storage.SaveNote(note); } storage.Dispose(); storage = new DbEncryptedStorage(connFactory, testUser, key); var new_key = CryptoHelper.Create256BitLowerCaseHexKey(new RNGCryptoServiceProvider()); storage.ReEncryptAllNotes(new_key); storage.Dispose(); // try to open the notes with the new key storage = new DbEncryptedStorage(connFactory, testUser, new_key); var decrypted_notes = storage.GetNotes(); foreach (var note in sample_notes) { Assert.AreEqual(note.Text, decrypted_notes.Values.First(n => n.Guid == note.Guid).Text); } }
public void NoteHistoryIsSaved() { var sample_notes = DbStorageTests.GetSampleNotes(); using (var storage = new DbStorage(this.connFactory, this.testUser.Username, this.testUser.Manifest, use_history: true)) { foreach (var note in sample_notes) { storage.SaveNote(note); } } // modify the notes using (var storage = new DbStorage(this.connFactory, this.testUser.Username, this.testUser.Manifest, use_history: true)) { foreach (var note in sample_notes) { note.Title = "Random new title"; storage.SaveNote(note); } } // for each note there should exist a backup copy foreach (var note in sample_notes) { using (var db = connFactory.OpenDbConnection()) { var archived_note = db.FirstOrDefault <DBArchivedNote> (n => n.Guid == note.Guid); Assert.IsNotNull(archived_note); Assert.AreNotEqual("Random new title", archived_note.Title); } } }
public void NoteIsEncryptedIsCorrectlySet() { // test with encrypted notes DbStorage storage = new DbEncryptedStorage(this.connFactory, this.testUser, key); var sample_notes = DbStorageTests.GetSampleNotes(); foreach (var note in sample_notes) { storage.SaveNote(note); } storage.Dispose(); foreach (var note in sample_notes) { // the stored notes should only contain hex chars using (var db = connFactory.OpenDbConnection()) { var db_note = db.First <DBNote> (n => n.Guid == note.Guid); // this will fail if any non-hex chars are in Assert.IsTrue(db_note.IsEncypted); } } storage = new DbStorage(this.connFactory, testUser.Username, testUser.Manifest); sample_notes = DbStorageTests.GetSampleNotes(); foreach (var note in sample_notes) { storage.SaveNote(note); } storage.Dispose(); foreach (var note in sample_notes) { // the stored notes should only contain hex chars using (var db = connFactory.OpenDbConnection()) { var db_note = db.First <DBNote> (n => n.Guid == note.Guid); // this will fail if any non-hex chars are in Assert.IsFalse(db_note.IsEncypted); } } }
public void EncryptedStorageStoresNoPlaintextNotes() { var storage = new DbEncryptedStorage(connFactory, testUser, key); var sample_notes = DbStorageTests.GetSampleNotes(); foreach (var note in sample_notes) { storage.SaveNote(note); } storage.Dispose(); foreach (var note in sample_notes) { // the stored notes should only contain hex chars using (var db = connFactory.OpenDbConnection()) { var db_note = db.First <DBNote> (n => n.Guid == note.Guid); // this will fail if any non-hex chars are in db_note.Text.ToByteArray(); } } }