コード例 #1
0
 // Token: 0x06000010 RID: 16 RVA: 0x000023C8 File Offset: 0x000005C8
 internal void ResetAsAuthenticate(string newCommandId, ImapAuthenticationMechanism authMechanism, string user, SecureString password, AuthenticationContext authContext)
 {
     this.Reset(ImapCommandType.Authenticate, newCommandId, delegate(ImapCommand cmd)
     {
         StringBuilder cachedStringBuilder = cmd.CachedStringBuilder;
         cachedStringBuilder.Length        = 0;
         cachedStringBuilder.Append(cmd.CommandId);
         cachedStringBuilder.Append(" AUTHENTICATE");
         ImapAuthenticationMechanism authMechanism2 = authMechanism;
         if (authMechanism2 != ImapAuthenticationMechanism.Basic)
         {
             if (authMechanism2 != ImapAuthenticationMechanism.Ntlm)
             {
                 string message = "Unexpected authentication mechanism " + authMechanism;
                 throw new InvalidOperationException(message);
             }
             cachedStringBuilder.Append(" NTLM\r\n");
         }
         else
         {
             cachedStringBuilder.Append(" PLAIN\r\n");
         }
         return(cachedStringBuilder.ToString());
     }, new object[]
     {
         authMechanism,
         user,
         password,
         authContext
     });
 }
コード例 #2
0
        /// <summary>sends AUTHENTICATE command</summary>
        /// <remarks>valid in non-authenticated state</remarks>
        public ImapCommandResult Authenticate(ICredentialsByHost credentials,
                                          string username,
                                          ImapAuthenticationMechanism authenticationMechanism,
                                          bool reissueCapability)
        {
            var ret = RejectNonConnectedOrGetAuthenticatedResult();

              if (ret != null)
            return ret;

              if (credentials == null)
            throw new ArgumentNullException("credentials");
              if (authenticationMechanism == null)
            throw new ArgumentNullException("authenticationMechanism");

              var credential = credentials.LookupCredential(connection, username, authenticationMechanism);

              if (credential == null)
            return new ImapCommandResult(ImapCommandResultCode.RequestError,
                                     string.Format("credential not found for {0};AUTH={1}@{2}:{3}", username, authenticationMechanism, connection.Host, connection.Port));

              using (var t = new AuthenticateTransaction(connection, credential, serverCapabilities.Has(ImapCapability.SaslIR))) {
            t.RequestArguments["authentication mechanism name"] = authenticationMechanism;

            return AuthenticateInternal(t, credential.UserName, authenticationMechanism, reissueCapability);
              }
        }
コード例 #3
0
 // Token: 0x06000F76 RID: 3958 RVA: 0x0003F25C File Offset: 0x0003D45C
 public ImapConnectionSettings(Fqdn serverName, int portNumber, ImapAuthenticationMechanism authentication, ImapSecurityMechanism security) : base(ConnectionSettingsType.Imap)
 {
     if (serverName == null)
     {
         throw new ArgumentNullException("serverName", "The serverName parameter cannot be null.");
     }
     if (portNumber < 0)
     {
         throw new ArgumentException("serverName", "The portNumber parameter must have a value greater than 0.");
     }
     this.ServerName     = serverName;
     this.Port           = portNumber;
     this.Authentication = authentication;
     this.Security       = security;
 }
コード例 #4
0
 /// <summary>sends AUTHENTICATE command</summary>
 /// <remarks>valid in non-authenticated state</remarks>
 public ImapCommandResult Authenticate(ICredentialsByHost credentials,
                                   string username,
                                   ImapAuthenticationMechanism authenticationMechanism)
 {
     return Authenticate(credentials, username, authenticationMechanism, false);
 }
コード例 #5
0
 /// <summary>sends AUTHENTICATE command</summary>
 /// <remarks>valid in non-authenticated state</remarks>
 public ImapCommandResult Authenticate(ICredentialsByHost credentials,
                                   ImapAuthenticationMechanism authenticationMechanism,
                                   bool reissueCapability)
 {
     return Authenticate(credentials, null, authenticationMechanism, reissueCapability);
 }
