1

I am running few security algorithms on my product and would like know few general details about the CRLs (Certificate Revocation Lists).

I am using the following command openssl asn1parse -inform DER -in signed.p7s >> sign_extract.txt to extract the information(crls) from my CA signed file(signed.p7s).Based on the string "id-smime-aa-timeStampToken" i am extracting the time information from offset and length of that particular field (sign_extract.txt). Below is the extracted time stamp

Time stamp: Oct 8 15:04:56 2020 GMT Accuracy: 0x02 seconds,

unspecified millis, unspecified micros

My questions are:

  1. The time present in CRL, is it always going to be in GMT or can have different format?

Most of my devices are set with some old date, so when running my algorithms i am extracting the time info as above and run my secure algorithms for validity of certificates.

  1. Is it ok if we extract using "id-smime-aa-timeStampToken" or we have any other generic way?

  2. My final aim is convert the time into unix epoch,is there any generic way to do that?

EDIT 1: This is from the example of man page timegm, on how to set & clear the timezone once the conversion is complete. Added just for the completeness.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

int main(void)
{
    struct tm tm;
    char buf[255];
    char *tz;
    tz = getenv("TZ");
    if (tz)
        tz = strdup(tz);
    setenv("TZ", "", 1);
    tzset();

    memset(&tm, 0, sizeof(struct tm));
    strptime("Oct 8 15:04:56 2020 GMT", "%B %d %H:%M:%S %Y GMT", &tm);
    strftime(buf, sizeof(buf), "%s", &tm);

    if (tz) {
       setenv("TZ", tz, 1);
      free(tz);
    } else
     unsetenv("TZ");
    tzset();
    puts(buf);
    exit(EXIT_SUCCESS);
}
4
  • 1
    RFC 5280 &sect;4.1.2.5.1 and &sect;4.1.2.5.2 state Validity times must be in Greenwich Mean Time (Zulu). Not sure about your #2 and #3 though; #3 depends on how you're doing all this (shell script? Python? C?) – gowenfawr Oct 29 '20 at 15:31
  • thanks @gowenfawr for letting me know the #1, for #2 and #3 am trying to use linux utilities like date command and functions like maketime locatime in C would like to know is there any generic way – csavvy Oct 29 '20 at 15:39
  • The date command can convert to epoch time, e.g. date --date='Oct 8 15:04:56 2020 GMT' '+%s'. The '+%s' tells it to output seconds since the epoch. – gowenfawr Oct 29 '20 at 15:53
  • Yes, infact i am using something similar date -d "Jul 10 15:20:25 2020 GMT" +%s , only problem with that is i will have to invoke that command using system function and write the output to some file, instead if i use standard functions it will be better, but is there something which works universally? i checked time.h which has lot of functions, i would like to get suggestions if someone has already done this kind of thing.. – csavvy Oct 29 '20 at 16:01
2
  1. RFC 5280 §4.1.2.5.1 and §4.1.2.5.2 state Validity times must be in Greenwich Mean Time (Zulu).

  2. I don't know. A better way than dumping text to a file? I'm not clear what you're looking for here.

  3. Using C, you can use strptime() to convert the string into a time structure, and strftime() to convert that time structure into epoch seconds. This modified example comes from man strptime:

#define _XOPEN_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

int main(void)
{
  struct tm tm;
  char buf[255];      
  memset(&tm, 0, sizeof(struct tm));
  /* Because strptime doesn't actually handle timezone */
  setenv("TZ", "", 1);
  tzset();
  strptime("Oct 8 15:04:56 2020 GMT", "%B %d %H:%M:%S %Y %Z", &tm);
  strftime(buf, sizeof(buf), "%s", &tm);
  puts(buf);
  exit(EXIT_SUCCESS);
}

And as you can see, it prints out the epoch time for the time string you've provided:

$ ./foo
1602169496
$
9
  • When i execute your program my output is 1602149696 , the difference is 19800 which is +5.30 hrs , but date -d "Oct 8 15:04:56 2020 GMT" +%s is showing 1602169496 , why am i seeing the difference? Is it because we are in different time zones? do you also get the same output with date -d "Oct 8 15:04:56 2020 GMT" +%s – csavvy Oct 29 '20 at 17:19
  • Yes, I get the same output (1602169496) using that date command. My system is actually set to UTC, so there's no local time adjustment from GMT for my numbers. Are you in a GMT +5:30 time zone? – gowenfawr Oct 29 '20 at 18:05
  • yes i am in GMT +5.30 my date command shows Thu Oct 29 07:01:41 IST 2020 currently, but how is that date is properly converting by making use tz, but the standard functions does not, what do i have to do to make my standard functions behave same as date command ? make use of tzset()? that is exactly what i want avoid because i dont want to change anything on my device, just want converted time thats all! – csavvy Oct 29 '20 at 18:25
  • if i add setenv("TZ", "", 1); tzset(); before strptime i am getting 1602169496, but i am looking for without using tzset(); – csavvy Oct 29 '20 at 19:02
  • 1
    strftime %s is not guaranteed by standard C or POSIX, although it is in GNU and (even more widely used) Olson. – dave_thompson_085 Oct 30 '20 at 1:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.