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) {}
            }
        }
        public Boolean AddShareTask(String id_to, String filePath)
        {
            if (System.IO.File.Exists(filePath) == false)
            {
                return(false);
            }
            FileMetaData fmd = PreKeyring.FileInfo_Query(filePath);

            if (fmd == null)
            {
                return(false);
            }

            ShareTaskUnit shareUnit = new ShareTaskUnit(id_to, filePath, fmd.Key);

            if (!this.IsPKExist(shareUnit.ID_TO))
            {
                this.ShareTaskSuspendList.Add(shareUnit);
            }
            else
            {
                shareUnit.PK = GetRequestedPK(shareUnit.ID_TO);
                this.ShareTaskWaitingList.Add(shareUnit);
            }

            if (!this.ShareWorker.IsBusy)
            {
                this.ShareWorker.RunWorkerAsync();
            }
            return(true);
        }
Exemple #3
0
        public void AddDecryptTask(String file)
        {
            FileInfo f = new FileInfo(file);
            String   fileFullPath_Dropbox = f.FullName;

            //If the file is being encrypted,skip it .
            if (this.LoopBackTool.IsWaitingOrDecrypting(fileFullPath_Dropbox))
            {
                return;
            }

            String fileFullPath_Local = this.DropboxSecuruStikFolder2SecuruStikFolder(fileFullPath_Dropbox);
            String hashValue_Local    = String.Empty;

            // TODO: error handling (it's returning bool (which is ignored) but should perhaps throw  exception)
            ProxyReEncryption.GetHashCode(fileFullPath_Local, ref hashValue_Local);

            FileMetaData fmd = PreKeyring.FileInfo_Query(fileFullPath_Local);

            if (fmd == null)
            {
                this.LostKeyFile.Add(fileFullPath_Dropbox);
            }
            else if (!File.Exists(fileFullPath_Local) || fmd.PlainTextHash != hashValue_Local)
            {
                // If the local file does not exist, redecrypt the file
                string hashValue_Dropbox = "";
                ProxyReEncryption.GetHashCode(fileFullPath_Local, ref hashValue_Dropbox);
                this.LoopBackTool.AddDecryptTask(fileFullPath_Dropbox, fileFullPath_Local, hashValue_Dropbox, (UInt64)f.Length, fmd.Key);
            }
        }
Exemple #4
0
        public void AddEncryptTask(string file)
        {
            FileInfo f = new FileInfo(file);

            String fileFullPath_Local = f.FullName;

            //if the file is beeing decrypted, skip it.
            if (this.LoopBackTool.IsWaitingOrEncrypting(file))
            {
                return;
            }

            string fileFullPath_Dropbox = this.SecuruStikFolder2DropboxSecuruStikFolder(fileFullPath_Local);

            string hashValue_DropBox = String.Empty;

            ProxyReEncryption.GetHashCode(fileFullPath_Dropbox, ref hashValue_DropBox);

            FileMetaData fmd = PreKeyring.FileInfo_Query(fileFullPath_Local);

            if (File.Exists(fileFullPath_Dropbox) == false || fmd == null ||
                hashValue_DropBox != fmd.CryptTextHash)
            {
                try
                {
                    String hashValue_Local = String.Empty;
                    ProxyReEncryption.GetHashCode(fileFullPath_Local, ref hashValue_Local);
                    this.LoopBackTool.AddEncryptTask(fileFullPath_Local, fileFullPath_Dropbox, hashValue_Local, (UInt64)f.Length);
                }
                catch (System.Exception ex)
                {
                    log.ErrorFormat("Add Encrypt Task for {0}", file, ex);
                }
            }
        }
Exemple #5
0
 private void DeleteDoWork(object sender, DoWorkEventArgs e)
 {
     while (this.deleteFileQueue.Count != 0 || this.deleteDirQueue.Count != 0)
     {
         while (this.deleteFileQueue.Count != 0)
         {
             String dropboxpath = this.deleteFileQueue.Peek();
             try
             {
                 File.Delete(dropboxpath);
                 this.deleteFileQueue.Dequeue();
                 PreKeyring.FileInfo_Delete(dropboxpath);
             }
             catch (System.Exception) { }
         }
         for (int i = deleteDirQueue.Count - 1; i >= 0; i--)
         {
             String path = deleteDirQueue[i];
             try
             {
                 Directory.Delete(path, true);
                 deleteDirQueue.RemoveAt(i);
             }
             catch (System.Exception) { }
         }
     }
 }
Exemple #6
0
 public void CopyAsync(String copyRef, String downloadPath)
 {
     this.client.CopyFromCopyRefAsync(copyRef, downloadPath,
                                      (response) =>
     {
     },
                                      (error) =>
     {
         PreKeyring.SharingFile_Delete(copyRef);
         SecuruStikMessageQueue.SendMessage_Download_Failed();
     }
                                      );
 }
 private void UpdateTaskInfo()
 {
     PreKeyring.FileInfo_Update
     (
         new SecuruStik.DB.FileMetaData
     {
         FileName      = Path.GetFileName(VelostiScsi.CurrentTask.PlaintextFilePath),
         FilePath      = VelostiScsi.CurrentTask.PlaintextFilePath,
         Key           = VelostiScsi.CurrentTask.Key,
         PlainTextHash = VelostiScsi.CurrentTask.HashValueOfPlaintext,
         CryptTextHash = VelostiScsi.CurrentTask.HashValueOfCryptotext
     }
     );
 }
Exemple #8
0
        public Boolean DownloadSharingFile(Protocal.SharingInfo si)
        {
            String copyRef  = si.Reference;
            String fileName = si.FileName;

            try
            {
                String dropboxPath = BaseExtension.FileStringHelper.GetNonConflictFileName(Path.Combine(DropBoxController.DropBox_DownloadFolder, fileName));

                UserKey uk      = PreKeyring.UserKey;
                PRE_KEY userKey = new PRE_KEY();
                userKey.PK.PK1 = uk.PK1;
                userKey.PK.PK2 = uk.PK2;
                userKey.SK.X1  = uk.SK1;
                userKey.SK.X2  = uk.SK2;

                PRE_Cipher CKey = new PRE_Cipher();
                CKey.E = si.CKey_E;
                CKey.F = si.CKey_F;
                CKey.U = si.CKey_U;
                CKey.W = si.CKey_W;

                String key = ProxyReEncryption.KeyDecrypt(userKey, CKey);

                FileMetaData fi = new FileMetaData();
                fi.FileName      = fileName;
                fi.FilePath      = this.dropBoxController.DropboxSecuruStikFolder2SecuruStikFolder(dropboxPath);
                fi.Key           = key;
                fi.PlainTextHash = "";
                fi.CryptTextHash = "";
                PreKeyring.FileInfo_Update(fi);

                String dropboxRemotePath = this.dropBoxController.SecuruStikFolder2RemoteDropboxPath(fi.FilePath);
                this.dropBoxController.CopyAsync(copyRef, dropboxRemotePath);
            }
            catch (System.Exception ex)
            {
                log.ErrorFormat("DownloadSharingFile {0}", si.FileName, ex);
                PreKeyring.SharingFile_Delete(si.Reference);
                return(false);
            }
            return(true);
        }