struct url_find_data_st {
gnutls_pkcs11_obj_t crt;
-<<<<<<< HEAD:lib/pkcs11.c
};
struct flags_find_data_st {
struct pkcs11_url_info info;
unsigned int slot_flags;
-=======
->>>>>>> Added gnutls_pubkey_t abstract type to handle public keys. It can currently:lib/pkcs11.c
};
struct flags_find_data_st {
int gnutls_pkcs11_obj_init(gnutls_pkcs11_obj_t * crt)
{
*crt = gnutls_calloc(1, sizeof(struct gnutls_pkcs11_obj_st));
-<<<<<<< HEAD:lib/pkcs11.c
-=======
->>>>>>> Added gnutls_pubkey_t abstract type to handle public keys. It can currently:lib/pkcs11.c
if (*crt == NULL) {
gnutls_assert();
return GNUTLS_E_MEMORY_ERROR;
crt->type = GNUTLS_PKCS11_OBJ_UNKNOWN;
}
-<<<<<<< HEAD:lib/pkcs11.c
-=======
switch(class) {
case CKO_CERTIFICATE:
crt->type = GNUTLS_PKCS11_OBJ_X509_CRT;
gnutls_datum_t data = { a[0].value, a[0].value_len };
gnutls_datum_t label = { a[1].value, a[1].value_len };
-<<<<<<< HEAD:lib/pkcs11.c
if (class == CKO_PUBLIC_KEY) {
ret = pkcs11_obj_import_pubkey(pks, obj, find_data->crt, &id, &label, &info->tinfo);
} else {
ret = pkcs11_obj_import(class, find_data->crt, &data, &id, &label, &info->tinfo);
}
-=======
- ret = pkcs11_obj_import(CKO_CERTIFICATE, find_data->crt, &data, &id, &label, &info->tinfo);
->>>>>>> Added gnutls_pubkey_t abstract type to handle public keys. It can currently:lib/pkcs11.c
if (ret < 0) {
gnutls_assert();
goto cleanup;
* Returns: The type of the certificate.
**/
gnutls_pkcs11_obj_type_t gnutls_pkcs11_obj_get_type (gnutls_pkcs11_obj_t obj)
-<<<<<<< HEAD:lib/pkcs11.c
{
return obj->type;
}
list->key_ids_size = current-1;
return 0;
-=======
-{
- return obj->type;
->>>>>>> Added gnutls_pubkey_t abstract type to handle public keys. It can currently:lib/pkcs11.c
}
struct pkey_list {
ck_object_handle_t obj;
unsigned long count, current;
char certid_tmp[PKCS11_ID_SIZE];
- int ret;
class = CKO_PRIVATE_KEY;
value.data = NULL;
value.size = 0;
}
-<<<<<<< HEAD:lib/pkcs11.c
if (find_data->flags == GNUTLS_PKCS11_OBJ_ATTR_ALL) {
a[0].type = CKA_CLASS;
a[0].value = &class;
a[0].value_len = sizeof class;
-=======
-
- if (find_data->flags == GNUTLS_PKCS11_OBJ_ATTR_ALL) {
- a[0].type = CKA_CLASS;
- a[0].value = &class;
- a[0].value_len = sizeof class;
-
->>>>>>> Added gnutls_pubkey_t abstract type to handle public keys. It can currently:lib/pkcs11.c
pakchois_get_attribute_value(pks, obj, a, 1);
}
goto fail;
}
-<<<<<<< HEAD:lib/pkcs11.c
if (class == CKO_PUBLIC_KEY) {
ret = pkcs11_obj_import_pubkey(pks, obj, find_data->p_list[find_data->current], &id, &label, &info->tinfo);
} else {
ret = pkcs11_obj_import(class, find_data->p_list[find_data->current], &value, &id, &label, &info->tinfo);
}
-=======
- ret = pkcs11_obj_import(class, find_data->p_list[find_data->current], &value, &id, &label, &info->tinfo);
->>>>>>> Added gnutls_pubkey_t abstract type to handle public keys. It can currently:lib/pkcs11.c
+
if (ret < 0) {
gnutls_assert();
goto fail;
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)