|
| 1 | +namespace sigtran.net.Core.Utilities; |
| 2 | + |
| 3 | +/// <summary> |
| 4 | +/// Identifies security vulnerability severity. |
| 5 | +/// </summary> |
| 6 | +public enum SigtranSecuritySeverity |
| 7 | +{ |
| 8 | + /// <summary>Low severity.</summary> |
| 9 | + Low, |
| 10 | + |
| 11 | + /// <summary>Moderate severity.</summary> |
| 12 | + Moderate, |
| 13 | + |
| 14 | + /// <summary>High severity.</summary> |
| 15 | + High, |
| 16 | + |
| 17 | + /// <summary>Critical severity.</summary> |
| 18 | + Critical |
| 19 | +} |
| 20 | + |
| 21 | +/// <summary> |
| 22 | +/// Describes the SDK security response policy. |
| 23 | +/// </summary> |
| 24 | +public sealed class SigtranSecurityResponsePolicy |
| 25 | +{ |
| 26 | + /// <summary>Creates a security response policy.</summary> |
| 27 | + /// <param name="contact">The security contact.</param> |
| 28 | + /// <param name="criticalResponseTime">The critical issue response time.</param> |
| 29 | + /// <param name="highResponseTime">The high issue response time.</param> |
| 30 | + /// <param name="usesPrivateDisclosure">Whether private disclosure is required.</param> |
| 31 | + public SigtranSecurityResponsePolicy( |
| 32 | + string contact, |
| 33 | + TimeSpan criticalResponseTime, |
| 34 | + TimeSpan highResponseTime, |
| 35 | + bool usesPrivateDisclosure) |
| 36 | + { |
| 37 | + Contact = string.IsNullOrWhiteSpace(contact) ? throw new ArgumentException("Security contact is required.", nameof(contact)) : contact; |
| 38 | + CriticalResponseTime = criticalResponseTime <= TimeSpan.Zero ? throw new ArgumentOutOfRangeException(nameof(criticalResponseTime)) : criticalResponseTime; |
| 39 | + HighResponseTime = highResponseTime <= TimeSpan.Zero ? throw new ArgumentOutOfRangeException(nameof(highResponseTime)) : highResponseTime; |
| 40 | + UsesPrivateDisclosure = usesPrivateDisclosure; |
| 41 | + } |
| 42 | + |
| 43 | + /// <summary>The security contact.</summary> |
| 44 | + public string Contact { get; } |
| 45 | + |
| 46 | + /// <summary>The critical issue response time.</summary> |
| 47 | + public TimeSpan CriticalResponseTime { get; } |
| 48 | + |
| 49 | + /// <summary>The high issue response time.</summary> |
| 50 | + public TimeSpan HighResponseTime { get; } |
| 51 | + |
| 52 | + /// <summary>Whether private disclosure is required.</summary> |
| 53 | + public bool UsesPrivateDisclosure { get; } |
| 54 | + |
| 55 | + /// <summary>Returns the response time for a severity.</summary> |
| 56 | + /// <param name="severity">The vulnerability severity.</param> |
| 57 | + /// <returns>The response time.</returns> |
| 58 | + public TimeSpan GetResponseTime(SigtranSecuritySeverity severity) |
| 59 | + { |
| 60 | + return severity switch |
| 61 | + { |
| 62 | + SigtranSecuritySeverity.Critical => CriticalResponseTime, |
| 63 | + SigtranSecuritySeverity.High => HighResponseTime, |
| 64 | + _ => TimeSpan.FromDays(14) |
| 65 | + }; |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +/// <summary> |
| 70 | +/// Provides the SDK security policy. |
| 71 | +/// </summary> |
| 72 | +public static class SigtranSecurityPolicy |
| 73 | +{ |
| 74 | + /// <summary>Creates the current security response policy.</summary> |
| 75 | + /// <returns>The current security response policy.</returns> |
| 76 | + public static SigtranSecurityResponsePolicy CreateCurrentPolicy() |
| 77 | + { |
| 78 | + return new( |
| 79 | + "security@sigtran.net", |
| 80 | + TimeSpan.FromDays(2), |
| 81 | + TimeSpan.FromDays(7), |
| 82 | + usesPrivateDisclosure: true); |
| 83 | + } |
| 84 | +} |
0 commit comments