Skip to content
This repository has been archived by the owner on Jan 27, 2022. It is now read-only.

time.clock is deprecated - python 3.7 #283

Open
ErwinHaasnoot opened this issue Jan 29, 2019 · 19 comments · May be fixed by #296
Open

time.clock is deprecated - python 3.7 #283

ErwinHaasnoot opened this issue Jan 29, 2019 · 19 comments · May be fixed by #296

Comments

@ErwinHaasnoot
Copy link

When using RSA encrypt with PKCS1_AOEP padding, DeprecationWarnings are thrown.

Prerequisites: an RSA private key in mykey.pem

openssl genrsa -out mykey.pem 1024

Run the following with the "-W error" option to trigger the warning and print stacktrace:

import os
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP
from Crypto.Hash import SHA
with open('rsa.key') as f: key = f.read()
rsa_key = RSA.importKey(key)
rsa = PKCS1_OAEP.new(rsa_key, SHA)
encdata = rsa.encrypt(data)
Traceback (most recent call last):
  File "test.py", line 13, in <module>
    encdata = rsa.encrypt(data)
  File "/usr/local/lib/python3.7/site-packages/Crypto/Cipher/PKCS1_OAEP.py", line 152, in encrypt
    ros = randFunc(hLen)
  File "/usr/local/lib/python3.7/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 202, in read
    return self._singleton.read(bytes)
  File "/usr/local/lib/python3.7/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 178, in read
    return _UserFriendlyRNG.read(self, bytes)
  File "/usr/local/lib/python3.7/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 129, in read
    self._ec.collect()
  File "/usr/local/lib/python3.7/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 77, in collect
    t = time.clock()
DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead```

@tirkarthi
Copy link

time.clock is now removed in 3.8 : python/cpython#13270

@fabiant7t fabiant7t linked a pull request Nov 18, 2019 that will close this issue
dave-shawley added a commit to dave-shawley/pyjwt that referenced this issue Nov 24, 2019
Note that pycrypto does not work with python 3.8 since they removed
`time.clock` altogether.

pycrypto/pycrypto#283
dave-shawley added a commit to dave-shawley/pyjwt that referenced this issue Nov 24, 2019
Note that pycrypto does not work with python 3.8 since they removed
`time.clock` altogether.

pycrypto/pycrypto#283
@rhanka
Copy link

rhanka commented Jan 9, 2020

python 3.8 is now the official 3 for docker images

This problem has then to be solved for most people who will use python 3 with docker.

We have the problem, as we use a docker container for encrypting fake data in our travis process (https://github.com/histovec/histovec-beta/). Even if the resource is not critical for our project, is would seem hygienic to solve this

...
    iv = Random.new.read(AES.bloc_ksize)
  File "/usr/local/lib/python3.7/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 202, in read
    return self._singleton.read(bytes)
  File "/usr/local/lib/python3.7/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 178, in read
    return _UserFriendlyRNG.read(self, bytes)
  File "/usr/local/lib/python3.7/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 129, in read
    self._ec.collect()
  File "/usr/local/lib/python3.7/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 77, in collect
    t = time.clock()
DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead

Users of the Crytpo lib with docker must now downgrade using a FROM python:3.7-slim (or FROM python:3.7) instead of FROM python:3-slim (or FROM python:3) in their Dockerfile, at least until the problem has been fixed and close here.

@ErwinHaasnoot
Copy link
Author

ErwinHaasnoot commented Jan 10, 2020 via email

@rhanka
Copy link

rhanka commented Jan 10, 2020

Thank your for your response - this explanation is profitable !

@cs01
Copy link

cs01 commented Feb 8, 2020

@ErwinHaasnoot if this library is deprecated, could it be marked as such on PyPI, GitHub and other relevant pages? It is not clear when stumbling across the project from search results. I luckily found it when running into this Python 3.8 incompatibility.

@ErwinHaasnoot
Copy link
Author

ErwinHaasnoot commented Feb 8, 2020 via email

@ThanhTuNguyen
Copy link

Please fix this bug, downgrade to 3.7 is not the acceptable solution

@SwapnilSoni1999
Copy link

2020 and still no fixed yet

@michael-k
Copy link

@SwapnilSoni1999 see above:

Please note that this library has been deprecated and one should
switch to pycryptodome for an API-compatible, updated lib, or to
cryptography.io for a more modern API.

@SwapnilSoni1999
Copy link

Okay thanks tho <3
I would suggest to archive or add deprecated tag/text on title description

@cs01
Copy link

cs01 commented Jun 3, 2020

Good idea #283 (comment)

@whitespots
Copy link

+1 to waiters

@dingyaguang117
Copy link

Please try this polyfill

time.clock = time.process_time

@cccnrc
Copy link

cccnrc commented Dec 12, 2020

+1 to waiters

@AyliD
Copy link

AyliD commented Dec 15, 2020

+1 for waiter

1 similar comment
@Pitastic
Copy link

+1 for waiter

@cygnusb
Copy link

cygnusb commented Feb 24, 2021

+1

@jfunction
Copy link

waiter++

@jfunction
Copy link

waiter--
I switched to pycryptodome and that worked for me.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.