Remove trailing whitespace from asn1 .cnf & template.[hc] files. Regenerate dissectors.
[metze/wireshark/wip.git] / epan / dissectors / packet-pkcs12.c
1 /* Do not modify this file. Changes will be overwritten.                      */
2 /* Generated automatically by the ASN.1 to Wireshark dissector compiler       */
3 /* packet-pkcs12.c                                                            */
4 /* ../../tools/asn2wrs.py -b -p pkcs12 -c ./pkcs12.cnf -s ./packet-pkcs12-template -D . -O ../../epan/dissectors pkcs12.asn */
5
6 /* Input file: packet-pkcs12-template.c */
7
8 #line 1 "../../asn1/pkcs12/packet-pkcs12-template.c"
9 /* packet-pkcs12.c
10  * Routines for PKCS#12: Personal Information Exchange packet dissection
11  * Graeme Lunt 2006
12  *
13  * See "PKCS #12 v1.1: Personal Information Exchange Syntax":
14  *
15  *    http://www.emc.com/emc-plus/rsa-labs/pkcs/files/h11301-wp-pkcs-12v1-1-personal-information-exchange-syntax.pdf
16  *
17  * Wireshark - Network traffic analyzer
18  * By Gerald Combs <gerald@wireshark.org>
19  * Copyright 1998 Gerald Combs
20  *
21  * This program is free software; you can redistribute it and/or
22  * modify it under the terms of the GNU General Public License
23  * as published by the Free Software Foundation; either version 2
24  * of the License, or (at your option) any later version.
25  *
26  * This program is distributed in the hope that it will be useful,
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29  * GNU General Public License for more details.
30  *
31  * You should have received a copy of the GNU General Public License
32  * along with this program; if not, write to the Free Software
33  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
34  */
35
36 #include "config.h"
37
38 #include <glib.h>
39 #include <epan/packet.h>
40 #include <epan/oids.h>
41 #include <epan/asn1.h>
42 #include <epan/prefs.h>
43 #include <epan/wmem/wmem.h>
44
45 #include "packet-ber.h"
46 #include "packet-pkcs12.h"
47 #include "packet-x509af.h"
48 #include "packet-x509if.h"
49 #include "packet-cms.h"
50
51 #ifdef HAVE_SYS_TYPES_H
52 #include <sys/types.h>
53 #endif
54
55 #ifdef HAVE_SYS_TIME_H
56 #include <sys/time.h>
57 #endif
58
59 #ifdef HAVE_LIBGCRYPT
60 #include <wsutil/wsgcrypt.h>
61 #endif
62
63 #define PNAME  "PKCS#12: Personal Information Exchange"
64 #define PSNAME "PKCS12"
65 #define PFNAME "pkcs12"
66
67 #define PKCS12_PBE_ARCFOUR_SHA1_OID     "1.2.840.113549.1.12.1.1"
68 #define PKCS12_PBE_3DES_SHA1_OID        "1.2.840.113549.1.12.1.3"
69 #define PKCS12_PBE_RC2_40_SHA1_OID      "1.2.840.113549.1.12.1.6"
70
71 void proto_register_pkcs12(void);
72 void proto_reg_handoff_pkcs12(void);
73
74 /* Initialize the protocol and registered fields */
75 static int proto_pkcs12 = -1;
76
77 static int hf_pkcs12_X509Certificate_PDU = -1;
78 static gint ett_decrypted_pbe = -1;
79
80 static const char *object_identifier_id = NULL;
81 static int iteration_count = 0;
82 static tvbuff_t *salt = NULL;
83 static const char *password = NULL;
84 static gboolean try_null_password = FALSE;
85
86 static void dissect_AuthenticatedSafe_OCTETSTRING_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
87 static void dissect_SafeContents_OCTETSTRING_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
88 static void dissect_PrivateKeyInfo_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
89
90
91 /*--- Included file: packet-pkcs12-hf.c ---*/
92 #line 1 "../../asn1/pkcs12/packet-pkcs12-hf.c"
93 static int hf_pkcs12_PFX_PDU = -1;                /* PFX */
94 static int hf_pkcs12_AuthenticatedSafe_PDU = -1;  /* AuthenticatedSafe */
95 static int hf_pkcs12_SafeContents_PDU = -1;       /* SafeContents */
96 static int hf_pkcs12_KeyBag_PDU = -1;             /* KeyBag */
97 static int hf_pkcs12_PKCS8ShroudedKeyBag_PDU = -1;  /* PKCS8ShroudedKeyBag */
98 static int hf_pkcs12_CertBag_PDU = -1;            /* CertBag */
99 static int hf_pkcs12_CRLBag_PDU = -1;             /* CRLBag */
100 static int hf_pkcs12_SecretBag_PDU = -1;          /* SecretBag */
101 static int hf_pkcs12_PrivateKeyInfo_PDU = -1;     /* PrivateKeyInfo */
102 static int hf_pkcs12_EncryptedPrivateKeyInfo_PDU = -1;  /* EncryptedPrivateKeyInfo */
103 static int hf_pkcs12_PBEParameter_PDU = -1;       /* PBEParameter */
104 static int hf_pkcs12_PBKDF2Params_PDU = -1;       /* PBKDF2Params */
105 static int hf_pkcs12_PBES2Params_PDU = -1;        /* PBES2Params */
106 static int hf_pkcs12_PBMAC1Params_PDU = -1;       /* PBMAC1Params */
107 static int hf_pkcs12_version = -1;                /* T_version */
108 static int hf_pkcs12_authSafe = -1;               /* ContentInfo */
109 static int hf_pkcs12_macData = -1;                /* MacData */
110 static int hf_pkcs12_mac = -1;                    /* DigestInfo */
111 static int hf_pkcs12_macSalt = -1;                /* OCTET_STRING */
112 static int hf_pkcs12_iterations = -1;             /* INTEGER */
113 static int hf_pkcs12_digestAlgorithm = -1;        /* DigestAlgorithmIdentifier */
114 static int hf_pkcs12_digest = -1;                 /* Digest */
115 static int hf_pkcs12_AuthenticatedSafe_item = -1;  /* ContentInfo */
116 static int hf_pkcs12_SafeContents_item = -1;      /* SafeBag */
117 static int hf_pkcs12_bagId = -1;                  /* T_bagId */
118 static int hf_pkcs12_bagValue = -1;               /* T_bagValue */
119 static int hf_pkcs12_bagAttributes = -1;          /* SET_OF_PKCS12Attribute */
120 static int hf_pkcs12_bagAttributes_item = -1;     /* PKCS12Attribute */
121 static int hf_pkcs12_certId = -1;                 /* T_certId */
122 static int hf_pkcs12_certValue = -1;              /* T_certValue */
123 static int hf_pkcs12_crlId = -1;                  /* T_crlId */
124 static int hf_pkcs12_crlValue = -1;               /* T_crlValue */
125 static int hf_pkcs12_secretTypeId = -1;           /* T_secretTypeId */
126 static int hf_pkcs12_secretValue = -1;            /* T_secretValue */
127 static int hf_pkcs12_attrId = -1;                 /* T_attrId */
128 static int hf_pkcs12_attrValues = -1;             /* T_attrValues */
129 static int hf_pkcs12_attrValues_item = -1;        /* T_attrValues_item */
130 static int hf_pkcs12_privateKeyVersion = -1;      /* Version */
131 static int hf_pkcs12_privateKeyAlgorithm = -1;    /* AlgorithmIdentifier */
132 static int hf_pkcs12_privateKey = -1;             /* PrivateKey */
133 static int hf_pkcs12_attributes = -1;             /* Attributes */
134 static int hf_pkcs12_Attributes_item = -1;        /* Attribute */
135 static int hf_pkcs12_encryptionAlgorithm = -1;    /* AlgorithmIdentifier */
136 static int hf_pkcs12_encryptedData = -1;          /* EncryptedData */
137 static int hf_pkcs12_salt = -1;                   /* OCTET_STRING */
138 static int hf_pkcs12_iterationCount = -1;         /* INTEGER */
139 static int hf_pkcs12_saltChoice = -1;             /* T_saltChoice */
140 static int hf_pkcs12_specified = -1;              /* OCTET_STRING */
141 static int hf_pkcs12_otherSource = -1;            /* AlgorithmIdentifier */
142 static int hf_pkcs12_keyLength = -1;              /* INTEGER_1_MAX */
143 static int hf_pkcs12_prf = -1;                    /* AlgorithmIdentifier */
144 static int hf_pkcs12_keyDerivationFunc = -1;      /* AlgorithmIdentifier */
145 static int hf_pkcs12_encryptionScheme = -1;       /* AlgorithmIdentifier */
146 static int hf_pkcs12_messageAuthScheme = -1;      /* AlgorithmIdentifier */
147
148 /*--- End of included file: packet-pkcs12-hf.c ---*/
149 #line 83 "../../asn1/pkcs12/packet-pkcs12-template.c"
150
151 /* Initialize the subtree pointers */
152
153 /*--- Included file: packet-pkcs12-ett.c ---*/
154 #line 1 "../../asn1/pkcs12/packet-pkcs12-ett.c"
155 static gint ett_pkcs12_PFX = -1;
156 static gint ett_pkcs12_MacData = -1;
157 static gint ett_pkcs12_DigestInfo = -1;
158 static gint ett_pkcs12_AuthenticatedSafe = -1;
159 static gint ett_pkcs12_SafeContents = -1;
160 static gint ett_pkcs12_SafeBag = -1;
161 static gint ett_pkcs12_SET_OF_PKCS12Attribute = -1;
162 static gint ett_pkcs12_CertBag = -1;
163 static gint ett_pkcs12_CRLBag = -1;
164 static gint ett_pkcs12_SecretBag = -1;
165 static gint ett_pkcs12_PKCS12Attribute = -1;
166 static gint ett_pkcs12_T_attrValues = -1;
167 static gint ett_pkcs12_PrivateKeyInfo = -1;
168 static gint ett_pkcs12_Attributes = -1;
169 static gint ett_pkcs12_EncryptedPrivateKeyInfo = -1;
170 static gint ett_pkcs12_PBEParameter = -1;
171 static gint ett_pkcs12_PBKDF2Params = -1;
172 static gint ett_pkcs12_T_saltChoice = -1;
173 static gint ett_pkcs12_PBES2Params = -1;
174 static gint ett_pkcs12_PBMAC1Params = -1;
175
176 /*--- End of included file: packet-pkcs12-ett.c ---*/
177 #line 86 "../../asn1/pkcs12/packet-pkcs12-template.c"
178
179 static void append_oid(proto_tree *tree, const char *oid)
180 {
181         const char *name = NULL;
182
183         name = oid_resolved_from_string(oid);
184         proto_item_append_text(tree, " (%s)", name ? name : oid);
185 }
186
187 #ifdef HAVE_LIBGCRYPT
188
189 static int
190 generate_key_or_iv(unsigned int id, tvbuff_t *salt_tvb, unsigned int iter,
191                        const char *pw, unsigned int req_keylen, char * keybuf)
192 {
193   int rc;
194   unsigned int i, j;
195   gcry_md_hd_t md;
196   gcry_mpi_t num_b1 = NULL;
197   size_t pwlen;
198   char hash[20], buf_b[64], buf_i[128], *p;
199   char *salt_p;
200   int salt_size;
201   size_t cur_keylen;
202   size_t n;
203   gcry_error_t  err;
204
205   cur_keylen = 0;
206
207   salt_size = tvb_length(salt_tvb);
208   salt_p = (char *)tvb_memdup(wmem_packet_scope(), salt_tvb, 0, salt_size);
209
210   if (pw == NULL)
211     pwlen = 0;
212   else
213     pwlen = strlen (pw);
214
215   if (pwlen > 63 / 2)
216     {
217       return FALSE;
218     }
219
220   /* Store salt and password in BUF_I */
221   p = buf_i;
222   for (i = 0; i < 64; i++)
223     *p++ = salt_p[i % salt_size];
224   if (pw)
225     {
226       for (i = j = 0; i < 64; i += 2)
227         {
228           *p++ = 0;
229           *p++ = pw[j];
230           if (++j > pwlen)      /* Note, that we include the trailing zero */
231             j = 0;
232         }
233     }
234   else
235     memset (p, 0, 64);
236
237   for (;;) {
238       err = gcry_md_open(&md, GCRY_MD_SHA1, 0);
239       if (gcry_err_code(err))
240         {
241           return FALSE;
242         }
243       for (i = 0; i < 64; i++)
244         {
245           unsigned char lid = id & 0xFF;
246           gcry_md_write (md, &lid, 1);
247         }
248
249       gcry_md_write(md, buf_i, pw ? 128 : 64);
250
251       gcry_md_final (md);
252       memcpy (hash, gcry_md_read (md, 0), 20);
253
254       gcry_md_close (md);
255
256       for (i = 1; i < iter; i++)
257         gcry_md_hash_buffer (GCRY_MD_SHA1, hash, hash, 20);
258
259       for (i = 0; i < 20 && cur_keylen < req_keylen; i++)
260         keybuf[cur_keylen++] = hash[i];
261
262       if (cur_keylen == req_keylen)
263       {
264         gcry_mpi_release (num_b1);
265         return TRUE;            /* ready */
266       }
267
268       /* need more bytes. */
269       for (i = 0; i < 64; i++)
270         buf_b[i] = hash[i % 20];
271
272       n = 64;
273
274       rc = gcry_mpi_scan (&num_b1, GCRYMPI_FMT_USG, buf_b, n, &n);
275
276       if (rc != 0)
277         {
278           return FALSE;
279         }
280
281       gcry_mpi_add_ui (num_b1, num_b1, 1);
282
283       for (i = 0; i < 128; i += 64)
284         {
285           gcry_mpi_t num_ij;
286
287           n = 64;
288           rc = gcry_mpi_scan (&num_ij, GCRYMPI_FMT_USG, buf_i + i, n, &n);
289
290           if (rc != 0)
291             {
292               return FALSE;
293             }
294
295           gcry_mpi_add (num_ij, num_ij, num_b1);
296           gcry_mpi_clear_highbit (num_ij, 64 * 8);
297
298           n = 64;
299
300           rc = gcry_mpi_print (GCRYMPI_FMT_USG, buf_i + i, n, &n, num_ij);
301           if (rc != 0)
302             {
303               return FALSE;
304             }
305
306           gcry_mpi_release (num_ij);
307         }
308   }
309 }
310
311 #endif
312
313 void PBE_reset_parameters(void)
314 {
315         iteration_count = 0;
316         salt = NULL;
317 }
318
319 int PBE_decrypt_data(const char *object_identifier_id_param, tvbuff_t *encrypted_tvb, asn1_ctx_t *actx, proto_item *item)
320 {
321 #ifdef HAVE_LIBGCRYPT
322         const char      *encryption_algorithm;
323         gcry_cipher_hd_t cipher;
324         gcry_error_t    err;
325         int             algo;
326         int             mode;
327         int             ivlen = 0;
328         int             keylen = 0;
329         int             datalen = 0;
330         char            *key = NULL;
331         char            *iv = NULL;
332         char            *clear_data = NULL;
333         tvbuff_t        *clear_tvb = NULL;
334         const gchar     *oidname;
335         GString         *name;
336         proto_tree      *tree;
337         char            byte;
338         gboolean        decrypt_ok = TRUE;
339
340         if(((password == NULL) || (*password == '\0')) && (try_null_password == FALSE)) {
341                 /* we are not configured to decrypt */
342                 return FALSE;
343         }
344
345         encryption_algorithm = x509af_get_last_algorithm_id();
346
347         /* these are the only encryption schemes we understand for now */
348         if(!strcmp(encryption_algorithm, PKCS12_PBE_3DES_SHA1_OID)) {
349                 ivlen = 8;
350                 keylen = 24;
351                 algo = GCRY_CIPHER_3DES;
352                 mode = GCRY_CIPHER_MODE_CBC;
353         } else if(!strcmp(encryption_algorithm, PKCS12_PBE_ARCFOUR_SHA1_OID)) {
354                 ivlen = 0;
355                 keylen = 16;
356                 algo = GCRY_CIPHER_ARCFOUR;
357                 mode = GCRY_CIPHER_MODE_NONE;
358         } else if(!strcmp(encryption_algorithm, PKCS12_PBE_RC2_40_SHA1_OID)) {
359                 ivlen = 8;
360                 keylen = 5;
361                 algo = GCRY_CIPHER_RFC2268_40;
362                 mode = GCRY_CIPHER_MODE_CBC;
363         } else {
364                 /* we don't know how to decrypt this */
365
366                 proto_item_append_text(item, " [Unsupported encryption algorithm]");
367                 return FALSE;
368         }
369
370         if((iteration_count == 0) || (salt == NULL)) {
371                 proto_item_append_text(item, " [Insufficient parameters]");
372                 return FALSE;
373         }
374
375         /* allocate buffers */
376         key = (char *)wmem_alloc(wmem_packet_scope(), keylen);
377
378         if(!generate_key_or_iv(1 /*LEY */, salt, iteration_count, password, keylen, key))
379                 return FALSE;
380
381         if(ivlen) {
382
383                 iv = (char *)wmem_alloc(wmem_packet_scope(), ivlen);
384
385                 if(!generate_key_or_iv(2 /* IV */, salt, iteration_count, password, ivlen, iv))
386                         return FALSE;
387         }
388
389         /* now try an internal function */
390         err = gcry_cipher_open(&cipher, algo, mode, 0);
391         if (gcry_err_code (err))
392                         return FALSE;
393
394         err = gcry_cipher_setkey (cipher, key, keylen);
395         if (gcry_err_code (err)) {
396                         gcry_cipher_close (cipher);
397                         return FALSE;
398         }
399
400         if(ivlen) {
401                   err = gcry_cipher_setiv (cipher, iv, ivlen);
402                   if (gcry_err_code (err)) {
403                           gcry_cipher_close (cipher);
404                           return FALSE;
405                   }
406         }
407
408         datalen = tvb_length(encrypted_tvb);
409         clear_data = (char *)g_malloc(datalen);
410
411         err = gcry_cipher_decrypt (cipher, clear_data, datalen, (char *)tvb_memdup(wmem_packet_scope(), encrypted_tvb, 0, datalen), datalen);
412         if (gcry_err_code (err)) {
413
414                 proto_item_append_text(item, " [Failed to decrypt with password preference]");
415
416                 gcry_cipher_close (cipher);
417                 g_free(clear_data);
418                 return FALSE;
419         }
420
421         gcry_cipher_close (cipher);
422
423         /* We don't know if we have successfully decrypted the data or not so we:
424                 a) check the trailing bytes
425                 b) see if we start with a sequence or a set (is this too constraining?
426                 */
427
428         /* first the trailing bytes */
429         byte = clear_data[datalen-1];
430         if(byte <= 0x08) {
431                 int i;
432
433                 for(i = (int)byte; i > 0 ; i--) {
434                         if(clear_data[datalen - i] != byte) {
435                                 decrypt_ok = FALSE;
436                                 break;
437                         }
438                 }
439         } else {
440                 /* XXX: is this a failure? */
441         }
442
443         /* we assume the result is ASN.1 - check it is a SET or SEQUENCE */
444         byte = clear_data[0];
445         if((byte != 0x30) && (byte != 0x31)) { /* do we need more here? OCTET STRING? */
446                 decrypt_ok = FALSE;
447         }
448
449         if(!decrypt_ok) {
450                 g_free(clear_data);
451                 proto_item_append_text(item, " [Failed to decrypt with supplied password]");
452
453                 return FALSE;
454         }
455
456         proto_item_append_text(item, " [Decrypted successfully]");
457
458         tree = proto_item_add_subtree(item, ett_decrypted_pbe);
459
460         /* OK - so now clear_data contains the decrypted data */
461
462         clear_tvb = tvb_new_child_real_data(encrypted_tvb,(const guint8 *)clear_data, datalen, datalen);
463         tvb_set_free_cb(clear_tvb, g_free);
464
465         name = g_string_new("");
466         oidname = oid_resolved_from_string(object_identifier_id_param);
467         g_string_printf(name, "Decrypted %s", oidname ? oidname : object_identifier_id_param);
468
469         /* add it as a new source */
470         add_new_data_source(actx->pinfo, clear_tvb, name->str);
471
472         g_string_free(name, TRUE);
473
474         /* now try and decode it */
475         call_ber_oid_callback(object_identifier_id_param, clear_tvb, 0, actx->pinfo, tree, NULL);
476
477         return TRUE;
478 #else
479         /* we cannot decrypt */
480         return FALSE;
481
482 #endif
483 }
484
485
486 /*--- Included file: packet-pkcs12-fn.c ---*/
487 #line 1 "../../asn1/pkcs12/packet-pkcs12-fn.c"
488
489 static const value_string pkcs12_T_version_vals[] = {
490   {   3, "v3" },
491   { 0, NULL }
492 };
493
494
495 static int
496 dissect_pkcs12_T_version(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
497   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
498                                                 NULL);
499
500   return offset;
501 }
502
503
504 static const ber_sequence_t DigestInfo_sequence[] = {
505   { &hf_pkcs12_digestAlgorithm, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_cms_DigestAlgorithmIdentifier },
506   { &hf_pkcs12_digest       , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_cms_Digest },
507   { NULL, 0, 0, 0, NULL }
508 };
509
510 static int
511 dissect_pkcs12_DigestInfo(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
512   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
513                                    DigestInfo_sequence, hf_index, ett_pkcs12_DigestInfo);
514
515   return offset;
516 }
517
518
519
520 static int
521 dissect_pkcs12_OCTET_STRING(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
522   offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
523                                        (hf_index == hf_pkcs12_salt ? &salt : NULL));
524
525   return offset;
526 }
527
528
529
530 static int
531 dissect_pkcs12_INTEGER(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
532   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
533                                                 (hf_index == hf_pkcs12_iterationCount ? &iteration_count : NULL));
534
535   return offset;
536 }
537
538
539 static const ber_sequence_t MacData_sequence[] = {
540   { &hf_pkcs12_mac          , BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_pkcs12_DigestInfo },
541   { &hf_pkcs12_macSalt      , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_pkcs12_OCTET_STRING },
542   { &hf_pkcs12_iterations   , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_pkcs12_INTEGER },
543   { NULL, 0, 0, 0, NULL }
544 };
545
546 static int
547 dissect_pkcs12_MacData(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
548   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
549                                    MacData_sequence, hf_index, ett_pkcs12_MacData);
550
551   return offset;
552 }
553
554
555 static const ber_sequence_t PFX_sequence[] = {
556   { &hf_pkcs12_version      , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_pkcs12_T_version },
557   { &hf_pkcs12_authSafe     , BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_cms_ContentInfo },
558   { &hf_pkcs12_macData      , BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_pkcs12_MacData },
559   { NULL, 0, 0, 0, NULL }
560 };
561
562 static int
563 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_) {
564 #line 58 "../../asn1/pkcs12/pkcs12.cnf"
565         dissector_handle_t dissector_handle;
566
567         /* we change the CMS id-data dissector to dissect as AuthenticatedSafe
568            not sure why PKCS#12 couldn't have used its own content type OID for AuthenticatedSafe */
569         dissector_handle=create_dissector_handle(dissect_AuthenticatedSafe_OCTETSTRING_PDU, proto_pkcs12);
570         dissector_change_string("ber.oid", "1.2.840.113549.1.7.1", dissector_handle);
571
572           offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
573                                    PFX_sequence, hf_index, ett_pkcs12_PFX);
574
575
576         /* restore the original dissector */
577         dissector_reset_string("ber.oid", "1.2.840.113549.1.7.1");
578
579
580
581   return offset;
582 }
583
584
585 static const ber_sequence_t AuthenticatedSafe_sequence_of[1] = {
586   { &hf_pkcs12_AuthenticatedSafe_item, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_cms_ContentInfo },
587 };
588
589 static int
590 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_) {
591 #line 71 "../../asn1/pkcs12/pkcs12.cnf"
592         dissector_handle_t dissector_handle;
593
594         /* we change the CMS id-data dissector to dissect as SafeContents */
595         dissector_handle=create_dissector_handle(dissect_SafeContents_OCTETSTRING_PDU, proto_pkcs12);
596         dissector_change_string("ber.oid", "1.2.840.113549.1.7.1", dissector_handle);
597
598           offset = dissect_ber_sequence_of(implicit_tag, actx, tree, tvb, offset,
599                                       AuthenticatedSafe_sequence_of, hf_index, ett_pkcs12_AuthenticatedSafe);
600
601
602         /* restore the original dissector */
603         dissector_reset_string("ber.oid", "1.2.840.113549.1.7.1");
604
605
606
607   return offset;
608 }
609
610
611
612 static int
613 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_) {
614   offset = dissect_ber_object_identifier_str(implicit_tag, actx, tree, tvb, offset, hf_index, &object_identifier_id);
615
616 #line 84 "../../asn1/pkcs12/pkcs12.cnf"
617   append_oid(tree, object_identifier_id);
618
619   return offset;
620 }
621
622
623
624 static int
625 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_) {
626 #line 108 "../../asn1/pkcs12/pkcs12.cnf"
627         if(object_identifier_id)
628                 offset = call_ber_oid_callback(object_identifier_id, tvb, offset, actx->pinfo, tree, NULL);
629
630
631
632   return offset;
633 }
634
635
636
637 static int
638 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_) {
639   offset = dissect_ber_object_identifier_str(implicit_tag, actx, tree, tvb, offset, hf_index, &object_identifier_id);
640
641 #line 104 "../../asn1/pkcs12/pkcs12.cnf"
642   append_oid(tree, object_identifier_id);
643
644   return offset;
645 }
646
647
648
649 static int
650 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_) {
651 #line 112 "../../asn1/pkcs12/pkcs12.cnf"
652         if(object_identifier_id)
653                 offset = call_ber_oid_callback(object_identifier_id, tvb, offset, actx->pinfo, tree, NULL);
654
655
656
657   return offset;
658 }
659
660
661 static const ber_sequence_t T_attrValues_set_of[1] = {
662   { &hf_pkcs12_attrValues_item, BER_CLASS_ANY, 0, BER_FLAGS_NOOWNTAG, dissect_pkcs12_T_attrValues_item },
663 };
664
665 static int
666 dissect_pkcs12_T_attrValues(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
667   offset = dissect_ber_set_of(implicit_tag, actx, tree, tvb, offset,
668                                  T_attrValues_set_of, hf_index, ett_pkcs12_T_attrValues);
669
670   return offset;
671 }
672
673
674 static const ber_sequence_t PKCS12Attribute_sequence[] = {
675   { &hf_pkcs12_attrId       , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_pkcs12_T_attrId },
676   { &hf_pkcs12_attrValues   , BER_CLASS_UNI, BER_UNI_TAG_SET, BER_FLAGS_NOOWNTAG, dissect_pkcs12_T_attrValues },
677   { NULL, 0, 0, 0, NULL }
678 };
679
680 static int
681 dissect_pkcs12_PKCS12Attribute(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
682   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
683                                    PKCS12Attribute_sequence, hf_index, ett_pkcs12_PKCS12Attribute);
684
685   return offset;
686 }
687
688
689 static const ber_sequence_t SET_OF_PKCS12Attribute_set_of[1] = {
690   { &hf_pkcs12_bagAttributes_item, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_pkcs12_PKCS12Attribute },
691 };
692
693 static int
694 dissect_pkcs12_SET_OF_PKCS12Attribute(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
695   offset = dissect_ber_set_of(implicit_tag, actx, tree, tvb, offset,
696                                  SET_OF_PKCS12Attribute_set_of, hf_index, ett_pkcs12_SET_OF_PKCS12Attribute);
697
698   return offset;
699 }
700
701
702 static const ber_sequence_t SafeBag_sequence[] = {
703   { &hf_pkcs12_bagId        , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_pkcs12_T_bagId },
704   { &hf_pkcs12_bagValue     , BER_CLASS_CON, 0, 0, dissect_pkcs12_T_bagValue },
705   { &hf_pkcs12_bagAttributes, BER_CLASS_UNI, BER_UNI_TAG_SET, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_pkcs12_SET_OF_PKCS12Attribute },
706   { NULL, 0, 0, 0, NULL }
707 };
708
709 static int
710 dissect_pkcs12_SafeBag(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
711   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
712                                    SafeBag_sequence, hf_index, ett_pkcs12_SafeBag);
713
714   return offset;
715 }
716
717
718 static const ber_sequence_t SafeContents_sequence_of[1] = {
719   { &hf_pkcs12_SafeContents_item, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_pkcs12_SafeBag },
720 };
721
722 static int
723 dissect_pkcs12_SafeContents(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
724   offset = dissect_ber_sequence_of(implicit_tag, actx, tree, tvb, offset,
725                                       SafeContents_sequence_of, hf_index, ett_pkcs12_SafeContents);
726
727   return offset;
728 }
729
730
731 static const value_string pkcs12_Version_vals[] = {
732   {   0, "v1" },
733   { 0, NULL }
734 };
735
736
737 static int
738 dissect_pkcs12_Version(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
739   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
740                                                 NULL);
741
742   return offset;
743 }
744
745
746
747 static int
748 dissect_pkcs12_PrivateKey(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
749   offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
750                                        NULL);
751
752   return offset;
753 }
754
755
756 static const ber_sequence_t Attributes_set_of[1] = {
757   { &hf_pkcs12_Attributes_item, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_x509if_Attribute },
758 };
759
760 static int
761 dissect_pkcs12_Attributes(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
762   offset = dissect_ber_set_of(implicit_tag, actx, tree, tvb, offset,
763                                  Attributes_set_of, hf_index, ett_pkcs12_Attributes);
764
765   return offset;
766 }
767
768
769 static const ber_sequence_t PrivateKeyInfo_sequence[] = {
770   { &hf_pkcs12_privateKeyVersion, BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_pkcs12_Version },
771   { &hf_pkcs12_privateKeyAlgorithm, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_x509af_AlgorithmIdentifier },
772   { &hf_pkcs12_privateKey   , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_pkcs12_PrivateKey },
773   { &hf_pkcs12_attributes   , BER_CLASS_CON, 0, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_pkcs12_Attributes },
774   { NULL, 0, 0, 0, NULL }
775 };
776
777 static int
778 dissect_pkcs12_PrivateKeyInfo(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
779   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
780                                    PrivateKeyInfo_sequence, hf_index, ett_pkcs12_PrivateKeyInfo);
781
782   return offset;
783 }
784
785
786
787 static int
788 dissect_pkcs12_KeyBag(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
789   offset = dissect_pkcs12_PrivateKeyInfo(implicit_tag, tvb, offset, actx, tree, hf_index);
790
791   return offset;
792 }
793
794
795
796 static int
797 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_) {
798 #line 139 "../../asn1/pkcs12/pkcs12.cnf"
799         tvbuff_t *encrypted_tvb;
800         dissector_handle_t dissector_handle;
801
802
803   offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
804                                        &encrypted_tvb);
805
806 #line 145 "../../asn1/pkcs12/pkcs12.cnf"
807
808
809
810         dissector_handle=create_dissector_handle(dissect_PrivateKeyInfo_PDU, proto_pkcs12);
811         dissector_change_string("ber.oid", object_identifier_id, dissector_handle);
812
813         PBE_decrypt_data(object_identifier_id, encrypted_tvb, actx, actx->created_item);
814
815         /* restore the original dissector */
816         dissector_reset_string("ber.oid", object_identifier_id);
817
818
819   return offset;
820 }
821
822
823 static const ber_sequence_t EncryptedPrivateKeyInfo_sequence[] = {
824   { &hf_pkcs12_encryptionAlgorithm, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_x509af_AlgorithmIdentifier },
825   { &hf_pkcs12_encryptedData, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_pkcs12_EncryptedData },
826   { NULL, 0, 0, 0, NULL }
827 };
828
829 static int
830 dissect_pkcs12_EncryptedPrivateKeyInfo(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
831   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
832                                    EncryptedPrivateKeyInfo_sequence, hf_index, ett_pkcs12_EncryptedPrivateKeyInfo);
833
834   return offset;
835 }
836
837
838
839 static int
840 dissect_pkcs12_PKCS8ShroudedKeyBag(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
841   offset = dissect_pkcs12_EncryptedPrivateKeyInfo(implicit_tag, tvb, offset, actx, tree, hf_index);
842
843   return offset;
844 }
845
846
847
848 static int
849 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_) {
850   offset = dissect_ber_object_identifier_str(implicit_tag, actx, tree, tvb, offset, hf_index, &object_identifier_id);
851
852 #line 89 "../../asn1/pkcs12/pkcs12.cnf"
853   append_oid(tree, object_identifier_id);
854
855   return offset;
856 }
857
858
859
860 static int
861 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_) {
862 #line 116 "../../asn1/pkcs12/pkcs12.cnf"
863         if(object_identifier_id)
864                 offset = call_ber_oid_callback(object_identifier_id, tvb, offset, actx->pinfo, tree, NULL);
865
866
867
868   return offset;
869 }
870
871
872 static const ber_sequence_t CertBag_sequence[] = {
873   { &hf_pkcs12_certId       , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_pkcs12_T_certId },
874   { &hf_pkcs12_certValue    , BER_CLASS_CON, 0, 0, dissect_pkcs12_T_certValue },
875   { NULL, 0, 0, 0, NULL }
876 };
877
878 static int
879 dissect_pkcs12_CertBag(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
880   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
881                                    CertBag_sequence, hf_index, ett_pkcs12_CertBag);
882
883   return offset;
884 }
885
886
887
888 static int
889 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_) {
890   offset = dissect_ber_object_identifier_str(implicit_tag, actx, tree, tvb, offset, hf_index, &object_identifier_id);
891
892 #line 94 "../../asn1/pkcs12/pkcs12.cnf"
893   append_oid(tree, object_identifier_id);
894
895   return offset;
896 }
897
898
899
900 static int
901 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_) {
902 #line 120 "../../asn1/pkcs12/pkcs12.cnf"
903         if(object_identifier_id)
904                 offset = call_ber_oid_callback(object_identifier_id, tvb, offset, actx->pinfo, tree, NULL);
905
906
907
908   return offset;
909 }
910
911
912 static const ber_sequence_t CRLBag_sequence[] = {
913   { &hf_pkcs12_crlId        , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_pkcs12_T_crlId },
914   { &hf_pkcs12_crlValue     , BER_CLASS_CON, 0, 0, dissect_pkcs12_T_crlValue },
915   { NULL, 0, 0, 0, NULL }
916 };
917
918 static int
919 dissect_pkcs12_CRLBag(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
920   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
921                                    CRLBag_sequence, hf_index, ett_pkcs12_CRLBag);
922
923   return offset;
924 }
925
926
927
928 static int
929 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_) {
930   offset = dissect_ber_object_identifier_str(implicit_tag, actx, tree, tvb, offset, hf_index, &object_identifier_id);
931
932 #line 99 "../../asn1/pkcs12/pkcs12.cnf"
933   append_oid(tree, object_identifier_id);
934
935   return offset;
936 }
937
938
939
940 static int
941 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_) {
942 #line 124 "../../asn1/pkcs12/pkcs12.cnf"
943         if(object_identifier_id)
944                 offset = call_ber_oid_callback(object_identifier_id, tvb, offset, actx->pinfo, tree, NULL);
945
946
947
948   return offset;
949 }
950
951
952 static const ber_sequence_t SecretBag_sequence[] = {
953   { &hf_pkcs12_secretTypeId , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_pkcs12_T_secretTypeId },
954   { &hf_pkcs12_secretValue  , BER_CLASS_CON, 0, 0, dissect_pkcs12_T_secretValue },
955   { NULL, 0, 0, 0, NULL }
956 };
957
958 static int
959 dissect_pkcs12_SecretBag(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
960   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
961                                    SecretBag_sequence, hf_index, ett_pkcs12_SecretBag);
962
963   return offset;
964 }
965
966
967 static const ber_sequence_t PBEParameter_sequence[] = {
968   { &hf_pkcs12_salt         , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_pkcs12_OCTET_STRING },
969   { &hf_pkcs12_iterationCount, BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_pkcs12_INTEGER },
970   { NULL, 0, 0, 0, NULL }
971 };
972
973 static int
974 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_) {
975 #line 128 "../../asn1/pkcs12/pkcs12.cnf"
976         /* initialise the encryption parameters */
977         PBE_reset_parameters();
978
979
980   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
981                                    PBEParameter_sequence, hf_index, ett_pkcs12_PBEParameter);
982
983   return offset;
984 }
985
986
987 static const value_string pkcs12_T_saltChoice_vals[] = {
988   {   0, "specified" },
989   {   1, "otherSource" },
990   { 0, NULL }
991 };
992
993 static const ber_choice_t T_saltChoice_choice[] = {
994   {   0, &hf_pkcs12_specified    , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_pkcs12_OCTET_STRING },
995   {   1, &hf_pkcs12_otherSource  , BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_x509af_AlgorithmIdentifier },
996   { 0, NULL, 0, 0, 0, NULL }
997 };
998
999 static int
1000 dissect_pkcs12_T_saltChoice(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1001   offset = dissect_ber_choice(actx, tree, tvb, offset,
1002                                  T_saltChoice_choice, hf_index, ett_pkcs12_T_saltChoice,
1003                                  NULL);
1004
1005   return offset;
1006 }
1007
1008
1009
1010 static int
1011 dissect_pkcs12_INTEGER_1_MAX(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1012   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
1013                                                 NULL);
1014
1015   return offset;
1016 }
1017
1018
1019 static const ber_sequence_t PBKDF2Params_sequence[] = {
1020   { &hf_pkcs12_saltChoice   , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_pkcs12_T_saltChoice },
1021   { &hf_pkcs12_iterationCount, BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_pkcs12_INTEGER },
1022   { &hf_pkcs12_keyLength    , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_pkcs12_INTEGER_1_MAX },
1023   { &hf_pkcs12_prf          , BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_x509af_AlgorithmIdentifier },
1024   { NULL, 0, 0, 0, NULL }
1025 };
1026
1027 static int
1028 dissect_pkcs12_PBKDF2Params(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1029   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
1030                                    PBKDF2Params_sequence, hf_index, ett_pkcs12_PBKDF2Params);
1031
1032   return offset;
1033 }
1034
1035
1036 static const ber_sequence_t PBES2Params_sequence[] = {
1037   { &hf_pkcs12_keyDerivationFunc, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_x509af_AlgorithmIdentifier },
1038   { &hf_pkcs12_encryptionScheme, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_x509af_AlgorithmIdentifier },
1039   { NULL, 0, 0, 0, NULL }
1040 };
1041
1042 static int
1043 dissect_pkcs12_PBES2Params(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1044   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
1045                                    PBES2Params_sequence, hf_index, ett_pkcs12_PBES2Params);
1046
1047   return offset;
1048 }
1049
1050
1051 static const ber_sequence_t PBMAC1Params_sequence[] = {
1052   { &hf_pkcs12_keyDerivationFunc, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_x509af_AlgorithmIdentifier },
1053   { &hf_pkcs12_messageAuthScheme, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_x509af_AlgorithmIdentifier },
1054   { NULL, 0, 0, 0, NULL }
1055 };
1056
1057 static int
1058 dissect_pkcs12_PBMAC1Params(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1059   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
1060                                    PBMAC1Params_sequence, hf_index, ett_pkcs12_PBMAC1Params);
1061
1062   return offset;
1063 }
1064
1065 /*--- PDUs ---*/
1066
1067 static void dissect_PFX_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
1068   asn1_ctx_t asn1_ctx;
1069   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
1070   dissect_pkcs12_PFX(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_PFX_PDU);
1071 }
1072 static void dissect_AuthenticatedSafe_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
1073   asn1_ctx_t asn1_ctx;
1074   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
1075   dissect_pkcs12_AuthenticatedSafe(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_AuthenticatedSafe_PDU);
1076 }
1077 static void dissect_SafeContents_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
1078   asn1_ctx_t asn1_ctx;
1079   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
1080   dissect_pkcs12_SafeContents(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_SafeContents_PDU);
1081 }
1082 static void dissect_KeyBag_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
1083   asn1_ctx_t asn1_ctx;
1084   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
1085   dissect_pkcs12_KeyBag(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_KeyBag_PDU);
1086 }
1087 static void dissect_PKCS8ShroudedKeyBag_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
1088   asn1_ctx_t asn1_ctx;
1089   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
1090   dissect_pkcs12_PKCS8ShroudedKeyBag(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_PKCS8ShroudedKeyBag_PDU);
1091 }
1092 static void dissect_CertBag_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
1093   asn1_ctx_t asn1_ctx;
1094   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
1095   dissect_pkcs12_CertBag(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_CertBag_PDU);
1096 }
1097 static void dissect_CRLBag_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
1098   asn1_ctx_t asn1_ctx;
1099   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
1100   dissect_pkcs12_CRLBag(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_CRLBag_PDU);
1101 }
1102 static void dissect_SecretBag_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
1103   asn1_ctx_t asn1_ctx;
1104   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
1105   dissect_pkcs12_SecretBag(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_SecretBag_PDU);
1106 }
1107 static void dissect_PrivateKeyInfo_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
1108   asn1_ctx_t asn1_ctx;
1109   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
1110   dissect_pkcs12_PrivateKeyInfo(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_PrivateKeyInfo_PDU);
1111 }
1112 static void dissect_EncryptedPrivateKeyInfo_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
1113   asn1_ctx_t asn1_ctx;
1114   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
1115   dissect_pkcs12_EncryptedPrivateKeyInfo(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_EncryptedPrivateKeyInfo_PDU);
1116 }
1117 static void dissect_PBEParameter_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
1118   asn1_ctx_t asn1_ctx;
1119   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
1120   dissect_pkcs12_PBEParameter(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_PBEParameter_PDU);
1121 }
1122 static void dissect_PBKDF2Params_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
1123   asn1_ctx_t asn1_ctx;
1124   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
1125   dissect_pkcs12_PBKDF2Params(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_PBKDF2Params_PDU);
1126 }
1127 static void dissect_PBES2Params_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
1128   asn1_ctx_t asn1_ctx;
1129   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
1130   dissect_pkcs12_PBES2Params(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_PBES2Params_PDU);
1131 }
1132 static void dissect_PBMAC1Params_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
1133   asn1_ctx_t asn1_ctx;
1134   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
1135   dissect_pkcs12_PBMAC1Params(FALSE, tvb, 0, &asn1_ctx, tree, hf_pkcs12_PBMAC1Params_PDU);
1136 }
1137
1138
1139 /*--- End of included file: packet-pkcs12-fn.c ---*/
1140 #line 394 "../../asn1/pkcs12/packet-pkcs12-template.c"
1141
1142 static int strip_octet_string(tvbuff_t *tvb)
1143 {
1144   gint8 ber_class;
1145   gboolean pc, ind;
1146   gint32 tag;
1147   guint32 len;
1148   int offset = 0;
1149
1150   /* PKCS#7 encodes the content as OCTET STRING, whereas CMS is just any ANY */
1151   /* if we use CMS (rather than PKCS#7) - which we are - we need to strip the OCTET STRING tag */
1152   /* before proceeding */
1153
1154   offset = get_ber_identifier(tvb, 0, &ber_class, &pc, &tag);
1155   offset = get_ber_length(tvb, offset, &len, &ind);
1156
1157   if((ber_class == BER_CLASS_UNI) && (tag == BER_UNI_TAG_OCTETSTRING))
1158     return offset;
1159
1160   return 0;
1161
1162 }
1163
1164 static void dissect_AuthenticatedSafe_OCTETSTRING_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
1165   int offset = 0;
1166   asn1_ctx_t asn1_ctx;
1167   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
1168
1169   if((offset = strip_octet_string(tvb)) > 0)
1170     dissect_pkcs12_AuthenticatedSafe(FALSE, tvb, offset, &asn1_ctx, tree, hf_pkcs12_AuthenticatedSafe_PDU);
1171   else
1172     proto_tree_add_text(tree, tvb, 0, 1, "BER Error: OCTET STRING expected");
1173 }
1174
1175 static void dissect_SafeContents_OCTETSTRING_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1176 {
1177   int offset = 0;
1178   asn1_ctx_t asn1_ctx;
1179   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
1180
1181   offset = strip_octet_string(tvb);
1182
1183   dissect_pkcs12_SafeContents(FALSE, tvb, offset, &asn1_ctx, tree, hf_pkcs12_SafeContents_PDU);
1184 }
1185
1186 static void dissect_X509Certificate_OCTETSTRING_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1187 {
1188   int offset = 0;
1189   asn1_ctx_t asn1_ctx;
1190   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
1191
1192   if((offset = strip_octet_string(tvb)) > 0)
1193         dissect_x509af_Certificate(FALSE, tvb, offset, &asn1_ctx, tree, hf_pkcs12_X509Certificate_PDU);
1194   else
1195         proto_tree_add_text(tree, tvb, 0, 1, "BER Error: OCTET STRING expected");
1196 }
1197
1198 /*--- proto_register_pkcs12 ----------------------------------------------*/
1199 void proto_register_pkcs12(void) {
1200
1201   /* List of fields */
1202   static hf_register_info hf[] = {
1203     { &hf_pkcs12_X509Certificate_PDU,
1204       { "X509Certificate", "pkcs12.X509Certificate",
1205         FT_NONE, BASE_NONE, NULL, 0,
1206         "pkcs12.X509Certificate", HFILL }},
1207
1208 /*--- Included file: packet-pkcs12-hfarr.c ---*/
1209 #line 1 "../../asn1/pkcs12/packet-pkcs12-hfarr.c"
1210     { &hf_pkcs12_PFX_PDU,
1211       { "PFX", "pkcs12.PFX_element",
1212         FT_NONE, BASE_NONE, NULL, 0,
1213         NULL, HFILL }},
1214     { &hf_pkcs12_AuthenticatedSafe_PDU,
1215       { "AuthenticatedSafe", "pkcs12.AuthenticatedSafe",
1216         FT_UINT32, BASE_DEC, NULL, 0,
1217         NULL, HFILL }},
1218     { &hf_pkcs12_SafeContents_PDU,
1219       { "SafeContents", "pkcs12.SafeContents",
1220         FT_UINT32, BASE_DEC, NULL, 0,
1221         NULL, HFILL }},
1222     { &hf_pkcs12_KeyBag_PDU,
1223       { "KeyBag", "pkcs12.KeyBag_element",
1224         FT_NONE, BASE_NONE, NULL, 0,
1225         NULL, HFILL }},
1226     { &hf_pkcs12_PKCS8ShroudedKeyBag_PDU,
1227       { "PKCS8ShroudedKeyBag", "pkcs12.PKCS8ShroudedKeyBag_element",
1228         FT_NONE, BASE_NONE, NULL, 0,
1229         NULL, HFILL }},
1230     { &hf_pkcs12_CertBag_PDU,
1231       { "CertBag", "pkcs12.CertBag_element",
1232         FT_NONE, BASE_NONE, NULL, 0,
1233         NULL, HFILL }},
1234     { &hf_pkcs12_CRLBag_PDU,
1235       { "CRLBag", "pkcs12.CRLBag_element",
1236         FT_NONE, BASE_NONE, NULL, 0,
1237         NULL, HFILL }},
1238     { &hf_pkcs12_SecretBag_PDU,
1239       { "SecretBag", "pkcs12.SecretBag_element",
1240         FT_NONE, BASE_NONE, NULL, 0,
1241         NULL, HFILL }},
1242     { &hf_pkcs12_PrivateKeyInfo_PDU,
1243       { "PrivateKeyInfo", "pkcs12.PrivateKeyInfo_element",
1244         FT_NONE, BASE_NONE, NULL, 0,
1245         NULL, HFILL }},
1246     { &hf_pkcs12_EncryptedPrivateKeyInfo_PDU,
1247       { "EncryptedPrivateKeyInfo", "pkcs12.EncryptedPrivateKeyInfo_element",
1248         FT_NONE, BASE_NONE, NULL, 0,
1249         NULL, HFILL }},
1250     { &hf_pkcs12_PBEParameter_PDU,
1251       { "PBEParameter", "pkcs12.PBEParameter_element",
1252         FT_NONE, BASE_NONE, NULL, 0,
1253         NULL, HFILL }},
1254     { &hf_pkcs12_PBKDF2Params_PDU,
1255       { "PBKDF2Params", "pkcs12.PBKDF2Params_element",
1256         FT_NONE, BASE_NONE, NULL, 0,
1257         NULL, HFILL }},
1258     { &hf_pkcs12_PBES2Params_PDU,
1259       { "PBES2Params", "pkcs12.PBES2Params_element",
1260         FT_NONE, BASE_NONE, NULL, 0,
1261         NULL, HFILL }},
1262     { &hf_pkcs12_PBMAC1Params_PDU,
1263       { "PBMAC1Params", "pkcs12.PBMAC1Params_element",
1264         FT_NONE, BASE_NONE, NULL, 0,
1265         NULL, HFILL }},
1266     { &hf_pkcs12_version,
1267       { "version", "pkcs12.version",
1268         FT_UINT32, BASE_DEC, VALS(pkcs12_T_version_vals), 0,
1269         NULL, HFILL }},
1270     { &hf_pkcs12_authSafe,
1271       { "authSafe", "pkcs12.authSafe_element",
1272         FT_NONE, BASE_NONE, NULL, 0,
1273         "ContentInfo", HFILL }},
1274     { &hf_pkcs12_macData,
1275       { "macData", "pkcs12.macData_element",
1276         FT_NONE, BASE_NONE, NULL, 0,
1277         NULL, HFILL }},
1278     { &hf_pkcs12_mac,
1279       { "mac", "pkcs12.mac_element",
1280         FT_NONE, BASE_NONE, NULL, 0,
1281         "DigestInfo", HFILL }},
1282     { &hf_pkcs12_macSalt,
1283       { "macSalt", "pkcs12.macSalt",
1284         FT_BYTES, BASE_NONE, NULL, 0,
1285         "OCTET_STRING", HFILL }},
1286     { &hf_pkcs12_iterations,
1287       { "iterations", "pkcs12.iterations",
1288         FT_INT32, BASE_DEC, NULL, 0,
1289         "INTEGER", HFILL }},
1290     { &hf_pkcs12_digestAlgorithm,
1291       { "digestAlgorithm", "pkcs12.digestAlgorithm_element",
1292         FT_NONE, BASE_NONE, NULL, 0,
1293         "DigestAlgorithmIdentifier", HFILL }},
1294     { &hf_pkcs12_digest,
1295       { "digest", "pkcs12.digest",
1296         FT_BYTES, BASE_NONE, NULL, 0,
1297         NULL, HFILL }},
1298     { &hf_pkcs12_AuthenticatedSafe_item,
1299       { "ContentInfo", "pkcs12.ContentInfo_element",
1300         FT_NONE, BASE_NONE, NULL, 0,
1301         NULL, HFILL }},
1302     { &hf_pkcs12_SafeContents_item,
1303       { "SafeBag", "pkcs12.SafeBag_element",
1304         FT_NONE, BASE_NONE, NULL, 0,
1305         NULL, HFILL }},
1306     { &hf_pkcs12_bagId,
1307       { "bagId", "pkcs12.bagId",
1308         FT_OID, BASE_NONE, NULL, 0,
1309         NULL, HFILL }},
1310     { &hf_pkcs12_bagValue,
1311       { "bagValue", "pkcs12.bagValue_element",
1312         FT_NONE, BASE_NONE, NULL, 0,
1313         NULL, HFILL }},
1314     { &hf_pkcs12_bagAttributes,
1315       { "bagAttributes", "pkcs12.bagAttributes",
1316         FT_UINT32, BASE_DEC, NULL, 0,
1317         "SET_OF_PKCS12Attribute", HFILL }},
1318     { &hf_pkcs12_bagAttributes_item,
1319       { "PKCS12Attribute", "pkcs12.PKCS12Attribute_element",
1320         FT_NONE, BASE_NONE, NULL, 0,
1321         NULL, HFILL }},
1322     { &hf_pkcs12_certId,
1323       { "certId", "pkcs12.certId",
1324         FT_OID, BASE_NONE, NULL, 0,
1325         NULL, HFILL }},
1326     { &hf_pkcs12_certValue,
1327       { "certValue", "pkcs12.certValue_element",
1328         FT_NONE, BASE_NONE, NULL, 0,
1329         NULL, HFILL }},
1330     { &hf_pkcs12_crlId,
1331       { "crlId", "pkcs12.crlId",
1332         FT_OID, BASE_NONE, NULL, 0,
1333         NULL, HFILL }},
1334     { &hf_pkcs12_crlValue,
1335       { "crlValue", "pkcs12.crlValue_element",
1336         FT_NONE, BASE_NONE, NULL, 0,
1337         NULL, HFILL }},
1338     { &hf_pkcs12_secretTypeId,
1339       { "secretTypeId", "pkcs12.secretTypeId",
1340         FT_OID, BASE_NONE, NULL, 0,
1341         NULL, HFILL }},
1342     { &hf_pkcs12_secretValue,
1343       { "secretValue", "pkcs12.secretValue_element",
1344         FT_NONE, BASE_NONE, NULL, 0,
1345         NULL, HFILL }},
1346     { &hf_pkcs12_attrId,
1347       { "attrId", "pkcs12.attrId",
1348         FT_OID, BASE_NONE, NULL, 0,
1349         NULL, HFILL }},
1350     { &hf_pkcs12_attrValues,
1351       { "attrValues", "pkcs12.attrValues",
1352         FT_UINT32, BASE_DEC, NULL, 0,
1353         NULL, HFILL }},
1354     { &hf_pkcs12_attrValues_item,
1355       { "attrValues item", "pkcs12.attrValues_item_element",
1356         FT_NONE, BASE_NONE, NULL, 0,
1357         NULL, HFILL }},
1358     { &hf_pkcs12_privateKeyVersion,
1359       { "version", "pkcs12.version",
1360         FT_UINT32, BASE_DEC, VALS(pkcs12_Version_vals), 0,
1361         NULL, HFILL }},
1362     { &hf_pkcs12_privateKeyAlgorithm,
1363       { "privateKeyAlgorithm", "pkcs12.privateKeyAlgorithm_element",
1364         FT_NONE, BASE_NONE, NULL, 0,
1365         "AlgorithmIdentifier", HFILL }},
1366     { &hf_pkcs12_privateKey,
1367       { "privateKey", "pkcs12.privateKey",
1368         FT_BYTES, BASE_NONE, NULL, 0,
1369         NULL, HFILL }},
1370     { &hf_pkcs12_attributes,
1371       { "attributes", "pkcs12.attributes",
1372         FT_UINT32, BASE_DEC, NULL, 0,
1373         NULL, HFILL }},
1374     { &hf_pkcs12_Attributes_item,
1375       { "Attribute", "pkcs12.Attribute_element",
1376         FT_NONE, BASE_NONE, NULL, 0,
1377         NULL, HFILL }},
1378     { &hf_pkcs12_encryptionAlgorithm,
1379       { "encryptionAlgorithm", "pkcs12.encryptionAlgorithm_element",
1380         FT_NONE, BASE_NONE, NULL, 0,
1381         "AlgorithmIdentifier", HFILL }},
1382     { &hf_pkcs12_encryptedData,
1383       { "encryptedData", "pkcs12.encryptedData",
1384         FT_BYTES, BASE_NONE, NULL, 0,
1385         NULL, HFILL }},
1386     { &hf_pkcs12_salt,
1387       { "salt", "pkcs12.salt",
1388         FT_BYTES, BASE_NONE, NULL, 0,
1389         "OCTET_STRING", HFILL }},
1390     { &hf_pkcs12_iterationCount,
1391       { "iterationCount", "pkcs12.iterationCount",
1392         FT_INT32, BASE_DEC, NULL, 0,
1393         "INTEGER", HFILL }},
1394     { &hf_pkcs12_saltChoice,
1395       { "salt", "pkcs12.salt",
1396         FT_UINT32, BASE_DEC, VALS(pkcs12_T_saltChoice_vals), 0,
1397         "T_saltChoice", HFILL }},
1398     { &hf_pkcs12_specified,
1399       { "specified", "pkcs12.specified",
1400         FT_BYTES, BASE_NONE, NULL, 0,
1401         "OCTET_STRING", HFILL }},
1402     { &hf_pkcs12_otherSource,
1403       { "otherSource", "pkcs12.otherSource_element",
1404         FT_NONE, BASE_NONE, NULL, 0,
1405         "AlgorithmIdentifier", HFILL }},
1406     { &hf_pkcs12_keyLength,
1407       { "keyLength", "pkcs12.keyLength",
1408         FT_UINT32, BASE_DEC, NULL, 0,
1409         "INTEGER_1_MAX", HFILL }},
1410     { &hf_pkcs12_prf,
1411       { "prf", "pkcs12.prf_element",
1412         FT_NONE, BASE_NONE, NULL, 0,
1413         "AlgorithmIdentifier", HFILL }},
1414     { &hf_pkcs12_keyDerivationFunc,
1415       { "keyDerivationFunc", "pkcs12.keyDerivationFunc_element",
1416         FT_NONE, BASE_NONE, NULL, 0,
1417         "AlgorithmIdentifier", HFILL }},
1418     { &hf_pkcs12_encryptionScheme,
1419       { "encryptionScheme", "pkcs12.encryptionScheme_element",
1420         FT_NONE, BASE_NONE, NULL, 0,
1421         "AlgorithmIdentifier", HFILL }},
1422     { &hf_pkcs12_messageAuthScheme,
1423       { "messageAuthScheme", "pkcs12.messageAuthScheme_element",
1424         FT_NONE, BASE_NONE, NULL, 0,
1425         "AlgorithmIdentifier", HFILL }},
1426
1427 /*--- End of included file: packet-pkcs12-hfarr.c ---*/
1428 #line 461 "../../asn1/pkcs12/packet-pkcs12-template.c"
1429   };
1430
1431   /* List of subtrees */
1432   static gint *ett[] = {
1433           &ett_decrypted_pbe,
1434
1435 /*--- Included file: packet-pkcs12-ettarr.c ---*/
1436 #line 1 "../../asn1/pkcs12/packet-pkcs12-ettarr.c"
1437     &ett_pkcs12_PFX,
1438     &ett_pkcs12_MacData,
1439     &ett_pkcs12_DigestInfo,
1440     &ett_pkcs12_AuthenticatedSafe,
1441     &ett_pkcs12_SafeContents,
1442     &ett_pkcs12_SafeBag,
1443     &ett_pkcs12_SET_OF_PKCS12Attribute,
1444     &ett_pkcs12_CertBag,
1445     &ett_pkcs12_CRLBag,
1446     &ett_pkcs12_SecretBag,
1447     &ett_pkcs12_PKCS12Attribute,
1448     &ett_pkcs12_T_attrValues,
1449     &ett_pkcs12_PrivateKeyInfo,
1450     &ett_pkcs12_Attributes,
1451     &ett_pkcs12_EncryptedPrivateKeyInfo,
1452     &ett_pkcs12_PBEParameter,
1453     &ett_pkcs12_PBKDF2Params,
1454     &ett_pkcs12_T_saltChoice,
1455     &ett_pkcs12_PBES2Params,
1456     &ett_pkcs12_PBMAC1Params,
1457
1458 /*--- End of included file: packet-pkcs12-ettarr.c ---*/
1459 #line 467 "../../asn1/pkcs12/packet-pkcs12-template.c"
1460   };
1461   module_t *pkcs12_module;
1462
1463   /* Register protocol */
1464   proto_pkcs12 = proto_register_protocol(PNAME, PSNAME, PFNAME);
1465
1466   /* Register fields and subtrees */
1467   proto_register_field_array(proto_pkcs12, hf, array_length(hf));
1468   proto_register_subtree_array(ett, array_length(ett));
1469
1470   /* Register preferences */
1471   pkcs12_module = prefs_register_protocol(proto_pkcs12, NULL);
1472
1473   prefs_register_string_preference(pkcs12_module, "password",
1474         "Password to decrypt the file with",
1475         "The password to used to decrypt the encrypted elements within"
1476         " the PKCS#12 file", &password);
1477
1478   prefs_register_bool_preference(pkcs12_module, "try_null_password",
1479         "Try to decrypt with a empty password",
1480         "Whether to try and decrypt the encrypted data within the"
1481         " PKCS#12 with a NULL password", &try_null_password);
1482
1483   register_ber_syntax_dissector("PKCS#12", proto_pkcs12, dissect_PFX_PDU);
1484   register_ber_oid_syntax(".p12", NULL, "PKCS#12");
1485   register_ber_oid_syntax(".pfx", NULL, "PKCS#12");
1486 }
1487
1488
1489 /*--- proto_reg_handoff_pkcs12 -------------------------------------------*/
1490 void proto_reg_handoff_pkcs12(void) {
1491
1492 /*--- Included file: packet-pkcs12-dis-tab.c ---*/
1493 #line 1 "../../asn1/pkcs12/packet-pkcs12-dis-tab.c"
1494   register_ber_oid_dissector("1.2.840.113549.1.12.10.1.1", dissect_KeyBag_PDU, proto_pkcs12, "keyBag");
1495   register_ber_oid_dissector("1.2.840.113549.1.12.10.1.2", dissect_PKCS8ShroudedKeyBag_PDU, proto_pkcs12, "pkcs8ShroudedKeyBag");
1496   register_ber_oid_dissector("1.2.840.113549.1.12.10.1.3", dissect_CertBag_PDU, proto_pkcs12, "certBag");
1497   register_ber_oid_dissector("1.2.840.113549.1.12.10.1.4", dissect_SecretBag_PDU, proto_pkcs12, "secretBag");
1498   register_ber_oid_dissector("1.2.840.113549.1.12.10.1.5", dissect_CRLBag_PDU, proto_pkcs12, "crlBag");
1499   register_ber_oid_dissector("1.2.840.113549.1.12.10.1.6", dissect_SafeContents_PDU, proto_pkcs12, "safeContentsBag");
1500   register_ber_oid_dissector("2.16.840.1.113730.3.1.216", dissect_PFX_PDU, proto_pkcs12, "pkcs-9-at-PKCS12");
1501   register_ber_oid_dissector("1.2.840.113549.1.9.25.2", dissect_EncryptedPrivateKeyInfo_PDU, proto_pkcs12, "pkcs-9-at-encryptedPrivateKeyInfo");
1502   register_ber_oid_dissector("1.2.840.113549.1.12.1.1", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithSHAAnd128BitRC4");
1503   register_ber_oid_dissector("1.2.840.113549.1.12.1.2", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithSHAAnd40BitRC4");
1504   register_ber_oid_dissector("1.2.840.113549.1.12.1.3", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithSHAAnd3-KeyTripleDES-CBC");
1505   register_ber_oid_dissector("1.2.840.113549.1.12.1.4", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithSHAAnd2-KeyTripleDES-CBC");
1506   register_ber_oid_dissector("1.2.840.113549.1.12.1.5", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithSHAAnd128BitRC2-CBC");
1507   register_ber_oid_dissector("1.2.840.113549.1.12.1.6", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithSHAAnd128BitRC2-CBC");
1508   register_ber_oid_dissector("1.2.840.113549.1.5.1", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithMD2AndDES-CBC");
1509   register_ber_oid_dissector("1.2.840.113549.1.5.3", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithMD5AndDES-CBC");
1510   register_ber_oid_dissector("1.2.840.113549.1.5.4", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithMD2AndRC2-CBC");
1511   register_ber_oid_dissector("1.2.840.113549.1.5.6", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithMD5AndRC2-CBC");
1512   register_ber_oid_dissector("1.2.840.113549.1.5.10", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithSHA1AndDES-CBC");
1513   register_ber_oid_dissector("1.2.840.113549.1.5.11", dissect_PBEParameter_PDU, proto_pkcs12, "pbeWithSHA1AndRC2-CBC");
1514   register_ber_oid_dissector("1.2.840.113549.1.5.12", dissect_PBKDF2Params_PDU, proto_pkcs12, "id-PBKDF2");
1515   register_ber_oid_dissector("1.2.840.113549.1.5.13", dissect_PBES2Params_PDU, proto_pkcs12, "id-PBES2");
1516   register_ber_oid_dissector("1.2.840.113549.1.5.14", dissect_PBMAC1Params_PDU, proto_pkcs12, "id-PBMAC1");
1517
1518
1519 /*--- End of included file: packet-pkcs12-dis-tab.c ---*/
1520 #line 499 "../../asn1/pkcs12/packet-pkcs12-template.c"
1521
1522         register_ber_oid_dissector("1.2.840.113549.1.9.22.1", dissect_X509Certificate_OCTETSTRING_PDU, proto_pkcs12, "x509Certificate");
1523
1524 }
1525