Added signature to auth response
parent
84af718071
commit
6d0925f20f
18
gql.go
18
gql.go
|
|
@ -62,6 +62,7 @@ func NewAuthReqJSON(curve ecdh.Curve, id *ecdsa.PrivateKey) (AuthReqJSON, *ecdh.
|
||||||
type AuthRespJSON struct {
|
type AuthRespJSON struct {
|
||||||
Granted time.Time `json:"granted"`
|
Granted time.Time `json:"granted"`
|
||||||
ECDHPubkey []byte `json:"echd_server"`
|
ECDHPubkey []byte `json:"echd_server"`
|
||||||
|
Signature []byte `json:"signature"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAuthRespJSON(thread *GQLThread, req AuthReqJSON) (AuthRespJSON, []byte, error) {
|
func NewAuthRespJSON(thread *GQLThread, req AuthReqJSON) (AuthRespJSON, []byte, error) {
|
||||||
|
|
@ -110,14 +111,27 @@ func NewAuthRespJSON(thread *GQLThread, req AuthReqJSON) (AuthRespJSON, []byte,
|
||||||
return AuthRespJSON{}, nil, err
|
return AuthRespJSON{}, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ec_key_pub := ec_key.PublicKey().Bytes()
|
||||||
|
|
||||||
|
granted := time.Now()
|
||||||
|
time_ser, _ := granted.MarshalJSON()
|
||||||
|
resp_sig_data := append(ec_key_pub, time_ser...)
|
||||||
|
resp_sig_hash := sha512.Sum512(resp_sig_data)
|
||||||
|
|
||||||
|
resp_sig, err := ecdsa.SignASN1(rand.Reader, thread.Key, resp_sig_hash[:])
|
||||||
|
if err != nil {
|
||||||
|
return AuthRespJSON{}, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
shared_secret, err := ec_key.ECDH(remote)
|
shared_secret, err := ec_key.ECDH(remote)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return AuthRespJSON{}, nil, err
|
return AuthRespJSON{}, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return AuthRespJSON{
|
return AuthRespJSON{
|
||||||
Granted: time.Now(),
|
Granted: granted,
|
||||||
ECDHPubkey: ec_key.PublicKey().Bytes(),
|
ECDHPubkey: ec_key_pub,
|
||||||
|
Signature: resp_sig,
|
||||||
}, shared_secret, nil
|
}, shared_secret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue