using Rebex.Net;

Welcome to using Rebex.Net; Sign in | Join | Help
in Search

Using Rebex.Net

News and announcements about Rebex.NET components

  • HOWTO: Terminal Color Schemes

    Color schemes is one of the features of our terminal emulator control (part of Rebex SSH Shell and Rebex Telnet) that was added few months ago after one of our users requested it. What is it for? If your application communicates with a monochrome terminal, you can define a custom color scheme to assign some colors to different visual styles to make them more readable. Doing this for a colors-capable terminal application usually doesn’t make much sense (although it is possible as well), but for a monochrome application, it can be a nice visual enhancement.

    Check out the results below – a monochrome “man” command output is on the left and the output of the same command using a custom color scheme is on the right:

    man-mono man-custom

    Defining a color scheme is very simple:

    C#:

    console.Options.ColorScheme = ColorScheme.Custom;
    console.Options.SetColorIndex(SchemeColorName.Background, 0);
    console.Options.SetColorIndex(SchemeColorName.Foreground, 7); //= normal text
    console.Options.SetColorIndex(SchemeColorName.Bold, 11); //= highlighted text
    console.Options.SetColorIndex(SchemeColorName.SingleUnderline, 9);
    console.Options.SetColorIndex(SchemeColorName.DoubleUnderline, 9);
    VB.NET:
    console.Options.ColorScheme = ColorScheme.Custom
    console.Options.SetColorIndex(SchemeColorName.Background, 0)
    console.Options.SetColorIndex(SchemeColorName.Foreground, 7) ' = normal text
    console.Options.SetColorIndex(SchemeColorName.Bold, 11) ' = highlighted
    console.Options.SetColorIndex(SchemeColorName.SingleUnderline, 9)
    console.Options.SetColorIndex(SchemeColorName.DoubleUnderline, 9)
    (where console is an instance of TerminalControl)

    You might be wondering about the numbers - these are indexes to the current color palette which contains the following colors:

    0 Black 8 Dark gray
    1 Red 9 Light red
    2 Green 10 Light green
    3 Yellow 11 Light yellow
    4 Blue 12 Light blue
    5 Magenta 13 Light magenta
    6 Cyan 14 Light cyan
    7 Light gray 15 White


    On the other hand, if you prefer monochrome color scheme instead, you can simply turn color-capable terminals into monochrome by setting TerminalOption’s ColorScheme property to ColorScheme.Monochrome.

     

  • HOWTO: Transfer compression in SFTP and SSH Shell

    A feature that is requested very often is integrated transfer compression in Rebex SFTP. This is particularly useful when transferring text files or other highly compressible files, and a similar feature is already included in Rebex FTP. So why does it take so long to add this to SFTP as well? The problem is that the .NET Framework compression API is well-suited to be used in protocols utilizing stream transfer modes such as FTP, but entirely unsuitable for protocols using block transfer mode such as SSH, the underlying protocol used by SFTP.

    Fortunately, since build 3428, it is possible to enable ZLIB compression in Rebex SFTP and Rebex SSH Shell using ZlibStream for .NET, a library build on top of a C# port of JCraft's Java JZlib library. JZlib is a re-implementation of zlib in pure Java. It is covered by a BSD-style license, which makes it possible to be used for free (even in commercial closed-source applications).

    OK, so how to enable transfer compression? It is rather simple – download and install ZlibStream for .NET, add a reference to Rebex.ZlibStream.dll to your application and when connecting to an SFTP server in your code, add few additional lines:

    C#

    Sftp sftp = new Sftp();
    SshParameters parameters = new SshParameters();
    parameters.CompressionStreamType = typeof(Rebex.IO.Compression.JZlib.ZlibOutputStream);
    sftp.Connect(hostname, password, parameters);

    VB.NET

    Dim sftp As New Sftp
    Dim parameters As New SshParameters
    parameters.CompressionStreamType = GetType(Rebex.IO.Compression.JZlib.ZlibOutputStream)
    sftp.Connect(hostname, password, parameters)

    In Rebex SSH Shell, an equivalent code can be used.

    At this point, you may be asking yourself – why is this not included in Rebex components by default? There are two reasons:

    1. A BSD-style license requires that all derivative works reproduce the full text of the license in the source code and documentation. This goes against our philosophy for .NET components - we don’t want our clients to still bother with licensing issues after they purchased a license.
    2. Some of our clients have a strict no-free-software policy that forbids them from using anything based on or derived from a software using an open source license. Therefore, no free or open source code is allowed into the codebase of products we sell.

    To address this, we are currently implementing a new ZLIB compression library from scratch, without using any third-party code. Once this is finished, Rebex SFTP and SSH Shell will finally support transfer compression by default. Until then, simply use ZlibStream for .NET as described above.

  • HOWTO: Download all files from a remote FTP directory and save them to a local disk

    Quick & dirty (yet a bit naive) directory download code

    To download all files in a specified remote folder seems to be a trivial task at first. Calling Ftp.GetList(), iterating through the returned collection and caling Ftp.GetFile() on each item looks like a no brainer. It would work in simple cases. However, there are some caveats in this approach. Consider the following situations:

    • Remote directory has both files and folder with other files. Should we download the content of subdirectories too?
    • What if some of the remote files already exist on the local computer? Should they be overwritten? Skipped? Should we overwrite older files only?
    • What if the local file is not writable? Should the whole transfer fail? Should we skip the file and continue to the next?
    • How to handle files on a remote disk which are unreadable because we don’t have sufficient access rights?
    • How are the symlinks, hard links and junction points handled? Links can easily be used to create an infinite recursive directory tree structure. Consider folder A with subfolder B which in fact is not the real folder but the *nix hard link pointing back to folder A. The naive approach will end in an application which never ends (at least if nobody manage to pull the plug).

    Download the directory – resolve the conflicts automatically

    public static void DownloadFolderSimple()
    {
    using (Ftp client = new Ftp())
    {
    // connect and login to the FTP site
    client.Connect("mirror.aarnet.edu.au");
    client.Login("anonymous", "my@password");

    // download all files
    client.GetFiles(
    "/pub/fedora/linux/development/i386/os/EFI/*",
    "c:\\temp\\download",
    FtpBatchTransferOptions.Recursive,
    FtpActionOnExistingFiles.OverwriteAll
    );

    client.Disconnect();
    }
    }
    The above code solves all the issues mentioned above. The programmer decides how to resolve most conflicts. In this case existing files are overwritten, links are followed and downloaded correctly, infinite link loops are detected and handled by the component code by throwing an exception. Such code is best for unattended processing.

    What if the user needs to choose which local files should be overwritten and which not? What if we want to skip files with certain type of problem? Let’s check another scenario and give this power to the hands of the user.

    Download the directory – let the user resolve the conflicts

    public static void DownloadFolderWithUserInteraction()
    {
    using (Ftp client = new Ftp())
    {
    // connect and login to the FTP site
    client.Connect("mirror.aarnet.edu.au");
    client.Login("anonymous", "my@password");

    // subscribe to the event which occurs when transfer conflict
    // or problem occures
    client.BatchTransferProblemDetected +=
    new FtpBatchTransferProblemDetectedEventHandler
    (client_BatchTransferProblemDetected);

    // download all files
    client.GetFiles(
    "/pub/fedora/linux/development/i386/os/EFI/*",
    "c:\\temp\\download",
    FtpBatchTransferOptions.Recursive
    );

    client.Disconnect();
    }
    }


     


    static void client_BatchTransferProblemDetected(
    object sender,
    FtpBatchTransferProblemDetectedEventArgs e)
    {
    // Problem type can be found in e.ProblemType
    //
    // Actions usable for solving the specific problem
    // can be retrieved by checking flags in e.PossibleActions or
    // by calling e.IsActionPossible method.
    //
    // e.Action = MyTransferrProblemDetecttedDialog.ShowModal(e);
    //
    // See http://www.rebex.net/ftp.net/sample-batch-transfer.aspx
    // for sample implementation.
    }

    Each time the component reaches the point in which a decision has to be made the user is asked. A dialog pops up and the user is given an option to resolve the issue for the specific file or directory. He is also able to resolve all similar cases with one choice - e. g. he is given an option to either  ‘Overwrite a specific file’ or ‘Overwrite all files if older’ as shown on the screeshot.

    To see this approach implemented in a fully functional application download the component and check the FTP Batch Transfer Sample. Both C# and VB.NET code available.

  • New component: Rebex Telnet for .NET - automated shell scripting and terminal emulation

    A new component has just been released: Rebex Telnet for .NET.

    Rebex Telnet terminal emulation and automated shell scripting library for .NET languages (such as C# or VB.NET). It makes it easy to execute commands on Unix/Windows Telnet servers or add terminal emulation capabilities to your applications.

    Features include:

    • Terminal emulation - Windows Forms control and virtual (off-screen) terminal.
    • Shell scripting objects.
    • Terminal session recording and replay.
    • Samples in C# and VB.NET including WinForm Telnet Client.
    • Easy-to-follow tutorial for a quick start.
    • Complete C# source code is optionally available.
    • And more...

    Of course, Rebex Telnet was added to Rebex Total Pack as well, so if you already have an active subscription, you can download it immediately. For information about upgrading, please contact us!

    See also: Telnet component homepage | Download trial | Pricing from $249

  • Build 3428: Faster upload/download and FIPS 140-2 mode support in SFTP and lots of other enhancements

    Faster uploads and downloads in SFTP

    We are now using a new approach in file download and upload methods that take advantage of the SFTP protocol's ability to queue multiple commands. By keeping the server's command queue full all the time, a better transfer speed can be achieved. Also, several other changes that further enhance the transfer speed were included, making the SFTP component faster than ever.

    FIPS 140-2 mode in SFTP

    This was one of the most requested features recently. When using Rebex SFTP on a machine where only certified FIPS 140-2 algorithms are allowed, a FIPS 140-2 mode is enabled and non-compliant algorithms are switched off. This mode can also be enabled manually by referencing Rebex.Security.dll and setting the Rebex.Security.Cryptography.CryptoHelper.UseFipsAlgorithmsOnly property to true.

    At the moment, this feature is only available in Rebex SFTP - if you would like to one of the other components to support it as well, please let us know!

    Transfer compression support in SFTP

    Well, kind of. The problem is that the .NET's compression support is not low-level enough to be used by SFTP's underlying SSH protocol. Even though there are several third-party ZLIB implementations that are usable, these come under a BSD-like license and require the full text of the license to be included with any product which uses them, which effectively makes it unusable for us because we don't want to force our clients into this, unlike several other SFTP component vendors who do and try to hide the fact.

    So until we write a custom implementation of ZLIB, we decided to offer a .NET ZLIB library based on a port of a JCraft's BSD-style-licensed JZLib as a separate download that can be used together with Rebex SFTP to make it possible to use compression. The decision whether to include a library under a BSD-style license is therefore up to you! Another blog post will explain how this can be used to enable compression support in Rebex SFTP.

    Lots of enhancements in Rebex Mail

    The new SmtpConfiguration class makes it possible to read SMTP settings from application configuration file's /configuration/system.net/mailSettings/smtp node, making it easier to store your SMTP server configuration. Gmail's XLIST IMAP command is supported - this makes it possible to detect which folder is which even if they are using localized names. There are lots of other enhancements as well that substantially increase server compatibility - check out the full list below.

    Complete list of changes:

    • SFTP: Upload and download speed enhanced a lot using the pipelining approach.
    • SFTP: Upload and download buffer size changed from 32K to 28K because the original size resulted in two packets being sent.
    • SFTP: Added support for transfer compression through a plugged-in library.
    • SFTP: UTF-8 encoding is used by default for WS_FTP server.
    • SFTP: Fixed a misleading error message that occurs when both password and public key authentication is required by the server but the clients only supply one of the credentials.
    • SFTP: Added several workarounds for CoreFTP server's SFTP implementation that suffers from numerous bugs such as missing file attributes or half-working SSH_FXP_REALPATH command.
    • SFTP: Fixed a bug in GetFiles and PutFiles method that caused a wrong path to be used when a filename only was specified or when a root path was specified.
    • SCP: Compatibility enhancements in Scp object's PutFile method.
    • SCP: Added a workaround for Bitvise's SCP that closes the SCP channel too early.
    • FTP: Disposing Ftp object from another thread while an operation is in progress no longer causes NullReferenceException and other similar errors to occur in the operation thread.
    • FTP: Better URL handling in the Connect method (although it is hostname-only by design, lot of users actually pass URLs to it).
    • FTP: Enhanced logging of incoming connection in active mode.
    • FTP: Added a workaround for WS_FTP that requires MLST/MLSD arguments to be quoted if they contain spaces.
    • FTP: Added FtpException.Transferred property as a replacement for the misspelled FtpException.Transfered property.
    • FTP: Fixed a bug in GetRemoteChecksum method that caused it not to work for filenames that contain space characters.
    • FTP: Fixed a bug that caused FtpException's BytesTransferred property not to be set for exceptions thrown by asynchronous methods.
    • FTP: Fixed a bug in MODE B transfer mode that might cause an improper block length to be received in rare circumstances.
    • FTP: Fixed a bug in GetFiles and PutFiles method that caused a wrong path to be used when a filename only was specified or when a root path was specified.
    • MIME: Added a workaround for broken Date headers to MailMessage class - when an unparsable Date header is encountered, the date value from the topmost Received header is used instead.
    • MIME: Fixed a bug in the TNEF parser that caused an exception to be thrown when parsing rich text bodies that contain zero characters (which are perfectly legal for RTF, unfortunately).
    • MIME: MailDateTime class now supports implicit conversion from DateTime.
    • MIME: Long file name support for attachments added to TNEF (winmail.dat) parser.
    • POP3: GetMessageList no longer fails on duplicate unique IDs because RFC 1939 actually allows them.
    • POP3: Disposing Pop3 object from another thread while an operation is in progress no longer causes NullReferenceException and other similar errors to occur in the operation thread.
    • POP3: GetMessageList or GetMessageInfo methods enhanced to make them compatible with servers that return the first message line as well when retrieving headers. In previous versions, this might have occasionally lead to parsing errors.
    • POP3: Enhanced GetMessageHeaders to always retrieve the headers only - on some servers, it used to retrieve the first line of the message as well.
    • IMAP: Fixed a bug in Imap.SelectFolder method that threw ArgumentOutOfRangeExceptions on some servers.
    • IMAP: Imap.SelectFolder now accepts an empty folder name because some servers (Zarafa) use it for the root folder.
    • IMAP: Added ImapMessageInfo.GetRawHeaders method.
    • IMAP: Fixed a bug in Imap.GetMessageHeaders method that caused it to download the whole message.
    • IMAP: SelecteFolder, UnselectFolder and Disconnect methods no longer purge messages marked as Deleted in the currently selected folder. New overload of UnselectFolder method was added that makes it possible to purge the messages when needed.
    • IMAP: Headers are now fetched using BODY.PEEK[HEADER] instead of RFC822.HEADER to improve IMAP server compatibility.
    • IMAP: Added a new ImapOptions.UsePeekForGetMessage option to make it possible to avoid automatically marking downloaded messages as read.
    • IMAP: StoreRawMessage method added to make it possible to upload a raw message from a stream without parsing it.
    • IMAP: Gmail's XLIST command is used instead of LIST by default and a new property ImapFolder.Purpose was added to make it possible to detect which folder is which regardless their national name.
    • IMAP: Added workaround for IMAP servers that return NIL as a folder delimiter (slash is used instead).
    • IMAP: Added workaround for servers that return the same folder name twice for unknown reasons.
    • IMAP: Invalid IMAP response lines such as "* AVK-VIRUS-CHECK: 1" are now ignored.
    • IMAP: Added workaround for broken IMAP servers that use their default charset where modified UTF-7 is required.
    • IMAP: Disposing Imap object from another thread while an operation is in progress no longer causes NullReferenceException and other similar errors to occur in the operation thread.
    • IMAP: Added ImapMessageIfo.GetRawHeaders method.
    • IMAP: Added MimeHeader.DecodeMimeHeader method.
    • IMAP: Added workaround for Exchange 2007's IMAP server that is unable to return the proper structure of multipart/signed messages.
    • SMTP: Added support for RFC 1870 - message size declaration.
    • SMTP: Added SmtpConfiguration class that makes it possible to read SMTP settings from application configuration file's /configuration/system.net/mailSettings/smtp node.
    • SMTP: Fixed a bug that caused an exception when sending a message with embedded message entity using an 8bit content transfer encoding through a server that doesn't support 8bit MIME.
    • SMTP: Disposing Smtp object from another thread while an operation is in progress no longer causes NullReferenceException and other similar errors to occur in the operation thread.
    • Terminal: Poll method added into IShellChannel.
    • Terminal: Fixed a bug that caused the Enter key not to be echoed when local echo is on.
    • TLS/SSL: Exception thrown by the certificate verifier because of certificate hostname mismatch is more descriptive.
    • TLS/SSL: Added a workaround for vsftpd that occasionally leaks unencrypted error messages while TLS/SSL is in use, which causes an error when the client tries to decode them as proper TLS/SSL messages.
    • TLS/SSL: Fixed a bug that could cause a deadlock when closing a socket from one thread that is currently sending data using another thread.
    • TLS/SSL: Fixed possible NullReferenceException in TlsSocket class.
    • TLS/SSL: BeginSend and BeginReceive methods work again.
    • SSH Core: Added FIPS 140-2 compliant mode that is automatically enabled on systems where only compliant algorithms are allowed.
    • SSH Core: Added a new exception status - PasswordChangeRequired - that is used when a password change is required before authentication can be successfully completed.
    • Security: .PFX/P12 private key file loading support for Windows Mobile 5 and newer

  • HOWTO: Solve the “Server certificate was rejected by the verifier” exception

    If you wrote an application using Rebex FTP/SSL or Rebex Secure Mail component and get the “Server certificate was rejected by the verifier because…” error when connecting to a server secured using the TLS/SSL protocol, this HOWTO is just what you need. In order to understand the problem, at least basic understanding of public key certificates is helpful. If this is still a gray area for you, just check out our Introduction to Public Key Certificates.

    The actual exception message varies, but the reason is similar – either something is wrong with the certificate or it is not trusted by the client.

    The following exceptions can occur as a result of failed certificate verification:

    1. Server certificate was rejected by the verifier because the certificate's common name '…' does not match the hostname '…'.
    2. Server certificate was rejected by the verifier because it has expired.
    3. Server certificate was rejected by the verifier because it is revoked.
    4. Server certificate was rejected by the verifier because of an unknown certificate authority.
    5. Server certificate was rejected by the verifier because it is bad.
    6. Server certificate was rejected by the verifier because of other problem.
    7. Server certificate was rejected by the verifier because it is unsupported.

    (Previous releases of Rebex components used slightly different versions of these message, but they are very similar.)

    In general, when any of these errors occur, you have the following options:

    a) Solve the problem. These error messages indicate that something is wrong with the certificate or certificate infrastructure. Fixing the problem is the proper thing to do, although it might not be always possible. See the instructions below for a detailed descriptions of various error conditions.

    b) If this is the “common name” mismatch problem (no. 1 in the list), see the instructions below for more information.

    c) Implement a custom certificate verifier - check out the appropriate section of our FTP/SSL tutorial or Secure Mail TLS/SSL tutorial for details. Also, check out the WinFormClient sample (in Rebex FTP/SSL) or Pop3Browser/ImapBrowser samples (in Secure Mail) - these include a custom verifier that asks the user whether to accept or reject a certificate if in doubt, and it even has a capability to automatically add the certification authority certificate into the appropriate store if the problem occurred because of an unknown certification authority (no. 4) - you can simply re-use this verifier in your application or modify it to suit your needs, because the source files that implement the verifier (Verifier.cs/.vb and VerifierForm.cs/.vb) are independent of the rest of the samples.

    d) Implement a custom certificate verifier that accepts or reject certificates based on their hash code (also known as fingerprint) – this value uniquely identifies a certificate, making it possible to be used as its ID:

    C#

    // A custom certificate verifier class.
    // Implements ICertificateVerifier interface.
    public class FingerprintVerifier : ICertificateVerifier
    {
    // This method gets called during the SSL handshake
    // process when the certificate chain is received from the server.
    public TlsCertificateAcceptance Verify(
    TlsSocket socket, string commonName, CertificateChain certChain)
    {
    // get a string representation of the certificate's fingerprint
    string fingerprint = BitConverter.ToString(certChain.LeafCertificate.GetCertHash());

    // check whether the fingerprint matches the desired fingerprint
    bool ok = ...

    if (ok)
    return TlsCertificateAcceptance.Accept;
    else
    return TlsCertificateAcceptance.Other;
    }
    }

    ...

    // To make your validator the current validator for an FTP session:

    Ftp ftp = new Ftp();

    // Create an instance of TlsParameters class and
    // set the certificate verifier to an instance of CustomVerifier.
    TlsParameters par = new TlsParameters();
    par.CertificateVerifier = new FingerprintVerifier();

    // Connect securely using explicit SSL.
    // The third argument refers to the parameters class
    ftp.Connect(hostname, 21, par, FtpSecurity.Explicit);

    ...

    VB.NET

    ' A custom certificate verifier class.
    ' Implements ICertificateVerifier interface.
    Public Class FingerprintVerifier
    Implements Rebex.Net.ICertificateVerifier

    ' This method gets called during the SSL handshake
    ' process when the certificate chain is received from the server.
    Public Overloads Function Verify(ByVal socket As TlsSocket, _
    ByVal commonName As String, _
    ByVal certChain As CertificateChain) _
    As TlsCertificateAcceptance _
    Implements ICertificateVerifier.Verify

    ' get a string representation of the certificate's fingerprint
    Dim fingerprint As String = _
    BitConverter.ToString(certChain.LeafCertificate.GetCertHash())

    ' check whether the fingerprint matches the desired fingerprint
    Dim ok As Boolean = ...

    If ok Then
    Return TlsCertificateAcceptance.Accept
    Else
    Return TlsCertificateAcceptance.Other
    End If
    End Function
    End Class

    ...

    ' To make your validator the current validator for an FTP session:

    Dim ftp As New Ftp()

    ' Create an instance of TlsParameters class and
    ' set the certificate verifier to an instance of CustomVerifier.
    Dim par As New TlsParameters()
    par.CertificateVerifier = New FingerprintVerifier()

    ' Connect securely using explicit SSL.
    ' The third argument refers to the parameters class.
    ftp.Connect(hostname, 21, par, FtpSecurity.Explicit)

    ...

    In practice, an application would have to keep a database of acceptable IDs and validate certificates according to it. However, this approach deviates from a standard public key infrastructure practices and should only be used if other solutions are unsuitable.
     
    e) Use the built-in AcceptAll verifier - this will undoubtedly make the certificate accepted, but doing this in production environment is highly discouraged, as it effectively disables server authentication, bypassing one of the key features of TLS/SSL. Even though this will make it possible for you to connect to the server, there will be no proof that you are actually connected to the desired server.

    C#:

    // create an instance of TlsParameters class
    TlsParameters parameters = new TlsParameters();

    // accept any certificate (don't do this in production environment!)
    parameters.CertificateVerifier = CertificateVerifier.AcceptAll;

    // connect to the server
    ftp.Connect(hostname, 21, parameters, FtpSecurity.Explicit);

    ...

    VB.NET:

    ' create an instance of TlsParameters class
    Dim parameters As New TlsParameters()

    ' accept any certificate (don't do this in production environment!)
    parameters.CertificateVerifier = CertificateVerifier.AcceptAll;

    ' connect to the server
    ftp.Connect("www.rebex.net", 21, parameters, FtpSecurity.Explicit)

    ...

    (Please note that Rebex.Net.SecureSocket.dll has to be referenced by your project for this to compile.)

     

    Now, let’s look at the different error conditions.

     

    1. Common name does not match the hostname

    This one is usually easy to solve. The server hostname you used in the Connect method call’s serverName argument has to match the server name that is embedded in the certificate’s common name attribute (part of certificate subject string). If they don’t match, it means, for example, that the server you know as “www.rebex.net” is presenting a certificate that belongs to “server01.rebex.net”, and this is an equivalent of one guy presenting another’s passport at the airport – while the document may be entirely valid, the two just don’t belong together.

    Possible solutions:

    a) Try using the proper server name present in the certificate to connect to the server. If the certificate says the server is “server01.rebex.net” when you connect to “www.rebex.net”, then perhaps it is in fact its proper name and you wish to connect to “server01.rebex.net” instead of “www.rebex.net” which is just an alias.

    b) If the common name in the certificate cannot be used to connect to the desired server (for example, it is a local domain-less name such as “server01”), the proper thing to do is to issue a new certificate for the server that contains the correct name. If this is not possible, try the solution below.

    c) If the common name in the certificate cannot be used to connect to the desired server, but you are unable to issue a new certificate (for example if the server is not under your control), use the variant of Connect method that accepts a TlsParameters argument and specify the expected common name:

    C#:

    // create an instance of TlsParameters class
    TlsParameters parameters = new TlsParameters();

    // specify the expected common name
    parameters.CommonName = "server01";

    // connect to the server
    ftp.Connect("www.rebex.net", 21, parameters, FtpSecurity.Explicit);

    ...

    xVB.NET:

    ' create an instance of TlsParameters class
    Dim parameters As New TlsParameters()

    ' specify the expected common name
    parameters.CommonName = "server01"

    ' connect to the server
    ftp.Connect("www.rebex.net", 21, parameters, FtpSecurity.Explicit)

    ...

    d) One of our users also encountered a server that presented a different certificate with different common name each time they connected. In this situation, the only workaround is to write a custom certificate verifier using the instructions in our tutorial.

     

    2. Server certificate was rejected by the verifier because it has expired.

    This happens when the validity period of the server certificate is over. It can also happen if the validity period of one of the certification authorities in its chain is over, but this is not very common. When the certificate expires, the proper thing to do is to replace it with a new certificate. If this can’t be done (if you don’t have control over the server and its administrators are refusing to solve the problem), the solution is to write a custom certificate verifier using the instructions in our tutorial.

     

    3 Server certificate was rejected by the verifier because it is revoked.

    This is a problem that is worth paying attention to. It means that the certificate signature has been revoked by its signer and that the certificate should no longer be used and trusted. A custom certificate verifier can also override this problem, but doing so is strongly discouraged.

     

    4 Server certificate was rejected by the verifier because of an unknown certificate authority.

    This error message means that the certificate authority that issued the server certificate is not in the list of trusted authorities. For this reason, the identity of the server could not have been verified. This problem can be solved by adding the certificate of the root CA that signed the server certificate into the list of trusted certification authorities as described by the previous post about public key certifciates, or using Rebex CertificateStore class - check out the Verifier.cs/.vb file in the WinFormClient or Pop3Browser/ImapBrowser samples for information on how to do this in a custom certificate verifier.

     

    5, 6 and 7…

    The following three possible errors still remain:

    5 Server certificate was rejected by the verifier because it is bad.

    6 Server certificate was rejected by the verifier because of other problem.

    7 Server certificate was rejected by the verifier because it is unsupported.

    While no one ever reported any of these problems, they can happen. If you get one of these, please let us know and mail us the communication log produced using the new LogWriter functionality with LogLevel.Verbose.

    That’s all for today – if you are still stuck with an unusable certificate after trying all the tricks above, please let us know!

  • Introduction to Public Key Certificates

    Once every week or two, one of our customers using Rebex FTP/SSL or Rebex Secure Mail components encounters the “Server certificate was rejected by the verifier because…” error when connecting to a server secured using the TLS/SSL protocol. And even though the workings of TLS/SSL - the communication protocol using certificates and public key infrastructure to authenticate servers and clients - are sufficiently explained in our FTP/SSL tutorial and Secure Mail TLS/SSL Tutorial, we often have to provide a quick introduction into public key certificates in order to explain why the error occurred and how to solve it. Publishing this on our blog looks like a proper thing to do.

     

    Public-key cryptography

    Public-key cryptography, also known as asymmetric key cryptography, is a method for secret communication between two parties without requiring an initial exchange of secret keys. It can be used to create digital signatures, to encrypt messages using public key encryption, or to compute a shared secret key. The most common public-key cryptography algorithms used to enable secure transmission of information over the Internet ate RSA, DSA and Diffie-Hellman.

    Public-key cryptography is known as asymmetric because a key owner has a pair of two cryptographic keys – a public key and a private key. The public key may be freely distributed and published, while the private key must be kept secret and only accessible to the owner. The keys are related mathematically, but the private key cannot be feasibly derived from the public key.

    To compute a digital signature of a message, the private key is needed. However, a digital signature can be verified using the public key alone. This makes it possible for the receiver of a message and its signature to verify that message was signed by an entity that has access to the corresponding private key – the claimed sender.

    For more information, check out the Wikipedia article on public-key cryptography.

     certificate

    Public key certificate

    A certificate is a document that uses a digital signature to bind a public key with an identity (such as a person, an organization or a server). A certificate can be freely distributes (just like the public key) and does not contain any secret information – basically, all it contains is the public key, identity information, validity conditions, additional attributes, information about its signer and a signature. However, for each certificate, there is a private key that corresponds to the certificate’s public key. The private key is not a part of the certificate and must be kept secret by the identity that owns the certificate.

    Check out the picture on the right – it shows the contents of Google’s certificate used by https://www.google.com to secure user authentication.

    Public key certificates can be used for variety of purposes – the ones our users are most interested in are:

    • Secure communication using TLS/SSL protocol, where a server presents its certificate to the client to make it possible for the client to verify that it is really connected to the desired server. Optionally, a client can also present his own certificate to authenticate himself to the server. TLS/SSL is used by HTTPS (HTTP over SSL), a well-known protocol used to secure websites, but many other protocols such as FTP, SMTP, POP3 or IMAP can also utilize it.
    • E-mail signature and encryption using S/MIME. This makes it possible to sign e-mail (using sender’s secret private key), enabling others to verify the signature using the signer certificate’s public key. On the other hand, to encrypt e-mail, the recipient certificate’s public key is used – once encrypted, the e-mail can only be decrypted by the recipient (using his corresponding private key). Check out our S/MIME tutorial for more information.

     

    Certification Authorities (CAs) and Public Key Infrastructure (PKI)

    The certificate is usually signed using a private key of another identity (known as certification authority) and the actual data being signed is the certificate content - public key, identity, validity conditions, additional attributes and information about the signer. This ensures that the certificate information cannot be forged or tampered with and that the signer (the certification authority) attests that the public key and the identity belong together. Therefore, if one trusts the signer (usually called the certificate issuer), all the certificates it signs (issues) are also trusted. This arrangement (using a CA to bind a public key with the respective identities) is called public key infrastructure.

    chainIn the X.509 public key infrastructure, the public key of a certificate authority itself is also a part of another certificate that is either signed by yet another certification authority or by the private key that corresponds to the certificate’s public key itself (that is a self-signed certificate, also known as root certificate). This forms a certificate chain of trust – certificate of every identity chains up to a root CA certificate. If a root certificate authority is trusted, all certificates it (or one of its sub-ordinate CAs) issues are also implicitly trusted if all the certificates in their chain are known and valid. The validity check evaluates the chain, making sure each link is signed by the next link, that the signature is valid, that each certificate has can be used for a specific purpose at the specific time and that the last certificate in the chain is a trusted CA certificate.

    The Google’s certificate above was issued and signed by Thawte, whose certificate was in turn issued and signed by Verisign using its root CA certificate. The picture on the right shows this certificate chain.

     

    Trusted root certification authoritiesroot-ca-store2

    Microsoft Windows and most web browsers and SSL libraries come with a list of trusted certification authorities. These are usually commercial certification authorities that have to undergo annual security audits by independent organizations in order to be included in these lists. Rebex TLS/SSL library also uses Windows certificate infrastructure and its certificate stores to validate certificates, which makes it easy to manage using well-known tools. The same infrastructure is utilized by Windows components and many Windows applications that use CryptoAPI to perform security operations. For example, Internet Explorer uses it to validate server certificates when browsing a website protected using HTTPS (HTTP over SSL) protocol. You can even use Internet Explorer to manage the certificate stores (alternatively, use the “Certificates” MMC snap-in).

    There are many commercial certification authorities (CAs) that charge for their services. Some of these are authorities that have been added to the aforementioned list by the OS and browser vendors, others are local certification authorities that are trusted by government institutions and are often not trusted by Microsoft Windows and other operating systems out-of-the-box. Some CAs that issue certificates to the public at no cost are also not trusted unless explicitly added to the list of trusted CAs.

    To add a certificate of a certification authority into the “Trusted Root Certification Authorities” store of the current user, simply right-click the .cer/.der or .p7b file downloaded from the CA’s web site or start Internet Explorer and follow the instructions in the picture on the right. Only self-signed certificates belong into this store – certificates of non-root CAs have their own store - “Intermediate certification authorities”.

    Please note that each Windows user has a separate set of certificate stores. There are also local machine certificate stores that are used by Windows Services and other similar applications. This can be managed using Microsoft Management Console’s “Certificates” snap-in that is a part of every Windows installation.

     

    What to do when a server certificate is not trusted?

    A server certificate will usually fall into one of these categories:

    • The certificate is signed by a certificate authority that is trusted by Windows certificate infrastructure. This is the desired state.
    • The certificate is signed by a certificate authority that is not trusted by Windows certificate infrastructure. For example, this can be a third-party CA or a corporate CA. Add the root CA certificate into “Trusted Root Certification Authorities” store and add each intermediate CA certificate into “Intermediate certification authorities” store to make the server certificate trusted.
    • The certificate is self-signed. This is what many FTP and mail servers generate by default. Either replace the default certificate with a certificate issued by a real CA, or make it trusted by Windows certificate infrastructure by adding it into the “Trusted Root Certification Authorities” store, because – in theory and in practice – it is both a server certificate and a CA certificate.

      

    To be continued…

    Tomorrow, we will look into the most common certificate problem encountered by our customers – the “Server certificate was rejected by the verifier because…” exception.

  • Build 3333: Keyword support in IMAP and TNEF (winmail.dat) support in MIME parser

    This build mostly adds features that didn't made it into the previous release.

    Keyword support in IMAP

    Support for keywords (also known as custom flags) has been added to Rebex IMAP component due to numerous user requests. New overloads for SetMessageInfo method were added and ImapMessageInfo class has new GetKeywords method. However, not all IMAP servers support custom flags, so make sure to check Imap object's CurrentFolder.SupportedFlags and PermanentFlags properties to make sure this feature is available.

    TNEF (winmail.dat) support in MIME parser

    Perhaps you receive an unreadable e-mail with the infamous winmail.dat attachment once in a while. This uses the Microsoft TNEF format that is unsupported by most mail clients - except Outlook. This release of Rebex Mail (and its Secure, POP3 and IMAP variants) adds experimental support for reading these e-mails. Next time you load an e-mail with a TNEF attachment, it should be parsed automatically. Please be aware that this is single-purpose winmail.dat parser, not a general-purpose TNEF parser.

    Complete list of changes:

    • IMAP: Added support for keywords (custom flags).
    • IMAP: Added a workaround for qq.com IMAP server that advertises PLAIN authentication method support but only accepts LOGIN.
    • SMTP: Fixed a problem with sending messges using "binary" content transfer encoding and parsed using DoNotParseMimeTree option.
    • SMTP: Fixed a problem in ResolveDomainMX that caused it to 'resolve' domains that don't exist.
    • MIME: Added experimental TNEF (winmail.dat) support to MailMessage class.
    • MIME: Added MimeOptions.OnlyParseHeaders option to make it easily possible to parse message headers only.
    • MIME: Fixed a problem with badly-formed MailMessage that was produced after being parsed with DoNotParseMimeTree option.
    • MIME: It is now possible to set BodyHtml and BodyText to null.
    • FTP: When client certificate authentication is done with Tumbleweed FTP server, an automated login attempt is performed.
    • FTP: FileExists and DirectoryExists methods modified to return the result for "." and "/" arguments instantly without asking the server.
    • FTP: Fixed a workaround for problem with local IP address announced by the server when connecting through ActiveSync to an FTP server that runs on the same machine.
    • FTP: KeepAliveDuringTransfer option made compatible with more FTP servers.
    • SCP: Scp.Logger renamed to Scp.LogWriter to match the other objects including Sftp.
    • SCP: Fixed improper handling of the first success response.
    • SFTP: Detection of GlobalScape server enhanced to properly detect more versions.
    • SSH: Banner message is now logged when using the LogWriter fuctionality.
    • SSH: Added workaround for badly-formed DSA signature produced by SSH Secure Shell 3.1.0 (and possibly other versions).
    • SSH: Added a workaround to the Compact Framework version for VanDyke VShell server that sends primes that are one bit longer than expected.
    • All: Asynchronous operations now use a thread pool.
    • Terminal: Shell.Close method added to make it possible to gracefully close an SSH shell session.
    • Terminal: Added a variant of SendCommand method that makes it possible to send 'invisible' data such as passwords.
    • Terminal: Prompt-matching changed to make it possible to match beginning of a line.
    • SecureSocket: Exception thrown because of certificate hostname mismatch is more descriptive.
    • ProxySocket: Fixed a bug in Socks4/Socks5 proxy code that made it impossible to use active mode with these proxies.
    • Security: CertificateStore.FindCertificate overloads that accept DistinguishedName now search for certificates signed by intermediate CAs as well.
    • Security: Enhanced treatment of empty passwords in the PFX loader.
    • Security: Certificates with SubjectAlternativeName extension marked as critical are now treated as not having any e-mail address assigned to them if no e-mail address is found in the extension data.
    • Security: Fixed a bug in DiffeHellmanManaged.ImportParameters method that made it impossible to import key with all parameters filled.
    Also, we would like some feedback on the recursive/wildcard transfers added in the previous release. If you have tried using this feature, please let us know about it!

  • HOWTO: Upgrade Rebex DLLs without recompiling

    With the first release of .NET Framework, Microsoft also introduced the concept of strongly-named assemblies (DLLs) in order to avoid some problems of what was known as DLL Hell. A strong name means that a DLL is uniquely identified not only by filename, but also by its public key token and version number. This makes it impossible to accidentally run an application with a different version of a DLL that is incompatible with the expected version.

    In practice, this means that as far as the .NET's class loader is concerned, version 2.0.0.0 and version 2.1.0.0 of an assembly are completely different identities and therefore considered incompatible. The same applies to versions that only differ in a build or revision number. Therefore, for example, applications compiled with Rebex FTP for .NET 2.5.2800.0 or 3.0.3200.0 will refuse to work with 3.0.3300.0. This applies both to Rebex FTP for .NET installed as a shared assembly in Global Assembly Cache (GAC) and as an application-private assembly in the application folder.

    The recommended way of dealing with this is to recompile your application with the new version and distribute the next version of your application with a new set of DLLs. However, there might be some scenarios where this is not desirable – and this document describes how to make your existing applications use the new Rebex component version instead of the old one without the need to recompile your code.

     

    Compatibility List

    The following table lists all currently available Rebex assemblies, their current version and all the versions it should be backward compatible with:

     

    Assembly Compatible Version Current Version
    Rebex.Net.Ftp.dll 2.0.0.0-3.0.3299.0 3.0.3300.0
    Rebex.Net.Sftp.dll 1.0.0.0-2.0.3299.0 2.0.3300.0
    Rebex.Net.Smtp.dll 1.0.0.0-1.0.3299.0 1.0.3300.0
    Rebex.Net.Pop3.dll 1.0.0.0-1.0.3299.0 1.0.3300.0
    Rebex.Net.Imap.dll 1.0.0.0-1.0.3299.0 1.0.3300.0
    Rebex.Net.Ssh.dll 2.0.0.0-2.0.3299.0 2.0.3300.0
    Rebex.Net.ProxySocket.dll 2.0.0.0-2.0.3299.0 2.0.3300.0
    Rebex.Net.SecureSocket.dll 3.0.0.0-3.0.3299.0 3.0.3300.0
    Rebex.Security.dll 1.5.0.0-1.5.3299.0 1.5.3300.0
    Rebex.Mail.dll 1.0.0.0-1.0.3299.0 1.0.3300.0
    Rebex.Net.SshShell.dll 1.0.0.0-1.0.3299.0 1.0.3300.0
    Rebex.TerminalEmulation.dll 1.0.0.0-1.0.3299.0 1.0.3300.0

    If you currently use an older version not shown in this table, it means that it is no longer compatible with the current version. In this case, you will have to recompile your code and possibly make several slight changes to it.

    The public key token for all Rebex assemblies is “1c4638788972655d”.

     

    Version Policies

    Microsoft .NET Framework supports version policies. These policies are stored in XML files and are simply a request to load one version of an assembly instead of another. This is exactly what we need here.

    The policy for redirecting from old versions of Rebex FTP for .NET (2.0.0.0 - 3.0.3299.0) to 3.3300.0.0:

     

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">    
        <dependentAssembly>
            <assemblyIdentity name="Rebex.Net.Ftp" publicKeyToken="1c4638788972655d" />
            <bindingRedirect oldVersion="2.0.0.0-3.0.3299.0" newVersion="3.0.3300.0" />
        </dependentAssembly>
    </assemblyBinding>


    There are three levels at which version policy can be applied in .NET:

    1. Application-Specific Policy

    Each application has an optional configuration file that can specify the redirections. The name of the configuration file is the name of the executable + the ".config" extension (eg. WinFormClient.exe.config) for executable files and Web.config for ASP.NET applications.

    To enforce binding to a different version than the application was linked with, place the version policy under the <runtime> node of the <configuration> root node:

     

    <configuration>    
        <runtime>
            <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
                <dependentAssembly>
                    <assemblyIdentity
                        name="Rebex.Net.Ftp"
                        publicKeyToken="1c4638788972655d" />
                    <bindingRedirect
                        oldVersion="1.0.0.0-1.2.2.0"
                        newVersion="1.3.0.0" />
                </dependentAssembly>
            </assemblyBinding>
        </runtime>
    </configuration>

     

    2. Global Assembly Cache Policy

    This only works if the component is installed in Global Assembly Cache. The binding policy can be specified manually using .NET Configuration Management Console (see the screenshot) after adding the assemblies into "Configured Assemblies" group:

    upgrade-binding

    One binding policy has to be defined for each Rebex assembly (only for the components you actually use and their references, of course). The drawback of this method is that this will affect all applications using Rebex components, so use with care.

     

    3. Machine-Wide Policy.

    Machine-wide policy is stored in machine.config file. Policy statements made in machine.config also affect all applications running on the machine. Edit this file only if you know what you are doing. See .NET Framework documentation for more information. We strongly suggest using one of the other methods instead.

  • HOWTO: Configure Network in Windows Mobile / PocketPC Device Emulator

    When Microsoft Visual Studio 2005 or 2008 is installed with .NET Compact Framework support, a part of the installation is a mobile device emulator that is very useful for testing and debugging .NET CF applications. Unfortunately, network access is not enabled in the emulator by default. Configuring it involves installing additional software and the whole process is complicated enough to cause a lot of confusion. Because of this, we have written the following guide.

    Step A. Configure the device emulator

        1. In the emulator menu, go to “File->Configure”.
        2. Click the “Network” tab.
        3. Check the “Enable NE2000 PCMCIA network adapter…” checkbox.
        4. Select “Connected network card” in the list below the checkbox.
        5. Click “OK”.
        6. If no error dialog appears at this point, continue directly to Step C. Otherwise, read instructions for Step B below.

    step1   step2

     

    Step B. Install the Virtual PC Network Driver

    Network adapter emulation is not working by default after installing Visual Studio 2005 because a VPC Network Driver is not a part of the installation. That’s why the following dialog usually appears after completing Step A above:

    step3

    VPC Network Driver is a network device driver that comes with Microsoft Virtual PC and is required by Visual Studio's device emulator as well to be able to bind to a physical network adapter in your computer. Few years ago, Microsoft used to distribute the driver as a small package at the URL from the error dialog above. Unfortunately, this is no longer available and the URL now redirects to Virtual PC 2007 download page that is much larger. If you don’t mind installing Virtual PC (recommended), this is not an issue, but in case you would only like the driver, you can get it from the “c:\Program Files\Microsoft Virtual PC\Utility\VMNetSrv” folder once Virtual PC is installed.


    Step C. Configure the emulated mobile device

       1. Check the emulator screen to see whether the emulated network adapter works – if you see the 'connected' icon, the network adapter works fine. If you see the 'g' icon, something is still wrong - go back to Step A and make sure everything was configured correctly.

    step4a

       2. Even though the network adapter is enabled now, you may still be unable to access the Internet – start Internet Explorer and try viewing a well-known website. You may get one of the following error messages, depending on your Windows Mobile version:

    step5astep5b 

       3. If you are unable to access the Internet (this assumes that you are actually able to access the Internet from your workstation, of course) and you can also see the 'established connection' icon, click it and choose that the network card connects you to “The Internet” instead of “Work” – you should be able to access the internet now. If you can’t see the icon, follow the steps below.

       4. Tap the “Start” menu and select “Settings”. Then tap the “Network Cards” icon.

    step6  step7

        5. Change the “My network card connects to” value from “Work” to “The Internet”.

    step8a  step8b

        6. Internet should work now – give it a try!

    step9

        7. If it still doesn't work, consult your network administrator. The network adapter is configured to use DHCP by default to get a network address, which might not work on high-security corporate networks. In this case, an IP address will have to be assigned manually (in the “Configure Network Adapters” dialog above – tap “NE2000 Compatible Ethernet Driver” in the list) by the network administrator.


    Done!

    Once this is done, you should also be able to access your local network and the Internet from the emulated device and from Rebex components for running on it, such as Rebex FTP/SSL or Rebex SFTP. If anything is still not working, please let us know!

     

  • Build 3300: Recursive wild-card directory transfers and enhanced logging

    Recursive wild-card directory transfers in FTP, FTP/SSL and SFTP

    Finally, GetFiles and PutFiles methods were added to Rebex FTP and SFTP components. Transferring a complete directory tree or a group of files matching the specified wildcard mask is now easier than ever before. Check out the BatchTransfer sample or the corresponding tutorial for more information about this new feature.

    Enhanced logging

    Enhanced logging capabilities were added to all session-based components (=nearly all Rebex components). Creating a detailed communication log is now only a matter of referencing the Rebex.Net.ProxySocket.dll from your project and adding a single line of code after each call to Ftp, Sftp, Smtp or other constructor:

    C#:
    client.LogWriter = new
    Rebex.FileLogWriter(@"c:\temp\log.txt", Rebex.LogLevel.Debug); // change the log path if needed

    VB.NET:
    client.LogWriter = new Rebex.FileLogWriter("c:\temp\log.txt", Rebex.LogLevel.Debug) ' change
    the log path if needed

    Where "client" is an instance of Ftp, Sftp, Smtp or other object. We are going to write a separate blogpost about this with more information soon.

    SSH Shell Enhancements

    The second release of Rebex SSH Shell adds many features our customers asked for such as Expect method in TerminalControl and VirtualTerminal control that makes it easilly possible to user these classes for scripting purposes. Other additions are custom color schemes (useful enhancement of monochrome terminal display), custom palettes and build-in routines for rendering most box-drawing and block element characters that are either not present or improperly drawn in majority of fonts - applications using these charactes now look much better.

    Complete list of changes:

    • FTP/SFTP/SMTP/POP3/IMAP: Added enhanced logging capabilities.
    • FTP/SFTP/SMTP/POP3/IMAP: A better exception is now thrown by a method that has been terminated by calling Dispose from another thread.
    • FTP/SFTP/SMTP/POP3/IMAP: Asynchronous method threads are now named.
    • FTP: Added PutFiles and GetFiles method to make it possible to transfer multiple files easily by transfering a whole directory tree or use wildcards.
    • FTP: Added PutFiles and GetFiles method to make it possible to transfer multiple files easily by transfering a whole directory tree or use wildcards.
    • FTP: Disabled control connection flushing when sending commands because it caused a noticeable slowdown on fast networks.
    • FTP: Added a workaround for Serv-U FTP that ungracefully closes data connection for zero-length files.
    • FTP: Transfer compression support added to .NET CF 3.5 build (it has only been available for .NET 2.0 and higher previously).
    • FTP: Added workaround for some releases of SecureTransport server - ForceSilentCcc option is enabled automatically.
    • FTP: Substantial transfer speed increase on fast networks.
    • FTP: Fixed a bug in CopyToAnotherServer method that caused it to fail for plain FTP unless SecureTransfers property was set to false.
    • FTP: Fixed a bug that caused the KeepAliveDuringTransfer option not to work properly.
    • FTP: FtpOptions.KeepAliveDuringTransfer option code enhanced by adding the '200 No-operation ...' response to the list of possible NOOP command responses.
    • FTP: Added a workaround for misconfigured FTP servers that send an unusable private network address when initializing a data transfer.
    • FTP: SetTransferType method changed to behave just like TransferType property and marked obsolete.
    • FTP/SFTP: Packages for .NET Compact Framework 3.5 added.
    • SFTP: Added PutFiles and GetFiles method to make it possible to transfer multiple files easily by transfering a whole directory tree or use wildcards.
    • SFTP: Setting ServerType property to Unix now causes '\' not to be treated as a directory separator for the remote server.
    • SFTP: Added Scp class to make it possible to transfer files using the legacy SCP protocol.
    • IMAP: Added FolderExists method to Imap class.
    • IMAP: Added a workaroud for servers that allow the "NO" reply in response to FETCH command - a behavior that is strongly discouraged.
    • IMAP: Added a workaround for buggy servers that don't understand the 'RFC822' item, although they process the functionally equivalent 'BODY[]' item just fine.
    • POP3: Added a workaroud for Exchange 2000 that is unable to properly transfer e-mail with a body that starts with a dot.
    • POP3: GetMessage method now returns the transferred message length instead of number of bytes transferred.
    • POP3: A proper Pop3Exception is now thrown if duplicate unique ID is found in a message list.
    • POP3: Fixed a bug that caused a wrong error to be reported when POP3 server closes the connection while transferring data.
    • MIME: GetRaw method added to MimeHeaderCollection class.
    • MIME: Added Insert method to AlternateViewList class.
    • MIME: Added workaround for some badly formatted dates.
    • MIME: Added IgnoreUnparsableSignatures option to MimeOptions to make it possible to read mail messages with broken signatures.
    • MIME: Added partial Mono support to make it possible to parse S/MIME messages (signature validation is still unsupported).
    • MIME: Added MimeOptions.AllowAnyTextCharacters option to make it possible to use any characters in text attachments.
    • MIME: Added a workaroud for Dovecot server that occasionally adds an extra CR (0xD) character at the end if its response when retrieving mail headers using IMAP.
    • MIME: Added a workaroud for parsing '@' character in Content-Type parameters.
    • MIME: Added a workaround for Outlook invitations with missing charset.
    • MIME: Workardound for Mac mail introduced in 1.0.2800.0 modified because it was incompatible with Outlook 2003 in combination with S/MIME messages.
    • MIME: Fixed a bug that caused some text parts to be parsed as attachments instead.
    • MIME: Fixed a bug that caused the DefaultEncoding to not be converted when converting MailMessage to MimeMessage or when sending MailMessage using the Smtp object.
    • MIME: Order of settting BodyText and BodyHtml now does not affect the actual order in the message. Previously, using an uncommon order caused problems GMail and iPhone to display the text part instead of HTML part.
    • SFTP/SSH/SSH Core: Asynchronous method threads are now named.
    • SFTP/SSH/SSH Core: Added support for servers that don't require a password.
    • SSH Core/Security: Added support for saving PuTTY private keys.
    • SSH Core/Security: Added support for reading and setting private key comment.
    • SSH Core: Added ChangePassword method to SshSession class to make it possible to change user password.
    • SSH Core: Fixed a bug in SshSession that caused problems when multiple channels through the same SSH session were used at the same time.
    • Terminal: Added support for custom color schemes to TerminalOptions class.
    • Terminal: Added the ability to scroll while selecting a long chunk of text.
    • Terminal: Added AutoAdjustTerminalFont, UserInputEnabled, ScrollBarEnabled and ScrollbackResetOnDisplayActivity properties to TerminalControl class.
    • Terminal: Added DataReceived event to TerminalControl and VirtualTerminal classes.
    • Terminal: Added scroll-back buffer support.
    • Terminal: Added support for setting the font using the Control's Font property (previously, TerminalFont had to be used).
    • Terminal: Added drawing routines for most box-drawing and block element characters that are either not present or improperly drawn in majority of fonts.
    • Terminal: Added custom palette support.
    • Terminal: Fixed a bug that caused the terminal control to resize several times when minimized and maximized again.
    • Terminal: Fixed a bug that caused an extra column to appear in a newly-created terminal control.
    • Shell: Added support for 'ksh' shell.
    • SecureSocket: Anonymous TLS/SSL ciphers are now supported (but disabled by default).
    • SecureSocket: Fixed an internal static method that was not thread safe.
    • Security: Added Equals method to DistinguishedName class.
    • Security: Added RootCertificate and LeafCertificate properties to CertificateChain class.
    • Security: Added GetCommonName method to DistinguishedName class.
    • Security: Added IEnumerator support to CertificateChain.
    • Security: Added new Certificate.LoadPfx to make it possible to load keys into machine store.
    • Security: Fixed a problem in Certificate.Decrypt method that made the decryption fail with some rare certificates.
    • Security: Fixed a bug in OID decoding routine that cased it to occasionally hang on broken input data.
    As you can see, this was a huge release!
  • HOWTO: Registering SFTP and FTP/SSL for use in SSIS package

    The SFTP and FTP/SSL component included in File Transfer Pack was not especially designed to run inside the SSIS (SQL Server Integration Services). However, with little effort both components can be used from inside the SSIS "script task".

    Registering the component for use in IDE for SSIS packages

    Registering the component for use in normal VS.NET is easy. Just use "Add Reference" and click on "Browse" button. Unfortunatelly, the "Add Reference" dialog in SSIS IDE does not allow adding reference by browsing the assembly on the disk. It offers only pre-registered assemblies.

    To register the component for use in SSIS package:

    1. Copy Rebex assemblies (DLLs) into C:\Program Files\Microsoft SQL Server\90\SDK\Assemblies\  - this should make them appear in the Visual Studio for Applications "References" dialog.
    2. Add Rebex assemblies into Global Assembly Cache (GAC)  - this is needed in order to make it possible for SSIS to run them.
    3. One user has also reported that copying the assemblies to C:\Program Files\Microsoft SQL Server\90\DTS\Binn instead of putting them into the GAC is sufficient too.

    Similar problem is discussed in newsgroup post on Microsoft website.

    Using the component from SSIS

    1. Add new Script Task
    2. Modify the script via the "Desing script" in "Properties dialog". The Visual Studio for Applications IDE pops up.
    3. Add reference to the dlls in the Project Explorer window. The SFTP and FTP/SSL components should be listed in the Add Reference dialog now.
    4. Add the code to connect, transfer files or do whatever you want as described in SFTP and FTP/SSL tutorials.

    Adding the references for the SSIS Script Component (used in data flow task) is similar.

  • HOWTO: Using FTP or SFTP in PowerShell

    PowerShell - a powerful new scripting language and command shell from Microsoft - has many built-in commands. However, it lacks support for transferring files over FTP, FTP/SSL or SFTP. Luckily, PowerShell is based on .NET and can invoke methods of .NET classes. Let's see how to upload or download files to an FTP or SFTP server from a PowerShell script using either Rebex FTP (/SSL) or Rebex SFTP component.

    Step 1 - Loading FTP or SFTP assembly

    First, we have to load Rebex assemblies via [Reflection.Assembly]::LoadFrom command. This will load Rebex.Net.Ftp.dll for FTP or FTP/SSL and Rebex.Net.Sftp.dll for SFTP. Other assemblies needed by the two will be loaded as well.

    PS C:\> [Reflection.Assembly]::LoadFrom("C:\Program Files\Rebex\FTP for .NET 2.0\bin\release\Rebex.Net.Ftp.dll")

    GAC Version Location
    --- ------- --------
    False v2.0.50727 C:\Program Files\Rebex\FTP for .NET 2.0\bin\release\Rebex.Net.Ftp.dll

    Step 2 - Connecting, logging in, uploading, downloading and deleting files

    Now, you can call the FTP methods as described in the FTP Tutorial:
    PS C:\> [Reflection.Assembly]::LoadFrom("C:\Program Files\Rebex\FTP for .NET 2.0\bin\release\Rebex.Net.Ftp.dll")

    GAC Version Location
    --- ------- --------
    False v2.0.50727 C:\Program Files\Rebex\FTP for .NET 2.0\bin\release\Rebex.Net.Ftp.dll

    PS C:\> $ftp = New-Object Rebex.Net.Ftp
    PS C:\> $ftp.Connect("ftp.rebex.net")
    220 Gene6 FTP Server v3.7.0 (Build 24) ready...

    PS C:\> $ftp.Login("username", "password")
    230 User logged in.

    PS C:\> $ftp.PutFile("C:\temp\test.txt", "test.txt")
    89
    PS C:\> $ftp.GetFile("test.txt", "C:\temp\test2.txt")
    89
    PS C:\> $ftp.DeleteFile("test.txt")
    PS C:\> $ftp.Disconnect()
    221 Goodbye.


    PS C:\> $ftp.Dispose()
    PS C:\> Remove-Variable ftp
    PS C:\>

    That's all!

    What about GAC?

    And in case you would like to load Rebex assemblies from Global Assembly Cache (GAC) instead of from a path, use Assembly.Load method instead:

    PS C:\> [Reflection.assembly]::Load("Rebex.Net.Ftp, Version=2.5.3127.0, Culture=neutral, PublicKeyToken=1c4638788972655d")

    GAC Version Location
    --- ------- --------
    True   v2.0.50727     C:\WINDOWS\assembly\GAC\Rebex.Net.Ftp\2.5.3127.0__1c4638788972655d\Rebex.Net.Ftp.dll


  • New component: Rebex SSH Shell for .NET - Secure shell and terminal emulation

    A new component has just been released: Rebex SSH Shell for .NET.

    Rebex SSH Shell component is an SSH shell and terminal emulation library for .NET languages (such as C# or VB.NET). It makes it easy to execute commands on Unix/Windows SSH servers or add terminal emulation capabilities to your applications. All popular Linux and Windows SSH servers are supported. Most common shells are supported as well.

    Features include:

    • Remote command execution over SSH channel.
    • Remote SSH shell.
    • Terminal emulation (Windows Forms control and virtual terminal).
    • Terminal session recording and replay
    • Username/password and public key authentication
    • Lot of samples in C# and VB.NET including WinForm SSH client.
    • Easy-to-follow tutorial for a quick start.
    • Includes Rebex Security component with support for signature/verification, encryption/decryption, etc.
    • Complete C# source code is optionally available.
    • And more...

    Additionally, we have added Rebex SSH Pack to our portfolio - this contains both SFTP (file transfer over SSH) and SSH Shell components in a single pack.

    See also: SSH Shell component homepage | Download trial | Pricing from $349

  • Build 3127: Wildcards in SFTP, better oversized packet support

    Wildcards in SFTP

    Even though the SFTP protocol does not support using wildcards to filter its directory listings, this feature was requested so often that we simply had to add it to the GetList method and its variants. How do we do it? It's simple - all the filtering is done at the client side. Of course, this won't help you speed up the listing if you have thousands of files in a directory, but at least you would be able to limit the listing scope easily.

    Better support for oversized packets

    We have noticed that one popular SFTP server sometimes sends packets that are about 4 times larger than the maximum packet size specified by the protocol draft. And this was too large even for our packet parser. To be able to communicate flawlessly with these servers, we implemented a growable receive buffer that can accomodate even very oversized packets, yet doesn't waste any precious memory space with servers that do behave according to the rules.

    Similar problem was discovered in the IMAP protocol - here it occured i the Search method on some servers. A similar workaround was added for these as well.

    Complete list of changes:

    FTP: Fixed a bug introduced in the last release that caused a bad InvalidOperationException to be thrown when FTP server reported an error during upload.
    SFTP: Enhanced packet reader to support oversized SFTP packets.
    SFTP: GetList, GetRawList and GetNameList enhanced to support wildcards. However, they are processed at the client side because the SFTP protocol can't do that at the protocol level.
    SSH: Fixed a problem in RSA private key reader that caused an error with some keys.
    SSH: Enhanced packet reader to support oversized SSH packets.
    IMAP: Response-reading code enhanced to handle oversized responses that occured while searching with some servers.
    SNTP: Ntp.SynchronizeSystemClock method can now syncrhonize system time even if the current clock value is outside the range supported by NTP.
    SNTP: Added experimental support for setting system time on Linux.

    The next release of FTP and SFTP components will finally feature directory tree transfers!

More Posts Next page »
Powered by Community Server (Personal Edition), by Telligent Systems