summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2016-12-10 15:47:21 +0900
committerGitHub <noreply@github.com>2016-12-10 15:47:21 +0900
commitc083ff82a79a9e6fe5c7ed1525eb0e6bf0627de9 (patch)
tree2e1058163caec852b2be107124e181e2e320f287
parent159a24dc970cb8b521710ac38c652d219d49dc80 (diff)
parent698b52c16ba8b29533963e16a61a3bfa254a51ee (diff)
downloadruby-openssl-c083ff82a79a9e6fe5c7ed1525eb0e6bf0627de9.tar.gz
Merge pull request #88 from yogo1212/generalizedtime_format
asn1: handle GENERALIZEDTIME without seconds
-rw-r--r--ext/openssl/ossl_asn1.c12
-rw-r--r--test/test_asn1.rb8
2 files changed, 17 insertions, 3 deletions
diff --git a/ext/openssl/ossl_asn1.c b/ext/openssl/ossl_asn1.c
index af8ae2a6..534796f5 100644
--- a/ext/openssl/ossl_asn1.c
+++ b/ext/openssl/ossl_asn1.c
@@ -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:
diff --git a/test/test_asn1.rb b/test/test_asn1.rb
index 3a435414..a0ac1ddb 100644
--- a/test/test_asn1.rb
+++ b/test/test_asn1.rb
@@ -275,6 +275,14 @@ rEzBQ0F9dUyqQ9gyRg8KHhDfv9HzT1d/rnUZMkoombwYBRIUChGCYV0GnJcan2Zm
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