Skip to content

Commit

Permalink
Add Subject parameter to New-PACertificate, New-PAOrder, and Set-PAOr…
Browse files Browse the repository at this point in the history
…der (#463)
  • Loading branch information
AkiraFFM authored Nov 22, 2022
1 parent cbe5e8c commit d9b6224
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 11 deletions.
6 changes: 5 additions & 1 deletion Posh-ACME/Private/New-Csr.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ function New-Csr {
# start building the cert request

# create the subject
$subject = New-Object Org.BouncyCastle.Asn1.X509.X509Name("CN=$($Order.MainDomain)")
if ($Order.Subject) {
$subject = New-Object Org.BouncyCastle.Asn1.X509.X509Name($Order.Subject)
} else {
$subject = New-Object Org.BouncyCastle.Asn1.X509.X509Name("CN=$($Order.MainDomain)")
}

# create a .NET Dictionary to hold our extensions because that's what BouncyCastle needs
$extDict = New-Object 'Collections.Generic.Dictionary[Org.BouncyCastle.Asn1.DerObjectIdentifier,Org.BouncyCastle.Asn1.X509.X509Extension]'
Expand Down
5 changes: 5 additions & 0 deletions Posh-ACME/Public/New-PACertificate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ function New-PACertificate {
[Parameter(ParameterSetName='FromScratch')]
[switch]$OCSPMustStaple,
[Parameter(ParameterSetName='FromScratch')]
[string]$Subject,
[Parameter(ParameterSetName='FromScratch')]
[string]$FriendlyName,
[Parameter(ParameterSetName='FromScratch')]
[string]$PfxPass='poshacme',
Expand Down Expand Up @@ -157,6 +159,7 @@ function New-PACertificate {
KeyLength = $CertKeyLength
OCSPMustStaple = $OCSPMustStaple
AlwaysNewKey = $AlwaysNewKey
Subject = $Subject
FriendlyName = $FriendlyName
PfxPass = $PfxPass
UseModernPfxEncryption = $UseModernPfxEncryption
Expand All @@ -168,6 +171,7 @@ function New-PACertificate {
if ($oldOrder) {
@( 'OCSPMustStaple'
'AlwaysNewKey'
'Subject'
'FriendlyName'
'PfxPass'
'UseModernPfxEncryption'
Expand Down Expand Up @@ -223,6 +227,7 @@ function New-PACertificate {
'PluginArgs'
'DnsAlias'
'Install'
'Subject'
'FriendlyName'
'PfxPass'
'UseModernPfxEncryption'
Expand Down
4 changes: 4 additions & 0 deletions Posh-ACME/Public/New-PAOrder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ function New-PAOrder {
[switch]$AlwaysNewKey,
[Parameter(ParameterSetName='FromScratch')]
[Parameter(ParameterSetName='ImportKey')]
[string]$Subject,
[Parameter(ParameterSetName='FromScratch')]
[Parameter(ParameterSetName='ImportKey')]
[string]$FriendlyName,
[Parameter(ParameterSetName='FromScratch')]
[Parameter(ParameterSetName='ImportKey')]
Expand Down Expand Up @@ -259,6 +262,7 @@ function New-PAOrder {
DnsAlias = $null
DnsSleep = $DnsSleep
ValidationTimeout = $ValidationTimeout
Subject = $Subject
FriendlyName = $FriendlyName
PfxPass = $PfxPass
Install = $Install.IsPresent
Expand Down
10 changes: 10 additions & 0 deletions Posh-ACME/Public/Set-PAOrder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ function Set-PAOrder {
[string]$NewName,
[Parameter(ParameterSetName='Edit')]
[ValidateNotNullOrEmpty()]
[string]$Subject,
[Parameter(ParameterSetName='Edit')]
[ValidateNotNullOrEmpty()]
[string]$FriendlyName,
[Parameter(ParameterSetName='Edit')]
[ValidateNotNullOrEmpty()]
Expand Down Expand Up @@ -147,6 +150,13 @@ function Set-PAOrder {
$saveChanges = $true
}

if ('Subject' -in $psbKeys -and $Subject -ne $order.Subject) {
Write-Verbose "Setting Subject to '$Subject'"
Write-Warning "Changing the value of Subject only affects future certificates generated with this order. It can not change the state of an existing certificate."
$order.Subject = $Subject
$saveChanges = $true
}

if ('FriendlyName' -in $psbKeys -and $FriendlyName -ne $order.FriendlyName) {
Write-Verbose "Setting FriendlyName to '$FriendlyName'"
$order.FriendlyName = $FriendlyName
Expand Down
84 changes: 84 additions & 0 deletions Posh-ACME/en-US/Posh-ACME-help.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2925,6 +2925,18 @@ New-PAAccount -ExtAcctKID $eabKID -ExtAcctHMACKey $eabHMAC -Contact 'me@example.
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Subject</maml:name>
<maml:description>
<maml:para>Sets the x509 "Subject" field in the certificate request that gets sent to the ACME server. By default, it is set to 'CN=FQDN' where 'FQDN' is the first name in the Domain parameter. For public certificate authorities issuing DV certificates, anything other than a DNS name from the list of domains will either be rejected or stripped from the finalized certificate.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>FriendlyName</maml:name>
<maml:description>
Expand Down Expand Up @@ -3392,6 +3404,18 @@ New-PAAccount -ExtAcctKID $eabKID -ExtAcctHMACKey $eabHMAC -Contact 'me@example.
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Subject</maml:name>
<maml:description>
<maml:para>Sets the x509 "Subject" field in the certificate request that gets sent to the ACME server. By default, it is set to 'CN=FQDN' where 'FQDN' is the first name in the Domain parameter. For public certificate authorities issuing DV certificates, anything other than a DNS name from the list of domains will either be rejected or stripped from the finalized certificate.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>FriendlyName</maml:name>
<maml:description>
Expand Down Expand Up @@ -3717,6 +3741,18 @@ New-PACertificate 'example.com' -Plugin FakeDNS -PluginArgs $pArgs -DnsAlias 'ac
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Subject</maml:name>
<maml:description>
<maml:para>Sets the x509 "Subject" field in the certificate request that gets sent to the ACME server. By default, it is set to 'CN=FQDN' where 'FQDN' is the first name in the Domain parameter. For public certificate authorities issuing DV certificates, anything other than a DNS name from the list of domains will either be rejected or stripped from the finalized certificate.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>FriendlyName</maml:name>
<maml:description>
Expand Down Expand Up @@ -3964,6 +4000,18 @@ New-PACertificate 'example.com' -Plugin FakeDNS -PluginArgs $pArgs -DnsAlias 'ac
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Subject</maml:name>
<maml:description>
<maml:para>Sets the x509 "Subject" field in the certificate request that gets sent to the ACME server. By default, it is set to 'CN=FQDN' where 'FQDN' is the first name in the Domain parameter. For public certificate authorities issuing DV certificates, anything other than a DNS name from the list of domains will either be rejected or stripped from the finalized certificate.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>FriendlyName</maml:name>
<maml:description>
Expand Down Expand Up @@ -4392,6 +4440,18 @@ New-PACertificate 'example.com' -Plugin FakeDNS -PluginArgs $pArgs -DnsAlias 'ac
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Subject</maml:name>
<maml:description>
<maml:para>Sets the x509 "Subject" field in the certificate request that gets sent to the ACME server. By default, it is set to 'CN=FQDN' where 'FQDN' is the first name in the Domain parameter. For public certificate authorities issuing DV certificates, anything other than a DNS name from the list of domains will either be rejected or stripped from the finalized certificate.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>FriendlyName</maml:name>
<maml:description>
Expand Down Expand Up @@ -6865,6 +6925,18 @@ Set-PAAccount -UseAltPluginEncryption:$false</dev:code>
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Subject</maml:name>
<maml:description>
<maml:para>Sets the x509 "Subject" field in the certificate request that gets sent to the ACME server. By default, it is set to 'CN=FQDN' where 'FQDN' is the first name in the Domain parameter. For public certificate authorities issuing DV certificates, anything other than a DNS name from the list of domains will either be rejected or stripped from the finalized certificate.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>FriendlyName</maml:name>
<maml:description>
Expand Down Expand Up @@ -7137,6 +7209,18 @@ Set-PAAccount -UseAltPluginEncryption:$false</dev:code>
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Subject</maml:name>
<maml:description>
<maml:para>Sets the x509 "Subject" field in the certificate request that gets sent to the ACME server. By default, it is set to 'CN=FQDN' where 'FQDN' is the first name in the Domain parameter. For public certificate authorities issuing DV certificates, anything other than a DNS name from the list of domains will either be rejected or stripped from the finalized certificate.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>FriendlyName</maml:name>
<maml:description>
Expand Down
17 changes: 16 additions & 1 deletion docs/Functions/New-PACertificate.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Request a new certificate
```powershell
New-PACertificate [-Domain] <String[]> [-Name <String>] [-Contact <String[]>] [-CertKeyLength <String>]
[-AlwaysNewKey] [-AcceptTOS] [-AccountKeyLength <String>] [-DirectoryUrl <String>] [-Plugin <String[]>]
[-PluginArgs <Hashtable>] [-LifetimeDays <Int32>] [-DnsAlias <String[]>] [-OCSPMustStaple]
[-PluginArgs <Hashtable>] [-LifetimeDays <Int32>] [-DnsAlias <String[]>] [-OCSPMustStaple] [-Subject <String>]
[-FriendlyName <String>] [-PfxPass <String>] [-PfxPassSecure <SecureString>] [-UseModernPfxEncryption]
[-Install] [-UseSerialValidation] [-Force] [-DnsSleep <Int32>] [-ValidationTimeout <Int32>]
[-PreferredChain <String>] [<CommonParameters>]
Expand Down Expand Up @@ -317,6 +317,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -Subject
Sets the x509 "Subject" field in the certificate request that gets sent to the ACME server. By default, it is set to 'CN=FQDN' where 'FQDN' is the first name in the Domain parameter. For public certificate authorities issuing DV certificates, anything other than a DNS name from the list of domains will either be rejected or stripped from the finalized certificate.

```yaml
Type: String
Parameter Sets: FromScratch
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -FriendlyName

Set a friendly name for the certificate.
Expand Down
27 changes: 21 additions & 6 deletions docs/Functions/New-PAOrder.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ Create a new order on the current ACME account.
```powershell
New-PAOrder [-Domain] <String[]> [[-KeyLength] <String>] [-Name <String>] [-Plugin <String[]>]
[-PluginArgs <Hashtable>] [-LifetimeDays <Int32>] [-DnsAlias <String[]>] [-OCSPMustStaple] [-AlwaysNewKey]
[-FriendlyName <String>] [-PfxPass <String>] [-PfxPassSecure <SecureString>] [-UseModernPfxEncryption]
[-Install] [-UseSerialValidation] [-DnsSleep <Int32>] [-ValidationTimeout <Int32>] [-PreferredChain <String>]
[-Force] [-WhatIf] [-Confirm] [<CommonParameters>]
[-Subject <String>] [-FriendlyName <String>] [-PfxPass <String>] [-PfxPassSecure <SecureString>]
[-UseModernPfxEncryption] [-Install] [-UseSerialValidation] [-DnsSleep <Int32>] [-ValidationTimeout <Int32>]
[-PreferredChain <String>] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]
```

### ImportKey
```powershell
New-PAOrder [-Domain] <String[]> -KeyFile <String> [-Name <String>] [-Plugin <String[]>]
[-PluginArgs <Hashtable>] [-LifetimeDays <Int32>] [-DnsAlias <String[]>] [-OCSPMustStaple] [-AlwaysNewKey]
[-FriendlyName <String>] [-PfxPass <String>] [-PfxPassSecure <SecureString>] [-UseModernPfxEncryption]
[-Install] [-UseSerialValidation] [-DnsSleep <Int32>] [-ValidationTimeout <Int32>] [-PreferredChain <String>]
[-Force] [-WhatIf] [-Confirm] [<CommonParameters>]
[-Subject <String>] [-FriendlyName <String>] [-PfxPass <String>] [-PfxPassSecure <SecureString>]
[-UseModernPfxEncryption] [-Install] [-UseSerialValidation] [-DnsSleep <Int32>] [-ValidationTimeout <Int32>]
[-PreferredChain <String>] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]
```

### FromCSR
Expand Down Expand Up @@ -261,6 +261,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -Subject
Sets the x509 "Subject" field in the certificate request that gets sent to the ACME server. By default, it is set to 'CN=FQDN' where 'FQDN' is the first name in the Domain parameter. For public certificate authorities issuing DV certificates, anything other than a DNS name from the list of domains will either be rejected or stripped from the finalized certificate.

```yaml
Type: String
Parameter Sets: FromScratch, ImportKey
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -FriendlyName
Set a friendly name for the certificate.
This will populate the "Friendly Name" field in the Windows certificate store when the PFX is imported.
Expand Down
21 changes: 18 additions & 3 deletions docs/Functions/Set-PAOrder.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ Switch to or modify an order.
```powershell
Set-PAOrder [[-MainDomain] <String>] [-Name <String>] [-NoSwitch] [-Plugin <String[]>]
[-PluginArgs <Hashtable>] [-LifetimeDays <Int32>] [-DnsAlias <String[]>] [-NewName <String>]
[-FriendlyName <String>] [-PfxPass <String>] [-PfxPassSecure <SecureString>] [-UseModernPfxEncryption]
[-Install] [-OCSPMustStaple] [-DnsSleep <Int32>] [-ValidationTimeout <Int32>] [-PreferredChain <String>]
[-AlwaysNewKey] [-UseSerialValidation] [-WhatIf] [-Confirm] [<CommonParameters>]
[-Subject <String>] [-FriendlyName <String>] [-PfxPass <String>] [-PfxPassSecure <SecureString>]
[-UseModernPfxEncryption] [-Install] [-OCSPMustStaple] [-DnsSleep <Int32>] [-ValidationTimeout <Int32>]
[-PreferredChain <String>] [-AlwaysNewKey] [-UseSerialValidation] [-WhatIf] [-Confirm] [<CommonParameters>]
```

### Revoke
Expand Down Expand Up @@ -209,6 +209,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -Subject
Sets the x509 "Subject" field in the certificate request that gets sent to the ACME server. By default, it is set to 'CN=FQDN' where 'FQDN' is the first name in the Domain parameter. For public certificate authorities issuing DV certificates, anything other than a DNS name from the list of domains will either be rejected or stripped from the finalized certificate.

```yaml
Type: String
Parameter Sets: Edit
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -FriendlyName
The friendly name for the certificate and subsequent renewals.
This will populate the "Friendly Name" field in the Windows certificate store when the PFX is imported.
Expand Down

0 comments on commit d9b6224

Please sign in to comment.