CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-python3-openid

OpenID support for modern servers and consumers with comprehensive authentication functionality.

Pending
Overview
Eval results
Files

utilities.mddocs/

OpenID Utilities

Core utility functions and classes providing essential functionality for OpenID implementations. These utilities handle URI normalization, cryptographic operations, key-value form processing, logging, and Diffie-Hellman key exchange operations.

Capabilities

Logging and Debugging

Logging infrastructure and debugging utilities for OpenID operations.

def log(message, level=0):
    """
    Log a message at the specified level.
    
    Parameters:
    - message: str, the message to log
    - level: int, logging level (0=DEBUG, 1=INFO, 2=WARNING, 3=ERROR)
    """

def autoSubmitHTML(form, title='OpenID transaction in progress'):
    """
    Generate HTML page that automatically submits a form.
    
    Parameters:
    - form: str, HTML form markup to auto-submit
    - title: str, page title for the auto-submit page
    
    Returns:
    str: Complete HTML page with auto-submit JavaScript
    """

def toUnicode(value):
    """
    Convert value to Unicode string.
    
    Parameters:
    - value: str or bytes, value to convert
    
    Returns:
    str: Unicode representation of the input value
    """

URI Normalization

RFC 3986 compliant URI normalization for OpenID identifier processing.

def urinorm(uri):
    """
    Normalize a URI according to RFC 3986.
    
    Parameters:
    - uri: str, URI to normalize
    
    Returns:
    str: Normalized URI
    
    Raises:
    ValueError: if URI contains illegal characters or malformed components
    """

def urlnorm(url):
    """
    Normalize a URL (alias for urinorm).
    
    Parameters:
    - url: str, URL to normalize
    
    Returns:
    str: Normalized URL
    """

def urlencode_unreserved(query):
    """
    URL encode query parameters, leaving unreserved characters unencoded.
    
    Parameters:
    - query: dict or list of tuples, query parameters
    
    Returns:
    str: URL encoded query string
    """

Key-Value Form Processing

Processing of OpenID key-value form data format.

def kvToDict(kv):
    """
    Parse key-value form data into a dictionary.
    
    Parameters:
    - kv: str, key-value form data (key:value\\nkey:value format)
    
    Returns:
    dict: Parsed key-value pairs
    
    Raises:
    ValueError: if form data is malformed
    """

def dictToKV(data):
    """
    Convert dictionary to key-value form data format.
    
    Parameters:
    - data: dict, key-value pairs to encode
    
    Returns:
    str: Key-value form data string
    """

def seqToKV(seq, sep=':'):
    """
    Convert sequence of pairs to key-value format.
    
    Parameters:
    - seq: list of tuples, key-value pairs
    - sep: str, separator character (default ':')
    
    Returns:
    str: Key-value formatted string
    """

Cryptographic Utilities

Cryptographic helper functions for OpenID operations.

def randomString(length, chrs=None):
    """
    Generate cryptographically secure random string.
    
    Parameters:
    - length: int, desired string length
    - chrs: str, character set to use (default: base64 characters)
    
    Returns:
    str: Random string of specified length
    """

def sha1(data):
    """
    Compute SHA-1 hash of data.
    
    Parameters:
    - data: bytes, data to hash
    
    Returns:
    bytes: SHA-1 hash digest
    """

def sha256(data):
    """
    Compute SHA-256 hash of data.
    
    Parameters:
    - data: bytes, data to hash
    
    Returns:
    bytes: SHA-256 hash digest
    """

def hmacSha1(key, data):
    """
    Compute HMAC-SHA1 of data with key.
    
    Parameters:
    - key: bytes, HMAC key
    - data: bytes, data to authenticate
    
    Returns:
    bytes: HMAC-SHA1 digest
    """

def hmacSha256(key, data):
    """
    Compute HMAC-SHA256 of data with key.
    
    Parameters:
    - key: bytes, HMAC key
    - data: bytes, data to authenticate
    
    Returns:
    bytes: HMAC-SHA256 digest
    """

Base64 Encoding

Base64 encoding utilities for OpenID data handling.

def toBase64(data):
    """
    Encode data to base64 string.
    
    Parameters:
    - data: bytes, data to encode
    
    Returns:
    str: Base64 encoded string
    """

def fromBase64(data):
    """
    Decode base64 string to bytes.
    
    Parameters:
    - data: str, base64 encoded string
    
    Returns:
    bytes: Decoded data
    
    Raises:
    ValueError: if input is not valid base64
    """

Diffie-Hellman Key Exchange

Diffie-Hellman key exchange implementation for secure association establishment.

class DiffieHellman:
    """
    Diffie-Hellman key exchange implementation.
    """
    
    def __init__(self, modulus, generator, private=None):
        """
        Initialize DH parameters.
        
        Parameters:
        - modulus: int, DH modulus (p)
        - generator: int, DH generator (g)
        - private: int, private key (optional, generated if not provided)
        """
    
    def createKeyExchange(cls, modulus=None, generator=None):
        """
        Create a new DH key exchange with default or custom parameters.
        
        Parameters:
        - modulus: int, DH modulus (default: OpenID default modulus)
        - generator: int, DH generator (default: 2)
        
        Returns:
        DiffieHellman: New DH instance
        """
    
    def getSharedSecret(self, other_public):
        """
        Compute shared secret from other party's public key.
        
        Parameters:
        - other_public: int, other party's public key
        
        Returns:
        bytes: Shared secret
        """
    
    def xorSecret(self, hash_func, shared_secret, composite):
        """
        XOR secret with composite using hash function.
        
        Parameters:
        - hash_func: callable, hash function (sha1 or sha256)
        - shared_secret: bytes, DH shared secret
        - composite: bytes, data to XOR with hashed secret
        
        Returns:
        bytes: XORed result
        """

# DH Constants
DEFAULT_MOD = 155172898181473697471232257763715539915724801966915404479707795314057629378541917580651227423698188993727816152646631438561595825688188889951272158842675419950341258706556549803580104870537681476726513255747040765857479291291572334510643245094715007229621094194349783925984760375594985848253359305585439638443
DEFAULT_GEN = 2

Install with Tessl CLI

npx tessl i tessl/pypi-python3-openid

docs

association-management.md

consumer-auth.md

discovery.md

extensions.md

index.md

message-processing.md

server-implementation.md

storage-backends.md

utilities.md

tile.json