private void DealReceiveSharingInfo(RequestContent ResponseContent)
        {
            SecuruStik.Protocal.SharingInfo si = ResponseContent as SecuruStik.Protocal.SharingInfo;
            if (si != null)
            {
                try
                {
                    PreKeyring.SharingFile_Update(
                        new DB.SharingInfo
                    {
                        CopyRef  = si.Reference,
                        FileName = si.FileName,
                        ID_From  = si.ID_From,
                        CKEY_E   = si.CKey_E,
                        CKEY_F   = si.CKey_F,
                        CKEY_U   = si.CKey_U,
                        CKEY_W   = si.CKey_W
                    });

                    String savePath = Path.Combine(DropBoxController.Local_ShareInfoFolder,
                                                   String.Format("[{1}]{0}.{2}", si.FileName, si.ID_From, AppSetting.Name_ShareInfoFileExtension)
                                                   );
                    Byte[] sharingInfoBytes = CommunicatingProtocal.Serialize(si);
                    File.WriteAllBytes(BaseExtension.FileStringHelper.GetNonConflictFileName(savePath), sharingInfoBytes);
                }
                catch (System.Exception ex) {}
            }
        }
        private void ShareWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            while (this.ShareTaskWaitingList.Count != 0)
            {
                for (int i = this.ShareTaskWaitingList.Count - 1; i >= 0; i--)
                {
                    ShareTaskUnit worker = this.ShareTaskWaitingList[i];
                    PublicKey     pubkey = worker.PK;
                    //Key1
                    PRE_KEY key = ProxyReEncryption.GenKey(
                        PreKeyring.UserKey.PK1,
                        PreKeyring.UserKey.PK2,
                        PreKeyring.UserKey.SK1,
                        PreKeyring.UserKey.SK2);

                    //Key_pk2
                    PRE_PK key2_pk = ProxyReEncryption.GenPK(pubkey.PK1, pubkey.PK2);

                    //ReKey
                    PRE_Cipher reKey = ProxyReEncryption.KeyEncrypt(key, key2_pk, worker.Key);

                    String cpyRef = this.DropboxController.GetCopyRef(
                        this.DropboxController.SecuruStikFolder2RemoteDropboxPath(worker.FilePath));
                    if (String.IsNullOrEmpty(cpyRef))
                    {
                        continue;//获取copyref失败处理
                    }
                    else
                    {
                        worker.CpyRef = cpyRef;
                    }

                    SecuruStik.Protocal.SharingInfo si = new SecuruStik.Protocal.SharingInfo(
                        this.Email,
                        pubkey.ID,
                        Path.GetFileName(worker.FilePath),
                        worker.CpyRef,
                        reKey.E, reKey.F, reKey.U, reKey.W);

                    Request r = new Request(MessageType.Request_SetSharingInfo, this.DropboxController.Email, si);
                    this.ProxyServerController.Send(r);
                    this.ShareTaskWaitingList.Remove(worker);
                    SecuruStikMessageQueue.SendMessage_Share_End(Path.GetFileName(worker.FilePath), worker.ID_TO);
                }
            }
        }
Exemple #3
0
        private void Request_SetSharingInfo(User client, Request request)
        {
            String retStr = String.Empty;

            SecuruStik.Protocal.SharingInfo si = request.RequestContent as SharingInfo;
            if (si == null)
            {
                retStr = String.Format("Failed to upload sharing info from 【{0}】 to 【{1}】.", client.userName, (request.RequestContent as SharingInfo).ID_TO);
            }
            else
            {
                User u = this.ClientList.Find(usr => usr.userName == si.ID_TO);
                if (u != null)
                {
                    SecuruStik.Protocal.Response response = new Response(
                        MessageType.Response_GetSharingInfo,
                        true,
                        si);
                    this.Send(u, response);
                    retStr = String.Format("Success : Forward sharing info from 【{0}】 to 【{1}】.", client.userName, u.userName);
                }
                else
                {
                    Boolean ret = this.DropBoxServerControler.SharingInfo.Upload(si);

                    retStr = String.Format("{3} : Upload sharing info from 【{0}】 to 【{1}】.",
                                           client.userName,
                                           (request.RequestContent as SharingInfo).ID_TO,
                                           ret?"Success":"Failed");
                }
            }
            AddLogs(
                new String[] {
                String.Format("【{0}】 upload sharing info to 【{1}】.", client.userName, request.UserID),
                retStr
            }
                );
        }
