예제 #1
0
// NewSetupClientSession returns a new setup client session
func NewSetupClientSession(username string, pin string) *SetupClientSession {
	rp, _ := srp.NewSRP(SRPGroup, sha512.New, KeyDerivativeFuncRFC2945(sha512.New, []byte(username)))

	client := rp.NewClientSession([]byte(username), []byte(pin))
	hap := SetupClientSession{
		session: client,
	}

	return &hap
}
예제 #2
0
// NewSetupServerSession return a new setup server session.
func NewSetupServerSession(username, pin string) (*SetupServerSession, error) {
	var err error
	pairName := []byte("Pair-Setup")
	srp, err := srp.NewSRP(SRPGroup, sha512.New, KeyDerivativeFuncRFC2945(sha512.New, []byte(pairName)))

	if err == nil {
		srp.SaltLength = 16
		salt, v, err := srp.ComputeVerifier([]byte(pin))
		if err == nil {
			session := srp.NewServerSession([]byte(pairName), salt, v)
			pairing := SetupServerSession{
				session:   session,
				Salt:      salt,
				PublicKey: session.GetB(),
				Username:  []byte(username),
			}
			return &pairing, nil
		}
	}

	return nil, err
}