Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions config/config-sample.ini
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ port = 3306
username = ska-user
password = password
database = ska-db
; The below options allow TLS encrypted MySQL Database Sessions
; usetls options:
; 0: TLS is disabled
; 1: TLS is enabled
; tls_ca_cert: Location for the TLS public key for the MySQL server
usetls = 0
tls_ca_cert = "/etc/ssl/certs/ca-certificates.crt"

[ldap]
; Address to connect to LDAP server
Expand Down
9 changes: 8 additions & 1 deletion core.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@ function autoload_model($classname) {
function setup_database() {
global $config, $database, $driver, $pubkey_dir, $user_dir, $group_dir, $server_dir, $server_account_dir, $event_dir, $sync_request_dir;
try {
$database = new mysqli($config['database']['hostname'], $config['database']['username'], $config['database']['password'], $config['database']['database'], $config['database']['port']);
if ($config['database']['usetls']) {
$database = mysqli_init();
$database->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, true);
$database->ssl_set(NULL, NULL, $config['database']['tls_ca_cert'], NULL, NULL);
$database->real_connect($config['database']['hostname'], $config['database']['username'], $config['database']['password'], $config['database']['database'], $config['database']['port']);
} else {
$database = new mysqli($config['database']['hostname'], $config['database']['username'], $config['database']['password'], $config['database']['database'], $config['database']['port']);
}
} catch(ErrorException $e) {
throw new DBConnectionFailedException($e->getMessage());
}
Expand Down