Exemple #4
0
 /// <summary>
 /// Upload the sharing-info file to the server
 /// </summary>
 /// <param pathFullName="newSharingInfo">From.To.Filename.URL.ReKey</param>
 /// <returns></returns>
 public Boolean Upload( SharingInfo newSharingInfo )
 {
     String sharingInfoFileDir = String.Format( "/{0}" , newSharingInfo.ID_TO );
     String sharingInfoFileName = String.Format( "{0}.txt" , newSharingInfo.Reference );
     String sharingInfoFilePath = String.Format( "{0}/{1}" , sharingInfoFileDir , sharingInfoFileName );
     try
     {
         //this.Client.Delete( sharingInfoFilePath );
         Client.Delete( sharingInfoFilePath );
     }
     catch ( System.Exception ) { }
     try
     {
         MemoryStream ms = new MemoryStream();
         BinaryFormatter bfer = new BinaryFormatter();
         bfer.Serialize( ms , newSharingInfo );
         Client.UploadFileAsync( sharingInfoFileDir , sharingInfoFileName , ms.ToArray() ,
                     ( response ) =>{} ,
                     ( error ) =>
                     {
                         //SecuruStikException.ThrowSecuruStik(
                         //                  SecuruStikExceptionType.DropBoxControl_Upload , "UpLoadError" , error );
                     } );
         return true;
     }
     catch ( System.Exception  ){return false;}
 }
        private void ShareWorker_DoWork( object sender , DoWorkEventArgs e )
        {
            while( this.ShareTaskWaitingList.Count != 0 )
            {
                for ( int i = this.ShareTaskWaitingList.Count - 1 ; i >= 0 ; i-- )
                {
                    ShareTaskUnit worker = this.ShareTaskWaitingList[i];
                    PublicKey pubkey = worker.PK;
                    //Key1
                    PRE_KEY key = ProxyReEncryption.GenKey(
                        PreKeyring.UserKey.PK1 ,
                        PreKeyring.UserKey.PK2 ,
                        PreKeyring.UserKey.SK1 ,
                        PreKeyring.UserKey.SK2 );

                    //Key_pk2
                    PRE_PK key2_pk = ProxyReEncryption.GenPK(pubkey.PK1,pubkey.PK2);

                    //ReKey
                    PRE_Cipher reKey = ProxyReEncryption.KeyEncrypt( key , key2_pk , worker.Key );

                    String cpyRef = this.DropboxController.GetCopyRef(
                        this.DropboxController.SecuruStikFolder2RemoteDropboxPath( worker.FilePath ) );
                    if ( String.IsNullOrEmpty( cpyRef ) )
                        continue;//获取copyref失败处理
                    else
                    {
                        worker.CpyRef = cpyRef;
                    }

                    SecuruStik.Protocal.SharingInfo si = new SecuruStik.Protocal.SharingInfo(
                        this.Email ,
                        pubkey.ID ,
                        Path.GetFileName( worker.FilePath ) ,
                        worker.CpyRef ,
                        reKey.E,reKey.F,reKey.U,reKey.W );

                    Request r = new Request( MessageType.Request_SetSharingInfo , this.DropboxController.Email , si );
                    this.ProxyServerController.Send( r );
                    this.ShareTaskWaitingList.Remove( worker );
                    SecuruStikMessageQueue.SendMessage_Share_End( Path.GetFileName( worker.FilePath ) , worker.ID_TO );
                }
            }
        }
 public Boolean Request_SetSharingInfo(SecuruStik.Protocal.SharingInfo sharingInfo)
 {
     SecuruStik.Protocal.Request r = new SecuruStik.Protocal.Request(MessageType.Response_SetSharingInfo, this.UserEmail, sharingInfo);
     return(this.Send(r));
 }