MySQL JDBC连接串中sslMode含义、与useSSL、requireSSL的关系

本文主要是介绍MySQL JDBC连接串中sslMode含义、与useSSL、requireSSL的关系,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录

  • 引言
  • 版本
  • SSL参数含义与默认值
  • 详细含义-中英文对比
    • sslMode
    • useSSL
    • requireSSL
    • verifyServerCertificate
    • trustCertificateKeyStoreType
    • trustCertificateKeyStoreUrl
    • trustCertificateKeyStorePassword
    • fallbackToSystemKeyStore
    • clientCertificateKeyStoreType
    • clientCertificateKeyStoreUrl
    • clientCertificateKeyStorePassword
    • fallbackToSystemKeyStore
  • 对应关系梳理

引言

从Java连接MySQL的连接属性中获取sslMode的含义

版本

驱动版本

<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.29</version>
</dependency>

服务端版本

Database Version: 8.0.35

SSL参数含义与默认值

序号默认值含义
1sslModePREFERRED默认情况下,网络连接是SSL加密的;此属性允许关闭安全连接,或者选择不同的安全级别。
2useSSLtrue与服务器通信时使用SSL(true/false)
3requireSSLfalse如果useSSL=true,则要求服务器支持SSL连接
4verifyServerCertificatefalse
////
1trustCertificateKeyStoreTypeJKS受信任的根证书的密钥存储类型。
2trustCertificateKeyStoreUrl/受信任的根证书密钥存储的URL。
[CR]如果未指定,属性“fallbackToSystemTrustStore”将确定是否使用系统范围的信任存储。
3trustCertificateKeyStorePassword/受信任的根证书密钥存储的密码。
4fallbackToSystemKeyStoretrue没有为“clientCertificateKeyStoreUrl”设置值是否会返回到使用通过系统属性“javax.net.ssl.keyStore*”定义的系统范围的密钥存储。
////
1clientCertificateKeyStoreTypeJKS客户端证书的密钥存储类型。JVM支持的标准密钥存储类型是“JKS\”和“PKCS12\”
2clientCertificateKeyStoreUrl/客户端证书KeyStore的URL。
如果未指定,属性“fallbackToSystemKeyStore”将确定是否使用系统范围的密钥存储。
3clientCertificateKeyStorePassword/客户端证书密钥存储的密码。
4fallbackToSystemKeyStoretrue没有为“clientCertificateKeyStoreUrl”设置值是否会返回到使用通过系统属性“javax.net.ssl.keyStore*”定义的系统范围的密钥存储。"

详细含义-中英文对比

sslMode

