summaryrefslogtreecommitdiff
path: root/src/pkcs11.c
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2010-05-22 20:15:22 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2010-06-03 19:52:33 +0200
commit1231655dfee3105aeaf89094aecd4b45c51b29ec (patch)
tree57f80bd8a1fa09fa93db791d6edb2b69d762ef0d /src/pkcs11.c
parent2f671fb4b159de431959f03496e4be46ea806f28 (diff)
downloadgnutls-1231655dfee3105aeaf89094aecd4b45c51b29ec.tar.gz
Added gnutls_pubkey_import_pkcs11(), gnutls_pubkey_import_rsa_raw(),
gnutls_pubkey_import_dsa_raw(), gnutls_pkcs11_obj_export().
Diffstat (limited to 'src/pkcs11.c')
-rw-r--r--src/pkcs11.c88
1 files changed, 69 insertions, 19 deletions
diff --git a/src/pkcs11.c b/src/pkcs11.c
index c22d8bc8e4..be99641777 100644
--- a/src/pkcs11.c
+++ b/src/pkcs11.c
@@ -367,34 +367,84 @@ size_t size;
exit(1);
}
- ret = gnutls_x509_crt_init(&xcrt);
- if (ret < 0) {
- fprintf(stderr, "Error in %s:%d: %s\n", __func__, __LINE__, gnutls_strerror(ret));
- exit(1);
- }
+ switch(gnutls_pkcs11_obj_get_type(crt)) {
+ case GNUTLS_PKCS11_OBJ_X509_CRT:
+ ret = gnutls_x509_crt_init(&xcrt);
+ if (ret < 0) {
+ fprintf(stderr, "Error in %s:%d: %s\n", __func__, __LINE__, gnutls_strerror(ret));
+ exit(1);
+ }
- ret = gnutls_x509_crt_import_pkcs11(xcrt, crt);
- if (ret < 0) {
- fprintf(stderr, "Error in %s:%d: %s\n", __func__, __LINE__, gnutls_strerror(ret));
- exit(1);
- }
+ ret = gnutls_x509_crt_import_pkcs11(xcrt, crt);
+ if (ret < 0) {
+ fprintf(stderr, "Error in %s:%d: %s\n", __func__, __LINE__, gnutls_strerror(ret));
+ exit(1);
+ }
- size = buffer_size;
- ret = gnutls_x509_crt_export (xcrt, GNUTLS_X509_FMT_PEM, buffer, &size);
- if (ret < 0) {
- fprintf(stderr, "Error in %s:%d: %s\n", __func__, __LINE__, gnutls_strerror(ret));
- exit(1);
+ size = buffer_size;
+ ret = gnutls_x509_crt_export (xcrt, GNUTLS_X509_FMT_PEM, buffer, &size);
+ if (ret < 0) {
+ fprintf(stderr, "Error in %s:%d: %s\n", __func__, __LINE__, gnutls_strerror(ret));
+ exit(1);
+ }
+ fwrite (buffer, 1, size, outfile);
+
+ gnutls_x509_crt_deinit(xcrt);
+ break;
+ case GNUTLS_PKCS11_OBJ_PUBKEY:
+ ret = gnutls_pubkey_init(&pubkey);
+ if (ret < 0) {
+ fprintf(stderr, "Error in %s:%d: %s\n", __func__, __LINE__, gnutls_strerror(ret));
+ exit(1);
+ }
+
+ ret = gnutls_pubkey_import_pkcs11(pubkey, crt, 0);
+ if (ret < 0) {
+ fprintf(stderr, "Error in %s:%d: %s\n", __func__, __LINE__, gnutls_strerror(ret));
+ exit(1);
+ }
+
+ size = buffer_size;
+ ret = gnutls_pubkey_export (pubkey, GNUTLS_X509_FMT_PEM, buffer, &size);
+ if (ret < 0) {
+ fprintf(stderr, "Error in %s:%d: %s\n", __func__, __LINE__, gnutls_strerror(ret));
+ exit(1);
+ }
+ fwrite (buffer, 1, size, outfile);
+
+ gnutls_pubkey_deinit(pubkey);
+ break;
+ default: {
+ gnutls_datum data, enc;
+
+ size = buffer_size;
+ ret = gnutls_pkcs11_obj_export (crt, buffer, &size);
+ if (ret < 0) {
+ break;
+ }
+
+ data.data = buffer;
+ data.size = size;
+
+ ret = gnutls_pem_base64_encode_alloc("DATA", &data, &enc);
+ if (ret < 0) {
+ fprintf(stderr, "Error in %s:%d: %s\n", __func__, __LINE__, gnutls_strerror(ret));
+ exit(1);
+ }
+
+ fwrite (enc.data, 1, enc.size, outfile);
+
+ gnutls_free(enc.data);
+ break;
+ }
}
- fwrite (buffer, 1, size, outfile);
fputs("\n\n", outfile);
- gnutls_x509_crt_deinit(xcrt);
+
gnutls_pkcs11_obj_deinit(crt);
return;
-
-
}
void pkcs11_token_list(FILE* outfile)