public List <SecuerShareData> ShareItem(string receiver, string message, SecureItem secureItem, int expirationPeriodIndex, bool passwordVisibleToRecipient, DateTime?expirationDate) { Share share = new Share() { Receiver = receiver, Message = message, Visible = passwordVisibleToRecipient, ExpirationDate = expirationDate ?? DateTime.Now.AddYears(50).ToUniversalTime() }; Share shareItem = new Share(); logger.Info("Start ShareItem"); try { bool isShareAllowed = true; bool isShareTresholdReached = pbData.IsShareTresholdReached(false, true); IFeatureChecker featureChecker = resolver.GetInstanceOf <IFeatureChecker>(); isShareAllowed = featureChecker.IsEnabled(DefaultProperties.Features_ShareCenter_UnlimitedShares, showUIIfNotEnabled: false); if (!isShareAllowed) { isShareAllowed = featureChecker.IsEnabled(DefaultProperties.Features_ShareCenter_UpTo5Shares, showUIIfNotEnabled: false) && !isShareTresholdReached; } if (!isShareAllowed) { featureChecker.FireActionNotEnabledUI(); return(new List <SecuerShareData>()); } //validate emails List <string> receiverList = new List <string>(); share.Receiver = share.Receiver.Replace(" ", String.Empty); if (share.Receiver.Contains(',')) { receiverList.AddRange(share.Receiver.Replace(" ", String.Empty).Split(',')); } if (share.Receiver.Contains(';')) { receiverList.AddRange(share.Receiver.Replace(" ", String.Empty).Split(';')); } if (receiverList.Count == 0) { receiverList.Add(share.Receiver); } Common cm = new Common(); //Changed List <Share> shareList = pbData.GetShares(true, false, null, null); List <string> alreadyShared = shareList.Select(x => x.Receiver).ToList <string>(); foreach (var rec in receiverList) { if (!cm.IsEmailValid(rec)) { continue; } if (rec == pbData.ActiveUser) { continue; } if (alreadyShared.Contains(rec)) { continue; } else { alreadyShared.Add(rec); } ShareRequest reqData = new ShareRequest() { receiver = rec, secure_item_type = null, status = ShareStatus.Waiting, nickname = share.Nickname, expiration_date = share.ExpirationDateString, message = share.Message }; dynamic response = pbWebApi.RequestShare(reqData, String.Format("{0}|{1}", pbData.ActiveUser, pbData.DeviceUUID)); if (response.error != null) { MessageBox.Show(response.error.details.ToString(), response.error.message.ToString()); return(new List <SecuerShareData>()); } if (response.shares.sent != null) { if (response.shares.sent[0] != null) { dynamic sent = response.shares.sent[0]; if (!String.IsNullOrEmpty(sent.public_key.ToString())) { string receiverPublicKey = sent.public_key.ToString(); // Don't make recipient item as favorite. UATD-387 if (share.SharedItem == SharedItems.folder) { foreach (Folder folder in share.Folders) { foreach (SecureItem item in folder.SecureItems) { item.Favorite = false; } } } else { foreach (SecureItem item in share.SecureItems) { item.Favorite = false; } } reqData.data = EncriptItemForShare(share, Encoding.UTF8.GetString(Convert.FromBase64String(receiverPublicKey)));// JsonConvert.SerializeObject(new { key = encriptionKey, payload = payload }, Formatting.None, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); reqData.status = ShareStatus.Pending; reqData.message = share.Message; if (!expirationDate.HasValue) { switch (expirationPeriodIndex) { case 0: share.ExpirationDate = DateTime.Now.AddYears(50).ToUniversalTime(); break; case 1: share.ExpirationDate = DateTime.Now.AddDays(1).ToUniversalTime(); break; case 2: share.ExpirationDate = DateTime.Now.AddDays(7).ToUniversalTime(); break; case 3: share.ExpirationDate = DateTime.Now.AddMonths(1).ToUniversalTime(); break; case 4: share.ExpirationDate = DateTime.Now.AddYears(1).ToUniversalTime(); break; default: share.ExpirationDate = DateTime.Now.AddYears(50).ToUniversalTime(); break; } } reqData.expiration_date = share.ExpirationDateString; reqData.order = "0"; reqData.uuid = sent.uuid.ToString(); reqData.visible = share.Visible; response = pbWebApi.RequestShare(reqData, String.Format("{0}|{1}", pbData.ActiveUser, pbData.DeviceUUID)); if (response.error != null) { MessageBox.Show(response.error.details.ToString(), response.error.message.ToString()); return(new List <SecuerShareData>()); } sent = response.shares.sent[0]; shareItem.Receiver = reqData.receiver; shareItem.Sender = pbData.ActiveUser; shareItem.ExpirationDate = expirationDate.Value; shareItem.Data = reqData.data; shareItem.Id = sent.uuid.ToString(); shareItem.UUID = sent.uuid.ToString(); shareItem.Status = sent.status; shareItem.Nickname = sent.nickname; shareItem.Message = reqData.message; shareItem.SecureItemType = reqData.secure_item_type; shareItem.ReceiverPrivateKey = receiverPublicKey; shareItem.Visible = reqData.visible; pbData.AddOrUpdateShare(shareItem); //return BindingSecureShareList(item.Id); //CASE #1 } else { sent = response.shares.sent[0]; shareItem.Receiver = reqData.receiver; shareItem.Sender = pbData.ActiveUser; shareItem.ExpirationDate = DateTime.Now.AddDays(1).ToUniversalTime(); shareItem.Data = reqData.data; shareItem.Id = sent.uuid.ToString(); shareItem.UUID = sent.uuid.ToString(); shareItem.Status = sent.status; shareItem.Nickname = sent.nickname; shareItem.Message = reqData.message; shareItem.SecureItemType = reqData.secure_item_type; shareItem.ReceiverPrivateKey = null; shareItem.Visible = reqData.visible; pbData.AddOrUpdateShare(shareItem); //return BindingSecureShareList(item.Id); //CASE #2 - user does not exist - no data encription } if (inAppAnalyitics != null) { doShareAnalytics(shareItem, ShareEventStatus.Shared); } } } } //((IAppCommand)System.Windows.Application.Current).ExecuteCommand("ReloadData", null); return(BindingSecureShareList(shareItem)); } catch (Exception ex) { logger.Error("Error in ShareItem -->" + ex.ToString()); MessageBox.Show("Error while saving share"); } return(new List <SecuerShareData>()); }
private void AcceptShare(object obj) { if (!AcceptMessageBoxVisibility) { if (obj == null) { return; } currentUUID = obj as string; AcceptMessageBoxVisibility = true; return; } AcceptMessageBoxVisibility = false; if (currentUUID == null) { return; } var uuid = currentUUID as string; currentUUID = null; if (String.IsNullOrWhiteSpace(uuid)) { return; } try { bool isShareAllowed = true; bool isShareTresholdReached = pbData.IsShareTresholdReached(true, false); IFeatureChecker featureChecker = resolver.GetInstanceOf <IFeatureChecker>(); isShareAllowed = featureChecker.IsEnabled(DefaultProperties.Features_ShareCenter_UnlimitedShares, showUIIfNotEnabled: false); if (!isShareAllowed) { isShareAllowed = featureChecker.IsEnabled(DefaultProperties.Features_ShareCenter_UpTo5Shares, showUIIfNotEnabled: false) && !isShareTresholdReached; } if (!isShareAllowed) { featureChecker.FireActionNotEnabledUI(); return; } //TODO extract data and save secureItem Share item = pbData.GetSharesByUuid(uuid); if (item != null) { IPBWebAPI wepApi = resolver.GetInstanceOf <IPBWebAPI>(); dynamic share = wepApi.JsonStringToDynamic(item.Data); if (share != null) { string encriptionKey = share.key.ToString(); UserInfo ui = pbData.GetUserInfo(pbData.ActiveUser); encriptionKey = pbData.DecriptWithRSA(ui.RSAPrivateKey, encriptionKey); AESKeySet keySet = AESKeySet.KeysFromString(encriptionKey); string encriptedPayload = share.payload.ToString(); string data = pbData.DecryptAndVerifyWithAES(encriptedPayload, keySet);//.DecriptWithAES(encriptedPayload, encriptionKey); SecureItemShare sharedSecureItem = Newtonsoft.Json.JsonConvert.DeserializeObject <SecureItemShare>(data); sharedSecureItem.data.password_visible_recipient = item.Visible; string secureItemId = null; if (SaveSecureItem(sharedSecureItem, out secureItemId)) { if (shareCommon.UpdateShareStatus(uuid, ShareStatus.Shared, true, secureItemId)) { UpdateData(false, true); } ((IAppCommand)System.Windows.Application.Current).ExecuteCommand("ReloadData", null); } } } } catch (Exception ex) { logger.Error(String.Format("Error while Accepting share with uuid -> {0} with error-> {1}", uuid, ex.ToString())); } }