demarches-normaliennes/app/lib/asn1/timestamp.rb
2024-08-22 09:26:48 +02:00

27 lines
1 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# frozen_string_literal: true
class ASN1::Timestamp
## Poor mans rfc3161 timestamp decoding
# This works, as of 2019-05, for timestamps delivered by the universign POST api.
# We should properly access the ASN1 contents using the sequence and tags structure.
# However:
# * Its hard to do right.
# * We currently dont require it for proper operation; timestamps are never exposed to users.
# * Theres an ongoing PR https://github.com/ruby/openssl/pull/204 for proper timestamp decoding in the ruby openssl library; lets use OpenSSL::TS once it exists.
def self.timestampInfo(asn1timestamp)
asn1 = OpenSSL::ASN1.decode(asn1timestamp)
tstInfo = OpenSSL::ASN1.decode(asn1.value[1].value[0].value[2].value[1].value[0].value)
tstInfo
end
def self.signature_time(asn1timestamp)
tstInfo = timestampInfo(asn1timestamp)
tstInfo.value[4].value
end
def self.signed_digest(asn1timestamp)
tstInfo = timestampInfo(asn1timestamp)
tstInfo.value[2].value[1].value.unpack1('H*')
end
end