Exemplo n.º 1
0
        private bool SaveSecureItem(SecureItemShare sharedSecureItem, out string secureItemId)
        {
            secureItemId = null;
            try
            {
                SecureItem si = new SecureItem();
                si.SecureItemTypeName = sharedSecureItem.secure_item_type_name;
                si.Type     = sharedSecureItem.type;
                si.Folder   = categoryList.FirstOrDefault(x => x.Id == sharedSecureItem.category_id);
                si.Data     = sharedSecureItem.data;
                si.Name     = sharedSecureItem.name;
                si.Color    = sharedSecureItem.color;
                si.LoginUrl = sharedSecureItem.login_url;
                si.Favorite = sharedSecureItem.favorite;

                if (si.Folder == null)
                {
                    si.Folder = new Folder()
                    {
                        Name = sharedSecureItem.category_name
                    };
                }

                if (si.SecureItemTypeName == DefaultProperties.SecurityItemType_PasswordVault)
                {
                    if (!sharedSecureItem.site_url.Contains("http") && !sharedSecureItem.site_url.Contains("https"))
                    {
                        sharedSecureItem.site_url = "http://" + sharedSecureItem.site_url;
                    }
                    //Uri siteUrl = new Uri(sharedSecureItem.site_url);
                    //var parts = siteUrl.Host.Split('.');

                    si.Site = new Site();

                    var siteId = pbData.GetSiteIdByUriFullSearch(new Uri(sharedSecureItem.site_url));
                    if (siteId == null)
                    {
                        //TODO: Call service to retreive from server

                        string uuid = pbSync.RegisterSite(new Uri(sharedSecureItem.site_url));
                        if (uuid != null)
                        {
                            siteId = pbData.GetSiteIdByUUID(uuid);
                        }
                    }


                    si.Site.Id = siteId;
                }
                else
                {
                    si.Data.password_visible_recipient = null;
                }



                si = pbData.AddOrUpdateSecureItem(si);
                if (si.Id != null)
                {
                    secureItemId = si.Id;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
            }
            return(false);
        }
Exemplo n.º 2
0
        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()));
            }
        }