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

Handle forever certificates #14

Merged
merged 4 commits into from Jun 8, 2023
Merged

Handle forever certificates #14

merged 4 commits into from Jun 8, 2023

Conversation

ghost
Copy link

@ghost ghost commented Jun 7, 2023

Creating a certificate using ssh-keygen with no expiry will cause the parser to throw an OverFlow error:

Traceback (most recent call last):
  File "/tmp/test.py", line 4, in <module>
    cert = SSHCertificate.from_file('/tmp/cert')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ssh_certificate_parser/__init__.py", line 102, in from_file
    return cls.from_file(f)
           ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ssh_certificate_parser/__init__.py", line 103, in from_file
    return cls.from_bytes(path_or_file_object.read())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ssh_certificate_parser/__init__.py", line 155, in from_bytes
    valid_before = datetime.datetime.utcfromtimestamp(valid_before)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OverflowError: timestamp out of range for platform time_t

If creating a certificate that is valid forever, the valid_after value will be set to 0 and the valid_before value will be set to a high number. Since CPython can only handle up to the year 9999 (ref) any values higher than that should be changed to the year 9999.

Copy link
Member

@Justintime50 Justintime50 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome, thank you! 😃

@Justintime50 Justintime50 merged commit ef4d888 into EasyPost:master Jun 8, 2023
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.

2 participants