Skip to content

Commit 4ced115

Browse files
committed
address comment
Signed-off-by: lance6716 <[email protected]>
1 parent a58b468 commit 4ced115

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,15 @@ Default: false
158158
`allowCleartextPasswords=true` allows using the [cleartext client side plugin](https://dev.mysql.com/doc/en/cleartext-pluggable-authentication.html) if required by an account, such as one defined with the [PAM authentication plugin](http://dev.mysql.com/doc/en/pam-authentication-plugin.html). Sending passwords in clear text may be a security problem in some configurations. To avoid problems if there is any possibility that the password would be intercepted, clients should connect to MySQL Server using a method that protects the password. Possibilities include [TLS / SSL](#tls), IPsec, or a private network.
159159

160160

161-
##### `allowFallbackToNoTLS`
161+
##### `allowFallbackToPlaintext`
162162

163163
```
164164
Type: bool
165165
Valid Values: true, false
166166
Default: false
167167
```
168168

169-
`allowFallbackToNoTLS=true` acts like a `--ssl-mode=PREFERRED` MySQL client as described in [Command Options for Connecting to the Server](https://dev.mysql.com/doc/refman/5.7/en/connection-options.html#option_general_ssl-mode)
169+
`allowFallbackToPlaintext=true` acts like a `--ssl-mode=PREFERRED` MySQL client as described in [Command Options for Connecting to the Server](https://dev.mysql.com/doc/refman/5.7/en/connection-options.html#option_general_ssl-mode)
170170

171171
##### `allowNativePasswords`
172172

dsn.go

+17-17
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ type Config struct {
5151
ReadTimeout time.Duration // I/O read timeout
5252
WriteTimeout time.Duration // I/O write timeout
5353

54-
AllowAllFiles bool // Allow all files to be used with LOAD DATA LOCAL INFILE
55-
AllowCleartextPasswords bool // Allows the cleartext client side plugin
56-
AllowFallbackToNoTLS bool // Allows fallback to unencrypted connection if server does not support TLS
57-
AllowNativePasswords bool // Allows the native password authentication method
58-
AllowOldPasswords bool // Allows the old insecure password method
59-
CheckConnLiveness bool // Check connections for liveness before using them
60-
ClientFoundRows bool // Return number of matching rows instead of rows changed
61-
ColumnsWithAlias bool // Prepend table alias to column names
62-
InterpolateParams bool // Interpolate placeholders into query string
63-
MultiStatements bool // Allow multiple statements in one query
64-
ParseTime bool // Parse time values to time.Time
65-
RejectReadOnly bool // Reject read-only connections
54+
AllowAllFiles bool // Allow all files to be used with LOAD DATA LOCAL INFILE
55+
AllowCleartextPasswords bool // Allows the cleartext client side plugin
56+
AllowFallbackToPlaintext bool // Allows fallback to unencrypted connection if server does not support TLS
57+
AllowNativePasswords bool // Allows the native password authentication method
58+
AllowOldPasswords bool // Allows the old insecure password method
59+
CheckConnLiveness bool // Check connections for liveness before using them
60+
ClientFoundRows bool // Return number of matching rows instead of rows changed
61+
ColumnsWithAlias bool // Prepend table alias to column names
62+
InterpolateParams bool // Interpolate placeholders into query string
63+
MultiStatements bool // Allow multiple statements in one query
64+
ParseTime bool // Parse time values to time.Time
65+
RejectReadOnly bool // Reject read-only connections
6666
}
6767

6868
// NewConfig creates a new Config and sets default values.
@@ -130,7 +130,7 @@ func (cfg *Config) normalize() error {
130130
cfg.TLS = &tls.Config{InsecureSkipVerify: true}
131131
case "preferred":
132132
cfg.TLS = &tls.Config{InsecureSkipVerify: true}
133-
cfg.AllowFallbackToNoTLS = true
133+
cfg.AllowFallbackToPlaintext = true
134134
default:
135135
cfg.TLS = getTLSConfigClone(cfg.TLSConfig)
136136
if cfg.TLS == nil {
@@ -210,8 +210,8 @@ func (cfg *Config) FormatDSN() string {
210210
writeDSNParam(&buf, &hasParam, "allowCleartextPasswords", "true")
211211
}
212212

213-
if cfg.AllowFallbackToNoTLS {
214-
writeDSNParam(&buf, &hasParam, "allowFallbackToNoTLS", "true")
213+
if cfg.AllowFallbackToPlaintext {
214+
writeDSNParam(&buf, &hasParam, "allowFallbackToPlaintext", "true")
215215
}
216216

217217
if !cfg.AllowNativePasswords {
@@ -402,9 +402,9 @@ func parseDSNParams(cfg *Config, params string) (err error) {
402402
}
403403

404404
// Allow fallback to unencrypted connection if server does not support TLS
405-
case "allowFallbackToNoTLS":
405+
case "allowFallbackToPlaintext":
406406
var isBool bool
407-
cfg.AllowFallbackToNoTLS, isBool = readBool(value)
407+
cfg.AllowFallbackToPlaintext, isBool = readBool(value)
408408
if !isBool {
409409
return errors.New("invalid bool value: " + value)
410410
}

dsn_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ var testDSNs = []struct {
4242
"user:password@/dbname?loc=UTC&timeout=30s&readTimeout=1s&writeTimeout=1s&allowAllFiles=1&clientFoundRows=true&allowOldPasswords=TRUE&collation=utf8mb4_unicode_ci&maxAllowedPacket=16777216&tls=false&allowCleartextPasswords=true&parseTime=true&rejectReadOnly=true",
4343
&Config{User: "user", Passwd: "password", Net: "tcp", Addr: "127.0.0.1:3306", DBName: "dbname", Collation: "utf8mb4_unicode_ci", Loc: time.UTC, TLSConfig: "false", AllowCleartextPasswords: true, AllowNativePasswords: true, Timeout: 30 * time.Second, ReadTimeout: time.Second, WriteTimeout: time.Second, AllowAllFiles: true, AllowOldPasswords: true, CheckConnLiveness: true, ClientFoundRows: true, MaxAllowedPacket: 16777216, ParseTime: true, RejectReadOnly: true},
4444
}, {
45-
"user:password@/dbname?allowNativePasswords=false&checkConnLiveness=false&maxAllowedPacket=0&allowFallbackToNoTLS=true",
46-
&Config{User: "user", Passwd: "password", Net: "tcp", Addr: "127.0.0.1:3306", DBName: "dbname", Collation: "utf8mb4_general_ci", Loc: time.UTC, MaxAllowedPacket: 0, AllowFallbackToNoTLS: true, AllowNativePasswords: false, CheckConnLiveness: false},
45+
"user:password@/dbname?allowNativePasswords=false&checkConnLiveness=false&maxAllowedPacket=0&allowFallbackToPlaintext=true",
46+
&Config{User: "user", Passwd: "password", Net: "tcp", Addr: "127.0.0.1:3306", DBName: "dbname", Collation: "utf8mb4_general_ci", Loc: time.UTC, MaxAllowedPacket: 0, AllowFallbackToPlaintext: true, AllowNativePasswords: false, CheckConnLiveness: false},
4747
}, {
4848
"user:p@ss(word)@tcp([de:ad:be:ef::ca:fe]:80)/dbname?loc=Local",
4949
&Config{User: "user", Passwd: "p@ss(word)", Net: "tcp", Addr: "[de:ad:be:ef::ca:fe]:80", DBName: "dbname", Collation: "utf8mb4_general_ci", Loc: time.Local, MaxAllowedPacket: defaultMaxAllowedPacket, AllowNativePasswords: true, CheckConnLiveness: true},
@@ -100,6 +100,7 @@ func TestDSNParserInvalid(t *testing.T) {
100100
"User:pass@tcp(1.2.3.4:3306)", // no trailing slash
101101
"net()/", // unknown default addr
102102
"user:pass@tcp(127.0.0.1:3306)/db/name", // invalid dbname
103+
"user:password@/dbname?allowFallbackToPlaintext=PREFERRED", // wrong bool flag
103104
//"/dbname?arg=/some/unescaped/path",
104105
}
105106

packets.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func (mc *mysqlConn) readHandshakePacket() (data []byte, plugin string, err erro
223223
return nil, "", ErrOldProtocol
224224
}
225225
if mc.flags&clientSSL == 0 && mc.cfg.TLS != nil {
226-
if mc.cfg.AllowFallbackToNoTLS {
226+
if mc.cfg.AllowFallbackToPlaintext {
227227
mc.cfg.TLS = nil
228228
} else {
229229
return nil, "", ErrNoTLS

0 commit comments

Comments
 (0)