1
0
mirror of https://github.com/bitwarden/server.git synced 2025-02-09 00:41:37 +01:00

implement useapi and apikey

This commit is contained in:
Kyle Spearrin 2019-03-02 15:09:33 -05:00
parent 66729fec3f
commit 15cb0ad4c3
11 changed files with 39 additions and 8 deletions

View File

@ -33,6 +33,7 @@ namespace Bit.Admin.Models
UseEvents = org.UseEvents; UseEvents = org.UseEvents;
UseTotp = org.UseTotp; UseTotp = org.UseTotp;
Use2fa = org.Use2fa; Use2fa = org.Use2fa;
UseApi = org.UseApi;
SelfHost = org.SelfHost; SelfHost = org.SelfHost;
UsersGetPremium = org.UsersGetPremium; UsersGetPremium = org.UsersGetPremium;
MaxStorageGb = org.MaxStorageGb; MaxStorageGb = org.MaxStorageGb;
@ -76,6 +77,8 @@ namespace Bit.Admin.Models
public bool UseTotp { get; set; } public bool UseTotp { get; set; }
[Display(Name = "2FA")] [Display(Name = "2FA")]
public bool Use2fa { get; set; } public bool Use2fa { get; set; }
[Display(Name = "API")]
public bool UseApi{ get; set; }
[Display(Name = "Self Host")] [Display(Name = "Self Host")]
public bool SelfHost { get; set; } public bool SelfHost { get; set; }
[Display(Name = "Users Get Premium")] [Display(Name = "Users Get Premium")]
@ -109,6 +112,7 @@ namespace Bit.Admin.Models
existingOrganization.UseEvents = UseEvents; existingOrganization.UseEvents = UseEvents;
existingOrganization.UseTotp = UseTotp; existingOrganization.UseTotp = UseTotp;
existingOrganization.Use2fa = Use2fa; existingOrganization.Use2fa = Use2fa;
existingOrganization.UseApi = UseApi;
existingOrganization.SelfHost = SelfHost; existingOrganization.SelfHost = SelfHost;
existingOrganization.UsersGetPremium = UsersGetPremium; existingOrganization.UsersGetPremium = UsersGetPremium;
existingOrganization.MaxStorageGb = MaxStorageGb; existingOrganization.MaxStorageGb = MaxStorageGb;

View File

@ -27,6 +27,7 @@
document.getElementById('@(nameof(Model.UsersGetPremium))').checked = true; document.getElementById('@(nameof(Model.UsersGetPremium))').checked = true;
document.getElementById('@(nameof(Model.UseTotp))').checked = true; document.getElementById('@(nameof(Model.UseTotp))').checked = true;
document.getElementById('@(nameof(Model.Use2fa))').checked = true; document.getElementById('@(nameof(Model.Use2fa))').checked = true;
document.getElementById('@(nameof(Model.UseApi))').checked = true;
document.getElementById('@(nameof(Model.SelfHost))').checked = true; document.getElementById('@(nameof(Model.SelfHost))').checked = true;
// Licensing // Licensing
document.getElementById('@(nameof(Model.LicenseKey))').value = '@Model.RandomLicenseKey'; document.getElementById('@(nameof(Model.LicenseKey))').value = '@Model.RandomLicenseKey';
@ -151,6 +152,10 @@
<input type="checkbox" class="form-check-input" asp-for="Use2fa"> <input type="checkbox" class="form-check-input" asp-for="Use2fa">
<label class="form-check-label" asp-for="Use2fa"></label> <label class="form-check-label" asp-for="Use2fa"></label>
</div> </div>
<div class="form-check">
<input type="checkbox" class="form-check-input" asp-for="UseApi">
<label class="form-check-label" asp-for="UseApi"></label>
</div>
<div class="form-check"> <div class="form-check">
<input type="checkbox" class="form-check-input" asp-for="UseGroups"> <input type="checkbox" class="form-check-input" asp-for="UseGroups">
<label class="form-check-label" asp-for="UseGroups"></label> <label class="form-check-label" asp-for="UseGroups"></label>

View File

