diff --git a/src/Core/Entities/Collection.cs b/src/Core/Entities/Collection.cs index fb7225fc20..8babe10e4c 100644 --- a/src/Core/Entities/Collection.cs +++ b/src/Core/Entities/Collection.cs @@ -1,15 +1,17 @@ using System.ComponentModel.DataAnnotations; using Bit.Core.Utilities; +#nullable enable + namespace Bit.Core.Entities; public class Collection : ITableObject { public Guid Id { get; set; } public Guid OrganizationId { get; set; } - public string Name { get; set; } + public string Name { get; set; } = null!; [MaxLength(300)] - public string ExternalId { get; set; } + public string? ExternalId { get; set; } public DateTime CreationDate { get; set; } = DateTime.UtcNow; public DateTime RevisionDate { get; set; } = DateTime.UtcNow; diff --git a/src/Core/Entities/CollectionCipher.cs b/src/Core/Entities/CollectionCipher.cs index d212ced514..d69a82f37d 100644 --- a/src/Core/Entities/CollectionCipher.cs +++ b/src/Core/Entities/CollectionCipher.cs @@ -1,5 +1,7 @@ namespace Bit.Core.Entities; +#nullable enable + public class CollectionCipher { public Guid CollectionId { get; set; } diff --git a/src/Core/Entities/CollectionGroup.cs b/src/Core/Entities/CollectionGroup.cs index 05b38c0064..f7561f18ed 100644 --- a/src/Core/Entities/CollectionGroup.cs +++ b/src/Core/Entities/CollectionGroup.cs @@ -1,5 +1,7 @@ namespace Bit.Core.Entities; +#nullable enable + public class CollectionGroup { public Guid CollectionId { get; set; } diff --git a/src/Core/Entities/CollectionUser.cs b/src/Core/Entities/CollectionUser.cs index de1a079d9c..6e1a111a67 100644 --- a/src/Core/Entities/CollectionUser.cs +++ b/src/Core/Entities/CollectionUser.cs @@ -1,5 +1,7 @@ namespace Bit.Core.Entities; +#nullable enable + public class CollectionUser { public Guid CollectionId { get; set; } diff --git a/src/Core/Entities/Device.cs b/src/Core/Entities/Device.cs index 0f9b9f8a75..44929fa2db 100644 --- a/src/Core/Entities/Device.cs +++ b/src/Core/Entities/Device.cs @@ -1,6 +1,8 @@ using System.ComponentModel.DataAnnotations; using Bit.Core.Utilities; +#nullable enable + namespace Bit.Core.Entities; public class Device : ITableObject @@ -8,12 +10,12 @@ public class Device : ITableObject public Guid Id { get; set; } public Guid UserId { get; set; } [MaxLength(50)] - public string Name { get; set; } + public string Name { get; set; } = null!; public Enums.DeviceType Type { get; set; } [MaxLength(50)] - public string Identifier { get; set; } + public string Identifier { get; set; } = null!; [MaxLength(255)] - public string PushToken { get; set; } + public string? PushToken { get; set; } public DateTime CreationDate { get; internal set; } = DateTime.UtcNow; public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow; @@ -21,20 +23,20 @@ public class Device : ITableObject /// Intended to be the users symmetric key that is encrypted in some form, the current way to encrypt this is with /// the devices public key. /// - public string EncryptedUserKey { get; set; } + public string? EncryptedUserKey { get; set; } /// /// Intended to be the public key that was generated for a device upon trust and encrypted. Currenly encrypted using /// a users symmetric key so that when trusted and unlocked a user can decrypt the public key for all their devices. /// This enabled a user to rotate the keys for all of their devices. /// - public string EncryptedPublicKey { get; set; } + public string? EncryptedPublicKey { get; set; } /// /// Intended to be the private key that was generated for a device upon trust and encrypted. Currenly encrypted with /// the devices key, that upon successful login a user can decrypt this value and therefor decrypt their vault. /// - public string EncryptedPrivateKey { get; set; } + public string? EncryptedPrivateKey { get; set; } public void SetNewId() diff --git a/src/Core/Entities/Event.cs b/src/Core/Entities/Event.cs index e666c76f76..2a6b6664c2 100644 --- a/src/Core/Entities/Event.cs +++ b/src/Core/Entities/Event.cs @@ -3,6 +3,8 @@ using Bit.Core.Enums; using Bit.Core.Models.Data; using Bit.Core.Utilities; +#nullable enable + namespace Bit.Core.Entities; public class Event : ITableObject, IEvent @@ -49,10 +51,10 @@ public class Event : ITableObject, IEvent public Guid? ProviderOrganizationId { get; set; } public DeviceType? DeviceType { get; set; } [MaxLength(50)] - public string IpAddress { get; set; } + public string? IpAddress { get; set; } public Guid? ActingUserId { get; set; } public EventSystemUser? SystemUser { get; set; } - public string DomainName { get; set; } + public string? DomainName { get; set; } public Guid? SecretId { get; set; } public Guid? ServiceAccountId { get; set; } diff --git a/src/Core/Entities/Folder.cs b/src/Core/Entities/Folder.cs index 37a1d3c692..378044725b 100644 --- a/src/Core/Entities/Folder.cs +++ b/src/Core/Entities/Folder.cs @@ -1,13 +1,15 @@ using Bit.Core.Entities; using Bit.Core.Utilities; +#nullable enable + namespace Bit.Core.Vault.Entities; public class Folder : ITableObject { public Guid Id { get; set; } public Guid UserId { get; set; } - public string Name { get; set; } + public string? Name { get; set; } public DateTime CreationDate { get; internal set; } = DateTime.UtcNow; public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow; diff --git a/src/Core/Entities/IRevisable.cs b/src/Core/Entities/IRevisable.cs index bba3b3c94f..b9fb4b1144 100644 --- a/src/Core/Entities/IRevisable.cs +++ b/src/Core/Entities/IRevisable.cs @@ -1,5 +1,7 @@ namespace Bit.Core.Entities; +#nullable enable + public interface IRevisable { DateTime CreationDate { get; } diff --git a/src/Core/Entities/IStorable.cs b/src/Core/Entities/IStorable.cs index fd0da49fea..06fa920883 100644 --- a/src/Core/Entities/IStorable.cs +++ b/src/Core/Entities/IStorable.cs @@ -1,5 +1,7 @@ namespace Bit.Core.Entities; +#nullable enable + public interface IStorable { long? Storage { get; set; } diff --git a/src/Core/Entities/IStorableSubscriber.cs b/src/Core/Entities/IStorableSubscriber.cs index 27fcb25f6c..b3e24cc058 100644 --- a/src/Core/Entities/IStorableSubscriber.cs +++ b/src/Core/Entities/IStorableSubscriber.cs @@ -1,4 +1,6 @@ namespace Bit.Core.Entities; +#nullable enable + public interface IStorableSubscriber : IStorable, ISubscriber { } diff --git a/src/Core/Entities/ITableObject.cs b/src/Core/Entities/ITableObject.cs index 1f54b8cc17..e4e50d928c 100644 --- a/src/Core/Entities/ITableObject.cs +++ b/src/Core/Entities/ITableObject.cs @@ -1,5 +1,7 @@ namespace Bit.Core.Entities; +#nullable enable + public interface ITableObject where T : IEquatable { T Id { get; set; } diff --git a/src/Core/Entities/Installation.cs b/src/Core/Entities/Installation.cs index a91ecef2e7..ff30236d3d 100644 --- a/src/Core/Entities/Installation.cs +++ b/src/Core/Entities/Installation.cs @@ -1,15 +1,17 @@ using System.ComponentModel.DataAnnotations; using Bit.Core.Utilities; +#nullable enable + namespace Bit.Core.Entities; public class Installation : ITableObject { public Guid Id { get; set; } [MaxLength(256)] - public string Email { get; set; } + public string Email { get; set; } = null!; [MaxLength(150)] - public string Key { get; set; } + public string Key { get; set; } = null!; public bool Enabled { get; set; } public DateTime CreationDate { get; internal set; } = DateTime.UtcNow; diff --git a/src/Core/Entities/OrganizationApiKey.cs b/src/Core/Entities/OrganizationApiKey.cs index af9f3c9122..0fe56f123b 100644 --- a/src/Core/Entities/OrganizationApiKey.cs +++ b/src/Core/Entities/OrganizationApiKey.cs @@ -2,6 +2,8 @@ using Bit.Core.Enums; using Bit.Core.Utilities; +#nullable enable + namespace Bit.Core.Entities; public class OrganizationApiKey : ITableObject @@ -10,7 +12,7 @@ public class OrganizationApiKey : ITableObject public Guid OrganizationId { get; set; } public OrganizationApiKeyType Type { get; set; } [MaxLength(30)] - public string ApiKey { get; set; } + public string ApiKey { get; set; } = null!; public DateTime RevisionDate { get; set; } public void SetNewId() diff --git a/src/Core/Entities/OrganizationConnection.cs b/src/Core/Entities/OrganizationConnection.cs index 5b466fb4a6..ff4e6ef553 100644 --- a/src/Core/Entities/OrganizationConnection.cs +++ b/src/Core/Entities/OrganizationConnection.cs @@ -1,13 +1,17 @@ -using System.Text.Json; +using System.Diagnostics.CodeAnalysis; +using System.Text.Json; using Bit.Core.Enums; using Bit.Core.Models.OrganizationConnectionConfigs; using Bit.Core.Utilities; +#nullable enable + namespace Bit.Core.Entities; public class OrganizationConnection : OrganizationConnection where T : IConnectionConfig { - public new T Config + [DisallowNull] + public new T? Config { get => base.GetConfig(); set => base.SetConfig(value); @@ -20,17 +24,22 @@ public class OrganizationConnection : ITableObject public OrganizationConnectionType Type { get; set; } public Guid OrganizationId { get; set; } public bool Enabled { get; set; } - public string Config { get; set; } + public string? Config { get; set; } public void SetNewId() { Id = CoreHelpers.GenerateComb(); } - public T GetConfig() where T : IConnectionConfig + public T? GetConfig() where T : IConnectionConfig { try { + if (Config is null) + { + return default; + } + return JsonSerializer.Deserialize(Config); } catch (JsonException) diff --git a/src/Core/Entities/OrganizationDomain.cs b/src/Core/Entities/OrganizationDomain.cs index d275d075b2..adbf705105 100644 --- a/src/Core/Entities/OrganizationDomain.cs +++ b/src/Core/Entities/OrganizationDomain.cs @@ -1,15 +1,17 @@ using System.ComponentModel.DataAnnotations; using Bit.Core.Utilities; +#nullable enable + namespace Bit.Core.Entities; public class OrganizationDomain : ITableObject { public Guid Id { get; set; } public Guid OrganizationId { get; set; } - public string Txt { get; set; } + public string Txt { get; set; } = null!; [MaxLength(255)] - public string DomainName { get; set; } + public string DomainName { get; set; } = null!; public DateTime CreationDate { get; set; } = DateTime.UtcNow; public DateTime? VerifiedDate { get; private set; } public DateTime NextRunDate { get; private set; } diff --git a/src/Core/Entities/OrganizationSponsorship.cs b/src/Core/Entities/OrganizationSponsorship.cs index 8d747bd623..77c77eab21 100644 --- a/src/Core/Entities/OrganizationSponsorship.cs +++ b/src/Core/Entities/OrganizationSponsorship.cs @@ -2,6 +2,8 @@ using Bit.Core.Enums; using Bit.Core.Utilities; +#nullable enable + namespace Bit.Core.Entities; public class OrganizationSponsorship : ITableObject @@ -11,9 +13,9 @@ public class OrganizationSponsorship : ITableObject public Guid SponsoringOrganizationUserId { get; set; } public Guid? SponsoredOrganizationId { get; set; } [MaxLength(256)] - public string FriendlyName { get; set; } + public string? FriendlyName { get; set; } [MaxLength(256)] - public string OfferedToEmail { get; set; } + public string? OfferedToEmail { get; set; } public PlanSponsorshipType? PlanSponsorshipType { get; set; } public DateTime? LastSyncDate { get; set; } public DateTime? ValidUntil { get; set; } diff --git a/src/Core/Entities/Role.cs b/src/Core/Entities/Role.cs index 5e1f6319c2..b171652383 100644 --- a/src/Core/Entities/Role.cs +++ b/src/Core/Entities/Role.cs @@ -1,9 +1,11 @@ namespace Bit.Core.Entities; +#nullable enable + /// /// This class is not used. It is implemented to make the Identity provider happy. /// public class Role { - public string Name { get; set; } + public string Name { get; set; } = null!; } diff --git a/src/Core/Entities/TaxRate.cs b/src/Core/Entities/TaxRate.cs index a04ccf445c..bf6406694d 100644 --- a/src/Core/Entities/TaxRate.cs +++ b/src/Core/Entities/TaxRate.cs @@ -1,17 +1,19 @@ using System.ComponentModel.DataAnnotations; +#nullable enable + namespace Bit.Core.Entities; public class TaxRate : ITableObject { [MaxLength(40)] - public string Id { get; set; } + public string Id { get; set; } = null!; [MaxLength(50)] - public string Country { get; set; } + public string Country { get; set; } = null!; [MaxLength(2)] - public string State { get; set; } + public string? State { get; set; } [MaxLength(10)] - public string PostalCode { get; set; } + public string PostalCode { get; set; } = null!; public decimal Rate { get; set; } public bool Active { get; set; } diff --git a/src/Core/Entities/Transaction.cs b/src/Core/Entities/Transaction.cs index 73f42bf97d..db51a31614 100644 --- a/src/Core/Entities/Transaction.cs +++ b/src/Core/Entities/Transaction.cs @@ -2,6 +2,8 @@ using Bit.Core.Enums; using Bit.Core.Utilities; +#nullable enable + namespace Bit.Core.Entities; public class Transaction : ITableObject @@ -14,11 +16,11 @@ public class Transaction : ITableObject public bool? Refunded { get; set; } public decimal? RefundedAmount { get; set; } [MaxLength(100)] - public string Details { get; set; } + public string? Details { get; set; } public PaymentMethodType? PaymentMethodType { get; set; } public GatewayType? Gateway { get; set; } [MaxLength(50)] - public string GatewayId { get; set; } + public string? GatewayId { get; set; } public DateTime CreationDate { get; set; } = DateTime.UtcNow; public Guid? ProviderId { get; set; } diff --git a/src/Core/Entities/User.cs b/src/Core/Entities/User.cs index bf13ff2a7d..0e538b9014 100644 --- a/src/Core/Entities/User.cs +++ b/src/Core/Entities/User.cs @@ -7,37 +7,39 @@ using Bit.Core.Tools.Entities; using Bit.Core.Utilities; using Microsoft.AspNetCore.Identity; +#nullable enable + namespace Bit.Core.Entities; public class User : ITableObject, IStorableSubscriber, IRevisable, ITwoFactorProvidersUser, IReferenceable { - private Dictionary _twoFactorProviders; + private Dictionary? _twoFactorProviders; public Guid Id { get; set; } [MaxLength(50)] - public string Name { get; set; } + public string? Name { get; set; } [Required] [MaxLength(256)] - public string Email { get; set; } + public string Email { get; set; } = null!; public bool EmailVerified { get; set; } [MaxLength(300)] - public string MasterPassword { get; set; } + public string? MasterPassword { get; set; } [MaxLength(50)] - public string MasterPasswordHint { get; set; } + public string? MasterPasswordHint { get; set; } [MaxLength(10)] public string Culture { get; set; } = "en-US"; [Required] [MaxLength(50)] - public string SecurityStamp { get; set; } - public string TwoFactorProviders { get; set; } + public string SecurityStamp { get; set; } = null!; + public string? TwoFactorProviders { get; set; } [MaxLength(32)] - public string TwoFactorRecoveryCode { get; set; } - public string EquivalentDomains { get; set; } - public string ExcludedGlobalEquivalentDomains { get; set; } + public string? TwoFactorRecoveryCode { get; set; } + public string? EquivalentDomains { get; set; } + public string? ExcludedGlobalEquivalentDomains { get; set; } public DateTime AccountRevisionDate { get; set; } = DateTime.UtcNow; - public string Key { get; set; } - public string PublicKey { get; set; } - public string PrivateKey { get; set; } + public string? Key { get; set; } + public string? PublicKey { get; set; } + public string? PrivateKey { get; set; } public bool Premium { get; set; } public DateTime? PremiumExpirationDate { get; set; } public DateTime? RenewalReminderDate { get; set; } @@ -45,15 +47,15 @@ public class User : ITableObject, IStorableSubscriber, IRevisable, ITwoFac public short? MaxStorageGb { get; set; } public GatewayType? Gateway { get; set; } [MaxLength(50)] - public string GatewayCustomerId { get; set; } + public string? GatewayCustomerId { get; set; } [MaxLength(50)] - public string GatewaySubscriptionId { get; set; } - public string ReferenceData { get; set; } + public string? GatewaySubscriptionId { get; set; } + public string? ReferenceData { get; set; } [MaxLength(100)] - public string LicenseKey { get; set; } + public string? LicenseKey { get; set; } [Required] [MaxLength(30)] - public string ApiKey { get; set; } + public string ApiKey { get; set; } = null!; public KdfType Kdf { get; set; } = KdfType.PBKDF2_SHA256; public int KdfIterations { get; set; } = AuthConstants.PBKDF2_ITERATIONS.Default; public int? KdfMemory { get; set; } @@ -65,7 +67,7 @@ public class User : ITableObject, IStorableSubscriber, IRevisable, ITwoFac public int FailedLoginCount { get; set; } public DateTime? LastFailedLoginDate { get; set; } [MaxLength(7)] - public string AvatarColor { get; set; } + public string? AvatarColor { get; set; } public DateTime? LastPasswordChangeDate { get; set; } public DateTime? LastKdfChangeDate { get; set; } public DateTime? LastKeyRotationDate { get; set; } @@ -76,12 +78,12 @@ public class User : ITableObject, IStorableSubscriber, IRevisable, ITwoFac Id = CoreHelpers.GenerateComb(); } - public string BillingEmailAddress() + public string? BillingEmailAddress() { return Email?.ToLowerInvariant()?.Trim(); } - public string BillingName() + public string? BillingName() { return Name; } @@ -125,7 +127,7 @@ public class User : ITableObject, IStorableSubscriber, IRevisable, ITwoFac public bool IsExpired() => PremiumExpirationDate.HasValue && PremiumExpirationDate.Value <= DateTime.UtcNow; - public Dictionary GetTwoFactorProviders() + public Dictionary? GetTwoFactorProviders() { if (string.IsNullOrWhiteSpace(TwoFactorProviders)) { @@ -178,7 +180,7 @@ public class User : ITableObject, IStorableSubscriber, IRevisable, ITwoFac SetTwoFactorProviders(new Dictionary()); } - public TwoFactorProvider GetTwoFactorProvider(TwoFactorProviderType provider) + public TwoFactorProvider? GetTwoFactorProvider(TwoFactorProviderType provider) { var providers = GetTwoFactorProviders(); if (providers == null || !providers.ContainsKey(provider))