Skip to content

Commit

Permalink
Minor fixes to MySQL SSL support
Browse files Browse the repository at this point in the history
  • Loading branch information
GreaterFire committed Mar 22, 2020
1 parent fadbfba commit 0b92c6c
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 15 deletions.
5 changes: 2 additions & 3 deletions docs/authenticator.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Authenticator

Trojan servers can authenticate users according to not only passwords in the config file but also entries in a MySQL (MariaDB) database. To turn this functionality on, set `enabled` field in the MySQL config to `true` and correctly configure the server address, credentials, and etc. If you would like to connect to the database securely, you can to fill the `cafile` and/or the `tls_version` field (refer to [MySQL Documentation](https://dev.mysql.com/doc/refman/8.0/en/encrypted-connection-protocols-ciphers.html)):
Trojan servers can authenticate users according to not only passwords in the config file but also entries in a MySQL (MariaDB) database. To turn this functionality on, set `enabled` field in the MySQL config to `true` and correctly configure the server address, credentials, and etc. If you would like to connect to the database securely, you can to fill the `cafile` field indicating the CA file:

```json
"mysql": {
Expand All @@ -10,8 +10,7 @@ Trojan servers can authenticate users according to not only passwords in the con
"database": "trojan",
"username": "trojan",
"password": "",
"cafile": "",
"tls_version": ""
"cafile": ""
}
```

Expand Down
3 changes: 1 addition & 2 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ The NAT config is for transparent proxy. You'll need to [setup iptables rules](h
"database": "trojan",
"username": "trojan",
"password": "",
"cafile": "",
"tls_version": ""
"cafile": ""
}
}
```
Expand Down
5 changes: 2 additions & 3 deletions examples/server.json-example
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
"server_port": 3306,
"database": "trojan",
"username": "trojan",
"password": "",
"cafile": "",
"tls_version": ""
"password": "",
"cafile": ""
}
}
5 changes: 1 addition & 4 deletions src/core/authenticator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ Authenticator::Authenticator(const Config &config) {
mysql_init(&con);
Log::log_with_date_time("connecting to MySQL server " + config.mysql.server_addr + ':' + to_string(config.mysql.server_port), Log::INFO);
if (config.mysql.cafile != "") {
mysql_options(&con, MYSQL_OPT_SSL_CA, config.mysql.cafile.c_str());
}
if (config.mysql.tls_version != "") {
mysql_optionsv(&con, MARIADB_OPT_TLS_VERSION, config.mysql.tls_version.c_str());
mysql_ssl_set(&con, NULL, NULL, config.mysql.cafile.c_str(), NULL, NULL);
}
if (mysql_real_connect(&con, config.mysql.server_addr.c_str(),
config.mysql.username.c_str(),
Expand Down
1 change: 0 additions & 1 deletion src/core/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ void Config::populate(const ptree &tree) {
mysql.username = tree.get("mysql.username", string("trojan"));
mysql.password = tree.get("mysql.password", string());
mysql.cafile = tree.get("mysql.cafile", string());
mysql.tls_version = tree.get("mysql.tls_version", string());
}

bool Config::sip003() {
Expand Down
1 change: 0 additions & 1 deletion src/core/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ class Config {
std::string username;
std::string password;
std::string cafile;
std::string tls_version;
} mysql;
void load(const std::string &filename);
void populate(const std::string &JSON);
Expand Down
3 changes: 2 additions & 1 deletion tests/LinuxSmokeTest/server.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"server_port": 0,
"database": "",
"username": "",
"password": ""
"password": "",
"cafile": ""
}
}

0 comments on commit 0b92c6c

Please sign in to comment.