@ -87,11 +87,11 @@ namespace Bit.Core.IdentityServer
{ {
ClientId = $"organization.{org.Id}", ClientId = $"organization.{org.Id}",
RequireClientSecret = true, RequireClientSecret = true,
ClientSecrets = { new Secret("secret".Sha256()) }, // TODO: org.ApiKey ClientSecrets = { new Secret(org.ApiKey.Sha256()) },
AllowedScopes = new string[] { "api.organization" }, AllowedScopes = new string[] { "api.organization" },
AllowedGrantTypes = GrantTypes.ClientCredentials, AllowedGrantTypes = GrantTypes.ClientCredentials,
AccessTokenLifetime = 3600 * 1, AccessTokenLifetime = 3600 * 1,
Enabled = org.Enabled, // TODO: && org.UseApi Enabled = org.Enabled && org.UseApi,
Claims = new List<Claim> { new Claim(JwtClaimTypes.Subject, org.Id.ToString()) } Claims = new List<Claim> { new Claim(JwtClaimTypes.Subject, org.Id.ToString()) }
}; };
} }

View File

@ -35,6 +35,7 @@ namespace Bit.Core.Models.Api
UseEvents = organization.UseEvents; UseEvents = organization.UseEvents;
UseTotp = organization.UseTotp; UseTotp = organization.UseTotp;
Use2fa = organization.Use2fa; Use2fa = organization.Use2fa;
UseApi = organization.UseApi;
UsersGetPremium = organization.UsersGetPremium; UsersGetPremium = organization.UsersGetPremium;
SelfHost = organization.SelfHost; SelfHost = organization.SelfHost;
} }
@ -58,6 +59,7 @@ namespace Bit.Core.Models.Api
public bool UseEvents { get; set; } public bool UseEvents { get; set; }
public bool UseTotp { get; set; } public bool UseTotp { get; set; }
public bool Use2fa { get; set; } public bool Use2fa { get; set; }
public bool UseApi { get; set; }
public bool UsersGetPremium { get; set; } public bool UsersGetPremium { get; set; }
public bool SelfHost { get; set; } public bool SelfHost { get; set; }
} }

View File

@ -15,6 +15,7 @@ namespace Bit.Core.Models.Api
UseEvents = organization.UseEvents; UseEvents = organization.UseEvents;
UseTotp = organization.UseTotp; UseTotp = organization.UseTotp;
Use2fa = organization.Use2fa; Use2fa = organization.Use2fa;
UseApi = organization.UseApi;
UsersGetPremium = organization.UsersGetPremium; UsersGetPremium = organization.UsersGetPremium;
SelfHost = organization.SelfHost; SelfHost = organization.SelfHost;
Seats = organization.Seats; Seats = organization.Seats;
@ -33,6 +34,7 @@ namespace Bit.Core.Models.Api
public bool UseEvents { get; set; } public bool UseEvents { get; set; }
public bool UseTotp { get; set; } public bool UseTotp { get; set; }
public bool Use2fa { get; set; } public bool Use2fa { get; set; }
public bool UseApi { get; set; }
public bool UsersGetPremium { get; set; } public bool UsersGetPremium { get; set; }
public bool SelfHost { get; set; } public bool SelfHost { get; set; }
public int Seats { get; set; } public int Seats { get; set; }

View File

