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