2012-06-29 14:07:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Andreas Steffen
|
2018-05-23 14:04:50 +00:00
|
|
|
* HSR Hochschule fuer Technik Rapperswil
|
2012-06-29 14:07:10 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2008-07-29 19:46:39 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <library.h>
|
2012-10-16 14:03:21 +00:00
|
|
|
#include <utils/debug.h>
|
2009-05-28 13:50:05 +00:00
|
|
|
#include <credentials/keys/private_key.h>
|
|
|
|
#include <credentials/keys/public_key.h>
|
|
|
|
|
2008-07-29 19:46:39 +00:00
|
|
|
/**
|
|
|
|
* print the keyids of a private or public key in sql format
|
|
|
|
*/
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
public_key_t *public;
|
|
|
|
private_key_t *private;
|
|
|
|
chunk_t chunk;
|
|
|
|
char buf[8096];
|
|
|
|
int read, n;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2014-01-22 10:50:39 +00:00
|
|
|
library_init(NULL, "keyid2sql");
|
2013-06-28 08:44:15 +00:00
|
|
|
lib->plugins->load(lib->plugins, PLUGINS);
|
2008-07-29 19:46:39 +00:00
|
|
|
atexit(library_deinit);
|
|
|
|
|
|
|
|
read = fread(buf, 1, sizeof(buf), stdin);
|
|
|
|
if (read <= 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "reading key failed.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-07-29 19:46:39 +00:00
|
|
|
chunk = chunk_create(buf, read);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-07-29 19:46:39 +00:00
|
|
|
private = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
|
2009-08-25 09:30:42 +00:00
|
|
|
BUILD_BLOB_PEM, chunk_clone(chunk),
|
2008-07-29 19:46:39 +00:00
|
|
|
BUILD_END);
|
|
|
|
if (private)
|
|
|
|
{
|
2010-07-13 09:28:04 +00:00
|
|
|
if (private->get_fingerprint(private, KEYID_PUBKEY_SHA1, &chunk))
|
2008-07-29 19:46:39 +00:00
|
|
|
{
|
2009-08-25 09:29:51 +00:00
|
|
|
printf("%d, X'", ID_KEY_ID);
|
|
|
|
for (n = 0; n < chunk.len; n++)
|
|
|
|
{
|
|
|
|
printf("%.2x", chunk.ptr[n]);
|
|
|
|
}
|
|
|
|
printf("'\n");
|
2008-07-29 19:46:39 +00:00
|
|
|
}
|
|
|
|
private->destroy(private);
|
|
|
|
return 0;
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-07-29 19:46:39 +00:00
|
|
|
public = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, KEY_ANY,
|
2009-08-25 09:30:42 +00:00
|
|
|
BUILD_BLOB_PEM, chunk_clone(chunk),
|
2008-07-29 19:46:39 +00:00
|
|
|
BUILD_END);
|
|
|
|
if (!public)
|
|
|
|
{
|
|
|
|
public = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, KEY_RSA,
|
2009-08-25 09:30:42 +00:00
|
|
|
BUILD_BLOB_PEM, chunk_clone(chunk),
|
2008-07-29 19:46:39 +00:00
|
|
|
BUILD_END);
|
|
|
|
}
|
|
|
|
if (public)
|
|
|
|
{
|
2010-07-13 09:28:04 +00:00
|
|
|
if (public->get_fingerprint(public, KEYID_PUBKEY_SHA1, &chunk))
|
2008-07-29 19:46:39 +00:00
|
|
|
{
|
2009-08-25 09:29:51 +00:00
|
|
|
printf("%d, X'", ID_KEY_ID);
|
|
|
|
for (n = 0; n < chunk.len; n++)
|
|
|
|
{
|
|
|
|
printf("%.2x", chunk.ptr[n]);
|
|
|
|
}
|
|
|
|
printf("'\n");
|
2008-07-29 19:46:39 +00:00
|
|
|
}
|
|
|
|
public->destroy(public);
|
|
|
|
return 0;
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-07-29 19:46:39 +00:00
|
|
|
fprintf(stderr, "unable to parse input key.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|