Beispiel #1
0
func NewToken(publicKey string) Token {
	// Generate and encrypt token
	token := make([]byte, 64)
	rand.Read(token)
	b64Token := base64.StdEncoding.EncodeToString(token)

	client := pgp.PublicKeyToPGPClient(publicKey)

	b64EncToken := base64.StdEncoding.EncodeToString(client.Encrypt(token))

	return Token{b64Token, b64EncToken}
}
Beispiel #2
0
func handleRegister(req *restful.Request, res *restful.Response) {
	var regReq struct {
		PublicKey string
	}
	req.ReadEntity(&regReq)

	client := pgp.PublicKeyToPGPClient(regReq.PublicKey)
	fingerprint := base64.StdEncoding.EncodeToString(client.Fingerprint())
	log.WithFields(log.Fields{
		"fingerprint": fingerprint,
	}).Debug("Received Register request")

	challenge := pushToken(fingerprint, regReq.PublicKey)
	res.WriteHeaderAndEntity(http.StatusAccepted, challenge)
}