예제 #1
0
func main() {
	pwd, err := pwd.PromptNewPassword(40.0)
	if err != nil {
		fmt.Println("Failed: ", err)
		return
	}

	salt := make([]byte, 32)
	if _, err := rand.Reader.Read(salt); err != nil {
		fmt.Println("Reading salt failed, you're likely doomed.")
		return
	}

	key := security.Scrypt([]byte(pwd), salt, 32)
	fmt.Printf("Key:  %x\nSalt: %x\n", key, salt)
}
예제 #2
0
func handleInit(ctx *cli.Context) error {
	ID, err := id.Cast(ctx.Args().First())
	if err != nil {
		return ExitCode{
			BadArgs,
			fmt.Sprintf("Bad ID: %v", err),
		}
	}

	// Extract the folder from the resource name by default:
	folder := ctx.GlobalString("path")
	fmt.Println("Folder:", folder)
	if folder == "." {
		folder = ID.AsPath()
	}

	pwd := ctx.GlobalString("password")
	fmt.Println(pwd)
	if pwd == "" {
		// TODO: Lower this or make it at least configurable
		pwdBytes, err := pwdutil.PromptNewPassword(40.0)
		if err != nil {
			return ExitCode{BadPassword, err.Error()}
		}

		pwd = string(pwdBytes)
	}

	log.Warning("============================================")
	log.Warning("Please make sure to remember the passphrase!")
	log.Warning("Your data will not be accessible without it.")
	log.Warning("============================================")

	repo, err := repo.NewRepository(string(ID), pwd, folder)
	if err != nil {
		return ExitCode{UnknownError, err.Error()}
	}

	if err := repo.Close(); err != nil {
		return ExitCode{
			UnknownError,
			fmt.Sprintf("close: %v", err),
		}
	}

	if !ctx.GlobalBool("nodaemon") {
		port, err := repo.Config.Int("daemon.port")
		if err != nil {
			return ExitCode{UnknownError, "Unable to find out port"}
		}

		if _, err := daemon.Reach(string(pwd), folder, port); err != nil {
			return ExitCode{
				DaemonNotResponding,
				fmt.Sprintf("Unable to start daemon: %v", err),
			}
		}
	}

	return nil
}