Skip to content

Commit 843d10a

Browse files
authored
Merge pull request #443 from dolthub/fulghum/mutual_tls
Updating auth interfaces to pass connection
2 parents b08b393 + 7fc324e commit 843d10a

File tree

4 files changed

+14
-17
lines changed

4 files changed

+14
-17
lines changed

go/mysql/auth_server.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"crypto/sha1"
2525
"crypto/sha256"
2626
"crypto/subtle"
27-
"crypto/x509"
2827
"encoding/hex"
2928
"net"
3029
"strings"
@@ -132,7 +131,7 @@ const (
132131
// such a hash based on the salt and auth response provided here after retrieving
133132
// the hashed password from the storage.
134133
type HashStorage interface {
135-
UserEntryWithHash(userCerts []*x509.Certificate, salt []byte, user string, authResponse []byte, remoteAddr net.Addr) (Getter, error)
134+
UserEntryWithHash(conn *Conn, salt []byte, user string, authResponse []byte, remoteAddr net.Addr) (Getter, error)
136135
}
137136

138137
// PlainTextStorage describes an object that is suitable to retrieve user information
@@ -146,7 +145,7 @@ type HashStorage interface {
146145
// When comparing plain text passwords directly, please ensure to use `subtle.ConstantTimeCompare`
147146
// to prevent timing based attacks on the password.
148147
type PlainTextStorage interface {
149-
UserEntryWithPassword(userCerts []*x509.Certificate, user string, password string, remoteAddr net.Addr) (Getter, error)
148+
UserEntryWithPassword(conn *Conn, user string, password string, remoteAddr net.Addr) (Getter, error)
150149
}
151150

152151
// CachingStorage describes an object that is suitable to retrieve user information
@@ -159,7 +158,7 @@ type PlainTextStorage interface {
159158
// such a hash based on the salt and auth response provided here after retrieving
160159
// the hashed password from the cache.
161160
type CachingStorage interface {
162-
UserEntryWithCacheHash(userCerts []*x509.Certificate, salt []byte, user string, authResponse []byte, remoteAddr net.Addr) (Getter, CacheState, error)
161+
UserEntryWithCacheHash(conn *Conn, salt []byte, user string, authResponse []byte, remoteAddr net.Addr) (Getter, CacheState, error)
163162
}
164163

165164
// NewMysqlNativeAuthMethod will create a new AuthMethod that implements the
@@ -507,7 +506,7 @@ func (n *mysqlNativePasswordAuthMethod) HandleAuthPluginData(conn *Conn, user st
507506
return nil, NewSQLError(ERAccessDeniedError, SSAccessDeniedError, "Access denied for user '%v'", user)
508507
}
509508
salt := serverAuthPluginData[:len(serverAuthPluginData)-1]
510-
return n.storage.UserEntryWithHash(conn.GetTLSClientCerts(), salt, user, clientAuthPluginData, remoteAddr)
509+
return n.storage.UserEntryWithHash(conn, salt, user, clientAuthPluginData, remoteAddr)
511510
}
512511

513512
type mysqlClearAuthMethod struct {
@@ -532,7 +531,7 @@ func (n *mysqlClearAuthMethod) HandleAuthPluginData(conn *Conn, user string, ser
532531
if len(clientAuthPluginData) > 0 {
533532
password = string(clientAuthPluginData[:len(clientAuthPluginData)-1])
534533
}
535-
return n.storage.UserEntryWithPassword(conn.GetTLSClientCerts(), user, password, remoteAddr)
534+
return n.storage.UserEntryWithPassword(conn, user, password, remoteAddr)
536535
}
537536

538537
type mysqlDialogAuthMethod struct {
@@ -557,7 +556,7 @@ func (n *mysqlDialogAuthMethod) AuthPluginData() ([]byte, error) {
557556
return result, nil
558557
}
559558
func (n *mysqlDialogAuthMethod) HandleAuthPluginData(conn *Conn, user string, serverAuthPluginData []byte, clientAuthPluginData []byte, remoteAddr net.Addr) (Getter, error) {
560-
return n.storage.UserEntryWithPassword(conn.GetTLSClientCerts(), user, string(clientAuthPluginData[:len(clientAuthPluginData)-1]), remoteAddr)
559+
return n.storage.UserEntryWithPassword(conn, user, string(clientAuthPluginData[:len(clientAuthPluginData)-1]), remoteAddr)
561560
}
562561

563562
type mysqlCachingSha2AuthMethod struct {
@@ -594,7 +593,7 @@ func (n *mysqlCachingSha2AuthMethod) HandleAuthPluginData(c *Conn, user string,
594593
return nil, NewSQLError(ERAccessDeniedError, SSAccessDeniedError, "Access denied for user '%v'", user)
595594
}
596595
salt := serverAuthPluginData[:len(serverAuthPluginData)-1]
597-
result, cacheState, err := n.cache.UserEntryWithCacheHash(c.GetTLSClientCerts(), salt, user, clientAuthPluginData, remoteAddr)
596+
result, cacheState, err := n.cache.UserEntryWithCacheHash(c, salt, user, clientAuthPluginData, remoteAddr)
598597
if err != nil {
599598
return nil, err
600599
}
@@ -638,7 +637,7 @@ func (n *mysqlCachingSha2AuthMethod) HandleAuthPluginData(c *Conn, user string,
638637
if err != nil {
639638
return nil, err
640639
}
641-
return n.storage.UserEntryWithPassword(c.GetTLSClientCerts(), user, password, remoteAddr)
640+
return n.storage.UserEntryWithPassword(c, user, password, remoteAddr)
642641
}
643642

644643
// ScrambleMysqlNativePassword computes the hash of the password using 4.1+ method.

go/mysql/auth_server_clientcert.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package mysql
1818

1919
import (
20-
"crypto/x509"
2120
"flag"
2221
"fmt"
2322
"net"
@@ -83,7 +82,8 @@ func (asl *AuthServerClientCert) HandleUser(user string, remoteAddr net.Addr) bo
8382
}
8483

8584
// UserEntryWithPassword is part of the PlaintextStorage interface
86-
func (asl *AuthServerClientCert) UserEntryWithPassword(userCerts []*x509.Certificate, user string, password string, remoteAddr net.Addr) (Getter, error) {
85+
func (asl *AuthServerClientCert) UserEntryWithPassword(conn *Conn, user string, password string, remoteAddr net.Addr) (Getter, error) {
86+
userCerts := conn.GetTLSClientCerts()
8787
if len(userCerts) == 0 {
8888
return nil, fmt.Errorf("no client certs for connection")
8989
}

go/mysql/auth_server_none.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package mysql
1818

1919
import (
20-
"crypto/x509"
2120
"net"
2221

2322
querypb "github.com/dolthub/vitess/go/vt/proto/query"
@@ -51,7 +50,7 @@ func (a *AuthServerNone) HandleUser(user string, remoteAddr net.Addr) bool {
5150

5251
// UserEntryWithHash validates the user if it exists and returns the information.
5352
// Always accepts any user.
54-
func (a *AuthServerNone) UserEntryWithHash(userCerts []*x509.Certificate, salt []byte, user string, authResponse []byte, remoteAddr net.Addr) (Getter, error) {
53+
func (a *AuthServerNone) UserEntryWithHash(conn *Conn, salt []byte, user string, authResponse []byte, remoteAddr net.Addr) (Getter, error) {
5554
return &NoneGetter{}, nil
5655
}
5756

go/mysql/auth_server_static.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package mysql
1919
import (
2020
"bytes"
2121
"crypto/subtle"
22-
"crypto/x509"
2322
"encoding/json"
2423
"flag"
2524
"net"
@@ -165,7 +164,7 @@ func (a *AuthServerStatic) HandleUser(user string, remoteAddr net.Addr) bool {
165164

166165
// UserEntryWithPassword implements password lookup based on a plain
167166
// text password that is negotiated with the client.
168-
func (a *AuthServerStatic) UserEntryWithPassword(userCerts []*x509.Certificate, user string, password string, remoteAddr net.Addr) (Getter, error) {
167+
func (a *AuthServerStatic) UserEntryWithPassword(conn *Conn, user string, password string, remoteAddr net.Addr) (Getter, error) {
169168
a.mu.Lock()
170169
entries, ok := a.entries[user]
171170
a.mu.Unlock()
@@ -183,7 +182,7 @@ func (a *AuthServerStatic) UserEntryWithPassword(userCerts []*x509.Certificate,
183182

184183
// UserEntryWithHash implements password lookup based on a
185184
// mysql_native_password hash that is negotiated with the client.
186-
func (a *AuthServerStatic) UserEntryWithHash(userCerts []*x509.Certificate, salt []byte, user string, authResponse []byte, remoteAddr net.Addr) (Getter, error) {
185+
func (a *AuthServerStatic) UserEntryWithHash(conn *Conn, salt []byte, user string, authResponse []byte, remoteAddr net.Addr) (Getter, error) {
187186
a.mu.Lock()
188187
entries, ok := a.entries[user]
189188
a.mu.Unlock()
@@ -213,7 +212,7 @@ func (a *AuthServerStatic) UserEntryWithHash(userCerts []*x509.Certificate, salt
213212

214213
// UserEntryWithCacheHash implements password lookup based on a
215214
// caching_sha2_password hash that is negotiated with the client.
216-
func (a *AuthServerStatic) UserEntryWithCacheHash(userCerts []*x509.Certificate, salt []byte, user string, authResponse []byte, remoteAddr net.Addr) (Getter, CacheState, error) {
215+
func (a *AuthServerStatic) UserEntryWithCacheHash(conn *Conn, salt []byte, user string, authResponse []byte, remoteAddr net.Addr) (Getter, CacheState, error) {
217216
a.mu.Lock()
218217
entries, ok := a.entries[user]
219218
a.mu.Unlock()

0 commit comments

Comments
 (0)