Migrated ike_mobike task to INIT/METHOD macros.
[strongswan.git] / scripts / key2keyid.c
index b74ac70..6a8301c 100644 (file)
@@ -2,11 +2,8 @@
 #include <stdio.h>
 #include <library.h>
 #include <debug.h>
-
-static void dbg_stderr(int level, char *fmt, ...)
-{
-       
-}
+#include <credentials/keys/private_key.h>
+#include <credentials/keys/public_key.h>
 
 /**
  * print the keyids of a private or public key
@@ -18,11 +15,9 @@ int main(int argc, char *argv[])
        chunk_t chunk;
        char buf[8096];
        int read;
-       
-       //dbg = dbg_stderr;
-       
+
        library_init(NULL);
-       lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR, "gmp pubkey sha1");
+       lib->plugins->load(lib->plugins, NULL, PLUGINS);
        atexit(library_deinit);
 
        read = fread(buf, 1, sizeof(buf), stdin);
@@ -31,47 +26,63 @@ int main(int argc, char *argv[])
                fprintf(stderr, "reading key failed.\n");
                return -1;
        }
-       
+
        chunk = chunk_create(buf, read);
-       
+
        private = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
-                                                                BUILD_BLOB_ASN1_DER, chunk_clone(chunk),
+                                                                BUILD_BLOB_PEM, chunk_clone(chunk),
                                                                 BUILD_END);
        if (private)
        {
                printf("parsed %d bits %N private key.\n",
-                          private->get_keysize(private)*8,
+                          private->get_keysize(private),
                           key_type_names, private->get_type(private));
-               printf("%N is:\t %D\n", id_type_names, ID_PUBKEY_INFO_SHA1,
-                          private->get_id(private, ID_PUBKEY_INFO_SHA1));
-               printf("%N is:\t %D\n", id_type_names, ID_PUBKEY_SHA1,
-                          private->get_id(private, ID_PUBKEY_SHA1));
+               if (private->get_fingerprint(private, KEYID_PUBKEY_INFO_SHA1, &chunk))
+               {
+                       printf("subjectPublicKeyInfo keyid: %#B\n", &chunk);
+               }
+               if (private->get_fingerprint(private, KEYID_PUBKEY_SHA1, &chunk))
+               {
+                       printf("subjectPublicKey keyid:     %#B\n", &chunk);
+               }
+               if (private->get_fingerprint(private, KEYID_PGPV3, &chunk))
+               {
+                       printf("PGP version 3 keyid:        %#B\n", &chunk);
+               }
                private->destroy(private);
                return 0;
        }
-       
+
        public = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, KEY_ANY,
-                                                               BUILD_BLOB_ASN1_DER, chunk_clone(chunk),
+                                                               BUILD_BLOB_PEM, chunk_clone(chunk),
                                                                BUILD_END);
        if (!public)
        {
                public = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, KEY_RSA,
-                                                                       BUILD_BLOB_ASN1_DER, chunk_clone(chunk),
+                                                                       BUILD_BLOB_PEM, chunk_clone(chunk),
                                                                        BUILD_END);
        }
        if (public)
        {
                printf("parsed %d bits %N public key.\n",
-                          public->get_keysize(public)*8,
+                          public->get_keysize(public),
                           key_type_names, public->get_type(public));
-               printf("%N is:\t %D\n", id_type_names, ID_PUBKEY_INFO_SHA1,
-                          public->get_id(public, ID_PUBKEY_INFO_SHA1));
-               printf("%N is:\t %D\n", id_type_names, ID_PUBKEY_SHA1,
-                          public->get_id(public, ID_PUBKEY_SHA1));
+               if (public->get_fingerprint(public, KEYID_PUBKEY_INFO_SHA1, &chunk))
+               {
+                       printf("subjectPublicKeyInfo keyid: %#B\n", &chunk);
+               }
+               if (public->get_fingerprint(public, KEYID_PUBKEY_SHA1, &chunk))
+               {
+                       printf("subjectPublicKey keyid:     %#B\n", &chunk);
+               }
+               if (public->get_fingerprint(public, KEYID_PGPV3, &chunk))
+               {
+                       printf("PGP version 3 keyid:        %#B\n", &chunk);
+               }
                public->destroy(public);
                return 0;
        }
-       
+
        fprintf(stderr, "unable to parse input key.\n");
        return -1;
 }