mirror of
https://github.com/bitwarden/server.git
synced 2025-06-13 22:40:48 -05:00
Removed SignatureBytes since it had only one usage
This commit is contained in:
parent
6181d0961c
commit
a7715632e7
@ -1,6 +1,5 @@
|
|||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Security.Cryptography.X509Certificates;
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
using Bit.Core.Billing.Licenses.Attributes;
|
using Bit.Core.Billing.Licenses.Attributes;
|
||||||
using Bit.Core.Enums;
|
using Bit.Core.Enums;
|
||||||
|
|
||||||
@ -48,10 +47,6 @@ public abstract class BaseLicense : ILicense
|
|||||||
[LicenseIgnore]
|
[LicenseIgnore]
|
||||||
public string Token { get; set; }
|
public string Token { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
|
||||||
[LicenseIgnore]
|
|
||||||
public byte[] SignatureBytes => Convert.FromBase64String(Signature);
|
|
||||||
|
|
||||||
public abstract byte[] GetDataBytes(bool forHash = false);
|
public abstract byte[] GetDataBytes(bool forHash = false);
|
||||||
|
|
||||||
public byte[] ComputeHash()
|
public byte[] ComputeHash()
|
||||||
@ -66,7 +61,7 @@ public abstract class BaseLicense : ILicense
|
|||||||
{
|
{
|
||||||
using (var rsa = certificate.GetRSAPublicKey())
|
using (var rsa = certificate.GetRSAPublicKey())
|
||||||
{
|
{
|
||||||
return rsa.VerifyData(GetDataBytes(), SignatureBytes, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
|
return rsa.VerifyData(GetDataBytes(), Convert.FromBase64String(Signature), HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@ public interface ILicense
|
|||||||
string Hash { get; set; }
|
string Hash { get; set; }
|
||||||
string Signature { get; set; }
|
string Signature { get; set; }
|
||||||
string Token { get; set; }
|
string Token { get; set; }
|
||||||
byte[] SignatureBytes { get; }
|
|
||||||
byte[] GetDataBytes(bool forHash = false);
|
byte[] GetDataBytes(bool forHash = false);
|
||||||
byte[] ComputeHash();
|
byte[] ComputeHash();
|
||||||
bool VerifySignature(X509Certificate2 certificate);
|
bool VerifySignature(X509Certificate2 certificate);
|
||||||
|
@ -62,7 +62,7 @@ public class CloudGetOrganizationLicenseQueryTests
|
|||||||
Assert.Equal(LicenseType.Organization, result.LicenseType);
|
Assert.Equal(LicenseType.Organization, result.LicenseType);
|
||||||
Assert.Equal(organization.Id, result.Id);
|
Assert.Equal(organization.Id, result.Id);
|
||||||
Assert.Equal(installationId, result.InstallationId);
|
Assert.Equal(installationId, result.InstallationId);
|
||||||
Assert.Equal(licenseSignature, result.SignatureBytes);
|
Assert.Equal(licenseSignature, Convert.FromBase64String(result.Signature));
|
||||||
Assert.Equal(string.Empty, result.Token);
|
Assert.Equal(string.Empty, result.Token);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ public class CloudGetOrganizationLicenseQueryTests
|
|||||||
Assert.Equal(LicenseType.Organization, result.LicenseType);
|
Assert.Equal(LicenseType.Organization, result.LicenseType);
|
||||||
Assert.Equal(organization.Id, result.Id);
|
Assert.Equal(organization.Id, result.Id);
|
||||||
Assert.Equal(installationId, result.InstallationId);
|
Assert.Equal(installationId, result.InstallationId);
|
||||||
Assert.Equal(licenseSignature, result.SignatureBytes);
|
Assert.Equal(licenseSignature, Convert.FromBase64String(result.Signature));
|
||||||
Assert.Equal(DateTime.UtcNow.AddYears(1).Date, result.Expires!.Value.Date);
|
Assert.Equal(DateTime.UtcNow.AddYears(1).Date, result.Expires!.Value.Date);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,7 @@ public class UpdateOrganizationLicenseCommandTests
|
|||||||
license.Version = OrganizationLicense.CurrentLicenseFileVersion;
|
license.Version = OrganizationLicense.CurrentLicenseFileVersion;
|
||||||
license.InstallationId = globalSettings.Installation.Id;
|
license.InstallationId = globalSettings.Installation.Id;
|
||||||
license.LicenseType = LicenseType.Organization;
|
license.LicenseType = LicenseType.Organization;
|
||||||
|
license.SelfHost = true;
|
||||||
sutProvider.GetDependency<ILicensingService>().VerifyLicense(license).Returns(true);
|
sutProvider.GetDependency<ILicensingService>().VerifyLicense(license).Returns(true);
|
||||||
sutProvider.GetDependency<ILicensingService>()
|
sutProvider.GetDependency<ILicensingService>()
|
||||||
.GetClaimsPrincipalFromLicense(license)
|
.GetClaimsPrincipalFromLicense(license)
|
||||||
@ -74,7 +75,7 @@ public class UpdateOrganizationLicenseCommandTests
|
|||||||
await using var fs = File.OpenRead(filePath);
|
await using var fs = File.OpenRead(filePath);
|
||||||
var licenseFromFile = await JsonSerializer.DeserializeAsync<OrganizationLicense>(fs);
|
var licenseFromFile = await JsonSerializer.DeserializeAsync<OrganizationLicense>(fs);
|
||||||
|
|
||||||
AssertHelper.AssertPropertyEqual(license, licenseFromFile, "SignatureBytes");
|
AssertHelper.AssertPropertyEqual(license, licenseFromFile, "");
|
||||||
|
|
||||||
// Assertion: should have updated and saved the organization
|
// Assertion: should have updated and saved the organization
|
||||||
// Properties excluded from the comparison below are exceptions to the rule that the Organization mirrors
|
// Properties excluded from the comparison below are exceptions to the rule that the Organization mirrors
|
||||||
@ -84,7 +85,7 @@ public class UpdateOrganizationLicenseCommandTests
|
|||||||
.ReplaceAndUpdateCacheAsync(Arg.Is<Organization>(
|
.ReplaceAndUpdateCacheAsync(Arg.Is<Organization>(
|
||||||
org => AssertPropertyEqual(license, org,
|
org => AssertPropertyEqual(license, org,
|
||||||
"Id", "MaxStorageGb", "Issued", "Refresh", "Version", "Trial", "LicenseType",
|
"Id", "MaxStorageGb", "Issued", "Refresh", "Version", "Trial", "LicenseType",
|
||||||
"Hash", "Signature", "SignatureBytes", "InstallationId", "Expires",
|
"Hash", "Signature", "InstallationId", "Expires",
|
||||||
"ExpirationWithoutGracePeriod", "Token", "LimitCollectionCreationDeletion",
|
"ExpirationWithoutGracePeriod", "Token", "LimitCollectionCreationDeletion",
|
||||||
"LimitCollectionCreation", "LimitCollectionDeletion", "AllowAdminAccessToAllCollectionItems",
|
"LimitCollectionCreation", "LimitCollectionDeletion", "AllowAdminAccessToAllCollectionItems",
|
||||||
"UseOrganizationDomains", "UseAdminSponsoredFamilies") &&
|
"UseOrganizationDomains", "UseAdminSponsoredFamilies") &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user