auth/__init__.py
def _parse_security_token(token):
    """Parse a CHIRP security token.

    Returns:
      A Credentials object, or None if the token is not valid.
      If a Credentials object is returned, its "user" field will not
      be set.
    """
    if not token:
        return None
    if ':' not in token:
        logging.warn('Malformed token: no signature separator')
        return None
    sig, body = token.split(':', 1)
    if _DISABLE_CRYPTO:
        plaintext = body
    else:
        key_storage = KeyStorage.get()
        hmac_key = key_storage.hmac_key
        if type(hmac_key) == unicode:
            # Crypto requires byte strings
            hmac_key = hmac_key.encode('utf8')
        computed_sig = HMAC.HMAC(key=hmac_key,
                                 msg=body).hexdigest()
        if sig != computed_sig:
            logging.warn('Malformed token: invalid signature')
            return None
        try:
            plaintext = AES.new(key_storage.aes_key,
                                AES.MODE_CBC).decrypt(body)
        except ValueError:
            logging.warn('Malformed token: wrong size')
            return None
    # Remove excess whitespace.
    plaintext = plaintext.strip()
    # The plaintext should contain at least one space.
    if ' ' not in plaintext:
        logging.warn('Malformed token: bad contents')
        return None
    parts = plaintext.split(' ')
    if len(parts) != 2:
        logging.warn('Malformed token: bad structure')
        return None
    timestamp, email = parts
    try:
        timestamp = int(timestamp, 16)
    except ValueError:
        logging.warn('Malformed token: bad timestamp')
        return None
    # Reject tokens that are too old or which have time-traveled.  We
    # allow for 1s of clock skew.
    age_s = time.time() - timestamp
    if age_s < -1 or age_s > _TOKEN_TIMEOUT_S:
        logging.warn('Malformed token: expired (age=%ds)', age_s)
        return None
    cred = _Credentials()
    cred.email = email
    cred.security_token_is_stale = (age_s > 0.5 * _TOKEN_TIMEOUT_S)
    return cred
Parse a CHIRP security token.

    Returns:
      A Credentials object, or None if the token is not valid.
      If a Credentials object is returned, its "user" field will not
      be set.
    
Parse a CHIRP security token.
Parse a CHIRP security token .
def _parse_security_token(token):
    if not token:
        return None
    if ':' not in token:
        logging.warn('Malformed token: no signature separator')
        return None
    sig, body = token.split(':', 1)
    if _DISABLE_CRYPTO:
        plaintext = body
    else:
        key_storage = KeyStorage.get()
        hmac_key = key_storage.hmac_key
        if type(hmac_key) == unicode:
            hmac_key = hmac_key.encode('utf8')
        computed_sig = HMAC.HMAC(key=hmac_key,
                                 msg=body).hexdigest()
        if sig != computed_sig:
            logging.warn('Malformed token: invalid signature')
            return None
        try:
            plaintext = AES.new(key_storage.aes_key,
                                AES.MODE_CBC).decrypt(body)
        except ValueError:
            logging.warn('Malformed token: wrong size')
            return None
    plaintext = plaintext.strip()
    if ' ' not in plaintext:
        logging.warn('Malformed token: bad contents')
        return None
    parts = plaintext.split(' ')
    if len(parts) != 2:
        logging.warn('Malformed token: bad structure')
        return None
    timestamp, email = parts
    try:
        timestamp = int(timestamp, 16)
    except ValueError:
        logging.warn('Malformed token: bad timestamp')
        return None
    age_s = time.time() - timestamp
    if age_s < -1 or age_s > _TOKEN_TIMEOUT_S:
        logging.warn('Malformed token: expired (age=%ds)', age_s)
        return None
    cred = _Credentials()
    cred.email = email
    cred.security_token_is_stale = (age_s > 0.5 * _TOKEN_TIMEOUT_S)
    return cred
def _parse_security_token ( token ) : if not token : return None if ':' not in token : logging . warn ( 'Malformed token: no signature separator' ) return None sig , body = token . split ( ':' , 1 ) if _DISABLE_CRYPTO : plaintext = body else : key_storage = KeyStorage . get ( ) hmac_key = key_storage . hmac_key if type ( hmac_key ) == unicode : hmac_key = hmac_key . encode ( 'utf8' ) computed_sig = HMAC . HMAC ( key = hmac_key , msg = body ) . hexdigest ( ) if sig != computed_sig : logging . warn ( 'Malformed token: invalid signature' ) return None try : plaintext = AES . new ( key_storage . aes_key , AES . MODE_CBC ) . decrypt ( body ) except ValueError : logging . warn ( 'Malformed token: wrong size' ) return None plaintext = plaintext . strip ( ) if ' ' not in plaintext : logging . warn ( 'Malformed token: bad contents' ) return None parts = plaintext . split ( ' ' ) if len ( parts ) != 2 : logging . warn ( 'Malformed token: bad structure' ) return None timestamp , email = parts try : timestamp = int ( timestamp , 16 ) except ValueError : logging . warn ( 'Malformed token: bad timestamp' ) return None age_s = time . time ( ) - timestamp if age_s < - 1 or age_s > _TOKEN_TIMEOUT_S : logging . warn ( 'Malformed token: expired (age=%ds)' , age_s ) return None cred = _Credentials ( ) cred . email = email cred . security_token_is_stale = ( age_s > 0.5 * _TOKEN_TIMEOUT_S ) return cred
Parse a CHIRP security token.
Parse a CHIRP security token .
"""Parse a CHIRP security token.

    Returns:
      A Credentials object, or None if the token is not valid.
      If a Credentials object is returned, its "user" field will not
      be set.
    """ # Crypto requires byte strings # Remove excess whitespace. # The plaintext should contain at least one space. # Reject tokens that are too old or which have time-traveled.  We # allow for 1s of clock skew.
A Credentials object, or None if the token is not valid.
If a Credentials object is returned, its "user" field will not
be set.
A Credentials object or None if the token is not valid . If a Credentials object is returned its " user " field will not be set .
token