Ejemplo n.º 1
0
// Reads the configuration file for storage setup, and sets up the cryptoservice
// mapping
func setUpCryptoservices(configuration *viper.Viper, allowedBackends []string) (
	signer.CryptoServiceIndex, error) {

	storeConfig, err := utils.ParseStorage(configuration, allowedBackends)
	if err != nil {
		return nil, err
	}

	var keyStore trustmanager.KeyStore
	if storeConfig.Backend == utils.MemoryBackend {
		keyStore = trustmanager.NewKeyMemoryStore(
			passphrase.ConstantRetriever("memory-db-ignore"))
	} else {
		defaultAlias := configuration.GetString("storage.default_alias")
		if defaultAlias == "" {
			// backwards compatibility - support this environment variable
			defaultAlias = configuration.GetString(defaultAliasEnv)
		}

		if defaultAlias == "" {
			return nil, fmt.Errorf("must provide a default alias for the key DB")
		}
		logrus.Debug("Default Alias: ", defaultAlias)

		dbStore, err := keydbstore.NewKeyDBStore(
			passphraseRetriever, defaultAlias, storeConfig.Backend, storeConfig.Source)
		if err != nil {
			return nil, fmt.Errorf("failed to create a new keydbstore: %v", err)
		}
		logrus.Debugf("Using %s DB: %s", storeConfig.Backend, storeConfig.Source)

		health.RegisterPeriodicFunc(
			"DB operational", dbStore.HealthCheck, time.Second*60)
		keyStore = dbStore
	}

	cryptoService := cryptoservice.NewCryptoService("", keyStore)
	cryptoServices := make(signer.CryptoServiceIndex)
	cryptoServices[data.ED25519Key] = cryptoService
	cryptoServices[data.ECDSAKey] = cryptoService
	return cryptoServices, nil
}
Ejemplo n.º 2
0
// parses the configuration and returns a backing store for the TUF files
func getStore(configuration *viper.Viper, allowedBackends []string) (
	storage.MetaStore, error) {

	storeConfig, err := utils.ParseStorage(configuration, allowedBackends)
	if err != nil {
		return nil, err
	}
	logrus.Infof("Using %s backend", storeConfig.Backend)

	if storeConfig.Backend == utils.MemoryBackend {
		return storage.NewMemStorage(), nil
	}

	store, err := storage.NewSQLStorage(storeConfig.Backend, storeConfig.Source)
	if err != nil {
		return nil, fmt.Errorf("Error starting DB driver: %s", err.Error())
	}
	health.RegisterPeriodicFunc(
		"DB operational", store.CheckHealth, time.Second*60)
	return store, nil
}