Ask Your Question
0

How to distinguish notBefore and notAfter Fields in x509af.utcTime?

asked 2025-06-05 07:00:28 +0000

updated 2025-06-05 11:26:17 +0000

Chuckc gravatar image

Dear,

"The field name x509af.utcTime appears multiple times (e.g., for notBefore and notAfter). How can I differentiate between these two values in a Lua script to check a certificate's validity?"

Best regards,

Tom

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2025-06-05 11:16:13 +0000

Chuckc gravatar image

updated 2025-06-05 11:17:20 +0000

x509af.notBefore and x509af.notAfter are BER encoded (TLV = Type, Length, Value) fields.
(Look for UTCTime 23 17 in A Layman's Guide to a Subset of ASN.1, BER, and DER)

epan/dissectors/packet-x509af.c:

static const ber_sequence_t Validity_sequence[] = {
  { &hf_x509af_notBefore    , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_x509af_Time },
  { &hf_x509af_notAfter     , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_x509af_Time },
  { NULL, 0, 0, 0, NULL }
};

BER is visible in the packet details by enabling the BER preference
ber.show_internals Changed Boolean TRUE

notBefore: utcTime (0)
    00.. .... = Class: UNIVERSAL (0)
    ..0. .... = P/C: Primitive Encoding
    ...1 0111 = Tag: UTCTime (23)
    Length: 13
    utcTime: 2015-12-16 01:00:05 (UTC)

notAfter: utcTime (0)
    00.. .... = Class: UNIVERSAL (0)
    ..0. .... = P/C: Primitive Encoding
    ...1 0111 = Tag: UTCTime (23)
    Length: 13
    utcTime: 2030-12-16 01:00:05 (UTC)

Packet bytes 0000 17 0d 31 35 31 32 31 36 30 31 30 30 30 35 5a ..151216010005Z
decodes as 0x17 = decimal 23 = UTCTime (23)
0x0d = decimal 13 = Length: 13
Remaining 13 (from length above) bytes are time string.

notBefore: utcTime (0)
    00.. .... = Class: UNIVERSAL (0)
    ..0. .... = P/C: Primitive Encoding
    ...1 0111 = Tag: UTCTime (23)
    Length: 13
    utcTime: 2015-12-16 01:00:05 (UTC)

Your lua code could grab x509af.notBefore and x509af.notAfter, verify type (0x17) and length (length field + 2 bytes for type and length bytes) then use an offset of two bytes into the field for the time string.

edit flag offensive delete link more

Comments

No personal experience but this might help: Firanel / lua-ber: Lua BER encoding / decoding

Chuckc gravatar imageChuckc ( 2025-06-05 11:24:53 +0000 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2025-06-05 07:00:28 +0000

Seen: 28 times

Last updated: yesterday