next-eeze.git

ref: b8662330e5a2aed7af1568e6cddb044597857f5c

config/init.go


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package config

import (
	"notabug.org/apiote/next-eeze/fs"

	"fmt"
	"os"

	"golang.org/x/crypto/ssh/terminal"
)

// todo memguard masterPassword
func Init(masterPassword string) {
	// todo memguard
	credentials := fs.Credentials{}
	fmt.Print("Server address: ")
	fmt.Scanf("%s", &credentials.Server)
	fmt.Print("Username: ")
	fmt.Scanf("%s", &credentials.Username)
	fmt.Print("Password: ")
	// todo memguard
	p_b, _ := terminal.ReadPassword(int(os.Stdin.Fd()))
	credentials.Password = string(p_b)
	fmt.Print("\n")

	fs.SaveCredentials(credentials, masterPassword)
}

func Reëncrypt(masterPassword string) (string, error) {
	fmt.Print("New master password: ")
	// todo memguard
	p_b, _ := terminal.ReadPassword(int(os.Stdin.Fd()))
	newMasterPassword := string(p_b)
	fmt.Print("\n")
	// todo memguard
	credentials, err := fs.ReadCredentials(masterPassword)
	if err != nil {
		return "", err
	}
	err = fs.SaveCredentials(credentials, newMasterPassword)
	if err != nil {
		return "", err
	}
	// todo memguard
	passwords, err := fs.Read(masterPassword)
	if err != nil {
		return "", err
	}
	err = fs.SaveBare(passwords, newMasterPassword)
	if err != nil {
		return "", err
	}

	return newMasterPassword, nil
}