Changeset 1374


Ignore:
Timestamp:
May 2, 2010, 1:43:33 PM (12 years ago)
Author:
Paul Lelgemann
Message:

+ Added P2P connection to CrypP2P based on PeerToPeerBase plugin (using default settings)
+ Added MD5Collider to CoreDeveloper solution

Location:
trunk/CrypP2P
Files:
11 added
2 edited
7 copied

Legend:

Unmodified
Added
Removed
  • trunk/CrypP2P/CrypP2P.csproj

    r1364 r1374  
    99    <OutputType>Library</OutputType>
    1010    <AppDesignerFolder>Properties</AppDesignerFolder>
    11     <RootNamespace>CrypP2P</RootNamespace>
     11    <RootNamespace>Cryptool.P2P</RootNamespace>
    1212    <AssemblyName>CrypP2P</AssemblyName>
    1313    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
     
    4040      <HintPath>..\AppReferences\CertServices.dll</HintPath>
    4141    </Reference>
     42    <Reference Include="DevComponents.WpfRibbon, Version=4.1.0.13, Culture=neutral, PublicKeyToken=2037e151916410e7, processorArchitecture=MSIL">
     43      <SpecificVersion>False</SpecificVersion>
     44      <HintPath>..\CoreDeveloper\CrypWin\DevComponents.WpfRibbon.dll</HintPath>
     45    </Reference>
    4246    <Reference Include="FullMeshDHT, Version=1.0.4654.4, Culture=neutral, PublicKeyToken=95429f90c3a66dd4, processorArchitecture=MSIL">
    4347      <SpecificVersion>False</SpecificVersion>
     
    6872      <HintPath>..\AppReferences\PeersAtPlayBase.dll</HintPath>
    6973    </Reference>
     74    <Reference Include="PresentationCore">
     75      <RequiredTargetFramework>3.0</RequiredTargetFramework>
     76    </Reference>
     77    <Reference Include="PresentationFramework">
     78      <RequiredTargetFramework>3.0</RequiredTargetFramework>
     79    </Reference>
    7080    <Reference Include="Stun, Version=1.0.0.0, Culture=neutral, PublicKeyToken=95429f90c3a66dd4, processorArchitecture=MSIL">
    7181      <SpecificVersion>False</SpecificVersion>
     
    7686      <RequiredTargetFramework>3.5</RequiredTargetFramework>
    7787    </Reference>
     88    <Reference Include="System.Security" />
     89    <Reference Include="System.Windows.Forms" />
    7890    <Reference Include="System.Xml.Linq">
    7991      <RequiredTargetFramework>3.5</RequiredTargetFramework>
     
    93105  </ItemGroup>
    94106  <ItemGroup>
     107    <Compile Include="P2PSettings.cs" />
     108    <Compile Include="Worker\ConnectionWorker.cs" />
     109    <Compile Include="Worker\WorkerBase.cs" />
     110    <Compile Include="Internal\DHT_CommonManagement.cs" />
     111    <Compile Include="Internal\IP2PControl.cs" />
     112    <Compile Include="Internal\KeySearcherResult.cs" />
    95113    <Compile Include="P2PManager.cs" />
     114    <Compile Include="Helper\PAPCertificate.cs" />
     115    <Compile Include="Internal\P2PBase.cs" />
    96116    <Compile Include="Properties\AssemblyInfo.cs" />
     117    <Compile Include="Internal\ResponseWait.cs" />
    97118  </ItemGroup>
    98119  <ItemGroup>
     
    110131    </ProjectReference>
    111132  </ItemGroup>
     133  <ItemGroup>
     134    <None Include="pap_certificates\CrypTool2.pfx" />
     135    <None Include="pap_certificates\opa.vs.uni-due.de.cer" />
     136    <None Include="pap_certificates\pap.cer" />
     137    <None Include="pap_certificates\pap0001.p12" />
     138    <None Include="pap_certificates\ServerCA.cer" />
     139  </ItemGroup>
    112140  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    113141  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
  • trunk/CrypP2P/Helper/PAPCertificate.cs

    r1370 r1374  
    55using System.Security.Cryptography.X509Certificates;
    66using System.IO;
     7using Cryptool.PluginBase;
    78
    89/*
     
    1011 */
    1112
    12 namespace Cryptool.Plugins.PeerToPeer
     13namespace Cryptool.P2P.Helper
    1314{
    1415    public static class PAPCertificate
     
    2930        /// directory or a specific certificate file name!
    3031        /// </summary>
    31         public static string CertPath 
     32        public static string CertPath
    3233        {
    3334            get { return sCertPath; }
    34             private set 
     35            private set
    3536            {
    3637                string combindedCertPath = Path.Combine(value, CERTIFICATE_DIRECTORY);
     
    9495            List<PAP_Certificates> lstMissingCerts = new List<PAP_Certificates>();
    9596            lstMissingCerts = CheckAvailabilityOfPAPCertificates(sPath);
    96             return InstallMissingCertificates(lstMissingCerts,sPath);
     97            return InstallMissingCertificates(lstMissingCerts, sPath);
    9798        }
    9899
     
    163164                {
    164165                    case PAP_Certificates.Server_CA:
    165                         intermediateResult = InstallCertificate(CERT_STORE_ROOT, CERT_STORE_LOCATION, 
    166                             Path.Combine(CertPath,CERT_SERVER_CA_FILE_NAME), CERT_SERVER_CA_PASSWORD);
     166                        intermediateResult = InstallCertificate(CERT_STORE_ROOT, CERT_STORE_LOCATION,
     167                            Path.Combine(CertPath, CERT_SERVER_CA_FILE_NAME), CERT_SERVER_CA_PASSWORD);
    167168                        break;
    168169                    case PAP_Certificates.Opa:
    169                         intermediateResult = InstallCertificate(CERT_STORE_ROOT, CERT_STORE_LOCATION, 
    170                             Path.Combine(CertPath,CERT_OPA_FILE_NAME), CERT_OPA_PASSWORD);
     170                        intermediateResult = InstallCertificate(CERT_STORE_ROOT, CERT_STORE_LOCATION,
     171                            Path.Combine(CertPath, CERT_OPA_FILE_NAME), CERT_OPA_PASSWORD);
    171172                        break;
    172173                    case PAP_Certificates.Pap:
    173                         intermediateResult = InstallCertificate(CERT_STORE_ROOT, CERT_STORE_LOCATION, 
    174                             Path.Combine(CertPath,CERT_PAP_FILE_NAME), CERT_PAP_PASSWORD);
     174                        intermediateResult = InstallCertificate(CERT_STORE_ROOT, CERT_STORE_LOCATION,
     175                            Path.Combine(CertPath, CERT_PAP_FILE_NAME), CERT_PAP_PASSWORD);
    175176                        break;
    176177                    case PAP_Certificates.User:
    177                         intermediateResult = InstallCertificate(CERT_STORE_USER, CERT_STORE_LOCATION, 
    178                             Path.Combine(CertPath,CERT_USER_FILE_NAME), CERT_USER_PASSWORD);
     178                        intermediateResult = InstallCertificate(CERT_STORE_USER, CERT_STORE_LOCATION,
     179                            Path.Combine(CertPath, CERT_USER_FILE_NAME), CERT_USER_PASSWORD);
    179180                        break;
    180181                    default:
     
    201202        private static X509Certificate2Collection FindCertificates(StoreName storeName, StoreLocation storeLocation, X509FindType findType, object findValue, bool onlyValidCerts)
    202203        {
    203             X509Certificate2Collection findedCertCol = null; 
     204            X509Certificate2Collection findedCertCol = null;
    204205            X509Store store = new X509Store(storeName, storeLocation);
    205206            try
     
    208209                findedCertCol = store.Certificates.Find(findType, findValue, onlyValidCerts);
    209210            }
    210             catch (Exception ex)
     211            catch (Exception)
    211212            {
    212213
     
    347348            {
    348349                MyCertificate = null;
    349                 throw(new Exception("Certificate not valid",ex));
     350                throw (new Exception("Certificate not valid", ex));
    350351            }
    351352            finally { store.Close(); }
     
    397398        }
    398399        #endregion
     400
     401        /// <summary>
     402        /// Checks if all certificates for using the pap p2p system are installed.
     403        /// Otherwise it tries to install the missing certificates. If all operations
     404        /// succeed, return value is true. Only when value is true, you can try
     405        /// to initialize the PAP System.
     406        /// </summary>
     407        /// <returns>If all operations succeed, return value is true. Only when value
     408        /// is true, you can try to initialize the PAP System.</returns>
     409        public static bool CheckAndInstallPAPCertificates()
     410        {
     411            bool retValue = false;
     412
     413            // get exe directory, because there resides the certificate directory
     414            System.Reflection.Assembly assemb = System.Reflection.Assembly.GetEntryAssembly();
     415            string applicationDir = System.IO.Path.GetDirectoryName(assemb.Location);
     416            // check if all necessary certs are installed
     417            P2PManager.Instance.GuiLogMessage("Check installation of all certificates, which are necessary to run the p2p system", NotificationLevel.Info);
     418            List<PAPCertificate.PAP_Certificates> lstMissingCerts = PAPCertificate.CheckAvailabilityOfPAPCertificates(applicationDir);
     419            if (lstMissingCerts.Count == 0)
     420            {
     421                //GuiLogMessage("All neccessary p2p certificates are installed.", NotificationLevel.Info);
     422                retValue = true;
     423            }
     424            else
     425            {
     426                StringBuilder sbMissingCerts = new StringBuilder();
     427                for (int i = 0; i < lstMissingCerts.Count; i++)
     428                {
     429                    sbMissingCerts.AppendLine(Enum.GetName(typeof(PAPCertificate.PAP_Certificates), lstMissingCerts[i]));
     430                }
     431                P2PManager.Instance.GuiLogMessage("Following certificates are missing. They will be installed now.\n" + sbMissingCerts.ToString(), NotificationLevel.Info);
     432
     433                // try/catch neccessary because the CT-Editor doesn't support the whole exception display process (e.g. shows only "unknown error.")
     434                try
     435                {
     436                    if (PAPCertificate.InstallMissingCertificates(lstMissingCerts, applicationDir))
     437                    {
     438                        P2PManager.Instance.GuiLogMessage("Installation of all missing certificates was successful.", NotificationLevel.Info);
     439                        retValue = true;
     440                    }
     441                    else
     442                    {
     443                        P2PManager.Instance.GuiLogMessage("No/not all missing certificates were installed successful.", NotificationLevel.Error);
     444                    }
     445                }
     446                catch (Exception ex)
     447                {
     448                    P2PManager.Instance.GuiLogMessage("Error occured while installing certificates. Exception: " + ex.ToString(), NotificationLevel.Error);
     449                }
     450            }
     451            return retValue;
     452        }
    399453    }
    400454}
  • trunk/CrypP2P/Internal/DHT_CommonManagement.cs

    r1370 r1374  
    66using Cryptool.PluginBase.IO;
    77
    8 namespace Cryptool.Plugins.PeerToPeer
     8namespace Cryptool.P2P.Internal
    99{
    1010    public static class DHT_CommonManagement
     
    3939            PeerId pid = null;
    4040            byte[] byteLoad = p2pControl.DHTload(sTopicName);
    41             if(byteLoad != null)
     41            if (byteLoad != null)
    4242                pid = p2pControl.GetPeerID(byteLoad);
    4343            return pid;
     
    177177
    178178        // new stuff - Arnie 2010.02.02
    179        
     179
    180180        ///// <summary>
    181181        ///// Sets or updates the TimeStamp for the actual Publisher
  • trunk/CrypP2P/Internal/IP2PControl.cs

    r1370 r1374  
    55using Cryptool.Plugins.PeerToPeer;
    66using Cryptool.PluginBase.Miscellaneous;
     7using Cryptool.PluginBase.Control;
    78
    8 namespace Cryptool.PluginBase.Control
     9namespace Cryptool.P2P.Internal
    910{
    1011    #region P2P Initialisation Enums
     
    2122
    2223    public enum P2POverlayType
    23     { 
     24    {
    2425        FullMeshOverlay = 0
    2526    }
     
    5657        /// must respond with a pong message
    5758        /// </summary>
    58         Ping = 4, 
     59        Ping = 4,
    5960        /// <summary>
    6061        /// adequate response to a
  • trunk/CrypP2P/Internal/KeySearcherResult.cs

    r1370 r1374  
    55using KeySearcher;
    66
    7 namespace Cryptool.Plugins.PeerToPeer
     7namespace Cryptool.P2P.Internal
    88{
    99    public class KeySearcherResult
  • trunk/CrypP2P/Internal/P2PBase.cs

    r1370 r1374  
    5656 * - Testing asynchronous methods incl. EventHandlers
    5757 */
    58 namespace Cryptool.Plugins.PeerToPeer
     58namespace Cryptool.P2P.Internal
    5959{
    6060    /* Advantages of this wrapper class:
     
    108108        /// If true, all kinds of actions will be logged in the PeersAtPlay LogMonitor.
    109109        /// </summary>
    110         public bool AllowLoggingToMonitor 
     110        public bool AllowLoggingToMonitor
    111111        {
    112112            get { return this.allowLoggingToMonitor; }
     
    120120        /// True if system was successfully joined, false if system is COMPLETELY left
    121121        /// </summary>
    122         public bool Started 
     122        public bool Started
    123123        {
    124124            get { return this.started; }
    125             private set { this.started = value; } 
     125            private set { this.started = value; }
    126126        }
    127127
     
    149149
    150150        #region Basic P2P Methods (Init, Start, Stop) - synch and asynch
     151
     152        public void Initialize(P2PSettings p2pSettings)
     153        {
     154            Initialize(p2pSettings.PeerName, p2pSettings.WorldName,
     155                (P2PLinkManagerType)p2pSettings.LinkManagerType, (P2PBootstrapperType)p2pSettings.BSType,
     156                (P2POverlayType)p2pSettings.OverlayType, (P2PDHTType)p2pSettings.DhtType);
     157        }
    151158
    152159        /// <summary>
     
    350357                 * ATTENTION: This could change the invocation order!!! In my case
    351358                              no problem, but maybe in future cases... */
    352                 OnP2PMessageReceived.BeginInvoke(pid, e.Message.Data.PopBytes(e.Message.Data.CurrentStackSize),null,null);
     359                OnP2PMessageReceived.BeginInvoke(pid, e.Message.Data.PopBytes(e.Message.Data.CurrentStackSize), null, null);
    353360                //OnP2PMessageReceived(pid, e.Message.Data.PopUTF8String());
    354361            }
     
    420427                    OnDhtStore_Completed(false);
    421428            }
    422                
     429
    423430        }
    424431
     
    437444            if (OnDhtRemove_Completed != null)
    438445            {
    439                 if(rr.Status == OperationStatus.Success)
     446                if (rr.Status == OperationStatus.Success)
    440447                    OnDhtRemove_Completed(true);
    441448                else
     
    463470            Guid g = this.dht.Store(OnSynchStoreCompleted, sKey, byteData);
    464471
    465             ResponseWait rw = new ResponseWait() { WaitHandle = are, key=sKey , value = byteData };
     472            ResponseWait rw = new ResponseWait() { WaitHandle = are, key = sKey, value = byteData };
    466473
    467474            waitDict.Add(g, rw);
     
    565572
    566573            LogToMonitor("Begin: SynchRetrieve. Key: " + sKey);
    567              
     574
    568575            Guid g = this.dht.Retrieve(OnSynchRetrieveCompleted, sKey);
    569            
    570             ResponseWait rw = new ResponseWait() {WaitHandle = are };
    571            
    572             waitDict.Add(g,rw  );
     576
     577            ResponseWait rw = new ResponseWait() { WaitHandle = are };
     578
     579            waitDict.Add(g, rw);
    573580            // blocking till response
    574581            are.WaitOne();
     
    587594        {
    588595            LogToMonitor(rr.Guid.ToString());
    589            
     596
    590597            ResponseWait rw;
    591598
     
    675682        public void LogToMonitor(string sTextToLog)
    676683        {
    677             if(AllowLoggingToMonitor)
     684            if (AllowLoggingToMonitor)
    678685                Log.Debug(sTextToLog);
    679686        }
  • trunk/CrypP2P/Internal/ResponseWait.cs

    r1370 r1374  
    55using System.Threading;
    66
    7 namespace Cryptool.Plugins.PeerToPeer
     7namespace Cryptool.P2P.Internal
    88{
    99    public class ResponseWait
  • trunk/CrypP2P/P2PManager.cs

    r1364 r1374  
    2222using Cryptool.PluginBase;
    2323using Cryptool.PluginBase.Miscellaneous;
     24using System.Windows.Forms;
     25using Cryptool.P2P.Worker;
     26using DevComponents.WpfRibbon;
     27using Cryptool.P2P.Helper;
     28using Cryptool.P2P.Internal;
    2429
    2530namespace Cryptool.P2P
     
    2934        #region Singleton
    3035        static readonly P2PManager INSTANCE = new P2PManager();
    31         static P2PManager() {}
    32         P2PManager() {}
     36        private P2PManager() { }
    3337
    3438        public static P2PManager Instance
     
    4751
    4852        #region Private variables
    49         private bool isP2PNetworkConnected = false;
     53        private P2PBase P2PBase { get; set; }
     54        private P2PSettings P2PSettings { get; set; }
     55        private ButtonDropDown P2PButton { get; set; }
    5056        #endregion
    5157
    52         public void initialize()
     58        #region Events
     59        public static event Cryptool.PluginBase.GuiLogNotificationEventHandler OnGuiLogNotificationOccured;
     60
     61        // to forward event from overlay/dht MessageReceived-Event from P2PBase
     62        public event P2PBase.P2PMessageReceived OnPeerMessageReceived;
     63        #endregion Events
     64
     65        /// <summary>
     66        /// Initialises variables and important environment settings
     67        /// regarding certificates.
     68        /// </summary>
     69        /// <param name="p2pButton">Button that can change the connection state
     70        /// and displays it by showing different images.</param>
     71        public void Initialize(ButtonDropDown p2pButton)
    5372        {
    54             // TODO P2P init code
     73            this.P2PButton = p2pButton;
     74            this.P2PBase = new P2PBase();
     75            this.P2PSettings = new P2PSettings();
     76            this.P2PBase.AllowLoggingToMonitor = this.P2PSettings.Log2Monitor;
     77
     78            // Validate certificats
     79            if (!PAPCertificate.CheckAndInstallPAPCertificates())
     80            {
     81                GuiLogMessage("Certificates not validated, P2P might not be working!", NotificationLevel.Error);
     82                return;
     83            }
     84
     85            // Register events
     86
     87            // to forward event from overlay/dht MessageReceived-Event from P2PBase
     88            this.P2PBase.OnP2PMessageReceived += new P2PBase.P2PMessageReceived(p2pBase_OnP2PMessageReceived);
     89
     90            // Register exit event to terminate P2P connection without loosing data
     91            // TODO check if this is correct, should be - but handler is not called (and application does not shut down), probably unrelated to this problem
     92            Application.ApplicationExit += new EventHandler(HandleDisconnectByApplicationShutdown);
    5593        }
    5694
    57         public void setConnectionState(bool newState)
     95        /// <summary>
     96        /// Changes the current connection state to the P2P network.
     97        /// If there is currently no connection, it will try to connect.
     98        /// If a connection is present, it will disconnect.
     99        /// The actual work will be done asynchronous.
     100        /// </summary>
     101        public void ToggleConnectionState()
    58102        {
    59             // TODO implement logic for handling connects/disconnects
    60             isP2PNetworkConnected = newState;
     103            new ConnectionWorker(P2PBase, P2PSettings, P2PButton).Start();
    61104        }
    62105
    63         public bool getP2PConnectionState()
     106        public bool P2PConnected()
    64107        {
    65             return isP2PNetworkConnected;
     108            return P2PBase.Started;
    66109        }
     110
     111        #region DHT operations
     112        // TODO add error handling, if P2P if not connected
     113        public static bool Store(string key, byte[] data)
     114        {
     115            return INSTANCE.P2PBase.SynchStore(key, data);
     116        }
     117
     118        public static byte[] Retrieve(string key)
     119        {
     120            return INSTANCE.P2PBase.SynchRetrieve(key);
     121        }
     122
     123        public static bool Remove(string key)
     124        {
     125            return INSTANCE.P2PBase.SynchRemove(key);
     126        }
     127        #endregion DHT operations
     128
     129        // to forward event from overlay/dht MessageReceived-Event from P2PBase
     130        private void p2pBase_OnP2PMessageReceived(PeerId sourceAddr, byte[] data)
     131        {
     132            if (OnPeerMessageReceived != null)
     133                OnPeerMessageReceived(sourceAddr, data);
     134        }
     135
     136        #region Framework methods
     137        void HandleDisconnectByApplicationShutdown(object sender, EventArgs e)
     138        {
     139            if (P2PConnected())
     140            {
     141                new ConnectionWorker(P2PBase, P2PSettings, P2PButton).Start();
     142            }
     143        }
     144
     145        public void GuiLogMessage(string message, NotificationLevel logLevel)
     146        {
     147            EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, null, new GuiLogEventArgs(message, null, logLevel));
     148        }
     149        #endregion Framework methods
    67150    }
    68151}
Note: See TracChangeset for help on using the changeset viewer.