add function wolfSSL_ASN1_TIME_to_string

This commit is contained in:
Jacob Barthelmeh
2016-04-28 09:41:49 -06:00
parent f19541ffe5
commit f88d82375e
5 changed files with 114 additions and 20 deletions

View File

@@ -10735,7 +10735,13 @@ WOLFSSL_X509* wolfSSL_X509_load_certificate_file(const char* fname, int format)
#ifdef OPENSSL_EXTRA /* needed for wolfSSL_X509_d21 function */
WOLFSSL_X509* wolfSSL_get_certificate(WOLFSSL* ssl)
{
DerBuffer* cert = ssl->buffers.certificate;
DerBuffer* cert;
if (ssl == NULL) {
return NULL;
}
cert = ssl->buffers.certificate;
return wolfSSL_X509_d2i(NULL, cert->buffer, cert->length);
}
#endif /* OPENSSL_EXTRA */
@@ -11759,6 +11765,67 @@ int wolfSSL_ASN1_TIME_print(WOLFSSL_BIO* bio, const WOLFSSL_ASN1_TIME* asnTime)
}
#if defined(WOLFSSL_MYSQL_COMPATIBLE)
char* wolfSSL_ASN1_TIME_to_string(WOLFSSL_ASN1_TIME* time, char* buf, int len)
{
struct tm t;
int idx = 0;
int format;
int dateLen;
byte* date = (byte*)time;
WOLFSSL_ENTER("wolfSSL_ASN1_TIME_to_string");
if (time == NULL || buf == NULL || len < 5) {
WOLFSSL_MSG("Bad argument");
return NULL;
}
format = *date; date++;
dateLen = *date; date++;
if (dateLen > len) {
return "error";
}
if (!ExtractDate(date, format, &t, &idx)) {
return "error";
}
if (date[idx] != 'Z') {
WOLFSSL_MSG("UTCtime, not Zulu") ;
return "Not Zulu";
}
/* place month in buffer */
buf[0] = '\0';
switch(t.tm_mon) {
case 0: XSTRNCAT(buf, "Jan ", 4); break;
case 1: XSTRNCAT(buf, "Feb ", 4); break;
case 2: XSTRNCAT(buf, "Mar ", 4); break;
case 3: XSTRNCAT(buf, "Apr ", 4); break;
case 4: XSTRNCAT(buf, "May ", 4); break;
case 5: XSTRNCAT(buf, "Jun ", 4); break;
case 6: XSTRNCAT(buf, "Jul ", 4); break;
case 7: XSTRNCAT(buf, "Aug ", 4); break;
case 8: XSTRNCAT(buf, "Sep ", 4); break;
case 9: XSTRNCAT(buf, "Oct ", 4); break;
case 10: XSTRNCAT(buf, "Nov ", 4); break;
case 11: XSTRNCAT(buf, "Dec ", 4); break;
default:
return "error";
}
idx = 4; /* use idx now for char buffer */
buf[idx] = ' ';
XSNPRINTF(buf + idx, len - idx, "%2d %02d:%02d:%02d %d GMT",
t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec, t.tm_year + 1900);
return buf;
}
#endif /* WOLFSSL_MYSQL_COMPATIBLE */
int wolfSSL_ASN1_INTEGER_cmp(const WOLFSSL_ASN1_INTEGER* a,
const WOLFSSL_ASN1_INTEGER* b)
{