Repository navigation
Expand file tree
/
Copy pathauth_context.go
More file actions
67 lines (58 loc) · 2.31 KB
/
Copy pathauth_context.go
File metadata and controls
67 lines (58 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
//
// Copyright 2026 The Go-MySQL-Driver Authors. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.
package mysql
import (
"crypto/rsa"
"math/big"
)
// AuthContext contains the credentials and transport information for the current
// authentication exchange. The driver creates a new snapshot whenever it starts
// a plugin and does not change it during that exchange. Plugins must not modify it.
type AuthContext struct {
user string
password string
tls bool
unixSocket bool
serverPublicKey *rsa.PublicKey
}
// newAuthContext snapshots the selected password and established transport.
// tlsEstablished describes the completed MySQL TLS handshake, not cfg.TLS.
func newAuthContext(cfg *Config, password string, tlsEstablished bool) *AuthContext {
auth := &AuthContext{
user: cfg.User,
password: password,
tls: tlsEstablished,
unixSocket: cfg.Net == "unix",
serverPublicKey: cfg.pubKey,
}
auth.serverPublicKey = auth.ServerPublicKey()
return auth
}
// User returns the username supplied for the connection.
func (a *AuthContext) User() string { return a.user }
// Password returns the password selected for this authentication exchange.
func (a *AuthContext) Password() string { return a.password }
// TLS reports whether the driver has completed the MySQL TLS handshake.
// It does not indicate whether the server's certificate was verified, nor does
// it describe encryption provided by a custom dialer or an external tunnel.
func (a *AuthContext) TLS() bool { return a.tls }
// UnixSocket reports whether the connection uses the configured unix network.
func (a *AuthContext) UnixSocket() bool { return a.unixSocket }
// ServerPublicKey returns a copy of the configured server RSA public key,
// or nil if none was configured. Modifying the copy does not affect the driver
// or subsequent calls to ServerPublicKey.
func (a *AuthContext) ServerPublicKey() *rsa.PublicKey {
if a.serverPublicKey == nil {
return nil
}
key := *a.serverPublicKey
if key.N != nil {
key.N = new(big.Int).Set(key.N)
}
return &key
}