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

asn1: handle GENERALIZEDTIME without seconds #88

Merged
merged 2 commits into from
Dec 10, 2016
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
12 changes: 9 additions & 3 deletions ext/openssl/ossl_asn1.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,15 @@ asn1time_to_time(const ASN1_TIME *time)
}
break;
case V_ASN1_GENERALIZEDTIME:
if (sscanf((const char *)time->data, "%4d%2d%2d%2d%2d%2dZ", &tm.tm_year, &tm.tm_mon,
&tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) {
ossl_raise(rb_eTypeError, "bad GENERALIZEDTIME format" );
count = sscanf((const char *)time->data, "%4d%2d%2d%2d%2d%2dZ",
&tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min,
&tm.tm_sec);
if (count == 5) {
tm.tm_sec = 0;
}
else if (count != 6) {
ossl_raise(rb_eTypeError, "bad GENERALIZEDTIME format: \"%s\"",
time->data);
}
break;
default:
Expand Down
8 changes: 8 additions & 0 deletions test/test_asn1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,14 @@ def test_encode_utctime_2k38
assert_equal 2 ** 31, OpenSSL::ASN1.decode(encoded).value.to_i
end

def test_decode_generalisedtime
expected = Time.at 1481225640
assert_equal expected, OpenSSL::ASN1.decode("\x18\x0D201612081934Z").value

expected += 29
assert_equal expected, OpenSSL::ASN1.decode("\x18\x0F20161208193429Z").value
end

def test_decode_enumerated
encoded = OpenSSL::ASN1.Enumerated(0).to_der
assert_equal "\x0a\x01\x00".b, encoded
Expand Down