Example #1
0
def generate_rsa_sha1_signature(client_private_key,
                                method, url, oauth_params=None,
                                *args, **kwargs):
    """
    Calculates an RSA-SHA1 OAuth signature.

    :see: RSA-SHA1 (http://tools.ietf.org/html/rfc5849#section-3.4.3)

    :param client_private_key:
        PEM-encoded RSA private key.
    :param method:
        Base string HTTP method.
    :param url:
        Base string URL that may include a query string.
        All protocol-specific paramters will be ignored from the query string.
    :param oauth_params:
        Base string protocol-specific query parameters.
        All non-protocol parameters will be ignored.
    :returns:
        RSA-SHA1 signature.
    """
    from pyoauth.crypto.rsa import create_private_key

    oauth_params = oauth_params or {}
    base_string = generate_signature_base_string(method, url, oauth_params)

    key = create_private_key(client_private_key)
    return base64_encode(key.pkcs1_v1_5_sign(sha1_digest(base_string)))
Example #2
0
def der_to_pem(der_cert_bytes, pem_header, pem_footer):
    """
    Takes a certificate in binary DER format and returns the
    PEM version of it as a string.

    Taken from the Python SSL module.

    :param der_cert_bytes:
        A byte string of the DER.
    :param pem_header:
        The PEM header to use.
    :param pem_footer:
        The PEM footer to use.
    """
    # Does what base64.b64encode without the `altchars` argument does.
    f = base64_encode(der_cert_bytes)
    return (pem_header + '\n' +
            textwrap.fill(f, 64) + '\n' +
            pem_footer + '\n')