Skip to main content

Module tls

Module tls 

Source
Expand description

TLS/SSL support for MySQL connections.

This module implements the TLS handshake for MySQL connections using rustls.

§MySQL TLS Handshake Flow

  1. Server sends initial handshake with CLIENT_SSL capability
  2. If SSL is requested, client sends short SSL request packet:
    • 4 bytes: capability flags (with CLIENT_SSL)
    • 4 bytes: max packet size
    • 1 byte: character set
    • 23 bytes: reserved (zeros)
  3. Client performs TLS handshake
  4. Client sends full handshake response over TLS
  5. Server sends auth result over TLS

§Feature Flag

TLS support requires the tls feature to be enabled:

[dependencies]
sqlmodel-mysql = { version = "0.1", features = ["tls"] }

§Example

use sqlmodel_mysql::{MySqlConfig, SslMode, TlsConfig};

let config = MySqlConfig::new()
    .host("db.example.com")
    .ssl_mode(SslMode::VerifyCa)
    .tls_config(TlsConfig::new()
        .ca_cert("/etc/ssl/certs/ca.pem"));

// Connection will use TLS after initial handshake
let conn = MySqlConnection::connect(config)?;

Structs§

TlsStream
TLS connection wrapper when tls feature is disabled.

Functions§

build_ssl_request_packet
Build an SSL request packet.
server_supports_ssl
Check if the server supports SSL/TLS.
validate_ssl_mode
Validate SSL mode against server capabilities.
validate_tls_config
Validate TLS configuration for the given SSL mode.