public void AddNewContact_RemotelyInitiated(string aliasID, string remotelyInitiatedIke1InvitationStr) { var localDrpPeer = UserRegistrationIDs.Select(x => x.LocalDrpPeer).FirstOrDefault(); if (localDrpPeer == null) { throw new InvalidOperationException("no local DRP peers found to send INVITE with contact invitation"); } this.User.LocalUserCertificate.AssertHasPrivateKey(); this.User.LocalUserCertificate.AssertIsValidNow(_userAppEngine.Engine.CryptoLibrary, User.UserID, _userAppEngine.Engine.DateTimeNowUtc); var unconfirmedContactId = _unconfirmedContactIdCounter--; var remotelyInitiatedIke1Invitation = Ike1Invitation.DecodeFromUI(remotelyInitiatedIke1InvitationStr); var newContact = new Contact() { UnconfirmedContactId = unconfirmedContactId, UnconfirmedContactOwnerLocalUserId = User.Id, RemotelyInitiatedIke1Invitation = remotelyInitiatedIke1Invitation, UserAliasID = aliasID }; Contacts.Add(unconfirmedContactId, newContact); localDrpPeer.BeginIke1(User.LocalUserCertificate, new Ike1Data { UserId = User.UserID, RegistrationIds = UserRegistrationIDs.Select(x => x.RegistrationId).ToArray() }, remotelyInitiatedIke1Invitation, TimeSpan.FromMinutes(10), (exc, remoteIke1Data) => { if (exc != null) { _userAppEngine.HandleException("IKE1 failed: ", exc); return; } newContact.User = new User { OwnerLocalUserId = this.User.Id, AliasID = newContact.UserAliasID, UserID = remoteIke1Data.UserId, Metadata = new UserMetadata { ContactCreatedAtUTC = _userAppEngine.Engine.DateTimeNowUtc, ContactCreatedWithRemoteEndpoint = remoteIke1Data.RemoteEndPoint } }; newContact.RegistrationIDs = remoteIke1Data.RegistrationIds.Select(x => new UserRegistrationID { RegistrationId = x }).ToList(); _userAppEngine.ConfirmContact(newContact); // insert new records into database Contacts.Remove(newContact.UnconfirmedContactId.Value); Contacts.Add(newContact.User.Id, newContact); }); }
} // is set by UI public void AddNewContact_LocallyInitiatedInvitation(string aliasID, string locallyInitiatedIke1Invitation) { if (String.IsNullOrEmpty(locallyInitiatedIke1Invitation)) { throw new ArgumentNullException(nameof(locallyInitiatedIke1Invitation)); } this.User.LocalUserCertificate.AssertHasPrivateKey(); this.User.LocalUserCertificate.AssertIsValidNow(_userAppEngine.Engine.CryptoLibrary, User.UserID, _userAppEngine.Engine.DateTimeNowUtc); var unconfirmedContactId = _unconfirmedContactIdCounter--; var locallyInitiatedInvitation = Ike1Invitation.DecodeFromUI(locallyInitiatedIke1Invitation); Contacts.Add(unconfirmedContactId, new Contact() { UnconfirmedContactId = unconfirmedContactId, UnconfirmedContactOwnerLocalUserId = User.Id, LocallyInitiatedIke1Invitation = locallyInitiatedInvitation, UserAliasID = aliasID }); // next we wait for INVITE with specific ContactInvitationToken }