gnutls_x509_crt_get_expiration_time problem on window

Simon Josefsson simon at josefsson.org
Sun Apr 19 21:38:18 CEST 2009


"Code Join" <info at codejoin.com> writes:

> Hi all,
> first of all: many thanks, gnutls is a precious work. .
> I'm using the 2.7.3 library with Microsoft Visual C++ 2008 Express. I have build on my own a server application and a client application using some code snippets from the examples programs included in the installation pack. Everything is fine but I am not able to print the activation/expiration time of my client certificate (I have created it using the certtol utility).
>
> If I run certtool to view the client certificate information I can see them.
>
> Here is my code:
> ...
>   expiration_time = gnutls_x509_crt_get_expiration_time(cert);
>   activation_time = gnutls_x509_crt_get_activation_time(cert);
> ...
>
>   Form1.display.Append("\tCertificate is valid since: "+xstring( ctime(&activation_time))+"\n");
>   Form1.display.Append("\tCertificate expires: "+xstring( ctime(&expiration_time))+"\n");
> ...
>
> It seems like those functions return strange values rather good or bad (-1 ) values

Strange that certtool works.  Here is the code that certtool uses:

    time_t tim;

    tim = gnutls_x509_crt_get_activation_time (cert);
    {
      char s[42];
      size_t max = sizeof (s);
      struct tm t;

      if (gmtime_r (&tim, &t) == NULL)
	addf (str, "error: gmtime_r (%ld)\n", (unsigned long) tim);
      else if (strftime (s, max, "%a %b %d %H:%M:%S UTC %Y", &t) == 0)
	addf (str, "error: strftime (%ld)\n", (unsigned long) tim);
      else
	addf (str, _("\t\tNot Before: %s\n"), s);
    }

Are you sure this doesn't work in your application?

Hm.  Maybe there is a 64-bit issue.  What values does it return for you?
Can you print just the integer returned by the functions, like this:

    printf ("foo: %ld\n", (long) gnutls_x509_crt_get_activation_time (cert));

/Simon





More information about the Gnutls-devel mailing list