diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/a_time.c')
-rw-r--r-- | src/lib/libcrypto/asn1/a_time.c | 79 |
1 files changed, 55 insertions, 24 deletions
diff --git a/src/lib/libcrypto/asn1/a_time.c b/src/lib/libcrypto/asn1/a_time.c index 8c0ddee4ac..27ddd30899 100644 --- a/src/lib/libcrypto/asn1/a_time.c +++ b/src/lib/libcrypto/asn1/a_time.c | |||
@@ -64,14 +64,14 @@ | |||
64 | #include <stdio.h> | 64 | #include <stdio.h> |
65 | #include <time.h> | 65 | #include <time.h> |
66 | #include "cryptlib.h" | 66 | #include "cryptlib.h" |
67 | #include <openssl/asn1.h> | 67 | #include "o_time.h" |
68 | #include <openssl/asn1t.h> | ||
68 | 69 | ||
69 | ASN1_TIME *ASN1_TIME_new(void) | 70 | IMPLEMENT_ASN1_MSTRING(ASN1_TIME, B_ASN1_TIME) |
70 | { return M_ASN1_TIME_new(); } | ||
71 | 71 | ||
72 | void ASN1_TIME_free(ASN1_TIME *x) | 72 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_TIME) |
73 | { M_ASN1_TIME_free(x); } | ||
74 | 73 | ||
74 | #if 0 | ||
75 | int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp) | 75 | int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp) |
76 | { | 76 | { |
77 | #ifdef CHARSET_EBCDIC | 77 | #ifdef CHARSET_EBCDIC |
@@ -95,33 +95,64 @@ int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp) | |||
95 | ASN1err(ASN1_F_I2D_ASN1_TIME,ASN1_R_EXPECTING_A_TIME); | 95 | ASN1err(ASN1_F_I2D_ASN1_TIME,ASN1_R_EXPECTING_A_TIME); |
96 | return -1; | 96 | return -1; |
97 | } | 97 | } |
98 | 98 | #endif | |
99 | |||
100 | ASN1_TIME *d2i_ASN1_TIME(ASN1_TIME **a, unsigned char **pp, long length) | ||
101 | { | ||
102 | unsigned char tag; | ||
103 | tag = **pp & ~V_ASN1_CONSTRUCTED; | ||
104 | if(tag == (V_ASN1_UTCTIME|V_ASN1_UNIVERSAL)) | ||
105 | return d2i_ASN1_UTCTIME(a, pp, length); | ||
106 | if(tag == (V_ASN1_GENERALIZEDTIME|V_ASN1_UNIVERSAL)) | ||
107 | return d2i_ASN1_GENERALIZEDTIME(a, pp, length); | ||
108 | ASN1err(ASN1_F_D2I_ASN1_TIME,ASN1_R_EXPECTING_A_TIME); | ||
109 | return(NULL); | ||
110 | } | ||
111 | 99 | ||
112 | 100 | ||
113 | ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t) | 101 | ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t) |
114 | { | 102 | { |
115 | struct tm *ts; | 103 | struct tm *ts; |
116 | #if defined(THREADS) && !defined(WIN32) && !defined(__CYGWIN32__) | ||
117 | struct tm data; | 104 | struct tm data; |
118 | 105 | ||
119 | gmtime_r(&t,&data); | 106 | ts=OPENSSL_gmtime(&t,&data); |
120 | ts=&data; /* should return &data, but doesn't on some systems, so we don't even look at the return value */ | 107 | if (ts == NULL) |
121 | #else | 108 | return NULL; |
122 | ts=gmtime(&t); | ||
123 | #endif | ||
124 | if((ts->tm_year >= 50) && (ts->tm_year < 150)) | 109 | if((ts->tm_year >= 50) && (ts->tm_year < 150)) |
125 | return ASN1_UTCTIME_set(s, t); | 110 | return ASN1_UTCTIME_set(s, t); |
126 | return ASN1_GENERALIZEDTIME_set(s,t); | 111 | return ASN1_GENERALIZEDTIME_set(s,t); |
127 | } | 112 | } |
113 | |||
114 | int ASN1_TIME_check(ASN1_TIME *t) | ||
115 | { | ||
116 | if (t->type == V_ASN1_GENERALIZEDTIME) | ||
117 | return ASN1_GENERALIZEDTIME_check(t); | ||
118 | else if (t->type == V_ASN1_UTCTIME) | ||
119 | return ASN1_UTCTIME_check(t); | ||
120 | return 0; | ||
121 | } | ||
122 | |||
123 | /* Convert an ASN1_TIME structure to GeneralizedTime */ | ||
124 | ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out) | ||
125 | { | ||
126 | ASN1_GENERALIZEDTIME *ret; | ||
127 | char *str; | ||
128 | |||
129 | if (!ASN1_TIME_check(t)) return NULL; | ||
130 | |||
131 | if (!out || !*out) | ||
132 | { | ||
133 | if (!(ret = ASN1_GENERALIZEDTIME_new ())) | ||
134 | return NULL; | ||
135 | if (out) *out = ret; | ||
136 | } | ||
137 | else ret = *out; | ||
138 | |||
139 | /* If already GeneralizedTime just copy across */ | ||
140 | if (t->type == V_ASN1_GENERALIZEDTIME) | ||
141 | { | ||
142 | if(!ASN1_STRING_set(ret, t->data, t->length)) | ||
143 | return NULL; | ||
144 | return ret; | ||
145 | } | ||
146 | |||
147 | /* grow the string */ | ||
148 | if (!ASN1_STRING_set(ret, NULL, t->length + 2)) | ||
149 | return NULL; | ||
150 | str = (char *)ret->data; | ||
151 | /* Work out the century and prepend */ | ||
152 | if (t->data[0] >= '5') strcpy(str, "19"); | ||
153 | else strcpy(str, "20"); | ||
154 | |||
155 | strcat(str, (char *)t->data); | ||
156 | |||
157 | return ret; | ||
158 | } | ||