It's a better pattern to refer to sessions in the same way consistently.
So we update the UpdateSessionRemotePubKey method to use a session ID as
a reference to the session instead of local pub key.
In this commit, we more tightly & explicitly link a session to an
account. At a persitance layer, we have always only linked a session to
an account by encoding the AccountID within the macaroon caveat that we
store with the session. We still keep this persistence the same but now
we first ensure that the account exists and we also add an AccountID
field to the Session struct.
When we link a session to an account, we want to be able to validate
that the account actually does exist. So in preparation for that, we
first give the session store access to the accounts store.
Before we add the SQL implementation of the store, we fix this timestamp
to be a more realistic number. This is needed since in sqlite,
timestamps are serialised as strings and golang actually cant parse the
string for the current timestamp back into a time.Time. This is the
error that will be encountered:
`parsing time "99999-01-01 00:00:00 +0000 UTC" as "2006-01-02
15:04:05.999999999 -0700 MST": cannot parse "9-01-01 00:00:00 +0000 UTC"
as "-"`
We only really ever use it in one place and even then, only for a
session State that we no longer use anymore.
This is done to make the SQL queries we will need to implement the SQL
Store more simple.
In preparation for adding helpers with the same names but that will
compile under different build flags, we add the helper DB constructors
to use when testing the session store logic against a KVDB backend.
This was used to check that all linked sessions are no longer
active before attempting to register an autopilot session. But this is
no longer needed since this is done within NewSession.
In this commit, we let StateReserved be the new initial state of a
session for when NewSession is called. We then do predicate checks for
linked sessions along with unique session alias (ID) and priv key
derivations all under the same DB transaction in NewSession.
ShiftState then moves a session to StateCreated. Only in StateCreated
does a session become usable.
With this change, we no longer need to ensure atomic session creation by
acquiring the `sessRegMu` mutex in the session RPC server.
For now, it makes no DB calls. But this is in prepartion for letting
this call persist a new session. This will also let us use a shared
`clock` for the time fields in a Session.
In this commit, we refactor various uses of the session.MacaroonRecipe
type outside of the session package. This is to decouple the baking of a
super macaroon from the sessions package and will help avoid import
cycles in future.