Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mysql connection with ssl #156

Open
icabraja opened this issue Jul 3, 2024 · 8 comments
Open

mysql connection with ssl #156

icabraja opened this issue Jul 3, 2024 · 8 comments

Comments

@icabraja
Copy link

icabraja commented Jul 3, 2024

Hello! Is it possible to connect to a mysql server using only ssl without a password with this module?

@mithrandyr
Copy link
Owner

@icabraja theoretically any known way of connecting should be supported by using the -ConnectionString parameter. the other parameter sets exist to make connecting simpler without having to formulate a connection string, but for the non-common cases, that parameter exists. There is also the -Additional parameter that allows you specify additional connection parameters while using the simpler approach.

if you can provide me a connection string example, I can provide a suggestion on how to make the connection.

@icabraja
Copy link
Author

icabraja commented Jul 4, 2024

Hello @mithrandyr!
Here is an example using MySQL .NET connector
$ConnectionString = "Server=$MySQLHost;Port=$MySQLPort;Uid=$MySQLUser;Database=$DatabaseName;SslMode=Required;SslCert=$CertificatePath;SslKey=$KeyPath"

$Connection = New-Object MySql.Data.MySqlClient.MySqlConnection($ConnectionString)

Regards, Ivan

Edit:

If I pass a hash table to a -Additional parameter with ssl cert, key and user i get and error:
SslCert and SslKey connection string options are not supported in netstandard2.0

Examlpe:

$ssl = @{
Uid = "ssluser"
SslCert = "C:\ssl\client-cert.pem"
SslKey = "C:\ssl\client-key.pem"
}
Open-MySqlConnection -ConnectionName "test" -Server "localhost" -Database "dashboard" -Port "3306" -SSLMode Required -Additional $ssl

I have also tried using the -ConnectionString parameter with above mentioned $ConnectionString and I get the same error.
Unfortunately I couldn't find an answer. Btw, the above mentioned $ConnectionString works with MySQL .NET connector.

Regards, Ivan

@mithrandyr
Copy link
Owner

@icabraja - it looks like a limitation of the MySqlConnector library and .Net standard 2.0 implementations.
https://github.com/mysql-net/MySqlConnector/blob/72ee684ed0e04e5f39d6e0757a1963e4aa36807f/src/MySqlConnector/Core/ServerSession.cs#L1516

Because I want SimplySql to work for both PS 5.1 and PS7+, I'm building against .NetStandard 2.0. I'd have to look at a different approach in order to handle this.

@icabraja
Copy link
Author

icabraja commented Jul 5, 2024

Hello @mithrandyr!

Thank you for the info and your effort, I apricate it.

Is there maybe a way to use ODBC driver with existing DSN or to pass DSN connection values? I have tried to pass to -ConnectionString New-Object System.Data.Odbc.OdbcConnection("DSN=mysql;") where mysql is the name of already configured DSN connection, but i get and error : Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot be used together or an insufficient number of parameters were provided.

Regards, Ivan

@mithrandyr
Copy link
Owner

@icabraja -- -ConnectionString always is just that... a connection string -- it can't be anything else. Now you could try just passing in "DSN=mysql" though I have no idea if that will work.

@mithrandyr
Copy link
Owner

@icabraja -- The next version (2.1.0, hopefully coming out soon) -- may fix the issue you are having...

@icabraja
Copy link
Author

Hello @mithrandyr!

Thank you for the heads-up, and thank you for the effort. Much appreciated.

@mithrandyr
Copy link
Owner

@icabraja -- Version 2.1 is released, please see if your issue is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants