What could happen if an app crashes while calling sqlite3_rekey_v2()?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

What could happen if an app crashes while calling sqlite3_rekey_v2()?

Pasin Suriyentrakorn
Hello,

What could happen if an app crashes while calling sqlite3_rekey_v2()? Is there best practice to safely call sqlite3_rekey_v2()?

Thanks,
Pasin
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: What could happen if an app crashes while calling sqlite3_rekey_v2()?

Simon Slavin-3
On 3 May 2019, at 4:15pm, Pasin Suriyentrakorn <[hidden email]> wrote:

> What could happen if an app crashes while calling sqlite3_rekey_v2()? Is there best practice to safely call sqlite3_rekey_v2()?

While rekey is working, the database temporarily contains both sets of some data.  Automatic crash recovery will see, this, recover the unconverted set, and wipe the converted set.  You do not need to take special precautions.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: What could happen if an app crashes while calling sqlite3_rekey_v2()?

David Raymond
Random question from a non-C person: What is sqlite3_rekey_v2()?

I was curious, so looked for it in the docs and don't see it listed in the C reference...
https://www.sqlite.org/c3ref/funclist.html
...and it doesn't get any hits when put into the search box for the web page.


-----Original Message-----
From: sqlite-users [mailto:[hidden email]] On Behalf Of Simon Slavin
Sent: Friday, May 03, 2019 11:38 AM
To: SQLite mailing list
Subject: Re: [sqlite] What could happen if an app crashes while calling sqlite3_rekey_v2()?

On 3 May 2019, at 4:15pm, Pasin Suriyentrakorn <[hidden email]> wrote:

> What could happen if an app crashes while calling sqlite3_rekey_v2()? Is there best practice to safely call sqlite3_rekey_v2()?

While rekey is working, the database temporarily contains both sets of some data.  Automatic crash recovery will see, this, recover the unconverted set, and wipe the converted set.  You do not need to take special precautions.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: What could happen if an app crashes while calling sqlite3_rekey_v2()?

J. King-3
It's part of the encryption extension. The function signature is
referenced publicly here:
<https://www.sqlite.org/see/doc/release/www/readme.wiki>

--
J. King

On 2019-05-03 12:04:32, "David Raymond" <[hidden email]>
wrote:

>Random question from a non-C person: What is sqlite3_rekey_v2()?
>
>I was curious, so looked for it in the docs and don't see it listed in the C reference...
>https://www.sqlite.org/c3ref/funclist.html
>...and it doesn't get any hits when put into the search box for the web page.
>
>
>-----Original Message-----
>From: sqlite-users [mailto:[hidden email]] On Behalf Of Simon Slavin
>Sent: Friday, May 03, 2019 11:38 AM
>To: SQLite mailing list
>Subject: Re: [sqlite] What could happen if an app crashes while calling sqlite3_rekey_v2()?
>
>On 3 May 2019, at 4:15pm, Pasin Suriyentrakorn <[hidden email]> wrote:
>
>>  What could happen if an app crashes while calling sqlite3_rekey_v2()? Is there best practice to safely call sqlite3_rekey_v2()?
>
>While rekey is working, the database temporarily contains both sets of some data.  Automatic crash recovery will see, this, recover the unconverted set, and wipe the converted set.  You do not need to take special precautions.
>_______________________________________________
>sqlite-users mailing list
>[hidden email]
>http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>_______________________________________________
>sqlite-users mailing list
>[hidden email]
>http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: What could happen if an app crashes while calling sqlite3_rekey_v2()?

Jens Alfke-2
In reply to this post by Simon Slavin-3


> On May 3, 2019, at 8:37 AM, Simon Slavin <[hidden email]> wrote:
>
> While rekey is working, the database temporarily contains both sets of some data.  Automatic crash recovery will see, this, recover the unconverted set, and wipe the converted set.  You do not need to take special precautions.

Thanks, Simon. So the rekey is expected to double the database file size? That’s good to know.
After the call completes, is the file size back to normal, or is a vacuum needed to reclaim disk space?

It would be good to update the SEE docs to describe this, as storage space can be a significant issue on a resource-constrained device.

—Jens
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: What could happen if an app crashes while calling sqlite3_rekey_v2()?

Simon Slavin-3
On 3 May 2019, at 5:56pm, Jens Alfke <[hidden email]> wrote:

> Thanks, Simon. So the rekey is expected to double the database file size? That’s good to know.

I don't know for sure.  I believe that the rekeying is done block by block rather than for the entire database at one time.

> After the call completes, is the file size back to normal, or is a vacuum needed to reclaim disk space?

Free space will be released once rekeying is complete, or the next time the database is closed, or something like that.  You are not expected to do VACUUM or anything like it.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: What could happen if an app crashes while calling sqlite3_rekey_v2()?

Pasin Suriyentrakorn-2
In reply to this post by Jens Alfke-2
Thanks Simon, for the answer. David, sqlite3_rekey_v2() is a function to
change the database encryption key - it's a SEE feature.

On Fri, May 3, 2019 at 9:56 AM Jens Alfke <[hidden email]> wrote:

>
>
> > On May 3, 2019, at 8:37 AM, Simon Slavin <[hidden email]> wrote:
> >
> > While rekey is working, the database temporarily contains both sets of
> some data.  Automatic crash recovery will see, this, recover the
> unconverted set, and wipe the converted set.  You do not need to take
> special precautions.
>
> Thanks, Simon. So the rekey is expected to double the database file size?
> That’s good to know.
> After the call completes, is the file size back to normal, or is a vacuum
> needed to reclaim disk space?
>
> It would be good to update the SEE docs to describe this, as storage space
> can be a significant issue on a resource-constrained device.
>
> —Jens
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: What could happen if an app crashes while calling sqlite3_rekey_v2()?

Richard Hipp-3
In reply to this post by Jens Alfke-2
On 5/3/19, Jens Alfke <[hidden email]> wrote:
>
> Thanks, Simon. So the rekey is expected to double the database file size?

Database size should be the same before and after rekey.  The rekey
operation will generate journal file entries that are about the same
size as the original database (actually slightly larger due to extra
per-page header information stored in the journal) but that temporary
space is transient. It is only used in the event of a system crash
occurs in the middle of a rekey. Once the operation completes, total
disk usage reverts to what it was before.  No VACUUM required.

VACUUM is *highly* recommended for security if you take an unencrypted
database that has never before been encrypted and "rekey" it into an
encrypted database.  That is a totally separate issue.
--
D. Richard Hipp
[hidden email]
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users