mirror of
https://github.com/chris2511/xca.git
synced 2026-09-12 19:51:05 +05:00
uses UTC time for certificate dates >1950 and < 2049
solves Bug: [ 783830 ] GeneralizedTime-format breaks browsers
This commit is contained in:
parent
9de1a05d5d
commit
5c43538374
@ -81,6 +81,11 @@ ASN1_TIME *a1time::get() const
|
||||
return M_ASN1_TIME_dup(time);
|
||||
}
|
||||
|
||||
ASN1_TIME *a1time::get_utc() const
|
||||
{
|
||||
return toUTCtime();
|
||||
}
|
||||
|
||||
a1time &a1time::set(const ASN1_TIME *a)
|
||||
{
|
||||
if (a == NULL) {
|
||||
@ -260,10 +265,40 @@ int a1time::derSize() const
|
||||
}
|
||||
|
||||
|
||||
ASN1_UTCTIME *a1time::toUTCtime() const
|
||||
{
|
||||
ASN1_UTCTIME *ret;
|
||||
int year=0,i ;
|
||||
// if (!ASN1_TIME_check(t)) return NULL;
|
||||
for (i=0; i<4; i++){
|
||||
year *= 10;
|
||||
year += time->data[i] - '0';
|
||||
}
|
||||
if (year > 2049 || year <1950)
|
||||
return NULL;
|
||||
|
||||
if (!(ret = ASN1_UTCTIME_new ()))
|
||||
return NULL;
|
||||
|
||||
/* If already UTC Time just copy across */
|
||||
if (time->type == V_ASN1_UTCTIME)
|
||||
{
|
||||
if(!ASN1_STRING_set(ret, time->data, time->length))
|
||||
return NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* copy w/o 19 or 20 */
|
||||
if (!ASN1_STRING_set(ret, time->data+2, time->length - 2))
|
||||
return NULL;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* this was happily copied from OpenSSL 0.9.7
|
||||
* and is used if linking against 0.9.6
|
||||
*/
|
||||
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER < 0x00907000L
|
||||
/* Convert an ASN1_TIME structure to GeneralizedTime */
|
||||
ASN1_GENERALIZEDTIME *a1time::ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out)
|
||||
|
||||
@ -57,10 +57,11 @@
|
||||
class a1time
|
||||
{
|
||||
private:
|
||||
ASN1_GENERALIZEDTIME *time;
|
||||
ASN1_TIME *time;
|
||||
#if OPENSSL_VERSION_NUMBER < 0x00907000L
|
||||
ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out);
|
||||
#endif
|
||||
ASN1_UTCTIME *toUTCtime() const;
|
||||
public:
|
||||
a1time();
|
||||
a1time(const ASN1_TIME *a);
|
||||
@ -76,6 +77,7 @@ class a1time
|
||||
int ymdg(int *y, int *m, int *d, int *g) const;
|
||||
int a1time::ymdg(int *y, int *m, int *d, int *h, int *M, int *s, int *g) const;
|
||||
ASN1_TIME *get() const;
|
||||
ASN1_TIME *get_utc() const;
|
||||
a1time &now(int delta = 0);
|
||||
unsigned char *i2d(unsigned char *p);
|
||||
unsigned char *d2i(unsigned char *p, int size);
|
||||
|
||||
@ -154,7 +154,9 @@ void pki_x509::setNotBefore(const a1time &a1)
|
||||
if (X509_get_notBefore(cert) != NULL ) {
|
||||
ASN1_TIME_free(X509_get_notBefore(cert));
|
||||
}
|
||||
X509_get_notBefore(cert) = a1.get();
|
||||
X509_get_notBefore(cert) = a1.get_utc();
|
||||
if (X509_get_notBefore(cert) == NULL)
|
||||
X509_get_notBefore(cert) = a1.get();
|
||||
openssl_error();
|
||||
}
|
||||
|
||||
@ -163,7 +165,9 @@ void pki_x509::setNotAfter(const a1time &a1)
|
||||
if (X509_get_notAfter(cert) != NULL ) {
|
||||
ASN1_TIME_free(X509_get_notAfter(cert));
|
||||
}
|
||||
X509_get_notAfter(cert) = a1.get();
|
||||
X509_get_notAfter(cert) = a1.get_utc();
|
||||
if (X509_get_notAfter(cert) == NULL)
|
||||
X509_get_notAfter(cert) = a1.get();
|
||||
openssl_error();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user