| 1148 | static inline int aktcerttime() { return time(NULL) / (time_t) 60; } // use minutes instead of seconds as timebase, so int will be more than enough |
| 1149 | |
| 1150 | bool cert::parse() // parse orgmsg[] and check the signature |
| 1151 | { |
| 1152 | isvalid = ischecked = needsrenewal = expired = false; |
| 1153 | pubkey = signedby = NULL; name = NULL; |
| 1154 | type = CERT_MISC; |
| 1155 | DELETEA(workmsg); |
| 1156 | lines.setsize(0); |
| 1157 | if(orglen > certheaderlenfull && orglen < (1<<20) && !strncmp(orgmsg, certheader, certheaderlen) && orgmsg[certheaderlen + 128] == '\n') |
| 1158 | { // frame ok |
| 1159 | workmsg = new char[orglen + 1]; |
| 1160 | memcpy(workmsg, orgmsg, orglen + 1); |
| 1161 | uchar *signature = (uchar*) orgmsg + certheaderlenfull - 64; |
| 1162 | if(hex2bin(signature, workmsg + certheaderlen, 64) == 64) |
| 1163 | { // parse all lines |
| 1164 | certline line; |
| 1165 | for(char *b, *l = strtok_r(workmsg + certheaderlenfull, "\n\r", &b); l; l = strtok_r(NULL, "\n\r", &b)) |
| 1166 | { |
| 1167 | // get comment |
| 1168 | line.comment = strstr(l, "//"); |
| 1169 | if(line.comment) |
| 1170 | { |
| 1171 | *line.comment = '\0'; |
| 1172 | line.comment += 2 + strspn(line.comment + 2, " "); |
| 1173 | trimtrailingwhitespace(line.comment); |
| 1174 | } |
| 1175 | trimtrailingwhitespace(l); |
| 1176 | |
| 1177 | // get keyword and value, separated by ":" |
| 1178 | l += strspn(l, " \t"); |
| 1179 | line.val = strchr(l, ':'); |
| 1180 | if(line.val && line.val > l) |
| 1181 | { |
| 1182 | line.key = l; |
| 1183 | *line.val++ = '\0'; |
| 1184 | line.val += strspn(line.val, " \t"); |
| 1185 | trimtrailingwhitespace(line.key); |
| 1186 | trimtrailingwhitespace(line.val); |
| 1187 | if(!strcasecmp(line.key, "signed-by")) |
| 1188 | { // parse "signed-by" key directly |
| 1189 | if(!(strlen(line.val) == 64 && (signedby = (uchar*)line.val) && hex2bin(signedby, orgmsg + (line.val - workmsg), 32) == 32)) signedby = NULL; |
| 1190 | } |
| 1191 | else if(!strcasecmp(line.key, "signed-date")) |
| 1192 | { // parse "signed-date" key directly |
| 1193 | signeddate = atoi(line.val); |
| 1194 | } |
| 1195 | else if(!strcasecmp(line.key, "pubkey")) |
| 1196 | { // parse "pubkey" key directly |
| 1197 | if(!(strlen(line.val) == 64 && (pubkey = (uchar*)line.val) && hex2bin(pubkey, orgmsg + (line.val - workmsg), 32) == 32)) pubkey = NULL; |
| 1198 | } |
| 1199 | else if(!strcasecmp(line.key, "name")) |
| 1200 | { // parse "name" key directly |
| 1201 | name = line.val; |
| 1202 | } |
| 1203 | else |
| 1204 | { // add to list |
| 1205 | lines.add(line); |
| 1206 | if(!strcasecmp(line.key, "type")) type = getlistindex(line.val, certtypekeywords, false, 0); |
| 1207 | } |
nothing calls this directly
no test coverage detected