Remove some unneeded includes of <sys/time.h>.
[metze/wireshark/wip.git] / epan / dissectors / packet-pkcs12.c
index 8d537ffede6e8f319c277ac50c5eae6771828b57..f9422abfaf21057fcb7b512ee14069c2db943c3f 100644 (file)
@@ -1,16 +1,18 @@
-/* Do not modify this file.                                                   */
-/* It is created automatically by the ASN.1 to Wireshark dissector compiler   */
+/* Do not modify this file. Changes will be overwritten.                      */
+/* Generated automatically by the ASN.1 to Wireshark dissector compiler       */
 /* packet-pkcs12.c                                                            */
-/* ../../tools/asn2wrs.py -b -e -p pkcs12 -c pkcs12.cnf -s packet-pkcs12-template pkcs12.asn */
+/* ../../tools/asn2wrs.py -b -p pkcs12 -c ./pkcs12.cnf -s ./packet-pkcs12-template -D . -O ../../epan/dissectors pkcs12.asn */
 
 /* Input file: packet-pkcs12-template.c */
 
-#line 1 "packet-pkcs12-template.c"
+#line 1 "../../asn1/pkcs12/packet-pkcs12-template.c"
 /* packet-pkcs12.c
  * Routines for PKCS#12: Personal Information Exchange packet dissection
  * Graeme Lunt 2006
  *
- * $Id$
+ * See "PKCS #12 v1.1: Personal Information Exchange Syntax":
+ *
+ *    http://www.emc.com/emc-plus/rsa-labs/pkcs/files/h11301-wp-pkcs-12v1-1-personal-information-exchange-syntax.pdf
  *
  * Wireshark - Network traffic analyzer
  * By Gerald Combs <gerald@wireshark.org>
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include "config.h"
 
-#include <glib.h>
 #include <epan/packet.h>
-#include <epan/conversation.h>
+#include <epan/expert.h>
 #include <epan/oids.h>
 #include <epan/asn1.h>
 #include <epan/prefs.h>
 
-#include <stdio.h>
-#include <string.h>
-
 #include "packet-ber.h"
 #include "packet-pkcs12.h"
 #include "packet-x509af.h"
 #include "packet-x509if.h"
 #include "packet-cms.h"
 
-#ifndef _WIN32  
-#include <sys/types.h>
-#include <sys/time.h>
-#endif
-
 #ifdef HAVE_LIBGCRYPT
-#ifdef _WIN32  
-#include <winposixtype.h>
+#include <wsutil/wsgcrypt.h>
 #endif
-#include "gcrypt.h"
-#endif 
 
 #define PNAME  "PKCS#12: Personal Information Exchange"
 #define PSNAME "PKCS12"
 #define PKCS12_PBE_3DES_SHA1_OID       "1.2.840.113549.1.12.1.3"
 #define PKCS12_PBE_RC2_40_SHA1_OID     "1.2.840.113549.1.12.1.6"
 
+void proto_register_pkcs12(void);
+void proto_reg_handoff_pkcs12(void);
+
 /* Initialize the protocol and registered fields */
-int proto_pkcs12 = -1;
+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 expert_field ei_pkcs12_octet_string_expected = EI_INIT;
+
+
+static const char *object_identifier_id = NULL;
 static int iteration_count = 0;
 static tvbuff_t *salt = NULL;
 static const char *password = NULL;
@@ -85,11 +79,11 @@ static gboolean try_null_password = FALSE;
 
 static void dissect_AuthenticatedSafe_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);
-static void dissect_PrivateKeyInfo_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
+static int dissect_PrivateKeyInfo_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data);
 
 
 /*--- Included file: packet-pkcs12-hf.c ---*/
-#line 1 "packet-pkcs12-hf.c"
+#line 1 "../../asn1/pkcs12/packet-pkcs12-hf.c"
 static int hf_pkcs12_PFX_PDU = -1;                /* PFX */
 static int hf_pkcs12_AuthenticatedSafe_PDU = -1;  /* AuthenticatedSafe */
 static int hf_pkcs12_SafeContents_PDU = -1;       /* SafeContents */
@@ -146,12 +140,12 @@ static int hf_pkcs12_encryptionScheme = -1;       /* AlgorithmIdentifier */
 static int hf_pkcs12_messageAuthScheme = -1;      /* AlgorithmIdentifier */
 
 /*--- End of included file: packet-pkcs12-hf.c ---*/
-#line 83 "packet-pkcs12-template.c"
+#line 77 "../../asn1/pkcs12/packet-pkcs12-template.c"
 
 /* Initialize the subtree pointers */
 
 /*--- Included file: packet-pkcs12-ett.c ---*/
-#line 1 "packet-pkcs12-ett.c"
+#line 1 "../../asn1/pkcs12/packet-pkcs12-ett.c"
 static gint ett_pkcs12_PFX = -1;
 static gint ett_pkcs12_MacData = -1;
 static gint ett_pkcs12_DigestInfo = -1;
@@ -174,19 +168,19 @@ static gint ett_pkcs12_PBES2Params = -1;
 static gint ett_pkcs12_PBMAC1Params = -1;
 
 /*--- End of included file: packet-pkcs12-ett.c ---*/
-#line 86 "packet-pkcs12-template.c"
+#line 80 "../../asn1/pkcs12/packet-pkcs12-template.c"
 
 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); 
+       name = oid_resolved_from_string(wmem_packet_scope(), oid);
+       proto_item_append_text(tree, " (%s)", name ? name : oid);
 }
 
 #ifdef HAVE_LIBGCRYPT
 
