Esempio n. 1
0
        public Boolean Download(String user, ref SecuruStik.Protocal.PublicKey pk)
        {
            Byte[]  pkBytes = null;
            Boolean ret     = Download(user, ref pkBytes);

            if (pkBytes != null)
            {
                try
                {
                    String pkStr = Encoding.ASCII.GetString(pkBytes);
                    if (this.IsOldVersion(pkStr))
                    {
                        //throw new Exception( "Old version" );
                        //Old version
                        MemoryStream    ms   = new MemoryStream(pkBytes);
                        BinaryFormatter bfer = new BinaryFormatter();
                        pk = (SecuruStik.Protocal.PublicKey)bfer.Deserialize(ms);

                        //Update
                        this.Update(user, pk);
                        return(true);
                    }
                    else
                    {
                        String[] param = pkStr.Split('\n');
                        pk = new PublicKey(user, param[0], param[1]);

                        return(true);
                    }
                } catch (System.Exception) {}
            }
            return(false);
        }
Esempio n. 2
0
        public ShareTaskUnit( String id_to , String filePath , String key )
        {
            this.ID_TO = id_to;
            this.FilePath = filePath;
            this.Key = key;

            this.PK = null;
            this.CpyRef = String.Empty;
        }
 private void DealReceivePK(RequestContent ResponseContent)
 {
     SecuruStik.Protocal.PublicKey receivepk = ResponseContent as SecuruStik.Protocal.PublicKey;
     if (receivepk != null)
     {
         PublicKeyUnit pku = PKList[receivepk.ID];
         if (pku == null)
         {
             this.PKList.Add(new PublicKeyUnit(receivepk.ID, receivepk));
         }
         else
         {
             PublicKey pk = pku.PK;
             if (pk == null || pk.PK1 != receivepk.PK1 || pk.PK2 != receivepk.PK2)
             {
                 pku.PK = receivepk;
             }
         }
         SecuruStikMessageQueue.SendMessage_ReceivePK(pku.ID, pku.PK.PK1, pku.PK.PK2);
     }
     return;
 }
Esempio n. 4
0
        public Boolean Download( String user , ref SecuruStik.Protocal.PublicKey pk )
        {
            Byte[] pkBytes = null;
            Boolean ret = Download( user , ref pkBytes );

            if ( pkBytes != null )
            {
                try
                {
                    String pkStr = Encoding.ASCII.GetString( pkBytes );
                    if ( this.IsOldVersion( pkStr ) )
                    {
                        //throw new Exception( "Old version" );
                        //Old version
                        MemoryStream ms = new MemoryStream( pkBytes );
                        BinaryFormatter bfer = new BinaryFormatter();
                        pk = (SecuruStik.Protocal.PublicKey)bfer.Deserialize( ms );

                        //Update
                        this.Update( user , pk );
                        return true;
                    }
                    else
                    {
                        String[] param = pkStr.Split( '\n' );
                        pk = new PublicKey( user , param[ 0 ] , param[ 1 ] );

                        return true;
                    }
                } catch ( System.Exception ){}
            }
            return false;
        }
Esempio n. 5
0
 public Boolean Update( String user , PublicKey newPK )
 {
     try
     {
         MemoryStream ms = new MemoryStream();
         String pkStr = String.Format( "{0}\n{1}" ,newPK.PK1,newPK.PK2);
         Byte[] pkByte = Encoding.ASCII.GetBytes( pkStr );
         return Update( user , pkByte );
     }
     catch ( System.Exception ex )
     {
         Console.WriteLine( ex.Message );
         return false;
     }
 }
Esempio n. 6
0
 public void ReceivePKInfo( PublicKey pubkey )
 {
     for ( int i = this.ShareTaskSuspendList.Count - 1 ; i >= 0 ; i-- )
     {
         ShareTaskUnit shareTaskWorker = this.ShareTaskSuspendList[ i ];
         if(shareTaskWorker.ID_TO == pubkey.ID)
         {
             shareTaskWorker.PK = pubkey;
             this.ShareTaskSuspendList.Remove( shareTaskWorker );
             this.ShareTaskWaitingList.Add( shareTaskWorker );
         }
     }
     if ( !this.ShareWorker.IsBusy )
     {
         this.ShareWorker.RunWorkerAsync();
     }
 }
 public Boolean Request_SetPK(SecuruStik.Protocal.PublicKey pk)
 {
     SecuruStik.Protocal.Request r = new SecuruStik.Protocal.Request(MessageType.Request_SetPK, this.UserEmail, pk);
     return(this.Send(r));
 }
Esempio n. 8
0
        private void Init_UserKey()
        {
            log.Info("Initializing User Key");
            UserKey userKey = PreKeyring.UserKey;

            if ( userKey == null )
            {
                this.ReGenUserKey();
                this.PublishPK();
            }
            else
            {
                this.PK = new Protocal.PublicKey(
                    id: this.dropBoxController.Email ,
                    pk1: userKey.PK1 ,
                    pk2: userKey.PK2 );

                if ( !userKey.IsPublicized )
                    this.PublishPK();
            }
        }
Esempio n. 9
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
            };
        }
Esempio n. 10
0
 private Boolean Request_GetPK( User client , Request request )
 {
     AddLog( string.Format( "【{0}】 request 【{1}】's public key." , client.userName , request.UserID ) );
     PublicKey pk = null;
     SecuruStik.Protocal.Response response = null;
     this.DropBoxServerControler.PublicKey.Download( request.UserID , ref pk );
     if ( pk == null )
     {
         pk = new PublicKey( request.UserID , null , null );
         response = new Response( MessageType.Response_GetPK , false , pk );
         AddLog( string.Format( "Failed to get 【{0}】's public key." , request.UserID ) );
     }
     else
     {
         response = new Response( MessageType.Response_GetPK , true , pk );
         AddLogs( new String[]
                     {
                             String.Format( "Return【{1}】's public key to【{0}】." , client.userName , request.UserID ) ,
                             String.Format( "PK1 : {0}" , pk.PK1 ) ,
                             String.Format( "PK2 : {0}" , pk.PK2 )
                     }
                 );
     }
     this.Send( client , response );
     return true;
 }