compare IKE config when reusing an existing IKE_SA to initiate a CHILD_SA
[strongswan.git] / scripts / key2keyid.c
1
2 #include <stdio.h>
3 #include <library.h>
4 #include <debug.h>
5 #include <credentials/keys/private_key.h>
6 #include <credentials/keys/public_key.h>
7
8 /**
9 * print the keyids of a private or public key
10 */
11 int main(int argc, char *argv[])
12 {
13 public_key_t *public;
14 private_key_t *private;
15 chunk_t chunk;
16 char buf[8096];
17 int read;
18
19 library_init(NULL);
20 lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR, "gmp pubkey sha1");
21 atexit(library_deinit);
22
23 read = fread(buf, 1, sizeof(buf), stdin);
24 if (read <= 0)
25 {
26 fprintf(stderr, "reading key failed.\n");
27 return -1;
28 }
29
30 chunk = chunk_create(buf, read);
31
32 private = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
33 BUILD_BLOB_ASN1_DER, chunk_clone(chunk),
34 BUILD_END);
35 if (private)
36 {
37 printf("parsed %d bits %N private key.\n",
38 private->get_keysize(private)*8,
39 key_type_names, private->get_type(private));
40 printf("%N is:\t %D\n", id_type_names, ID_PUBKEY_INFO_SHA1,
41 private->get_id(private, ID_PUBKEY_INFO_SHA1));
42 printf("%N is:\t %D\n", id_type_names, ID_PUBKEY_SHA1,
43 private->get_id(private, ID_PUBKEY_SHA1));
44 private->destroy(private);
45 return 0;
46 }
47
48 public = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, KEY_ANY,
49 BUILD_BLOB_ASN1_DER, chunk_clone(chunk),
50 BUILD_END);
51 if (!public)
52 {
53 public = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, KEY_RSA,
54 BUILD_BLOB_ASN1_DER, chunk_clone(chunk),
55 BUILD_END);
56 }
57 if (public)
58 {
59 printf("parsed %d bits %N public key.\n",
60 public->get_keysize(public)*8,
61 key_type_names, public->get_type(public));
62 printf("%N is:\t %D\n", id_type_names, ID_PUBKEY_INFO_SHA1,
63 public->get_id(public, ID_PUBKEY_INFO_SHA1));
64 printf("%N is:\t %D\n", id_type_names, ID_PUBKEY_SHA1,
65 public->get_id(public, ID_PUBKEY_SHA1));
66 public->destroy(public);
67 return 0;
68 }
69
70 fprintf(stderr, "unable to parse input key.\n");
71 return -1;
72 }
73