Skip to content
Permalink
Browse files

New endpoint protocol seems to be working :>

  • Loading branch information...
GlitchedPolygons committed Aug 7, 2019
1 parent 30b99dd commit c7ee38572f79378a78d52e2ca578f0dac8bac404
@@ -108,6 +108,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=OLED/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=parameterless/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=passwordbox/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=perma/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=PKCS/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=pkey/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=POCO/@EntryIndexedValue">True</s:Boolean>
@@ -19,6 +19,10 @@
using GlitchedPolygons.GlitchedEpistle.Client.Windows.PubSubEvents;
using GlitchedPolygons.GlitchedEpistle.Client.Windows.Views;
using GlitchedPolygons.RepositoryPattern;
using GlitchedPolygons.Services.CompressionUtility;
using GlitchedPolygons.Services.Cryptography.Asymmetric;

using Newtonsoft.Json;

using Prism.Events;

@@ -28,15 +32,15 @@ public class EditConvoMetadataViewModel : ViewModel, ICloseable
{
#region Constants
private readonly User user;
private readonly ICompressionUtility gzip;
private readonly IUserService userService;
private readonly IConvoService convoService;
private readonly IEventAggregator eventAggregator;
private readonly IAsymmetricCryptographyRSA crypto;
private readonly IConvoPasswordProvider convoPasswordProvider;
private readonly Timer messageTimer = new Timer(7000) { AutoReset = true };
#endregion

private readonly IRepository<Convo, string> convoProvider;

#region Events
public event EventHandler<EventArgs> RequestedClose;
#endregion
@@ -186,6 +190,8 @@ public Convo Convo
}
}

private readonly IRepository<Convo, string> convoProvider;

