1027 Commits

Author SHA1 Message Date
Alberto Mardegan
37e83765f3 asserts: fix errors reported by linter
Besides some trivial fixes, this also adds the (previously unused) class
`isUnacceptedUpdateSuite` to the tests suite.
2021-05-05 10:16:20 +03:00
Samuele Pedroni
35c76d6f1a seed: ReadSystemEssentialAndBetterEarliestTime (#10005)
ReadSystemEssentialAndBetterEarliestTime retrieves in one go
information about the model and essential snaps of the given types
for the Core 20 recovery system seed specified by seedDir and label
(which cannot be empty).
It can operate even if current system time is unreliable by taking
a earliestTime lower bound for current time.
It returns as well an improved lower bound by considering appropriate
assertions in the seed.

* asserts: Batch.CommitToAndObserve

have a variant of CommitTo that supports a callback to consider each
assertion immediately after it has been added to the database, at
which point it also verified
2021-03-18 18:40:16 +01:00
Samuele Pedroni
1b4d6fe258 asserts: isValidAssumingCurTimeWithin earliest=time.Time{} tests
also fix some test comments
2021-03-12 14:33:31 +01:00
Samuele Pedroni
0109e8c283 asserts: fix some typos 2021-03-11 09:58:07 +01:00
Samuele Pedroni
f3d9f94d54 asserts: clarify/simplify AccountKey.isValidAssumingCurTimeWithin
simplify the code a bit, try to improve the name/comments

thanks @mvo and @stolowski
2021-03-10 14:14:54 +01:00
Samuele Pedroni
0409b0d0e9 asserts: mode where Database only assumes cur time >= earliest time
if current system time is unreliable have a mode where Database checks
for key expiry just based on assuming that current time is >= known
earliest time

this is set up via Database.SetEarliestTime

internally a new predicate AccountKey.isKeyValidAbout(earliest,
latest) is used to support this
2021-03-05 09:27:12 +01:00
Paweł Stołowski
9861c37af9 Cleanup the tests to make them more consistent (thanks ijohnson),
simplify addToGrouping ifs.
2021-03-02 13:08:44 +00:00
Paweł Stołowski
37828afb66 Use Fetcher in AddSequenceToUpdate. Fix addUnresolvedSeq not returning error. 2021-03-02 13:08:03 +00:00
Pawel Stolowski
07b6ed2059 asserts: pool changes for validation-sets (#9930)
Support for sequence-forming assertions in pool.
2021-03-02 12:09:21 +01:00
Maciej Borzecki
0fb99cff8c asserts: include the assertion timestamp in error message when outside of signing key validity range
We occasionally get the following backtrace in the tests:

----------------------------------------------------------------------
PANIC: api_users_test.go:762: userSuite.TestPostCreateUserFromAssertionNoModel

... Panic: cannot add test assertions: model assertion timestamp outside of signing key validity (key valid since "2021-02-23 11:10:41 +0000 UTC") (PC=0x45CF4A)

/snap/go/2117/src/runtime/panic.go:491
  in gopanic
/home/runner/work/snapd/snapd/src/github.com/snapcore/snapd/overlord/assertstate/assertstatetest/add_many.go:38
  in AddMany
api_users_test.go:776
  in userSuite.TestPostCreateUserFromAssertionNoModel
/snap/go/2117/src/reflect/value.go:302
  in Value.Call
/snap/go/2117/src/runtime/asm_amd64.s:2337
  in goexit
OOPS: 439 passed, 1 skipped, 1 PANICKED
--- FAIL: Test (9.62s)
FAIL
coverage: 86.4% of statements
FAIL	github.com/snapcore/snapd/daemon	9.786s

Adding a timestamp of the assertion, will help it to debug the problem further.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2021-02-25 11:42:27 +01:00
Michael Vogt
95dfe3f77b Merge pull request #9880 from anonymouse64/feature/uc20-recover-repair-asserts-5.2
tests/lib/fakestore: support repair assertions too
2021-02-22 09:22:55 +01:00
Michael Vogt
fafbca2c3b Merge pull request #9931 from pedronis/asserts-deeper-authority-x-check
asserts: repeat the authority cross-check in CheckSignature as well
2021-02-15 09:24:22 +01:00
Michael Vogt
79af41af63 Merge remote-tracking branch 'upstream/master' into feature/uc20-recover-repair-asserts-5.2 2021-02-15 09:22:31 +01:00
Ian Johnson
b7defb8284 asserts/systestkeys/trusted.go: adjust root testkeys repair assertion
The root account-key testkeys assertion for repairs should have the same
account-id and authority-id.

This was generated using https://gist.github.com/anonymouse64/f644d32f8fc24b98399cf2cb36891931

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-02-12 13:48:23 -06:00
Samuele Pedroni
8eff2997ae asserts: repeat the authority cross-check in CheckSignature as well
findAccountKey was alread checking this but
this is an additional defense and makes CheckSignature a more
robust standalone helper if used that way
2021-02-12 18:29:30 +01:00
Ian Johnson
8150796546 asserts/assertstest: line-wrap some doc-comments
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-02-11 16:03:09 -06:00
Ian Johnson
eba91d25fb asserts/systestkeys/trusted.go: add separate root of trust for repair asserts
This is to mimic real repair assertions which have a separate root of trust from
the main root canonical keys, we should have a separate (testkeys) root of trust
to use in spread tests.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-02-11 15:26:21 -06:00
Paweł Stołowski
f8140735e9 Merge branch 'master' into validation-sets/store-action-validation-sets 2021-02-05 09:16:37 +00:00
Paweł Stołowski
1fb898b3e8 Two extra test checks. 2021-02-04 15:07:41 +00:00
Paweł Stołowski
bf0b0d6158 Update error handling as error-list can have sequence key instead of
primary-key for sequence-forming assertions.
2021-02-04 11:51:53 +00:00
Paweł Stołowski
7271dc757e Merge branch 'validation-sets/at-sequence' into validation-sets/store-action-validation-sets 2021-02-04 11:46:49 +00:00
Paweł Stołowski
cf75a47c6b Tweak AtSequence comment, omit "?" in the string repr if sequence point
is not set.
2021-02-04 11:36:38 +00:00
Paweł Stołowski
f027fdcf1a Handle NotFound error explicitly from Resolve; add
HeadersFromSequenceKey helper.
2021-02-03 16:28:04 +00:00
Paweł Stołowski
fe6ced9742 Extend comments, simplify String(). 2021-02-03 15:52:22 +00:00
Paweł Stołowski
cd8cfd0c3d Update ToResolve() signature in pool and the tests. 2021-02-03 11:50:23 +00:00