diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/a_time.c')
-rw-r--r-- | src/lib/libcrypto/asn1/a_time.c | 63 |
1 files changed, 35 insertions, 28 deletions
diff --git a/src/lib/libcrypto/asn1/a_time.c b/src/lib/libcrypto/asn1/a_time.c index 1978e8d3dc..29d56b827a 100644 --- a/src/lib/libcrypto/asn1/a_time.c +++ b/src/lib/libcrypto/asn1/a_time.c | |||
@@ -7,7 +7,7 @@ | |||
7 | * are met: | 7 | * are met: |
8 | * | 8 | * |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * | 11 | * |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in | 13 | * notice, this list of conditions and the following disclaimer in |
@@ -72,43 +72,45 @@ IMPLEMENT_ASN1_MSTRING(ASN1_TIME, B_ASN1_TIME) | |||
72 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_TIME) | 72 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_TIME) |
73 | 73 | ||
74 | #if 0 | 74 | #if 0 |
75 | int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp) | 75 | int |
76 | i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp) | ||
76 | { | 77 | { |
77 | if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME) | 78 | if (a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME) |
78 | return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, | 79 | return(i2d_ASN1_bytes((ASN1_STRING *)a, pp, |
79 | a->type ,V_ASN1_UNIVERSAL)); | 80 | a->type, V_ASN1_UNIVERSAL)); |
80 | ASN1err(ASN1_F_I2D_ASN1_TIME,ASN1_R_EXPECTING_A_TIME); | 81 | ASN1err(ASN1_F_I2D_ASN1_TIME, ASN1_R_EXPECTING_A_TIME); |
81 | return -1; | 82 | return -1; |
82 | } | 83 | } |
83 | #endif | 84 | #endif |
84 | 85 | ||
85 | 86 | ASN1_TIME * | |
86 | ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t) | 87 | ASN1_TIME_set(ASN1_TIME *s, time_t t) |
87 | { | 88 | { |
88 | return ASN1_TIME_adj(s, t, 0, 0); | 89 | return ASN1_TIME_adj(s, t, 0, 0); |
89 | } | 90 | } |
90 | 91 | ||
91 | ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t, | 92 | ASN1_TIME * |
92 | int offset_day, long offset_sec) | 93 | ASN1_TIME_adj(ASN1_TIME *s, time_t t, int offset_day, long offset_sec) |
93 | { | 94 | { |
94 | struct tm *ts; | 95 | struct tm *ts; |
95 | struct tm data; | 96 | struct tm data; |
96 | 97 | ||
97 | ts=gmtime_r(&t,&data); | 98 | ts = gmtime_r(&t, &data); |
98 | if (ts == NULL) { | 99 | if (ts == NULL) { |
99 | ASN1err(ASN1_F_ASN1_TIME_ADJ, ASN1_R_ERROR_GETTING_TIME); | 100 | ASN1err(ASN1_F_ASN1_TIME_ADJ, ASN1_R_ERROR_GETTING_TIME); |
100 | return NULL; | 101 | return NULL; |
101 | } | 102 | } |
102 | if (offset_day || offset_sec) { | 103 | if (offset_day || offset_sec) { |
103 | if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) | 104 | if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) |
104 | return NULL; | 105 | return NULL; |
105 | } | 106 | } |
106 | if((ts->tm_year >= 50) && (ts->tm_year < 150)) | 107 | if ((ts->tm_year >= 50) && (ts->tm_year < 150)) |
107 | return ASN1_UTCTIME_adj(s, t, offset_day, offset_sec); | 108 | return ASN1_UTCTIME_adj(s, t, offset_day, offset_sec); |
108 | return ASN1_GENERALIZEDTIME_adj(s, t, offset_day, offset_sec); | 109 | return ASN1_GENERALIZEDTIME_adj(s, t, offset_day, offset_sec); |
109 | } | 110 | } |
110 | 111 | ||
111 | int ASN1_TIME_check(ASN1_TIME *t) | 112 | int |
113 | ASN1_TIME_check(ASN1_TIME *t) | ||
112 | { | 114 | { |
113 | if (t->type == V_ASN1_GENERALIZEDTIME) | 115 | if (t->type == V_ASN1_GENERALIZEDTIME) |
114 | return ASN1_GENERALIZEDTIME_check(t); | 116 | return ASN1_GENERALIZEDTIME_check(t); |
@@ -118,24 +120,27 @@ int ASN1_TIME_check(ASN1_TIME *t) | |||
118 | } | 120 | } |
119 | 121 | ||
120 | /* Convert an ASN1_TIME structure to GeneralizedTime */ | 122 | /* Convert an ASN1_TIME structure to GeneralizedTime */ |
121 | ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out) | 123 | ASN1_GENERALIZEDTIME * |
124 | ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out) | ||
122 | { | 125 | { |
123 | ASN1_GENERALIZEDTIME *ret; | 126 | ASN1_GENERALIZEDTIME *ret; |
124 | char *str; | 127 | char *str; |
125 | int newlen; | 128 | int newlen; |
126 | 129 | ||
127 | if (!ASN1_TIME_check(t)) return NULL; | 130 | if (!ASN1_TIME_check(t)) |
131 | return NULL; | ||
128 | 132 | ||
129 | if (!out || !*out) { | 133 | if (!out || !*out) { |
130 | if (!(ret = ASN1_GENERALIZEDTIME_new ())) | 134 | if (!(ret = ASN1_GENERALIZEDTIME_new ())) |
131 | return NULL; | 135 | return NULL; |
132 | if (out) *out = ret; | 136 | if (out) |
133 | } | 137 | *out = ret; |
134 | else ret = *out; | 138 | } else |
139 | ret = *out; | ||
135 | 140 | ||
136 | /* If already GeneralizedTime just copy across */ | 141 | /* If already GeneralizedTime just copy across */ |
137 | if (t->type == V_ASN1_GENERALIZEDTIME) { | 142 | if (t->type == V_ASN1_GENERALIZEDTIME) { |
138 | if(!ASN1_STRING_set(ret, t->data, t->length)) | 143 | if (!ASN1_STRING_set(ret, t->data, t->length)) |
139 | return NULL; | 144 | return NULL; |
140 | return ret; | 145 | return ret; |
141 | } | 146 | } |
@@ -147,22 +152,24 @@ ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZE | |||
147 | newlen = t->length + 2 + 1; | 152 | newlen = t->length + 2 + 1; |
148 | str = (char *)ret->data; | 153 | str = (char *)ret->data; |
149 | /* Work out the century and prepend */ | 154 | /* Work out the century and prepend */ |
150 | if (t->data[0] >= '5') strlcpy(str, "19", newlen); | 155 | if (t->data[0] >= '5') |
151 | else strlcpy(str, "20", newlen); | 156 | strlcpy(str, "19", newlen); |
152 | 157 | else | |
158 | strlcpy(str, "20", newlen); | ||
153 | strlcat(str, (char *)t->data, newlen); | 159 | strlcat(str, (char *)t->data, newlen); |
154 | 160 | ||
155 | return ret; | 161 | return ret; |
156 | } | 162 | } |
157 | 163 | ||
158 | int ASN1_TIME_set_string(ASN1_TIME *s, const char *str) | 164 | int |
165 | ASN1_TIME_set_string(ASN1_TIME *s, const char *str) | ||
159 | { | 166 | { |
160 | ASN1_TIME t; | 167 | ASN1_TIME t; |
161 | 168 | ||
162 | t.length = strlen(str); | 169 | t.length = strlen(str); |
163 | t.data = (unsigned char *)str; | 170 | t.data = (unsigned char *)str; |
164 | t.flags = 0; | 171 | t.flags = 0; |
165 | 172 | ||
166 | t.type = V_ASN1_UTCTIME; | 173 | t.type = V_ASN1_UTCTIME; |
167 | 174 | ||
168 | if (!ASN1_TIME_check(&t)) { | 175 | if (!ASN1_TIME_check(&t)) { |
@@ -170,9 +177,9 @@ int ASN1_TIME_set_string(ASN1_TIME *s, const char *str) | |||
170 | if (!ASN1_TIME_check(&t)) | 177 | if (!ASN1_TIME_check(&t)) |
171 | return 0; | 178 | return 0; |
172 | } | 179 | } |
173 | 180 | ||
174 | if (s && !ASN1_STRING_copy((ASN1_STRING *)s, (ASN1_STRING *)&t)) | 181 | if (s && !ASN1_STRING_copy((ASN1_STRING *)s, (ASN1_STRING *)&t)) |
175 | return 0; | 182 | return 0; |
176 | 183 | ||
177 | return 1; | 184 | return 1; |
178 | } | 185 | } |