public void AssignsLegalIdentity_FromArgs_WhenSet() { LegalIdentity legalIdentityArgs = new LegalIdentity { Properties = new[] { new Property(Constants.XmppProperties.JId, "42") } }; ViewIdentityNavigationArgs args = new ViewIdentityNavigationArgs(legalIdentityArgs, null); this.navigationService.Setup(x => x.TryPopArgs(out args)).Returns(true); this.tagProfile.SetupGet(x => x.LegalIdentity).Returns(new LegalIdentity { Id = Guid.NewGuid().ToString() }); Given(AViewModel) .And(async vm => await vm.Bind()) .ThenAssert(vm => ReferenceEquals(legalIdentityArgs, vm.LegalIdentity)); }
public void ClearPin_WhenNotComplete_DecrementsStep() { TagProfile tagProfile = new TagProfile(); Assert.AreEqual(RegistrationStep.Operator, tagProfile.Step); tagProfile.SetDomain("domain"); Assert.AreEqual(RegistrationStep.Account, tagProfile.Step); tagProfile.SetAccount("account", "hash", "hashMethod"); Assert.AreEqual(RegistrationStep.RegisterIdentity, tagProfile.Step); LegalIdentity identity = new LegalIdentity { State = IdentityState.Approved }; tagProfile.SetLegalIdentity(identity); Assert.AreEqual(RegistrationStep.ValidateIdentity, tagProfile.Step); tagProfile.SetIsValidated(); Assert.AreEqual(RegistrationStep.Pin, tagProfile.Step); tagProfile.ClearPin(); Assert.AreEqual(RegistrationStep.ValidateIdentity, tagProfile.Step); }
/// <summary> /// TAG Signature request scanned. /// </summary> /// <param name="request">Request string.</param> public async Task TagSignature(string request) { int i = request.IndexOf(','); if (i < 0) { throw new InvalidOperationException("Invalid TAG Signature URI."); } string JID = request.Substring(0, i); string Key = request.Substring(i + 1); LegalIdentity ID = this.tagProfile?.LegalIdentity; if (ID is null) { throw new InvalidOperationException("No Legal ID selected."); } if (ID.State != IdentityState.Approved) { throw new InvalidOperationException("Legal ID not approved."); } string IdRef = this.tagProfile?.LegalIdentity?.Id ?? string.Empty; StringBuilder Xml = new StringBuilder(); Xml.Append("<ql xmlns='https://tagroot.io/schema/Signature' key='"); Xml.Append(XML.Encode(Key)); Xml.Append("' legalId='"); Xml.Append(XML.Encode(IdRef)); Xml.Append("'/>"); if (!this.neuronService.IsOnline) { throw new InvalidOperationException("App is not connected to the network."); } await this.neuronService.Xmpp.IqSetAsync(JID, Xml.ToString()); }
public void ClearIsValidated_DecrementsStep() { TagProfile tagProfile = new TagProfile(); Assert.AreEqual(RegistrationStep.Operator, tagProfile.Step); tagProfile.SetDomain("domain"); Assert.AreEqual(RegistrationStep.Account, tagProfile.Step); tagProfile.SetAccount("account", "hash", "hashMethod"); tagProfile.SetLegalJId("jid"); Assert.AreEqual(RegistrationStep.RegisterIdentity, tagProfile.Step); LegalIdentity identity = new LegalIdentity { State = IdentityState.Approved }; tagProfile.SetLegalIdentity(identity); Assert.AreEqual(RegistrationStep.ValidateIdentity, tagProfile.Step); tagProfile.ClearIsValidated(); Assert.AreEqual(RegistrationStep.RegisterIdentity, tagProfile.Step); Assert.IsNull(tagProfile.LegalIdentity); Assert.AreEqual("jid", tagProfile.LegalJid); }
public void LegalIdentityChanged(LegalIdentity Identity) { this.OnPropertyChanged("Created"); this.OnPropertyChanged("Updated"); this.OnPropertyChanged("LegalId"); this.OnPropertyChanged("BareJid"); this.OnPropertyChanged("State"); this.OnPropertyChanged("From"); this.OnPropertyChanged("To"); this.OnPropertyChanged("FirstName"); this.OnPropertyChanged("MiddleNames"); this.OnPropertyChanged("LastNames"); this.OnPropertyChanged("PNr"); this.OnPropertyChanged("Address"); this.OnPropertyChanged("Address2"); this.OnPropertyChanged("PostalCode"); this.OnPropertyChanged("Area"); this.OnPropertyChanged("City"); this.OnPropertyChanged("Region"); this.OnPropertyChanged("Country"); this.OnPropertyChanged("IsApproved"); }
private RegisterIdentityViewModel CreateViewModelForRegister(bool photoUploadSucceeds) { SKBitmap bitmap = new SKBitmap(300, 300); string path = Path.Combine(Path.GetTempPath(), Folder); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } this.fullPath = Path.Combine(path, File); using (var data = bitmap.Encode(SKEncodedImageFormat.Jpeg, 100)) { byte[] bytes = data.ToArray(); using (FileStream fs = System.IO.File.OpenWrite(fullPath)) { fs.Write(bytes); } } this.neuronService.SetupGet(x => x.IsOnline).Returns(true); Guid guid = Guid.NewGuid(); // Upload attachment this.identity = new LegalIdentity { Id = guid.ToString(), State = IdentityState.Approved }; this.networkService.Setup(x => x.TryRequest(It.IsAny <Func <Task <LegalIdentity> > >(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <string>())) .Returns(Task.FromResult((photoUploadSucceeds, this.identity))); // Short circuit the begin invoke calls, so they're executed synchronously. this.dispatcher.Setup(x => x.BeginInvokeOnMainThread(It.IsAny <Action>())).Callback <Action>(x => x()); this.tagProfile.SetupGet(x => x.HttpFileUploadMaxSize).Returns(short.MaxValue); this.tagProfile.SetupGet(x => x.LegalJid).Returns(Guid.NewGuid().ToString); this.tagProfile.SetupGet(x => x.RegistryJid).Returns(Guid.NewGuid().ToString); this.tagProfile.SetupGet(x => x.ProvisioningJid).Returns(Guid.NewGuid().ToString); return(AViewModel()); }
public void SetLegalIdentity_ToAnInvalidValue_DoesNotIncrementStep() { TagProfile tagProfile = new TagProfile(); Assert.AreEqual(RegistrationStep.Operator, tagProfile.Step); tagProfile.SetDomain("domain"); Assert.AreEqual(RegistrationStep.Account, tagProfile.Step); tagProfile.SetAccount("account", "hash", "hashMethod"); Assert.AreEqual(RegistrationStep.RegisterIdentity, tagProfile.Step); LegalIdentity identity = new LegalIdentity { State = IdentityState.Compromised }; tagProfile.SetLegalIdentity(identity); Assert.AreEqual(RegistrationStep.RegisterIdentity, tagProfile.Step); identity.State = IdentityState.Obsoleted; tagProfile.SetLegalIdentity(identity); Assert.AreEqual(RegistrationStep.RegisterIdentity, tagProfile.Step); identity.State = IdentityState.Rejected; tagProfile.SetLegalIdentity(identity); Assert.AreEqual(RegistrationStep.RegisterIdentity, tagProfile.Step); }
public void IdentityProperties_AreCopied_WhenMovingBackward_WithAnExistingAccount() { LegalIdentity legalIdentity = new LegalIdentity { State = IdentityState.Approved }; Property[] properties = { new Property(Constants.XmppProperties.FirstName, "John"), new Property(Constants.XmppProperties.LastName, "Doe"), new Property(Constants.XmppProperties.City, "Town") }; legalIdentity.Properties = properties; this.tagProfile.SetupGet(x => x.LegalIdentity).Returns(legalIdentity); this.tagProfile.SetupGet(x => x.Step).Returns(RegistrationStep.ValidateIdentity); Given(AViewModel) .And(async vm => await vm.Bind()) .ThenAssert(vm => { // Pre-condition RegisterIdentityViewModel rvm = (RegisterIdentityViewModel)vm.RegistrationSteps[(int)RegistrationStep.RegisterIdentity]; return(rvm.FirstName is null && rvm.LastNames is null && rvm.City is null); }) .When(vm => { vm.GoToPrevCommand.Execute(); }) .ThenAssert(vm => { // Post-condition, verify properties have been copied from LegalIdentity to VM. RegisterIdentityViewModel rvm = (RegisterIdentityViewModel)vm.RegistrationSteps[(int)RegistrationStep.RegisterIdentity]; return(rvm.FirstName == "John" && rvm.LastNames == "Doe" && rvm.City == "Town"); }) .Finally(async vm => await vm.Unbind()); }
public IdentityPage(XmppConfiguration XmppConfiguration, Page Owner, LegalIdentity Identity) : this(XmppConfiguration, Owner, Identity, XmppConfiguration.LegalIdentity.Id == Identity.Id) { }
/// <summary> /// Creates an instance of a <see cref="LegalIdentityChangedEventArgs"/>. /// </summary> /// <param name="identity">The changed identity.</param> public LegalIdentityChangedEventArgs(LegalIdentity identity) { Identity = identity; }
/// <summary> /// Creates a new instance of the <see cref="ClientSignatureNavigationArgs"/> class. /// </summary> /// <param name="signature">The signature to display.</param> /// <param name="identity">The legal identity to display.</param> public ClientSignatureNavigationArgs(ClientSignature signature, LegalIdentity identity) { this.Signature = signature; this.Identity = identity; }
public IdentityPage(XmppConfiguration XmppConfiguration, Page Owner, LegalIdentity Identity, SignaturePetitionEventArgs Review) : this(XmppConfiguration, Owner, Identity, XmppConfiguration.LegalIdentity.Id == Identity.Id, Review) { }
/// <summary> /// Returns <c>true</c> if the <see cref="LegalIdentity"/> is in either of the two states <c>Created</c> or <c>Approved</c>. /// </summary> /// <param name="legalIdentity">The legal identity whose state to check.</param> /// <returns></returns> public static bool IsCreatedOrApproved(this LegalIdentity legalIdentity) { return(!(legalIdentity is null) && (legalIdentity.State == IdentityState.Created || legalIdentity.State == IdentityState.Approved)); }
public static async Task ShowPage() { if (configuration.Step >= 2) { await UpdateXmpp(); if (configuration.Step > 2 && ( configuration.LegalIdentity is null || configuration.LegalIdentity.State == IdentityState.Compromised || configuration.LegalIdentity.State == IdentityState.Obsoleted || configuration.LegalIdentity.State == IdentityState.Rejected)) { configuration.Step = 2; await Database.Update(configuration); } if (configuration.Step > 4 && configuration.UsePin && string.IsNullOrEmpty(configuration.PinHash)) { configuration.Step = 4; await Database.Update(configuration); } } Page Page; switch (configuration.Step) { case 0: Page = new OperatorPage(configuration); break; case 1: Page = new AccountPage(configuration); break; case 2: if (configuration.LegalIdentity is null || configuration.LegalIdentity.State == IdentityState.Compromised || configuration.LegalIdentity.State == IdentityState.Obsoleted || configuration.LegalIdentity.State == IdentityState.Rejected) { DateTime Now = DateTime.Now; LegalIdentity Created = null; LegalIdentity Approved = null; bool Changed = false; if (await CheckServices()) { foreach (LegalIdentity Identity in await App.Contracts.GetLegalIdentitiesAsync()) { if (Identity.HasClientSignature && Identity.HasClientPublicKey && Identity.From <= Now && Identity.To >= Now && (Identity.State == IdentityState.Approved || Identity.State == IdentityState.Created) && Identity.ValidateClientSignature()) { if (Identity.State == IdentityState.Approved) { Approved = Identity; break; } else if (Created is null) { Created = Identity; } } } if (!(Approved is null)) { configuration.LegalIdentity = Approved; Changed = true; } else if (!(Created is null)) { configuration.LegalIdentity = Created; Changed = true; } if (Changed) { configuration.Step++; await Database.Update(configuration); Page = new Connection.IdentityPage(configuration); break; } } } Page = new RegisterIdentityPage(configuration); break;
private async Task <bool> ConnectToAccount() { try { string password = Password; (string hostName, int portNumber, bool isIpAddress) = await this.networkService.LookupXmppHostnameAndPort(this.TagProfile.Domain); async Task OnConnected(XmppClient client) { this.PasswordHash = client.PasswordHash; this.PasswordHashMethod = client.PasswordHashMethod; DateTime now = DateTime.Now; LegalIdentity createdIdentity = null; LegalIdentity approvedIdentity = null; bool serviceDiscoverySucceeded; if (this.TagProfile.NeedsUpdating()) { serviceDiscoverySucceeded = await this.NeuronService.DiscoverServices(client); } else { serviceDiscoverySucceeded = true; } if (serviceDiscoverySucceeded) { foreach (LegalIdentity identity in await this.NeuronService.Contracts.GetLegalIdentities(client)) { if (identity.HasClientSignature && identity.HasClientPublicKey && identity.From <= now && identity.To >= now && (identity.State == IdentityState.Approved || identity.State == IdentityState.Created) && identity.ValidateClientSignature()) { if (identity.State == IdentityState.Approved) { approvedIdentity = identity; break; } if (createdIdentity is null) { createdIdentity = identity; } } } if (!(approvedIdentity is null)) { this.LegalIdentity = approvedIdentity; } else if (!(createdIdentity is null)) { this.LegalIdentity = createdIdentity; } if (!(this.LegalIdentity is null)) { this.TagProfile.SetAccountAndLegalIdentity(this.ConnectToExistingAccountName, client.PasswordHash, client.PasswordHashMethod, this.LegalIdentity); } else { this.TagProfile.SetAccount(this.ConnectToExistingAccountName, client.PasswordHash, client.PasswordHashMethod); } }
/// <summary> /// Creates a new instance of the <see cref="ViewIdentityNavigationArgs"/> class. /// </summary> /// <param name="identity">The identity.</param> /// <param name="identityToReview">An identity to review, or <c>null</c>.</param> public ViewIdentityNavigationArgs(LegalIdentity identity, SignaturePetitionEventArgs identityToReview) { this.Identity = identity; this.IdentityToReview = identityToReview; }
public bool?ValidateSignature(LegalIdentity legalIdentity, byte[] data, byte[] signature) { AssertContractsIsAvailable(); return(contractsClient.ValidateSignature(legalIdentity, data, signature)); }
public Task PetitionPeerReviewId(string legalId, LegalIdentity identity, string petitionId, string purpose) { AssertContractsIsAvailable(); return(contractsClient.PetitionPeerReviewIDAsync(legalId, identity, petitionId, purpose)); }
public Task <LegalIdentity> AddPeerReviewIdAttachment(LegalIdentity identity, LegalIdentity reviewerLegalIdentity, byte[] peerSignature) { AssertContractsIsAvailable(); return(contractsClient.AddPeerReviewIDAttachment(identity, reviewerLegalIdentity, peerSignature)); }