Add VerifyPassword to API

It takes in an email and plain text password to verify. If it fails to find a password stored for email, it returns not_found. If it finds the password hash stored but that hash doesn't match the password passed via the API, it returns verified = false, else it returns verified = true.

Co-authored-by: Alban Seurat <alban.seurat@me.com>
This commit is contained in:
Tyler Cloke 2018-08-06 12:04:56 -07:00 committed by Alban Seurat
parent 92920c86ea
commit dd84e73c0e
6 changed files with 274 additions and 57 deletions

View file

@ -31,6 +31,8 @@ It has these top-level messages:
ListRefreshResp
RevokeRefreshReq
RevokeRefreshResp
VerifyPasswordReq
VerifyPasswordResp
*/
package api
@ -607,6 +609,54 @@ func (m *RevokeRefreshResp) GetNotFound() bool {
return false
}
type VerifyPasswordReq struct {
Email string `protobuf:"bytes,1,opt,name=email" json:"email,omitempty"`
Password string `protobuf:"bytes,2,opt,name=password" json:"password,omitempty"`
}
func (m *VerifyPasswordReq) Reset() { *m = VerifyPasswordReq{} }
func (m *VerifyPasswordReq) String() string { return proto.CompactTextString(m) }
func (*VerifyPasswordReq) ProtoMessage() {}
func (*VerifyPasswordReq) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{23} }
func (m *VerifyPasswordReq) GetEmail() string {
if m != nil {
return m.Email
}
return ""
}
func (m *VerifyPasswordReq) GetPassword() string {
if m != nil {
return m.Password
}
return ""
}
type VerifyPasswordResp struct {
Verified bool `protobuf:"varint,1,opt,name=verified" json:"verified,omitempty"`
NotFound bool `protobuf:"varint,2,opt,name=not_found,json=notFound" json:"not_found,omitempty"`
}
func (m *VerifyPasswordResp) Reset() { *m = VerifyPasswordResp{} }
func (m *VerifyPasswordResp) String() string { return proto.CompactTextString(m) }
func (*VerifyPasswordResp) ProtoMessage() {}
func (*VerifyPasswordResp) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{24} }
func (m *VerifyPasswordResp) GetVerified() bool {
if m != nil {
return m.Verified
}
return false
}
func (m *VerifyPasswordResp) GetNotFound() bool {
if m != nil {
return m.NotFound
}
return false
}
func init() {
proto.RegisterType((*Client)(nil), "api.Client")
proto.RegisterType((*CreateClientReq)(nil), "api.CreateClientReq")
@ -631,6 +681,8 @@ func init() {
proto.RegisterType((*ListRefreshResp)(nil), "api.ListRefreshResp")
proto.RegisterType((*RevokeRefreshReq)(nil), "api.RevokeRefreshReq")
proto.RegisterType((*RevokeRefreshResp)(nil), "api.RevokeRefreshResp")
proto.RegisterType((*VerifyPasswordReq)(nil), "api.VerifyPasswordReq")
proto.RegisterType((*VerifyPasswordResp)(nil), "api.VerifyPasswordResp")
}
// Reference imports to suppress errors if they are not otherwise used.
@ -666,6 +718,8 @@ type DexClient interface {
//
// Note that each user-client pair can have only one refresh token at a time.
RevokeRefresh(ctx context.Context, in *RevokeRefreshReq, opts ...grpc.CallOption) (*RevokeRefreshResp, error)
// VerifyPassword returns whether a password matches a hash for a specific email or not.
VerifyPassword(ctx context.Context, in *VerifyPasswordReq, opts ...grpc.CallOption) (*VerifyPasswordResp, error)
}
type dexClient struct {
@ -766,6 +820,15 @@ func (c *dexClient) RevokeRefresh(ctx context.Context, in *RevokeRefreshReq, opt
return out, nil
}
func (c *dexClient) VerifyPassword(ctx context.Context, in *VerifyPasswordReq, opts ...grpc.CallOption) (*VerifyPasswordResp, error) {
out := new(VerifyPasswordResp)
err := grpc.Invoke(ctx, "/api.Dex/VerifyPassword", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for Dex service
type DexServer interface {
@ -791,6 +854,8 @@ type DexServer interface {
//
// Note that each user-client pair can have only one refresh token at a time.
RevokeRefresh(context.Context, *RevokeRefreshReq) (*RevokeRefreshResp, error)
// VerifyPassword returns whether a password matches a hash for a specific email or not.
VerifyPassword(context.Context, *VerifyPasswordReq) (*VerifyPasswordResp, error)
}
func RegisterDexServer(s *grpc.Server, srv DexServer) {
@ -977,6 +1042,24 @@ func _Dex_RevokeRefresh_Handler(srv interface{}, ctx context.Context, dec func(i
return interceptor(ctx, in, info, handler)
}
func _Dex_VerifyPassword_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(VerifyPasswordReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(DexServer).VerifyPassword(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/api.Dex/VerifyPassword",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(DexServer).VerifyPassword(ctx, req.(*VerifyPasswordReq))
}
return interceptor(ctx, in, info, handler)
}
var _Dex_serviceDesc = grpc.ServiceDesc{
ServiceName: "api.Dex",
HandlerType: (*DexServer)(nil),
@ -1021,6 +1104,10 @@ var _Dex_serviceDesc = grpc.ServiceDesc{
MethodName: "RevokeRefresh",
Handler: _Dex_RevokeRefresh_Handler,
},
{
MethodName: "VerifyPassword",
Handler: _Dex_VerifyPassword_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "api/api.proto",
@ -1029,58 +1116,62 @@ var _Dex_serviceDesc = grpc.ServiceDesc{
func init() { proto.RegisterFile("api/api.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 848 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x56, 0xdb, 0x4e, 0xf3, 0x46,
0x10, 0x4e, 0x62, 0x92, 0x38, 0x93, 0xf3, 0x36, 0x3f, 0x84, 0xa0, 0x4a, 0xb0, 0xa8, 0x12, 0xa8,
0x52, 0x28, 0x54, 0x6a, 0xa5, 0xa2, 0xd2, 0x03, 0xb4, 0x05, 0xa9, 0xaa, 0x90, 0xd5, 0xf4, 0xb2,
0x96, 0x89, 0x07, 0x58, 0x61, 0x6c, 0x77, 0x77, 0x43, 0x68, 0x2f, 0xfb, 0x18, 0x7d, 0x9b, 0xbe,
0xd9, 0xaf, 0x5d, 0x6f, 0x82, 0x0f, 0x81, 0x70, 0xe7, 0xf9, 0x76, 0xe6, 0x9b, 0xf3, 0xc8, 0xd0,
0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0x38, 0x9e, 0x46, 0x1c, 0x23, 0x31, 0xf6, 0xf1, 0x59, 0x69, 0xde, 0xd4, 0xf4, 0x4f,
0xd1, 0x97, 0x1f, 0x03, 0x00, 0x00, 0xff, 0xff, 0xd1, 0x00, 0x08, 0xae, 0x25, 0x09, 0x00, 0x00,
// 905 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x56, 0xeb, 0x6e, 0xdb, 0x36,
0x14, 0xb6, 0xad, 0xd8, 0x96, 0x8f, 0xef, 0x9c, 0x9b, 0xba, 0x2e, 0x06, 0xa4, 0x2c, 0x06, 0xa4,
0x18, 0xe0, 0xac, 0x1d, 0xb0, 0x01, 0x2b, 0xd6, 0x5d, 0xd2, 0x6e, 0x2d, 0xb0, 0x0d, 0x85, 0x30,
0xe7, 0xe7, 0x04, 0xc5, 0x3a, 0x4e, 0x88, 0x28, 0x92, 0x46, 0xd2, 0x71, 0xb2, 0x47, 0xd9, 0xdb,
0xec, 0xd7, 0x5e, 0xab, 0x20, 0x45, 0x29, 0xba, 0x38, 0x71, 0xfe, 0xf9, 0x7c, 0xe2, 0xb9, 0x7d,
0x87, 0xe7, 0xa3, 0xa1, 0xef, 0xc5, 0xec, 0xc8, 0x8b, 0xd9, 0x3c, 0xe6, 0x91, 0x8c, 0x88, 0xe5,
0xc5, 0x8c, 0xfe, 0x57, 0x87, 0xd6, 0x71, 0xc0, 0x30, 0x94, 0x64, 0x00, 0x0d, 0xe6, 0x4f, 0xeb,
0x07, 0xf5, 0xc3, 0x8e, 0xd3, 0x60, 0x3e, 0xd9, 0x87, 0x96, 0xc0, 0x25, 0x47, 0x39, 0x6d, 0x68,
0xcc, 0x58, 0xe4, 0x39, 0xf4, 0x39, 0xfa, 0x8c, 0xe3, 0x52, 0xba, 0x6b, 0xce, 0xc4, 0xd4, 0x3a,
0xb0, 0x0e, 0x3b, 0x4e, 0x2f, 0x05, 0x17, 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00, 0x00, 0xff,
0xff, 0x49, 0x46, 0x0e, 0xa3, 0x00, 0x0a, 0x00, 0x00,
}

View file

@ -148,6 +148,16 @@ message RevokeRefreshResp {
bool not_found = 1;
}
message VerifyPasswordReq {
string email = 1;
string password = 2;
}
message VerifyPasswordResp {
bool verified = 1;
bool not_found = 2;
}
// Dex represents the dex gRPC service.
service Dex {
// CreateClient creates a client.
@ -172,4 +182,6 @@ service Dex {
//
// Note that each user-client pair can have only one refresh token at a time.
rpc RevokeRefresh(RevokeRefreshReq) returns (RevokeRefreshResp) {};
// VerifyPassword returns whether a password matches a hash for a specific email or not.
rpc VerifyPassword(VerifyPasswordReq) returns (VerifyPasswordResp) {};
}

View file

@ -48,7 +48,8 @@ Finally run the Dex client providing the CA certificate, client certificate and
Running the gRPC client will cause the following API calls to be made to the server
1. CreatePassword
2. ListPasswords
3. DeletePassword
3. VerifyPassword
4. DeletePassword
## Cleaning up

View file

@ -76,6 +76,39 @@ func createPassword(cli api.DexClient) error {
log.Printf("%+v", pass)
}
// Verifying correct and incorrect passwords
log.Print("Verifying Password:\n")
verifyReq := &api.VerifyPasswordReq{
Email: "test@example.com",
Password: "test1",
}
verifyResp, err := cli.VerifyPassword(context.TODO(), verifyReq)
if err != nil {
return fmt.Errorf("failed to run VerifyPassword for correct password: %v", err)
}
if !verifyResp.Verified {
return fmt.Errorf("failed to verify correct password: %v", verifyResp)
}
log.Printf("properly verified correct password: %t\n", verifyResp.Verified)
badVerifyReq := &api.VerifyPasswordReq{
Email: "test@example.com",
Password: "wrong_password",
}
badVerifyResp, err := cli.VerifyPassword(context.TODO(), badVerifyReq)
if err != nil {
return fmt.Errorf("failed to run VerifyPassword for incorrect password: %v", err)
}
if badVerifyResp.Verified {
return fmt.Errorf("verify returned true for incorrect password: %v", badVerifyResp)
}
log.Printf("properly failed to verify incorrect password: %t\n", badVerifyResp.Verified)
log.Print("Listing Passwords:\n")
for _, pass := range resp.Passwords {
log.Printf("%+v", pass)
}
deleteReq := &api.DeletePasswordReq{
Email: p.Email,
}

View file

@ -254,6 +254,37 @@ func (d dexAPI) ListPasswords(ctx context.Context, req *api.ListPasswordReq) (*a
}
func (d dexAPI) VerifyPassword(ctx context.Context, req *api.VerifyPasswordReq) (*api.VerifyPasswordResp, error) {
if req.Email == "" {
return nil, errors.New("no email supplied")
}
if req.Password == "" {
return nil, errors.New("no password to verify supplied")
}
password, err := d.s.GetPassword(req.Email)
if err != nil {
if err == storage.ErrNotFound {
return &api.VerifyPasswordResp{
NotFound: true,
}, nil
}
d.logger.Errorf("api: there was an error retrieving the password: %v", err)
return nil, fmt.Errorf("verify password: %v", err)
}
if err := bcrypt.CompareHashAndPassword(password.Hash, []byte(req.Password)); err != nil {
d.logger.Info("api: password check failed : %v", err)
return &api.VerifyPasswordResp{
Verified: false,
}, nil
}
return &api.VerifyPasswordResp{
Verified: true,
}, nil
}
func (d dexAPI) ListRefresh(ctx context.Context, req *api.ListRefreshReq) (*api.ListRefreshResp, error) {
id := new(internal.IDTokenSubject)
if err := internal.Unmarshal(req.UserId, id); err != nil {

View file

@ -69,8 +69,9 @@ func TestPassword(t *testing.T) {
defer client.Close()
ctx := context.Background()
email := "test@example.com"
p := api.Password{
Email: "test@example.com",
Email: email,
// bcrypt hash of the value "test1" with cost 10
Hash: []byte("$2a$10$XVMN/Fid.Ks4CXgzo8fpR.iU1khOMsP5g9xQeXuBm1wXjRX8pjUtO"),
Username: "test",
@ -93,8 +94,56 @@ func TestPassword(t *testing.T) {
t.Fatalf("Created password %s twice", createReq.Password.Email)
}
// Attempt to verify valid password and email
goodVerifyReq := &api.VerifyPasswordReq{
Email: email,
Password: "test1",
}
goodVerifyResp, err := client.VerifyPassword(ctx, goodVerifyReq)
if err != nil {
t.Fatalf("Unable to run verify password we expected to be valid for correct email: %v", err)
}
if !goodVerifyResp.Verified {
t.Fatalf("verify password failed for password expected to be valid for correct email. expected %t, found %t", true, goodVerifyResp.Verified)
}
if goodVerifyResp.NotFound {
t.Fatalf("verify password failed to return not found response. expected %t, found %t", false, goodVerifyResp.NotFound)
}
// Check not found response for valid password with wrong email
badEmailVerifyReq := &api.VerifyPasswordReq{
Email: "somewrongaddress@email.com",
Password: "test1",
}
badEmailVerifyResp, err := client.VerifyPassword(ctx, badEmailVerifyReq)
if err != nil {
t.Fatalf("Unable to run verify password for incorrect email: %v", err)
}
if badEmailVerifyResp.Verified {
t.Fatalf("verify password passed for password expected to be not found. expected %t, found %t", false, badEmailVerifyResp.Verified)
}
if !badEmailVerifyResp.NotFound {
t.Fatalf("expected not found response for verify password with bad email. expected %t, found %t", true, badEmailVerifyResp.NotFound)
}
// Check that wrong password fails
badPassVerifyReq := &api.VerifyPasswordReq{
Email: email,
Password: "wrong_password",
}
badPassVerifyResp, err := client.VerifyPassword(ctx, badPassVerifyReq)
if err != nil {
t.Fatalf("Unable to run verify password for password we expected to be invalid: %v", err)
}
if badPassVerifyResp.Verified {
t.Fatalf("verify password passed for password we expected to fail. expected %t, found %t", false, badPassVerifyResp.Verified)
}
if badPassVerifyResp.NotFound {
t.Fatalf("did not expect expected not found response for verify password with bad email. expected %t, found %t", false, badPassVerifyResp.NotFound)
}
updateReq := api.UpdatePasswordReq{
Email: "test@example.com",
Email: email,
NewUsername: "test1",
}