- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
场景:我在 Windows Server 2012r2 上使用 PowerShell 生成根证书,并希望使用它在动态生成(和销毁)的开发/测试环境中签署新创建的中间证书和 Web 证书。这些脚本是远程部署的,目的是尽可能保持纯 PowerShell。在 Windows 10/2016 中,这相对容易,生成根证书后:
$Cert = New-SelfSignedCertificate -Signer $Root -Subject "CN=$Subject"
X509Enrollment.CX509CertificateRequestCertificate
生成了根证书和
Security.Cryptography.X509Certificates.X509Certificate2
在我已经有一段时间的 SCSS PS 中,主要是因为我需要确保主题和用法设置得非常具体。如果没有上述内容(我以前使用过),我不太确定如何使用它来签署标准证书。
最佳答案
就我而言,避免 makecert 和 openssl 的最终解决方案是使用 Powershell 和 BouncyCaSTLe。我从 PSBouncyCastle fork 了 PSBouncyCaSTLe 存储库由 RLipscombe 发布并插入 1.8.1 Bouncy CaSTLe。我的 fork 版本是我用于脚本的版本, fork 位于 Forked: PSBouncyCastle.New .
然后我使用了StackOverflow: C# Generate Certificates on the Fly作为在下面编写以下 powershell 的灵感,我将把它添加到我的 GitHub 并发表评论,我会尽快修改它 :
Import-Module -Name PSBouncyCastle.New
function New-SelfSignedCertificate {
[CmdletBinding()]
param (
[string]$SubjectName,
[string]$FriendlyName = "New Certificate",
[object]$Issuer,
[bool]$IsCA = $false,
[int]$KeyStrength = 2048,
[int]$ValidYears = 2,
[hashtable]$EKU = @{}
)
# Needed generators
$random = New-SecureRandom
$certificateGenerator = New-CertificateGenerator
if($Issuer -ne $null -and $Issuer.HasPrivateKey -eq $true)
{
$IssuerName = $Issuer.IssuerName.Name
$IssuerPrivateKey = $Issuer.PrivateKey
}
# Create and set a random certificate serial number
$serial = New-SerialNumber -Random $random
$certificateGenerator.SetSerialNumber($serial)
# The signature algorithm
$certificateGenerator.SetSignatureAlgorithm('SHA256WithRSA')
# Basic Constraints - certificate is allowed to be used as intermediate.
# Powershell requires either a $null or reassignment or it will return this from the function
$certificateGenerator = Add-BasicConstraints -isCertificateAuthority $IsCA -certificateGenerator $certificateGenerator
# Key Usage
if($EKU.Count -gt 0)
{
$certificateGenerator = $certificateGenerator | Add-ExtendedKeyUsage @EKU
}
# Create and set the Issuer and Subject name
$subjectDN = New-X509Name -Name ($SubjectName)
if($Issuer -ne $null) {
$IssuerDN = New-X509Name -Name ($IssuerName)
}
else
{
$IssuerDN = New-X509Name -Name ($SubjectName)
}
$certificateGenerator.SetSubjectDN($subjectDN)
$certificateGenerator.SetIssuerDN($IssuerDN)
# Authority Key and Subject Identifier
if($Issuer -ne $null)
{
$IssuerKeyPair = ConvertTo-BouncyCastleKeyPair -PrivateKey $IssuerPrivateKey
$IssuerSerial = [Org.BouncyCastle.Math.BigInteger]$Issuer.GetSerialNumber()
$authorityKeyIdentifier = New-AuthorityKeyIdentifier -name $Issuer.IssuerName.Name -publicKey $IssuerKeyPair.Public -serialNumber $IssuerSerial
$certificateGenerator = Add-AuthorityKeyIdentifier -certificateGenerator $certificateGenerator -authorityKeyIdentifier $authorityKeyIdentifier
}
# Validity range of the certificate
[DateTime]$notBefore = (Get-Date).AddDays(-1)
if($ValidYears -gt 0) {
[DateTime]$notAfter = $notBefore.AddYears($ValidYears)
}
$certificateGenerator.SetNotBefore($notBefore)
$certificateGenerator.SetNotAfter($notAfter)
# Subject public key ~and private
$subjectKeyPair = New-KeyPair -Strength $keyStrength -Random $random
if($IssuerPrivateKey -ne $null)
{
$IssuerKeyPair = [Org.BouncyCastle.Security.DotNetUtilities]::GetKeyPair($IssuerPrivateKey)
}
else
{
$IssuerKeyPair = $subjectKeyPair
}
$certificateGenerator.SetPublicKey($subjectKeyPair.Public)
# Create the Certificate
$IssuerKeyPair = $subjectKeyPair
$certificate = $certificateGenerator.Generate($IssuerKeyPair.Private, $random)
# At this point you have the certificate and need to convert it and export, I return the private key for signing the next cert
$pfxCertificate = ConvertFrom-BouncyCastleCertificate -certificate $certificate -subjectKeyPair $subjectKeyPair -friendlyName $FriendlyName
return $pfxCertificate
}
$TestRootCA = New-SelfSignedCertificate -subjectName "CN=TestRootCA" -IsCA $true
Export-Certificate -Certificate $test -OutputFile "TestRootCA.pfx" -X509ContentType Pfx
$TestSS = New-SelfSignedCertificate -subjectName "CN=TestLocal"
Export-Certificate -Certificate $TestSS -OutputFile "TestLocal.pfx" -X509ContentType Pfx
$TestRootCA = New-SelfSignedCertificate -subjectName "CN=TestRootCA" -IsCA $true
$TestSigned = New-SelfSignedCertificate -subjectName "CN=TestSignedByRoot" -issuer $TestRootCA
Export-Certificate -Certificate $test -OutputFile "TestRootCA.pfx" -X509ContentType Pfx
Export-Certificate -Certificate $test -OutputFile "TestRootCA.pfx" -X509ContentType Pfx
$TestServerCert = New-SelfSignedCertificate -subjectName "CN=TestServerCert" -EKU @{ "ServerAuthentication" = $true }
关于powershell - 使用 Root CA Signer 生成自签名证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44004052/
我们在 Java 应用程序中更新了安全证书,突然我们开始收到下面提到的异常: java.lang.SecurityException: class "org.hibernate.cfg.Configu
我有一个在浏览器中运行并从 Javascript 调用的小程序。有 2 个类:PortalLauncher 和 ParamSplitter,它们位于默认包中。 Javascript 调用 Portal
我在 eclipse 中使用 OSGi 项目运行 JUnit 测试,我遇到了这个异常: java.lang.SecurityException: class "org.eclipse.core.run
我正在开发一个给 PDF 加水印的小工具,它适用于某些 PDF,但对某些其他 PDF 会崩溃。 我正在使用 iText 库和 bouncycaSTLe(依赖项) pom.xml:
我花了 2 天时间试图解决这个问题,但找不到解决办法或至少找不到解决方案: Exception in thread "main" java.lang.SecurityException: class
如果黑客可以调用或调用某些程序功能,我如何在 Solana Anchor 中进行测试? 是通过更改 signers 数组中的第一个元素来实现的: await program.rpc.initializ
iPhone 连接到运行最新 iTunes 版本的 Mac,我 100% 确定她的 UDID 在配置文件中。她的iPhone没有越狱,我们甚至恢复了出厂设置。 我在这一台 iPhone 上安装我们的开
我使用 ant 为 web-start 部署签署我的 jars。Ant.signjar 在 web-start 签名时非常慢。如何加快签名过程? 最佳答案 我找到了一种可能的解决方案。 在构建脚本的早
我已经为 JAVA 创建了部署规则集。该文件是使用证书自签名的。为了使用此规则集,您需要将证书导入 JAVA > Security > Certificates > Signer CA。 如果我手动执
场景:我在 Windows Server 2012r2 上使用 PowerShell 生成根证书,并希望使用它在动态生成(和销毁)的开发/测试环境中签署新创建的中间证书和 Web 证书。这些脚本是远程
遇到一个让我抓狂的问题。在 AEM (6.0 SP3) 中实现 Amakai Edgegrid 身份验证,它会阻止我的主要服务包启动,因为它不是 OSGi 包。 与 this issue 中指出的问题
我在 Nginx 上设置 OCSP 装订并收到错误 OCSP_basic_verify() failed (SSL: error:27069076:OCSP routines:OCSP_basic_v
我正在使用 Laravel (ocotber CMS) 开发我的项目并使用 Spatie URL Signer包来保护我的文件与有限的生命链接。我将文件上传到被 .htaccess 文件列入黑名单的
今天我发现自己无法在我的计算机上恢复 NuGet 包。这样做会产生类似以下的错误: Myproject.csproj : error NU3034: Package 'SomePackage 1.2.
我需要使用 SignServer 代表客户端创建数字签名。我对两个问题有点困惑。 是否每个客户都需要唯一的证书,还是可以为所有客户使用一个证书? 我可以使用 SignServer 创建数字签名证书吗,
当我尝试使用 PKCS11 签名时抛出此异常。我尝试更改字母的大小写,认为这可能是问题所在,但事实并非如此。 最佳答案 此问题的真正原因与我的情况下的异常消息并不对应,然后我意识到这只是 PKCS11
我正在使用node-mysql2 库与 AWS.RDS.signer 结合使用. 我有以下函数,它创建一个连接池以重用连接: const createPool = () => new Promise(
我正在使用 Liberty 16.0.0.4,我想从 Facebook 帐户图像中获取图像,所以我运行了下一个命令以将 Facebook 证书添加到 Liberty 服务器 keytool -imp
我正在尝试实例化一个 X509Certificate 对象,但我一直遇到相同的 CryptographicException,并显示错误消息: "Cannot find the original si
我正在尝试使用 Lambda 生成并返回签名的 cookie,以便我的 iOS 应用程序可以使用该 cookie 通过 CloudFront 访问受限文件。 我认为这应该可以使用 Signer 类:h
我是一名优秀的程序员,十分优秀!