Beispiel #1
0
func presentQRCode(pl meddler.Payload, res http.ResponseWriter, req *http.Request) {
	foundKeySet, err := lookUpKeySet(pl.PublicKey)

	if err != nil {
		http.Error(res, fmt.Sprintf("encountered error: %v", err), 400)
		return
	}

	if foundKeySet == nil {
		panic("null keySet returned from publicKeyLookup")
	}

	rawTextForSigning := pl.RawTextForSigning()
	if !foundKeySet.Match([]byte(rawTextForSigning), []byte(pl.Signature)) {
		http.Error(res, "invalid signature", 403)
		return
	}

	curTimeUnix := time.Now().Unix()
	if pl.ExpiryTime < curTimeUnix {
		http.Error(res, fmt.Sprintf("request expired at %q, current time %q", pl.ExpiryTime, curTimeUnix), 403)
		return
	}

	uri := pl.URI
	code, err := qr.Encode(uri, qr.Q)
	if err != nil {
		fmt.Fprintf(res, "%s %v\n", uri, err)
		return
	}

	pngImage := code.PNG()
	fmt.Fprintf(res, "%s", pngImage)
}
Beispiel #2
0
func main() {
	var strChan chan string
	if len(os.Args) < 2 {
		strChan = freadLines(os.Stdin)
	} else {
		strChan = linesThroughChan(os.Args[1:]...)
	}

	for url := range strChan {
		url = trimStripLine(url)
		code, err := qr.Encode(url, qr.Q)
		if err != nil {
			fmt.Fprintf(os.Stderr, "%s %v\n", url, err)
			continue
		}

		pngImage := code.PNG()

		base := path.Base(url)

		rawPath := fmt.Sprintf("%s.png", base)
		f, err := os.Create(rawPath)
		if err != nil {
			fmt.Fprintf(os.Stderr, "open %s %v\n", rawPath, err)
			continue
		}

		fmt.Fprintf(f, "%s\n", pngImage)
		f.Close()
	}
}
Beispiel #3
0
func presentQRCode(pl meddler.Payload, res http.ResponseWriter, req *http.Request) {
	if pl.PublicKey != envKeySet.PublicKey {
		http.Error(res, "invalid publickey", 405)
		return
	}

	rawTextForSigning := pl.RawTextForSigning()
	if !envKeySet.Match([]byte(rawTextForSigning), []byte(pl.Signature)) {
		http.Error(res, "invalid signature", 403)
		return
	}

	curTimeUnix := time.Now().Unix()
	if pl.ExpiryTime < curTimeUnix {
		http.Error(res, fmt.Sprintf("request expired at %q, current time %q", pl.ExpiryTime, curTimeUnix), 403)
		return
	}

	uri := pl.URI
	code, err := qr.Encode(uri, qr.Q)
	if err != nil {
		fmt.Fprintf(res, "%s %v\n", uri, err)
		return
	}

	pngImage := code.PNG()
	fmt.Fprintf(res, "%s", pngImage)
}