Skip to content

Added to pass ssl_mode in configuration. #347

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

Merged
merged 11 commits into from
Dec 3, 2019

Conversation

migimigi
Copy link
Contributor

SSL was enabled by default when connecting to MySQL 5.7.
See https://dev.mysql.com/worklog/task/?id=7712

Added to configuration to enable/disable SSL.
The reason for not using --ssl or --skip-ssl described in MySQL Worklog, --ssl option is deprecated as of MySQL 5.7.11.
See https://dev.mysql.com/doc/refman/5.7/en/encrypted-connection-options.html

@codecov
Copy link

codecov bot commented Mar 19, 2019

Codecov Report

Merging #347 into master will increase coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #347      +/-   ##
==========================================
+ Coverage   87.14%   87.18%   +0.04%     
==========================================
  Files          13       14       +1     
  Lines        1556     1561       +5     
==========================================
+ Hits         1356     1361       +5     
  Misses        200      200
Impacted Files Coverage Δ
MySQLdb/__init__.py 84.78% <100%> (ø) ⬆️
MySQLdb/constants/__init__.py 100% <100%> (ø) ⬆️
MySQLdb/constants/SSL_MODE.py 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e04c597...fd02b7d. Read the comment docs.

@codecov
Copy link

codecov bot commented Mar 19, 2019

Codecov Report

Merging #347 into master will increase coverage by 0.14%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #347      +/-   ##
==========================================
+ Coverage   86.61%   86.75%   +0.14%     
==========================================
  Files          12       12              
  Lines        1531     1533       +2     
==========================================
+ Hits         1326     1330       +4     
+ Misses        205      203       -2
Impacted Files Coverage Δ
MySQLdb/connections.py 81.81% <ø> (+1.67%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8fd628e...bd87447. Read the comment docs.

@migimigi migimigi changed the title Added to pass sql_mode in configuration. Added to pass ssl_mode in configuration. Mar 20, 2019
@methane methane added this to the v2.0 milestone Nov 18, 2019
@methane
Copy link
Member

methane commented Nov 28, 2019

I think there is no MYSQL_OPT_SSL_MODE in old MySQL Connector/C or MariaDB.
Would you test it?

@migimigi
Copy link
Contributor Author

MYSQL_OPT_SSL_MODE exists from MySQL5.5.55.
https://dev.mysql.com/doc/relnotes/mysql/5.5/en/news-5-5-55.html#mysqld-5-5-55-security
I don't know about MariaDB.
I'm going to investigate, fix and test.
I couldn't find MySQL and MariaDB versions supported by mysqlclient-python at https://mysqlclient.readthedocs.io/
Is it there?

@methane
Copy link
Member

methane commented Nov 28, 2019

MySQL 5.5+ are supported.

@methane
Copy link
Member

methane commented Nov 28, 2019

I used MYSQL_DEFAULT_AUTH which is introduced in MySQL 5.5.10. (see #396)
So MySQL 5.5.10+ are supported now.

I wll drop Python 2 support. So I am OK to drop some old MySQL support.
But 5.5.55 looks too new.

@migimigi
Copy link
Contributor Author

I see.

@migimigi
Copy link
Contributor Author

migimigi commented Nov 29, 2019

@methane
Copy link
Member

methane commented Nov 29, 2019

Options should be similar to my.cnf file. Imagine that users may load options from their config file.
So ssl_mode="VERIFY_CA", not ssl_mode=SSL_MODE.VERIFY_CA.

@migimigi
Copy link
Contributor Author

migimigi commented Dec 2, 2019

It has modified

@methane
Copy link
Member

methane commented Dec 2, 2019

I don't like this. This implementation ignores the ssl_mode option silently when it is not supported by the underlying library.

There are two options to fix this:

  • Raise an error if ssl_mode is not supported by the underlying library.
  • Support ssl_mode using legacy options.

@migimigi
Copy link
Contributor Author

migimigi commented Dec 2, 2019

I see.
Choose to raises an error if the ssl_mode setting is not supported.
The legacy option was deprecated and was not used.

MySQLdb/_mysql.c Outdated
(PyCFunction)_mysql_get_have_enum_mysql_opt_ssl_mode,
METH_NOARGS,
_mysql_get_have_enum_mysql_opt_ssl_mode__doc__
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't add new API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.

@@ -102,6 +102,13 @@ class object, used to create cursors (keyword only)
:param int client_flag:
flags to use or 0 (see MySQL docs or constants/CLIENTS.py)

:param str ssl_mode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:param str ssl_mode
:param str ssl_mode:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

Comment on lines 172 to 179
if 'ssl_mode' in kwargs:
if not _mysql.get_have_enum_mysql_opt_ssl_mode():
raise NotSupportedError('Does not support ssl_mode specification: %s' % _mysql.get_client_info())
if hasattr(SSL_MODE, kwargs['ssl_mode']):
kwargs2['ssl_mode'] = getattr(SSL_MODE, kwargs['ssl_mode'])
else:
raise NotSupportedError('Unknown MySQL ssl_mode specification: %s' % kwargs['ssl_mode'])

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement this block in C.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented error checking on the C lang side.
And removed MySQLdb.constants.SSL_MODE, which is no longer needed.

@methane
Copy link
Member

methane commented Dec 3, 2019

Thanks!

@methane methane merged commit 1a5ae1d into PyMySQL:master Dec 3, 2019
@migimigi migimigi deleted the feature/add_ssl_mode branch December 3, 2019 11:17
@migimigi migimigi restored the feature/add_ssl_mode branch December 4, 2019 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants