@@ -36,7 +36,6 @@ import (
3636 "github.com/snapcore/snapd/asserts"
3737 "github.com/snapcore/snapd/features"
3838 "github.com/snapcore/snapd/logger"
39- "github.com/snapcore/snapd/overlord/assertstate"
4039 "github.com/snapcore/snapd/overlord/configstate/config"
4140 "github.com/snapcore/snapd/overlord/snapstate"
4241 "github.com/snapcore/snapd/overlord/state"
@@ -55,15 +54,22 @@ const (
5554)
5655
5756var (
58- timeNow = time .Now
59- assertstateFetchAccountKey = assertstate .FetchAccountKey
57+ timeNow = time .Now
6058
6159 maxSequences = 256
6260 maxBlockedMessagesPerSequence = 8
6361
6462 awaitSubsystemRetryInterval = 30 * time .Second
6563
6664 deviceMgmtExchangeChangeKind = swfeats .RegisterChangeKind ("device-management-exchange" )
65+
66+ // AssertstateDB, AssertstateAccountKey and AssertstateFetchAccountKey are
67+ // wired to the corresponding assertstate helpers by
68+ // assertstate.delayedCrossMgrInit. They exist to break the import cycle
69+ // assertstate -> confdbstate -> devicemgmtstate -> assertstate.
70+ AssertstateDB func (s * state.State ) asserts.RODatabase
71+ AssertstateAccountKey func (st * state.State , signKeyID string ) (* asserts.AccountKey , error )
72+ AssertstateFetchAccountKey func (st * state.State , userID int , signKeyID string ) error
6773)
6874
6975// deviceBackend provides device identity and response message signing.
@@ -660,7 +666,7 @@ func (m *DeviceMgmtManager) doValidateMessage(t *state.Task, _ *tomb.Tomb) error
660666 }
661667 }
662668
663- err = assertstate . DB (m .state ).Check (a )
669+ err = AssertstateDB (m .state ).Check (a )
664670 if err != nil {
665671 rejectMsg (fmt .Sprintf ("cannot verify message signature: %v" , err ))
666672 return nil
@@ -720,15 +726,15 @@ func (m *DeviceMgmtManager) doValidateMessage(t *state.Task, _ *tomb.Tomb) error
720726// ensureAccountKey fetches the account-key assertion for signKeyID from the
721727// store if it is not already in the local database.
722728func (m * DeviceMgmtManager ) ensureAccountKey (signKeyID string ) (fetched bool , err error ) {
723- _ , err = assertstate . AccountKey (m .state , signKeyID )
729+ _ , err = AssertstateAccountKey (m .state , signKeyID )
724730 if err == nil {
725731 return false , nil
726732 }
727733 if ! errors .Is (err , & asserts.NotFoundError {}) {
728734 return false , err
729735 }
730736
731- err = assertstateFetchAccountKey (m .state , 0 , signKeyID )
737+ err = AssertstateFetchAccountKey (m .state , 0 , signKeyID )
732738 if err != nil && ! errors .Is (err , & asserts.NotFoundError {}) {
733739 return true , err
734740 }
0 commit comments