@ -19,7 +19,7 @@ namespace Bit.Core.Models.Business
public OrganizationLicense(Organization org, SubscriptionInfo subscriptionInfo, Guid installationId, public OrganizationLicense(Organization org, SubscriptionInfo subscriptionInfo, Guid installationId,
ILicensingService licenseService) ILicensingService licenseService)
{ {
Version = 4; Version = 4; // TODO: Version 5 bump
LicenseKey = org.LicenseKey; LicenseKey = org.LicenseKey;
InstallationId = installationId; InstallationId = installationId;
Id = org.Id; Id = org.Id;
@ -36,6 +36,7 @@ namespace Bit.Core.Models.Business
UseDirectory = org.UseDirectory; UseDirectory = org.UseDirectory;
UseTotp = org.UseTotp; UseTotp = org.UseTotp;
Use2fa = org.Use2fa; Use2fa = org.Use2fa;
UseApi = org.UseApi;
MaxStorageGb = org.MaxStorageGb; MaxStorageGb = org.MaxStorageGb;
SelfHost = org.SelfHost; SelfHost = org.SelfHost;
UsersGetPremium = org.UsersGetPremium; UsersGetPremium = org.UsersGetPremium;
@ -102,6 +103,7 @@ namespace Bit.Core.Models.Business
public bool UseDirectory { get; set; } public bool UseDirectory { get; set; }
public bool UseTotp { get; set; } public bool UseTotp { get; set; }
public bool Use2fa { get; set; } public bool Use2fa { get; set; }
public bool UseApi { get; set; }
public short? MaxStorageGb { get; set; } public short? MaxStorageGb { get; set; }
public bool SelfHost { get; set; } public bool SelfHost { get; set; }
public bool UsersGetPremium { get; set; } public bool UsersGetPremium { get; set; }
@ -118,7 +120,7 @@ namespace Bit.Core.Models.Business
public byte[] GetDataBytes(bool forHash = false) public byte[] GetDataBytes(bool forHash = false)
{ {
string data = null; string data = null;
if(Version >= 1 && Version <= 4) if(Version >= 1 && Version <= 5)
{ {
var props = typeof(OrganizationLicense) var props = typeof(OrganizationLicense)
.GetProperties(BindingFlags.Public | BindingFlags.Instance) .GetProperties(BindingFlags.Public | BindingFlags.Instance)
@ -131,6 +133,8 @@ namespace Bit.Core.Models.Business
(Version >= 3 || !p.Name.Equals(nameof(UseEvents))) && (Version >= 3 || !p.Name.Equals(nameof(UseEvents))) &&
// Use2fa was added in Version 4 // Use2fa was added in Version 4
(Version >= 4 || !p.Name.Equals(nameof(Use2fa))) && (Version >= 4 || !p.Name.Equals(nameof(Use2fa))) &&
// UseApi was added in Version 5
(Version >= 5 || !p.Name.Equals(nameof(UseApi))) &&
( (
!forHash || !forHash ||
( (
@ -167,7 +171,7 @@ namespace Bit.Core.Models.Business
return false; return false;
} }
if(Version >= 1 && Version <= 4) if(Version >= 1 && Version <= 5)
{ {
return InstallationId == globalSettings.Installation.Id && SelfHost; return InstallationId == globalSettings.Installation.Id && SelfHost;
} }
@ -184,7 +188,7 @@ namespace Bit.Core.Models.Business
return false; return false;
} }
if(Version >= 1 && Version <= 4) if(Version >= 1 && Version <= 5)
{ {
var valid = var valid =
globalSettings.Installation.Id == InstallationId && globalSettings.Installation.Id == InstallationId &&
@ -214,6 +218,11 @@ namespace Bit.Core.Models.Business
valid = organization.Use2fa == Use2fa; valid = organization.Use2fa == Use2fa;
} }
if(valid && Version >= 5)
{
valid = organization.UseApi == UseApi;
}
return valid; return valid;
} }
else else

View File

@ -12,6 +12,7 @@ namespace Bit.Core.Models.Data
public bool UseEvents { get; set; } public bool UseEvents { get; set; }
public bool UseTotp { get; set; } public bool UseTotp { get; set; }
public bool Use2fa { get; set; } public bool Use2fa { get; set; }
public bool UseApi{ get; set; }
public bool SelfHost { get; set; } public bool SelfHost { get; set; }
public bool UsersGetPremium { get; set; } public bool UsersGetPremium { get; set; }
public int Seats { get; set; } public int Seats { get; set; }

View File

@ -19,6 +19,7 @@ namespace Bit.Core.Models.StaticStore
public bool UseEvents { get; set; } public bool UseEvents { get; set; }
public bool UseTotp { get; set; } public bool UseTotp { get; set; }
public bool Use2fa { get; set; } public bool Use2fa { get; set; }
public bool UseApi { get; set; }
public short? MaxStorageGb { get; set; } public short? MaxStorageGb { get; set; }
public decimal BasePrice { get; set; } public decimal BasePrice { get; set; }
public decimal SeatPrice { get; set; } public decimal SeatPrice { get; set; }

View File

@ -1,8 +1,6 @@
using System; using System;
using Bit.Core.Utilities; using Bit.Core.Utilities;
using Bit.Core.Enums; using Bit.Core.Enums;
using Bit.Core.Services;
using Bit.Core.Exceptions;
using System.Collections.Generic; using System.Collections.Generic;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Linq; using System.Linq;
@ -31,6 +29,7 @@ namespace Bit.Core.Models.Table
public bool UseEvents { get; set; } public bool UseEvents { get; set; }
public bool UseTotp { get; set; } public bool UseTotp { get; set; }
public bool Use2fa { get; set; } public bool Use2fa { get; set; }
public bool UseApi { get; set; }
public bool SelfHost { get; set; } public bool SelfHost { get; set; }
public bool UsersGetPremium { get; set; } public bool UsersGetPremium { get; set; }
public long? Storage { get; set; } public long? Storage { get; set; }
@ -40,6 +39,7 @@ namespace Bit.Core.Models.Table
public string GatewaySubscriptionId { get; set; } public string GatewaySubscriptionId { get; set; }
public bool Enabled { get; set; } = true; public bool Enabled { get; set; } = true;
public string LicenseKey { get; set; } public string LicenseKey { get; set; }
public string ApiKey { get; set; }
public string TwoFactorProviders { get; set; } public string TwoFactorProviders { get; set; }
public DateTime? ExpirationDate { get; set; } public DateTime? ExpirationDate { get; set; }
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow; public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;

View File

@ -513,12 +513,14 @@ namespace Bit.Core.Services
UseDirectory = plan.UseDirectory, UseDirectory = plan.UseDirectory,
UseTotp = plan.UseTotp, UseTotp = plan.UseTotp,
Use2fa = plan.Use2fa, Use2fa = plan.Use2fa,
UseApi = plan.UseApi,
SelfHost = plan.SelfHost, SelfHost = plan.SelfHost,
UsersGetPremium = plan.UsersGetPremium || signup.PremiumAccessAddon, UsersGetPremium = plan.UsersGetPremium || signup.PremiumAccessAddon,
Plan = plan.Name, Plan = plan.Name,
Gateway = null, Gateway = null,
Enabled = true, Enabled = true,
LicenseKey = CoreHelpers.SecureRandomString(20), LicenseKey = CoreHelpers.SecureRandomString(20),
ApiKey = CoreHelpers.SecureRandomString(30),
CreationDate = DateTime.UtcNow, CreationDate = DateTime.UtcNow,
RevisionDate = DateTime.UtcNow RevisionDate = DateTime.UtcNow
}; };
@ -582,6 +584,7 @@ namespace Bit.Core.Services
UseEvents = license.UseEvents, UseEvents = license.UseEvents,
UseTotp = license.UseTotp, UseTotp = license.UseTotp,
Use2fa = license.Use2fa, Use2fa = license.Use2fa,
UseApi = license.UseApi,
Plan = license.Plan, Plan = license.Plan,
SelfHost = license.SelfHost, SelfHost = license.SelfHost,
UsersGetPremium = license.UsersGetPremium, UsersGetPremium = license.UsersGetPremium,
@ -591,6 +594,7 @@ namespace Bit.Core.Services
Enabled = license.Enabled, Enabled = license.Enabled,
ExpirationDate = license.Expires, ExpirationDate = license.Expires,
LicenseKey = license.LicenseKey, LicenseKey = license.LicenseKey,
ApiKey = CoreHelpers.SecureRandomString(30),
CreationDate = DateTime.UtcNow, CreationDate = DateTime.UtcNow,
RevisionDate = DateTime.UtcNow RevisionDate = DateTime.UtcNow
}; };
@ -740,6 +744,7 @@ namespace Bit.Core.Services
organization.UseEvents = license.UseEvents; organization.UseEvents = license.UseEvents;
organization.UseTotp = license.UseTotp; organization.UseTotp = license.UseTotp;
organization.Use2fa = license.Use2fa; organization.Use2fa = license.Use2fa;
organization.UseApi = license.UseApi;
organization.SelfHost = license.SelfHost; organization.SelfHost = license.SelfHost;
organization.UsersGetPremium = license.UsersGetPremium; organization.UsersGetPremium = license.UsersGetPremium;
organization.Plan = license.Plan; organization.Plan = license.Plan;

View File

@ -169,6 +169,7 @@ namespace Bit.Core.Utilities
UseEvents = true, UseEvents = true,
UseTotp = true, UseTotp = true,
Use2fa = true, Use2fa = true,
UseApi = true,
MaxStorageGb = 1, MaxStorageGb = 1,
SelfHost = true, SelfHost = true,
UsersGetPremium = true UsersGetPremium = true
@ -191,6 +192,7 @@ namespace Bit.Core.Utilities
UseEvents = true, UseEvents = true,
UseTotp = true, UseTotp = true,
Use2fa = true, Use2fa = true,
UseApi = true,
MaxStorageGb = 1, MaxStorageGb = 1,
SelfHost = true, SelfHost = true,
UsersGetPremium = true UsersGetPremium = true