aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-pkcs12.c
diff options
context:
space:
mode:
authorgerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>2009-12-21 21:06:01 +0000
committergerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>2009-12-21 21:06:01 +0000
commitfc9cceceada79c5499a41db9b1d99d7ed66fe582 (patch)
treec7dd20c72484499198d106b5ba392787651f500a /epan/dissectors/packet-pkcs12.c
parenta831efc2418106a9eec3633aff7fe561c5042402 (diff)
Switch to using a bundled version of the openSUSE Build Service packages
for GNUTLS since they provide 32-bit and 64-bit Windows packages. We no longer have winposixtype.h, so remove its #includes and add a ssize_t typedef to config.h.win32. git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@31341 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'epan/dissectors/packet-pkcs12.c')
-rw-r--r--epan/dissectors/packet-pkcs12.c61
1 files changed, 29 insertions, 32 deletions
diff --git a/epan/dissectors/packet-pkcs12.c b/epan/dissectors/packet-pkcs12.c
index fc5fd29a48..71099a439d 100644
--- a/epan/dissectors/packet-pkcs12.c
+++ b/epan/dissectors/packet-pkcs12.c
@@ -59,11 +59,8 @@
#endif
#ifdef HAVE_LIBGCRYPT
-#ifdef _WIN32
-#include <winposixtype.h>
-#endif
#include <gcrypt.h>
-#endif
+#endif
#define PNAME "PKCS#12: Personal Information Exchange"
#define PSNAME "PKCS12"
@@ -79,7 +76,7 @@ static int proto_pkcs12 = -1;
static int hf_pkcs12_X509Certificate_PDU = -1;
static gint ett_decrypted_pbe = -1;
-static const char *object_identifier_id = NULL;
+static const char *object_identifier_id = NULL;
static int iteration_count = 0;
static tvbuff_t *salt = NULL;
static const char *password = NULL;
@@ -183,7 +180,7 @@ static void append_oid(proto_tree *tree, const char *oid)
const char *name = NULL;
name = oid_resolved_from_string(oid);
- proto_item_append_text(tree, " (%s)", name ? name : oid);
+ proto_item_append_text(tree, " (%s)", name ? name : oid);
}
#ifdef HAVE_LIBGCRYPT
@@ -196,7 +193,7 @@ generate_key_or_iv(unsigned int id, tvbuff_t *salt_tvb, unsigned int iter,
unsigned int i, j;
gcry_md_hd_t md;
gcry_mpi_t num_b1 = NULL;
- unsigned int pwlen;
+ size_t pwlen;
char hash[20], buf_b[64], buf_i[128], *p;
char *salt;
int salt_size;
@@ -245,14 +242,14 @@ generate_key_or_iv(unsigned int id, tvbuff_t *salt_tvb, unsigned int iter,
unsigned char lid = id & 0xFF;
gcry_md_write (md, &lid, 1);
}
-
+
gcry_md_write(md, buf_i, pw ? 128 : 64);
gcry_md_final (md);
memcpy (hash, gcry_md_read (md, 0), 20);
-
+
gcry_md_close (md);
-
+
for (i = 1; i < iter; i++)
gcry_md_hash_buffer (GCRY_MD_SHA1, hash, hash, 20);
@@ -280,17 +277,17 @@ generate_key_or_iv(unsigned int id, tvbuff_t *salt_tvb, unsigned int iter,
for (i = 0; i < 128; i += 64) {
gcry_mpi_t num_ij;
-
+
n = 64;
rc = gcry_mpi_scan (&num_ij, GCRYMPI_FMT_USG, buf_i + i, n, &n);
if (rc != 0) {
return FALSE;
}
-
+
gcry_mpi_add (num_ij, num_ij, num_b1);
gcry_mpi_clear_highbit (num_ij, 64 * 8);
-
+
n = 64;
rc = gcry_mpi_print (GCRYMPI_FMT_USG, buf_i + i, n, &n, num_ij);
@@ -303,7 +300,7 @@ generate_key_or_iv(unsigned int id, tvbuff_t *salt_tvb, unsigned int iter,
}
}
-#endif
+#endif
void PBE_reset_parameters()
{
@@ -331,7 +328,7 @@ int PBE_decrypt_data(const char *object_identifier_id _U_, tvbuff_t *encrypted_t
proto_tree *tree;
char byte;
gboolean decrypt_ok = TRUE;
-
+
if(((password == NULL) || (*password == '\0')) && (try_null_password == FALSE)) {
/* we are not configured to decrypt */
return FALSE;
@@ -357,12 +354,12 @@ int PBE_decrypt_data(const char *object_identifier_id _U_, tvbuff_t *encrypted_t
mode = GCRY_CIPHER_MODE_CBC;
} else {
/* we don't know how to decrypt this */
-
+
proto_item_append_text(item, " [Unsupported encryption algorithm]");
return FALSE;
}
- if((iteration_count == 0) || (salt == NULL)) {
+ if((iteration_count == 0) || (salt == NULL)) {
proto_item_append_text(item, " [Insufficient parameters]");
return FALSE;
}
@@ -374,9 +371,9 @@ int PBE_decrypt_data(const char *object_identifier_id _U_, tvbuff_t *encrypted_t
return FALSE;
if(ivlen) {
-
+
iv = ep_alloc(ivlen);
-
+
if(!generate_key_or_iv(2 /* IV */, salt, iteration_count, password, ivlen, iv))
return FALSE;
}
@@ -386,14 +383,14 @@ int PBE_decrypt_data(const char *object_identifier_id _U_, tvbuff_t *encrypted_t
if (gcry_err_code (err))
return FALSE;
- err = gcry_cipher_setkey (cipher, key, keylen);
+ err = gcry_cipher_setkey (cipher, key, keylen);
if (gcry_err_code (err)) {
gcry_cipher_close (cipher);
return FALSE;
}
-
+
if(ivlen) {
- err = gcry_cipher_setiv (cipher, iv, ivlen);
+ err = gcry_cipher_setiv (cipher, iv, ivlen);
if (gcry_err_code (err)) {
gcry_cipher_close (cipher);
return FALSE;
@@ -416,7 +413,7 @@ int PBE_decrypt_data(const char *object_identifier_id _U_, tvbuff_t *encrypted_t
gcry_cipher_close (cipher);
/* We don't know if we have successfully decrypted the data or not so we:
- a) check the trailing bytes
+ a) check the trailing bytes
b) see if we start with a sequence or a set (is this too constraining?
*/
@@ -431,7 +428,7 @@ int PBE_decrypt_data(const char *object_identifier_id _U_, tvbuff_t *encrypted_t
break;
}
}
- } else {
+ } else {
/* XXX: is this a failure? */
}
@@ -463,13 +460,13 @@ int PBE_decrypt_data(const char *object_identifier_id _U_, tvbuff_t *encrypted_t
/* add it as a new source */
add_new_data_source(actx->pinfo, clear_tvb, name->str);
-
+
g_string_free(name, TRUE);
/* now try and decode it */
call_ber_oid_callback(object_identifier_id, clear_tvb, 0, actx->pinfo, tree);
- return TRUE;
+ return TRUE;
#else
/* we cannot decrypt */
return FALSE;
@@ -497,7 +494,7 @@ dissect_pkcs12_T_version(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offse
static const ber_sequence_t DigestInfo_sequence[] = {
- { &hf_pkcs12_digestAlgorithm, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_cms_DigestAlgorithmIdentifier },
+ { &hf_pkcs12_digestAlgorithm, -1/*imported*/, -1/*imported*/, BER_FLAGS_NOOWNTAG, dissect_cms_DigestAlgorithmIdentifier },
{ &hf_pkcs12_digest , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_cms_Digest },
{ NULL, 0, 0, 0, NULL }
};
@@ -1134,7 +1131,7 @@ static void dissect_PBMAC1Params_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_,
/*--- End of included file: packet-pkcs12-fn.c ---*/
#line 386 "packet-pkcs12-template.c"
-static int strip_octet_string(tvbuff_t *tvb)
+static int strip_octet_string(tvbuff_t *tvb)
{
gint8 class;
gboolean pc, ind;
@@ -1167,18 +1164,18 @@ static void dissect_AuthenticatedSafe_OCTETSTRING_PDU(tvbuff_t *tvb, packet_info
proto_tree_add_text(tree, tvb, 0, 1, "BER Error: OCTET STRING expected");
}
-static void dissect_SafeContents_OCTETSTRING_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+static void dissect_SafeContents_OCTETSTRING_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
int offset = 0;
asn1_ctx_t asn1_ctx;
asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
offset = strip_octet_string(tvb);
-
+
dissect_pkcs12_SafeContents(FALSE, tvb, offset, &asn1_ctx, tree, hf_pkcs12_SafeContents_PDU);
}
-static void dissect_X509Certificate_OCTETSTRING_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+static void dissect_X509Certificate_OCTETSTRING_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
int offset = 0;
asn1_ctx_t asn1_ctx;
@@ -1475,7 +1472,7 @@ void proto_register_pkcs12(void) {
"Whether to try and decrypt the encrypted data within the"
" PKCS#12 with a NULL password", &try_null_password);
- register_ber_syntax_dissector("PKCS#12", proto_pkcs12, dissect_PFX_PDU);
+ register_ber_syntax_dissector("PKCS#12", proto_pkcs12, dissect_PFX_PDU);
register_ber_oid_syntax(".p12", NULL, "PKCS#12");
register_ber_oid_syntax(".pfx", NULL, "PKCS#12");
}