2019-11-18 16:28:18 +00:00
|
|
|
package pogs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"zombiezen.com/go/capnproto2/pogs"
|
|
|
|
"zombiezen.com/go/capnproto2/server"
|
2021-03-23 14:30:43 +00:00
|
|
|
|
2024-05-14 04:22:06 +00:00
|
|
|
"github.com/cloudflare/cloudflared/tunnelrpc/proto"
|
2019-11-18 16:28:18 +00:00
|
|
|
)
|
|
|
|
|
2024-05-14 04:22:06 +00:00
|
|
|
func (i TunnelServer_PogsImpl) Authenticate(p proto.TunnelServer_authenticate) error {
|
2019-11-18 16:28:18 +00:00
|
|
|
originCert, err := p.Params.OriginCert()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
hostname, err := p.Params.Hostname()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
options, err := p.Params.Options()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
pogsOptions, err := UnmarshalRegistrationOptions(options)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
server.Ack(p.Options)
|
|
|
|
resp, err := i.impl.Authenticate(p.Ctx, originCert, hostname, pogsOptions)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
result, err := p.Results.NewResult()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return MarshalAuthenticateResponse(result, resp)
|
|
|
|
}
|
|
|
|
|
2024-05-14 04:22:06 +00:00
|
|
|
func MarshalAuthenticateResponse(s proto.AuthenticateResponse, p *AuthenticateResponse) error {
|
|
|
|
return pogs.Insert(proto.AuthenticateResponse_TypeID, s.Struct, p)
|
2019-11-18 16:28:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c TunnelServer_PogsClient) Authenticate(ctx context.Context, originCert []byte, hostname string, options *RegistrationOptions) (*AuthenticateResponse, error) {
|
2024-05-14 04:22:06 +00:00
|
|
|
client := proto.TunnelServer{Client: c.Client}
|
|
|
|
promise := client.Authenticate(ctx, func(p proto.TunnelServer_authenticate_Params) error {
|
2019-11-18 16:28:18 +00:00
|
|
|
err := p.SetOriginCert(originCert)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = p.SetHostname(hostname)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
registrationOptions, err := p.NewOptions()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = MarshalRegistrationOptions(registrationOptions, options)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
retval, err := promise.Result().Struct()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return UnmarshalAuthenticateResponse(retval)
|
|
|
|
}
|
|
|
|
|
2024-05-14 04:22:06 +00:00
|
|
|
func UnmarshalAuthenticateResponse(s proto.AuthenticateResponse) (*AuthenticateResponse, error) {
|
2019-11-18 16:28:18 +00:00
|
|
|
p := new(AuthenticateResponse)
|
2024-05-14 04:22:06 +00:00
|
|
|
err := pogs.Extract(p, proto.AuthenticateResponse_TypeID, s.Struct)
|
2019-11-18 16:28:18 +00:00
|
|
|
return p, err
|
|
|
|
}
|