Пример #1
0
func (c App) storeHOTP(otp *hotp.HOTP) error {
	out, err := hotp.Marshal(otp)
	if err != nil {
		c.Flash.Error("Oh no! I couldn't store the HOTP key value!")
		revel.ERROR.Printf("failed to store HOTP key value: %v", err)
		c.FlashParams()
		return err
	}

	c.Session["otp"] = base64.StdEncoding.EncodeToString(out)
	return nil
}
Пример #2
0
func main() {
	digits := flag.Int("d", 6, "number of digits")
	doRand := flag.Bool("r", false, "randomise counter")
	flag.Parse()

	var label string
	if flag.NArg() == 1 {
		label = flag.Arg(0)
	}

	otp, err := hotp.GenerateHOTP(*digits, *doRand)
	if err != nil {
		fmt.Printf("! %v\n", err.Error())
		return
	}

	url := otp.URL(label)
	png, err := otp.QR(label)
	if err != nil {
		fmt.Printf("! %v\n", err.Error())
		return
	}

	filename := label
	if label == "" {
		filename = base32.StdEncoding.EncodeToString([]byte(url))
	}
	err = ioutil.WriteFile(filename+".png", png, 0644)
	if err != nil {
		fmt.Printf("! %v\n", err.Error())
		return
	}

	err = ioutil.WriteFile(filename+".txt", []byte(url), 0644)
	if err != nil {
		fmt.Printf("! %v\n", err.Error())
		return
	}

	keyFile, err := hotp.Marshal(otp)
	if err != nil {
		fmt.Printf("! %v\n", err.Error())
		return
	}
	err = ioutil.WriteFile(filename+".key", keyFile, 0644)
	if err != nil {
		fmt.Printf("! %v\n", err.Error())
		return
	}
}
Пример #3
0
func main() {
	check := flag.Bool("c", false, "do integrity check")
	noUpdate := flag.Bool("n", false, "don't update counter")
	keyFile := flag.String("k", "hotp.key", "key file")
	url := flag.String("u", "", "URL to load new key from")
	write := flag.Bool("w", false, "only write URL-loaded key to file")
	flag.Parse()

	var otp *hotp.HOTP
	if *url != "" {
		var err error
		otp, _, err = hotp.FromURL(*url)
		if err != nil {
			fmt.Printf("[!] %v\n", err.Error())
			return
		}

		if *write {
			out, err := hotp.Marshal(otp)
			if err != nil {
				fmt.Printf("[!] %v\n", err.Error())
				return
			}

			err = ioutil.WriteFile(*keyFile, out, 0600)
			if err != nil {
				fmt.Printf("[!] %v\n", err.Error())
				return
			}

			return
		}
	} else {
		in, err := ioutil.ReadFile(*keyFile)
		if err != nil {
			fmt.Printf("[!] %v\n", err.Error())
			return
		}

		otp, err = hotp.Unmarshal(in)
		if err != nil {
			fmt.Printf("[!] %v\n", err.Error())
			return
		}
	}

	if *check {
		code, counter := otp.IntegrityCheck()
		fmt.Println("   code:", code)
		fmt.Println("counter:", counter)
	} else {
		fmt.Println(otp.OTP())
	}

	if !*noUpdate {
		out, err := hotp.Marshal(otp)
		if err != nil {
			fmt.Printf("[!] %v\n", err.Error())
			return
		}

		err = ioutil.WriteFile(*keyFile, out, 0600)
		if err != nil {
			fmt.Printf("[!] %v\n", err.Error())
			return
		}
	}
}