mirror of
https://github.com/bitwarden/server.git
synced 2025-05-02 10:12:16 -05:00
[PM-19728] Add keys on devices list and get responses (#5633)
* Add keys on devices list and get responses * Mark retrieve device keys endpoint as deprecated
This commit is contained in:
parent
159e4fe502
commit
c195f83402
@ -128,6 +128,7 @@ public class DevicesController : Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("{identifier}/retrieve-keys")]
|
[HttpPost("{identifier}/retrieve-keys")]
|
||||||
|
[Obsolete("This endpoint is deprecated. The keys are on the regular device GET endpoints now.")]
|
||||||
public async Task<ProtectedDeviceResponseModel> GetDeviceKeys(string identifier)
|
public async Task<ProtectedDeviceResponseModel> GetDeviceKeys(string identifier)
|
||||||
{
|
{
|
||||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using Bit.Core.Entities;
|
using Bit.Core.Entities;
|
||||||
using Bit.Core.Enums;
|
using Bit.Core.Enums;
|
||||||
using Bit.Core.Models.Api;
|
using Bit.Core.Models.Api;
|
||||||
|
using Bit.Core.Utilities;
|
||||||
|
|
||||||
namespace Bit.Api.Models.Response;
|
namespace Bit.Api.Models.Response;
|
||||||
|
|
||||||
@ -21,6 +22,8 @@ public class DeviceResponseModel : ResponseModel
|
|||||||
Identifier = device.Identifier;
|
Identifier = device.Identifier;
|
||||||
CreationDate = device.CreationDate;
|
CreationDate = device.CreationDate;
|
||||||
IsTrusted = device.IsTrusted();
|
IsTrusted = device.IsTrusted();
|
||||||
|
EncryptedUserKey = device.EncryptedUserKey;
|
||||||
|
EncryptedPublicKey = device.EncryptedPublicKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
@ -29,4 +32,10 @@ public class DeviceResponseModel : ResponseModel
|
|||||||
public string Identifier { get; set; }
|
public string Identifier { get; set; }
|
||||||
public DateTime CreationDate { get; set; }
|
public DateTime CreationDate { get; set; }
|
||||||
public bool IsTrusted { get; set; }
|
public bool IsTrusted { get; set; }
|
||||||
|
[EncryptedString]
|
||||||
|
[EncryptedStringLength(2000)]
|
||||||
|
public string EncryptedUserKey { get; set; }
|
||||||
|
[EncryptedString]
|
||||||
|
[EncryptedStringLength(2000)]
|
||||||
|
public string EncryptedPublicKey { get; set; }
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using Bit.Core.Auth.Models.Data;
|
using Bit.Core.Auth.Models.Data;
|
||||||
using Bit.Core.Enums;
|
using Bit.Core.Enums;
|
||||||
using Bit.Core.Models.Api;
|
using Bit.Core.Models.Api;
|
||||||
|
using Bit.Core.Utilities;
|
||||||
|
|
||||||
namespace Bit.Core.Auth.Models.Api.Response;
|
namespace Bit.Core.Auth.Models.Api.Response;
|
||||||
|
|
||||||
@ -19,6 +20,8 @@ public class DeviceAuthRequestResponseModel : ResponseModel
|
|||||||
Identifier = deviceAuthDetails.Identifier,
|
Identifier = deviceAuthDetails.Identifier,
|
||||||
CreationDate = deviceAuthDetails.CreationDate,
|
CreationDate = deviceAuthDetails.CreationDate,
|
||||||
IsTrusted = deviceAuthDetails.IsTrusted,
|
IsTrusted = deviceAuthDetails.IsTrusted,
|
||||||
|
EncryptedPublicKey = deviceAuthDetails.EncryptedPublicKey,
|
||||||
|
EncryptedUserKey = deviceAuthDetails.EncryptedUserKey
|
||||||
};
|
};
|
||||||
|
|
||||||
if (deviceAuthDetails.AuthRequestId != null && deviceAuthDetails.AuthRequestCreatedAt != null)
|
if (deviceAuthDetails.AuthRequestId != null && deviceAuthDetails.AuthRequestCreatedAt != null)
|
||||||
@ -39,6 +42,12 @@ public class DeviceAuthRequestResponseModel : ResponseModel
|
|||||||
public string Identifier { get; set; }
|
public string Identifier { get; set; }
|
||||||
public DateTime CreationDate { get; set; }
|
public DateTime CreationDate { get; set; }
|
||||||
public bool IsTrusted { get; set; }
|
public bool IsTrusted { get; set; }
|
||||||
|
[EncryptedString]
|
||||||
|
[EncryptedStringLength(2000)]
|
||||||
|
public string EncryptedUserKey { get; set; }
|
||||||
|
[EncryptedString]
|
||||||
|
[EncryptedStringLength(2000)]
|
||||||
|
public string EncryptedPublicKey { get; set; }
|
||||||
|
|
||||||
public PendingAuthRequest DevicePendingAuthRequest { get; set; }
|
public PendingAuthRequest DevicePendingAuthRequest { get; set; }
|
||||||
|
|
||||||
|
@ -29,6 +29,8 @@ public class DeviceAuthDetails : Device
|
|||||||
Identifier = device.Identifier;
|
Identifier = device.Identifier;
|
||||||
CreationDate = device.CreationDate;
|
CreationDate = device.CreationDate;
|
||||||
IsTrusted = device.IsTrusted();
|
IsTrusted = device.IsTrusted();
|
||||||
|
EncryptedPublicKey = device.EncryptedPublicKey;
|
||||||
|
EncryptedUserKey = device.EncryptedUserKey;
|
||||||
AuthRequestId = authRequestId;
|
AuthRequestId = authRequestId;
|
||||||
AuthRequestCreatedAt = authRequestCreationDate;
|
AuthRequestCreatedAt = authRequestCreationDate;
|
||||||
}
|
}
|
||||||
@ -74,6 +76,8 @@ public class DeviceAuthDetails : Device
|
|||||||
EncryptedPrivateKey = encryptedPrivateKey,
|
EncryptedPrivateKey = encryptedPrivateKey,
|
||||||
Active = active
|
Active = active
|
||||||
}.IsTrusted();
|
}.IsTrusted();
|
||||||
|
EncryptedPublicKey = encryptedPublicKey;
|
||||||
|
EncryptedUserKey = encryptedUserKey;
|
||||||
AuthRequestId = authRequestId != Guid.Empty ? authRequestId : null;
|
AuthRequestId = authRequestId != Guid.Empty ? authRequestId : null;
|
||||||
AuthRequestCreatedAt =
|
AuthRequestCreatedAt =
|
||||||
authRequestCreationDate != DateTime.MinValue ? authRequestCreationDate : null;
|
authRequestCreationDate != DateTime.MinValue ? authRequestCreationDate : null;
|
||||||
|
@ -63,7 +63,9 @@ public class DevicesControllerTest
|
|||||||
UserId = userId,
|
UserId = userId,
|
||||||
Name = "chrome",
|
Name = "chrome",
|
||||||
Type = DeviceType.ChromeBrowser,
|
Type = DeviceType.ChromeBrowser,
|
||||||
Identifier = Guid.Parse("811E9254-F77C-48C8-AF0A-A181943F5708").ToString()
|
Identifier = Guid.Parse("811E9254-F77C-48C8-AF0A-A181943F5708").ToString(),
|
||||||
|
EncryptedPublicKey = "PublicKey",
|
||||||
|
EncryptedUserKey = "UserKey",
|
||||||
},
|
},
|
||||||
Guid.Parse("E09D6943-D574-49E5-AC85-C3F12B4E019E"),
|
Guid.Parse("E09D6943-D574-49E5-AC85-C3F12B4E019E"),
|
||||||
authDateTimeResponse)
|
authDateTimeResponse)
|
||||||
@ -78,6 +80,13 @@ public class DevicesControllerTest
|
|||||||
// Assert
|
// Assert
|
||||||
Assert.NotNull(result);
|
Assert.NotNull(result);
|
||||||
Assert.IsType<ListResponseModel<DeviceAuthRequestResponseModel>>(result);
|
Assert.IsType<ListResponseModel<DeviceAuthRequestResponseModel>>(result);
|
||||||
|
var resultDevice = result.Data.First();
|
||||||
|
Assert.Equal("chrome", resultDevice.Name);
|
||||||
|
Assert.Equal(DeviceType.ChromeBrowser, resultDevice.Type);
|
||||||
|
Assert.Equal(Guid.Parse("B3136B10-7818-444F-B05B-4D7A9B8C48BF"), resultDevice.Id);
|
||||||
|
Assert.Equal(Guid.Parse("811E9254-F77C-48C8-AF0A-A181943F5708").ToString(), resultDevice.Identifier);
|
||||||
|
Assert.Equal("PublicKey", resultDevice.EncryptedPublicKey);
|
||||||
|
Assert.Equal("UserKey", resultDevice.EncryptedUserKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user