Exemplo n.º 1
0
        /// <summary>Sends client SASL negotiation for specialized encrypted handshake.</summary>
        /// <param name="underlyingOut">connection output stream</param>
        /// <param name="underlyingIn">connection input stream</param>
        /// <param name="encryptionKey">for an encrypted SASL handshake</param>
        /// <returns>new pair of streams, wrapped after SASL negotiation</returns>
        /// <exception cref="System.IO.IOException">for any error</exception>
        private IOStreamPair GetEncryptedStreams(OutputStream underlyingOut, InputStream
                                                 underlyingIn, DataEncryptionKey encryptionKey)
        {
            IDictionary <string, string> saslProps = DataTransferSaslUtil.CreateSaslPropertiesForEncryption
                                                         (encryptionKey.encryptionAlgorithm);

            Log.Debug("Client using encryption algorithm {}", encryptionKey.encryptionAlgorithm
                      );
            string userName = GetUserNameFromEncryptionKey(encryptionKey);

            char[] password = DataTransferSaslUtil.EncryptionKeyToPassword(encryptionKey.encryptionKey
                                                                           );
            CallbackHandler callbackHandler = new SaslDataTransferClient.SaslClientCallbackHandler
                                                  (userName, password);

            return(DoSaslHandshake(underlyingOut, underlyingIn, userName, saslProps, callbackHandler
                                   ));
        }
Exemplo n.º 2
0
        /// <summary>Receives SASL negotiation for specialized encrypted handshake.</summary>
        /// <param name="peer">connection peer</param>
        /// <param name="underlyingOut">connection output stream</param>
        /// <param name="underlyingIn">connection input stream</param>
        /// <returns>new pair of streams, wrapped after SASL negotiation</returns>
        /// <exception cref="System.IO.IOException">for any error</exception>
        private IOStreamPair GetEncryptedStreams(Peer peer, OutputStream underlyingOut, InputStream
                                                 underlyingIn)
        {
            if (peer.HasSecureChannel() || dnConf.GetTrustedChannelResolver().IsTrusted(DataTransferSaslUtil.GetPeerAddress
                                                                                            (peer)))
            {
                return(new IOStreamPair(underlyingIn, underlyingOut));
            }
            IDictionary <string, string> saslProps = DataTransferSaslUtil.CreateSaslPropertiesForEncryption
                                                         (dnConf.GetEncryptionAlgorithm());

            if (Log.IsDebugEnabled())
            {
                Log.Debug("Server using encryption algorithm " + dnConf.GetEncryptionAlgorithm());
            }
            CallbackHandler callbackHandler = new SaslDataTransferServer.SaslServerCallbackHandler
                                                  (new _PasswordFunction_172(this));

            return(DoSaslHandshake(underlyingOut, underlyingIn, saslProps, callbackHandler));
        }