private void RefreshParticipantLists()
{
Participants = new ObservableCollection<string>();
@@ -209,9 +215,11 @@ private void RefreshParticipantLists()

private string oldPw, newPw, newPw2;

public EditConvoMetadataViewModel(IConvoService convoService, User user, IUserService userService, IEventAggregator eventAggregator, IConvoPasswordProvider convoPasswordProvider)
public EditConvoMetadataViewModel(IConvoService convoService, User user, IUserService userService, IEventAggregator eventAggregator, IConvoPasswordProvider convoPasswordProvider, IAsymmetricCryptographyRSA crypto, ICompressionUtility gzip)
{
this.user = user;
this.gzip = gzip;
this.crypto = crypto;
this.userService = userService;
this.convoService = convoService;
this.eventAggregator = eventAggregator;
@@ -299,7 +307,20 @@ private void OnLeave(object commandParam)
{
Task.Run(async () =>
{
bool success = await convoService.LeaveConvo(Convo.Id, Totp, user.Id, user.Token.Item2);
var dto = new ConvoLeaveRequestDto
{
ConvoId = Convo.Id,
Totp = Totp
};

var body = new EpistleRequestBody
{
UserId = user.Id,
Auth = user.Token.Item2,
Body = JsonConvert.SerializeObject(dto)
};

bool success = await convoService.LeaveConvo(body.Sign(crypto, user.PrivateKeyPem));

if (!success)
{
@@ -323,7 +344,7 @@ private void OnMakeAdmin(object commandParam)
{
if (oldPw.NullOrEmpty())
{
PrintMessage("Please authenticate your request by providing the current convo's password (at the bottom of the form).", true);
PrintMessage("Please authenticate your request by providing the current convo's password (at the top of the form).", true);
return;
}

@@ -336,8 +357,6 @@ private void OnMakeAdmin(object commandParam)
{
var dto = new ConvoChangeMetadataRequestDto
{
UserId = user.Id,
Auth = user.Token.Item2,
ConvoId = Convo.Id,
ConvoPasswordSHA512 = oldPw.SHA512(),
NewConvoPasswordSHA512 = null,
@@ -347,7 +366,14 @@ private void OnMakeAdmin(object commandParam)
CreatorId = newAdminUserId
};

bool success = await convoService.ChangeConvoMetadata(dto);
var body = new EpistleRequestBody
{
UserId = user.Id,
Auth = user.Token.Item2,
Body = gzip.Compress(JsonConvert.SerializeObject(dto))
};

bool success = await convoService.ChangeConvoMetadata(body.Sign(crypto, user.PrivateKeyPem));
if (!success)
{
PrintMessage("The convo admin change request was rejected server-side! Perhaps double-check the provided convo password?",true);
@@ -394,7 +420,22 @@ private void OnKickAndBanUser(object commandParam)
{
Task.Run(async () =>
{
bool success = await convoService.KickUser(Convo.Id, oldPw.SHA512(), user.Id, user.Token.Item2, userIdToKick, true);
var dto = new ConvoKickUserRequestDto
{
ConvoId = Convo.Id,
ConvoPasswordSHA512 = oldPw.SHA512(),
UserIdToKick = userIdToKick,
PermaBan = true
};

var body = new EpistleRequestBody
{
UserId = user.Id,
Auth = user.Token.Item2,
Body = gzip.Compress(JsonConvert.SerializeObject(dto))
};

bool success = await convoService.KickUser(body.Sign(crypto, user.PrivateKeyPem));
if (!success)
{
PrintMessage($"The user \"{userIdToKick}\" could not be kicked and banned from the convo. Perhaps double-check the provided convo password?", true);
@@ -408,6 +449,7 @@ private void OnKickAndBanUser(object commandParam)
{
convo.BannedUsers.Add(userIdToKick);
convo.Participants.Remove(userIdToKick);

await convoProvider.Update(convo);
}

@@ -438,7 +480,20 @@ private void OnDelete(object commandParam)
{
Task.Run(async () =>
{
bool success = await convoService.DeleteConvo(Convo.Id, Totp, user.Id, user.Token.Item2);
var dto = new ConvoDeletionRequestDto
{
ConvoId = Convo.Id,
Totp = Totp
};

var body = new EpistleRequestBody
{
UserId = user.Id,
Auth = user.Token.Item2,
Body = JsonConvert.SerializeObject(dto)
};

bool success = await convoService.DeleteConvo(body.Sign(crypto, user.PrivateKeyPem));
if (!success)
{
PrintMessage("The convo deletion request could not be fulfilled server-side; please double check the provided 2FA token and try again.", true);
@@ -505,8 +560,6 @@ private void OnSubmit(object commandParam)
{
ConvoId = Convo.Id,
ConvoPasswordSHA512 = oldPw.SHA512(),
UserId = user.Id,
Auth = user.Token.Item2
};

if (Name.NotNullNotEmpty() && Name != Convo.Name)
@@ -529,7 +582,14 @@ private void OnSubmit(object commandParam)
dto.NewConvoPasswordSHA512 = newPw.SHA512();
}

bool successful = await convoService.ChangeConvoMetadata(dto);
var body = new EpistleRequestBody
{
UserId = user.Id,
Auth = user.Token.Item2,
Body = gzip.Compress(JsonConvert.SerializeObject(dto))
};

bool successful = await convoService.ChangeConvoMetadata(body.Sign(crypto, user.PrivateKeyPem));

if (!successful)
{
@@ -11,6 +11,10 @@
using GlitchedPolygons.GlitchedEpistle.Client.Services.Web.Convos;
using GlitchedPolygons.GlitchedEpistle.Client.Windows.Commands;
using GlitchedPolygons.GlitchedEpistle.Client.Windows.PubSubEvents;
using GlitchedPolygons.Services.CompressionUtility;
using GlitchedPolygons.Services.Cryptography.Asymmetric;

using Newtonsoft.Json;

using Prism.Events;

@@ -23,8 +27,10 @@ public class JoinConvoDialogViewModel : ViewModel, ICloseable

// Injections:
private readonly User user;
private readonly ICompressionUtility gzip;
private readonly IConvoService convoService;
private readonly IConvoPasswordProvider convoPasswordProvider;
private readonly IAsymmetricCryptographyRSA crypto;
private readonly IEventAggregator eventAggregator;
#endregion

@@ -60,9 +66,11 @@ public bool UIEnabled
}
#endregion

public JoinConvoDialogViewModel(IConvoService convoService, IEventAggregator eventAggregator, User user, IConvoPasswordProvider convoPasswordProvider)
public JoinConvoDialogViewModel(IConvoService convoService, IEventAggregator eventAggregator, User user, IConvoPasswordProvider convoPasswordProvider, ICompressionUtility gzip, IAsymmetricCryptographyRSA crypto)
{
this.user = user;
this.gzip = gzip;
this.crypto = crypto;
this.convoService = convoService;
this.eventAggregator = eventAggregator;
this.convoPasswordProvider = convoPasswordProvider;
@@ -99,7 +107,20 @@ private void OnClickedJoinConvo(object commandParam)

Task.Run(async () =>
{
if (!await convoService.JoinConvo(ConvoId, passwordSHA512, user.Id, user.Token.Item2))
var dto = new ConvoJoinRequestDto
{
ConvoId = this.ConvoId,
ConvoPasswordSHA512 = passwordSHA512
};

var body = new EpistleRequestBody
{
UserId = user.Id,
Auth = user.Token.Item2,
Body = JsonConvert.SerializeObject(dto)
};

if (!await convoService.JoinConvo(body.Sign(crypto, user.PrivateKeyPem)))
{
convoPasswordProvider.RemovePasswordSHA512(ConvoId);

@@ -30,6 +30,8 @@
using GlitchedPolygons.GlitchedEpistle.Client.Windows.Commands;
using GlitchedPolygons.GlitchedEpistle.Client.Windows.Constants;
using GlitchedPolygons.GlitchedEpistle.Client.Windows.PubSubEvents;
using GlitchedPolygons.Services.CompressionUtility;
using GlitchedPolygons.Services.Cryptography.Asymmetric;

using Microsoft.Win32;

@@ -56,9 +58,11 @@ public class ActiveConvoViewModel : ViewModel, IDisposable
private readonly ILogger logger;
private readonly IMethodQ methodQ;
private readonly ISettings settings;
private readonly ICompressionUtility gzip;
private readonly IUserService userService;
private readonly IConvoService convoService;
private readonly IMessageCryptography crypto;
private readonly IAsymmetricCryptographyRSA rsa;
private readonly IEventAggregator eventAggregator;
private readonly IRepository<Convo, string> convoProvider;
private readonly IConvoPasswordProvider convoPasswordProvider;
@@ -148,10 +152,12 @@ public Convo ActiveConvo
IMessageCryptography crypto,
ISettings settings,
ILogger logger,
IConvoPasswordProvider convoPasswordProvider)
IConvoPasswordProvider convoPasswordProvider, ICompressionUtility gzip, IAsymmetricCryptographyRSA rsa)
{
#region Injections
this.rsa = rsa;
this.user = user;
this.gzip = gzip;
this.logger = logger;
this.crypto = crypto;
this.methodQ = methodQ;
@@ -493,14 +499,20 @@ private async Task<bool> SubmitMessage(JObject messageBodyJson)

var postParamsDto = new PostMessageParamsDto
{
UserId = user.Id,
SenderName = username,
Auth = user.Token.Item2,
ConvoId = ActiveConvo.Id,
ConvoPasswordSHA512 = convoPasswordProvider.GetPasswordSHA512(ActiveConvo.Id),
MessageBodiesJson = messageBodiesJson.ToString(Formatting.None)
};

bool success = await convoService.PostMessage(ActiveConvo.Id, postParamsDto);
var body = new EpistleRequestBody
{
UserId = user.Id,
Auth = user.Token.Item2,
Body = gzip.Compress(JsonConvert.SerializeObject(postParamsDto))
};

bool success = await convoService.PostMessage(body.Sign(rsa, user.PrivateKeyPem));
return success;
}

@@ -16,6 +16,9 @@
using GlitchedPolygons.GlitchedEpistle.Client.Windows.Services.Factories;
using GlitchedPolygons.GlitchedEpistle.Client.Windows.Views;
using GlitchedPolygons.RepositoryPattern;
using GlitchedPolygons.Services.Cryptography.Asymmetric;

using Newtonsoft.Json;

using Prism.Events;

@@ -30,11 +33,10 @@ public class ConvosListViewModel : ViewModel
private readonly IConvoService convoService;
private readonly IConvoPasswordProvider convoPasswordProvider;
private readonly IEventAggregator eventAggregator;
private readonly IAsymmetricCryptographyRSA crypto;
private readonly User user;
#endregion

private IRepository<Convo, string> convoProvider;

#region Commands
public ICommand OpenConvoCommand { get; }
public ICommand EditConvoCommand { get; }
@@ -57,11 +59,14 @@ public bool CanJoin
}
#endregion

public ConvosListViewModel(IEventAggregator eventAggregator, IWindowFactory windowFactory, IViewModelFactory viewModelFactory, IConvoPasswordProvider convoPasswordProvider, User user, IConvoService convoService)
private IRepository<Convo, string> convoProvider;

public ConvosListViewModel(IEventAggregator eventAggregator, IWindowFactory windowFactory, IViewModelFactory viewModelFactory, IConvoPasswordProvider convoPasswordProvider, User user, IConvoService convoService, IAsymmetricCryptographyRSA crypto)
{
#region Injections
this.user = user;
this.convoService = convoService;
this.crypto = crypto;
this.windowFactory = windowFactory;
this.eventAggregator = eventAggregator;
this.viewModelFactory = viewModelFactory;
@@ -108,7 +113,20 @@ private void OnClickedOnConvo(object commandParam)
{
Task.Run(async () =>
{
if (!await convoService.JoinConvo(_convo.Id, cachedPwSHA512, user.Id, user.Token.Item2))
var dto = new ConvoJoinRequestDto
{
ConvoId = _convo.Id,
ConvoPasswordSHA512 = cachedPwSHA512
};

var body = new EpistleRequestBody
{
UserId = user.Id,
Auth = user.Token.Item2,
Body = JsonConvert.SerializeObject(dto)
};

if (!await convoService.JoinConvo(body.Sign(crypto,user.PrivateKeyPem)))
{
convoPasswordProvider.RemovePasswordSHA512(_convo.Id);
Application.Current?.Dispatcher?.Invoke(() =>
@@ -160,11 +178,7 @@ private void OnClickedEditConvo(object commandParam)
var view = windowFactory.Create<EditConvoMetadataView>(true);
var viewModel = viewModelFactory.Create<EditConvoMetadataViewModel>();
viewModel.Convo = convo;

if (view.DataContext is null)
{
view.DataContext = viewModel;
}
view.DataContext = viewModel;

view.Show();
view.Focus();

0 comments on commit c7ee385

Please sign in to comment.
You can’t perform that action at this time.