Beispiel #1
0
func ReadAToken(debug utils.Debug, iv []byte, key []byte, ibuff utils.IEncoding) (tok AToken, err error) {
	err = nil

	debug.Printf("Reading A's token")
	ciphertext, err := ibuff.ReadBinary()
	if err != nil {
		return
	}
	debug.PrintBuffer(ciphertext, "Token Ciphertext = ")

	t, err := utils.Decrypt(AMP, iv, key[0:], ciphertext)
	if err != nil {
		return
	}
	debug.PrintBuffer(t, "Token Plaintext = ")

	sbuff := utils.MakeByteIEncoding(t)

	debug.Printf("Reading nonce N")
	nonce, err := sbuff.ReadBinary()
	if err != nil {
		return
	}
	debug.PrintBuffer(nonce, "Nonce N = ")
	tok.Nonce = nonce[0:]

	debug.Printf("Reading B")
	b, err := sbuff.ReadString()
	if err != nil {
		return
	}
	debug.Printf("B = %v", b)
	tok.B = b

	debug.Printf("Reading session key")
	skey, err := sbuff.ReadBinary()
	if err != nil {
		return
	}
	debug.PrintBuffer(skey, "Session Key = ")
	tok.Key = skey[0:]

	debug.Printf("Reading ciphertext of B's token")
	ct, err := sbuff.ReadBinary()
	if err != nil {
		return
	}
	debug.PrintBuffer(ct, "Ciphertext of B's token = ")
	tok.CipherText = ct[0:]
	return
}
Beispiel #2
0
func ReadUserToken(debug utils.Debug, user string, iv []byte, key []byte, ibuff utils.IEncoding) (tok UserToken, err error) {
	err = nil

	debug.Printf("Reading %s's token", user)
	ciphertext, err := ibuff.ReadBinary()
	if err != nil {
		return
	}
	debug.PrintBuffer(ciphertext, "Token Ciphertext = ")

	t, err := utils.Decrypt(AMP, iv, key[0:], ciphertext)
	if err != nil {
		return
	}
	debug.PrintBuffer(t, "Token Plaintext = ")

	sbuff := utils.MakeByteIEncoding(t)

	debug.Printf("Reading nonce N%s", user)
	usernonce, err := sbuff.ReadBinary()
	if err != nil {
		return
	}
	debug.PrintBuffer(usernonce, "Nonce = ")
	tok.UserNonce = usernonce[0:]

	debug.Printf("Reading nonce N")
	nonce, err := sbuff.ReadBinary()
	if err != nil {
		return
	}
	debug.PrintBuffer(nonce, "Nonce N = ")
	tok.Nonce = nonce[0:]

	debug.Printf("Reading A")
	a, err := sbuff.ReadString()
	if err != nil {
		return
	}
	debug.Printf("A = %v", a)
	tok.A = a

	debug.Printf("Reading B")
	b, err := sbuff.ReadString()
	if err != nil {
		return
	}
	debug.Printf("B = %v", b)
	tok.B = b
	return
}
Beispiel #3
0
func ReadBToken(debug utils.Debug, iv []byte, key []byte, ibuff utils.IEncoding) (tok BToken, err error) {
	err = nil

	debug.Printf("Reading B's token")
	ciphertext, err := ibuff.ReadBinary()
	if err != nil {
		return
	}
	debug.PrintBuffer(ciphertext, "Token Ciphertext = ")

	t, err := utils.Decrypt(AMP, iv, key[0:], ciphertext)
	if err != nil {
		return
	}
	debug.PrintBuffer(t, "Token Plaintext = ")

	sbuff := utils.MakeByteIEncoding(t)

	debug.Printf("Reading session key")
	skey, err := sbuff.ReadBinary()
	if err != nil {
		return
	}
	debug.PrintBuffer(skey, "Session Key = ")
	tok.Key = skey[0:]

	debug.Printf("Reading A")
	a, err := sbuff.ReadString()
	if err != nil {
		return
	}
	debug.Printf("A = %v", a)
	tok.A = a

	return
}
Beispiel #4
0
func ReadKeyToken(debug utils.Debug, user string, iv []byte, key []byte, ibuff utils.IEncoding) (tok KeyToken, err error) {
	err = nil

	debug.Printf("Reading %s's key token", user)
	ciphertext, err := ibuff.ReadBinary()
	if err != nil {
		return
	}
	debug.PrintBuffer(ciphertext, "Key Token Ciphertext = ")

	t, err := utils.Decrypt(AMP, iv, key[0:], ciphertext)
	if err != nil {
		return
	}
	debug.PrintBuffer(t, "Key Token Plaintext = ")

	sbuff := utils.MakeByteIEncoding(t)

	debug.Printf("Reading nonce N%s", user)
	usernonce, err := sbuff.ReadBinary()
	if err != nil {
		return
	}
	debug.PrintBuffer(usernonce, "Nonce = ")
	tok.UserNonce = usernonce[0:]

	debug.Printf("Reading session key")
	skey, err := sbuff.ReadBinary()
	if err != nil {
		return
	}
	debug.PrintBuffer(skey, "Session Key = ")
	tok.Key = skey[0:]

	return
}