pythonjwtpyopenssl

JWT header gives error "OpenSSL.crypto.Error: [('asn1 encoding routines', '', 'illegal zero content')]" on version 23.3.0 but works on earlier version


I recently updated my python/conda to 3.11. Included is a new version of OpenSSL. The below code has worked for some time on version 1.1.1, but now with version 3.0.1, the kid line is giving an error. Is there a new syntax, or another argument that needs to be passed?

from OpenSSL import crypto
headers = {'alg': 'RS256',
                             # this is the line that throws the error
           'kid': crypto.X509().digest('sha1').decode('utf-8').replace(':', ''), 
           'typ': 'JWT',
           }

Please let me know if more code is needed


Solution

  • Commented out the 'kid' line and the jwt is still accepted by the receiving end and produces the necessary token. I also had to update my pyjwt package to 2.8.0 from 2.4.0.