Changeset 2378


Ignore:
Timestamp:
Jan 18, 2011, 6:18:13 PM (10 years ago)
Author:
kopal
Message:

settings are now "upgraded" too if ct2 is upgraded
certificate registration now doesnt use message boxes any more

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypP2P/P2PSettings.Designer.cs

    r2348 r2378  
    99//------------------------------------------------------------------------------
    1010
    11 using System.Text;
    12 using System.Security.Cryptography;
    13 using System;
    1411namespace Cryptool.P2P {
    1512   
     
    2926        [global::System.Configuration.UserScopedSettingAttribute()]
    3027        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    31         [global::System.Configuration.DefaultSettingValueAttribute("")]
     28        [global::System.Configuration.DefaultSettingValueAttribute("CrypTool2")]
    3229        public string PeerName {
    3330            get {
     
    5047            }
    5148        }
    52 
    53         [global::System.Configuration.UserScopedSettingAttribute()]
    54         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    55         [global::System.Configuration.DefaultSettingValueAttribute("")]
    56         public string Password
    57         {
    58             get
    59             {
    60                 return decrypt(((string)(this["Password"])));
    61             }
    62             set
    63             {
    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 
     49       
    9750        [global::System.Configuration.UserScopedSettingAttribute()]
    9851        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
     
    193146        [global::System.Configuration.UserScopedSettingAttribute()]
    194147        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    195         [global::System.Configuration.DefaultSettingValueAttribute("WebDHT")]
     148        [global::System.Configuration.DefaultSettingValueAttribute("Chord")]
    196149        public global::Cryptool.Plugins.PeerToPeer.Internal.P2PArchitecture Architecture {
    197150            get {
     
    226179            }
    227180        }
     181       
     182        [global::System.Configuration.UserScopedSettingAttribute()]
     183        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
     184        [global::System.Configuration.DefaultSettingValueAttribute("")]
     185        public string Password {
     186            get {
     187                return ((string)(this["Password"]));
     188            }
     189            set {
     190                this["Password"] = value;
     191            }
     192        }
     193       
     194        [global::System.Configuration.UserScopedSettingAttribute()]
     195        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
     196        [global::System.Configuration.DefaultSettingValueAttribute("True")]
     197        public bool UpdateFlag {
     198            get {
     199                return ((bool)(this["UpdateFlag"]));
     200            }
     201            set {
     202                this["UpdateFlag"] = value;
     203            }
     204        }
    228205    }
    229206}
  • trunk/CrypP2P/P2PSettings.settings

    r2273 r2378  
    4545      <Value Profile="(Default)" />
    4646    </Setting>
     47    <Setting Name="UpdateFlag" Type="System.Boolean" Scope="User">
     48      <Value Profile="(Default)">True</Value>
     49    </Setting>
    4750  </Settings>
    4851</SettingsFile>
  • trunk/CrypP2P/app.config

    r2273 r2378  
    5050                <value />
    5151            </setting>
     52            <setting name="UpdateFlag" serializeAs="String">
     53                <value>True</value>
     54            </setting>
    5255        </Cryptool.P2P.P2PSettings>
    5356    </userSettings>
  • trunk/CrypPlugins/P2PEditor/GUI/Controls/GetNewCertificateView.xaml

    r2347 r2378  
    44             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    55             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:GUI="clr-namespace:Cryptool.P2PEditor.GUI" mc:Ignorable="d"
    6              d:DesignHeight="280" d:DesignWidth="680">
     6             d:DesignHeight="320" d:DesignWidth="680">
    77    <Grid>
    88    <ScrollViewer Name="RequestPage" VerticalScrollBarVisibility="Auto">
    9         <Grid Height="280" Width="670">
     9        <Grid Height="320" Width="670">
    1010            <Grid.ColumnDefinitions>
    1111                <ColumnDefinition Width="75" />
     
    1515                <RowDefinition Height="90"/>
    1616                <RowDefinition Height="28"/>
     17                <RowDefinition Height="28"/>
    1718                <RowDefinition Height="28" />
    1819                <RowDefinition Height="28" />
    1920                <RowDefinition Height="28" />
    20                 <RowDefinition Height="60*" />
     21                <RowDefinition Height="80" />                   
    2122            </Grid.RowDefinitions>
    22 
    2323            <Label Content="Account Creation"  Grid.ColumnSpan="2" Margin="0,0,0,56" FontSize="15" FontWeight="Bold" HorizontalAlignment="Center" />
    2424            <TextBlock Grid.ColumnSpan="2" Margin="5,32,0,0" FlowDirection="LeftToRight" HorizontalAlignment="Center">
     
    2929            your account data. This data will be stored into your application data folder of windows.
    3030            </TextBlock>
    31             <Label Content="_Username:" Target="{Binding ElementName=UsernameField}" Grid.Row="1" Grid.Column="0" />
    32             <Label Content="_Email:" Target="{Binding ElementName=EmailField}" Grid.Row="2" Grid.Column="0" />
    33             <Label Content="_Password:" Target="{Binding ElementName=PasswordField}" Grid.Row="3" Grid.Column="0" />
    34             <Label Content="_Confirm:" Target="{Binding ElementName=ConfirmField}" Grid.Row="4" Grid.Column="0" />
     31            <Label Name="MessageLabel" Foreground="Red" Grid.Row="1" Grid.ColumnSpan="2" />
     32            <Label Content="_Username:" Target="{Binding ElementName=UsernameField}" Grid.Row="2" Grid.Column="0" />
     33            <Label Content="_Email:" Target="{Binding ElementName=EmailField}" Grid.Row="3" Grid.Column="0" />
     34            <Label Content="_Password:" Target="{Binding ElementName=PasswordField}" Grid.Row="4" Grid.Column="0" />
     35            <Label Content="_Confirm:" Target="{Binding ElementName=ConfirmField}" Grid.Row="5" Grid.Column="0" />
    3536
    36             <TextBox Text="{Binding Name}" x:Name="UsernameField" Grid.Row="1" Grid.Column="1" Height="24" />
    37             <TextBox Text="{Binding Name}" x:Name="EmailField" Grid.Row="2" Grid.Column="1" Height="24" />
    38             <PasswordBox x:Name="PasswordField" Grid.Row="3" Grid.Column="1" Height="24" />
    39             <PasswordBox x:Name="ConfirmField" Grid.Row="4" Grid.Column="1" Height="24" />
    40             <Button Name="RequestButton" Content="_Request" HorizontalAlignment="Right" Width="80" Grid.Row="5" Grid.Column="1" Height="24" Click="Request_Click" Margin="0,19,114,35" />
    41             <Button Name="BackButton" Content="_Back" Height="24" HorizontalAlignment="Right" Margin="0,19,18,35" Width="80" Grid.Row="5" Grid.Column="1" Click="BackButton_Click" />
    42             <Label Name="RequestLabel" Content="Requesting certificate..." Visibility="Hidden" Target="{Binding ElementName=ConfirmField}" Grid.Row="5" Margin="0,19,325,27" HorizontalAlignment="Right" Width="151" Grid.Column="1" FontWeight="Bold" />
    43             <Image Name="WorldIcon" Source="..\..\images\connected.png" Grid.Column="1" Margin="200,0,194,0" Grid.Row="5" RenderTransformOrigin="0.5,0.5">
     37            <TextBox Text="{Binding Name}" x:Name="UsernameField" Grid.Row="2" Grid.Column="1" Height="24" />
     38            <TextBox Text="{Binding Name}" x:Name="EmailField" Grid.Row="3" Grid.Column="1" Height="24" />
     39            <PasswordBox x:Name="PasswordField" Grid.Row="4" Grid.Column="1" Height="24" />
     40            <PasswordBox x:Name="ConfirmField" Grid.Row="5" Grid.Column="1" Height="24" />
     41            <Button Name="RequestButton" Content="_Request" HorizontalAlignment="Right" Width="80" Grid.Row="6" Grid.Column="1" Height="24" Click="Request_Click" Margin="0,19,114,35" />
     42            <Button Name="BackButton" Content="_Back" Height="24" HorizontalAlignment="Right" Margin="0,19,18,35" Width="80" Grid.Row="6" Grid.Column="1" Click="BackButton_Click" />
     43            <Label Name="RequestLabel" Content="Requesting certificate..." Visibility="Hidden" Target="{Binding ElementName=ConfirmField}" Grid.Row="6" Margin="0,19,325,27" HorizontalAlignment="Right" Width="151" Grid.Column="1" FontWeight="Bold" />
     44            <Image Name="WorldIcon" Source="..\..\images\connected.png" Grid.Column="1" Margin="200,0,194,0" Grid.Row="6" RenderTransformOrigin="0.5,0.5">
    4445                <Image.RenderTransform>
    4546                    <RotateTransform x:Name="WorldIconImageRotate"/>
  • trunk/CrypPlugins/P2PEditor/GUI/Controls/GetNewCertificateView.xaml.cs

    r2372 r2378  
    2121        public GetNewCertificate()
    2222        {
    23             InitializeComponent();
     23            InitializeComponent();           
    2424        }
    2525
    2626        private void Request_Click(object sender, RoutedEventArgs e)
    2727        {
     28            this.MessageLabel.Visibility = Visibility.Hidden;
    2829            if (!Verification.IsValidAvatar(this.UsernameField.Text))
    2930            {
    30                 System.Windows.MessageBox.Show("Username is not valid.", "Username is not valid");               
     31
     32                this.MessageLabel.Content = "Username is not valid.";
     33                this.MessageLabel.Visibility = Visibility.Visible;     
    3134                this.UsernameField.Focus();
    3235                this.UsernameField.SelectAll();
     
    3639            if (!Verification.IsValidEmailAddress(this.EmailField.Text))
    3740            {
    38                 System.Windows.MessageBox.Show("Email is not valid.", "Email is not valid");
     41                this.MessageLabel.Content = "Email is not valid.";
     42                this.MessageLabel.Visibility = Visibility.Visible;
    3943                this.EmailField.Focus();
    4044                this.EmailField.SelectAll();
     
    4448            if (this.PasswordField.Password != this.ConfirmField.Password)
    4549            {
    46                 System.Windows.MessageBox.Show("Passwords did not match", "Passwords did not match");
     50                this.MessageLabel.Content = "Passwords did not match.";
     51                this.MessageLabel.Visibility = Visibility.Visible;
    4752                this.PasswordField.Password = "";
    4853                this.ConfirmField.Password = "";
     
    5358            if (!Verification.IsValidPassword(this.PasswordField.Password))
    5459            {
    55                 System.Windows.MessageBox.Show("Password is not valid.", "Password is not valid");
     60                this.MessageLabel.Content = "Password is not valid.";
     61                this.MessageLabel.Visibility = Visibility.Visible;
    5662                this.PasswordField.Password = "";
    5763                this.ConfirmField.Password = "";
     
    8187                certificateClient.CertificateAuthorizationDenied += new EventHandler<EventArgs>(delegate
    8288                {
    83                     System.Windows.MessageBox.Show("Certificate authorization denied", "Certificate authorization denied");
     89                    this.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     90                    {
     91                        this.MessageLabel.Content = "Certificate authorization denied";
     92                        this.MessageLabel.Visibility = Visibility.Visible;
     93                    }, null);       
    8494                });
    8595
    8696                certificateClient.CertificateAuthorizationRequired += new EventHandler<EventArgs>(delegate
    8797                {
    88                     System.Windows.MessageBox.Show("Certificate authorization required", "Certificate authorization required");
     98                    this.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     99                    {
     100                        this.MessageLabel.Content = "Certificate authorization required";
     101                        this.MessageLabel.Visibility = Visibility.Visible;
     102                    }, null);
    89103                });
    90104
    91105                certificateClient.CertificateNotYetAuthorized += new EventHandler<EventArgs>(delegate
    92106                {
    93                     System.Windows.MessageBox.Show("Certificate not yet authorized", "Certificate not yet authorized");
     107                    this.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     108                    {
     109                        this.MessageLabel.Content = "Certificate not yet authorized";
     110                        this.MessageLabel.Visibility = Visibility.Visible;
     111                    }, null);
    94112                });
    95113
     
    100118                certificateClient.InvalidEmailCheck += new EventHandler<InvalidRequestEventArgs>(delegate
    101119                {
    102                     System.Windows.MessageBox.Show("Invalid email address", "Invalid email address");
     120                    this.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     121                    {
     122                        this.MessageLabel.Content = "Invalid email address";
     123                        this.MessageLabel.Visibility = Visibility.Visible;
     124                    }, null);
    103125                });
    104126
    105127                certificateClient.ServerErrorOccurred += new EventHandler<EventArgs>(delegate
    106128                {
    107                     System.Windows.MessageBox.Show("Server error occurred. Please try again later", "Server error occurred");
     129                    this.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     130                    {
     131                        this.MessageLabel.Content = "Server error occurred. Please try again later";
     132                        this.MessageLabel.Visibility = Visibility.Visible;
     133                    }, null);
    108134                });
    109135
    110136                certificateClient.NewProtocolVersion += new EventHandler<EventArgs>(delegate
    111137                {
    112                     System.Windows.MessageBox.Show("The protocol of the certificate server is different from the clients one. Please update.", "Protocol mismatch");
     138                    this.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     139                    {
     140                        this.MessageLabel.Content = "New ProtocolVersion. Please update CrypTool 2.0";
     141                        this.MessageLabel.Visibility = Visibility.Visible;
     142                    }, null);
    113143                });
    114144
     
    120150            catch (NetworkException nex)
    121151            {
    122                 System.Windows.MessageBox.Show("There was a communication problem with the server: " + nex.Message + "\n" + "Please try again later"  , "Communication problem");
     152                this.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     153                {
     154                    this.MessageLabel.Content = "There was a communication problem with the server: " + nex.Message + "\n" + "Please try again later";
     155                    this.MessageLabel.Visibility = Visibility.Visible;
     156                }, null);
    123157            }
    124158            catch (Exception ex)
    125159            {
    126                 System.Windows.MessageBox.Show("An exception occured: " + ex.Message, "Exception occured");
     160                this.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     161                {
     162                    this.MessageLabel.Content = "An exception occured: " + ex.Message;
     163                    this.MessageLabel.Visibility = Visibility.Visible;
     164                }, null);
    127165            }
    128166            finally
     
    139177                {
    140178                    case RespondType.AvatarAlreadyExists:
    141                         System.Windows.MessageBox.Show("The username already exists. Please chose another one.", "Username already exists");
     179                        this.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     180                        {
     181                            this.MessageLabel.Content = "The username already exists. Please chose another one.";
     182                            this.MessageLabel.Visibility = Visibility.Visible;
     183                        }, null);
    142184                        break;
    143185                    case RespondType.EmailAlreadyExists:
    144                         System.Windows.MessageBox.Show("The email already exists. Please chose another ones.", "Email already exists");
     186                        this.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     187                        {
     188                            this.MessageLabel.Content = "The email already exists. Please chose another ones.";
     189                            this.MessageLabel.Visibility = Visibility.Visible;
     190                        }, null);
    145191                        break;
    146192                    case RespondType.AvatarEmailAlreadyExists:
    147                         System.Windows.MessageBox.Show("The username and email already exist but the entered password was wrong. Either enter a new username and email combination or enter the correct password to receive the certificate again", "Username and email already exist");
     193                        this.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     194                        {
     195                            this.MessageLabel.Content = "The username and email already exist but the entered password was wrong.";
     196                            this.MessageLabel.Visibility = Visibility.Visible;
     197                        }, null);
    148198                        this.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    149199                        {                           ;
     
    154204                        break;
    155205                    default:
    156                         System.Windows.MessageBox.Show("Invalid certificate request: " + args.ErrorType, "Invalid certificate request");
     206                        this.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     207                        {
     208                            this.MessageLabel.Content = "Invalid certificate request: " + args.ErrorType;
     209                            this.MessageLabel.Visibility = Visibility.Visible;
     210                        }, null);
    157211                        break;
    158212                }
     
    187241            catch (Exception ex)
    188242            {
    189                 System.Windows.MessageBox.Show("Could not save the received certificate to your AppData folder:\n\n" +
    190                        (ex.GetBaseException() != null && ex.GetBaseException().Message != null ? ex.GetBaseException().Message : ex.Message),
    191                        "Error while saving the certificate");
     243                 this.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     244                        {
     245                            this.MessageLabel.Content = "Could not save the received certificate to your AppData folder:\n\n" +
     246                                (ex.GetBaseException() != null && ex.GetBaseException().Message != null ? ex.GetBaseException().Message : ex.Message);
     247                            this.MessageLabel.Visibility = Visibility.Visible;
     248                        }, null);
    192249            }
    193250            finally
  • trunk/CrypPlugins/P2PEditor/P2PEditorSettings.cs

    r2360 r2378  
    4040            this.p2PEditor = p2PEditor;
    4141            settings = P2PSettings.Default;
     42            try
     43            {
     44                if (settings.UpdateFlag)
     45                {
     46                    settings.Upgrade();
     47                    settings.UpdateFlag = false;
     48                    this.p2PEditor.GuiLogMessage("Upgrading settings", NotificationLevel.Debug);
     49                }
     50            }catch
     51            {
     52           
     53            }
    4254            UpdateSettings();
    4355        }
Note: See TracChangeset for help on using the changeset viewer.