Skip to content

Mysql connector j override flags #66

@lanklaas

Description

@lanklaas

Hello,

Looking at this open PR related to the jdbc issue and maybe the basic auth PR as well, it seems like people might just be happy changing the flags in client code. Would you accept something like below (happy to send a PR) just so that users can override the flags to get past the jdbc connection issues?

// Additional method on the `MysqlShim` trait with a default impl in this crate
fn write_flags<Writer: Write>(&self, rw: &mut Writer) -> Result<(), io::Error> {
    rw.write_all(&[10])?; // protocol 10

    // 5.1.10 because that's what Ruby's ActiveRecord requires
    rw.write_all(&b"5.1.10-alpha-msql-proxy\0"[..])?;

    rw.write_all(&[0x08, 0x00, 0x00, 0x00])?; // TODO: connection ID
    rw.write_all(&b";X,po_k}\0"[..])?; // auth seed
    let capabilities = &mut [0x00, 0x42]; // 4.1 proto
    #[cfg(feature = "tls")]
    if self.tls_config().is_some() {
        capabilities[1] |= 0x08; // SSL support flag
    }
    rw.write_all(capabilities)?;
    rw.write_all(&[0x21])?; // UTF8_GENERAL_CI
    rw.write_all(&[0x00, 0x00])?; // status flags
    rw.write_all(&[0x00, 0x00])?; // extended capabilities
    rw.write_all(&[0x00])?; // no plugins
    rw.write_all(&[0x00; 6][..])?; // filler
    rw.write_all(&[0x00; 4][..])?; // filler
    rw.write_all(&b">o6^Wz!/kM}N\0"[..])?; // 4.1+ servers must extend salt
    rw.flush()
}

Then on the client side you could do (Taken from the PR):

fn write_flags<Writer: OtherWrite>(&self, rw: &mut Writer) -> Result<(), std::io::Error> {
        rw.write_all(&[10])?; // protocol 10
        let mut capabilities = CapabilityFlags::empty();
        capabilities.insert(CapabilityFlags::CLIENT_PROTOCOL_41);
        capabilities.insert(CapabilityFlags::CLIENT_RESERVED);
        capabilities.insert(CapabilityFlags::CLIENT_SECURE_CONNECTION);
        capabilities.insert(CapabilityFlags::CLIENT_PLUGIN_AUTH);
        let mut capabilities_bytes = capabilities.bits().to_le_bytes();
        // 5.1.10 because that's what Ruby's ActiveRecord requires
        rw.write_all(&b"5.1.10-alpha-msql-proxy\0"[..])?;

        rw.write_all(&[0x08, 0x00, 0x00, 0x00])?; // TODO: connection ID
        rw.write_all(&b";X,po_k}\0"[..])?; // auth seed
        let capabilities = &mut capabilities_bytes[..2]; // 4.1 proto

        capabilities[1] |= 0x08; // SSL support flag

        rw.write_all(capabilities)?;
        rw.write_all(&[0x21])?; // UTF8_GENERAL_CI
        rw.write_all(&[0x00, 0x00])?; // status flags
        rw.write_all(&capabilities_bytes[2..])?; // extended capabilities
        rw.write_all(&[0x00])?; // no plugins
        rw.write_all(&[0x00; 6][..])?; // filler
        rw.write_all(&[0x00; 4][..])?; // filler
        rw.write_all(&b">o6^Wz!/kM}N\0"[..])?; // 4.1+ servers must extend salt
        rw.flush()
}

This does allow the jdbc connector to work with client SSL cert CA verify

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions