x509 plugin supports encoding of CA basicConstraint extension
[strongswan.git] / scripts / keyid2sql.c
index f7d447a..bf95217 100644 (file)
@@ -2,6 +2,8 @@
 #include <stdio.h>
 #include <library.h>
 #include <debug.h>
 #include <stdio.h>
 #include <library.h>
 #include <debug.h>
+#include <credentials/keys/private_key.h>
+#include <credentials/keys/public_key.h>
 
 /**
  * print the keyids of a private or public key in sql format
 
 /**
  * print the keyids of a private or public key in sql format
@@ -10,13 +12,12 @@ int main(int argc, char *argv[])
 {
        public_key_t *public;
        private_key_t *private;
 {
        public_key_t *public;
        private_key_t *private;
-       identification_t *keyid;
        chunk_t chunk;
        char buf[8096];
        int read, n;
        chunk_t chunk;
        char buf[8096];
        int read, n;
-       
+
        library_init(NULL);
        library_init(NULL);
-       lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR, "gmp pubkey sha1");
+       lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR, PLUGINS);
        atexit(library_deinit);
 
        read = fread(buf, 1, sizeof(buf), stdin);
        atexit(library_deinit);
 
        read = fread(buf, 1, sizeof(buf), stdin);
@@ -25,51 +26,51 @@ int main(int argc, char *argv[])
                fprintf(stderr, "reading key failed.\n");
                return -1;
        }
                fprintf(stderr, "reading key failed.\n");
                return -1;
        }
-       
+
        chunk = chunk_create(buf, read);
        chunk = chunk_create(buf, read);
-       
+
        private = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
        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)
        {
                                                                 BUILD_END);
        if (private)
        {
-               keyid = private->get_id(private, ID_PUBKEY_INFO_SHA1);
-               chunk = keyid->get_encoding(keyid);
-
-               printf("%d, X'", ID_PUBKEY_INFO_SHA1);
-               for (n = 0; n < chunk.len; n++)
+               if (private->get_fingerprint(private, KEY_ID_PUBKEY_SHA1, &chunk))
                {
                {
-                       printf("%.2x", chunk.ptr[n]);
+                       printf("%d, X'", ID_KEY_ID);
+                       for (n = 0; n < chunk.len; n++)
+                       {
+                               printf("%.2x", chunk.ptr[n]);
+                       }
+                       printf("'\n");
                }
                }
-               printf("'\n");
                private->destroy(private);
                return 0;
        }
                private->destroy(private);
                return 0;
        }
-       
+
        public = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, KEY_ANY,
        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_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)
        {
                                                                        BUILD_END);
        }
        if (public)
        {
-               keyid = public->get_id(public, ID_PUBKEY_INFO_SHA1);
-               chunk = keyid->get_encoding(keyid);
-
-               printf("%d, X'", ID_PUBKEY_INFO_SHA1);
-               for (n = 0; n < chunk.len; n++)
+               if (public->get_fingerprint(public, KEY_ID_PUBKEY_SHA1, &chunk))
                {
                {
-                       printf("%.2x", chunk.ptr[n]);
+                       printf("%d, X'", ID_KEY_ID);
+                       for (n = 0; n < chunk.len; n++)
+                       {
+                               printf("%.2x", chunk.ptr[n]);
+                       }
+                       printf("'\n");
                }
                }
-               printf("'\n");
                public->destroy(public);
                return 0;
        }
                public->destroy(public);
                return 0;
        }
-       
+
        fprintf(stderr, "unable to parse input key.\n");
        return -1;
 }
        fprintf(stderr, "unable to parse input key.\n");
        return -1;
 }