By default, network connections are SSL encrypted; this property permits secure connections to be turned off, or a different levels of security to be chosen. 
The following values are allowed: 
\"DISABLED\" - Establish unencrypted connections; 
\"PREFERRED\" - (default) Establish encrypted connections if the server enabled them, otherwise fall back to unencrypted connections; 
\"REQUIRED\" - Establish secure connections if the server enabled them, fail otherwise; 
\"VERIFY_CA\" - Like \"REQUIRED\" but additionally verify the server TLS certificate against the configured Certificate Authority (CA) certificates;
\"VERIFY_IDENTITY\" - Like \"VERIFY_CA\", but additionally verify that the server certificate matches the host to which the connection is attempted.
[CR] This property replaced the deprecated legacy properties \"useSSL\", \"requireSSL\", and \"verifyServerCertificate\", 
which are still accepted but translated into a value for \"sslMode\" if \"sslMode\" is not explicitly set: 
\"useSSL=false\" is translated to \"sslMode=DISABLED\"; 
{\"useSSL=true\", \"requireSSL=false\", \"verifyServerCertificate=false\"} is translated to \"sslMode=PREFERRED\"; 
{\"useSSL=true\", \"requireSSL=true\", \"verifyServerCertificate=false\"} is translated to \"sslMode=REQUIRED\"; 
{\"useSSL=true\" AND \"verifyServerCertificate=true\"} is translated to \"sslMode=VERIFY_CA\". 
There is no equivalent legacy settings for \"sslMode=VERIFY_IDENTITY\". 
Note that, for ALL server versions, the default setting of \"sslMode\" is \"PREFERRED\", and it is equivalent to the legacy settings of \"useSSL=true\", \"requireSSL=false\", and \"verifyServerCertificate=false\", 
which are different from their default settings for Connector/J 8.0.12 and earlier in some situations. Applications that continue to use the legacy properties and rely on their old default settings should be reviewed.
[CR] The legacy properties are ignored if \"sslMode\" is set explicitly. If none of \"sslMode\" or \"useSSL\" is set explicitly, the default setting of \"sslMode=PREFERRED\" applies. "
默认情况下,网络连接是SSL加密的;此属性允许关闭安全连接,或者选择不同的安全级别。
允许使用以下值:
\“DISABLED\”-建立未加密的连接;
\"PREFERRED\" - (默认)如果服务器启用了加密连接,则建立加密连接,否则返回到未加密连接;
\“REQUIRED\”-如果服务器启用了安全连接,则建立安全连接,否则将失败;
\“VERIFY_CA\”-类似于“REQUIRED\”,但还要根据配置的证书颁发机构(CA)证书验证服务器TLS证书;
\“VERIFY_IDENTITY\”-类似于“VERIFY_CA\”,但还要验证服务器证书是否与尝试连接的主机匹配。
[CR]此属性替换了不推荐使用的旧属性\“useSSL\”、\“requireSSL\”和\“verifyServerCertificate\”,
它们仍然被接受,但如果没有明确设置\“sslMode\”,则转换为\“sslMode”的值:
\“useSSL=false\”被翻译为“sslMode=DISABLED\”;
{\“useSSL=true\”、“requireSSL=false\”、“verifyServerCertificate=false”}被翻译为“sslMode=PREFERRED\”;
{\“useSSL=true\”、\“requireSSL=true=”、“verifyServerCertificate=false\”}被翻译为\“sslMode=REQUIRED\”;
{\“useSSL=true\”AND\“verifyServerCertificate=true\”}被翻译为\“sslMode=VERIFY_CA\”。
“sslMode=VERIFY_IDENTITY\”没有等效的旧设置。
请注意,对于所有服务器版本,“sslMode”的默认设置为“PREFERRED”,它等效于“useSSL=true\”、“requireSSL=false”和“verifyServerCertificate=false”的旧设置,
在某些情况下,这与连接器/J 8.0.12及更早版本的默认设置不同。应审查继续使用旧属性并依赖其旧默认设置的应用程序。
[CR]如果显式设置了\“sslMode\”,则会忽略旧属性。如果没有显式设置“sslMode\”或“useSSL\”,则应用默认设置“sslMode=PREFERRED\”。"

useSSL

For 8.0.12 and earlier: Use SSL when communicating with the server (true/false), 
default is 'true' when connecting to MySQL 5.5.45+, 5.6.26+ or 5.7.6+, otherwise default is 'false'.
[CR] For 8.0.13 and later: Default is 'true'. DEPRECATED. See sslMode property description for details."
对于8.0.12及更早版本:与服务器通信时使用SSL(true/false),
连接到MySQL 5.5.45+、5.6.26+或5.7.6+时默认为“true”,否则默认为“false”。
[CR]对于8.0.13及更高版本:默认值为“true”。已弃用。有关详细信息,请参阅sslMode属性描述。"

requireSSL

For 8.0.12 and earlier: Require server support of SSL connection if useSSL=true? (defaults to 'false').
[CR] For 8.0.13 and later: DEPRECATED. See sslMode property description for details.",
对于8.0.12及更早版本:如果useSSL=true,则要求服务器支持SSL连接?(默认为“false”)。
[CR]对于8.0.13及更高版本:已弃用。有关详细信息,请参阅sslMode属性描述。",

verifyServerCertificate

For 8.0.12 and earlier: If \"useSSL\" is set to \"true\", should the driver verify the server's certificate? 
When using this feature, the key store parameters should be specified by the \"clientCertificateKeyStore*\" properties, rather than system properties. 
Default is 'false' when connecting to MySQL 5.5.45+, 5.6.26+ or 5.7.6+ and \"useSSL\" was not explicitly set to \"true\". Otherwise default is 'true'.
[CR] For 8.0.13 and later: Default is 'false'. DEPRECATED. See sslMode property description for details."
对于8.0.12及更早版本:如果“useSSL\”设置为“true\”,驱动程序是否应该验证服务器的证书?
使用此功能时,密钥存储参数应由“clientCertificateKeyStore*”属性指定,而不是由系统属性指定。
当连接到MySQL 5.5.45+、5.6.26+或5.7.6+时,默认值为“false”,并且“useSSL\”未明确设置为“true\”。否则,默认值为“true”。
[CR]对于8.0.13及更高版本:默认值为“false”。已弃用。有关详细信息,请参阅sslMode属性描述。"

trustCertificateKeyStoreType

Key store type for trusted root certificates.
[CR]NULL or empty means use the default, which is \"JKS\". 
Standard key store types supported by the JVM are \"JKS\" and \"PKCS12\", your environment may have more available depending on what security products are installed and available to the JVM.
受信任的根证书的密钥存储类型。
[CR]NULL或空表示使用默认值,即“JKS\”。
JVM支持的标准密钥存储类型是“JKS\”和“PKCS12\”,您的环境可能有更多可用的密钥存储类型,这取决于JVM安装的安全产品和可用的安全产品。

trustCertificateKeyStoreUrl

URL for the trusted root certificates key store.
[CR]If not specified, the property 'fallbackToSystemTrustStore' determines if system-wide trust store is used.
受信任的根证书密钥存储的URL。
[CR]如果未指定,属性“fallbackToSystemTrustStore”将确定是否使用系统范围的信任存储。

trustCertificateKeyStorePassword

Password for the trusted root certificates key store.
受信任的根证书密钥存储的密码。

fallbackToSystemKeyStore

Whether the absence of setting a value for 'clientCertificateKeyStoreUrl' falls back to using the system-wide key store defined through the system properties 'javax.net.ssl.keyStore*'.
没有为“clientCertificateKeyStoreUrl”设置值是否会返回到使用通过系统属性“javax.net.ssl.keyStore*”定义的系统范围的密钥存储。

clientCertificateKeyStoreType

Key store type for client certificates.
[CR]NULL or empty means use the default, which is \"JKS\". Standard key store types supported by the JVM are \"JKS\" and \"PKCS12\", 
your environment may have more available depending on what security products are installed and available to the JVM.",
客户端证书的密钥存储类型。
[CR]NULL或空表示使用默认值,即“JKS\”。JVM支持的标准密钥存储类型是“JKS\”和“PKCS12\”,
您的环境可能有更多的可用性,这取决于安装了哪些安全产品并且JVM可以使用这些产品。",

clientCertificateKeyStoreUrl

URL for the client certificate KeyStore[CR]If not specified, the property 'fallbackToSystemKeyStore' determines if system-wide key store is used.
客户端证书KeyStore的URL[CR]如果未指定,属性“fallbackToSystemKeyStore”将确定是否使用系统范围的密钥存储。

clientCertificateKeyStorePassword

Password for the client certificates key store.
客户端证书密钥存储的密码。

fallbackToSystemKeyStore

Whether the absence of setting a value for 'clientCertificateKeyStoreUrl' falls back to using the system-wide key store defined through the system properties 'javax.net.ssl.keyStore*'."
没有为“clientCertificateKeyStoreUrl”设置值是否会返回到使用通过系统属性“javax.net.ssl.keyStore*”定义的系统范围的密钥存储。"

对应关系梳理

sslMode含义useSSLrequireSSLverifyServerCertificate
DISABLED禁用:建立未加密的连接false
PREFERRED首选:(默认)如果服务器启用了加密连接,则建立加密连接,否则返回到未加密连接truefalsefalse
REQUIRED必须:如果服务器启用了安全连接,则建立安全连接,否则将失败truetruefalse
VERIFY_CA验证授权:类似于“REQUIRED\”,但还要根据配置的证书颁发机构(CA)证书验证服务器TLS证书;truetrue
VERIFY_IDENTITY验证身份:类似于“VERIFY_CA\”,但还要验证服务器证书是否与尝试连接的主机匹配。

这篇关于MySQL JDBC连接串中sslMode含义、与useSSL、requireSSL的关系的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!


原文地址:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.chinasem.cn/article/1020213

相关文章

MySQL 主从复制部署及验证(示例详解)

《MySQL主从复制部署及验证(示例详解)》本文介绍MySQL主从复制部署步骤及学校管理数据库创建脚本,包含表结构设计、示例数据插入和查询语句,用于验证主从同步功能,感兴趣的朋友一起看看吧... 目录mysql 主从复制部署指南部署步骤1.环境准备2. 主服务器配置3. 创建复制用户4. 获取主服务器状态5

SpringBoot中六种批量更新Mysql的方式效率对比分析

《SpringBoot中六种批量更新Mysql的方式效率对比分析》文章比较了MySQL大数据量批量更新的多种方法,指出REPLACEINTO和ONDUPLICATEKEY效率最高但存在数据风险,MyB... 目录效率比较测试结构数据库初始化测试数据批量修改方案第一种 for第二种 case when第三种

MySql基本查询之表的增删查改+聚合函数案例详解

《MySql基本查询之表的增删查改+聚合函数案例详解》本文详解SQL的CURD操作INSERT用于数据插入(单行/多行及冲突处理),SELECT实现数据检索(列选择、条件过滤、排序分页),UPDATE... 目录一、Create1.1 单行数据 + 全列插入1.2 多行数据 + 指定列插入1.3 插入否则更

MySQL深分页进行性能优化的常见方法

《MySQL深分页进行性能优化的常见方法》在Web应用中,分页查询是数据库操作中的常见需求,然而,在面对大型数据集时,深分页(deeppagination)却成为了性能优化的一个挑战,在本文中,我们将... 目录引言:深分页,真的只是“翻页慢”那么简单吗?一、背景介绍二、深分页的性能问题三、业务场景分析四、

MySQL 迁移至 Doris 最佳实践方案(最新整理)

《MySQL迁移至Doris最佳实践方案(最新整理)》本文将深入剖析三种经过实践验证的MySQL迁移至Doris的最佳方案,涵盖全量迁移、增量同步、混合迁移以及基于CDC(ChangeData... 目录一、China编程JDBC Catalog 联邦查询方案(适合跨库实时查询)1. 方案概述2. 环境要求3.

SQL server数据库如何下载和安装

《SQLserver数据库如何下载和安装》本文指导如何下载安装SQLServer2022评估版及SSMS工具,涵盖安装配置、连接字符串设置、C#连接数据库方法和安全注意事项,如混合验证、参数化查... 目录第一步:打开官网下载对应文件第二步:程序安装配置第三部:安装工具SQL Server Manageme

C#连接SQL server数据库命令的基本步骤

《C#连接SQLserver数据库命令的基本步骤》文章讲解了连接SQLServer数据库的步骤,包括引入命名空间、构建连接字符串、使用SqlConnection和SqlCommand执行SQL操作,... 目录建议配合使用:如何下载和安装SQL server数据库-CSDN博客1. 引入必要的命名空间2.

全面掌握 SQL 中的 DATEDIFF函数及用法最佳实践

《全面掌握SQL中的DATEDIFF函数及用法最佳实践》本文解析DATEDIFF在不同数据库中的差异,强调其边界计算原理,探讨应用场景及陷阱,推荐根据需求选择TIMESTAMPDIFF或inte... 目录1. 核心概念:DATEDIFF 究竟在计算什么?2. 主流数据库中的 DATEDIFF 实现2.1

MySQL 多列 IN 查询之语法、性能与实战技巧(最新整理)

《MySQL多列IN查询之语法、性能与实战技巧(最新整理)》本文详解MySQL多列IN查询,对比传统OR写法,强调其简洁高效,适合批量匹配复合键,通过联合索引、分批次优化提升性能,兼容多种数据库... 目录一、基础语法:多列 IN 的两种写法1. 直接值列表2. 子查询二、对比传统 OR 的写法三、性能分析

MySQL中的LENGTH()函数用法详解与实例分析

《MySQL中的LENGTH()函数用法详解与实例分析》MySQLLENGTH()函数用于计算字符串的字节长度,区别于CHAR_LENGTH()的字符长度,适用于多字节字符集(如UTF-8)的数据验证... 目录1. LENGTH()函数的基本语法2. LENGTH()函数的返回值2.1 示例1:计算字符串