Giter Site home page Giter Site logo

Comments (7)

alex avatar alex commented on June 12, 2024

from pyopenssl.

FelixSchwarz avatar FelixSchwarz commented on June 12, 2024

How fun. Is the suggested solution something that works on Python 3.7?

No, I don't think so but this works:

$ python3.7
Python 3.7.16 (default, May 29 2023, 00:00:00) 
[GCC 13.1.1 20230511 (Red Hat 13.1.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import *
>>> datetime.now(timezone.utc)
datetime.datetime(2023, 7, 6, 20, 52, 13, 270136, tzinfo=datetime.timezone.utc)

from pyopenssl.

alex avatar alex commented on June 12, 2024

from pyopenssl.

reaperhulk avatar reaperhulk commented on June 12, 2024

The proposed solution creates a tzaware datetime, which can't be compared to a naïve. So the strptime parsed object will need to have a utc tzinfo added to it as well.

from pyopenssl.

FelixSchwarz avatar FelixSchwarz commented on June 12, 2024

The proposed solution creates a tzaware datetime, which can't be compared to a naïve. So the strptime parsed object will need to have a utc tzinfo added to it as well.

Yeah, I thought that was obvious. :-) My reply was intended to show that we can build a tz-aware "utcnow" even with Python 3.7.

Actually we could approach the problem in the code posted at the top in two ways:

  • compare tz-aware datetime instances (basically use datetime.strptime(time_string, "%Y%m%d%H%M%S%z"))
  • strip tzinfo from a tz-aware "utcnow" (datetime.now(timezone.utc).replace(tzinfo=None).

I am in favor of the second approach because self.get_notAfter() returns the "ASN.1 TIME" format which I think is supposed to always have a "Z" at the end. If we use %z as a format string for .strptime() we would accept also other formats.

Great. I guess we should use that everywhere. Are you interested in submitting a PR?

#1229

from pyopenssl.

FelixSchwarz avatar FelixSchwarz commented on June 12, 2024

PR merged, closing.

from pyopenssl.

alex avatar alex commented on June 12, 2024

from pyopenssl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.