示例#1
0
        public string EncriptItemForShare(Share share, string receiverPublicKey)
        {
            string    payloadPlain  = share.GetShareJson();
            string    encriptionKey = String.Empty;
            AESKeySet keySet        = null;
            string    payload       = pbData.EcryptAndSignWithAES(payloadPlain, out keySet);//.EncriptWithAES(payloadPlain, out encriptionKey);

            encriptionKey = pbData.EncriptWithRSA(receiverPublicKey, keySet.KeysToString());
            return(JsonConvert.SerializeObject(new { key = encriptionKey, payload = payload }, Formatting.None, new JsonSerializerSettings()
            {
                NullValueHandling = NullValueHandling.Ignore
            }));
        }
示例#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()));
            }
        }