Loading crypto/asn1/a_gentm.c +57 −0 Original line number Diff line number Diff line Loading @@ -257,3 +257,60 @@ ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, #endif return (s); } const char *_asn1_mon[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm) { char *v; int gmt = 0; int i; int y = 0, M = 0, d = 0, h = 0, m = 0, s = 0; char *f = NULL; int f_len = 0; i = tm->length; v = (char *)tm->data; if (i < 12) goto err; if (v[i - 1] == 'Z') gmt = 1; for (i = 0; i < 12; i++) if ((v[i] > '9') || (v[i] < '0')) goto err; y = (v[0] - '0') * 1000 + (v[1] - '0') * 100 + (v[2] - '0') * 10 + (v[3] - '0'); M = (v[4] - '0') * 10 + (v[5] - '0'); if ((M > 12) || (M < 1)) goto err; d = (v[6] - '0') * 10 + (v[7] - '0'); h = (v[8] - '0') * 10 + (v[9] - '0'); m = (v[10] - '0') * 10 + (v[11] - '0'); if (tm->length >= 14 && (v[12] >= '0') && (v[12] <= '9') && (v[13] >= '0') && (v[13] <= '9')) { s = (v[12] - '0') * 10 + (v[13] - '0'); /* Check for fractions of seconds. */ if (tm->length >= 15 && v[14] == '.') { int l = tm->length; f = &v[14]; /* The decimal point. */ f_len = 1; while (14 + f_len < l && f[f_len] >= '0' && f[f_len] <= '9') ++f_len; } } if (BIO_printf(bp, "%s %2d %02d:%02d:%02d%.*s %d%s", _asn1_mon[M - 1], d, h, m, s, f_len, f, y, (gmt) ? " GMT" : "") <= 0) return (0); else return (1); err: BIO_write(bp, "Bad time value", 14); return (0); } crypto/asn1/a_print.c +29 −0 Original line number Diff line number Diff line Loading @@ -126,3 +126,32 @@ int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s) s->type = ASN1_PRINTABLE_type(s->data, s->length); return (1); } int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v) { int i, n; char buf[80]; const char *p; if (v == NULL) return (0); n = 0; p = (const char *)v->data; for (i = 0; i < v->length; i++) { if ((p[i] > '~') || ((p[i] < ' ') && (p[i] != '\n') && (p[i] != '\r'))) buf[n] = '.'; else buf[n] = p[i]; n++; if (n >= 80) { if (BIO_write(bp, buf, n) <= 0) return (0); n = 0; } } if (n > 0) if (BIO_write(bp, buf, n) <= 0) return (0); return (1); } crypto/asn1/a_time.c +10 −0 Original line number Diff line number Diff line Loading @@ -198,3 +198,13 @@ int ASN1_TIME_diff(int *pday, int *psec, return 0; return OPENSSL_gmtime_diff(pday, psec, &tm_from, &tm_to); } int ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm) { if (tm->type == V_ASN1_UTCTIME) return ASN1_UTCTIME_print(bp, tm); if (tm->type == V_ASN1_GENERALIZEDTIME) return ASN1_GENERALIZEDTIME_print(bp, tm); BIO_write(bp, "Bad time value", 14); return (0); } crypto/asn1/a_utctm.c +41 −0 Original line number Diff line number Diff line Loading @@ -261,3 +261,44 @@ int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t) return -1; return 0; } int ASN1_UTCTIME_print(BIO *bp, const ASN1_UTCTIME *tm) { const char *v; int gmt = 0; int i; int y = 0, M = 0, d = 0, h = 0, m = 0, s = 0; i = tm->length; v = (const char *)tm->data; if (i < 10) goto err; if (v[i - 1] == 'Z') gmt = 1; for (i = 0; i < 10; i++) if ((v[i] > '9') || (v[i] < '0')) goto err; y = (v[0] - '0') * 10 + (v[1] - '0'); if (y < 50) y += 100; M = (v[2] - '0') * 10 + (v[3] - '0'); if ((M > 12) || (M < 1)) goto err; d = (v[4] - '0') * 10 + (v[5] - '0'); h = (v[6] - '0') * 10 + (v[7] - '0'); m = (v[8] - '0') * 10 + (v[9] - '0'); if (tm->length >= 12 && (v[10] >= '0') && (v[10] <= '9') && (v[11] >= '0') && (v[11] <= '9')) s = (v[10] - '0') * 10 + (v[11] - '0'); if (BIO_printf(bp, "%s %2d %02d:%02d:%02d %d%s", _asn1_mon[M - 1], d, h, m, s, y + 1900, (gmt) ? " GMT" : "") <= 0) return (0); else return (1); err: BIO_write(bp, "Bad time value", 14); return (0); } crypto/asn1/asn1_locl.h +3 −0 Original line number Diff line number Diff line Loading @@ -87,6 +87,9 @@ struct asn1_sctx_st { void *app_data; } /* ASN1_SCTX */ ; /* Month values for printing out times */ extern const char *_asn1_mon[12]; /* * Method to handle CRL access. In general a CRL could be very large (several * Mb) and can consume large amounts of resources if stored in memory by Loading Loading
crypto/asn1/a_gentm.c +57 −0 Original line number Diff line number Diff line Loading @@ -257,3 +257,60 @@ ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, #endif return (s); } const char *_asn1_mon[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm) { char *v; int gmt = 0; int i; int y = 0, M = 0, d = 0, h = 0, m = 0, s = 0; char *f = NULL; int f_len = 0; i = tm->length; v = (char *)tm->data; if (i < 12) goto err; if (v[i - 1] == 'Z') gmt = 1; for (i = 0; i < 12; i++) if ((v[i] > '9') || (v[i] < '0')) goto err; y = (v[0] - '0') * 1000 + (v[1] - '0') * 100 + (v[2] - '0') * 10 + (v[3] - '0'); M = (v[4] - '0') * 10 + (v[5] - '0'); if ((M > 12) || (M < 1)) goto err; d = (v[6] - '0') * 10 + (v[7] - '0'); h = (v[8] - '0') * 10 + (v[9] - '0'); m = (v[10] - '0') * 10 + (v[11] - '0'); if (tm->length >= 14 && (v[12] >= '0') && (v[12] <= '9') && (v[13] >= '0') && (v[13] <= '9')) { s = (v[12] - '0') * 10 + (v[13] - '0'); /* Check for fractions of seconds. */ if (tm->length >= 15 && v[14] == '.') { int l = tm->length; f = &v[14]; /* The decimal point. */ f_len = 1; while (14 + f_len < l && f[f_len] >= '0' && f[f_len] <= '9') ++f_len; } } if (BIO_printf(bp, "%s %2d %02d:%02d:%02d%.*s %d%s", _asn1_mon[M - 1], d, h, m, s, f_len, f, y, (gmt) ? " GMT" : "") <= 0) return (0); else return (1); err: BIO_write(bp, "Bad time value", 14); return (0); }
crypto/asn1/a_print.c +29 −0 Original line number Diff line number Diff line Loading @@ -126,3 +126,32 @@ int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s) s->type = ASN1_PRINTABLE_type(s->data, s->length); return (1); } int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v) { int i, n; char buf[80]; const char *p; if (v == NULL) return (0); n = 0; p = (const char *)v->data; for (i = 0; i < v->length; i++) { if ((p[i] > '~') || ((p[i] < ' ') && (p[i] != '\n') && (p[i] != '\r'))) buf[n] = '.'; else buf[n] = p[i]; n++; if (n >= 80) { if (BIO_write(bp, buf, n) <= 0) return (0); n = 0; } } if (n > 0) if (BIO_write(bp, buf, n) <= 0) return (0); return (1); }
crypto/asn1/a_time.c +10 −0 Original line number Diff line number Diff line Loading @@ -198,3 +198,13 @@ int ASN1_TIME_diff(int *pday, int *psec, return 0; return OPENSSL_gmtime_diff(pday, psec, &tm_from, &tm_to); } int ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm) { if (tm->type == V_ASN1_UTCTIME) return ASN1_UTCTIME_print(bp, tm); if (tm->type == V_ASN1_GENERALIZEDTIME) return ASN1_GENERALIZEDTIME_print(bp, tm); BIO_write(bp, "Bad time value", 14); return (0); }
crypto/asn1/a_utctm.c +41 −0 Original line number Diff line number Diff line Loading @@ -261,3 +261,44 @@ int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t) return -1; return 0; } int ASN1_UTCTIME_print(BIO *bp, const ASN1_UTCTIME *tm) { const char *v; int gmt = 0; int i; int y = 0, M = 0, d = 0, h = 0, m = 0, s = 0; i = tm->length; v = (const char *)tm->data; if (i < 10) goto err; if (v[i - 1] == 'Z') gmt = 1; for (i = 0; i < 10; i++) if ((v[i] > '9') || (v[i] < '0')) goto err; y = (v[0] - '0') * 10 + (v[1] - '0'); if (y < 50) y += 100; M = (v[2] - '0') * 10 + (v[3] - '0'); if ((M > 12) || (M < 1)) goto err; d = (v[4] - '0') * 10 + (v[5] - '0'); h = (v[6] - '0') * 10 + (v[7] - '0'); m = (v[8] - '0') * 10 + (v[9] - '0'); if (tm->length >= 12 && (v[10] >= '0') && (v[10] <= '9') && (v[11] >= '0') && (v[11] <= '9')) s = (v[10] - '0') * 10 + (v[11] - '0'); if (BIO_printf(bp, "%s %2d %02d:%02d:%02d %d%s", _asn1_mon[M - 1], d, h, m, s, y + 1900, (gmt) ? " GMT" : "") <= 0) return (0); else return (1); err: BIO_write(bp, "Bad time value", 14); return (0); }
crypto/asn1/asn1_locl.h +3 −0 Original line number Diff line number Diff line Loading @@ -87,6 +87,9 @@ struct asn1_sctx_st { void *app_data; } /* ASN1_SCTX */ ; /* Month values for printing out times */ extern const char *_asn1_mon[12]; /* * Method to handle CRL access. In general a CRL could be very large (several * Mb) and can consume large amounts of resources if stored in memory by Loading