1 Star 0 Fork 1

mysnapcore/mysnapd

forked from tupelo-shen/mysnapd 
加入 Gitee
與超過 1200 萬 開發者一起發現、參與優秀開源項目,私有倉庫也完全免費 :)
免費加入
文件
.gitee
advisor
arch
aspects
asserts
boot
bootloader
c-vendor
client
cmd
daemon
dbusutil
desktop
dirs
docs
errtracker
features
gadget
httputil
i18n
image
include/lk
interfaces
jsonutil
kernel
logger
metautil
netutil
osutil
overlord
assertstate
assertstatetest
assertmgr.go
assertstate.go
assertstate_test.go
bulk.go
export_test.go
helpers.go
validation_set_tracking.go
validation_set_tracking_test.go
auth
cmdstate
configstate
devicestate
healthstate
hookstate
ifacestate
patch
restart
servicestate
snapshotstate
snapstate
standby
state
storecontext
backend.go
export_test.go
managers_test.go
overlord.go
overlord_test.go
stateengine.go
stateengine_test.go
unknowntask.go
po
polkit
progress
randutil
release
sandbox
secboot
seed
snap
snapdenv
snapdtool
spdx
store
strutil
syscheck
sysconfig
systemd
tests
testutil
timeout
timeutil
timings
usersession
vendor
wrappers
x11
.gitignore
LICENSE
README.en.md
README.md
get-deps.sh
go.mod
go.sum
mdlint.py
mkversion.sh
update-pot
克隆/下載
assertmgr.go 4.26 KB
一鍵複製 編輯 原始數據 按行查看 歷史
tupelo-shen 提交於 3年前 . fix: overlord commit
// -*- Mode: Go; indent-tabs-mode: t -*-
/*
* Copyright (C) 2016-2022 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package assertstate
import (
"fmt"
"gopkg.in/tomb.v2"
"gitee.com/mysnapcore/mysnapd/asserts"
"gitee.com/mysnapcore/mysnapd/asserts/snapasserts"
"gitee.com/mysnapcore/mysnapd/asserts/sysdb"
"gitee.com/mysnapcore/mysnapd/overlord/snapstate"
"gitee.com/mysnapcore/mysnapd/overlord/state"
)
// AssertManager is responsible for the enforcement of assertions in
// system states. It manipulates the observed system state to ensure
// nothing in it violates existing assertions, or misses required
// ones.
type AssertManager struct{}
// Manager returns a new assertion manager.
func Manager(s *state.State, runner *state.TaskRunner) (*AssertManager, error) {
delayedCrossMgrInit()
runner.AddHandler("validate-snap", doValidateSnap, nil)
db, err := sysdb.Open()
if err != nil {
return nil, err
}
s.Lock()
ReplaceDB(s, db)
s.Unlock()
return &AssertManager{}, nil
}
// Ensure implements StateManager.Ensure.
func (m *AssertManager) Ensure() error {
return nil
}
type cachedDBKey struct{}
// ReplaceDB replaces the assertion database used by the manager.
func ReplaceDB(state *state.State, db *asserts.Database) {
state.Cache(cachedDBKey{}, db)
}
func cachedDB(s *state.State) *asserts.Database {
db := s.Cached(cachedDBKey{})
if db == nil {
panic("internal error: needing an assertion database before the assertion manager is initialized")
}
return db.(*asserts.Database)
}
// DB returns a read-only view of system assertion database.
func DB(s *state.State) asserts.RODatabase {
return cachedDB(s)
}
// doValidateSnap fetches the relevant assertions for the snap being installed and cross checks them with the snap.
func doValidateSnap(t *state.Task, _ *tomb.Tomb) error {
st := t.State()
st.Lock()
defer st.Unlock()
snapsup, err := snapstate.TaskSnapSetup(t)
if err != nil {
return fmt.Errorf("internal error: cannot obtain snap setup: %s", err)
}
sha3_384, snapSize, err := asserts.SnapFileSHA3_384(snapsup.SnapPath)
if err != nil {
return err
}
deviceCtx, err := snapstate.DeviceCtx(st, t, nil)
if err != nil {
return err
}
modelAs := deviceCtx.Model()
expectedProv := snapsup.ExpectedProvenance
err = doFetch(st, snapsup.UserID, deviceCtx, nil, func(f asserts.Fetcher) error {
if err := snapasserts.FetchSnapAssertions(f, sha3_384, expectedProv); err != nil {
return err
}
// fetch store assertion if available
if modelAs.Store() != "" {
err := snapasserts.FetchStore(f, modelAs.Store())
if notFound, ok := err.(*asserts.NotFoundError); ok {
if notFound.Type != asserts.StoreType {
return err
}
} else if err != nil {
return err
}
}
return nil
})
if notFound, ok := err.(*asserts.NotFoundError); ok {
if notFound.Type == asserts.SnapRevisionType {
return fmt.Errorf("cannot verify snap %q, no matching signatures found", snapsup.InstanceName())
} else {
return fmt.Errorf("cannot find supported signatures to verify snap %q and its hash (%v)", snapsup.InstanceName(), notFound)
}
}
if err != nil {
return err
}
db := DB(st)
verifiedRev, err := snapasserts.CrossCheck(snapsup.InstanceName(), sha3_384, expectedProv, snapSize, snapsup.SideInfo, modelAs, db)
if err != nil {
// TODO: trigger a global validity check
// that will generate the changes to deal with this
// for things like snap-decl revocation and renames?
return err
}
// we have an authorized snap-revision with matching hash for
// the blob, double check that the snap metadata provenance
// matches
if err := snapasserts.CheckProvenanceWithVerifiedRevision(snapsup.SnapPath, verifiedRev); err != nil {
return err
}
// TODO: set DeveloperID from assertions
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mysnapcore/mysnapd.git
git@gitee.com:mysnapcore/mysnapd.git
mysnapcore
mysnapd
mysnapd
v0.0.1

搜索幫助