Exemple #1
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 #2
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 #3
0
 public void Close()
 {
     try
     {
         ProxyReEncryption.UnSetup();
         this.proxyServerController.UnInit();
     }
     catch (System.Exception e)
     {
         log.Error("Closing DBox_User", e);
     }
 }
        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 #5
0
        public void ReGenUserKey()
        {
            //Create a new user key
            PRE_KEY key = ProxyReEncryption.GenRandomKey();

            this.PK = new Protocal.PublicKey(
                id: this.dropBoxController.Email,
                pk1: key.PK.PK1,
                pk2: key.PK.PK2);

            PreKeyring.UserKey = new SecuruStik.DB.UserKey
            {
                PK1          = key.PK.PK1,
                PK2          = key.PK.PK2,
                SK1          = key.SK.X1,
                SK2          = key.SK.X2,
                IsPublicized = false
            };
        }
Exemple #6
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);
        }