コード例 #6
0
        private ImapCommandResult AuthenticateInternal(IImapTransaction t,
                                                   string username,
                                                   ImapAuthenticationMechanism authenticationMechanism,
                                                   bool reissueCapability)
        {
            var result = ProcessTransaction(t);
              var refferalResponseCode = result.GetResponseCode(ImapResponseCode.Referral);

              if (refferalResponseCode != null) {
            // RFC 2221 IMAP4 Login Referrals
            // http://tools.ietf.org/html/rfc2221
            // 4.1. LOGIN and AUTHENTICATE Referrals
            //    An IMAP4 server MAY respond to a LOGIN or AUTHENTICATE command with a
            //    home server referral if it wishes to direct the user to another IMAP4
            //    server.
            var referToUri = ImapResponseTextConverter.FromReferral(refferalResponseCode.ResponseText)[0];

            if (handlesReferralAsException) {
              throw new ImapLoginReferralException(string.Format("try another server: '{0}'", refferalResponseCode.ResponseText.Text),
                                               referToUri);
            }
            else {
              Trace.Info("login referral: '{0}'", refferalResponseCode.ResponseText.Text);

              if (result.Succeeded)
            Trace.Info("  another server available at {0}", referToUri);
              else
            Trace.Info("  try to connect to {0}", referToUri);
            }
              }

              if (result.Succeeded) {
            UpdateAuthority(username, authenticationMechanism);
            TransitStateTo(ImapSessionState.Authenticated);

            // 6.2.2. AUTHENTICATE Command
            //       A server MAY include a CAPABILITY response code in the tagged OK
            //       response of a successful AUTHENTICATE command in order to send
            //       capabilities automatically.

            // 6.2.3. LOGIN Command
            //       A server MAY include a CAPABILITY response code in the tagged OK
            //       response to a successful LOGIN command in order to send
            //       capabilities automatically.  It is unnecessary for a client to
            //       send a separate CAPABILITY command if it recognizes these
            //       automatic capabilities.
            var capabilityResponseCode = result.GetResponseCode(ImapResponseCode.Capability);

            if (capabilityResponseCode == null) {
              var capability = result.GetResponse(ImapDataResponseType.Capability);

              if (capability != null) {
            SetServerCapabilities(ImapDataResponseConverter.FromCapability(capability));
            reissueCapability = false;
              }
            }
            else {
              SetServerCapabilities(ImapResponseTextConverter.FromCapability(capabilityResponseCode.ResponseText));
              reissueCapability = false;
            }
              }
              else {
            return result;
              }

              if (reissueCapability)
            Capability();

              return result;
        }
コード例 #7
0
        internal void UpdateAuthority(string username, ImapAuthenticationMechanism authType)
        {
            authority.Scheme    = connection.IsSecurePortConnection ? ImapUri.UriSchemeImaps : ImapUri.UriSchemeImap;
              authority.Host      = connection.Host;
              authority.Port      = connection.Port;
              authority.UserName  = username;
              authority.AuthType  = authType;

              TraceInfo("authority: {0}", authority);
        }
コード例 #8
0
 // Token: 0x060000F5 RID: 245 RVA: 0x00006328 File Offset: 0x00004528
 public static string ToStringParameterValue(ImapAuthenticationMechanism authMechanism)
 {
     return(authMechanism.ToString());
 }
