Exemple #1
0
func (ks *keyStore) createKeyStore() error {
	// Create keystore directory root if it doesn't exist yet
	ksPath := ks.conf.getKeyStorePath()
	ks.log.Debug("Creating Keystore at [%s]...", ksPath)

	missing, err := utils.FileMissing(ksPath, ks.conf.getKeyStoreFilename())
	if !missing {
		ks.log.Debug("Creating Keystore at [%s]. Keystore already there", ksPath)
		return nil
	}

	os.MkdirAll(ksPath, 0755)

	// Create Raw material folder
	os.MkdirAll(ks.conf.getRawsPath(), 0755)

	// Create DB
	ks.log.Debug("Open Keystore DB...")
	db, err := sql.Open("sqlite3", filepath.Join(ksPath, ks.conf.getKeyStoreFilename()))
	if err != nil {
		return err
	}

	ks.log.Debug("Ping Keystore DB...")
	err = db.Ping()
	if err != nil {
		ks.log.Fatal(err)
	}
	defer db.Close()

	ks.log.Debug("Keystore created at [%s].", ksPath)
	return nil
}
Exemple #2
0
func (ks *keyStore) createKeyStoreIfKeyStorePathEmpty() error {
	// Check directory
	ksPath := ks.conf.getKeyStorePath()
	missing, err := utils.DirMissingOrEmpty(ksPath)
	ks.log.Debug("Keystore path [%s] missing [%t]: [%s]", ksPath, missing, utils.ErrToString(err))

	if !missing {
		// Check file
		missing, err = utils.FileMissing(ks.conf.getKeyStorePath(), ks.conf.getKeyStoreFilename())
		ks.log.Debug("Keystore file [%s] missing [%t]:[%s]", ks.conf.getKeyStoreFilePath(), missing, utils.ErrToString(err))
	}

	if missing {
		err := ks.createKeyStore()
		if err != nil {
			ks.log.Debug("Failed creating db At [%s]: ", ks.conf.getKeyStoreFilePath(), err.Error())
			return nil
		}
	}

	return nil
}
Exemple #3
0
func (ks *keyStore) createKeyStore() error {
	dbPath := ks.conf.getKeyStorePath()
	ks.log.Debug("Creating Keystore at [%s].", dbPath)

	missing, err := utils.FileMissing(dbPath, ks.conf.getKeyStoreFilename())
	if !missing {
		ks.log.Debug("Creating Keystore at [%s]. Keystore already there", dbPath)
		return nil
	}

	os.MkdirAll(dbPath, 0755)

	ks.log.Debug("Open Keystore at [%s].", dbPath)
	db, err := sql.Open("sqlite3", filepath.Join(dbPath, ks.conf.getKeyStoreFilename()))
	if err != nil {
		return err
	}

	ks.log.Debug("Ping Keystore at [%s].", dbPath)
	err = db.Ping()
	if err != nil {
		ks.log.Fatal(err)
	}

	defer db.Close()

	// create tables
	log.Debug("Create Table if not exists [%s] at [%s].", "Certificates", dbPath)
	if _, err := db.Exec("CREATE TABLE IF NOT EXISTS Certificates (id VARCHAR, cert BLOB, PRIMARY KEY (id))"); err != nil {
		log.Debug("Failed creating table [%s].", err.Error())
		return err
	}

	ks.log.Debug("Keystore created at [%s].", dbPath)
	return nil
}
Exemple #4
0
func (node *nodeImpl) isRegistered() bool {
	missing, _ := utils.FileMissing(node.conf.getRawsPath(), node.conf.getEnrollmentIDFilename())

	return !missing
}