diff options
author | Martin Willi <martin@strongswan.org> | 2008-05-13 13:57:42 +0000 |
---|---|---|
committer | Martin Willi <martin@strongswan.org> | 2008-05-13 13:57:42 +0000 |
commit | 6e8840981ded2d29a31be134aecb686b0eb0f540 (patch) | |
tree | 386470e4bdc6f4101bbed7cfb10e76d59211d67c /scripts/key2keyid.c | |
parent | 7af8995cdec2783433b01c78a8a6c49b682d1fd1 (diff) | |
download | strongswan-6e8840981ded2d29a31be134aecb686b0eb0f540.tar.bz2 strongswan-6e8840981ded2d29a31be134aecb686b0eb0f540.tar.xz |
tool to calculate KEYIDs from keys
Diffstat (limited to 'scripts/key2keyid.c')
-rw-r--r-- | scripts/key2keyid.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/scripts/key2keyid.c b/scripts/key2keyid.c new file mode 100644 index 000000000..cab5db730 --- /dev/null +++ b/scripts/key2keyid.c @@ -0,0 +1,77 @@ + +#include <stdio.h> +#include <library.h> +#include <debug.h> + +static void dbg_stderr(int level, char *fmt, ...) +{ +} + +/** + * print the keyids of a private or public key + */ +int main(int argc, char *argv[]) +{ + public_key_t *public; + private_key_t *private; + chunk_t chunk; + char buf[8096]; + int read; + + dbg = dbg_stderr; + + library_init(NULL); + lib->plugins->load(lib->plugins, "/usr/local/libexec/ipsec/plugins", "libstrongswan-"); + atexit(library_deinit); + + read = fread(buf, 1, sizeof(buf), stdin); + if (read <= 0) + { + 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_END); + if (private) + { + printf("parsed %d bits %N private key.\n", + private->get_keysize(private)*8, + 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)); + private->destroy(private); + return 0; + } + + public = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, KEY_ANY, + BUILD_BLOB_ASN1_DER, 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_END); + } + if (public) + { + printf("parsed %d bits %N public key.\n", + public->get_keysize(public)*8, + 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)); + public->destroy(public); + return 0; + } + + fprintf(stderr, "unable to parse input key.\n"); + return -1; +} + |