]>
git.ipfire.org Git - thirdparty/strongswan.git/blob - scripts/key2keyid.c
2 * Copyright (C) 2008-2009 Martin Willi
3 * Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 #include <utils/debug.h>
19 #include <credentials/keys/private_key.h>
20 #include <credentials/keys/public_key.h>
23 * print the keyids of a private or public key
25 int main(int argc
, char *argv
[])
28 private_key_t
*private;
33 library_init(NULL
, "key2keyid");
34 lib
->plugins
->load(lib
->plugins
, PLUGINS
);
35 atexit(library_deinit
);
37 read
= fread(buf
, 1, sizeof(buf
), stdin
);
40 fprintf(stderr
, "reading key failed.\n");
44 chunk
= chunk_create(buf
, read
);
46 private = lib
->creds
->create(lib
->creds
, CRED_PRIVATE_KEY
, KEY_RSA
,
47 BUILD_BLOB_PEM
, chunk_clone(chunk
),
51 printf("parsed %d bits %N private key.\n",
52 private->get_keysize(private),
53 key_type_names
, private->get_type(private));
54 if (private->get_fingerprint(private, KEYID_PUBKEY_INFO_SHA1
, &chunk
))
56 printf("subjectPublicKeyInfo keyid: %#B\n", &chunk
);
58 if (private->get_fingerprint(private, KEYID_PUBKEY_SHA1
, &chunk
))
60 printf("subjectPublicKey keyid: %#B\n", &chunk
);
62 if (private->get_fingerprint(private, KEYID_PGPV3
, &chunk
))
64 printf("PGP version 3 keyid: %#B\n", &chunk
);
66 private->destroy(private);
70 public = lib
->creds
->create(lib
->creds
, CRED_PUBLIC_KEY
, KEY_ANY
,
71 BUILD_BLOB_PEM
, chunk_clone(chunk
),
75 public = lib
->creds
->create(lib
->creds
, CRED_PUBLIC_KEY
, KEY_RSA
,
76 BUILD_BLOB_PEM
, chunk_clone(chunk
),
81 printf("parsed %d bits %N public key.\n",
82 public->get_keysize(public),
83 key_type_names
, public->get_type(public));
84 if (public->get_fingerprint(public, KEYID_PUBKEY_INFO_SHA1
, &chunk
))
86 printf("subjectPublicKeyInfo keyid: %#B\n", &chunk
);
88 if (public->get_fingerprint(public, KEYID_PUBKEY_SHA1
, &chunk
))
90 printf("subjectPublicKey keyid: %#B\n", &chunk
);
92 if (public->get_fingerprint(public, KEYID_PGPV3
, &chunk
))
94 printf("PGP version 3 keyid: %#B\n", &chunk
);
96 public->destroy(public);
100 fprintf(stderr
, "unable to parse input key.\n");