183 Commits

Author SHA1 Message Date
Samuele Pedroni
4a8ecace54 devicestate: Unregister deletes the device key pair as well
* daemon,tests: support forgetting device serial via API

this is done by posting {"action":"forget"} to /v2/model/serial

a flag no-registration-until-reboot is also supported

* many: more consistent naming Delete => DeleteByName on keypair mgrs

we actually want to introduce a Delete by key id on some of them now

* asserts: implement KeypairManager.Delete

* devicestate: Unregister deletes the device key pair as well

* tests: test device key deletion in generic-unregister

* asserts: avoid skipping the GPGKeypairManager.Delete test

pair --yes to --batch in the test
2021-12-02 18:04:53 +01:00
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
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
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
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
Samuele Pedroni
790f40c403 asserts: comment about building the sequence key
thanks @bboozzoo
2020-07-08 11:44:03 +02:00
Samuele Pedroni
30e07ef812 asserts: make use errors more grammatical
thanks @stolowski, @degville
2020-07-08 11:40:50 +02:00
Samuele Pedroni
237c0103ac asserts: implement Database.FindSequence
FindSequence finds a sequence-forming assertion based the given
headers. Provided headers must contain a prefix of the primary key
for the assertion type except for the sequence header.
Th assertion is the first in the sequence under the prefix with
sequential number > after.
If after is -1 it returns instead the assertion with the largest
sequential number.
2020-06-29 14:14:28 +02:00
Samuele Pedroni
e70ab5bf84 asserts: adjust terminology: sequence key, sequence number 2020-06-29 14:04:15 +02:00
Samuele Pedroni
4422c93e87 asserts: introduce Backstore.SequenceMemberAfter
implement it first for the memoryBackstore

there's also an always failing impementation for filesystemBackstore
for now
2020-06-29 13:52:36 +02:00
Samuele Pedroni
cb0829320a make stackedOn a first class field for clarity 2019-07-25 17:09:33 +02:00
Samuele Pedroni
d1e2afcbb1 introduce asserts.Database.WithStackedBackstore 2019-07-19 09:37:15 +02:00
Samuele Pedroni
97e3ef21a3 many: introduce asserts.NotFoundError replacing both ErrNotFound and store.AssertionNotFoundError (#3893)
This converts the singleton asserts.ErrNotFound to a richer asserts.NotFoundError struct carrying Type and optionally PrimaryKey, similar to store.AssertionNotFoundError which then gets folded with this.

This means code doesn't have to worry anymore which is which or to convert between the two. And when possible there is more information around. Though Backstores can continue to return minimal information (Type but not Headers in the new error).

A helper asserts.IsNotFound is also added to cover the simple old ==/!= asserts.ErrNotFound needs.

This also fixes/adjust some error handling to usually not repeat the richer information twice.
2017-09-12 16:34:53 +02:00
Samuele Pedroni
392fbba353 improve errors 2017-08-10 16:02:25 +02:00
Samuele Pedroni
103f98f17e support predefined assertions that don't establish foundational trust 2017-08-09 12:55:23 +02:00
Samuele Pedroni
ad12f1c854 asserts: implement FindManyTrusted as well (#3516) 2017-06-23 11:16:55 +02:00
Michael Vogt
82e8c19461 address review feedback 2017-01-20 09:43:40 +01:00
Michael Vogt
519ced9127 Improve error message when key is not valid at the given time
A user ran into this today and this makes it easier for the user
to know what exactly the problem is.
2017-01-12 17:13:22 +01:00
Samuele Pedroni
4c9a64cf73 review feedback 2016-10-18 12:01:29 +02:00
Samuele Pedroni
881219252e add FindSupported(.,.,maxFormat) to the Datbase 2016-10-17 21:11:38 +02:00
Samuele Pedroni
aed9a33777 Merge branch 'asserts-format' into asserts-format-find 2016-10-17 20:06:09 +02:00
Samuele Pedroni
613d492324 review feedback 2016-10-17 19:57:08 +02:00
Samuele Pedroni
048581aac2 start teaching backends about selecting by max supported format 2016-10-17 19:29:56 +02:00