Sqlserver安全篇之_手工创建TLS用到的pfx证书文件

Sqlserver官方提供的Windows Powershell脚本

https://learn.microsoft.com/zh-cn/sql/database-engine/configure-windows/configure-sql-server-encryption?view=sql-server-ver16

bash 复制代码
# Define parameters
$certificateParams = @{
    Type = "SSLServerAuthentication"
    Subject = "CN=$env:COMPUTERNAME"
    DnsName = @("$($env:COMPUTERNAME)", $([System.Net.Dns]::GetHostEntry('').HostName), 'localhost')
    KeyAlgorithm = "RSA"
    KeyLength = 2048
    HashAlgorithm = "SHA256"
    TextExtension = "2.5.29.37={text}1.3.6.1.5.5.7.3.1"
    NotAfter = (Get-Date).AddMonths(36)
    KeySpec = "KeyExchange"
    Provider = "Microsoft RSA SChannel Cryptographic Provider"
    CertStoreLocation = "cert:\LocalMachine\My"
}

# Call the cmdlet
New-SelfSignedCertificate @certificateParams

自己测试实验

在woncntestdb3数据库服务器上创建一个自签名的证书,再把这个自签名证书导出到C:\Certs\dainetdaicom.pfx,这个自签名证书的subject必须是woncntestdb3.dai.netdai.com,就算是*.dai.netdai.com或dai.netdai.com都无法把它从C:\Certs\dainetdaicom.pfx导入到woncntestdb3的sqlserver中

bash 复制代码
$certParams = @{
    Type = "SSLServerAuthentication"
    Subject = "CN=$env:COMPUTERNAME.dai.netdai.com"
    DnsName = @("$($env:COMPUTERNAME)", $([System.Net.Dns]::GetHostEntry('').HostName), 'localhost')
    KeyAlgorithm = "RSA"
    KeyLength = 2048
    HashAlgorithm = "SHA256"
    TextExtension = "2.5.29.37={text}1.3.6.1.5.5.7.3.1"
    NotAfter = (Get-Date).AddMonths(36) # 有效期3年
    KeySpec = "KeyExchange"
    Provider = "Microsoft RSA SChannel Cryptographic Provider"
    FriendlyName     = "Certificate test for woncntestdb3.dai.netdai.com"
    CertStoreLocation = "cert:\LocalMachine\My"
}
$cert = New-SelfSignedCertificate @certParams
$password = ConvertTo-SecureString -String "123456" -Force -AsPlainText # 导入到sqlserver中提示输入密码的时候,就填这个密码
$exportPath = "C:\Certs\dainetdaicom.pfx"
Export-PfxCertificate -Cert $cert -FilePath $exportPath -Password $password

--把上面生成的C:\Certs\dainetdaicom.pfx拷贝到Linux路径/root/123/dainetdaicom.pfx,执行如下语句可以看到证书的有效期

bash 复制代码
openssl x509 -in /root/123/dainetdaicom.pfx -noout -dates

证书可以在linux和windows下互用,目前已经成功验证windows下生成的pfx证书可以在linux中使用,但是还没有成功实验linux生成的证书可以在windows下使用

相关推荐
DolphinDB12 小时前
集成 Prometheus 与 DolphinDB 规则引擎,构建敏捷监控解决方案
数据库
IvorySQL13 小时前
PostgreSQL 技术日报 (3月10日)|IIoT 性能瓶颈与内核优化新讨论
数据库·postgresql·开源
DBA小马哥16 小时前
时序数据库是什么?能源行业国产化替换的入门必看
数据库·时序数据库
爱可生开源社区18 小时前
某马来西亚游戏公司如何从 SQL Server 迁移至 OceanBase?
数据库
小瓦码J码20 小时前
PostgreSQL表名超长踩坑记
数据库·postgresql
yhyyht20 小时前
InfluxDB入门记录(三)flux-dsl
数据库·后端
IvorySQL2 天前
PostgreSQL 技术日报 (3月9日)|EXPLAIN ANALYZE 计时优化与复制语法讨论
数据库·postgresql·开源
stark张宇2 天前
MySQL 核心内幕:从索引原理、字段选型到日志机制与外键约束,一篇打通数据库任督二脉
数据库·mysql·架构
倔强的石头_2 天前
融合数据库架构实践:关系型、JSON与全文检索的“一库多能”深度解析
数据库
星辰员2 天前
KingbaseES数据库:ksql 命令行用户与权限全攻略,从创建到删除
数据库