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下使用

相关推荐
IT枫斗者枫哥1 小时前
MyBatis一对多分页:LIMIT 20,为什么凑不齐20个订单?
java·数据库
Thneonl1 小时前
Flink Operator 的隐藏陷阱:容器名不是你以为的那个
安全·kubernetes
Thneonl1 小时前
kubectl scale ds 是个 404:DaemonSet 没有 replicas
安全·kubernetes
Y001 小时前
PostgreSQL 的锁:为什么你的 ALTER TABLE 会卡住,以及怎么查
数据库·postgresql
灰原喜欢柯南1 小时前
OceanBase 运维管理知识点——OCP 监控、诊断与变更控制
数据库·oceanbase
码农-0041 小时前
Springboot 集成 Ehcache操作数据库显示SQL语句设置
数据库·spring boot·sql
仍然.1 小时前
Redis---事务
数据库·redis
oradh1 小时前
Oracle 执行计划的阅读方法(二叉树结构来理解和阅读)
数据库·oracle·执行计划的阅读方法
SelectDB1 小时前
Doris 向量检索上线踩坑记录:七个排查现场与可直接复制的命令
大数据·数据库·数据分析
数据库小学妹1 小时前
MySQL深分页优化:LIMIT大偏移的根因分析与五种解法对比
数据库·mysql·性能优化