mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-28 22:55:49 +08:00
# Description Introduces a pluggable user-identity provider model covering all OPC UA Part 6 §6.5 mechanisms (Anonymous, UserName, X509, IssuedToken/JWT) on both client and server, with full `Microsoft.Extensions.DependencyInjection` integration, plus the Part 12 §9 `AuthorizationService` two-phase token-request flow **including refresh-token rotation**, the Part 12 §8 KeyCredential Push model, and a clean provider model for OPC 10000-12 §7.2 `ApplicationSelfAdmin`. The work is split across phase-by-phase commits so it can be reviewed independently; nothing here changes wire-level behaviour or forces existing applications to migrate. ### Documentation All under `Docs/`: - `IdentityProviders.md` — full developer guide: three-layer model, recipes, configuration reference, "what gets auto-wired" matrix, JWS algorithm table, identity-augmenters section, **"Implementing your own provider"** how-to subsections for Entra / OIDC / Windows / AspNetCore (sibling files merged in per review feedback). - `DependencyInjection.md` — `Identity` sections with `appsettings.json` examples, identity-extension matrix, `WithAuthorizationService` + `WithKeyCredentialPush` + `AddIdentityAugmenter` extensions documented. - `RoleBasedUserManagement.md` — claim-criteria callout describing `IIdentityClaims` probe surface. - `AuthorizationService.md` — Architecture diagram + `IAccessTokenProvider` conceptual narrative restored from master; modern `StartRequestToken` / `FinishRequestToken` flow leads; refresh-token recipe added. - `KeyCredentialService.md` — Push model + Pull vs Push vs Bridge decision matrix + Hybrid (Push + Pull) section; explicit experimental warning for the bridge. - `GDS.md` — KeyCredential Push, `StartRequestToken`, `GdsApplicationSelfAdminProvider`, **shipped Refresh-token support with rotation policy and audit semantics** all documented. - `MigrationGuide.md` — User Identity Providers section listing `[Obsolete]` markers + mechanical recipes; SelfAdmin migration via `IIdentityAugmenter`; `EnableRefreshTokens` default note. - `README.md` index entries. ## Checklist - [x] I have signed the [CLA](https://opcfoundation.org/license/cla/ContributorLicenseAgreementv1.0.pdf) and read the [CONTRIBUTING](https://github.com/OPCFoundation/UA-.NETStandard/blob/master/CONTRIBUTING.md) doc. - [x] I have added tests that prove my fix is effective or that my feature works and increased code coverage. - [x] I have added all necessary documentation. - [x] I have verified that my changes do not introduce (new) build or analyzer warnings. - [x] I ran **all** tests locally using the **UA.slnx** solution against at least .net **framework** and .net **10**, and all passed. - [x] I fixed **all** failing and flaky tests in the CI pipelines and **all** CodeQL warnings. - [x] I have addressed **all** PR feedback received.
193 lines
7.3 KiB
C#
193 lines
7.3 KiB
C#
/* ========================================================================
|
|
* Copyright (c) 2005-2025 The OPC Foundation, Inc. All rights reserved.
|
|
*
|
|
* OPC Foundation MIT License 1.00
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person
|
|
* obtaining a copy of this software and associated documentation
|
|
* files (the "Software"), to deal in the Software without
|
|
* restriction, including without limitation the rights to use,
|
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following
|
|
* conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be
|
|
* included in all copies or substantial portions of the Software.
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
*
|
|
* The complete license agreement can be found here:
|
|
* http://opcfoundation.org/License/MIT/1.00/
|
|
* ======================================================================*/
|
|
|
|
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Opc.Ua.Security.Certificates;
|
|
|
|
namespace Opc.Ua
|
|
{
|
|
/// <summary>
|
|
/// An interface to open a certificate store.
|
|
/// </summary>
|
|
public interface IOpenStore
|
|
{
|
|
/// <summary>
|
|
/// Returns an object to access the store containing the certificates.
|
|
/// </summary>
|
|
ICertificateStore OpenStore(ITelemetryContext telemetry);
|
|
}
|
|
|
|
/// <summary>
|
|
/// An abstract interface to certificate stores.
|
|
/// </summary>
|
|
public interface ICertificateStore : IDisposable
|
|
{
|
|
/// <summary>
|
|
/// Opens the store at the specified location.
|
|
/// </summary>
|
|
/// <param name="location">The location.</param>
|
|
/// <param name="noPrivateKeys">Indicates whether NO private keys are found in the store. Default <c>true</c>.</param>
|
|
/// <remarks>
|
|
/// The syntax depends on the store implementation.
|
|
/// </remarks>
|
|
void Open(string location, bool noPrivateKeys = true);
|
|
|
|
/// <summary>
|
|
/// Closes the store.
|
|
/// </summary>
|
|
void Close();
|
|
|
|
/// <summary>
|
|
/// The store type.
|
|
/// </summary>
|
|
string StoreType { get; }
|
|
|
|
/// <summary>
|
|
/// The store path used to open the store.
|
|
/// </summary>
|
|
string StorePath { get; }
|
|
|
|
/// <summary>
|
|
/// Gets a value indicating whether any private keys are found in the store.
|
|
/// </summary>
|
|
/// <value>
|
|
/// <c>true</c> if [no private keys]; otherwise, <c>false</c>.
|
|
/// </value>
|
|
bool NoPrivateKeys { get; }
|
|
|
|
/// <summary>
|
|
/// Enumerates the certificates in the store.
|
|
/// </summary>
|
|
Task<CertificateCollection> EnumerateAsync(CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// Adds a certificate to the store.
|
|
/// </summary>
|
|
/// <param name="certificate">The certificate.</param>
|
|
/// <param name="password">The certificate password.</param>
|
|
/// <param name="ct">Cancellation token to cancel operation with</param>
|
|
Task AddAsync(
|
|
Certificate certificate,
|
|
char[]? password = null,
|
|
CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// Adds a rejected certificate chain to the store.
|
|
/// </summary>
|
|
/// <param name="certificates">The certificate collection.</param>
|
|
/// <param name="maxCertificates">The max number of rejected certificates to keep in the store.
|
|
/// A negative number keeps no history, 0 is unlimited.</param>
|
|
/// <param name="ct">Cancellation token to cancel operation with</param>
|
|
Task AddRejectedAsync(
|
|
CertificateCollection certificates,
|
|
int maxCertificates,
|
|
CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// Deletes a certificate from the store.
|
|
/// </summary>
|
|
/// <param name="thumbprint">The thumbprint.</param>
|
|
/// <param name="ct">Cancellation token to cancel operation with</param>
|
|
/// <returns>True if the certificate exists.</returns>
|
|
Task<bool> DeleteAsync(string thumbprint, CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// Finds the certificate with the specified thumbprint.
|
|
/// </summary>
|
|
/// <param name="thumbprint">The thumbprint.</param>
|
|
/// <param name="ct">Cancellation token to cancel operation with</param>
|
|
/// <returns>The matching certificate</returns>
|
|
Task<CertificateCollection> FindByThumbprintAsync(
|
|
string thumbprint,
|
|
CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// If the store supports the LoadPrivateKey operation.
|
|
/// </summary>
|
|
bool SupportsLoadPrivateKey { get; }
|
|
|
|
/// <summary>
|
|
/// Finds the certificate with the specified thumbprint.
|
|
/// </summary>
|
|
/// <param name="thumbprint">The thumbprint.</param>
|
|
/// <param name="subjectName">The certificate subject.</param>
|
|
/// <param name="applicationUri">The application uri in the cert extension.</param>
|
|
/// <param name="certificateType">The certificate type to load.</param>
|
|
/// <param name="password">The certificate password.</param>
|
|
/// <param name="ct">Cancellation token to cancel operation with</param>
|
|
/// <remarks>Returns always null if SupportsLoadPrivateKey returns false.</remarks>
|
|
/// <returns>The matching certificate with private key</returns>
|
|
Task<Certificate?> LoadPrivateKeyAsync(
|
|
string thumbprint,
|
|
string? subjectName,
|
|
string? applicationUri,
|
|
NodeId certificateType,
|
|
char[]? password,
|
|
CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// Checks if issuer has revoked the certificate.
|
|
/// </summary>
|
|
Task<StatusCode> IsRevokedAsync(
|
|
Certificate issuer,
|
|
Certificate certificate,
|
|
CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// Whether the store supports CRLs.
|
|
/// </summary>
|
|
bool SupportsCRLs { get; }
|
|
|
|
/// <summary>
|
|
/// Returns the CRLs in the store.
|
|
/// </summary>
|
|
Task<X509CRLCollection> EnumerateCRLsAsync(CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// Returns the CRLs for the issuer.
|
|
/// </summary>
|
|
Task<X509CRLCollection> EnumerateCRLsAsync(
|
|
Certificate issuer,
|
|
bool validateUpdateTime = true,
|
|
CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// Adds a CRL to the store.
|
|
/// </summary>
|
|
Task AddCRLAsync(X509CRL crl, CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// Removes a CRL from the store.
|
|
/// </summary>
|
|
Task<bool> DeleteCRLAsync(X509CRL crl, CancellationToken ct = default);
|
|
}
|
|
}
|