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

相关推荐
白衣鸽子7 分钟前
数据库高可用设计的灵魂抉择:CAP权衡
数据库·后端
DokiDoki之父1 小时前
Mybatis—入门 & (配置)SQL提示和日志输出
数据库·sql·mybatis
TDengine (老段)2 小时前
TDengine 数据函数 LN 用户手册
大数据·数据库·物联网·时序数据库·tdengine·涛思数据
机灵猫2 小时前
Redis 在订单系统中的实战应用:防重、限流与库存扣减
数据库·redis·缓存
木易2.02 小时前
从零构建RAG知识库管理系统(二)
数据库·oracle
程序新视界2 小时前
什么是MySQL JOIN查询的驱动表和被驱动表?
数据库·后端·mysql
lingggggaaaa3 小时前
小迪安全v2023学习笔记(一百三十四讲)—— Windows权限提升篇&数据库篇&MySQL&MSSQL&Oracle&自动化项目
java·数据库·windows·笔记·学习·安全·网络安全
小光学长3 小时前
基于Vue的保护动物信息管理系统r7zl6b88 (程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
前端·数据库·vue.js
一匹电信狗3 小时前
【MySQL】数据库的相关操作
linux·运维·服务器·数据库·mysql·ubuntu·小程序
TDengine (老段)5 小时前
连接 TDengine 遇到报错 “failed to connect to server, reason: Connection refused” 怎么办?
大数据·数据库·物联网·时序数据库·iot·tdengine·涛思数据