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

Fix invalid cast from ASN1_TIME to ASN1_GENERALIZEDTIME #612

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def find_meta(meta):
package_dir={"": "src"},
install_requires=[
# Fix cryptographyMinimum in tox.ini when changing this!
"cryptography>=1.7",
"cryptography>=1.9",
"six>=1.5.2"
],
)
14 changes: 3 additions & 11 deletions src/OpenSSL/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _set_asn1_time(boundary, when):
"""
The the time value of an ASN1 time object.

@param boundary: An ASN1_GENERALIZEDTIME pointer (or an object safely
@param boundary: An ASN1_TIME pointer (or an object safely
castable to that type) which will have its value set.
@param when: A string representation of the desired time value.

Expand All @@ -116,17 +116,9 @@ def _set_asn1_time(boundary, when):
if not isinstance(when, bytes):
raise TypeError("when must be a byte string")

set_result = _lib.ASN1_GENERALIZEDTIME_set_string(
_ffi.cast('ASN1_GENERALIZEDTIME*', boundary), when)
set_result = _lib.ASN1_TIME_set_string(boundary, when)
if set_result == 0:
dummy = _ffi.gc(_lib.ASN1_STRING_new(), _lib.ASN1_STRING_free)
_lib.ASN1_STRING_set(dummy, when, len(when))
check_result = _lib.ASN1_GENERALIZEDTIME_check(
_ffi.cast('ASN1_GENERALIZEDTIME*', dummy))
if not check_result:
raise ValueError("Invalid string")
else:
_untested_error()
raise ValueError("Invalid string")


def _get_asn1_time(timestamp):
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ deps =
coverage>=4.2
pytest>=3.0.1
cryptographyMaster: git+https://github.com/pyca/cryptography.git
cryptographyMinimum: cryptography<1.8
cryptographyMinimum: cryptography<=1.9
setenv =
# Do not allow the executing environment to pollute the test environment
# with extra packages.
Expand Down