Skip to content
Merged
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
37 changes: 37 additions & 0 deletions docs/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,43 @@ authentication schemes as the CA endpoints.
When Graph cannot determine a certificate's status, the report gives a generic reason and
the server log retains the diagnostic detail; the certificate is not revoked.

### Dynamic SCEP authorization

Intune creates and delivers the device-specific challenge; it cannot be replaced with a
password generated by the CA. Optionally require a second, webhook-based authorization
after Intune validates the CSR:

| Key | Meaning |
|---|---|
| `Scep:DynamicChallenge:Enabled` | Enables the extra webhook decision; requires `Scep:Intune`. Default `false`. |
| `Scep:DynamicChallenge:Webhook` | Absolute HTTPS endpoint; redirects are not followed. |
| `Scep:DynamicChallenge:Secret` | Bearer credential for the webhook; supply via a secret store or `Scep__DynamicChallenge__Secret`, never in source control. |

The server POSTs JSON with `transactionId`, `profileName`, `messageType` and
`certificateRequest` (base64 DER CSR). The CSR contains the Intune challenge and may
contain personal data: protect the webhook and restrict access. The webhook must return
HTTP 2xx and JSON `{"allowed":true}`. Any other response, invalid JSON, timeout or
connection error denies issuance; Intune is notified of the failure if it had approved
the request. Intune-refused requests never reach the webhook. A verified SCEP renewal
still requires the webhook, even though its previous certificate replaces Intune validation.
The webhook timeout defaults to 30 seconds; embedded hosts can set
`DynamicChallengeOptions.Timeout` to a value up to five minutes.

`GET /scep/intune/devices?page=0&pageSize=100` requires `scep_intune_sync` and returns
certificate serial, thumbprint, profile, expiry, revocation status, and device/user
identifiers read from the certificate. Pages are pages of the underlying certificate
inventory, filtered after retrieval to `SyncProfiles` and checkable identities, so a page
may be empty even when `hasMore` is true. Profile membership does not prove a certificate
was issued through Intune. Configure dedicated profiles and a persistent certificate
store for reliable reporting. This is not an S03 device catalog or a history of failed
enrollments.

Built-in certificate stores batch profile and certificate lookups per inventory page.
Custom `IStoreCertificates` implementations should override `GetIssuingProfiles` for
the same efficiency; its compatibility fallback calls `GetIssuingProfile` per thumbprint.
The revocation sync uses a shared in-process gate across transient sync instances; it
does not coordinate sync runs across separate server processes.

## ACME endpoints

ACME endpoints are mounted by `UseAcmeServer()` and protected by RFC 8555 account-based JWS
Expand Down
6 changes: 6 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,11 @@ one.

