Skip to content
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

iOS 15.2 beta 2 (19C5036e) throws "bad parameter or other API misuse (code: 21)" when using SQLCipher Connection.key and Connection.rekey #1097

Closed
claustrofob opened this issue Nov 15, 2021 · 15 comments

Comments

@claustrofob
Copy link

claustrofob commented Nov 15, 2021

When trying to encrypt non encrypted db or change the key on an open encrypted db with Connection.rekey or decrypt the encrypted db with Connection.key it throws "bad parameter or other API misuse (code: 21)".

On iOS 15.1 and earlier the same code works fine.
Tested on different devices.

SQLite v. 0.13.0
SQLite.swift/SQLCipher v. 0.13.0
SQLCipher 4.4.3, 4.5.0

@claustrofob claustrofob changed the title iOS 15.2 beta 2 (19C5036e) throws "bad parameter or other API misuse (code: 21)" when using Connection.rekey iOS 15.2 beta 2 (19C5036e) throws "bad parameter or other API misuse (code: 21)" when using SQLCipher Connection.rekey Nov 16, 2021
@claustrofob claustrofob changed the title iOS 15.2 beta 2 (19C5036e) throws "bad parameter or other API misuse (code: 21)" when using SQLCipher Connection.rekey iOS 15.2 beta 2 (19C5036e) throws "bad parameter or other API misuse (code: 21)" when using SQLCipher Connection.key and Connection.rekey Nov 16, 2021
@tomrbn01
Copy link

Hey, we have same problem sqlcipher/sqlcipher#412

@jberkel
Copy link
Collaborator

jberkel commented Nov 16, 2021

Strange, that's an error from SQLite. Do you know if it works without SQLite.swift ?

@claustrofob
Copy link
Author

I did not check if it works without SQLite.swift. But SQLite.swift definitely works without using key and rekey methods.

@nitrag
Copy link

nitrag commented Nov 16, 2021

I am having this issue as well.

SQLCipher - 4.4.3
SQLite.swift/SQLCipher - 0.13.0

How much time do we have to patch this before 15.2 release?

@jberkel
Copy link
Collaborator

jberkel commented Nov 16, 2021

As commented on sqlcipher/sqlcipher#412, it looks like there's a conflict between the bundled version of SQLite and SQLCipher.

@claustrofob
Copy link
Author

Tested vanilla SQLCipher v. 4.5.0 with sqlite3_key and sqlite3_rekey. No issues, works good.

@jberkel
Copy link
Collaborator

jberkel commented Nov 16, 2021

@claustrofob can you post your Podfile?

@claustrofob
Copy link
Author

@jberkel

    pod 'SQLite.swift', '~> 0.13.0'
    pod 'SQLite.swift/SQLCipher', '~> 0.13.0'

but I've got my mistake. It must be just subspec:

pod 'SQLite.swift/SQLCipher', '~> 0.13.0'

Now it works. The docs are a bit misleading for me here.
Thank you.

jberkel added a commit that referenced this issue Nov 16, 2021
Clarify SQLCipher integration (#1097)
@nitrag
Copy link

nitrag commented Nov 17, 2021

I'm sorry but it's still not working for me even after the subspec:

  - SQLCipher (4.5.0):
    - SQLCipher/standard (= 4.5.0)
  - SQLCipher/common (4.5.0)
  - SQLCipher/standard (4.5.0):
    - SQLCipher/common
  - SQLite.swift (0.13.1):
    - SQLite.swift/standard (= 0.13.1)
  - SQLite.swift/SQLCipher (0.13.1):
    - SQLCipher (>= 4.0.0)
  - SQLite.swift/standard (0.13.1)
  - SQLiteMigrationManager.swift (0.7.0):
    - SQLite.swift (~> 0.13.0)

@nitrag
Copy link

nitrag commented Nov 17, 2021

Ok it appears that I have resolved it. SQLiteMigrationManager depends upon non-cipher so I had to fork the repo and change the Podspec dependency. Is this resolvable automatically with CocoaPods somehow? Should I open an Issue on SQLiteMigrationManager repo?

image


Vanilla SQLiteMigrationManager 0.8.0
  - SQLCipher (4.5.0):
    - SQLCipher/standard (= 4.5.0)
  - SQLCipher/common (4.5.0)
  - SQLCipher/standard (4.5.0):
    - SQLCipher/common
  - SQLite.swift (0.13.1):
    - SQLite.swift/standard (= 0.13.1)
  - SQLite.swift/SQLCipher (0.13.1):
    - SQLCipher (>= 4.0.0)
  - SQLite.swift/standard (0.13.1)
  - SQLiteMigrationManager.swift (0.8.0):
    - SQLite.swift (~> 0.13.0)

Forked Repository SQLiteMigrationManager 0.8.0 /w SQLCipher podspec dependency
  - SQLCipher (4.5.0):
    - SQLCipher/standard (= 4.5.0)
  - SQLCipher/common (4.5.0)
  - SQLCipher/standard (4.5.0):
    - SQLCipher/common
  - SQLite.swift/SQLCipher (0.13.1):
    - SQLCipher (>= 4.0.0)
  - SQLiteMigrationManager.swift (0.8.0):
    - SQLite.swift/SQLCipher (~> 0.13.0)

@jberkel
Copy link
Collaborator

jberkel commented Nov 17, 2021

@nitrag I'm not sure what the best solution here is. Perhaps SQLiteMigrationManager could have a subspec which depends on SQLite.swift/SQLCipher (open an issue/ask over there). Or you could do some trickery in pre_install, to remove the dependency there.

@claustrofob
Copy link
Author

claustrofob commented Nov 23, 2021

Seems like there is an incompatibility between SQLite.swift and SQLite.swift/SQLCipher.

The db encrypted with some key when both specs enabled:

    pod 'SQLite.swift', '~> 0.13.0'
    pod 'SQLite.swift/SQLCipher', '~> 0.13.0'

cannot be decrypted with the same key when only subspec is enabled:

pod 'SQLite.swift/SQLCipher', '~> 0.13.0'

This is a serious problem:

  • without fix it will stop working with the next ios release
  • with the fix it breaks db access immediately for current users

Is there any workaround for this?

@claustrofob claustrofob reopened this Nov 23, 2021
@jberkel
Copy link
Collaborator

jberkel commented Nov 23, 2021

@claustrofob please see #1098. Maybe the db wasn't encrypted correctly, the documentation is misleading.

This is a serious problem:

You're using an unsupported configuration (2 specs enabled), don't blame the library for not functioning.

@claustrofob
Copy link
Author

claustrofob commented Nov 23, 2021

@jberkel sure i dont blame the library, that was my mistake. But i guess it might affect other users of the library. So i need to recover from this state somehow.

i would appreciate any idea.

@jberkel
Copy link
Collaborator

jberkel commented Nov 24, 2021

Sorry, this is not directly related to SQLite.swift, and it sounds like you might have misused SQLite.swift and/or SQLCipher. Closing this.

@jberkel jberkel closed this as completed Nov 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants