def verify_rsa_sha1_signature(client_certificate, signature, method, url, oauth_params=None, *args, **kwargs): """ Verifies a RSA-SHA1 OAuth signature. :see: RSA-SHA1 (http://tools.ietf.org/html/rfc5849#section-3.4.3) :param client_certificate: PEM-encoded X.509 certificate or RSA public key. :param signature: RSA-SHA1 OAuth signature. :param method: Base string HTTP method. :param url: Base string URL that may include a query string. All protocol-specific parameters will be ignored from the query string. :param oauth_params: Base string protocol-specific query parameters. All non-protocol parameters will be ignored. :returns: ``True`` if verified to be correct; ``False`` otherwise. """ from pyoauth.crypto.rsa import create_public_key oauth_params = oauth_params or {} base_string = generate_signature_base_string(method, url, oauth_params) key = create_public_key(client_certificate) return key.pkcs1_v1_5_verify(sha1_digest(base_string), base64_decode(signature))
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)))