Пример #1
0
func loadStore(path string, m secret.ScryptMode) *store.SecretStore {
	passphrase, err := util.PassPrompt("Secrets passphrase> ")
	if err != nil {
		util.Errorf("Failed to read passphrase: %v", err)
		return nil
	}

	var passwords *store.SecretStore
	if ok, _ := util.Exists(path); ok {
		defer util.Zero(passphrase)
		fileData, err := util.ReadFile(path)
		if err != nil {
			util.Errorf("%v", err)
			return nil
		}
		var ok bool
		passwords, ok = store.UnmarshalSecretStore(fileData, passphrase, m)
		if !ok {
			return nil
		}
		return passwords
	}
	util.Errorf("could not find %s", path)
	return nil
}
Пример #2
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
}
Пример #3
0
func merge(ps *store.SecretStore, cfg *config, m secret.ScryptMode) error {
	otherPath := cfg.Args[0]
	passphrase, err := util.PassPrompt("Passphrase for other store> ")
	if err != nil {
		return err
	}

	otherData, err := util.ReadFile(otherPath)
	if err != nil {
		return err
	}

	otherStore, ok := store.UnmarshalSecretStore(otherData, passphrase, m)
	if !ok {
		return errors.New("failed to open other password store")
	}

	mergeList := ps.Merge(otherStore)
	fmt.Printf("%+v\n", mergeList)
	if len(mergeList) > 0 {
		sort.Strings(mergeList)
		for _, label := range mergeList {
			fmt.Printf("Merged '%s'\n", label)
		}
	}
	return nil
}
Пример #4
0
func main() {
	baseFile := filepath.Join(os.Getenv("HOME"), ".secrets.db")
	flag.StringVar(&session.Path, "f", baseFile, "path to password store")
	flag.DurationVar(&defaultTimeout, "t", defaultTimeout, "`timeout`")
	scryptInteractive := flag.Bool("i", false, "use scrypt interactive")
	flag.Parse()

	if defaultTimeout > maxTimeout {
		fmt.Fprintf(os.Stderr, "[!] timeout is too long (max is %s).\n",
			maxTimeout)
		os.Exit(1)
	}

	session.Scrypt = secret.ScryptStandard
	if *scryptInteractive {
		session.Scrypt = secret.ScryptInteractive
	}

	prompt := fmt.Sprintf("Passphrase to unlock %s: ", session.Path)
	passphrase, err := util.PassPrompt(prompt)
	if err != nil {
		fmt.Fprintf(os.Stderr, "[!] %v\n", err)
		os.Exit(1)
	}

	fileData, err := ioutil.ReadFile(session.Path)
	if err != nil {
		fmt.Fprintf(os.Stderr, "[!] %v\n", err)
		os.Exit(1)
	}

	var ok bool
	session.Store, ok = store.UnmarshalSecretStore(fileData, passphrase,
		session.Scrypt)
	if !ok {
		fmt.Fprintf(os.Stderr, "[!] failed to unlocked store.\n")
		os.Exit(1)
	}
	defer shutdown()

	inputLoop(session.Path)
}