|
Lines 36-41
Link Here
|
| 36 |
#include "log.h" |
36 |
#include "log.h" |
| 37 |
#include "digest.h" |
37 |
#include "digest.h" |
| 38 |
#include "bitmap.h" |
38 |
#include "bitmap.h" |
|
|
39 |
#include "utf8.h" |
| 39 |
|
40 |
|
| 40 |
#include "krl.h" |
41 |
#include "krl.h" |
| 41 |
|
42 |
|
|
Lines 1353-1355
ssh_krl_file_contains_key(const char *path, const struct sshkey *key)
Link Here
|
| 1353 |
errno = oerrno; |
1354 |
errno = oerrno; |
| 1354 |
return r; |
1355 |
return r; |
| 1355 |
} |
1356 |
} |
|
|
1357 |
|
| 1358 |
int |
| 1359 |
krl_dump(struct ssh_krl *krl, FILE *f) |
| 1360 |
{ |
| 1361 |
struct sshkey *key = NULL; |
| 1362 |
struct revoked_blob *rb; |
| 1363 |
struct revoked_certs *rc; |
| 1364 |
struct revoked_serial *rs; |
| 1365 |
struct revoked_key_id *rki; |
| 1366 |
int r, ret = 0; |
| 1367 |
char *fp, timestamp[64]; |
| 1368 |
|
| 1369 |
/* Try to print in a KRL spec-compatible format */ |
| 1370 |
format_timestamp(krl->generated_date, timestamp, sizeof(timestamp)); |
| 1371 |
fprintf(f, "# KRL version %lld\n", krl->krl_version); |
| 1372 |
fprintf(f, "# Generated at %s\n", timestamp); |
| 1373 |
if (krl->comment != NULL && *krl->comment != '\0') { |
| 1374 |
r = INT_MAX; |
| 1375 |
asmprintf(&fp, INT_MAX, &r, "%s", krl->comment); |
| 1376 |
fprintf(f, "# Comment: %s\n", fp); |
| 1377 |
free(fp); |
| 1378 |
} |
| 1379 |
fputc('\n', f); |
| 1380 |
|
| 1381 |
RB_FOREACH(rb, revoked_blob_tree, &krl->revoked_keys) { |
| 1382 |
if ((r = sshkey_from_blob(rb->blob, rb->len, &key)) != 0) { |
| 1383 |
ret = SSH_ERR_INVALID_FORMAT; |
| 1384 |
error("Parse key in KRL: %s", ssh_err(r)); |
| 1385 |
continue; |
| 1386 |
} |
| 1387 |
if ((fp = sshkey_fingerprint(key, SSH_FP_HASH_DEFAULT, |
| 1388 |
SSH_FP_DEFAULT)) == NULL) { |
| 1389 |
ret = SSH_ERR_INVALID_FORMAT; |
| 1390 |
error("sshkey_fingerprint failed"); |
| 1391 |
continue; |
| 1392 |
} |
| 1393 |
fprintf(f, "hash: SHA256:%s # %s\n", fp, sshkey_ssh_name(key)); |
| 1394 |
free(fp); |
| 1395 |
free(key); |
| 1396 |
} |
| 1397 |
RB_FOREACH(rb, revoked_blob_tree, &krl->revoked_sha256s) { |
| 1398 |
fp = tohex(rb->blob, rb->len); |
| 1399 |
fprintf(f, "hash: SHA256:%s\n", fp); |
| 1400 |
free(fp); |
| 1401 |
} |
| 1402 |
RB_FOREACH(rb, revoked_blob_tree, &krl->revoked_sha1s) { |
| 1403 |
/* |
| 1404 |
* There is not KRL spec keyword for raw SHA1 hashes, so |
| 1405 |
* print them as comments. |
| 1406 |
*/ |
| 1407 |
fp = tohex(rb->blob, rb->len); |
| 1408 |
fprintf(f, "# hash SHA1:%s\n", fp); |
| 1409 |
free(fp); |
| 1410 |
} |
| 1411 |
|
| 1412 |
TAILQ_FOREACH(rc, &krl->revoked_certs, entry) { |
| 1413 |
fputc('\n', f); |
| 1414 |
if (rc->ca_key == NULL) |
| 1415 |
fprintf(f, "# Wildcard CA\n"); |
| 1416 |
else { |
| 1417 |
if ((fp = sshkey_fingerprint(rc->ca_key, |
| 1418 |
SSH_FP_HASH_DEFAULT, SSH_FP_DEFAULT)) == NULL) { |
| 1419 |
ret = SSH_ERR_INVALID_FORMAT; |
| 1420 |
error("sshkey_fingerprint failed"); |
| 1421 |
continue; |
| 1422 |
} |
| 1423 |
fprintf(f, "# CA key %s %s\n", |
| 1424 |
sshkey_ssh_name(rc->ca_key), fp); |
| 1425 |
free(fp); |
| 1426 |
} |
| 1427 |
RB_FOREACH(rs, revoked_serial_tree, &rc->revoked_serials) { |
| 1428 |
if (rs->lo == rs->hi) |
| 1429 |
fprintf(f, "serial: %lld\n", rs->lo); |
| 1430 |
else { |
| 1431 |
fprintf(f, "serial: %lld-%lld\n", |
| 1432 |
rs->lo, rs->hi); |
| 1433 |
} |
| 1434 |
} |
| 1435 |
RB_FOREACH(rki, revoked_key_id_tree, &rc->revoked_key_ids) { |
| 1436 |
/* |
| 1437 |
* We don't want key IDs with embedded newlines to |
| 1438 |
* mess up the display. |
| 1439 |
*/ |
| 1440 |
r = INT_MAX; |
| 1441 |
asmprintf(&fp, INT_MAX, &r, "%s", rki->key_id); |
| 1442 |
fprintf(f, "id: %s\n", fp); |
| 1443 |
free(fp); |
| 1444 |
} |
| 1445 |
} |
| 1446 |
return ret; |
| 1447 |
} |