Changeset 2348


Ignore:
Timestamp:
Jan 15, 2011, 10:32:51 PM (10 years ago)
Author:
kopal
Message:
  • removed old certificate stuff
  • p2p editor now checks if certificate exists and can be loaded BEFORE trying to connect to network
  • p2p password is now encrypted using the current windows user
  • some design changes of p2p editor
Location:
trunk
Files:
2 deleted
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypP2P/CrypP2P.csproj

    r2310 r2348  
    5555  </PropertyGroup>
    5656  <ItemGroup>
    57       <Reference Include="Bootstrapper">
     57    <Reference Include="Bootstrapper">
    5858      <HintPath>..\appreferences\bootstrapper.dll</HintPath>
    5959      <Private>false</Private>
     
    159159      <LastGenOutput>P2PSettings.Designer.cs</LastGenOutput>
    160160    </None>
    161     <None Include="pap_certificates\CrypTool2.pfx" />
    162     <None Include="pap_certificates\opa.vs.uni-due.de.cer" />
    163     <None Include="pap_certificates\pap.cer" />
    164     <None Include="pap_certificates\pap0001.p12" />
    165     <None Include="pap_certificates\ServerCA.cer" />
    166161  </ItemGroup>
    167162  <ItemGroup>
     
    196191  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    197192  <PropertyGroup>
    198     <PostBuildEvent>mkdir "$(TargetDir)pap_certificates"
    199 xcopy  /E /Y /F "$(ProjectDir)pap_certificates" "$(TargetDir)pap_certificates"</PostBuildEvent>
     193    <PostBuildEvent>
     194    </PostBuildEvent>
    200195  </PropertyGroup>
    201196  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
  • trunk/CrypP2P/Internal/ConnectionManager.cs

    r2276 r2348  
    2020using Cryptool.P2P.Worker;
    2121using Cryptool.PluginBase;
     22using PeersAtPlay.CertificateLibrary.Certificates;
     23using System.IO;
    2224
    2325namespace Cryptool.P2P.Internal
     
    9395            }
    9496        }
    95 
     97       
    9698        public void Connect()
    9799        {
     
    100102                disconnected = false;
    101103                lastConnectionAttempt = DateTime.Now;
     104
     105                try
     106                {
     107                    if (CertificateServices.GetPeerCertificateByAvatar(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "PeersAtPlay" + Path.DirectorySeparatorChar + "Certificates" + Path.DirectorySeparatorChar),
     108                        P2PSettings.Default.PeerName, P2PSettings.Default.Password) == null)
     109                    {
     110                        P2PManager.GuiLogMessage("Cannot connect, account \"" + P2PSettings.Default.PeerName + "\" not found!",
     111                                                 NotificationLevel.Warning);
     112                        return;
     113                    }
     114                }
     115                catch (Exception ex)
     116                {
     117                    P2PManager.GuiLogMessage("Cannot connect using account \"" + P2PSettings.Default.PeerName + "\": " + (ex.InnerException != null ? ex.InnerException.Message : ex.Message),
     118                                                 NotificationLevel.Warning);
     119                    return;
     120                }
    102121
    103122                if (p2PBase.IsConnected || IsConnecting)
  • trunk/CrypP2P/P2PManager.cs

    r1665 r2348  
    6262            var isReadyToConnect = ConnectionManager.IsReadyToConnect();
    6363
    64             if (isReadyToConnect && isAutoconnectConfiguredOrRequested)
     64            if (isAutoconnectConfiguredOrRequested && isReadyToConnect)
    6565            {
    6666                GuiLogMessage("Connect on startup enabled. Establishing connection...", NotificationLevel.Info);
  • trunk/CrypP2P/P2PSettings.Designer.cs

    r2347 r2348  
    99//------------------------------------------------------------------------------
    1010
     11using System.Text;
     12using System.Security.Cryptography;
     13using System;
    1114namespace Cryptool.P2P {
    1215   
     
    5558            get
    5659            {
    57                 return ((string)(this["Password"]));
     60                return decrypt(((string)(this["Password"])));
    5861            }
    5962            set
    6063            {
    61                 this["Password"] = value;
    62             }
    63         }
    64        
     64                this["Password"] = encrypt(value);
     65            }
     66        }
     67
     68        /// <summary>
     69        /// Encrypts the given string using the current windows user password and converts
     70        /// this to a base64 string
     71        /// </summary>
     72        /// <param name="s"></param>
     73        /// <returns>encrypted base64 string</returns>
     74        private string encrypt(string s)
     75        {
     76            byte[] bytes = Encoding.Unicode.GetBytes(s);
     77            byte[] encBytes = ProtectedData.Protect(bytes, null, DataProtectionScope.CurrentUser);
     78            return Convert.ToBase64String(encBytes);
     79        }
     80
     81        /// <summary>
     82        /// Decrypts the given base64 string using the current windows user password
     83        /// </summary>
     84        /// <param name="s"></param>
     85        /// <returns>decrypted string</returns>
     86        private string decrypt(string s)
     87        {
     88            if (string.IsNullOrEmpty(s))
     89            {
     90                return "";
     91            }
     92            byte[] encBytes = Convert.FromBase64String(s);
     93            byte[] bytes = ProtectedData.Unprotect(encBytes, null, DataProtectionScope.CurrentUser);
     94            return Encoding.Unicode.GetString(bytes);
     95        }
     96
    6597        [global::System.Configuration.UserScopedSettingAttribute()]
    6698        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  • trunk/CrypPlugins/P2PEditor/GUI/Controls/ConnectView.xaml

    r2347 r2348  
    1111                <Label FontSize="20" HorizontalContentAlignment="Center">CrypTool 2.0</Label>
    1212                <Label FontSize="13" HorizontalContentAlignment="Center">Distributed Computing Platform</Label>               
    13                 <Image Width="200" Name="WorldIcon" Source="..\..\images\disconnected.png" RenderTransformOrigin="0.5,0.5">
     13                <Image Width="200" Name="WorldIcon" Source="..\..\images\connected.png" RenderTransformOrigin="0.5,0.5">
    1414                    <Image.RenderTransform>
    15                         <RotateTransform x:Name="WorldIconImageRotate"/>
     15                        <RotateTransform x:Name="WorldIconImageRotate" />
    1616                    </Image.RenderTransform>
    1717                </Image>
    1818                <Label>Username:</Label>
    19                 <TextBox Name="Username" TextChanged="Username_TextChanged"/>
     19                <TextBox Name="Username" TextChanged="Username_TextChanged" IsEnabled="{Binding IsP2PConnecting, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource InverseBooleanConverter}}" />
    2020                <Label>Password:</Label>
    21                 <PasswordBox Name="Password" PasswordChanged="Password_PasswordChanged"/>
     21                <PasswordBox Name="Password" PasswordChanged="Password_PasswordChanged" IsEnabled="{Binding IsP2PConnecting, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource InverseBooleanConverter}}" />
    2222                <Label>Worldname:</Label>
    23                 <TextBox Name="Worldname" TextChanged="Worldname_TextChanged" />
     23                <TextBox Name="Worldname" TextChanged="Worldname_TextChanged" IsEnabled="{Binding IsP2PConnecting, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource InverseBooleanConverter}}" />
    2424                <Label/>
    25                 <Button Name="ConnectButton" Content="Connect" Height="38" FontFamily="Consolas" FontSize="20" Click="ConnectButtonClick" IsEnabled="{Binding IsP2PConnecting, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource InverseBooleanConverter}}" />
     25                <Button Name="ConnectButton" IsDefault="True" Content="Connect" Height="38" FontFamily="Consolas" FontSize="20" Click="ConnectButtonClick" IsEnabled="{Binding IsP2PConnecting, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource InverseBooleanConverter}}" />
    2626                <Button Name="GetACertificateButton" Content="Create a new account!" FontFamily="Consolas" FontSize="12" Height="20" Margin="0,10,0,0" Click="GetACertificateButton_Click" IsEnabled="{Binding IsP2PConnecting, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource InverseBooleanConverter}}"/>
    2727                <Button Name="ForgotPassword" Content="Forgot password" FontFamily="Consolas" FontSize="12" Height="20" Margin="0,10,0,0" IsEnabled="False"/>
  • trunk/CrypPlugins/P2PEditor/GUI/Controls/ConnectView.xaml.cs

    r2347 r2348  
    55using System.Windows.Threading;
    66using System.Threading;
     7using Cryptool.P2P.Internal;
     8using PeersAtPlay.CertificateLibrary.Certificates;
     9using Cryptool.PluginBase;
     10using System.IO;
    711
    812namespace Cryptool.P2PEditor.GUI.Controls
     
    1014    public partial class ConnectTab
    1115    {
     16
    1217        public static readonly DependencyProperty IsP2PConnectingProperty =
    1318            DependencyProperty.Register("IsP2PConnecting",
     
    2530        public ConnectTab()
    2631        {
    27             InitializeComponent();           
     32            InitializeComponent();
     33
     34            P2PManager.ConnectionManager.OnP2PTryConnectingStateChangeOccurred += new ConnectionManager.P2PTryConnectingStateChangeEventHandler(delegate(object sender, bool newState)
     35            {
     36                if (newState)
     37                {
     38                    ((P2PEditorPresentation)P2PEditor.Presentation).UpdateConnectionState();
     39
     40                    Storyboard storyboard = (Storyboard)FindResource("AnimateBigWorldIcon");
     41                    storyboard.Begin();   
     42                }
     43                else
     44                {
     45                    ((P2PEditorPresentation)P2PEditor.Presentation).UpdateConnectionState();
     46
     47                    Storyboard storyboard = (Storyboard)FindResource("AnimateBigWorldIcon");
     48                    storyboard.Stop();   
     49                }
     50            });
     51
    2852        }
    2953
    3054        private void ConnectButtonClick(object sender, RoutedEventArgs e)
    31         {           
     55        {
     56            try
     57            {
     58                if (CertificateServices.GetPeerCertificateByAvatar(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "PeersAtPlay" + Path.DirectorySeparatorChar + "Certificates" + Path.DirectorySeparatorChar),
     59                    P2PSettings.Default.PeerName, P2PSettings.Default.Password) == null)
     60                {
     61                    System.Windows.MessageBox.Show("Cannot connect, account \"" + P2PSettings.Default.PeerName + "\" not found!", "Can not connect.");
     62                    return;
     63                }
     64            }
     65            catch (NoCertificateFoundException)
     66            {
     67                System.Windows.MessageBox.Show("Cannot connect, account \"" + P2PSettings.Default.PeerName + "\" not found!", "Can not connect.");
     68                return;
     69            }           
     70            catch (Exception ex)
     71            {
     72                System.Windows.MessageBox.Show("Cannot connect using account \"" + P2PSettings.Default.PeerName + "\": " + (ex.InnerException != null ? ex.InnerException.Message : ex.Message), "Can not connect.");
     73                return;
     74            }
     75
    3276            if (!P2PManager.IsConnected)
    3377                P2PManager.Connect();
    34 
    35             ((P2PEditorPresentation) P2PEditor.Presentation).UpdateConnectionState();
    36            
    37             Storyboard storyboard = (Storyboard)FindResource("AnimateBigWorldIcon");               
    38             storyboard.Begin();               
    39 
    4078        }
    4179
     
    69107            this.Username.Text = ((P2PEditorSettings)((P2PEditor)GetValue(P2PEditorProperty)).Settings).PeerName;
    70108            this.Worldname.Text = ((P2PEditorSettings)((P2PEditor)GetValue(P2PEditorProperty)).Settings).WorldName;
    71             this.Password.Password = ((P2PEditorSettings)((P2PEditor)GetValue(P2PEditorProperty)).Settings).Password;
    72            
    73             Storyboard storyboard = (Storyboard)FindResource("AnimateBigWorldIcon");
    74             if (IsP2PConnecting)
    75             {
    76                 storyboard.Begin();
    77             }
    78             else
    79             {
    80                 storyboard.Stop();
    81             }
     109            this.Password.Password = ((P2PEditorSettings)((P2PEditor)GetValue(P2PEditorProperty)).Settings).Password;                   
    82110        }
    83111    }
  • trunk/CrypPlugins/P2PEditor/P2PEditor.csproj

    r2347 r2348  
    4646    <Reference Include="System.Data.Linq" />
    4747    <Reference Include="System.Drawing" />
     48    <Reference Include="System.Security" />
    4849    <Reference Include="System.Windows.Forms" />
    4950    <Reference Include="System.Xaml" />
  • trunk/CrypPlugins/P2PEditor/P2PEditorSettings.cs

    r2334 r2348  
    2121using Cryptool.PluginBase;
    2222using Cryptool.Plugins.PeerToPeer.Internal;
     23using System.Text;
     24using System.Security.Cryptography;
     25using System;
    2326
    2427namespace Cryptool.P2PEditor
  • trunk/CrypPlugins/PeerToPeerBase/P2PPeer.cs

    r2269 r2348  
    204204                // to forward event from overlay/dht MessageReceived-Event from P2PBase
    205205                this.p2pBase.OnP2PMessageReceived += new P2PBase.P2PMessageReceived(p2pBase_OnP2PMessageReceived);
    206 
    207                 if (CheckAndInstallPAPCertificates())
     206               
     207                this.p2pBase.Initialize(this.settings.P2PPeerName, this.settings.P2PWorldName,
     208                    (P2PLinkManagerType)this.settings.P2PLinkMngrType, (P2PBootstrapperType)this.settings.P2PBSType,
     209                    (P2PArchitecture)this.settings.P2PArchitecture);
     210                this.PeerStarted = this.p2pBase.SynchStart();
     211
     212                if (this.PeerStarted)
    208213                {
    209                     this.p2pBase.Initialize(this.settings.P2PPeerName, this.settings.P2PWorldName,
    210                         (P2PLinkManagerType)this.settings.P2PLinkMngrType, (P2PBootstrapperType)this.settings.P2PBSType,
    211                         (P2PArchitecture)this.settings.P2PArchitecture);
    212                     this.PeerStarted = this.p2pBase.SynchStart();
    213 
    214                     if (this.PeerStarted)
    215                     {
    216                         this.settings.PeerStatusChanged(P2PPeerSettings.PeerStatus.Online);
    217                     }
    218                     string joiningStatus = this.PeerStarted == true ? "successful" : "canceled";
    219                     GuiLogMessage("Status of joining the P2P System: " + joiningStatus, NotificationLevel.Info);
     214                    this.settings.PeerStatusChanged(P2PPeerSettings.PeerStatus.Online);
    220215                }
    221                 else
    222                 {
    223                     GuiLogMessage("Because not all p2p certificates were installed, you can't start the p2p system!", NotificationLevel.Error);
    224                 }
     216                string joiningStatus = this.PeerStarted == true ? "successful" : "canceled";
     217                GuiLogMessage("Status of joining the P2P System: " + joiningStatus, NotificationLevel.Info);
     218               
    225219            }
    226220            else
     
    254248                GuiLogMessage("Peer is already stopped!", NotificationLevel.Info);
    255249            }
    256         }
    257 
    258         /// <summary>
    259         /// Checks if all certificates for using the pap p2p system are installed.
    260         /// Otherwise it tries to install the missing certificates. If all operations
    261         /// succeed, return value is true. Only when value is true, you can try
    262         /// to initialize the PAP System.
    263         /// </summary>
    264         /// <returns>If all operations succeed, return value is true. Only when value
    265         /// is true, you can try to initialize the PAP System.</returns>
    266         private bool CheckAndInstallPAPCertificates()
    267         {
    268             bool retValue = false;
    269 
    270             // get exe directory, because there resides the certificate directory
    271             System.Reflection.Assembly assemb = System.Reflection.Assembly.GetEntryAssembly();
    272             string applicationDir = System.IO.Path.GetDirectoryName(assemb.Location);
    273             // check if all necessary certs are installed
    274             GuiLogMessage("Check installation of all certificates, which are necessary to run the p2p system", NotificationLevel.Info);
    275             List<PAPCertificate.PAP_Certificates> lstMissingCerts = PAPCertificate.CheckAvailabilityOfPAPCertificates(applicationDir);
    276             if (lstMissingCerts.Count == 0)
    277             {
    278                 GuiLogMessage("All neccessary p2p certificates are installed.", NotificationLevel.Info);
    279                 retValue = true;
    280             }
    281             else
    282             {
    283                 StringBuilder sbMissingCerts = new StringBuilder();
    284                 for (int i = 0; i < lstMissingCerts.Count; i++)
    285                 {
    286                     sbMissingCerts.AppendLine(Enum.GetName(typeof(PAPCertificate.PAP_Certificates),lstMissingCerts[i]));
    287                 }
    288                 GuiLogMessage("Following certificates are missing. They will be installed now.\n" + sbMissingCerts.ToString(), NotificationLevel.Info);
    289 
    290                 // try/catch neccessary because the CT-Editor doesn't support the whole exception display process (e.g. shows only "unknown error.")
    291                 try
    292                 {
    293                     if (PAPCertificate.InstallMissingCertificates(lstMissingCerts, applicationDir))
    294                     {
    295                         GuiLogMessage("Installation of all missing certificates was successful.", NotificationLevel.Info);
    296                         retValue = true;
    297                     }
    298                     else
    299                     {
    300                         GuiLogMessage("No/not all missing certificates were installed successful.", NotificationLevel.Error);
    301                     }
    302                 }
    303                 catch (Exception ex)
    304                 {
    305                     GuiLogMessage("Error occured while installing certificates. Exception: " + ex.ToString(), NotificationLevel.Error);
    306                 }
    307             }
    308             return retValue;
    309         }
     250        }       
    310251
    311252        public void LogInternalState()
  • trunk/CrypPlugins/PeerToPeerBase/P2PPeerSettings.cs

    r2269 r2348  
    8787        #region Setting-Fields
    8888
    89         private string p2pPeerName = PAPCertificate.CERTIFIED_PEER_NAME;
     89        private string p2pPeerName = "";
    9090        [TaskPane("P2P Username", "Your username for the peers@play-system. Note that you need to have a corresponding certificate installed on your computer. If you don't know what this means, just leave the default \"CrypTool2\"-username and everything will be taken care of.", null, 0, false, ControlType.TextBox)]
    9191        public string P2PPeerName
  • trunk/CrypPlugins/PeerToPeerBase/PeerToPeerBase.csproj

    r2310 r2348  
    5555  </PropertyGroup>
    5656  <ItemGroup>
    57       <Reference Include="Bootstrapper">
     57    <Reference Include="Bootstrapper">
    5858      <HintPath>..\..\appreferences\bootstrapper.dll</HintPath>
    5959      <Private>false</Private>
     
    164164      <Private>False</Private>
    165165    </ProjectReference>
    166     <ProjectReference Include="..\PeerToPeerCertificates\PeerToPeerCertificates.csproj">
    167       <Project>{7BED5C93-30BE-47BE-BC4A-16453F5DE9EA}</Project>
    168       <Name>PeerToPeerCertificates</Name>
    169       <Private>False</Private>
    170     </ProjectReference>
    171166    <ProjectReference Include="..\PeerToPeer\PeerToPeer.csproj">
    172167      <Project>{12829116-8FAD-4D09-A0AA-D75D88F07626}</Project>
  • trunk/CrypTool 2.0.sln

    r2310 r2348  
    186186EndProject
    187187Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PeerToPeerBase", "CrypPlugins\PeerToPeerBase\PeerToPeerBase.csproj", "{A7CD30E7-5381-40CF-BB78-268EC998CCB3}"
    188 EndProject
    189 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PeerToPeerCertificates", "CrypPlugins\PeerToPeerCertificates\PeerToPeerCertificates.csproj", "{7BED5C93-30BE-47BE-BC4A-16453F5DE9EA}"
    190188EndProject
    191189Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PeerToPeerPublisher", "CrypPlugins\PeerToPeerPublisher\PeerToPeerPublisher.csproj", "{A1E7F287-DFC1-44C2-A681-C62DF46B43C5}"
     
    629627                {A7CD30E7-5381-40CF-BB78-268EC998CCB3}.Release|x86.ActiveCfg = Release|x86
    630628                {A7CD30E7-5381-40CF-BB78-268EC998CCB3}.Release|x86.Build.0 = Release|x86
    631                 {7BED5C93-30BE-47BE-BC4A-16453F5DE9EA}.Debug|x86.ActiveCfg = Debug|x86
    632                 {7BED5C93-30BE-47BE-BC4A-16453F5DE9EA}.Debug|x86.Build.0 = Debug|x86
    633                 {7BED5C93-30BE-47BE-BC4A-16453F5DE9EA}.Release|x86.ActiveCfg = Release|x86
    634                 {7BED5C93-30BE-47BE-BC4A-16453F5DE9EA}.Release|x86.Build.0 = Release|x86
    635629                {A1E7F287-DFC1-44C2-A681-C62DF46B43C5}.Debug|x86.ActiveCfg = Debug|x86
    636630                {A1E7F287-DFC1-44C2-A681-C62DF46B43C5}.Debug|x86.Build.0 = Debug|x86
     
    778772                {0FEE94EF-C54B-496D-AA98-7E4682B2280B} = {775BB529-52BD-4B18-A092-E4EA70E53838}
    779773                {A7CD30E7-5381-40CF-BB78-268EC998CCB3} = {775BB529-52BD-4B18-A092-E4EA70E53838}
    780                 {7BED5C93-30BE-47BE-BC4A-16453F5DE9EA} = {775BB529-52BD-4B18-A092-E4EA70E53838}
    781774                {A1E7F287-DFC1-44C2-A681-C62DF46B43C5} = {775BB529-52BD-4B18-A092-E4EA70E53838}
    782775                {612FEE87-F51F-4BE6-81D1-F91EA4A5DD43} = {775BB529-52BD-4B18-A092-E4EA70E53838}
Note: See TracChangeset for help on using the changeset viewer.