-int
+static int
 generate_key_or_iv(unsigned int id, tvbuff_t *salt_tvb, unsigned int iter,
                       const char *pw, unsigned int req_keylen, char * keybuf)
 {
@@ -194,9 +188,9 @@ 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;
+  char *salt_p;
   int salt_size;
   size_t cur_keylen;
   size_t n;
@@ -204,8 +198,8 @@ generate_key_or_iv(unsigned int id, tvbuff_t *salt_tvb, unsigned int iter,
 
   cur_keylen = 0;
 
-  salt_size = tvb_length(salt_tvb);
-  salt = tvb_get_ephemeral_string(salt_tvb, 0, salt_size);
+  salt_size = tvb_captured_length(salt_tvb);
+  salt_p = (char *)tvb_memdup(wmem_packet_scope(), salt_tvb, 0, salt_size);
 
   if (pw == NULL)
     pwlen = 0;
@@ -220,7 +214,7 @@ generate_key_or_iv(unsigned int id, tvbuff_t *salt_tvb, unsigned int iter,
   /* Store salt and password in BUF_I */
   p = buf_i;
   for (i = 0; i < 64; i++)
-    *p++ = salt[i % salt_size];
+    *p++ = salt_p[i % salt_size];
   if (pw)
     {
       for (i = j = 0; i < 64; i += 2)
@@ -234,82 +228,89 @@ generate_key_or_iv(unsigned int id, tvbuff_t *salt_tvb, unsigned int iter,
   else
     memset (p, 0, 64);
 
-  for (;;){
+  for (;;) {
       err = gcry_md_open(&md, GCRY_MD_SHA1, 0);
-      if (gcry_err_code(err)) {
-                 return FALSE;
-         }
-      for (i = 0; i < 64; i++) {
-                 unsigned char lid = id & 0xFF;
-                 gcry_md_write (md, &lid, 1);
-         }
-      
-         gcry_md_write(md, buf_i, pw ? 128 : 64);
+      if (gcry_err_code(err))
+        {
+          return FALSE;
+        }
+      for (i = 0; i < 64; i++)
+        {
+          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);
+
+      gcry_md_close (md);
+
+      for (i = 1; i < iter; i++)
+        gcry_md_hash_buffer (GCRY_MD_SHA1, hash, hash, 20);
 
       for (i = 0; i < 20 && cur_keylen < req_keylen; i++)
-                 keybuf[cur_keylen++] = hash[i];
+        keybuf[cur_keylen++] = hash[i];
 
-         if (cur_keylen == req_keylen) {
-                 gcry_mpi_release (num_b1);
-                 return TRUE;          /* ready */
-         }
+      if (cur_keylen == req_keylen)
+      {
+        gcry_mpi_release (num_b1);
+        return TRUE;           /* ready */
+      }
 
       /* need more bytes. */
       for (i = 0; i < 64; i++)
-                 buf_b[i] = hash[i % 20];
+        buf_b[i] = hash[i % 20];
 
-         n = 64;
+      n = 64;
 
-         rc = gcry_mpi_scan (&num_b1, GCRYMPI_FMT_USG, buf_b, n, &n);
+      rc = gcry_mpi_scan (&num_b1, GCRYMPI_FMT_USG, buf_b, n, &n);
 
-         if (rc != 0) {
-                 return FALSE;
-         }
+      if (rc != 0)
+        {
+          return FALSE;
+        }
 
-         gcry_mpi_add_ui (num_b1, num_b1, 1);
+      gcry_mpi_add_ui (num_b1, num_b1, 1);
 
-         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);
+      for (i = 0; i < 128; i += 64)
+        {
+          gcry_mpi_t num_ij;
 
-                 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);
-                 if (rc != 0){
-                         return FALSE;
-                 }
+          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);
+          if (rc != 0)
+            {
+              return FALSE;
+            }
 
-                 gcry_mpi_release (num_ij);
-         }
+          gcry_mpi_release (num_ij);
+        }
   }
 }
 
-#endif 
+#endif
 
-void PBE_reset_parameters()
+void PBE_reset_parameters(void)
 {
        iteration_count = 0;
        salt = NULL;
 }
 
-int PBE_decrypt_data(const char *object_identifier_id _U_, tvbuff_t *encrypted_tvb _U_, asn1_ctx_t *actx _U_, proto_item *item _U_)
+int PBE_decrypt_data(const char *object_identifier_id_param, tvbuff_t *encrypted_tvb, asn1_ctx_t *actx, proto_item *item)
 {
 #ifdef HAVE_LIBGCRYPT
        const char      *encryption_algorithm;
@@ -329,7 +330,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;
@@ -355,26 +356,26 @@ 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;
        }
 
        /* allocate buffers */
-       key = ep_alloc(keylen);
+       key = (char *)wmem_alloc(wmem_packet_scope(), keylen);
 
        if(!generate_key_or_iv(1 /*LEY */, salt, iteration_count, password, keylen, key))
                return FALSE;
 
        if(ivlen) {
-               
-               iv = ep_alloc(ivlen);
-               
+
+               iv = (char *)wmem_alloc(wmem_packet_scope(), ivlen);
+
                if(!generate_key_or_iv(2 /* IV */, salt, iteration_count, password, ivlen, iv))
                        return FALSE;
        }
@@ -384,24 +385,24 @@ 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;
                  }
        }
 
-       datalen = tvb_length(encrypted_tvb);
-       clear_data = g_malloc(datalen);
+       datalen = tvb_captured_length(encrypted_tvb);
+       clear_data = (char *)g_malloc(datalen);
 
-       err = gcry_cipher_decrypt (cipher, clear_data, datalen, tvb_get_ephemeral_string(encrypted_tvb, 0, datalen), datalen);
+       err = gcry_cipher_decrypt (cipher, clear_data, datalen, (char *)tvb_memdup(wmem_packet_scope(), encrypted_tvb, 0, datalen), datalen);
        if (gcry_err_code (err)) {
 
                proto_item_append_text(item, " [Failed to decrypt with password preference]");
@@ -414,7 +415,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?
                */
 
@@ -429,7 +430,7 @@ int PBE_decrypt_data(const char *object_identifier_id _U_, tvbuff_t *encrypted_t
                                break;
                        }
                }
-       } else {        
+       } else {
                /* XXX: is this a failure? */
        }
 
