github.com/rigado/snapd@v2.42.5-go-mod+incompatible/asserts/sysdb/sysdb.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2015-2016 Canonical Ltd
     5   *
     6   * This program is free software: you can redistribute it and/or modify
     7   * it under the terms of the GNU General Public License version 3 as
     8   * published by the Free Software Foundation.
     9   *
    10   * This program is distributed in the hope that it will be useful,
    11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13   * GNU General Public License for more details.
    14   *
    15   * You should have received a copy of the GNU General Public License
    16   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17   *
    18   */
    19  
    20  // Package sysdb supports the system-wide assertion database with ways to open it and to manage the trusted set of assertions founding it.
    21  package sysdb
    22  
    23  import (
    24  	"github.com/snapcore/snapd/asserts"
    25  	"github.com/snapcore/snapd/dirs"
    26  )
    27  
    28  func openDatabaseAt(path string, cfg *asserts.DatabaseConfig) (*asserts.Database, error) {
    29  	bs, err := asserts.OpenFSBackstore(path)
    30  	if err != nil {
    31  		return nil, err
    32  	}
    33  	keypairMgr, err := asserts.OpenFSKeypairManager(path)
    34  	if err != nil {
    35  		return nil, err
    36  	}
    37  	cfg.Backstore = bs
    38  	cfg.KeypairManager = keypairMgr
    39  	return asserts.OpenDatabase(cfg)
    40  }
    41  
    42  // Open opens the system-wide assertion database with the trusted assertions set configured.
    43  func Open() (*asserts.Database, error) {
    44  	cfg := &asserts.DatabaseConfig{
    45  		Trusted:         Trusted(),
    46  		OtherPredefined: Generic(),
    47  	}
    48  	return openDatabaseAt(dirs.SnapAssertsDBDir, cfg)
    49  }