public AuthUserPublicKeyEventArgs(string userName, SshPublicKey publicKey)
     : base(userName)
 {
     this.PublicKey = publicKey;
     this.Result = AuthenticationResult.Failure;
 }
 public AuthUserHostBasedEventArgs(string userName, string clientHostName,
     string clientUserName, SshPublicKey publicKey)
     : base(userName)
 {
     this.ClientHostName = clientHostName;
     this.ClientUserName = clientUserName;
     this.PublicKey = publicKey;
 }
 public void ImportPublicKey(SshPublicKey key)
 {
     // Import only public key parameters.
     LoadKeyAndCertificatesData(key.KeyAndCertificatesData);
 }
예제 #4
0
        public static SshPublicKey FromStream(Stream stream)
        {
            var obj = new SshPublicKey();

            using (var reader = new StreamReader(stream, Encoding.ASCII))
            {
                // Read lines from stream.
                string curLine;
                bool beginMarkerFound = false;
                bool endMarkerFound = false;
                StringBuilder headerBuilder = null;
                bool headerContinued = false;
                StringBuilder keyDataBuilder = new StringBuilder();

                while ((curLine = reader.ReadLine()) != null)
                {
                    // Check if line is begin marker.
                    if (curLine == _beginMarker)
                    {
                        beginMarkerFound = true;
                        headerBuilder = new StringBuilder();
                        continue;
                    }

                    // Check if line is end marker.
                    if (curLine == _endMarker)
                    {
                        endMarkerFound = true;
                        continue;
                    }

                    // Check that line is between begin and end markers.
                    if (!beginMarkerFound || endMarkerFound) continue;

                    // Check if line is start of header.
                    bool isHeaderStart = (curLine.IndexOf(':') >= 0);

                    if (isHeaderStart && headerBuilder.Length > 0)
                    {
                        // Read last header from text.
                        obj.ReadHeader(headerBuilder.ToString());

                        // Begin new header.
                        headerBuilder = new StringBuilder();
                    }

                    // Check if line is part of header.
                    if (isHeaderStart || headerContinued)
                    {
                        // Check if header is continued onto next line.
                        headerContinued = (curLine[curLine.Length - 1] == '\\');

                        // Append current line to current header.
                        headerBuilder.Append(curLine.Substring(0, curLine.Length - (headerContinued ?
                            1 : 0)));
                    }
                    else
                    {
                        // Check if last header has been read yet.
                        if (headerBuilder != null && headerBuilder.Length > 0)
                        {
                            // Read last header from text.
                            obj.ReadHeader(headerBuilder.ToString());

                            headerBuilder = null;
                        }

                        // Append current line to key data.
                        keyDataBuilder.Append(curLine);
                    }
                }

                // Decode key data.
                obj.KeyAndCertificatesData = Convert.FromBase64String(keyDataBuilder.ToString());
            }

            return obj;
        }
예제 #5
0
        public static SshPublicKey FromStream(Stream stream)
        {
            var obj = new SshPublicKey();

            using (var reader = new StreamReader(stream, Encoding.ASCII))
            {
                // Read lines from stream.
                string        curLine;
                bool          beginMarkerFound = false;
                bool          endMarkerFound   = false;
                StringBuilder headerBuilder    = null;
                bool          headerContinued  = false;
                StringBuilder keyDataBuilder   = new StringBuilder();

                while ((curLine = reader.ReadLine()) != null)
                {
                    // Check if line is begin marker.
                    if (curLine == _beginMarker)
                    {
                        beginMarkerFound = true;
                        headerBuilder    = new StringBuilder();
                        continue;
                    }

                    // Check if line is end marker.
                    if (curLine == _endMarker)
                    {
                        endMarkerFound = true;
                        continue;
                    }

                    // Check that line is between begin and end markers.
                    if (!beginMarkerFound || endMarkerFound)
                    {
                        continue;
                    }

                    // Check if line is start of header.
                    bool isHeaderStart = (curLine.IndexOf(':') >= 0);

                    if (isHeaderStart && headerBuilder.Length > 0)
                    {
                        // Read last header from text.
                        obj.ReadHeader(headerBuilder.ToString());

                        // Begin new header.
                        headerBuilder = new StringBuilder();
                    }

                    // Check if line is part of header.
                    if (isHeaderStart || headerContinued)
                    {
                        // Check if header is continued onto next line.
                        headerContinued = (curLine[curLine.Length - 1] == '\\');

                        // Append current line to current header.
                        headerBuilder.Append(curLine.Substring(0, curLine.Length - (headerContinued ?
                                                                                    1 : 0)));
                    }
                    else
                    {
                        // Check if last header has been read yet.
                        if (headerBuilder != null && headerBuilder.Length > 0)
                        {
                            // Read last header from text.
                            obj.ReadHeader(headerBuilder.ToString());

                            headerBuilder = null;
                        }

                        // Append current line to key data.
                        keyDataBuilder.Append(curLine);
                    }
                }

                // Decode key data.
                obj.KeyAndCertificatesData = Convert.FromBase64String(keyDataBuilder.ToString());
            }

            return(obj);
        }