@@ -452,22 +453,22 @@ int PBE_decrypt_data(const char *object_identifier_id _U_, tvbuff_t *encrypted_t
 
        /* OK - so now clear_data contains the decrypted data */
 
-       clear_tvb = tvb_new_real_data((const guint8 *)clear_data, datalen, datalen);
+       clear_tvb = tvb_new_child_real_data(encrypted_tvb,(const guint8 *)clear_data, datalen, datalen);
        tvb_set_free_cb(clear_tvb, g_free);
 
        name = g_string_new("");
-       oidname = oid_resolved_from_string(object_identifier_id);
-       g_string_printf(name, "Decrypted %s", oidname ? oidname : object_identifier_id);
+       oidname = oid_resolved_from_string(wmem_packet_scope(), object_identifier_id_param);
+       g_string_printf(name, "Decrypted %s", oidname ? oidname : object_identifier_id_param);
 
        /* 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);
+       call_ber_oid_callback(object_identifier_id_param, clear_tvb, 0, actx->pinfo, tree, NULL);
 
-       return TRUE;            
+       return TRUE;
 #else
        /* we cannot decrypt */
        return FALSE;
@@ -477,7 +478,7 @@ int PBE_decrypt_data(const char *object_identifier_id _U_, tvbuff_t *encrypted_t
 
 
 /*--- Included file: packet-pkcs12-fn.c ---*/
-#line 1 "packet-pkcs12-fn.c"
+#line 1 "../../asn1/pkcs12/packet-pkcs12-fn.c"
 
 static const value_string pkcs12_T_version_vals[] = {
   {   3, "v3" },
@@ -554,7 +555,7 @@ static const ber_sequence_t PFX_sequence[] = {
 
 static int
 dissect_pkcs12_PFX(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
-#line 60 "pkcs12.cnf"
+#line 58 "../../asn1/pkcs12/pkcs12.cnf"
        dissector_handle_t dissector_handle;
 
        /* we change the CMS id-data dissector to dissect as AuthenticatedSafe
@@ -581,7 +582,7 @@ static const ber_sequence_t AuthenticatedSafe_sequence_of[1] = {
 
 static int
 dissect_pkcs12_AuthenticatedSafe(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
-#line 73 "pkcs12.cnf"
+#line 71 "../../asn1/pkcs12/pkcs12.cnf"
        dissector_handle_t dissector_handle;
 
        /* we change the CMS id-data dissector to dissect as SafeContents */
@@ -606,7 +607,7 @@ static int
 dissect_pkcs12_T_bagId(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
   offset = dissect_ber_object_identifier_str(implicit_tag, actx, tree, tvb, offset, hf_index, &object_identifier_id);
 
-#line 86 "pkcs12.cnf"
+#line 84 "../../asn1/pkcs12/pkcs12.cnf"
   append_oid(tree, object_identifier_id);
 
   return offset;
@@ -616,9 +617,9 @@ dissect_pkcs12_T_bagId(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset
 
 static int
 dissect_pkcs12_T_bagValue(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
-#line 110 "pkcs12.cnf"
+#line 108 "../../asn1/pkcs12/pkcs12.cnf"
        if(object_identifier_id)
-               offset = call_ber_oid_callback(object_identifier_id, tvb, offset, actx->pinfo, tree);
+               offset = call_ber_oid_callback(object_identifier_id, tvb, offset, actx->pinfo, tree, NULL);
 
 
 
@@ -631,7 +632,7 @@ static int
 dissect_pkcs12_T_attrId(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
   offset = dissect_ber_object_identifier_str(implicit_tag, actx, tree, tvb, offset, hf_index, &object_identifier_id);
 
-#line 106 "pkcs12.cnf"
+#line 104 "../../asn1/pkcs12/pkcs12.cnf"
   append_oid(tree, object_identifier_id);
 
   return offset;
@@ -641,9 +642,9 @@ dissect_pkcs12_T_attrId(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset
 
 static int
 dissect_pkcs12_T_attrValues_item(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
-#line 114 "pkcs12.cnf"
+#line 112 "../../asn1/pkcs12/pkcs12.cnf"
        if(object_identifier_id)
-               offset = call_ber_oid_callback(object_identifier_id, tvb, offset, actx->pinfo, tree);
+               offset = call_ber_oid_callback(object_identifier_id, tvb, offset, actx->pinfo, tree, NULL);
 
 
 
@@ -788,26 +789,26 @@ dissect_pkcs12_KeyBag(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _
 
 static int
 dissect_pkcs12_EncryptedData(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
-#line 141 "pkcs12.cnf"
+#line 139 "../../asn1/pkcs12/pkcs12.cnf"
        tvbuff_t *encrypted_tvb;
        dissector_handle_t dissector_handle;
-       
+
 
   offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
                                        &encrypted_tvb);
 
-#line 147 "pkcs12.cnf"
+#line 145 "../../asn1/pkcs12/pkcs12.cnf"
+
 
-       
 
-       dissector_handle=create_dissector_handle(dissect_PrivateKeyInfo_PDU, proto_pkcs12);
-       dissector_change_string("ber.oid", (gchar*) object_identifier_id, dissector_handle);
-       
+       dissector_handle=new_create_dissector_handle(dissect_PrivateKeyInfo_PDU, proto_pkcs12);
+       dissector_change_string("ber.oid", object_identifier_id, dissector_handle);
+
        PBE_decrypt_data(object_identifier_id, encrypted_tvb, actx, actx->created_item);
-       
+
        /* restore the original dissector */
        dissector_reset_string("ber.oid", object_identifier_id);
-       
+
 
   return offset;
 }
@@ -842,7 +843,7 @@ static int
 dissect_pkcs12_T_certId(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
   offset = dissect_ber_object_identifier_str(implicit_tag, actx, tree, tvb, offset, hf_index, &object_identifier_id);
 
-#line 91 "pkcs12.cnf"
+#line 89 "../../asn1/pkcs12/pkcs12.cnf"
   append_oid(tree, object_identifier_id);
 
   return offset;
@@ -852,9 +853,9 @@ dissect_pkcs12_T_certId(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset
 
 static int
 dissect_pkcs12_T_certValue(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
-#line 118 "pkcs12.cnf"
+#line 116 "../../asn1/pkcs12/pkcs12.cnf"
        if(object_identifier_id)
-               offset = call_ber_oid_callback(object_identifier_id, tvb, offset, actx->pinfo, tree);
+               offset = call_ber_oid_callback(object_identifier_id, tvb, offset, actx->pinfo, tree, NULL);
 
 
 
@@ -882,7 +883,7 @@ static int
 dissect_pkcs12_T_crlId(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
   offset = dissect_ber_object_identifier_str(implicit_tag, actx, tree, tvb, offset, hf_index, &object_identifier_id);
 
-#line 96 "pkcs12.cnf"
+#line 94 "../../asn1/pkcs12/pkcs12.cnf"
   append_oid(tree, object_identifier_id);
 
   return offset;
@@ -892,9 +893,9 @@ dissect_pkcs12_T_crlId(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset
 
 static int
 dissect_pkcs12_T_crlValue(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
-#line 122 "pkcs12.cnf"
+#line 120 "../../asn1/pkcs12/pkcs12.cnf"
        if(object_identifier_id)
-               offset = call_ber_oid_callback(object_identifier_id, tvb, offset, actx->pinfo, tree);
+               offset = call_ber_oid_callback(object_identifier_id, tvb, offset, actx->pinfo, tree, NULL);
 
 
 
@@ -922,7 +923,7 @@ static int
 dissect_pkcs12_T_secretTypeId(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
   offset = dissect_ber_object_identifier_str(implicit_tag, actx, tree, tvb, offset, hf_index, &object_identifier_id);
 
-#line 101 "pkcs12.cnf"
+#line 99 "../../asn1/pkcs12/pkcs12.cnf"
   append_oid(tree, object_identifier_id);
 
   return offset;
@@ -932,10 +933,10 @@ dissect_pkcs12_T_secretTypeId(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int
 
 static int
 dissect_pkcs12_T_secretValue(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
-#line 126 "pkcs12.cnf"
+#line 124 "../../asn1/pkcs12/pkcs12.cnf"
        if(object_identifier_id)
-               offset = call_ber_oid_callback(object_identifier_id, tvb, offset, actx->pinfo, tree);
-               
+               offset = call_ber_oid_callback(object_identifier_id, tvb, offset, actx->pinfo, tree, NULL);
+
 
 
   return offset;
@@ -965,7 +966,7 @@ static const ber_sequence_t PBEParameter_sequence[] = {
 
 static int
 dissect_pkcs12_PBEParameter(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
-#line 130 "pkcs12.cnf"
+#line 128 "../../asn1/pkcs12/pkcs12.cnf"
        /* initialise the encryption parameters */
        PBE_reset_parameters();
 
@@ -1057,84 +1058,112 @@ dissect_pkcs12_PBMAC1Params(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int of
 
 /*--- PDUs ---*/
 
-static void dissect_PFX_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
+static int dissect_PFX_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
+  int offset = 0;
   asn1_ctx_t asn1_ctx;
   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
-  dissect_pkcs12_PFX(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_PFX_PDU);
+  offset = dissect_pkcs12_PFX(FALSE, tvb, offset, &asn1_ctx, tree, hf_pkcs12_PFX_PDU);
+  return offset;
 }
-static void dissect_AuthenticatedSafe_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
+static int dissect_AuthenticatedSafe_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
+  int offset = 0;
   asn1_ctx_t asn1_ctx;
   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
-  dissect_pkcs12_AuthenticatedSafe(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_AuthenticatedSafe_PDU);
+  offset = dissect_pkcs12_AuthenticatedSafe(FALSE, tvb, offset, &asn1_ctx, tree, hf_pkcs12_AuthenticatedSafe_PDU);
+  return offset;
 }
-static void dissect_SafeContents_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
+static int dissect_SafeContents_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
+  int offset = 0;
   asn1_ctx_t asn1_ctx;
   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
-  dissect_pkcs12_SafeContents(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_SafeContents_PDU);
+  offset = dissect_pkcs12_SafeContents(FALSE, tvb, offset, &asn1_ctx, tree, hf_pkcs12_SafeContents_PDU);
+  return offset;
 }
-static void dissect_KeyBag_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
+static int dissect_KeyBag_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
+  int offset = 0;
   asn1_ctx_t asn1_ctx;
   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
-  dissect_pkcs12_KeyBag(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_KeyBag_PDU);
+  offset = dissect_pkcs12_KeyBag(FALSE, tvb, offset, &asn1_ctx, tree, hf_pkcs12_KeyBag_PDU);
+  return offset;
 }
-static void dissect_PKCS8ShroudedKeyBag_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
+static int dissect_PKCS8ShroudedKeyBag_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
+  int offset = 0;
   asn1_ctx_t asn1_ctx;
   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
-  dissect_pkcs12_PKCS8ShroudedKeyBag(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_PKCS8ShroudedKeyBag_PDU);
+  offset = dissect_pkcs12_PKCS8ShroudedKeyBag(FALSE, tvb, offset, &asn1_ctx, tree, hf_pkcs12_PKCS8ShroudedKeyBag_PDU);
+  return offset;
 }
-static void dissect_CertBag_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
+static int dissect_CertBag_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
+  int offset = 0;
   asn1_ctx_t asn1_ctx;
   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
-  dissect_pkcs12_CertBag(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_CertBag_PDU);
+  offset = dissect_pkcs12_CertBag(FALSE, tvb, offset, &asn1_ctx, tree, hf_pkcs12_CertBag_PDU);
+  return offset;
 }
-static void dissect_CRLBag_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
+static int dissect_CRLBag_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
+  int offset = 0;
   asn1_ctx_t asn1_ctx;
   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
-  dissect_pkcs12_CRLBag(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_CRLBag_PDU);
+  offset = dissect_pkcs12_CRLBag(FALSE, tvb, offset, &asn1_ctx, tree, hf_pkcs12_CRLBag_PDU);
+  return offset;
 }
-static void dissect_SecretBag_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
+static int dissect_SecretBag_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
+  int offset = 0;
   asn1_ctx_t asn1_ctx;
   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
-  dissect_pkcs12_SecretBag(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_SecretBag_PDU);
+  offset = dissect_pkcs12_SecretBag(FALSE, tvb, offset, &asn1_ctx, tree, hf_pkcs12_SecretBag_PDU);
+  return offset;
 }
-static void dissect_PrivateKeyInfo_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
+static int dissect_PrivateKeyInfo_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
+  int offset = 0;
   asn1_ctx_t asn1_ctx;
   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
-  dissect_pkcs12_PrivateKeyInfo(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_PrivateKeyInfo_PDU);
+  offset = dissect_pkcs12_PrivateKeyInfo(FALSE, tvb, offset, &asn1_ctx, tree, hf_pkcs12_PrivateKeyInfo_PDU);
+  return offset;
 }
-static void dissect_EncryptedPrivateKeyInfo_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
+static int dissect_EncryptedPrivateKeyInfo_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
+  int offset = 0;
   asn1_ctx_t asn1_ctx;
   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
-  dissect_pkcs12_EncryptedPrivateKeyInfo(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_EncryptedPrivateKeyInfo_PDU);
+  offset = dissect_pkcs12_EncryptedPrivateKeyInfo(FALSE, tvb, offset, &asn1_ctx, tree, hf_pkcs12_EncryptedPrivateKeyInfo_PDU);
+  return offset;
 }
-static void dissect_PBEParameter_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
+static int dissect_PBEParameter_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
+  int offset = 0;
   asn1_ctx_t asn1_ctx;
   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
-  dissect_pkcs12_PBEParameter(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_PBEParameter_PDU);
+  offset = dissect_pkcs12_PBEParameter(FALSE, tvb, offset, &asn1_ctx, tree, hf_pkcs12_PBEParameter_PDU);
+  return offset;
 }
-static void dissect_PBKDF2Params_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
+static int dissect_PBKDF2Params_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
+  int offset = 0;
   asn1_ctx_t asn1_ctx;
   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
-  dissect_pkcs12_PBKDF2Params(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_PBKDF2Params_PDU);
+  offset = dissect_pkcs12_PBKDF2Params(FALSE, tvb, offset, &asn1_ctx, tree, hf_pkcs12_PBKDF2Params_PDU);
+  return offset;
 }
-static void dissect_PBES2Params_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
+static int dissect_PBES2Params_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
+  int offset = 0;
   asn1_ctx_t asn1_ctx;
   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
-  dissect_pkcs12_PBES2Params(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_PBES2Params_PDU);
+  offset = dissect_pkcs12_PBES2Params(FALSE, tvb, offset, &asn1_ctx, tree, hf_pkcs12_PBES2Params_PDU);
+  return offset;
 }
-static void dissect_PBMAC1Params_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
+static int dissect_PBMAC1Params_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
+  int offset = 0;
   asn1_ctx_t asn1_ctx;
   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
-  dissect_pkcs12_PBMAC1Params(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_PBMAC1Params_PDU);
+  offset = dissect_pkcs12_PBMAC1Params(FALSE, tvb, offset, &asn1_ctx, tree, hf_pkcs12_PBMAC1Params_PDU);
+  return offset;
 }
 
 
 /*--- End of included file: packet-pkcs12-fn.c ---*/
-#line 387 "packet-pkcs12-template.c"
+#line 388 "../../asn1/pkcs12/packet-pkcs12-template.c"
 
-static int strip_octet_string(tvbuff_t *tvb) 
+static int strip_octet_string(tvbuff_t *tvb)
 {
-  gint8 class;
+  gint8 ber_class;
   gboolean pc, ind;
   gint32 tag;
   guint32 len;
@@ -1144,10 +1173,10 @@ static int strip_octet_string(tvbuff_t *tvb)
   /* if we use CMS (rather than PKCS#7) - which we are - we need to strip the OCTET STRING tag */
   /* before proceeding */
 
-  offset = get_ber_identifier(tvb, 0, &class, &pc, &tag);
+  offset = get_ber_identifier(tvb, 0, &ber_class, &pc, &tag);
   offset = get_ber_length(tvb, offset, &len, &ind);
 
-  if((class == BER_CLASS_UNI) && (tag == BER_UNI_TAG_OCTETSTRING))
+  if((ber_class == BER_CLASS_UNI) && (tag == BER_UNI_TAG_OCTETSTRING))
     return offset;
 
   return 0;
@@ -1162,21 +1191,21 @@ static void dissect_AuthenticatedSafe_OCTETSTRING_PDU(tvbuff_t *tvb, packet_info
   if((offset = strip_octet_string(tvb)) > 0)
     dissect_pkcs12_AuthenticatedSafe(FALSE, tvb, offset, &asn1_ctx, tree, hf_pkcs12_AuthenticatedSafe_PDU);
   else
-       proto_tree_add_text(tree, tvb, 0, 1, "BER Error: OCTET STRING expected");
+    proto_tree_add_expert(tree, pinfo, &ei_pkcs12_octet_string_expected, tvb, 0, 1);
 }
 
-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;
@@ -1185,7 +1214,7 @@ static void dissect_X509Certificate_OCTETSTRING_PDU(tvbuff_t *tvb, packet_info *
   if((offset = strip_octet_string(tvb)) > 0)
        dissect_x509af_Certificate(FALSE, tvb, offset, &asn1_ctx, tree, hf_pkcs12_X509Certificate_PDU);
   else
-       proto_tree_add_text(tree, tvb, 0, 1, "BER Error: OCTET STRING expected");
+       proto_tree_add_expert(tree, pinfo, &ei_pkcs12_octet_string_expected, tvb, 0, 1);
 }
 
 /*--- proto_register_pkcs12 ----------------------------------------------*/
@@ -1193,232 +1222,232 @@ void proto_register_pkcs12(void) {
 
   /* List of fields */
   static hf_register_info hf[] = {
-       { &hf_pkcs12_X509Certificate_PDU,
+    { &hf_pkcs12_X509Certificate_PDU,
       { "X509Certificate", "pkcs12.X509Certificate",
         FT_NONE, BASE_NONE, NULL, 0,
         "pkcs12.X509Certificate", HFILL }},
 
 /*--- Included file: packet-pkcs12-hfarr.c ---*/
-#line 1 "packet-pkcs12-hfarr.c"
+#line 1 "../../asn1/pkcs12/packet-pkcs12-hfarr.c"
     { &hf_pkcs12_PFX_PDU,
-      { "PFX", "pkcs12.PFX",
+      { "PFX", "pkcs12.PFX_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "pkcs12.PFX", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_AuthenticatedSafe_PDU,
       { "AuthenticatedSafe", "pkcs12.AuthenticatedSafe",
         FT_UINT32, BASE_DEC, NULL, 0,
-        "pkcs12.AuthenticatedSafe", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_SafeContents_PDU,
       { "SafeContents", "pkcs12.SafeContents",
         FT_UINT32, BASE_DEC, NULL, 0,
-        "pkcs12.SafeContents", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_KeyBag_PDU,
-      { "KeyBag", "pkcs12.KeyBag",
+      { "KeyBag", "pkcs12.KeyBag_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "pkcs12.KeyBag", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_PKCS8ShroudedKeyBag_PDU,
-      { "PKCS8ShroudedKeyBag", "pkcs12.PKCS8ShroudedKeyBag",
+      { "PKCS8ShroudedKeyBag", "pkcs12.PKCS8ShroudedKeyBag_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "pkcs12.PKCS8ShroudedKeyBag", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_CertBag_PDU,
-      { "CertBag", "pkcs12.CertBag",
+      { "CertBag", "pkcs12.CertBag_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "pkcs12.CertBag", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_CRLBag_PDU,
-      { "CRLBag", "pkcs12.CRLBag",
+      { "CRLBag", "pkcs12.CRLBag_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "pkcs12.CRLBag", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_SecretBag_PDU,
-      { "SecretBag", "pkcs12.SecretBag",
+      { "SecretBag", "pkcs12.SecretBag_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "pkcs12.SecretBag", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_PrivateKeyInfo_PDU,
-      { "PrivateKeyInfo", "pkcs12.PrivateKeyInfo",
+      { "PrivateKeyInfo", "pkcs12.PrivateKeyInfo_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "pkcs12.PrivateKeyInfo", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_EncryptedPrivateKeyInfo_PDU,
-      { "EncryptedPrivateKeyInfo", "pkcs12.EncryptedPrivateKeyInfo",
+      { "EncryptedPrivateKeyInfo", "pkcs12.EncryptedPrivateKeyInfo_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "pkcs12.EncryptedPrivateKeyInfo", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_PBEParameter_PDU,
-      { "PBEParameter", "pkcs12.PBEParameter",
+      { "PBEParameter", "pkcs12.PBEParameter_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "pkcs12.PBEParameter", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_PBKDF2Params_PDU,
-      { "PBKDF2Params", "pkcs12.PBKDF2Params",
+      { "PBKDF2Params", "pkcs12.PBKDF2Params_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "pkcs12.PBKDF2Params", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_PBES2Params_PDU,
-      { "PBES2Params", "pkcs12.PBES2Params",
+      { "PBES2Params", "pkcs12.PBES2Params_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "pkcs12.PBES2Params", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_PBMAC1Params_PDU,
-      { "PBMAC1Params", "pkcs12.PBMAC1Params",
+      { "PBMAC1Params", "pkcs12.PBMAC1Params_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "pkcs12.PBMAC1Params", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_version,
       { "version", "pkcs12.version",
         FT_UINT32, BASE_DEC, VALS(pkcs12_T_version_vals), 0,
-        "pkcs12.T_version", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_authSafe,
-      { "authSafe", "pkcs12.authSafe",
+      { "authSafe", "pkcs12.authSafe_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "cms.ContentInfo", HFILL }},
+        "ContentInfo", HFILL }},
     { &hf_pkcs12_macData,
-      { "macData", "pkcs12.macData",
+      { "macData", "pkcs12.macData_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "pkcs12.MacData", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_mac,
-      { "mac", "pkcs12.mac",
+      { "mac", "pkcs12.mac_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "pkcs12.DigestInfo", HFILL }},
+        "DigestInfo", HFILL }},
     { &hf_pkcs12_macSalt,
       { "macSalt", "pkcs12.macSalt",
-        FT_BYTES, BASE_HEX, NULL, 0,
-        "pkcs12.OCTET_STRING", HFILL }},
+        FT_BYTES, BASE_NONE, NULL, 0,
+        "OCTET_STRING", HFILL }},
     { &hf_pkcs12_iterations,
       { "iterations", "pkcs12.iterations",
         FT_INT32, BASE_DEC, NULL, 0,
-        "pkcs12.INTEGER", HFILL }},
+        "INTEGER", HFILL }},
     { &hf_pkcs12_digestAlgorithm,
-      { "digestAlgorithm", "pkcs12.digestAlgorithm",
+      { "digestAlgorithm", "pkcs12.digestAlgorithm_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "cms.DigestAlgorithmIdentifier", HFILL }},
+        "DigestAlgorithmIdentifier", HFILL }},
     { &hf_pkcs12_digest,
       { "digest", "pkcs12.digest",
-        FT_BYTES, BASE_HEX, NULL, 0,
-        "cms.Digest", HFILL }},
+        FT_BYTES, BASE_NONE, NULL, 0,
+        NULL, HFILL }},
     { &hf_pkcs12_AuthenticatedSafe_item,
-      { "AuthenticatedSafe", "pkcs12.AuthenticatedSafe_item",
+      { "ContentInfo", "pkcs12.ContentInfo_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "cms.ContentInfo", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_SafeContents_item,
-      { "SafeContents", "pkcs12.SafeContents_item",
+      { "SafeBag", "pkcs12.SafeBag_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "pkcs12.SafeBag", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_bagId,
       { "bagId", "pkcs12.bagId",
         FT_OID, BASE_NONE, NULL, 0,
-        "pkcs12.T_bagId", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_bagValue,
-      { "bagValue", "pkcs12.bagValue",
+      { "bagValue", "pkcs12.bagValue_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "pkcs12.T_bagValue", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_bagAttributes,
       { "bagAttributes", "pkcs12.bagAttributes",
         FT_UINT32, BASE_DEC, NULL, 0,
-        "pkcs12.SET_OF_PKCS12Attribute", HFILL }},
+        "SET_OF_PKCS12Attribute", HFILL }},
     { &hf_pkcs12_bagAttributes_item,
-      { "bagAttributes", "pkcs12.bagAttributes_item",
+      { "PKCS12Attribute", "pkcs12.PKCS12Attribute_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "pkcs12.PKCS12Attribute", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_certId,
       { "certId", "pkcs12.certId",
         FT_OID, BASE_NONE, NULL, 0,
-        "pkcs12.T_certId", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_certValue,
-      { "certValue", "pkcs12.certValue",
+      { "certValue", "pkcs12.certValue_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "pkcs12.T_certValue", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_crlId,
       { "crlId", "pkcs12.crlId",
         FT_OID, BASE_NONE, NULL, 0,
-        "pkcs12.T_crlId", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_crlValue,
-      { "crlValue", "pkcs12.crlValue",
+      { "crlValue", "pkcs12.crlValue_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "pkcs12.T_crlValue", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_secretTypeId,
       { "secretTypeId", "pkcs12.secretTypeId",
         FT_OID, BASE_NONE, NULL, 0,
-        "pkcs12.T_secretTypeId", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_secretValue,
-      { "secretValue", "pkcs12.secretValue",
+      { "secretValue", "pkcs12.secretValue_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "pkcs12.T_secretValue", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_attrId,
       { "attrId", "pkcs12.attrId",
         FT_OID, BASE_NONE, NULL, 0,
-        "pkcs12.T_attrId", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_attrValues,
       { "attrValues", "pkcs12.attrValues",
         FT_UINT32, BASE_DEC, NULL, 0,
-        "pkcs12.T_attrValues", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_attrValues_item,
-      { "attrValues", "pkcs12.attrValues_item",
+      { "attrValues item", "pkcs12.attrValues_item_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "pkcs12.T_attrValues_item", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_privateKeyVersion,
       { "version", "pkcs12.version",
-        FT_INT32, BASE_DEC, VALS(x509af_Version_vals), 0,
-        "pkcs12.Version", HFILL }},
+        FT_UINT32, BASE_DEC, VALS(pkcs12_Version_vals), 0,
+        NULL, HFILL }},
     { &hf_pkcs12_privateKeyAlgorithm,
-      { "privateKeyAlgorithm", "pkcs12.privateKeyAlgorithm",
+      { "privateKeyAlgorithm", "pkcs12.privateKeyAlgorithm_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "x509af.AlgorithmIdentifier", HFILL }},
+        "AlgorithmIdentifier", HFILL }},
     { &hf_pkcs12_privateKey,
       { "privateKey", "pkcs12.privateKey",
-        FT_BYTES, BASE_HEX, NULL, 0,
-        "pkcs12.PrivateKey", HFILL }},
+        FT_BYTES, BASE_NONE, NULL, 0,
+        NULL, HFILL }},
     { &hf_pkcs12_attributes,
       { "attributes", "pkcs12.attributes",
         FT_UINT32, BASE_DEC, NULL, 0,
-        "pkcs12.Attributes", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_Attributes_item,
-      { "Attributes", "pkcs12.Attributes_item",
+      { "Attribute", "pkcs12.Attribute_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "x509if.Attribute", HFILL }},
+        NULL, HFILL }},
     { &hf_pkcs12_encryptionAlgorithm,
-      { "encryptionAlgorithm", "pkcs12.encryptionAlgorithm",
+      { "encryptionAlgorithm", "pkcs12.encryptionAlgorithm_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "x509af.AlgorithmIdentifier", HFILL }},
+        "AlgorithmIdentifier", HFILL }},
     { &hf_pkcs12_encryptedData,
       { "encryptedData", "pkcs12.encryptedData",
-        FT_BYTES, BASE_HEX, NULL, 0,
-        "pkcs12.EncryptedData", HFILL }},
+        FT_BYTES, BASE_NONE, NULL, 0,
+        NULL, HFILL }},
     { &hf_pkcs12_salt,
       { "salt", "pkcs12.salt",
-        FT_BYTES, BASE_HEX, NULL, 0,
-        "pkcs12.OCTET_STRING", HFILL }},
+        FT_BYTES, BASE_NONE, NULL, 0,
+        "OCTET_STRING", HFILL }},
     { &hf_pkcs12_iterationCount,
       { "iterationCount", "pkcs12.iterationCount",
         FT_INT32, BASE_DEC, NULL, 0,
-        "pkcs12.INTEGER", HFILL }},
+        "INTEGER", HFILL }},
     { &hf_pkcs12_saltChoice,
       { "salt", "pkcs12.salt",
         FT_UINT32, BASE_DEC, VALS(pkcs12_T_saltChoice_vals), 0,
-        "pkcs12.T_saltChoice", HFILL }},
+        "T_saltChoice", HFILL }},
     { &hf_pkcs12_specified,
       { "specified", "pkcs12.specified",
-        FT_BYTES, BASE_HEX, NULL, 0,
-        "pkcs12.OCTET_STRING", HFILL }},
+        FT_BYTES, BASE_NONE, NULL, 0,
+        "OCTET_STRING", HFILL }},
     { &hf_pkcs12_otherSource,
-      { "otherSource", "pkcs12.otherSource",
+      { "otherSource", "pkcs12.otherSource_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "x509af.AlgorithmIdentifier", HFILL }},
+        "AlgorithmIdentifier", HFILL }},
     { &hf_pkcs12_keyLength,
       { "keyLength", "pkcs12.keyLength",
         FT_UINT32, BASE_DEC, NULL, 0,
-        "pkcs12.INTEGER_1_MAX", HFILL }},
+        "INTEGER_1_MAX", HFILL }},
     { &hf_pkcs12_prf,
-      { "prf", "pkcs12.prf",
+      { "prf", "pkcs12.prf_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "x509af.AlgorithmIdentifier", HFILL }},
+        "AlgorithmIdentifier", HFILL }},
     { &hf_pkcs12_keyDerivationFunc,
-      { "keyDerivationFunc", "pkcs12.keyDerivationFunc",
+      { "keyDerivationFunc", "pkcs12.keyDerivationFunc_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "x509af.AlgorithmIdentifier", HFILL }},
+        "AlgorithmIdentifier", HFILL }},
     { &hf_pkcs12_encryptionScheme,
-      { "encryptionScheme", "pkcs12.encryptionScheme",
+      { "encryptionScheme", "pkcs12.encryptionScheme_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "x509af.AlgorithmIdentifier", HFILL }},
+        "AlgorithmIdentifier", HFILL }},
     { &hf_pkcs12_messageAuthScheme,
-      { "messageAuthScheme", "pkcs12.messageAuthScheme",
+      { "messageAuthScheme", "pkcs12.messageAuthScheme_element",
         FT_NONE, BASE_NONE, NULL, 0,
-        "x509af.AlgorithmIdentifier", HFILL }},
+        "AlgorithmIdentifier", HFILL }},
 
 /*--- End of included file: packet-pkcs12-hfarr.c ---*/
-#line 454 "packet-pkcs12-template.c"
+#line 455 "../../asn1/pkcs12/packet-pkcs12-template.c"
   };
 
   /* List of subtrees */
@@ -1426,7 +1455,7 @@ void proto_register_pkcs12(void) {
          &ett_decrypted_pbe,
 
 /*--- Included file: packet-pkcs12-ettarr.c ---*/
-#line 1 "packet-pkcs12-ettarr.c"
+#line 1 "../../asn1/pkcs12/packet-pkcs12-ettarr.c"
     &ett_pkcs12_PFX,
     &ett_pkcs12_MacData,
     &ett_pkcs12_DigestInfo,
@@ -1449,9 +1478,14 @@ void proto_register_pkcs12(void) {
     &ett_pkcs12_PBMAC1Params,
 
 /*--- End of included file: packet-pkcs12-ettarr.c ---*/
-#line 460 "packet-pkcs12-template.c"
+#line 461 "../../asn1/pkcs12/packet-pkcs12-template.c"
   };
+  static ei_register_info ei[] = {
+      { &ei_pkcs12_octet_string_expected, { "pkcs12.octet_string_expected", PI_PROTOCOL, PI_WARN, "BER Error: OCTET STRING expected", EXPFILL }},
+  };
+
   module_t *pkcs12_module;
+  expert_module_t* expert_pkcs12;
 
   /* Register protocol */
   proto_pkcs12 = proto_register_protocol(PNAME, PSNAME, PFNAME);
@@ -1459,6 +1493,8 @@ void proto_register_pkcs12(void) {
   /* Register fields and subtrees */
   proto_register_field_array(proto_pkcs12, hf, array_length(hf));
   proto_register_subtree_array(ett, array_length(ett));
+  expert_pkcs12 = expert_register_protocol(proto_pkcs12);
+  expert_register_field_array(expert_pkcs12, ei, array_length(ei));
 
   /* Register preferences */
   pkcs12_module = prefs_register_protocol(proto_pkcs12, NULL);
@@ -1473,7 +1509,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); 
+  new_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");
 }
@@ -1483,34 +1519,34 @@ void proto_register_pkcs12(void) {
 void proto_reg_handoff_pkcs12(void) {
 
 /*--- Included file: packet-pkcs12-dis-tab.c ---*/
-#line 1 "packet-pkcs12-dis-tab.c"
-  register_ber_oid_dissector("1.2.840.113549.1.12.10.1.1", dissect_KeyBag_PDU, proto_pkcs12, "keyBag");
-  register_ber_oid_dissector("1.2.840.113549.1.12.10.1.2", dissect_PKCS8ShroudedKeyBag_PDU, proto_pkcs12, "pkcs8ShroudedKeyBag");
-  register_ber_oid_dissector("1.2.840.113549.1.12.10.1.3", dissect_CertBag_PDU, proto_pkcs12, "certBag");
-  register_ber_oid_dissector("1.2.840.113549.1.12.10.1.4", dissect_SecretBag_PDU, proto_pkcs12, "secretBag");
-  register_ber_oid_dissector("1.2.840.113549.1.12.10.1.5", dissect_CRLBag_PDU, proto_pkcs12, "crlBag");
-  register_ber_oid_dissector("1.2.840.113549.1.12.10.1.6", dissect_SafeContents_PDU, proto_pkcs12, "safeContentsBag");
-  register_ber_oid_dissector("2.16.840.1.113730.3.1.216", dissect_PFX_PDU, proto_pkcs12, "pkcs-9-at-PKCS12");
-  register_ber_oid_dissector("1.2.840.113549.1.9.25.2", dissect_EncryptedPrivateKeyInfo_PDU, proto_pkcs12, "pkcs-9-at-encryptedPrivateKeyInfo");
-  register_ber_oid_dissector("1.2.840.113549.1.12.1.1", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithSHAAnd128BitRC4");
-  register_ber_oid_dissector("1.2.840.113549.1.12.1.2", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithSHAAnd40BitRC4");
-  register_ber_oid_dissector("1.2.840.113549.1.12.1.3", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithSHAAnd3-KeyTripleDES-CBC");
-  register_ber_oid_dissector("1.2.840.113549.1.12.1.4", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithSHAAnd2-KeyTripleDES-CBC");
-  register_ber_oid_dissector("1.2.840.113549.1.12.1.5", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithSHAAnd128BitRC2-CBC");
-  register_ber_oid_dissector("1.2.840.113549.1.12.1.6", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithSHAAnd128BitRC2-CBC");
-  register_ber_oid_dissector("1.2.840.113549.1.5.1", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithMD2AndDES-CBC");
-  register_ber_oid_dissector("1.2.840.113549.1.5.3", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithMD5AndDES-CBC");
-  register_ber_oid_dissector("1.2.840.113549.1.5.4", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithMD2AndRC2-CBC");
-  register_ber_oid_dissector("1.2.840.113549.1.5.6", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithMD5AndRC2-CBC");
-  register_ber_oid_dissector("1.2.840.113549.1.5.10", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithSHA1AndDES-CBC");
-  register_ber_oid_dissector("1.2.840.113549.1.5.11", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithSHA1AndRC2-CBC");
-  register_ber_oid_dissector("1.2.840.113549.1.5.12", dissect_PBKDF2Params_PDU, proto_pkcs12, "id-PBKDF2");
-  register_ber_oid_dissector("1.2.840.113549.1.5.13", dissect_PBES2Params_PDU, proto_pkcs12, "id-PBES2");
-  register_ber_oid_dissector("1.2.840.113549.1.5.14", dissect_PBMAC1Params_PDU, proto_pkcs12, "id-PBMAC1");
+#line 1 "../../asn1/pkcs12/packet-pkcs12-dis-tab.c"
+  new_register_ber_oid_dissector("1.2.840.113549.1.12.10.1.1", dissect_KeyBag_PDU, proto_pkcs12, "keyBag");
+  new_register_ber_oid_dissector("1.2.840.113549.1.12.10.1.2", dissect_PKCS8ShroudedKeyBag_PDU, proto_pkcs12, "pkcs8ShroudedKeyBag");
+  new_register_ber_oid_dissector("1.2.840.113549.1.12.10.1.3", dissect_CertBag_PDU, proto_pkcs12, "certBag");
+  new_register_ber_oid_dissector("1.2.840.113549.1.12.10.1.4", dissect_SecretBag_PDU, proto_pkcs12, "secretBag");
+  new_register_ber_oid_dissector("1.2.840.113549.1.12.10.1.5", dissect_CRLBag_PDU, proto_pkcs12, "crlBag");
+  new_register_ber_oid_dissector("1.2.840.113549.1.12.10.1.6", dissect_SafeContents_PDU, proto_pkcs12, "safeContentsBag");
+  new_register_ber_oid_dissector("2.16.840.1.113730.3.1.216", dissect_PFX_PDU, proto_pkcs12, "pkcs-9-at-PKCS12");
+  new_register_ber_oid_dissector("1.2.840.113549.1.9.25.2", dissect_EncryptedPrivateKeyInfo_PDU, proto_pkcs12, "pkcs-9-at-encryptedPrivateKeyInfo");
+  new_register_ber_oid_dissector("1.2.840.113549.1.12.1.1", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithSHAAnd128BitRC4");
+  new_register_ber_oid_dissector("1.2.840.113549.1.12.1.2", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithSHAAnd40BitRC4");
+  new_register_ber_oid_dissector("1.2.840.113549.1.12.1.3", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithSHAAnd3-KeyTripleDES-CBC");
+  new_register_ber_oid_dissector("1.2.840.113549.1.12.1.4", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithSHAAnd2-KeyTripleDES-CBC");
+  new_register_ber_oid_dissector("1.2.840.113549.1.12.1.5", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithSHAAnd128BitRC2-CBC");
+  new_register_ber_oid_dissector("1.2.840.113549.1.12.1.6", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithSHAAnd128BitRC2-CBC");
+  new_register_ber_oid_dissector("1.2.840.113549.1.5.1", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithMD2AndDES-CBC");
+  new_register_ber_oid_dissector("1.2.840.113549.1.5.3", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithMD5AndDES-CBC");
+  new_register_ber_oid_dissector("1.2.840.113549.1.5.4", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithMD2AndRC2-CBC");
+  new_register_ber_oid_dissector("1.2.840.113549.1.5.6", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithMD5AndRC2-CBC");
+  new_register_ber_oid_dissector("1.2.840.113549.1.5.10", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithSHA1AndDES-CBC");
+  new_register_ber_oid_dissector("1.2.840.113549.1.5.11", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithSHA1AndRC2-CBC");
+  new_register_ber_oid_dissector("1.2.840.113549.1.5.12", dissect_PBKDF2Params_PDU, proto_pkcs12, "id-PBKDF2");
+  new_register_ber_oid_dissector("1.2.840.113549.1.5.13", dissect_PBES2Params_PDU, proto_pkcs12, "id-PBES2");
+  new_register_ber_oid_dissector("1.2.840.113549.1.5.14", dissect_PBMAC1Params_PDU, proto_pkcs12, "id-PBMAC1");
 
 
 /*--- End of included file: packet-pkcs12-dis-tab.c ---*/
-#line 492 "packet-pkcs12-template.c"
+#line 500 "../../asn1/pkcs12/packet-pkcs12-template.c"
 
        register_ber_oid_dissector("1.2.840.113549.1.9.22.1", dissect_X509Certificate_OCTETSTRING_PDU, proto_pkcs12, "x509Certificate");