Пример #1
0
// KiSSAnonHandshake does an anonymous KiSS handshake over the given transport,
// validating the other end using the given verifier, which may be nil.
//
// Usually, clients use the anonymous handshake, while servers use the named handshake.
func KiSSAnonHandshake(check Verifier, transport io.ReadWriteCloser) (io.ReadWriteCloser, error) {
	eph_priv := natrium.ECDHGenerateKey()

	// send AHLO message
	tosend := kissAnonHello{eph_priv.PublicKey()}
	buf := new(bytes.Buffer)
	struc.Pack(buf, &tosend)
	packaged := kissSegment{0, kiss_AHLO, append(make([]byte, 0), buf.Bytes()...)}

	return kissFinishHandshake(eph_priv, packaged, check, transport)
}
Пример #2
0
// KiSSAnonHandshake does a named KiSS handshake over the given transport,
// validating the other end using the given verifier, which may be nil.
//
// Usually, clients use the anonymous handshake, while servers use the named handshake.
func KiSSNamedHandshake(identity natrium.EdDSAPrivate, check Verifier, transport io.ReadWriteCloser) (io.ReadWriteCloser, error) {
	eph_priv := natrium.ECDHGenerateKey()
	signat := identity.Sign(eph_priv.PublicKey())

	// send NHLO message
	tosend := kissNamedHello{eph_priv.PublicKey(), signat, identity.PublicKey()}
	buf := new(bytes.Buffer)
	err := struc.Pack(buf, &tosend)
	if err != nil {
		panic(err.Error())
	}
	packaged := kissSegment{0, kiss_NHLO, buf.Bytes()}

	return kissFinishHandshake(eph_priv, packaged, check, transport)
}