Browse Source

enable basic TLS for mysql connection without server CA cert validation

pull/2501/head
Thorsten 9 years ago
parent
commit
bcf8b733b1
  1. 8
      models/models.go

8
models/models.go

@ -123,12 +123,16 @@ func getEngine() (*xorm.Engine, error) {
cnnstr := "" cnnstr := ""
switch DbCfg.Type { switch DbCfg.Type {
case "mysql": case "mysql":
tls := ""
if DbCfg.SSLMode == "skip-verify" {
tls = "&tls=skip-verify";
}
if DbCfg.Host[0] == '/' { // looks like a unix socket if DbCfg.Host[0] == '/' { // looks like a unix socket
cnnstr = fmt.Sprintf("%s:%s@unix(%s)/%s?charset=utf8&parseTime=true", cnnstr = fmt.Sprintf("%s:%s@unix(%s)/%s?charset=utf8&parseTime=true",
DbCfg.User, DbCfg.Passwd, DbCfg.Host, DbCfg.Name) DbCfg.User, DbCfg.Passwd, DbCfg.Host, DbCfg.Name)
} else { } else {
cnnstr = fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8&parseTime=true", cnnstr = fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8&parseTime=true%s",
DbCfg.User, DbCfg.Passwd, DbCfg.Host, DbCfg.Name) DbCfg.User, DbCfg.Passwd, DbCfg.Host, DbCfg.Name, tls)
} }
case "postgres": case "postgres":
var host, port = "127.0.0.1", "5432" var host, port = "127.0.0.1", "5432"

Loading…
Cancel
Save