Perform cookie-based silent re-authentication¶
This operation is the library's silent sign-in path, used by both fallback branches before they resort to a redirect or a browser challenge. It reads the SAIFAUTH request cookie, decrypts and validates the credentials packed inside it, exchanges those credentials for a Windows logon token, and — only if every step succeeds — assigns the resulting WindowsPrincipal to HttpContext.Current.User.
| Field | Value |
|---|---|
| Operation ID | perform-cookie-based-silent-reauthentication |
| Trigger | An internal or external authenticator attempts silent sign-in for the current request. |
| Inputs | HttpApplication, SAIFAUTH cookie, Request.UserHostAddress, sec-logindomain |
| Outputs | Boolean success/failure and optional HttpContext.Current.User assignment |
| Primary components | CookieAuthenticator.Authenticate, CookieAuthenticator.DecryptCookie, TokenProvider.GetToken |
| Entry point | SAIF.Framework.SecurityModule\Authenticators\CookieAuthenticator.vb |
Steps¶
- Log
Begin AuthenticateCookie, initialize the local success flag and credential variables, and readContext.Request.Cookies("SAIFAUTH"). - If the cookie is missing, skip the credential path entirely and return
Falseafter the closing log entry — a missing cookie is not treated as an error. - Call
DecryptCookie(authCookie.Value, Context.Request.UserHostAddress, username, password)to recover the packed credentials from the cookie. - The helper delegates the cryptographic reversal to Protect and unprotect sensitive values.
- It splits the decrypted string on tab characters, discarding empty entries, and accepts the payload only when exactly two fields remain (BR-003).
- If the split count is wrong, log a warning and return
False. - If decryption or splitting throws an exception, log the exception together with the cookie value and entropy, then return
False. - If cookie decryption or validation failed at any point, log
Error decrypting SAIFAuth cookie, logEnd AuthenticateCookie, and returnFalseto the caller. - If cookie decryption and validation succeeded, call
TokenProvider.GetToken(username, password)to obtain a Windows logon token for the recovered credentials. GetTokencalls Win32LogonUseragainst the domain named inAppSettings("sec-logindomain"), duplicates the returned handle, and closes the original handle.- If the Win32 logon fails or the original handle is zero,
GetTokenthrowsUnable to login, which this operation does not catch (BR-004). - Clear the local password reference, construct a
WindowsIdentityfrom the token, wrap it in aWindowsPrincipal, and assign that principal toHttpContext.Current.User. - If the assignment succeeds, set the local result flag to
True. - If the assignment throws, catch the exception locally, log its message at debug level, and leave the result as
Falserather than propagating the exception. - In a
Finallyblock, callTokenProvider.ReleaseToken(Token)unconditionally, regardless of whether token creation or principal assignment succeeded. - Log
End AuthenticateCookieand return the Boolean result to the caller.
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start([Read SAIFAUTH cookie]) --> D1{Cookie present?}
D1 -->|No| EndFail([Return False])
D1 -->|Yes| S1[Decrypt and split cookie]
S1 --> D2{Exactly two fields?}
D2 -->|No| EndFail
D2 -->|Yes| S2[Call TokenProvider.GetToken]
S2 --> D3{Token created?}
D3 -->|No| EndErr([Exception to caller])
D3 -->|Yes| S3[Create principal and assign HttpContext.Current.User]
S3 --> EndOk([Return True])
Failure and edge-case behavior¶
- A missing cookie is a normal silent-authentication miss: the operation returns
Falsewithout raising an exception, letting the caller fall back to a redirect or challenge. - A cookie payload that fails to decrypt, or that decrypts but does not split into exactly two tab-delimited fields, is rejected and logged rather than accepted partially (BR-003).
- A failed Windows logon during token creation propagates
Unable to loginup to the top-level request handler rather than being swallowed here (BR-004). - Principal-assignment failures are caught and logged locally, so the caller only ever sees a plain
Falseresult — never an exception — for that specific failure mode.
Related documentation¶
Sources¶
SAIF.Framework.SecurityModule\Authenticators\CookieAuthenticator.vbSAIF.Framework.SecurityModule\TokenProvider.vbSAIF.Framework.SecurityModule\DAPIEncrypt.vb