1

I am converting ASN1_TIME to std::string in this way:

std::string timeString;
BIO *bmem = BIO_new(BIO_s_mem());

if (ASN1_TIME_print(bmem, asn1Time)) {
    BUF_MEM * bptr;

    BIO_get_mem_ptr(bmem, &bptr);
    timeString.assign(std::string(bptr->data, bptr->length));
}
else { // Log error
}
BIO_free_all(bmem);

Whats wrong with BUF_MEM use? I am getting very large numbers in bptr->length causing exception in std::string construction.

Nitesh
  • 2,681
  • 4
  • 27
  • 45
  • maybe this can help: http://stackoverflow.com/questions/10975542/asn1-time-to-time-t-conversion – Edd Mar 23 '17 at 10:23
  • Can you show how you populate `asn1Time`? Is `bptr->data` valid, or is it `NULL`? – jww Mar 23 '17 at 14:52
  • Found the problem - Mismatched headers caused this problem. The project used headers from 1.0.1 release but the library on OSX 10.11 is 0.9.8. (The BUF_MEM struct's members have been changed from int to size_t.) – Nitesh Mar 24 '17 at 15:36

1 Answers1

0

The code in question is fine. The problem was due to mismatched headers. Earlier headers from system were being used hence everything was fine. Since (most probably) El-Capitan, OSX no longer includes headers and discourages relying on OSX for SSL, to avoid issues due to version incompatibility.

See http://lists.apple.com/archives/macnetworkprog/2015/Jun/msg00025.html

That is exactly what was happening - Code was being linked against library on OS but the headers getting used were from different version as they were downloaded from openssl latest source.

Nitesh
  • 2,681
  • 4
  • 27
  • 45