summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/asn1/pkcs12
diff options
context:
space:
mode:
Diffstat (limited to 'epan/dissectors/asn1/pkcs12')
-rw-r--r--epan/dissectors/asn1/pkcs12/packet-pkcs12-template.c87
1 files changed, 44 insertions, 43 deletions
diff --git a/epan/dissectors/asn1/pkcs12/packet-pkcs12-template.c b/epan/dissectors/asn1/pkcs12/packet-pkcs12-template.c
index faec6b15..290d9bdb 100644
--- a/epan/dissectors/asn1/pkcs12/packet-pkcs12-template.c
+++ b/epan/dissectors/asn1/pkcs12/packet-pkcs12-template.c
@@ -20,6 +20,7 @@
#include <epan/oids.h>
#include <epan/asn1.h>
#include <epan/prefs.h>
+#include <wsutil/array.h>
#include "packet-ber.h"
#include "packet-pkcs12.h"
@@ -41,20 +42,20 @@ void proto_register_pkcs12(void);
void proto_reg_handoff_pkcs12(void);
/* Initialize the protocol and registered fields */
-static int proto_pkcs12 = -1;
+static int proto_pkcs12;
-static int hf_pkcs12_X509Certificate_PDU = -1;
-static int hf_pkcs12_AuthenticatedSafe_PDU = -1; /* AuthenticatedSafe */
-static gint ett_decrypted_pbe = -1;
+static int hf_pkcs12_X509Certificate_PDU;
+static int hf_pkcs12_AuthenticatedSafe_PDU; /* AuthenticatedSafe */
+static int ett_decrypted_pbe;
-static expert_field ei_pkcs12_octet_string_expected = EI_INIT;
+static expert_field ei_pkcs12_octet_string_expected;
-static const char *object_identifier_id = NULL;
-static int iteration_count = 0;
-static tvbuff_t *salt = NULL;
-static const char *password = NULL;
-static gboolean try_null_password = FALSE;
+static const char *object_identifier_id;
+static int iteration_count;
+static tvbuff_t *salt;
+static const char *password;
+static bool try_null_password;
static int dissect_AuthenticatedSafe_OCTETSTRING_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data);
static int dissect_SafeContents_OCTETSTRING_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data);
@@ -101,7 +102,7 @@ generate_key_or_iv(packet_info *pinfo, unsigned int id, tvbuff_t *salt_tvb, unsi
if (pwlen > 63 / 2)
{
- return FALSE;
+ return false;
}
/* Store salt and password in BUF_I */
@@ -125,7 +126,7 @@ generate_key_or_iv(packet_info *pinfo, unsigned int id, tvbuff_t *salt_tvb, unsi
err = gcry_md_open(&md, GCRY_MD_SHA1, 0);
if (gcry_err_code(err))
{
- return FALSE;
+ return false;
}
for (i = 0; i < 64; i++)
{
@@ -149,7 +150,7 @@ generate_key_or_iv(packet_info *pinfo, unsigned int id, tvbuff_t *salt_tvb, unsi
if (cur_keylen == req_keylen)
{
gcry_mpi_release (num_b1);
- return TRUE; /* ready */
+ return true; /* ready */
}
/* need more bytes. */
@@ -162,7 +163,7 @@ generate_key_or_iv(packet_info *pinfo, unsigned int id, tvbuff_t *salt_tvb, unsi
if (rc != 0)
{
- return FALSE;
+ return false;
}
gcry_mpi_add_ui (num_b1, num_b1, 1);
@@ -176,7 +177,7 @@ generate_key_or_iv(packet_info *pinfo, unsigned int id, tvbuff_t *salt_tvb, unsi
if (rc != 0)
{
- return FALSE;
+ return false;
}
gcry_mpi_add (num_ij, num_ij, num_b1);
@@ -187,7 +188,7 @@ generate_key_or_iv(packet_info *pinfo, unsigned int id, tvbuff_t *salt_tvb, unsi
rc = gcry_mpi_print (GCRYMPI_FMT_USG, buf_i + i, n, &n, num_ij);
if (rc != 0)
{
- return FALSE;
+ return false;
}
gcry_mpi_release (num_ij);
@@ -215,15 +216,15 @@ int PBE_decrypt_data(const char *object_identifier_id_param _U_, tvbuff_t *encry
char *iv = NULL;
char *clear_data = NULL;
tvbuff_t *clear_tvb = NULL;
- const gchar *oidname;
+ const char *oidname;
GString *name;
proto_tree *tree;
char byte;
- gboolean decrypt_ok = TRUE;
+ bool decrypt_ok = true;
- if(((password == NULL) || (*password == '\0')) && (try_null_password == FALSE)) {
+ if(((password == NULL) || (*password == '\0')) && (try_null_password == false)) {
/* we are not configured to decrypt */
- return FALSE;
+ return false;
}
encryption_algorithm = x509af_get_last_algorithm_id();
@@ -248,44 +249,44 @@ int PBE_decrypt_data(const char *object_identifier_id_param _U_, tvbuff_t *encry
/* we don't know how to decrypt this */
proto_item_append_text(item, " [Unsupported encryption algorithm]");
- return FALSE;
+ return false;
}
if((iteration_count == 0) || (salt == NULL)) {
proto_item_append_text(item, " [Insufficient parameters]");
- return FALSE;
+ return false;
}
/* allocate buffers */
key = (char *)wmem_alloc(pinfo->pool, keylen);
if(!generate_key_or_iv(pinfo, 1 /*LEY */, salt, iteration_count, password, keylen, key))
- return FALSE;
+ return false;
if(ivlen) {
iv = (char *)wmem_alloc(pinfo->pool, ivlen);
if(!generate_key_or_iv(pinfo, 2 /* IV */, salt, iteration_count, password, ivlen, iv))
- return FALSE;
+ return false;
}
/* now try an internal function */
err = gcry_cipher_open(&cipher, algo, mode, 0);
if (gcry_err_code (err))
- return FALSE;
+ return false;
err = gcry_cipher_setkey (cipher, key, keylen);
if (gcry_err_code (err)) {
gcry_cipher_close (cipher);
- return FALSE;
+ return false;
}
if(ivlen) {
err = gcry_cipher_setiv (cipher, iv, ivlen);
if (gcry_err_code (err)) {
gcry_cipher_close (cipher);
- return FALSE;
+ return false;
}
}
@@ -298,7 +299,7 @@ int PBE_decrypt_data(const char *object_identifier_id_param _U_, tvbuff_t *encry
proto_item_append_text(item, " [Failed to decrypt with password preference]");
gcry_cipher_close (cipher);
- return FALSE;
+ return false;
}
gcry_cipher_close (cipher);
@@ -315,7 +316,7 @@ int PBE_decrypt_data(const char *object_identifier_id_param _U_, tvbuff_t *encry
for(i = (int)byte; i > 0 ; i--) {
if(clear_data[datalen - i] != byte) {
- decrypt_ok = FALSE;
+ decrypt_ok = false;
break;
}
}
@@ -326,13 +327,13 @@ int PBE_decrypt_data(const char *object_identifier_id_param _U_, tvbuff_t *encry
/* we assume the result is ASN.1 - check it is a SET or SEQUENCE */
byte = clear_data[0];
if((byte != 0x30) && (byte != 0x31)) { /* do we need more here? OCTET STRING? */
- decrypt_ok = FALSE;
+ decrypt_ok = false;
}
if(!decrypt_ok) {
proto_item_append_text(item, " [Failed to decrypt with supplied password]");
- return FALSE;
+ return false;
}
proto_item_append_text(item, " [Decrypted successfully]");
@@ -341,7 +342,7 @@ int PBE_decrypt_data(const char *object_identifier_id_param _U_, tvbuff_t *encry
/* OK - so now clear_data contains the decrypted data */
- clear_tvb = tvb_new_child_real_data(encrypted_tvb,(const guint8 *)clear_data, datalen, datalen);
+ clear_tvb = tvb_new_child_real_data(encrypted_tvb,(const uint8_t *)clear_data, datalen, datalen);
name = g_string_new("");
oidname = oid_resolved_from_string(pinfo->pool, object_identifier_id_param);
@@ -355,17 +356,17 @@ int PBE_decrypt_data(const char *object_identifier_id_param _U_, tvbuff_t *encry
/* now try and decode it */
call_ber_oid_callback(object_identifier_id_param, clear_tvb, 0, actx->pinfo, tree, NULL);
- return TRUE;
+ return true;
}
#include "packet-pkcs12-fn.c"
static int strip_octet_string(tvbuff_t *tvb)
{
- gint8 ber_class;
+ int8_t ber_class;
bool pc, ind;
- gint32 tag;
- guint32 len;
+ int32_t tag;
+ uint32_t len;
int offset = 0;
/* PKCS#7 encodes the content as OCTET STRING, whereas CMS is just any ANY */
@@ -385,10 +386,10 @@ static int strip_octet_string(tvbuff_t *tvb)
static int dissect_AuthenticatedSafe_OCTETSTRING_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) {
int offset = 0;
asn1_ctx_t asn1_ctx;
- asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
+ asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, true, pinfo);
if((offset = strip_octet_string(tvb)) > 0)
- dissect_pkcs12_AuthenticatedSafe(FALSE, tvb, offset, &asn1_ctx, tree, hf_pkcs12_AuthenticatedSafe_PDU);
+ dissect_pkcs12_AuthenticatedSafe(false, tvb, offset, &asn1_ctx, tree, hf_pkcs12_AuthenticatedSafe_PDU);
else
proto_tree_add_expert(tree, pinfo, &ei_pkcs12_octet_string_expected, tvb, 0, 1);
return tvb_captured_length(tvb);
@@ -398,11 +399,11 @@ static int dissect_SafeContents_OCTETSTRING_PDU(tvbuff_t *tvb, packet_info *pinf
{
int offset = 0;
asn1_ctx_t asn1_ctx;
- asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
+ 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);
+ dissect_pkcs12_SafeContents(false, tvb, offset, &asn1_ctx, tree, hf_pkcs12_SafeContents_PDU);
return tvb_captured_length(tvb);
}
@@ -410,10 +411,10 @@ static int dissect_X509Certificate_OCTETSTRING_PDU(tvbuff_t *tvb, packet_info *p
{
int offset = 0;
asn1_ctx_t asn1_ctx;
- asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
+ asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, true, pinfo);
if((offset = strip_octet_string(tvb)) > 0)
- dissect_x509af_Certificate(FALSE, tvb, offset, &asn1_ctx, tree, hf_pkcs12_X509Certificate_PDU);
+ dissect_x509af_Certificate(false, tvb, offset, &asn1_ctx, tree, hf_pkcs12_X509Certificate_PDU);
else
proto_tree_add_expert(tree, pinfo, &ei_pkcs12_octet_string_expected, tvb, 0, 1);
@@ -438,7 +439,7 @@ void proto_register_pkcs12(void) {
};
/* List of subtrees */
- static gint *ett[] = {
+ static int *ett[] = {
&ett_decrypted_pbe,
#include "packet-pkcs12-ettarr.c"
};