GrantTrust
Decides whether a presented Grant lets a device back into this host's room now.
A device that comes back shows the pass the host gave it. Before letting it skip vetting, the host checks that the pass is its own (hostKey issued and signed it), that it names the device that is presenting it, that it is for this room, that the device was not revoked since (revocations), that it is not dated in the future, and that it has not run out. verify answers with the first check that fails, in that order, or GrantVerdict.Valid:
GrantVerdict.UntrustedIssuer — Grant.issuer is not hostKey.
GrantVerdict.BadSignature — the signature is not hostKey's over the grant's terms.
GrantVerdict.WrongSubject — Grant.subject is not the presenting device's key.
GrantVerdict.WrongScope — a GrantScope.Room for another room id. GrantScope.AnyRoomOfIssuer is good in every room hostKey hosts.
GrantVerdict.Revoked — Grant.issuedAt is before the subject's RevocationList.notBefore.
GrantVerdict.NotYetValid — Grant.issuedAt is more than CLOCK_SKEW_ALLOWANCE_MILLIS past
now. A grant dated up to the allowance ahead is accepted, so a clock nudged back a little between issuing and checking does not turn a good pass away.GrantVerdict.Expired —
nowis at or past Grant.notAfter. A grant with Grant.NO_EXPIRY never expires, not even atnow = Long.MAX_VALUE.
The last two are the two ends of the span a grant is good for, and no grant meets both: its Grant.notAfter is always after its Grant.issuedAt, so a grant dated after now has not run out.
A future-dated grant is refused because of what it does to a revocation. A pass issued while the host's clock ran a year ahead carries an Grant.issuedAt a year out. Once the clock is corrected, revoke(subject, now + 1) sets a cutoff before that date and does not void the pass. Refusing it as GrantVerdict.NotYetValid stops the device returning on it until the clock nears its date. From then on it is good again, so a host that must void such a pass for good still picks a cutoff past the latest Grant.issuedAt it gave the device.
The only trusted issuer is the host's own key. So losing that key is the safe direction: every grant the host ever issued becomes GrantVerdict.UntrustedIssuer, and those devices are vetted again. Losing the revocations is the dangerous one, since revoked devices come back on their old passes.
verify reads no clock and keeps no state of its own: given the same grant, subject, room, time and revocations it gives the same verdict. It reads revocations as they are at the call.
Parameters
The scheme the signature is checked in: the room's own DeviceKeyStore.keyScheme. The two-argument constructor checks in KeyScheme.P256.
Samples
val host = DeviceKey.generate() // the host's own key: the only issuer it trusts
val phone = DeviceKey.generate() // a device the host let in once
val revocations = RevocationList.inMemory()
val trust = GrantTrust(host.id, revocations)
val now = 1_700_000_000_000L // epoch ms, from your clock: the check never reads one
// The phone comes back with the pass the host gave it, having proved it holds `phone`'s key.
val pass = Grant.issue(host, phone.id, GrantScope.Room("table-7"), issuedAt = now, notAfter = now + 3_600_000)
check(trust.verify(pass, phone.id, "table-7", now + 60_000) == GrantVerdict.Valid)
// The first thing wrong is the answer: another room, another device, too late.
check(trust.verify(pass, phone.id, "table-8", now + 60_000) == GrantVerdict.WrongScope)
check(trust.verify(pass, host.id, "table-7", now + 60_000) == GrantVerdict.WrongSubject)
check(trust.verify(pass, phone.id, "table-7", now + 3_600_000) == GrantVerdict.Expired)
// Too early: a pass dated more than five minutes past the clock, issued while it ran ahead.
val postDated = Grant.issue(host, phone.id, GrantScope.Room("table-7"), issuedAt = now + 600_000, notAfter = now + 3_600_000)
check(trust.verify(postDated, phone.id, "table-7", now) == GrantVerdict.NotYetValid)
// The phone is lost: revoke it. A pass issued exactly at the cutoff stays good, so the cutoff is
// one past the clock, or one issued in this same millisecond would slip through.
val lostAt = now + 120_000
val sameMillisecond = Grant.issue(host, phone.id, GrantScope.Room("table-7"), issuedAt = lostAt, notAfter = lostAt + 3_600_000)
revocations.revoke(phone.id, notBefore = lostAt + 1)
check(trust.verify(pass, phone.id, "table-7", lostAt + 60_000) == GrantVerdict.Revoked)
check(trust.verify(sameMillisecond, phone.id, "table-7", lostAt + 60_000) == GrantVerdict.Revoked)
// A fresh pass, issued after the cutoff, works again.
val fresh = Grant.issue(host, phone.id, GrantScope.Room("table-7"), issuedAt = lostAt + 120_000, notAfter = lostAt + 3_720_000)
check(trust.verify(fresh, phone.id, "table-7", lostAt + 180_000) == GrantVerdict.Valid)Constructors
A trust that checks signatures in KeyScheme.P256: ECDSA through the platform's provider.