Every `PKCSReq` is now checked with Intune; if Intune refuses, cannot be reached or throttles,
nothing is issued.
To require an additional policy decision, configure `Scep__DynamicChallenge__Enabled=true`,
`Scep__DynamicChallenge__Webhook` with the HTTPS webhook URL, and
`Scep__DynamicChallenge__Secret` with its bearer credential. See the
[webhook contract](documentation.md#dynamic-scep-authorization); Intune continues to
generate and validate the device challenge.
3. **Trusted certificate profiles in Intune** for the CA chain - the root into the computer's root
store, an issuing CA into the intermediate store. `GetCACert` publishes the root as well, and
Windows compares it with the root of its Intune profile before it sends a request.
Expand All @@ -718,6 +723,7 @@ one.
reasonable start. It judges only certificates issued through `Scep:Intune:SyncProfiles`,
revokes those of disabled or deleted users and of retired devices, and never revokes when
Graph is unreachable.
The same role can call `GET /scep/intune/devices` for certificate-backed device reporting.

**Renewal on Windows.** Windows renews by enrolling again with a fresh Intune challenge, not with a
`RenewalReq`. The previous certificate stays valid at the CA until it expires; see
Expand Down
5 changes: 4 additions & 1 deletion docs/standards.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ Intune.
|---|---|
| `IntuneChallengeValidator` | Sends each `PKCSReq` (transaction ID and CSR) to Intune's SCEP validation service (`validateRequest`, discovered through Microsoft Graph) and lets the CA issue only when Intune agrees. Refused, unreachable or throttled (429) all mean *deny*. After issuing it sends `successNotification`; when the CA refuses or fails after Intune agreed, `failureNotification`. A CA that throws (an unreachable store or database) is answered like a refusal: a signed `FAILURE` `CertRep` with `failInfo=badRequest`, the exception in the server log, and a fixed reason in the notification. A `RenewalReq` signed with the previous certificate passes without Intune. |
| `IntuneRevocationSync` | Walks the certificates issued through the configured profiles (`SyncProfiles`, by the issuing profile the store recorded) and asks Graph about the user (UPN from the subjectAltName), the Intune managed device (`IntuneDeviceId://` URI) and the Entra device. What is gone or disabled is revoked (`cessationOfOperation`); certificates from other profiles are never judged. Graph unreachable, throttled or answering in an unexpected shape means *unknown*, and unknown is never revoked; a run that would revoke more than `MaxRevocationsPerSync` aborts. |
| Dynamic SCEP authorization | Optional fail-closed webhook decision after Intune validation; Intune generates the per-device challenge. `GET /scep/intune/devices` reports identifiers from the certificate inventory, scoped to configured profiles. |
| `POST /scep/intune/sync?dryRun=` | Runs the sync and returns the report; 409 while a run is in progress. Requires the authorization policy `scep_intune_sync`. It is an operation, not a scheduler - the caller decides how often. |
| `IIntuneClient.GetManagedDeviceName` | The name of a managed device, for an inventory that lists certificates by device. |

Expand All @@ -277,8 +278,10 @@ throttled, unreachable or answering without a value list (nothing revoked), a ce
another profile, no sync profiles, dry run, the revocation limit, a second run while one is in
progress, and the endpoint's policy.
* [IntuneDeviceName.feature](../tests/opencertserver.contrib.intune.tests/Features/IntuneDeviceName.feature).
* [DynamicScep.feature](../tests/opencertserver.contrib.intune.tests/Features/DynamicScep.feature) —
Intune and webhook authorization, webhook failure, device reporting, and report authorization.

All three run against an in-process fake of Entra, Graph and the validation service. What a fake
These run against an in-process fake of Entra, Graph and the validation service. What a fake
cannot say about the real service was checked against a real tenant: Windows 11 devices enrolled
and renewed through Intune, with `validateRequest` and `successNotification` accepted by Intune,
and the sync running daily.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public bool IsCertificateValid(X509Certificate2? certificate)
return false;
}

var now = DateTime.UtcNow;
var now = DateTime.UtcNow;

