Browse Source

Parse GENERALIZEDTIME ASN structures

This fixes certificate dates beyond year 2049.
pull/1/head
Timothy Pearson 2 years ago
parent
commit
07dbb3b5c9
1 changed files with 21 additions and 12 deletions
  1. 21
    12
      tdeio/kssl/ksslutils.cc

+ 21
- 12
tdeio/kssl/ksslutils.cc View File

@@ -35,6 +35,9 @@ TQDateTime ASN1_UTCTIME_QDateTime(ASN1_UTCTIME *tm, int *isGmt) {
35 35
 TQDateTime qdt;
36 36
 char *v;
37 37
 int gmt=0;
38
+int gentime=0;
39
+int yoffset=0;
40
+int yearbase=1900;
38 41
 int i;
39 42
 int y=0,M=0,d=0,h=0,m=0,s=0;
40 43
 TQDate qdate;
@@ -42,24 +45,30 @@ TQTime qtime;
42 45
  
43 46
   i = tm->length;
44 47
   v = (char *)tm->data;
45
- 
48
+  if ((i == 15) || (i == 21)) {
49
+          gentime=1;
50
+          yoffset=2;
51
+          yearbase=0;
52
+  }
46 53
   if (i < 10) goto auq_err;
47 54
   if (v[i-1] == 'Z') gmt=1;
48
-  for (i=0; i<10; i++)
55
+  for (i=0; i<10+yoffset; i++)
49 56
           if ((v[i] > '9') || (v[i] < '0')) goto auq_err;
50
-  y = (v[0]-'0')*10+(v[1]-'0');
57
+  y = (v[0+yoffset]-'0')*10+(v[1+yoffset]-'0');
58
+  if (gentime)
59
+          y += (v[0]-'0')*1000+(v[1]-'0')*100;
51 60
   if (y < 50) y+=100;
52
-  M = (v[2]-'0')*10+(v[3]-'0');
61
+  M = (v[2+yoffset]-'0')*10+(v[3+yoffset]-'0');
53 62
   if ((M > 12) || (M < 1)) goto auq_err;
54
-  d = (v[4]-'0')*10+(v[5]-'0');
55
-  h = (v[6]-'0')*10+(v[7]-'0');
56
-  m =  (v[8]-'0')*10+(v[9]-'0');
57
-  if (    (v[10] >= '0') && (v[10] <= '9') &&
58
-          (v[11] >= '0') && (v[11] <= '9'))
59
-          s = (v[10]-'0')*10+(v[11]-'0');
60
- 
63
+  d = (v[4+yoffset]-'0')*10+(v[5+yoffset]-'0');
64
+  h = (v[6+yoffset]-'0')*10+(v[7+yoffset]-'0');
65
+  m =  (v[8+yoffset]-'0')*10+(v[9+yoffset]-'0');
66
+  if (    (v[10+yoffset] >= '0') && (v[10+yoffset] <= '9') &&
67
+          (v[11+yoffset] >= '0') && (v[11+yoffset] <= '9'))
68
+          s = (v[10+yoffset]-'0')*10+(v[11+yoffset]-'0');
69
+
61 70
   // localize the date and display it.
62
-  qdate.setYMD(y+1900, M, d);
71
+  qdate.setYMD(y+yearbase, M, d);
63 72
   qtime.setHMS(h,m,s);
64 73
   qdt.setDate(qdate); qdt.setTime(qtime);
65 74
   auq_err:

Loading…
Cancel
Save