From 7dcc66d7e161515029c9126c33e2a536cdb32567 Mon Sep 17 00:00:00 2001 From: gswilcox01 Date: Fri, 20 Jan 2017 17:50:24 -0600 Subject: [PATCH 1/2] gitignores --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index e75cfbc..b78ebbf 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,7 @@ virtualenv/* .coverage !.gitignore !.gitmodules +venv/* +/.project +/.pydevproject +/.settings From b9b03ff0c3663bc2f6d6a469201f8c02f234f7bf Mon Sep 17 00:00:00 2001 From: gswilcox01 Date: Fri, 20 Jan 2017 18:29:22 -0600 Subject: [PATCH 2/2] Added SHA256 sig method --- rauth/oauth.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/rauth/oauth.py b/rauth/oauth.py index 5dc44b1..74c3a69 100644 --- a/rauth/oauth.py +++ b/rauth/oauth.py @@ -10,6 +10,7 @@ import hmac from hashlib import sha1 +from hashlib import sha256 from rauth.compat import is_basestring, quote, urlencode, urlsplit, urlunsplit from rauth.utils import FORM_URLENCODED @@ -102,16 +103,17 @@ def _normalize_request_parameters(self, oauth_params, req_kwargs): .replace('+', '%20')\ .replace('%7E', '~') - -class HmacSha1Signature(SignatureMethod): +class HmacShaAnySignature(SignatureMethod): ''' - HMAC-SHA1 Signature Method. + Parent class for HMAC-SHA1 or HMAC-SHA256 Signature Method. This is a signature method, as per the OAuth 1.0/a specs. As the name - might suggest, this method signs parameters with HMAC using SHA1. + might suggest, this method signs parameters with HMAC using SHA1 or SHA256. ''' - NAME = 'HMAC-SHA1' - + def __init__(self, name, sha_hash): + self.NAME = name + self.HASH = sha_hash + def sign(self, consumer_secret, access_token_secret, @@ -148,12 +150,20 @@ def sign(self, # build a Signature Base String signature_base_string = b'&'.join(parameters) - # hash the string with HMAC-SHA1 - hashed = hmac.new(key, signature_base_string, sha1) + # hash the string with HMAC-SHA* + hashed = hmac.new(key, signature_base_string, self.HASH) # return the signature return base64.b64encode(hashed.digest()).decode() +class HmacSha1Signature(HmacShaAnySignature): + def __init__(self): + HmacShaAnySignature.__init__(self, 'HMAC-SHA1', sha1) + +class HmacSha256Signature(HmacShaAnySignature): + def __init__(self): + HmacShaAnySignature.__init__(self, 'HMAC-SHA256', sha256) + class RsaSha1Signature(SignatureMethod): '''