]>
git.ipfire.org Git - thirdparty/strongswan.git/blob - scripts/keyid2sql.c
2 * Copyright (C) 2008 Andreas Steffen
4 * Copyright (C) secunet Security Networks AG
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 #include <utils/debug.h>
20 #include <credentials/keys/private_key.h>
21 #include <credentials/keys/public_key.h>
24 * print the keyids of a private or public key in sql format
26 int main(int argc
, char *argv
[])
29 private_key_t
*private;
34 library_init(NULL
, "keyid2sql");
35 lib
->plugins
->load(lib
->plugins
, PLUGINS
);
36 atexit(library_deinit
);
38 read
= fread(buf
, 1, sizeof(buf
), stdin
);
41 fprintf(stderr
, "reading key failed.\n");
45 chunk
= chunk_create(buf
, read
);
47 private = lib
->creds
->create(lib
->creds
, CRED_PRIVATE_KEY
, KEY_RSA
,
48 BUILD_BLOB_PEM
, chunk_clone(chunk
),
52 if (private->get_fingerprint(private, KEYID_PUBKEY_SHA1
, &chunk
))
54 printf("%d, X'", ID_KEY_ID
);
55 for (n
= 0; n
< chunk
.len
; n
++)
57 printf("%.2x", chunk
.ptr
[n
]);
61 private->destroy(private);
65 public = lib
->creds
->create(lib
->creds
, CRED_PUBLIC_KEY
, KEY_ANY
,
66 BUILD_BLOB_PEM
, chunk_clone(chunk
),
70 public = lib
->creds
->create(lib
->creds
, CRED_PUBLIC_KEY
, KEY_RSA
,
71 BUILD_BLOB_PEM
, chunk_clone(chunk
),
76 if (public->get_fingerprint(public, KEYID_PUBKEY_SHA1
, &chunk
))
78 printf("%d, X'", ID_KEY_ID
);
79 for (n
= 0; n
< chunk
.len
; n
++)
81 printf("%.2x", chunk
.ptr
[n
]);
85 public->destroy(public);
89 fprintf(stderr
, "unable to parse input key.\n");