_logger.LogTrace("Validating cert UntilExpiry {UntilExpiry}, AfterIssue {AfterIssue} - {Certificate}",
_options.TimeUntilExpiryBeforeRenewal, _options.TimeAfterIssueDateBeforeRenewal, certificate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected async void DoWorkCallback(object? state)
{
_interlock.Release();
}
catch(ObjectDisposedException)
catch (ObjectDisposedException)
{
// ignore, service is stopping
}
Expand Down
17 changes: 17 additions & 0 deletions src/opencertserver.ca.utils/Ca/IStoreCertificates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ Task AddCertificate(
Task<string?> GetIssuingProfile(string thumbprint, CancellationToken cancellationToken = default) =>
Task.FromResult<string?>(null);

/// <summary>
/// Returns trusted issuing profiles keyed by certificate thumbprint. Unknown certificates
/// and certificates without provenance may be omitted or mapped to null. Implementations
/// should override this compatibility fallback to retrieve a page in one operation.
/// </summary>
async Task<IReadOnlyDictionary<string, string?>> GetIssuingProfiles(
IEnumerable<string> thumbprints, CancellationToken cancellationToken = default)
{
var profiles = new Dictionary<string, string?>(StringComparer.OrdinalIgnoreCase);
foreach (var thumbprint in thumbprints)
{
cancellationToken.ThrowIfCancellationRequested();
profiles[thumbprint] = await GetIssuingProfile(thumbprint, cancellationToken).ConfigureAwait(false);
}
return profiles;
}

Task<bool> RemoveCertificate(
string serialNumber,
X509RevocationReason reason,
Expand Down
12 changes: 12 additions & 0 deletions src/opencertserver.ca.utils/Ca/InMemoryCertificateStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ public Task AddCertificate(
return Task.FromResult(item?.IssuingProfile);
}

/// <inheritdoc />
public Task<IReadOnlyDictionary<string, string?>> GetIssuingProfiles(
IEnumerable<string> thumbprints, CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
var keys = thumbprints.ToHashSet(StringComparer.OrdinalIgnoreCase);
IReadOnlyDictionary<string, string?> profiles = _certificates.Values
.Where(item => keys.Contains(item.Thumbprint))
.ToDictionary(item => item.Thumbprint, item => item.IssuingProfile, StringComparer.OrdinalIgnoreCase);
return Task.FromResult(profiles);
}

/// <inheritdoc />
public Task<bool> RemoveCertificate(
string serialNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ private static byte[] EncodeIssuingDistributionPoint(IEnumerable<string> uris)
{
var writer = new AsnWriter(AsnEncodingRules.DER);
using (writer.PushSequence())
using (writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 0, true)))
using (writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 0, true)))
{
foreach (var uri in uris)
{
writer.WriteCharacterString(
UniversalTagNumber.IA5String,
uri,
new Asn1Tag(TagClass.ContextSpecific, 6));
}
}
using (writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 0, true)))
using (writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 0, true)))
{
foreach (var uri in uris)
{
writer.WriteCharacterString(
UniversalTagNumber.IA5String,
uri,
new Asn1Tag(TagClass.ContextSpecific, 6));
}
}
return writer.Encode();
}
}
12 changes: 6 additions & 6 deletions src/opencertserver.ca/CertificateAuthority.cs
Original file line number Diff line number Diff line change
Expand Up @@ -866,14 +866,14 @@ public IReadOnlyCollection<string> GetValues(
var sanValue = name switch
{
{
Type: GeneralName.GeneralNameType.Rfc822Name or GeneralName.GeneralNameType.DnsName,
Value: AsnString asnString
}
Type: GeneralName.GeneralNameType.Rfc822Name or GeneralName.GeneralNameType.DnsName,
Value: AsnString asnString
}
=> asnString.Value,
{
Type: GeneralName.GeneralNameType.OtherName,
Value: OtherName { TypeId: Oids.UserPrincipalName } otherName
}
Type: GeneralName.GeneralNameType.OtherName,
Value: OtherName { TypeId: Oids.UserPrincipalName } otherName
}
=> otherName.StringValue,
_ => null
};
Expand Down
20 changes: 19 additions & 1 deletion src/opencertserver.certserver/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ public static async Task Main(string[] args)
if (builder.Configuration.GetSection(IntuneOptions.SectionName).Exists())
{
app.MapIntuneSync();
app.MapIntuneDeviceReport();
}

await app.RunAsync().ConfigureAwait(false);
Expand Down Expand Up @@ -627,9 +628,26 @@ private static async Task<IServiceCollection> AddScep(
// sync is mapped (see opencertserver.contrib.intune).
if (configuration.GetSection(IntuneOptions.SectionName).Exists())
{
return services.AddIntune(configuration).AddScepServer(options);
services.AddIntune(configuration).AddScepServer(options);
if (configuration.GetValue<bool>("Scep:DynamicChallenge:Enabled"))
{
var webhook = configuration["Scep:DynamicChallenge:Webhook"];
var secret = configuration["Scep:DynamicChallenge:Secret"];
if (!Uri.TryCreate(webhook, UriKind.Absolute, out var address) || secret is null)
{
throw new InvalidOperationException("Scep:DynamicChallenge requires Webhook and Secret.");
}

services.AddIntuneDynamicChallenge(new DynamicChallengeOptions { Webhook = address, Secret = secret });
}

return services;
}

if (configuration.GetValue<bool>("Scep:DynamicChallenge:Enabled"))
{
throw new InvalidOperationException("Scep:DynamicChallenge requires Scep:Intune.");
}
var challenge = configuration["Scep:Challenge"];
return string.IsNullOrEmpty(challenge)
? services.AddScepServer(options)
Expand Down
7 changes: 7 additions & 0 deletions src/opencertserver.certserver/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
"Ca": {
"Persistence": "memory"
},
"Scep": {
"DynamicChallenge": {
"Enabled": false,
"Webhook": null,
"Secret": null
}
},
"Cors": {
"TrustedOrigins": [
"http://localhost:3000",
Expand Down
2 changes: 1 addition & 1 deletion src/opencertserver.cli/Program_EstReEnroll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ async Task ReEnroll(ParseResult parse)
options.ExplicitTrustAnchors.Add(X509CertificateLoader.LoadCertificateFromFile(path));
}

HttpMessageHandler? messageHandler = MessageHandlerFactory();
HttpMessageHandler? messageHandler = MessageHandlerFactory();
if (messageHandler is HttpClientHandler or SocketsHttpHandler)
{
// Let EstClient own TLS identity changes and connection pools for real transports.
Expand Down
Loading
Loading