Ejemplo n.º 1
0
        /*
         * LexicographicalOrdering Implementation:
         */
        public int CompareTo(ECKeyPair other)
        {
            if (other == null)
            {
                return(1);
            }

            bool publicKeyCompare = !other.HasPrivateKey || !HasPrivateKey;

            var thisHex  = publicKeyCompare ? PublicKeyCompressed.ToHex() : PrivateKeyData.ToHex();
            var otherHex = publicKeyCompare ? other.PublicKeyCompressed.ToHex(): other.PrivateKeyData.ToHex();

            return(String.Compare(thisHex, otherHex, StringComparison.Ordinal));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Occurs when an item in the list of available keys is clicked.
        /// </summary>
        /// <param name="sender">The object where the event handler is attached.</param>
        /// <param name="e">The event data.</param>
        private async void Keys_ItemClick(object sender, ItemClickEventArgs e)
        {
            PrivateKeyData privateKeyData = e.ClickedItem as PrivateKeyData;

            if (e.ClickedItem == null)
            {
                return;
            }

            MessageDialog dlg = null;

            try
            {
                PrivateKeyFile privateKey;
                using (var privateKeyStream = new MemoryStream(privateKeyData.Data))
                {
                    privateKey = new PrivateKeyFile(privateKeyStream);
                }

                var addedAgentKey = PrivateKeyAgentManager.PrivateKeyAgent.AddSsh2(privateKey.HostKey, privateKeyData.FileName);
                if (addedAgentKey != null)
                {
                    this.AgentKeys.Add(addedAgentKey);
                }
                else
                {
                    dlg = new MessageDialog("This private key is already loaded into the agent.", "Error loading private key");
                }
                this.SetEmptyHintVisibilities();
            }
            catch (SshPassPhraseNullOrEmptyException)
            {
                var clickedItem = ((ListViewBase)sender).ContainerFromItem(e.ClickedItem);
                this.loadKeyPasswordErrorTextBlock.Visibility = Visibility.Collapsed;
                this.loadKeyPasswordBox.Tag = e.ClickedItem;
                Flyout.GetAttachedFlyout((ListViewBase)this.keysGridView).ShowAt((FrameworkElement)clickedItem);
                this.loadKeyPasswordBox.Focus(FocusState.Programmatic);
            }
            catch (SshException ex)
            {
                dlg = new MessageDialog(ex.Message, "Error loading private key");
            }

            if (dlg != null)
            {
                await dlg.ShowAsync();
            }
        }
Ejemplo n.º 3
0
 internal static IStrongNameKeyInfo LoadStrongNameKeyData(Stream targetStream, bool @private = true)
 {
     if (@private)
     {
         PrivateKeyData targetData = new PrivateKeyData();
         using (var targetReader = new BinaryReader(targetStream))
             targetData.Read(targetReader);
         var data = targetData.GetData();
         StrongNamePrivateKeyInfo result = new StrongNamePrivateKeyInfo(data.Item3, data.Item2, data.Item1, (int)targetData.header.BitLength);
         return(result);
     }
     else
     {
         PublicKeyData targetData = new PublicKeyData();
         using (var targetReader = new BinaryReader(targetStream))
             targetData.Read(targetReader);
         return(targetData);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Occurs when the load key button is clicked.
        /// </summary>
        /// <param name="sender">The object where the event handler is attached.</param>
        /// <param name="e">The event data.</param>
        private async void keyLoadButton_Click(object sender, RoutedEventArgs e)
        {
            PrivateKeyData privateKeyData = this.loadKeyPasswordBox.Tag as PrivateKeyData;

            if (privateKeyData == null)
            {
                return;
            }

            try
            {
                PrivateKeyFile privateKey;
                using (var privateKeyStream = new MemoryStream(privateKeyData.Data))
                {
                    privateKey = new PrivateKeyFile(privateKeyStream, loadKeyPasswordBox.Password);
                }

                var addedAgentKey = PrivateKeyAgentManager.PrivateKeyAgent.AddSsh2(privateKey.HostKey, privateKeyData.FileName);
                if (addedAgentKey != null)
                {
                    this.AgentKeys.Add(addedAgentKey);
                }
                else
                {
                    MessageDialog dlg = new MessageDialog("This private key is already loaded into the private key agent.", "Error loading private key");
                    await dlg.ShowAsync();
                }

                Flyout.GetAttachedFlyout(this.keysGridView).Hide();
                this.SetEmptyHintVisibilities();
            }
            catch (Exception)
            {
                this.loadKeyPasswordErrorTextBlock.Text       = "Wrong password.";
                this.loadKeyPasswordErrorTextBlock.Visibility = Visibility.Visible;
                this.loadKeyPasswordBox.Focus(FocusState.Programmatic);
            }

            this.loadKeyPasswordBox.Password = string.Empty;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes the connection object with the specified connection data.
        /// </summary>
        /// <param name="connectionData">The connection data for the connection.</param>
        /// <exception cref="ObjectDisposedException">The connection object is already disposed.</exception>
        /// <exception cref="InvalidOperationException">The connection object is currently connected.</exception>
        /// <exception cref="ArgumentException">The <paramref name="connectionData"/> object contains a connection type that is not supported by the connection object.</exception>
        /// <exception cref="Exception">Some other error occured (here: the private key for the SSH authentication could not be found).</exception>
        public void Initialize(ConnectionData connectionData)
        {
            this.CheckDisposed();
            this.MustBeConnected(false);

            if (connectionData.Type != ConnectionType.Ssh)
            {
                throw new ArgumentException("ConnectionData does not use Ssh connection.", "connectionData");
            }

            this.connectionData = connectionData;

            // This is already done here instead of in the ConnectAsync method because here the PrivateKeysDataSource.GetPrivateKey method is able to access the Resources.
            if (connectionData.Authentication == AuthenticationType.PrivateKey)
            {
                this.privateKeyData = PrivateKeysDataSource.GetPrivateKey(connectionData.PrivateKeyName);
                if (this.privateKeyData == null)
                {
                    throw new Exception("Private Key '" + connectionData.PrivateKeyName + "' not found. Please correct the authentication details of the connection.");
                }
            }
        }
Ejemplo n.º 6
0
 internal static IStrongNameKeyInfo LoadStrongNameKeyData(byte[] data, bool @private = true)
 {
     if (@private)
     {
         using (MemoryStream targetStream = new MemoryStream(data))
         {
             PrivateKeyData targetData = new PrivateKeyData();
             using (var targetReader = new BinaryReader(targetStream))
                 targetData.Read(targetReader);
             var resultData = targetData.GetData();
             StrongNamePrivateKeyInfo result = new StrongNamePrivateKeyInfo(resultData.Item3, resultData.Item2, resultData.Item1, (int)targetData.header.BitLength);
             return(result);
         }
     }
     else
     {
         if (data.SequenceEqual(StandardPublicKey))
         {
             return(StandardPublicKeyStream.StandardPublicKey);
         }
         else if (PublicKeyData.IsDataProperLength(data))
         {
             using (MemoryStream targetStream = new MemoryStream(data))
             {
                 PublicKeyData targetData = new PublicKeyData();
                 using (var targetReader = new BinaryReader(targetStream))
                     targetData.Read(targetReader);
                 return(targetData);
             }
         }
         else
         {
             throw new ArgumentException("publicKey");
         }
     }
 }