Given the recent popularity of Privnote as consequence of appearing in ReadWriteWeb and the front-page of Digg, a rather heated discussion has arisen about whether notes send through Privnote are really protected against someone with access to the Privnote database.
We believe it is, and I'll explain the reasons here by detailing the exact process used to store the notes in the database. I did try to explain it before in this post but unfortunately the explanation was obfuscated at best, and incorrect at worst.
So here's what happens when you create a note in Privnote:
- You write the note and click the POST button
- The server generates a random note id, let's call it the NoteID. This is the 16 chars ID you see in the note link
- The server hashes the note ID and gets a HashedNoteID = Hash(NoteID). We're currently using SHA-1 as the hashing algorithm, but the particular algorithm is not very important here
- The server encrypts the note contents (and also the email and reference, if there is any) using the NoteID, and stores the encrypted version in the database using the HashedNoteID as the database primary key
If someone with access to the database would like to read the note she would be unable because she doesn't have the key to decrypt it (NoteID), only the database primary key (HashedNoteID). The HashedNoteID cannot be used to "go back" to the NoteID because hashes are "one-way". So the only person who can actually decrypt (and thus see) the note is the one who has the original NoteID or, in other words, the one who has the link to the note.
For completeness, this is what happens when you view a note in Privnote:
- The server extracts the NoteID from the URL
- The server hashes the NoteID and gets the HashedNoteID. This is the same HashedNoteID used when generating the note, since the NoteID used to make the hash is the same in both cases
- The server retrieves the note from the database using HashedNoteID as the database primary key and decrypts its contents using NoteID as the encryption key
- The server shows the page with the decrypted note
- The server permanently deletes the note from the database, keeping only a record of the HashedNoteID, the time when it was read, and the IP address where it was read from, to show it when someone tries to see the note again
I apologize for not being clear in my original explanation, and hope to have explained myself better this time. Thanks to everyone who corrected me and provided a better explanation, both here and in other blogs.
Finally, I must say that we have received a lot of great feedback these days, and that motivates us to keep improving Privnote as well as making it available in more languages.