| | | 1 | | using System.Globalization; |
| | | 2 | | using System.Runtime.ExceptionServices; |
| | | 3 | | using AsiBackbone.Core.Signing; |
| | | 4 | | |
| | | 5 | | namespace AsiBackbone.Signing.ManagedKey; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Provides managed-key signing for AsiBackbone signing abstractions through a host-owned managed-key client. |
| | | 9 | | /// </summary> |
| | | 10 | | /// <remarks> |
| | | 11 | | /// This service signs precomputed hashes only. It never requests or handles raw private key material. |
| | | 12 | | /// </remarks> |
| | | 13 | | public sealed class ManagedKeySigningService : IAsiBackboneSigningService |
| | | 14 | | { |
| | | 15 | | private const string ProviderKind = "managed-key"; |
| | | 16 | | |
| | | 17 | | private readonly ManagedKeySigningOptions options; |
| | | 18 | | private readonly IManagedKeySigningClient client; |
| | | 19 | | private readonly IManagedKeyRetryJitterSource jitterSource; |
| | | 20 | | private readonly IManagedKeyRetryDelay retryDelay; |
| | | 21 | | |
| | | 22 | | /// <summary> |
| | | 23 | | /// Initializes a new instance of the <see cref="ManagedKeySigningService" /> class. |
| | | 24 | | /// </summary> |
| | | 25 | | public ManagedKeySigningService(ManagedKeySigningOptions options, IManagedKeySigningClient client) |
| | 66 | 26 | | : this( |
| | 66 | 27 | | options, |
| | 66 | 28 | | client, |
| | 66 | 29 | | SharedRandomManagedKeyRetryJitterSource.Instance, |
| | 66 | 30 | | SystemManagedKeyRetryDelay.Instance) |
| | | 31 | | { |
| | 66 | 32 | | } |
| | | 33 | | |
| | 70 | 34 | | internal ManagedKeySigningService( |
| | 70 | 35 | | ManagedKeySigningOptions options, |
| | 70 | 36 | | IManagedKeySigningClient client, |
| | 70 | 37 | | IManagedKeyRetryJitterSource jitterSource, |
| | 70 | 38 | | IManagedKeyRetryDelay retryDelay) |
| | | 39 | | { |
| | 70 | 40 | | ArgumentNullException.ThrowIfNull(options); |
| | 70 | 41 | | ArgumentNullException.ThrowIfNull(client); |
| | 70 | 42 | | ArgumentNullException.ThrowIfNull(jitterSource); |
| | 70 | 43 | | ArgumentNullException.ThrowIfNull(retryDelay); |
| | | 44 | | |
| | 70 | 45 | | options.Validate(); |
| | 70 | 46 | | this.options = options; |
| | 70 | 47 | | this.client = client; |
| | 70 | 48 | | this.jitterSource = jitterSource; |
| | 70 | 49 | | this.retryDelay = retryDelay; |
| | 70 | 50 | | } |
| | | 51 | | |
| | | 52 | | /// <inheritdoc /> |
| | | 53 | | public async ValueTask<SigningResult> SignAsync( |
| | | 54 | | SigningRequest request, |
| | | 55 | | CancellationToken cancellationToken = default) |
| | | 56 | | { |
| | 54 | 57 | | ArgumentNullException.ThrowIfNull(request); |
| | 54 | 58 | | cancellationToken.ThrowIfCancellationRequested(); |
| | | 59 | | |
| | 54 | 60 | | ManagedKeySigningAttemptDiagnostics diagnostics = CreateAttemptDiagnostics(); |
| | 54 | 61 | | string? validationFailure = ValidateSigningRequest(request); |
| | 54 | 62 | | if (validationFailure is not null) |
| | | 63 | | { |
| | 12 | 64 | | return HandleValidationFailure(request, validationFailure, diagnostics); |
| | | 65 | | } |
| | | 66 | | |
| | 42 | 67 | | int attempt = 0; |
| | | 68 | | |
| | | 69 | | while (true) |
| | | 70 | | { |
| | | 71 | | try |
| | | 72 | | { |
| | 58 | 73 | | ManagedKeySignResult managedResult = await client |
| | 58 | 74 | | .SignAsync(CreateManagedKeyRequest(request), cancellationToken) |
| | 58 | 75 | | .ConfigureAwait(false); |
| | | 76 | | |
| | 24 | 77 | | return CreateSignedResult(request, managedResult, attempt, diagnostics); |
| | | 78 | | } |
| | 26 | 79 | | catch (ManagedKeySigningException exception) when (exception.IsRetryable && attempt < options.MaxRetryAttemp |
| | | 80 | | { |
| | 16 | 81 | | diagnostics.RecordRetry(exception); |
| | 16 | 82 | | attempt++; |
| | 16 | 83 | | await DelayForRetryAsync(attempt, diagnostics, cancellationToken).ConfigureAwait(false); |
| | 16 | 84 | | } |
| | 10 | 85 | | catch (ManagedKeySigningException exception) |
| | | 86 | | { |
| | 10 | 87 | | return HandleFailure(request, exception.FailureCode, exception.Message, attempt, diagnostics, exception) |
| | | 88 | | } |
| | 2 | 89 | | catch (TimeoutException exception) |
| | | 90 | | { |
| | 2 | 91 | | return HandleFailure(request, "managedkey.signing.provider-unavailable", exception.GetType().Name, attem |
| | | 92 | | } |
| | 4 | 93 | | catch (InvalidOperationException exception) |
| | | 94 | | { |
| | 4 | 95 | | return HandleFailure(request, "managedkey.signing.failed", exception.GetType().Name, attempt, diagnostic |
| | | 96 | | } |
| | 2 | 97 | | catch (NotSupportedException exception) |
| | | 98 | | { |
| | 2 | 99 | | return HandleFailure(request, "managedkey.signing.unsupported", exception.GetType().Name, attempt, diagn |
| | | 100 | | } |
| | | 101 | | } |
| | 48 | 102 | | } |
| | | 103 | | |
| | | 104 | | private SigningResult HandleValidationFailure( |
| | | 105 | | SigningRequest request, |
| | | 106 | | string failureCode, |
| | | 107 | | ManagedKeySigningAttemptDiagnostics diagnostics) |
| | | 108 | | { |
| | 12 | 109 | | diagnostics.RecordValidationFailure(); |
| | | 110 | | |
| | 12 | 111 | | return !options.ReturnUnsignedOnFailure |
| | 12 | 112 | | ? throw new ManagedKeySigningException(failureCode, failureCode) |
| | 12 | 113 | | : CreateUnsignedFailureResult(request, failureCode, failureCode, retryAttempts: 0, diagnostics); |
| | | 114 | | } |
| | | 115 | | |
| | | 116 | | private SigningResult HandleFailure( |
| | | 117 | | SigningRequest request, |
| | | 118 | | string failureCode, |
| | | 119 | | string failureMessage, |
| | | 120 | | int retryAttempts, |
| | | 121 | | ManagedKeySigningAttemptDiagnostics diagnostics, |
| | | 122 | | Exception exception) |
| | | 123 | | { |
| | 18 | 124 | | diagnostics.RecordFailure(exception); |
| | | 125 | | |
| | 18 | 126 | | if (!options.ReturnUnsignedOnFailure) |
| | | 127 | | { |
| | 4 | 128 | | ExceptionDispatchInfo.Capture(exception).Throw(); |
| | | 129 | | } |
| | | 130 | | |
| | 14 | 131 | | return CreateUnsignedFailureResult(request, failureCode, failureMessage, retryAttempts, diagnostics); |
| | | 132 | | } |
| | | 133 | | |
| | | 134 | | private ManagedKeySignRequest CreateManagedKeyRequest(SigningRequest request) |
| | | 135 | | { |
| | 58 | 136 | | return new ManagedKeySignRequest( |
| | 58 | 137 | | request.SigningHash, |
| | 58 | 138 | | NormalizeHashAlgorithm(request.HashAlgorithm), |
| | 58 | 139 | | NormalizeRequired(options.SignatureAlgorithm, ManagedKeySigningOptions.DefaultSignatureAlgorithm), |
| | 58 | 140 | | ResolveKeyId(request), |
| | 58 | 141 | | ResolveKeyVersion(request), |
| | 58 | 142 | | request.Purpose, |
| | 58 | 143 | | request.Metadata); |
| | | 144 | | } |
| | | 145 | | |
| | | 146 | | private SigningResult CreateSignedResult( |
| | | 147 | | SigningRequest request, |
| | | 148 | | ManagedKeySignResult managedResult, |
| | | 149 | | int retryAttempts, |
| | | 150 | | ManagedKeySigningAttemptDiagnostics diagnostics) |
| | | 151 | | { |
| | 24 | 152 | | string resolvedKeyVersion = managedResult.KeyVersion ?? ResolveKeyVersion(request) ?? string.Empty; |
| | 24 | 153 | | Dictionary<string, string> metadata = CreateBaseMetadata(request, retryAttempts, providerAttempts: retryAttempts |
| | 24 | 154 | | metadata["signing_status"] = "signed"; |
| | | 155 | | |
| | 24 | 156 | | if (managedResult.ProviderOperationId is not null) |
| | | 157 | | { |
| | 12 | 158 | | metadata["provider_operation_id"] = managedResult.ProviderOperationId; |
| | | 159 | | } |
| | | 160 | | |
| | 72 | 161 | | foreach (KeyValuePair<string, string> item in managedResult.Metadata) |
| | | 162 | | { |
| | 12 | 163 | | if (!IsSafeProviderMetadataKey(item.Key) || IsReservedDiagnosticMetadataKey(item.Key)) |
| | | 164 | | { |
| | | 165 | | continue; |
| | | 166 | | } |
| | | 167 | | |
| | 12 | 168 | | metadata[item.Key.Trim()] = item.Value?.Trim() ?? string.Empty; |
| | | 169 | | } |
| | | 170 | | |
| | 24 | 171 | | var signingMetadata = SigningMetadata.Create( |
| | 24 | 172 | | signingHash: request.SigningHash, |
| | 24 | 173 | | hashAlgorithm: NormalizeHashAlgorithm(request.HashAlgorithm), |
| | 24 | 174 | | signature: managedResult.Signature, |
| | 24 | 175 | | signatureAlgorithm: managedResult.SignatureAlgorithm, |
| | 24 | 176 | | keyId: managedResult.KeyId, |
| | 24 | 177 | | keyVersion: string.IsNullOrWhiteSpace(resolvedKeyVersion) ? null : resolvedKeyVersion, |
| | 24 | 178 | | provider: NormalizeRequired(options.ProviderName, ManagedKeySigningOptions.DefaultProviderName), |
| | 24 | 179 | | signedUtc: managedResult.SignedUtc, |
| | 24 | 180 | | metadata: metadata); |
| | | 181 | | |
| | 24 | 182 | | return SigningResult.FromMetadata(signingMetadata); |
| | | 183 | | } |
| | | 184 | | |
| | | 185 | | private SigningResult CreateUnsignedFailureResult( |
| | | 186 | | SigningRequest request, |
| | | 187 | | string failureCode, |
| | | 188 | | string failureMessage, |
| | | 189 | | int retryAttempts, |
| | | 190 | | ManagedKeySigningAttemptDiagnostics diagnostics) |
| | | 191 | | { |
| | 24 | 192 | | int providerAttempts = diagnostics.HasValidationFailure ? 0 : retryAttempts + 1; |
| | 24 | 193 | | Dictionary<string, string> metadata = CreateBaseMetadata(request, retryAttempts, providerAttempts, diagnostics); |
| | 24 | 194 | | metadata["signing_status"] = "failed"; |
| | 24 | 195 | | metadata["failure_code"] = failureCode; |
| | 24 | 196 | | metadata["failure_message"] = failureMessage; |
| | | 197 | | |
| | 24 | 198 | | var signingMetadata = SigningMetadata.Create( |
| | 24 | 199 | | signingHash: request.SigningHash, |
| | 24 | 200 | | hashAlgorithm: NormalizeHashAlgorithm(request.HashAlgorithm), |
| | 24 | 201 | | keyId: ResolveKeyId(request), |
| | 24 | 202 | | keyVersion: ResolveKeyVersion(request), |
| | 24 | 203 | | provider: NormalizeRequired(options.ProviderName, ManagedKeySigningOptions.DefaultProviderName), |
| | 24 | 204 | | metadata: metadata); |
| | | 205 | | |
| | 24 | 206 | | return SigningResult.FromMetadata(signingMetadata); |
| | | 207 | | } |
| | | 208 | | |
| | | 209 | | private Dictionary<string, string> CreateBaseMetadata( |
| | | 210 | | SigningRequest request, |
| | | 211 | | int retryAttempts, |
| | | 212 | | int providerAttempts, |
| | | 213 | | ManagedKeySigningAttemptDiagnostics diagnostics) |
| | | 214 | | { |
| | 48 | 215 | | Dictionary<string, string> metadata = new(StringComparer.Ordinal); |
| | | 216 | | |
| | 216 | 217 | | foreach (KeyValuePair<string, string> item in request.Metadata) |
| | | 218 | | { |
| | 60 | 219 | | if (string.IsNullOrWhiteSpace(item.Key) || IsReservedDiagnosticMetadataKey(item.Key)) |
| | | 220 | | { |
| | | 221 | | continue; |
| | | 222 | | } |
| | | 223 | | |
| | 10 | 224 | | metadata[item.Key.Trim()] = item.Value?.Trim() ?? string.Empty; |
| | | 225 | | } |
| | | 226 | | |
| | 48 | 227 | | metadata["provider_kind"] = ProviderKind; |
| | 48 | 228 | | metadata["remote_key_material"] = "true"; |
| | 48 | 229 | | metadata["raw_private_key_loaded"] = "false"; |
| | 48 | 230 | | metadata["retry_attempts"] = retryAttempts.ToString(CultureInfo.InvariantCulture); |
| | 48 | 231 | | metadata["provider_attempts"] = providerAttempts.ToString(CultureInfo.InvariantCulture); |
| | 48 | 232 | | metadata["max_retry_attempts"] = diagnostics.MaxRetryAttempts.ToString(CultureInfo.InvariantCulture); |
| | 48 | 233 | | metadata["retry_delay_milliseconds"] = diagnostics.BaseRetryDelay.TotalMilliseconds.ToString("0.###", CultureInf |
| | 48 | 234 | | metadata["max_retry_delay_milliseconds"] = diagnostics.MaxRetryDelay.TotalMilliseconds.ToString("0.###", Culture |
| | 48 | 235 | | metadata["last_retry_delay_milliseconds"] = diagnostics.LastRetryDelay.TotalMilliseconds.ToString("0.###", Cultu |
| | 48 | 236 | | metadata["total_retry_delay_milliseconds"] = diagnostics.TotalRetryDelay.TotalMilliseconds.ToString("0.###", Cul |
| | 48 | 237 | | metadata["retry_delay_count"] = diagnostics.RetryDelayCount.ToString(CultureInfo.InvariantCulture); |
| | 48 | 238 | | metadata["retry_backoff_strategy"] = ManagedKeyRetryBackoff.StrategyName; |
| | 48 | 239 | | metadata["retry_delay_configured"] = ToMetadataBoolean(diagnostics.BaseRetryDelay > TimeSpan.Zero); |
| | 48 | 240 | | metadata["retry_delay_applied"] = ToMetadataBoolean(diagnostics.RetryDelayCount > 0); |
| | 48 | 241 | | metadata["signature_algorithm"] = NormalizeRequired(options.SignatureAlgorithm, ManagedKeySigningOptions.Default |
| | | 242 | | |
| | 48 | 243 | | if (diagnostics.LastRetryFailureCode is not null) |
| | | 244 | | { |
| | 12 | 245 | | metadata["last_retry_failure_code"] = diagnostics.LastRetryFailureCode; |
| | | 246 | | } |
| | | 247 | | |
| | 48 | 248 | | if (diagnostics.LastRetryFailureExceptionType is not null) |
| | | 249 | | { |
| | 12 | 250 | | metadata["last_retry_failure_exception_type"] = diagnostics.LastRetryFailureExceptionType; |
| | | 251 | | } |
| | | 252 | | |
| | 48 | 253 | | if (diagnostics.FailureExceptionType is not null) |
| | | 254 | | { |
| | 14 | 255 | | metadata["failure_exception_type"] = diagnostics.FailureExceptionType; |
| | | 256 | | } |
| | | 257 | | |
| | 48 | 258 | | if (diagnostics.FailureRetryable is not null) |
| | | 259 | | { |
| | 14 | 260 | | metadata["failure_retryable"] = ToMetadataBoolean(diagnostics.FailureRetryable.Value); |
| | | 261 | | } |
| | | 262 | | |
| | 48 | 263 | | if (request.Purpose is not null) |
| | | 264 | | { |
| | 18 | 265 | | metadata["purpose"] = request.Purpose; |
| | | 266 | | } |
| | | 267 | | |
| | 48 | 268 | | return metadata; |
| | | 269 | | } |
| | | 270 | | |
| | | 271 | | private string? ValidateSigningRequest(SigningRequest request) |
| | | 272 | | { |
| | 54 | 273 | | if (!IsSupportedHashAlgorithm(request.HashAlgorithm)) |
| | | 274 | | { |
| | 4 | 275 | | return "managedkey.signing.hash-algorithm-unsupported"; |
| | | 276 | | } |
| | | 277 | | |
| | 50 | 278 | | string configuredKeyId = NormalizeRequired(options.KeyId, string.Empty); |
| | 50 | 279 | | if (request.KeyId is not null && !string.Equals(request.KeyId, configuredKeyId, StringComparison.Ordinal)) |
| | | 280 | | { |
| | 2 | 281 | | return "managedkey.signing.key-mismatch"; |
| | | 282 | | } |
| | | 283 | | |
| | 48 | 284 | | string? configuredKeyVersion = NormalizeOptional(options.KeyVersion); |
| | 48 | 285 | | return options.RequireKeyVersion && request.KeyVersion is null && configuredKeyVersion is null |
| | 48 | 286 | | ? "managedkey.signing.key-version-missing" |
| | 48 | 287 | | : request.KeyVersion is not null |
| | 48 | 288 | | && configuredKeyVersion is not null |
| | 48 | 289 | | && !string.Equals(request.KeyVersion, configuredKeyVersion, StringComparison.Ordinal) |
| | 48 | 290 | | ? "managedkey.signing.key-version-mismatch" |
| | 48 | 291 | | : null; |
| | | 292 | | } |
| | | 293 | | |
| | | 294 | | private string ResolveKeyId(SigningRequest request) |
| | | 295 | | { |
| | 82 | 296 | | return request.KeyId ?? NormalizeRequired(options.KeyId, string.Empty); |
| | | 297 | | } |
| | | 298 | | |
| | | 299 | | private string? ResolveKeyVersion(SigningRequest request) |
| | | 300 | | { |
| | 84 | 301 | | return request.KeyVersion ?? NormalizeOptional(options.KeyVersion); |
| | | 302 | | } |
| | | 303 | | |
| | | 304 | | private string NormalizeHashAlgorithm(string? hashAlgorithm) |
| | | 305 | | { |
| | 214 | 306 | | string normalized = string.IsNullOrWhiteSpace(hashAlgorithm) |
| | 214 | 307 | | ? options.HashAlgorithm |
| | 214 | 308 | | : hashAlgorithm.Trim(); |
| | | 309 | | |
| | 214 | 310 | | return normalized.Equals("SHA256", StringComparison.OrdinalIgnoreCase) |
| | 214 | 311 | | ? ManagedKeySigningOptions.DefaultHashAlgorithm |
| | 214 | 312 | | : normalized.Equals(ManagedKeySigningOptions.DefaultHashAlgorithm, StringComparison.OrdinalIgnoreCase) |
| | 214 | 313 | | ? ManagedKeySigningOptions.DefaultHashAlgorithm |
| | 214 | 314 | | : normalized; |
| | | 315 | | } |
| | | 316 | | |
| | | 317 | | private bool IsSupportedHashAlgorithm(string? hashAlgorithm) |
| | | 318 | | { |
| | 54 | 319 | | return NormalizeHashAlgorithm(hashAlgorithm).Equals( |
| | 54 | 320 | | NormalizeHashAlgorithm(options.HashAlgorithm), |
| | 54 | 321 | | StringComparison.OrdinalIgnoreCase); |
| | | 322 | | } |
| | | 323 | | |
| | | 324 | | private async ValueTask DelayForRetryAsync( |
| | | 325 | | int retryAttempt, |
| | | 326 | | ManagedKeySigningAttemptDiagnostics diagnostics, |
| | | 327 | | CancellationToken cancellationToken) |
| | | 328 | | { |
| | 16 | 329 | | TimeSpan delay = ManagedKeyRetryBackoff.CalculateDelay( |
| | 16 | 330 | | options.RetryDelay, |
| | 16 | 331 | | options.MaxRetryDelay, |
| | 16 | 332 | | retryAttempt, |
| | 16 | 333 | | jitterSource.NextDouble(), |
| | 16 | 334 | | diagnostics.LastRetryDelay); |
| | | 335 | | |
| | 16 | 336 | | if (delay <= TimeSpan.Zero) |
| | | 337 | | { |
| | 6 | 338 | | return; |
| | | 339 | | } |
| | | 340 | | |
| | 10 | 341 | | diagnostics.RecordRetryDelay(delay); |
| | 10 | 342 | | await retryDelay.DelayAsync(delay, cancellationToken).ConfigureAwait(false); |
| | 16 | 343 | | } |
| | | 344 | | |
| | | 345 | | private ManagedKeySigningAttemptDiagnostics CreateAttemptDiagnostics() |
| | | 346 | | { |
| | 54 | 347 | | return new ManagedKeySigningAttemptDiagnostics( |
| | 54 | 348 | | options.MaxRetryAttempts, |
| | 54 | 349 | | options.RetryDelay, |
| | 54 | 350 | | options.MaxRetryDelay); |
| | | 351 | | } |
| | | 352 | | |
| | | 353 | | private static bool IsSafeProviderMetadataKey(string key) |
| | | 354 | | { |
| | 12 | 355 | | return !string.IsNullOrWhiteSpace(key) |
| | 12 | 356 | | && !key.Contains("secret", StringComparison.OrdinalIgnoreCase) |
| | 12 | 357 | | && !key.Contains("token", StringComparison.OrdinalIgnoreCase) |
| | 12 | 358 | | && !key.Contains("credential", StringComparison.OrdinalIgnoreCase) |
| | 12 | 359 | | && !key.Contains("private", StringComparison.OrdinalIgnoreCase) |
| | 12 | 360 | | && !key.Contains("connection", StringComparison.OrdinalIgnoreCase); |
| | | 361 | | } |
| | | 362 | | |
| | | 363 | | private static bool IsReservedDiagnosticMetadataKey(string key) |
| | | 364 | | { |
| | 72 | 365 | | return ManagedKeyDiagnosticMetadataKeyClassifier.IsReserved(key); |
| | | 366 | | } |
| | | 367 | | |
| | | 368 | | private static string NormalizeRequired(string? value, string fallback) |
| | | 369 | | { |
| | 204 | 370 | | return string.IsNullOrWhiteSpace(value) ? fallback : value.Trim(); |
| | | 371 | | } |
| | | 372 | | |
| | | 373 | | private static string? NormalizeOptional(string? value) |
| | | 374 | | { |
| | 56 | 375 | | return string.IsNullOrWhiteSpace(value) ? null : value.Trim(); |
| | | 376 | | } |
| | | 377 | | |
| | | 378 | | private static string ToMetadataBoolean(bool value) |
| | | 379 | | { |
| | 110 | 380 | | return value ? "true" : "false"; |
| | | 381 | | } |
| | | 382 | | |
| | 54 | 383 | | private sealed class ManagedKeySigningAttemptDiagnostics( |
| | 54 | 384 | | int maxRetryAttempts, |
| | 54 | 385 | | TimeSpan baseRetryDelay, |
| | 54 | 386 | | TimeSpan maxRetryDelay) |
| | | 387 | | { |
| | 102 | 388 | | public int MaxRetryAttempts { get; } = maxRetryAttempts; |
| | | 389 | | |
| | 150 | 390 | | public TimeSpan BaseRetryDelay { get; } = baseRetryDelay; |
| | | 391 | | |
| | 102 | 392 | | public TimeSpan MaxRetryDelay { get; } = maxRetryDelay; |
| | | 393 | | |
| | 74 | 394 | | public TimeSpan LastRetryDelay { get; private set; } |
| | | 395 | | |
| | 68 | 396 | | public TimeSpan TotalRetryDelay { get; private set; } |
| | | 397 | | |
| | 116 | 398 | | public int RetryDelayCount { get; private set; } |
| | | 399 | | |
| | 36 | 400 | | public bool HasValidationFailure { get; private set; } |
| | | 401 | | |
| | 76 | 402 | | public string? LastRetryFailureCode { get; private set; } |
| | | 403 | | |
| | 76 | 404 | | public string? LastRetryFailureExceptionType { get; private set; } |
| | | 405 | | |
| | 80 | 406 | | public string? FailureExceptionType { get; private set; } |
| | | 407 | | |
| | 80 | 408 | | public bool? FailureRetryable { get; private set; } |
| | | 409 | | |
| | | 410 | | public void RecordValidationFailure() |
| | | 411 | | { |
| | 12 | 412 | | HasValidationFailure = true; |
| | 12 | 413 | | } |
| | | 414 | | |
| | | 415 | | public void RecordRetry(ManagedKeySigningException exception) |
| | | 416 | | { |
| | 16 | 417 | | LastRetryFailureCode = exception.FailureCode; |
| | 16 | 418 | | LastRetryFailureExceptionType = exception.GetType().Name; |
| | 16 | 419 | | } |
| | | 420 | | |
| | | 421 | | public void RecordRetryDelay(TimeSpan delay) |
| | | 422 | | { |
| | 10 | 423 | | LastRetryDelay = delay; |
| | 10 | 424 | | TotalRetryDelay += delay; |
| | 10 | 425 | | RetryDelayCount++; |
| | 10 | 426 | | } |
| | | 427 | | |
| | | 428 | | public void RecordFailure(Exception exception) |
| | | 429 | | { |
| | 18 | 430 | | FailureExceptionType = exception.GetType().Name; |
| | 18 | 431 | | FailureRetryable = exception is ManagedKeySigningException managedKeyException && managedKeyException.IsRetr |
| | 18 | 432 | | } |
| | | 433 | | } |
| | | 434 | | } |