-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Passphrase can be truncated #115
Comments
Hi @patrickhartling, Good catch, and definitely would like to get it updated to use NSData. It might be naive, but would it be possible to just check if the byte sequence is a valid UTF8String, and if not use NSData. That would maintain backwards compatibility, but still allow raw bytes. Playing around, the following code seems to accomplish this:
I'm sure there are edge cases I'm not considering, but it would give you a way to figure out if the password could possibly be used in an older version. |
and crash if truncation is done on first character |
@gavin-black Hi, any updates on this idea ? Because, together with @tomasz-czyzak-mobica we've noticed that this issue might cause some serious bugs if first string character is null-termination - then strlen treats it as 0-length key thus store opening fails. Please take a look at related topic #269 |
In the current handling of the passphrase for SQLCipher, the passphrase type has to be an instance of
NSString
—or at least something that responds to the message‑UTF8String
. A problem can arise if the passphrase is generated randomly using a function such asSecRandomCopyBytes()
. The byte 0 is as likely to occur as any other, but whenstrlen(3)
sees'\0'
, it concludes that the end of the string has been reached. In the worst case,'\0'
is the first character in the random data interpreted as a C string, and the supplied passphrase is effectively ignored as zero-length input.It would be more robust to use
NSData
as the type for the passphrase. Sincesqlite3_key()
expects to be given an array of bytes (not necessarily achar *
) of a specified length,NSData
is a much better fit for the expectations of SQLCipher than a string. I could submit a pull request to switch over toNSData
, but it would break all existing uses of Encrypted Core Data without some backwards compatibility code. At this point, I feel that it might be better to discuss this issue rather than to jump to a conclusion about how to solve it.The text was updated successfully, but these errors were encountered: