void gnutls_pkcs12_bag_deinit(gnutls_pkcs12_bag bag);
int gnutls_pkcs12_bag_get_count(gnutls_pkcs12_bag bag);
+int gnutls_pkcs12_bag_get_key_id(gnutls_pkcs12_bag bag, int indx,
+ gnutls_datum* id);
+int gnutls_pkcs12_bag_set_key_id(gnutls_pkcs12_bag bag, int indx,
+ const gnutls_datum* id);
+
+int gnutls_pkcs12_bag_get_friendly_name(gnutls_pkcs12_bag bag, int indx,
+ char **name);
+int gnutls_pkcs12_bag_set_friendly_name(gnutls_pkcs12_bag bag, int indx,
+ const char* name);
+
+
#ifdef __cplusplus
}
#endif
int _gnutls_x509_read_value( ASN1_TYPE c, const char* root, gnutls_datum *ret, int str);
int _gnutls_x509_write_value( ASN1_TYPE c, const char* root, const gnutls_datum* data, int str);
+
+int _gnutls_x509_encode_and_write_attribute( const char* given_oid, ASN1_TYPE asn1_struct,
+ const char* where, const unsigned char* data, int sizeof_data, int multi);
+int _gnutls_x509_decode_and_read_attribute(ASN1_TYPE asn1_struct, const char* where,
+ char* oid, int oid_size, gnutls_datum* value, int multi);
char tmpbuffer2[64];
char tmpbuffer3[64];
char counter[MAX_INT_DIGITS];
- char value[200];
+ char value[256];
char escaped[256];
const char *ldap_desc;
char oid[128];
return 0;
}
+/* Decodes an X.509 Attribute (if multi==1) or an AttributeTypeAndValue
+ * otherwise.
+ */
+int _gnutls_x509_decode_and_read_attribute(ASN1_TYPE asn1_struct, const char* where,
+ char* oid, int oid_size, gnutls_datum* value, int multi)
+{
+char tmpbuffer[128];
+int len, result;
+
+ /* Read the OID
+ */
+ _gnutls_str_cpy(tmpbuffer, sizeof(tmpbuffer), where);
+ _gnutls_str_cat(tmpbuffer, sizeof(tmpbuffer), ".type");
+
+ len = oid_size - 1;
+ result = asn1_read_value(asn1_struct, tmpbuffer, oid, &len);
+
+ if (result != ASN1_SUCCESS) {
+ gnutls_assert();
+ result = _gnutls_asn2err(result);
+ return result;
+ }
+
+ /* Read the Value
+ */
+
+ _gnutls_str_cpy(tmpbuffer, sizeof(tmpbuffer), where);
+ _gnutls_str_cat(tmpbuffer, sizeof(tmpbuffer), ".value");
+
+ if (multi)
+ _gnutls_str_cat(tmpbuffer, sizeof(tmpbuffer), "s.?1"); /* .values.?1 */
+
+ result = _gnutls_x509_read_value( asn1_struct, tmpbuffer, value, 0);
+ if (result < 0) {
+ gnutls_assert();
+ return result;
+ }
+
+ return 0;
+
+}
/* Sets an X509 DN in the asn1_struct, and puts the given OID in the DN.
* The input is assumed to be raw data.
const char* asn1_rdn_name, const char* oid, const char *name,
int sizeof_name);
-int _gnutls_x509_encode_and_write_attribute( const char* given_oid, ASN1_TYPE asn1_struct,
- const char* where, const unsigned char* data, int sizeof_data, int multi);
#endif
return NULL;
}
+static inline
+char* ucs2_to_ascii( char* data, int size) {
+int i;
+
+ for (i=0;i<size/2;i++)
+ data[i] = data[i*2 + 1];
+ data[i] = 0;
+
+ return data;
+}
+
/* Decodes the SafeContents, and puts the output in
* the given bag.
*/
ASN1_TYPE c2 = ASN1_TYPE_EMPTY;
int len, result;
int bag_type;
-int count = 0, i;
+gnutls_datum attr_val;
+int count = 0, i, attributes, j;
char counter[MAX_INT_DIGITS];
/* Step 1. Extract the SEQUENCE.
_gnutls_free_datum( &tmp);
}
+ /* read the bag attributes
+ */
+ _gnutls_str_cpy( root, sizeof(root), "?");
+ _gnutls_int2str( i+1, counter);
+ _gnutls_str_cat( root, sizeof(root), counter);
+ _gnutls_str_cat( root, sizeof(root), ".bagAttributes");
+
+ result = asn1_number_of_elements( c2, root, &attributes);
+ if (result != ASN1_SUCCESS) {
+ gnutls_assert();
+ result = _gnutls_asn2err(result);
+ goto cleanup;
+ }
+
+ if (attributes < 0) attributes = 1;
+
+ for (j=0;j<attributes;j++) {
+
+ _gnutls_str_cpy( root, sizeof(root), "?");
+ _gnutls_int2str( i+1, counter);
+ _gnutls_str_cat( root, sizeof(root), counter);
+ _gnutls_str_cat( root, sizeof(root), ".bagAttributes.?");
+ _gnutls_int2str( j+1, counter);
+ _gnutls_str_cat( root, sizeof(root), counter);
+
+ result = _gnutls_x509_decode_and_read_attribute(
+ c2, root, oid, sizeof(oid), &attr_val, 1);
+ if (result < 0) {
+ gnutls_assert();
+ goto cleanup;
+ }
+
+
+ if (strcmp( oid, KEY_ID_OID)==0)
+ bag->element[i].local_key_id = attr_val;
+ else if (strcmp( oid, FRIENDLY_NAME_OID)==0)
+ bag->element[i].friendly_name = ucs2_to_ascii( attr_val.data, attr_val.size);
+ else {
+ _gnutls_x509_log( "Unknown PKCS12 Bag Attribute OID '%s'\n", oid);
+ }
+ }
+
+
bag->element[i].type = bag_type;
}
return result;
}
-#define FRIENDLY_NAME_OID "1.2.840.113549.1.9.20"
-#define KEY_ID_OID "1.2.840.113549.1.9.21"
static int write_attributes( gnutls_pkcs12_bag bag, int elem, ASN1_TYPE c2, const char* where) {
int result;
#define DATA_OID "1.2.840.113549.1.7.1"
#define ENC_DATA_OID "1.2.840.113549.1.7.6"
+/* Bag attributes
+ */
+#define FRIENDLY_NAME_OID "1.2.840.113549.1.9.20"
+#define KEY_ID_OID "1.2.840.113549.1.9.21"
+
typedef struct gnutls_pkcs12_int *gnutls_pkcs12;
typedef struct gnutls_pkcs12_bag_int *gnutls_pkcs12_bag;