コード例 #9
0
 // Token: 0x06000020 RID: 32 RVA: 0x00002DC0 File Offset: 0x00000FC0
 internal Stream GetCommandParameterStream(string targetHost, string responseLine, out Exception failureException)
 {
     failureException = null;
     if (this.CommandType == ImapCommandType.Append)
     {
         return(this.CommandParameters[2] as Stream);
     }
     if (this.CommandType == ImapCommandType.Authenticate)
     {
         byte[]       inputBuffer = null;
         MemoryStream result      = null;
         ImapAuthenticationMechanism imapAuthenticationMechanism = (ImapAuthenticationMechanism)this.CommandParameters[0];
         string                text     = (string)this.CommandParameters[1];
         SecureString          password = (SecureString)this.CommandParameters[2];
         AuthenticationContext authenticationContext = (AuthenticationContext)this.CommandParameters[3];
         string                text2 = null;
         if (responseLine != null && responseLine.Length > 2)
         {
             inputBuffer = Encoding.ASCII.GetBytes(responseLine.Substring(2));
         }
         byte[] buffer = null;
         ImapAuthenticationMechanism imapAuthenticationMechanism2 = imapAuthenticationMechanism;
         if (imapAuthenticationMechanism2 != ImapAuthenticationMechanism.Basic)
         {
             if (imapAuthenticationMechanism2 == ImapAuthenticationMechanism.Ntlm)
             {
                 SecurityStatus securityStatus;
                 if (authenticationContext == null)
                 {
                     authenticationContext     = new AuthenticationContext();
                     this.CommandParameters[3] = authenticationContext;
                     string spn = "IMAP/" + targetHost;
                     securityStatus = authenticationContext.InitializeForOutboundNegotiate(AuthenticationMechanism.Ntlm, spn, text, password);
                     if (securityStatus != SecurityStatus.OK)
                     {
                         failureException = new ImapAuthenticationException(targetHost, imapAuthenticationMechanism.ToString(), RetryPolicy.Backoff);
                         return(null);
                     }
                 }
                 securityStatus = authenticationContext.NegotiateSecurityContext(inputBuffer, out buffer);
                 SecurityStatus securityStatus2 = securityStatus;
                 if (securityStatus2 != SecurityStatus.OK && securityStatus2 != SecurityStatus.ContinueNeeded)
                 {
                     failureException = new ImapAuthenticationException(targetHost, imapAuthenticationMechanism.ToString(), RetryPolicy.Backoff);
                     return(null);
                 }
                 result = new MemoryStream(buffer);
             }
             else
             {
                 failureException = new ImapUnsupportedAuthenticationException(targetHost, imapAuthenticationMechanism.ToString(), RetryPolicy.Backoff);
             }
         }
         else
         {
             SecurityStatus securityStatus;
             if (authenticationContext == null)
             {
                 authenticationContext     = new AuthenticationContext();
                 this.CommandParameters[3] = authenticationContext;
                 Match match = ImapCommand.UserNameWithAuthorizationId.Match(text);
                 if (match != null && match.Success && match.Groups.Count == 3)
                 {
                     text2 = match.Groups[1].Value;
                     text  = match.Groups[2].Value;
                 }
                 securityStatus = authenticationContext.InitializeForOutboundNegotiate(AuthenticationMechanism.Plain, null, text, password);
                 if (securityStatus != SecurityStatus.OK)
                 {
                     failureException = new ImapAuthenticationException(targetHost, imapAuthenticationMechanism.ToString(), RetryPolicy.Backoff);
                     return(null);
                 }
                 if (text2 != null)
                 {
                     authenticationContext.AuthorizationIdentity = Encoding.ASCII.GetBytes(text2);
                 }
             }
             securityStatus = authenticationContext.NegotiateSecurityContext(inputBuffer, out buffer);
             SecurityStatus securityStatus3 = securityStatus;
             if (securityStatus3 != SecurityStatus.OK)
             {
                 failureException = new ImapAuthenticationException(targetHost, imapAuthenticationMechanism.ToString(), RetryPolicy.Backoff);
                 return(null);
             }
             result = new MemoryStream(buffer);
         }
         return(result);
     }
     return(null);
 }
コード例 #10
0
 // Token: 0x060001C6 RID: 454 RVA: 0x0000A83A File Offset: 0x00008A3A
 public ImapAuthenticationParameters(NetworkCredential networkCredential, ImapAuthenticationMechanism imapAuthenticationMechanism, ImapSecurityMechanism imapSecurityMechanism) : base(networkCredential)
 {
     this.ImapAuthenticationMechanism = imapAuthenticationMechanism;
     this.ImapSecurityMechanism       = imapSecurityMechanism;
 }
コード例 #11
0
 // Token: 0x060001C5 RID: 453 RVA: 0x0000A821 File Offset: 0x00008A21
 public ImapAuthenticationParameters(string userName, SecureString userPassword, ImapAuthenticationMechanism imapAuthenticationMechanism, ImapSecurityMechanism imapSecurityMechanism) : base(userName, userPassword)
 {
     this.ImapAuthenticationMechanism = imapAuthenticationMechanism;
     this.ImapSecurityMechanism       = imapSecurityMechanism;
 }
コード例 #12
0
 private static ImapCommandResult AuthenticateWithSuppliedMechanism(ImapSession session,
                                                                ICredentialsByHost credentials,
                                                                string username,
                                                                ImapAuthenticationMechanism authMechanism)
 {
     /*
        * http://tools.ietf.org/html/rfc5092
        * 3.2. IMAP User Name and Authentication Mechanism
        *
        *    An authentication mechanism (as used by the IMAP AUTHENTICATE
        *    command) can be expressed by adding ";AUTH=<enc-auth-type>" to the
        *    end of the user name in an IMAP URL.  When such an <enc-auth-type> is
        *    indicated, the client SHOULD request appropriate credentials from
        *    that mechanism and use the "AUTHENTICATE" command instead of the
        *    "LOGIN" command.  If no user name is specified, one MUST be obtained
        *    from the mechanism or requested from the user/configuration as
        *    appropriate.
        */
       return session.Authenticate(credentials, username, authMechanism, true);
 }