Open a secure cookie based session.

        This will return None if a signing serializer is not availabe,
        usually if the config SECRET_KEY is not set.
199367
async def open_session(
            self,
            app: 'Quart',
            request: BaseRequestWebsocket,
    ) -> Optional[SecureCookieSession]:
        
        signer = self.get_signing_serializer(app)
        if signer is None:
            return None

        cookie = request.cookies.get(app.session_cookie_name)
        if cookie is None:
            return self.session_class()
        try:
            data = signer.loads(
                cookie, max_age=app.permanent_session_lifetime.total_seconds(),
            )
            return self.session_class(**data)
        except BadSignature:
            return self.session_class()
43441
def _initialize_session():
    # type: () -> None
    
    sys_random = random.SystemRandom()
    _thread_local_storage.secret_key = b''.join(
        int2byte(sys_random.randint(0, 255))
        for _ in range(SECRET_KEY_BITS // 8))
937466
def sign_in(authenticatable)
      key = cookie_name(authenticatable.class)
      cookies.encrypted.permanent[key] = {value: authenticatable.id}
      authenticatable
    end
1071260
def login(self):
        
        authtype = self.lookup(self.profile, 'authtype')
        if authtype is None:
            cert = self.lookup(self.profile, 'cert')
            if cert and os.path.isfile(os.path.expanduser(cert)):
                authtype = 'ssl'
            # Note: official koji cli is a little more lax here. If authtype is
            # None and we have a valid kerberos ccache, we still try kerberos
            # auth.
        if authtype == 'kerberos':
            # Note: we don't try the old-style kerberos login here.
            result = yield self._gssapi_login()
        elif authtype == 'ssl':
            result = yield self._ssl_login()
        else:
            raise NotImplementedError('unsupported auth: %s' % authtype)
        self.session_id = result['session-id']
        self.session_key = result['session-key']
        self.callnum = 0  # increment this on every call for this session.
        defer.returnValue(True)
633868
def sign_out(authenticatable_class)
      key = cookie_name(authenticatable_class)
      cookies.encrypted.permanent[key] = {value: nil}
      cookies.delete(key)
      true
    end
1372921
def _init_security(self):
        
        if not self._starttls():
            raise SecurityError("Could not start TLS connection")
        # _ssh_handshake() will throw an exception upon failure
        self._ssl_handshake()
        if not self._auth():
            raise SecurityError("Could not authorize connection")
521553
def open_session(self):
        
        if self.session is not None:
            msg = "session already open; commit it or rollback before opening another one in %s" % self
            logger.error(msg)
            raise RuntimeError(msg)

        logger.info("opening a new session")
        logger.info("removing %s" % self.loc_session)
        try:
            shutil.rmtree(self.loc_session)
        except:
            logger.info("failed to delete %s" % self.loc_session)
        logger.info("cloning server from %s to %s" %
                    (self.loc_stable, self.loc_session))
        shutil.copytree(self.loc_stable, self.loc_session)
        self.session = SimServer(self.loc_session, use_locks=self.use_locks)
        self.lock_update.acquire()
1218374
def get_session(username, password, pin, cookie_path=COOKIE_PATH):
    """"""
    class MoparAuth(AuthBase):  # pylint: disable=too-few-public-methods
        """Authentication wrapper."""

        def __init__(self, username, password, pin, cookie_path):
            """Init."""
            self.username = username
            self.password = password
            self.pin = pin
            self.cookie_path = cookie_path

        def __call__(self, r):
            """No-op."""
            return r

    session = requests.session()
    session.auth = MoparAuth(username, password, pin, cookie_path)
    session.headers.update({'User-Agent': USER_AGENT})
    if os.path.exists(cookie_path):
        _LOGGER.info("cookie found at: %s", cookie_path)
        session.cookies = _load_cookies(cookie_path)
    else:
        _login(session)
    return session
472474
function getSecretBag (req, sessionKey, cookie) {
  if (cookie) {
    // get secret from cookie
    var cookieKey = cookie.signed
      ? 'signedCookies'
      : 'cookies'

    return req[cookieKey]
  } else {
    // get secret from session
    return req[sessionKey]
  }
}
773716
def initialise_shopify_session():
    
    if not settings.SHOPIFY_APP_API_KEY or not settings.SHOPIFY_APP_API_SECRET:
        raise ImproperlyConfigured("SHOPIFY_APP_API_KEY and SHOPIFY_APP_API_SECRET must be set in settings")
    shopify.Session.setup(api_key=settings.SHOPIFY_APP_API_KEY, secret=settings.SHOPIFY_APP_API_SECRET)
1286438
function getSession (ctx) {
    let signedCookie = ctx.cookies.get(sessionKey, {signed: cookie.signed}) || ''
    signedCookie = signedCookie.split('.')

    return ctx.thunk()(function () {
      if (!storeAvailable) throw new Error('session store is not available')
      if (signedCookie[0]) return store.get(signedCookie[0])
    })(function (err, session) {
      if (err) throw err
      let sessionId
      let originalHash

      if (session) {
        sessionId = signedCookie[0]
        originalHash = signedCookie[1]
        if (hashSession(session, sessionId) !== originalHash) session = null
      }

      if (!session) {
        session = genSession()
        sessionId = genSid(sidSize)
        originalHash = hashSession(session, sessionId)
      }

      return {
        session: session,
        sessionId: sessionId,
        originalHash: originalHash,
        isNew: originalHash !== signedCookie[1]
      }
    })
  }
276978
def INIT_TLS_SESSION(self):
        
        self.cur_session = tlsSession(connection_end="server")
        self.cur_session.server_certs = [self.mycert]
        self.cur_session.server_key = self.mykey
        if isinstance(self.mykey, PrivKeyRSA):
            self.cur_session.server_rsa_key = self.mykey
        # elif isinstance(self.mykey, PrivKeyECDSA):
        #    self.cur_session.server_ecdsa_key = self.mykey
        raise self.WAITING_CLIENTFLIGHT1()
916371
def initialize_hmac(self):
        # type: (EncryptionMetadata) -> hmac.HMAC
        
        if self._signkey is not None:
            return hmac.new(self._signkey, digestmod=hashlib.sha256)
        else:
            return None
88724
def set_cookie!
      cookies[:user_session] = {
        :value => self.temporary_token,
        :secure => controller.request.ssl?,
        :httponly => true,
        :expires => self.expires_at
      }
      Authie.config.events.dispatch(:session_cookie_updated, self)
      true
    end
542438
def _prepare(self, serialized_obj):
        '''
        
        '''
        # generating a nonce
        nonce = nacl.utils.random(nacl.secret.SecretBox.NONCE_SIZE)
        # encrypting using the nonce
        encrypted = self.__safe.encrypt(serialized_obj, nonce)
        # sign the message
        signed = self.__signing_key.sign(encrypted)
        return signed
1352067
public Cookie getSessionCookie(HttpSession session,boolean requestIsSecure)
    {
        if (_handler.isUsingCookies())
        {
            Cookie cookie = _handler.getSessionManager().getHttpOnly()
                ?new HttpOnlyCookie(SessionManager.__SessionCookie,session.getId())
                :new Cookie(SessionManager.__SessionCookie,session.getId());    
            String domain=_handler.getServletContext().getInitParameter(SessionManager.__SessionDomain);
            String maxAge=_handler.getServletContext().getInitParameter(SessionManager.__MaxAge);
            String path=_handler.getServletContext().getInitParameter(SessionManager.__SessionPath);
            if (path==null)
                path=getCrossContextSessionIDs()?"/":_handler.getHttpContext().getContextPath();
            if (path==null || path.length()==0)
                path="/";
            
            if (domain!=null)
                cookie.setDomain(domain);       
            if (maxAge!=null)
                cookie.setMaxAge(Integer.parseInt(maxAge));
            else
                cookie.setMaxAge(-1);
            
            cookie.setSecure(requestIsSecure && getSecureCookies());
            cookie.setPath(path);
            
            return cookie;    
        }
        return null;
    }
1196007
def _get_cookies_as_dict():
    
    config = ConfigParser.SafeConfigParser()
    config.read(_config)

    if config.has_section('cookies'):
        cookie_dict = {}
        for option in config.options('cookies'):
            option_key = option.upper() if option == 'jsessionid' else option
            cookie_dict[option_key] = config.get('cookies', option)

        return cookie_dict