pubkey_speed: Add header and fix usage
[strongswan.git] / scripts / keyid2sql.c
index 094e1af..6e9a133 100644 (file)
@@ -1,7 +1,21 @@
+/*
+ * Copyright (C) 2008 Andreas Steffen
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
 
 #include <stdio.h>
 #include <library.h>
-#include <debug.h>
+#include <utils/debug.h>
 #include <credentials/keys/private_key.h>
 #include <credentials/keys/public_key.h>
 
@@ -15,9 +29,9 @@ int main(int argc, char *argv[])
        chunk_t chunk;
        char buf[8096];
        int read, n;
-       
+
        library_init(NULL);
-       lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR, "gmp pubkey sha1");
+       lib->plugins->load(lib->plugins, PLUGINS);
        atexit(library_deinit);
 
        read = fread(buf, 1, sizeof(buf), stdin);
@@ -26,15 +40,15 @@ 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)
        {
-               if (private->get_fingerprint(private, KEY_ID_PUBKEY_SHA1, &chunk))
+               if (private->get_fingerprint(private, KEYID_PUBKEY_SHA1, &chunk))
                {
                        printf("%d, X'", ID_KEY_ID);
                        for (n = 0; n < chunk.len; n++)
@@ -46,19 +60,19 @@ int main(int argc, char *argv[])
                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)
        {
-               if (public->get_fingerprint(public, KEY_ID_PUBKEY_SHA1, &chunk))
+               if (public->get_fingerprint(public, KEYID_PUBKEY_SHA1, &chunk))
                {
                        printf("%d, X'", ID_KEY_ID);
                        for (n = 0; n < chunk.len; n++)
@@ -70,7 +84,7 @@ int main(int argc, char *argv[])
                public->destroy(public);
                return 0;
        }
-       
+
        fprintf(stderr, "unable to parse input key.\n");
        return -1;
 }