Exemplo n.º 1
0
func initStore(path string, m secret.ScryptMode) error {
	passphrase, err := util.PassPrompt("Secrets passphrase> ")
	if err != nil {
		util.Errorf("Failed to read passphrase: %v", err)
		return err
	}

	if len(passphrase) == 0 {
		return fmt.Errorf("No passphrase provided.")
	}

	defer util.Zero(passphrase)
	passwords := store.NewSecretStore(passphrase)
	if passwords == nil {
		return fmt.Errorf("failed to create store")
	}

	fmt.Println("creating store...")
	fileData, ok := store.MarshalSecretStore(passwords, m)
	if !ok {
		return fmt.Errorf("failed to marshal store")
	}

	err = util.WriteFile(fileData, path)
	if err != nil {
		return err
	}

	passwords, ok = store.UnmarshalSecretStore(fileData, passphrase, m)
	if !ok {
		err = fmt.Errorf("failed to unmarshal store")
	}
	return err
}
Exemplo n.º 2
0
func writeStore(ps *store.SecretStore, path string, m secret.ScryptMode) bool {
	fileData, ok := store.MarshalSecretStore(ps, m)
	if !ok {
		return false
	}

	err := util.WriteFile(fileData, path)
	if err != nil {
		util.Errorf("Write failed: %v", err)
		return false
	}
	return true
}
Exemplo n.º 3
0
func writeStore() bool {
	if !session.Dirty {
		return true
	}

	fmt.Printf("[+] storing secret store...\n")
	fileData, ok := store.MarshalSecretStore(session.Store, session.Scrypt)
	if !ok {
		return false
	}

	err := util.WriteFile(fileData, session.Path)
	if err != nil {
		fmt.Fprintf(os.Stderr, "[!] failed to write store to %s:\n",
			err)
		fmt.Fprintf(os.Stderr, "\t%v\n", err)
		return false
	}

	session.Dirty = false
	return true
}