Skip to content
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

Add support of python 3.8 #452

Merged
merged 1 commit into from
Dec 27, 2019
Merged

Add support of python 3.8 #452

merged 1 commit into from
Dec 27, 2019

Conversation

Djailla
Copy link
Contributor

@Djailla Djailla commented Oct 22, 2019

Python 3.8 is out, let's make pyjwt CI and package compatible

@coveralls
Copy link

coveralls commented Oct 22, 2019

Pull Request Test Coverage Report for Build 110

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at ?%

Totals Coverage Status
Change from base Build 106: 0.0%
Covered Lines:
Relevant Lines: 0

💛 - Coveralls

@Djailla
Copy link
Contributor Author

Djailla commented Oct 29, 2019

@jpadilla Hello, could you take a look at my PR, especially the error I got with python 3.8 with incompatibility with pycrypto (no longer supported library) using time.clock deprecated in Python 3.8.

Thanks !

@Djailla
Copy link
Contributor Author

Djailla commented Oct 29, 2019

Here is the stack trace :

_ TestPycryptoAlgorithms.test_rsa_sign_should_generate_correct_signature_value _

self = <tests.contrib.test_algorithms.TestPycryptoAlgorithms object at 0x7fba84ebf2e0>

    def test_rsa_sign_should_generate_correct_signature_value(self):
        algo = RSAAlgorithm(RSAAlgorithm.SHA256)
    
        jwt_message = force_bytes("Hello World!")
    
        expected_sig = base64.b64decode(
            force_bytes(
                "yS6zk9DBkuGTtcBzLUzSpo9gGJxJFOGvUqN01iLhWHrzBQ9ZEz3+Ae38AXp"
                "10RWwscp42ySC85Z6zoN67yGkLNWnfmCZSEv+xqELGEvBJvciOKsrhiObUl"
                "2mveSc1oeO/2ujkGDkkkJ2epn0YliacVjZF5+/uDmImUfAAj8lzjnHlzYix"
                "sn5jGz1H07jYYbi9diixN8IUhXeTafwFg02IcONhum29V40Wu6O5tAKWlJX"
                "fHJnNUzAEUOXS0WahHVb57D30pcgIji9z923q90p5c7E2cU8V+E1qe8NdCA"
                "APCDzZZ9zQ/dgcMVaBrGrgimrcLbPjueOKFgSO+SSjIElKA=="
            )
        )
    
        with open(key_path("testkey_rsa"), "r") as keyfile:
            jwt_key = algo.prepare_key(keyfile.read())
    
        with open(key_path("testkey_rsa.pub"), "r") as keyfile:
            jwt_pub_key = algo.prepare_key(keyfile.read())
    
>       algo.sign(jwt_message, jwt_key)

tests/contrib/test_algorithms.py:68: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
jwt/contrib/algorithms/pycrypto.py:44: in sign
    return PKCS1_v1_5.new(key).sign(self.hash_alg.new(msg))
.tox/py38-contrib_crypto/lib/python3.8/site-packages/Crypto/Signature/PKCS1_v1_5.py:112: in sign
    m = self._key.decrypt(em)
.tox/py38-contrib_crypto/lib/python3.8/site-packages/Crypto/PublicKey/RSA.py:174: in decrypt
    return pubkey.pubkey.decrypt(self, ciphertext)
.tox/py38-contrib_crypto/lib/python3.8/site-packages/Crypto/PublicKey/pubkey.py:93: in decrypt
    plaintext=self._decrypt(ciphertext)
.tox/py38-contrib_crypto/lib/python3.8/site-packages/Crypto/PublicKey/RSA.py:235: in _decrypt
    r = getRandomRange(1, self.key.n-1, randfunc=self._randfunc)
.tox/py38-contrib_crypto/lib/python3.8/site-packages/Crypto/Util/number.py:123: in getRandomRange
    value = getRandomInteger(bits, randfunc)
.tox/py38-contrib_crypto/lib/python3.8/site-packages/Crypto/Util/number.py:104: in getRandomInteger
    S = randfunc(N>>3)
.tox/py38-contrib_crypto/lib/python3.8/site-packages/Crypto/Random/_UserFriendlyRNG.py:202: in read
    return self._singleton.read(bytes)
.tox/py38-contrib_crypto/lib/python3.8/site-packages/Crypto/Random/_UserFriendlyRNG.py:178: in read
    return _UserFriendlyRNG.read(self, bytes)
.tox/py38-contrib_crypto/lib/python3.8/site-packages/Crypto/Random/_UserFriendlyRNG.py:129: in read
    self._ec.collect()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <Crypto.Random._UserFriendlyRNG._EntropyCollector object at 0x7fba84ebfd30>

    def collect(self):
        # Collect 64 bits of entropy from the operating system and feed it to Fortuna.
        self._osrng_es.feed(self._osrng.read(8))
    
        # Add the fractional part of time.time()
        t = time.time()
        self._time_es.feed(struct.pack("@I", int(2**30 * (t - floor(t)))))
    
        # Add the fractional part of time.clock()
>       t = time.clock()
E       AttributeError: module 'time' has no attribute 'clock'

.tox/py38-contrib_crypto/lib/python3.8/site-packages/Crypto/Random/_UserFriendlyRNG.py:77: AttributeError```

@jpadilla jpadilla merged commit 09f2e20 into jpadilla:master Dec 27, 2019
@Djailla Djailla deleted the py38 branch December 27, 2019 17:31
@tirkarthi
Copy link

The error due to time.clock is an upstream issue : pycrypto/pycrypto#283 . The upstream package is not maintained so it would make sense to look into pycryptodome as noted in the message for compatibility.

Thanks.

@jpadilla jpadilla added this to the v2.0.0 milestone Dec 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants