Skip to content

Improved nonce safety #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions woocommerce/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
__license__ = "MIT"

from time import time
from random import randint
from os import urandom
from hmac import new as HMAC
from hashlib import sha1, sha256
from base64 import b64encode
from hashlib import sha256
from base64 import b64encode, urlsafe_b64encode
from collections import OrderedDict
from urllib.parse import urlencode, quote, unquote, parse_qsl, urlparse

Expand Down Expand Up @@ -122,10 +122,5 @@ def get_value_like_as_php(val):

@staticmethod
def generate_nonce():
""" Generate nonce number """
nonce = ''.join([str(randint(0, 9)) for i in range(8)])
return HMAC(
nonce.encode(),
"secret".encode(),
sha1
).hexdigest()
"""Generate a crypto safe random 32-byte string and encode it in Base64"""
return urlsafe_b64encode(urandom(32)).decode('utf-8').rstrip('=')