author | Olivier Brunel
<jjk@jjacky.com> 2023-10-02 11:53:24 UTC |
committer | Olivier Brunel
<jjk@jjacky.com> 2023-10-02 12:02:39 UTC |
parent | d65c7d829bd31585a7e0d061d51069db5a5d8bdc |
meta/deps/limb/version | +1 | -1 |
src/doc/ssp.1.md | +6 | -4 |
src/ssp/database.c | +8 | -2 |
diff --git a/meta/deps/limb/version b/meta/deps/limb/version index 6e8bf73..17e51c3 100644 --- a/meta/deps/limb/version +++ b/meta/deps/limb/version @@ -1 +1 @@ -0.1.0 +0.1.1 diff --git a/src/doc/ssp.1.md b/src/doc/ssp.1.md index 52b02bf..5bf4592 100644 --- a/src/doc/ssp.1.md +++ b/src/doc/ssp.1.md @@ -37,10 +37,12 @@ as well as TOTP (Time-Based One-Time Password Algorithm; as per [RFC 6238]). :: Use `ITER` iterations when performing key derivation to write database. See :: [[DATABASE]] below for more. Must be at least 50 000; Defaults to 500 000. :: -:: Note that this only applies when writing database, not reading it (since the -:: number of iterations used is stored within the file), but since the database -:: is re-encrypted each time it is written, any operation requiring to write -:: the database will make use of this setting. +:: Note that this only applies when writing database, not reading it - since the +:: number of iterations used is stored within the file. +:: +:: In addition, when re-writing (i.e. updating/editing) a database, and unless +:: this option is used, the number of iterations previously used (as read from +:: the file during opening) will be re-used by default. : *-q*, *--quiet* <inc autoopt_quiet.md> diff --git a/src/ssp/database.c b/src/ssp/database.c index d300e78..a3bcad7 100644 --- a/src/ssp/database.c +++ b/src/ssp/database.c @@ -64,7 +64,8 @@ open_db(struct ssp *ctx, int is_needed) u32 magic = SSP_MAGIC; u64 ver; - if (!shldata_read(&magic, &ver, &ctx->sa, AT_FDCWD, db_file(ctx), ctx->pwd, plen)) { + unsigned algo, iter; + if (!shldata_read(&magic, &ver, &algo, &iter, &ctx->sa, AT_FDCWD, db_file(ctx), ctx->pwd, plen)) { if (errno == EINVAL && magic != SSP_MAGIC) warnu("open database ", ESC, db_file(ctx), ESC, ": ", "not an SSP database"); else if (errno == EBADMSG) @@ -79,6 +80,11 @@ open_db(struct ssp *ctx, int is_needed) return -1; } + if (!ctx->iter) { + ctx->iter = iter; + dbg("set iteration to ", PMUINT(ctx->iter)); + } + ctx->cdboff = off; cdb_init_frommem(&ctx->cdb, ctx->sa.s + off, ctx->sa.len - off); dbg("initialized cdb [off=", PMUINT(off), " size=", PMUINT(ctx->cdb.size), "]"); @@ -185,7 +191,7 @@ rebuild_cdb(cdbmaker_sa *mkr, const char *oldkey, const char *newkey, int write_db(char *data, size_t dlen, struct ssp *ctx) { - dbg("writing db"); + dbg("writing db; iter=", PMUINT((ctx->iter) ? ctx->iter : ITER_DEF)); ssize_t plen;