Changeset 2408


Ignore:
Timestamp:
Jan 21, 2011, 2:28:52 PM (10 years ago)
Author:
kopal
Message:
  • added auto download of certificate data
  • increased space in gui for messages / error messages
Location:
trunk/CrypPlugins/P2PEditor/GUI/Controls
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/P2PEditor/GUI/Controls/ActivateEmailView.xaml

    r2390 r2408  
    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="693">
     6             d:DesignHeight="310" d:DesignWidth="693">
    77    <Grid>
    88    <ScrollViewer Name="ActivatePage" VerticalScrollBarVisibility="Auto">
    9         <Grid Height="280" Width="670">
     9        <Grid Height="310" Width="670">
    1010            <Grid.ColumnDefinitions>
    1111                <ColumnDefinition Width="110" />
     
    1414            <Grid.RowDefinitions>
    1515                <RowDefinition Height="100"/>
    16                 <RowDefinition Height="28"/>
     16                <RowDefinition Height="56"/>
    1717                <RowDefinition Height="28"/>
    1818                <RowDefinition Height="28"/>
     
    4545        <Image Name="Account" Source="..\..\images\account.png"  Margin="5,5,5,5" Width="48" />
    4646        <TextBlock Grid.ColumnSpan="2" Margin="15,15,15,15" FlowDirection="LeftToRight" HorizontalAlignment="Center">
    47         Your new account was successfully activatend and can now be used.
     47        Your new account was successfully activated and can now be used.
    4848        <LineBreak/>
    4949        Press the OK button to proceed.
  • trunk/CrypPlugins/P2PEditor/GUI/Controls/ConnectView.xaml.cs

    r2379 r2408  
    1010using System.IO;
    1111using System.ComponentModel;
     12using PeersAtPlay.CertificateLibrary.Network;
    1213
    1314namespace Cryptool.P2PEditor.GUI.Controls
     
    5960        }
    6061
     62        private bool HaveCertificate { get; set; }
     63        private bool EmailVerificationRequired { get; set; }
     64        private bool WrongPassword { get; set; }
     65
    6166        private void ConnectButtonClick(object sender, RoutedEventArgs e)
    6267        {
    6368            this.MessageLabel.Visibility = Visibility.Hidden;
     69            HaveCertificate = true;
     70            EmailVerificationRequired = false;
     71            WrongPassword = false;
    6472            try
    6573            {
    6674                if (CertificateServices.GetPeerCertificateByAvatar(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "PeersAtPlay" + Path.DirectorySeparatorChar + "Certificates" + Path.DirectorySeparatorChar),
    6775                    P2PSettings.Default.PeerName, P2PBase.DecryptString(P2PSettings.Default.Password)) == null)
    68                 {
    69                     this.MessageLabel.Content = "Cannot connect, account \"" + P2PSettings.Default.PeerName + "\" not found!";
     76                {                   
     77                    HaveCertificate = false;               
     78                }
     79            }
     80            catch (NoCertificateFoundException)
     81            {
     82                HaveCertificate = false;
     83            }           
     84            catch (Exception ex)
     85            {
     86                this.MessageLabel.Content = "Cannot connect using account \"" + P2PSettings.Default.PeerName + "\": " + (ex.InnerException != null ? ex.InnerException.Message : ex.Message);
     87                this.MessageLabel.Visibility = Visibility.Visible;
     88                return;
     89            }
     90            if(!HaveCertificate){
     91                try
     92                {
     93                    //we did not find a fitting certificate, so we just try to download one:
     94                    CertificateClient certificateClient = new CertificateClient();
     95                    certificateClient.TimeOut = 5;
     96                    certificateClient.ProgramName = System.Reflection.Assembly.GetEntryAssembly().GetName().Name;
     97                    certificateClient.ProgramVersion = System.Reflection.Assembly.GetEntryAssembly().GetName().Version.ToString();
     98                    certificateClient.InvalidCertificateRequest += InvalidCertificateRequest;
     99                    certificateClient.CertificateReceived += CertificateReceived;
     100                    certificateClient.RequestCertificate(new CertificateRequest(P2PSettings.Default.PeerName, null, P2PBase.DecryptString(P2PSettings.Default.Password)));
     101                }
     102                catch (Exception ex)
     103                {
     104                    this.MessageLabel.Content = "Error while autodownloading your account data: " + ex.Message;
    70105                    this.MessageLabel.Visibility = Visibility.Visible;
    71106                    return;
    72107                }
    73108            }
    74             catch (NoCertificateFoundException)
    75             {
     109
     110            //user entered the wrong password and the cert could not be download
     111            if (WrongPassword)
     112            {
     113                this.MessageLabel.Content = "Your password was wrong. We could not autodownload your account data.";
     114                this.MessageLabel.Visibility = Visibility.Visible;
     115                return;
     116            }
     117
     118            //we used login data, but our email was not authorized
     119            if (EmailVerificationRequired)
     120            {
     121                this.MessageLabel.Content = "The email address was not verified.\nPlease check your email account for an activation code we just sent to you and activate your account.";
     122                this.MessageLabel.Visibility = Visibility.Visible;
     123                return;
     124            }
     125
     126            //if we are here we did not find a fitting certificate in users appdate and could not download a certificate
     127            if (!HaveCertificate)
     128            {
     129               
    76130                this.MessageLabel.Content = "Cannot connect, account \"" + P2PSettings.Default.PeerName + "\" not found!";
    77                 this.MessageLabel.Visibility = Visibility.Visible;
    78                 return;
    79             }           
    80             catch (Exception ex)
    81             {
    82                 this.MessageLabel.Content = "Cannot connect using account \"" + P2PSettings.Default.PeerName + "\": " + (ex.InnerException != null ? ex.InnerException.Message : ex.Message);
    83131                this.MessageLabel.Visibility = Visibility.Visible;
    84132                return;
     
    87135            if (!P2PManager.IsConnected)
    88136                P2PManager.Connect();
     137        }
     138
     139        public void InvalidCertificateRequest(object sender, ProcessingErrorEventArgs args)
     140        {           
     141            switch (args.Type)
     142            {
     143                case ErrorType.EmailNotYetVerified:
     144                    EmailVerificationRequired = true;
     145                    break;
     146                case ErrorType.WrongPassword:
     147                    WrongPassword = true;
     148                    break;
     149            }
     150        }
     151
     152        public void CertificateReceived(object sender, CertificateReceivedEventArgs args)
     153        {
     154            try
     155            {
     156                args.Certificate.SaveCrtToAppData();
     157                args.Certificate.SavePkcs12ToAppData(args.Certificate.Password);
     158                HaveCertificate = true;
     159            }
     160            catch (Exception ex)
     161            {
     162                this.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     163                {
     164                    this.MessageLabel.Content = "Could not save the received certificate to your AppData folder:\n\n" +
     165                        (ex.GetBaseException() != null && ex.GetBaseException().Message != null ? ex.GetBaseException().Message : ex.Message);
     166                    this.MessageLabel.Visibility = Visibility.Visible;
     167                }, null);
     168            }
    89169        }
    90170
  • trunk/CrypPlugins/P2PEditor/GUI/Controls/GetNewCertificateView.xaml

    r2390 r2408  
    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="340" d:DesignWidth="693">
     6             d:DesignHeight="360" d:DesignWidth="693">
    77    <Grid>
    88    <ScrollViewer Name="RequestPage" VerticalScrollBarVisibility="Auto">
    9         <Grid Height="320" Width="670">
     9        <Grid Height="350" Width="670">
    1010            <Grid.ColumnDefinitions>
    1111                <ColumnDefinition Width="110" />
     
    1414            <Grid.RowDefinitions>
    1515                <RowDefinition Height="100"/>
    16                 <RowDefinition Height="28"/>
     16                <RowDefinition Height="56"/>
    1717                <RowDefinition Height="28"/>
    1818                <RowDefinition Height="28" />
     
    2222                    <RowDefinition Height="12*" />
    2323                </Grid.RowDefinitions>
    24             <Label Content="Account Creation"  Grid.ColumnSpan="2" Margin="0,0,0,56" FontSize="15" FontWeight="Bold" HorizontalAlignment="Center" />
    25             <TextBlock Grid.ColumnSpan="2" Margin="5,32,0,0" FlowDirection="LeftToRight" HorizontalAlignment="Center">
     24                <Label Content="Account Creation"  Grid.ColumnSpan="2" Margin="0,0,0,56" FontSize="15" FontWeight="Bold" HorizontalAlignment="Center"/>
     25                <TextBlock Grid.ColumnSpan="2" Margin="5,32,0,0" FlowDirection="LeftToRight" HorizontalAlignment="Center">
    2626            Please enter the data below to request your own personal account (needed for participating in distributed
    2727            <LineBreak/>
  • trunk/CrypPlugins/P2PEditor/GUI/Controls/GetNewCertificateView.xaml.cs

    r2399 r2408  
    9898                    this.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    9999                    {
    100                         this.MessageLabel.Content = "Registration successful. To activate your account, you need to validate your email address. A verification code was sent per email.";
     100                        this.MessageLabel.Content = "Registration successful. To activate your account, you need to validate your email address.\n A verification code was sent per email.";
     101                        this.UsernameField.Text = "";
     102                        this.EmailField.Text = "";
     103                        this.PasswordField.Password = "";
     104                        this.ConfirmField.Password = "";
    101105                        this.MessageLabel.Visibility = Visibility.Visible;
    102106                    }, null);
Note: See TracChangeset for help on using the changeset viewer.