Skip to content

Commit

Permalink
Fix passing keys starting with digits
Browse files Browse the repository at this point in the history
  • Loading branch information
jgiannuzzi committed Nov 11, 2022
1 parent 34e1e85 commit c96939f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 4 additions & 2 deletions sqlcipher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ func TestCipher(t *testing.T) {
keys := []string{
// Passphrase with Key Derivation
"passphrase",
// Passphrase with Key Derivation starting with a digit
"1passphrase",
// Raw Key Data (Without Key Derivation)
`"x'2DD29CA851E7B56E4697B0E1F08507293D761A05CE4D1B628663F411A8086D99'"`,
"x'2DD29CA851E7B56E4697B0E1F08507293D761A05CE4D1B628663F411A8086D99'",
// Raw Key Data with Explicit Salt (Without Key Derivation)
`"x'98483C6EB40B6C31A448C22A66DED3B5E5E8D5119CAC8327B655C8B5C483648101010101010101010101010101010101'"`,
"x'98483C6EB40B6C31A448C22A66DED3B5E5E8D5119CAC8327B655C8B5C483648101010101010101010101010101010101'",
}
for _, key := range keys {
fname := TempFilename(t)
Expand Down
9 changes: 8 additions & 1 deletion sqlite3.go
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,14 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
// https://www.zetetic.net/sqlcipher/sqlcipher-api/#PRAGMA_key
//
if val := params.Get("_key"); val != "" {
key = val
switch {
case strings.Contains(val, `'`) && strings.Contains(val, `"`):
return nil, errors.New("Invalid key provided, cannot contain both ' and \"")
case strings.Contains(val, `'`):
key = fmt.Sprintf(`"%s"`, val)
default:
key = fmt.Sprintf(`'%s'`, val)
}
}

// Locking Mode (_locking)
Expand Down

0 comments on commit c96939f

Please sign in to comment.