Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev 2.1 #25

Open
wants to merge 9 commits into
base: release-2.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# v2.0.0
# v2.1.0
* Support external SANs/subject (not in CSR)
* Change Certificate ID on enrollment to use a GUID for uniqueness

# v2.0.1
* Set `grpc.max_receive_message_length` to -1 on `CertificateAuthorityServiceClientBuilder`

# v2.0.0
* Migrate `packages.config` to `PackageReference` format
* Upgrade packages to support Keyfactor AnyCA Gateway DCOM v24.2
* Upgrade `Keyfactor.AnyGateway.SDK` to `24.2.0-PRERELEASE-47446`
Expand Down
26 changes: 5 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,6 @@ The GCP CAS AnyCA Gateway DCOM plugin is open source and there is **no SLA**. Ke
> To report a problem or suggest a new feature, use the **[Issues](../../issues)** tab. If you want to contribute actual bug fixes or proposed enhancements, use the **[Pull requests](../../pulls)** tab.


## Overview

The [Google Cloud Platform (GCP) CA Services (CAS)](https://cloud.google.com/security/products/certificate-authority-service) AnyCA Gateway DCOM plugin extends the capabilities of connected GCP CAS CAs to [Keyfactor Command](https://www.keyfactor.com/products/command/) via the Keyfactor AnyCA Gateway DCOM. The plugin represents a fully featured AnyCA DCOM Plugin with the following capabilies:

* CA Sync:
* Download all certificates issued by connected Enterprise tier CAs in GCP CAS (full sync).
* Download all certificates issued by connected Enterprise tier CAs in GCP CAS issued after a specified time (incremental sync).
* Certificate enrollment for all published GoDaddy Certificate SKUs:
* Support certificate enrollment (new keys/certificate).
* Certificate revocation:
* Request revocation of a previously issued certificate.

> The GCP CAS AnyCA Gateway DCOM plugin is **not** supported for [DevOps Tier](https://cloud.google.com/certificate-authority-service/docs/tiers) Certificate Authority Pools.
>
> DevOps tier CA Pools don't offer listing, describing, or revoking certificates.

## Compatibility

This AnyGateway is designed to be used with version 24.2 of the Keyfactor AnyCA Gateway DCOM Framework.
Expand All @@ -65,7 +49,7 @@ Please refer to [Google's documentation](https://cloud.google.com/docs/authentic
>
> 1. The service account that the AnyCA Gateway REST runs under must have read permission to the GCP credential JSON file.
> 2. You must set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable for the Windows Service running the AnyCA Gateway REST using the [Windows registry editor](https://learn.microsoft.com/en-us/troubleshoot/windows-server/performance/windows-registry-advanced-users).
> * Refer to the [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment](https://learn.microsoft.com/en-us/windows/win32/procthread/environment-variables) docs.
> * Refer to the [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment](https://learn.microsoft.com/en-us/windows/win32/procthread/environment-variables) docs.

If the selected ADC mechanism is [Service Account Key](https://cloud.google.com/docs/authentication/provide-credentials-adc#wlif-key), it's recommended that a [custom role is created](https://cloud.google.com/iam/docs/creating-custom-roles) that has the following minimum permissions:

Expand All @@ -84,7 +68,7 @@ If the selected ADC mechanism is [Service Account Key](https://cloud.google.com/

Both the Keyfactor Command and AnyCA Gateway DCOM servers must trust the root CA, and if applicable, any subordinate CAs for all features to work as intended. Download the CA Certificate (and chain, if applicable) from GCP [CAS](https://console.cloud.google.com/security/cas), and import them into the appropriate certificate store on the AnyCA Gateway DCOM server.

* **Windows** - The root CA and applicable subordinate CAs must be imported into the Windows certificate store. The certificates can be imported using the Microsoft Management Console (MMC) or PowerShell.
* **Windows** - The root CA and applicable subordinate CAs must be imported into the Windows certificate store. The certificates can be imported using the Microsoft Management Console (MMC) or PowerShell.
* Certificates can be imported in MMC by "File" -> "Add/Remove Snap-in" -> "Certificates" -> "Add >" -> "Computer account" -> "Local computer".
* Root CAs must go in the `Trusted Root Certification Authorities` certificate store.
* Subordinate CAs must go in the `Intermediate Certification Authorities` certificate store.
Expand Down Expand Up @@ -139,14 +123,14 @@ The GCP CAS AnyCA Gateway DCOM plugin supports [GCP CAS Certificate Templates](h
</dependentAssembly>
```

> Depending on additional environment-specific factors, additional binding redirects may need to be applied to `CAProxyServer.config`.
> Depending on additional environment-specific factors, additional binding redirects may need to be applied to `CAProxyServer.config`.

## Configuration
The following sections will breakdown the required configurations for the AnyGatewayConfig.json file that will be imported to configure the Google CA.
The following sections will breakdown the required configurations for the AnyGatewayConfig.json file that will be imported to configure the Google CA.

### Templates

As discussed in the [Template Identification](#template-identification), the GCP CAS AnyCA Gateway DCOM plugin supports [GCP CAS Certificate Templates](https://cloud.google.com/certificate-authority-service/docs/policy-controls). The Keyfactor AnyCA Gateway DCOM maps [AD Certificate Templates](https://learn.microsoft.com/en-us/windows-server/identity/ad-cs/certificate-template-concepts) to GCP Certificate Templates via the `ProductID` property in the `Templates` section of configuration files.
As discussed in the [Template Identification](#template-identification), the GCP CAS AnyCA Gateway DCOM plugin supports [GCP CAS Certificate Templates](https://cloud.google.com/certificate-authority-service/docs/policy-controls). The Keyfactor AnyCA Gateway DCOM maps [AD Certificate Templates](https://learn.microsoft.com/en-us/windows-server/identity/ad-cs/certificate-template-concepts) to GCP Certificate Templates via the `ProductID` property in the `Templates` section of configuration files.

_At least one_ Certificate Template must be defined in this section with the `ProductID` set to `Default`. This Product ID corresponds to no Certificate Template for the [CreateCertificate RPC](https://cloud.google.com/certificate-authority-service/docs/reference/rpc/google.cloud.security.privateca.v1#google.cloud.security.privateca.v1.CertificateAuthorityService.CreateCertificate).

Expand Down
15 changes: 8 additions & 7 deletions readme_source.md → docsource/content.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Overview
## Overview

The [Google Cloud Platform (GCP) CA Services (CAS)](https://cloud.google.com/security/products/certificate-authority-service) AnyCA Gateway DCOM plugin extends the capabilities of connected GCP CAS CAs to [Keyfactor Command](https://www.keyfactor.com/products/command/) via the Keyfactor AnyCA Gateway DCOM. The plugin represents a fully featured AnyCA DCOM Plugin with the following capabilies:

Expand All @@ -7,11 +7,12 @@ The [Google Cloud Platform (GCP) CA Services (CAS)](https://cloud.google.com/sec
* Download all certificates issued by connected Enterprise tier CAs in GCP CAS issued after a specified time (incremental sync).
* Certificate enrollment for all published GoDaddy Certificate SKUs:
* Support certificate enrollment (new keys/certificate).
* Support auto-enrollment (subject/SANs supplied outside of CSR)
* Certificate revocation:
* Request revocation of a previously issued certificate.

> The GCP CAS AnyCA Gateway DCOM plugin is **not** supported for [DevOps Tier](https://cloud.google.com/certificate-authority-service/docs/tiers) Certificate Authority Pools.
>
>
> DevOps tier CA Pools don't offer listing, describing, or revoking certificates.

## Compatibility
Expand All @@ -32,7 +33,7 @@ Please refer to [Google's documentation](https://cloud.google.com/docs/authentic
>
> 1. The service account that the AnyCA Gateway REST runs under must have read permission to the GCP credential JSON file.
> 2. You must set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable for the Windows Service running the AnyCA Gateway REST using the [Windows registry editor](https://learn.microsoft.com/en-us/troubleshoot/windows-server/performance/windows-registry-advanced-users).
> * Refer to the [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment](https://learn.microsoft.com/en-us/windows/win32/procthread/environment-variables) docs.
> * Refer to the [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment](https://learn.microsoft.com/en-us/windows/win32/procthread/environment-variables) docs.

If the selected ADC mechanism is [Service Account Key](https://cloud.google.com/docs/authentication/provide-credentials-adc#wlif-key), it's recommended that a [custom role is created](https://cloud.google.com/iam/docs/creating-custom-roles) that has the following minimum permissions:

Expand All @@ -51,7 +52,7 @@ If the selected ADC mechanism is [Service Account Key](https://cloud.google.com/

Both the Keyfactor Command and AnyCA Gateway DCOM servers must trust the root CA, and if applicable, any subordinate CAs for all features to work as intended. Download the CA Certificate (and chain, if applicable) from GCP [CAS](https://console.cloud.google.com/security/cas), and import them into the appropriate certificate store on the AnyCA Gateway DCOM server.

* **Windows** - The root CA and applicable subordinate CAs must be imported into the Windows certificate store. The certificates can be imported using the Microsoft Management Console (MMC) or PowerShell.
* **Windows** - The root CA and applicable subordinate CAs must be imported into the Windows certificate store. The certificates can be imported using the Microsoft Management Console (MMC) or PowerShell.
* Certificates can be imported in MMC by "File" -> "Add/Remove Snap-in" -> "Certificates" -> "Add >" -> "Computer account" -> "Local computer".
* Root CAs must go in the `Trusted Root Certification Authorities` certificate store.
* Subordinate CAs must go in the `Intermediate Certification Authorities` certificate store.
Expand Down Expand Up @@ -106,14 +107,14 @@ The GCP CAS AnyCA Gateway DCOM plugin supports [GCP CAS Certificate Templates](h
</dependentAssembly>
```

> Depending on additional environment-specific factors, additional binding redirects may need to be applied to `CAProxyServer.config`.
> Depending on additional environment-specific factors, additional binding redirects may need to be applied to `CAProxyServer.config`.

## Configuration
The following sections will breakdown the required configurations for the AnyGatewayConfig.json file that will be imported to configure the Google CA.
The following sections will breakdown the required configurations for the AnyGatewayConfig.json file that will be imported to configure the Google CA.

### Templates

As discussed in the [Template Identification](#template-identification), the GCP CAS AnyCA Gateway DCOM plugin supports [GCP CAS Certificate Templates](https://cloud.google.com/certificate-authority-service/docs/policy-controls). The Keyfactor AnyCA Gateway DCOM maps [AD Certificate Templates](https://learn.microsoft.com/en-us/windows-server/identity/ad-cs/certificate-template-concepts) to GCP Certificate Templates via the `ProductID` property in the `Templates` section of configuration files.
As discussed in the [Template Identification](#template-identification), the GCP CAS AnyCA Gateway DCOM plugin supports [GCP CAS Certificate Templates](https://cloud.google.com/certificate-authority-service/docs/policy-controls). The Keyfactor AnyCA Gateway DCOM maps [AD Certificate Templates](https://learn.microsoft.com/en-us/windows-server/identity/ad-cs/certificate-template-concepts) to GCP Certificate Templates via the `ProductID` property in the `Templates` section of configuration files.

_At least one_ Certificate Template must be defined in this section with the `ProductID` set to `Default`. This Product ID corresponds to no Certificate Template for the [CreateCertificate RPC](https://cloud.google.com/certificate-authority-service/docs/reference/rpc/google.cloud.security.privateca.v1#google.cloud.security.privateca.v1.CertificateAuthorityService.CreateCertificate).

Expand Down
86 changes: 73 additions & 13 deletions src/GoogleCAProxy/GoogleCAProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using CAProxy.Common;
using CSS.PKI;
using Google.Api.Gax;
using Google.Api.Gax.Grpc;
using Google.Cloud.Security.PrivateCA.V1;
using Google.Protobuf.WellKnownTypes;
using Grpc.Core;
Expand Down Expand Up @@ -100,13 +101,47 @@ public override EnrollmentResult Enroll(ICertificateDataReader certificateDataRe
$"LifetimeKey not found in Product Parameters for Product Id {productInfo.ProductID}. Using default value of 365 days.");
}

Log.LogDebug($"Configuring {typeof(Certificate)} for {subject} with {lifetimeInDays} days validity");
CertificateConfig certConfig = new CertificateConfig();
certConfig.SubjectConfig = new CertificateConfig.Types.SubjectConfig();
bool useConfig = false;
if (!string.IsNullOrEmpty(subject))
{
certConfig.SubjectConfig.Subject = new Subject
{
CommonName = ParseSubject(subject, "CN=", false),
Organization = ParseSubject(subject, "O=", false),
OrganizationalUnit = ParseSubject(subject, "OU=", false),
CountryCode = ParseSubject(subject, "C=", false),
Locality = ParseSubject(subject, "L=", false)
};
useConfig = true;
}
var dnsSans = new List<string>();
if (san != null & san.Count > 0)
{
var dnsKeys = san.Keys.Where(k => k.IndexOf("dns", StringComparison.OrdinalIgnoreCase) >= 0);
foreach (var key in dnsKeys)
{
dnsSans.AddRange(san[key]);
}
}
if (dnsSans.Count > 0)
{
certConfig.SubjectConfig.SubjectAltName = new SubjectAltNames
{
DnsNames = { dnsSans }
};
useConfig = true;
}

Log.LogDebug($"Configuring {typeof(Certificate)} for {subject} with {lifetimeInDays} days validity");
Certificate certificate = new Certificate
{
PemCsr =
$"-----BEGIN NEW CERTIFICATE REQUEST-----\n{pemify(csr)}\n-----END NEW CERTIFICATE REQUEST-----",
Lifetime = Duration.FromTimeSpan(new TimeSpan(lifetimeInDays, 0, 0, 0,
0)) //365 day default or defined by config
0)), //365 day default or defined by config
Config = (useConfig) ? certConfig : null
};

if (productInfo.ProductID == NoTemplateProductId)
Expand All @@ -131,8 +166,7 @@ public override EnrollmentResult Enroll(ICertificateDataReader certificateDataRe
ParentAsCaPoolName = caPoolAsTypedName,
Certificate = certificate,
//RequestId="",//if used, this needs to be durable between reties
CertificateId =
$"{now:yyyy}{now:MM}{now:dd}-{now:HH}{now:mm}{now:ss}" //ID is required for Enterprise tier CAs and ignored for other.
CertificateId = Guid.NewGuid().ToString() //ID is required for Enterprise tier CAs and ignored for other.
};

if (!string.IsNullOrEmpty(CaId))
Expand Down Expand Up @@ -644,19 +678,45 @@ private CAConnectorCertificate ProcessCAResponse(Certificate caCertificate)
/// <returns></returns>
private static CertificateAuthorityServiceClient BuildClient()
{
CertificateAuthorityServiceClientBuilder caClient = new CertificateAuthorityServiceClientBuilder
string credentialsPath = Environment.GetEnvironmentVariable(AuthEnvVariableName, EnvironmentVariableTarget.Machine);

// Set the gRPC buffer size to -1 for "no limit"
// https://grpc.github.io/grpc/core/group__grpc__arg__keys.html#ga813f94f9ac3174571dd712c96cdbbdc1
GrpcChannelOptions grpcChannelOptions = GrpcChannelOptions.Empty.WithMaxReceiveMessageSize(-1);

CertificateAuthorityServiceClientBuilder caClientBuilder = new CertificateAuthorityServiceClientBuilder
{
CredentialsPath =
Environment.GetEnvironmentVariable(AuthEnvVariableName, EnvironmentVariableTarget.Machine)
CredentialsPath = credentialsPath,
GrpcChannelOptions = grpcChannelOptions,
};
return caClient.Build();
}

#endregion

#region Obsolete Methods
return caClientBuilder.Build();
}

[Obsolete]
private static string ParseSubject(string subject, string rdn, bool required = true)
{
string escapedSubject = subject.Replace("\\,", "|");
string rdnString = escapedSubject.Split(',').ToList().Where(x => x.Contains(rdn)).FirstOrDefault();

if (!string.IsNullOrEmpty(rdnString))
{
return rdnString.Replace(rdn, "").Replace("|", ",").Trim();
}
else if (required)
{
throw new Exception($"The request is missing a {rdn} value");
}
else
{
return null;
}
}

#endregion

#region Obsolete Methods

[Obsolete]
public override EnrollmentResult Enroll(string csr, string subject, Dictionary<string, string[]> san,
EnrollmentProductInfo productInfo, PKIConstants.X509.RequestFormat requestFormat,
RequestUtilities.EnrollmentType enrollmentType)
Expand Down
Loading