pkcs12_helper.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <stdlib.h>
  12. #include "internal/nelem.h"
  13. #include <openssl/pkcs12.h>
  14. #include <openssl/x509.h>
  15. #include <openssl/x509v3.h>
  16. #include <openssl/pem.h>
  17. #include "testutil.h"
  18. /* Set this to > 0 write test data to file */
  19. extern int write_files;
  20. /* -------------------------------------------------------------------------
  21. * PKCS#12 Test structures
  22. */
  23. /* Holds a set of Attributes */
  24. typedef struct pkcs12_attr {
  25. char *oid;
  26. char *value;
  27. } PKCS12_ATTR;
  28. /* Holds encryption parameters */
  29. typedef struct pkcs12_enc {
  30. int nid;
  31. char *pass;
  32. int iter;
  33. } PKCS12_ENC;
  34. /* Set of variables required for constructing the PKCS#12 structure */
  35. typedef struct pkcs12_builder {
  36. const char *filename;
  37. int success;
  38. BIO *p12bio;
  39. STACK_OF(PKCS7) *safes;
  40. int safe_idx;
  41. STACK_OF(PKCS12_SAFEBAG) *bags;
  42. int bag_idx;
  43. } PKCS12_BUILDER;
  44. /* -------------------------------------------------------------------------
  45. * PKCS#12 Test function declarations
  46. */
  47. /* Allocate and initialise a PKCS#12 builder object */
  48. PKCS12_BUILDER *new_pkcs12_builder(const char *filename);
  49. /* Finalise and free the PKCS#12 builder object, returning the success/fail flag */
  50. int end_pkcs12_builder(PKCS12_BUILDER *pb);
  51. /* Encode/build functions */
  52. void start_pkcs12(PKCS12_BUILDER *pb);
  53. void end_pkcs12(PKCS12_BUILDER *pb);
  54. void end_pkcs12_with_mac(PKCS12_BUILDER *pb, const PKCS12_ENC *mac);
  55. void start_contentinfo(PKCS12_BUILDER *pb);
  56. void end_contentinfo(PKCS12_BUILDER *pb);
  57. void end_contentinfo_encrypted(PKCS12_BUILDER *pb, const PKCS12_ENC *enc);
  58. void add_certbag(PKCS12_BUILDER *pb, const unsigned char *bytes, int len,
  59. const PKCS12_ATTR *attrs);
  60. void add_keybag(PKCS12_BUILDER *pb, const unsigned char *bytes, int len,
  61. const PKCS12_ATTR *attrs, const PKCS12_ENC *enc);
  62. void add_secretbag(PKCS12_BUILDER *pb, int secret_nid, const char *secret,
  63. const PKCS12_ATTR *attrs);
  64. /* Decode/check functions */
  65. void start_check_pkcs12(PKCS12_BUILDER *pb);
  66. void start_check_pkcs12_with_mac(PKCS12_BUILDER *pb, const PKCS12_ENC *mac);
  67. void start_check_pkcs12_file(PKCS12_BUILDER *pb);
  68. void start_check_pkcs12_file_with_mac(PKCS12_BUILDER *pb, const PKCS12_ENC *mac);
  69. void end_check_pkcs12(PKCS12_BUILDER *pb);
  70. void start_check_contentinfo(PKCS12_BUILDER *pb);
  71. void start_check_contentinfo_encrypted(PKCS12_BUILDER *pb, const PKCS12_ENC *enc);
  72. void end_check_contentinfo(PKCS12_BUILDER *pb);
  73. void check_certbag(PKCS12_BUILDER *pb, const unsigned char *bytes, int len,
  74. const PKCS12_ATTR *attrs);
  75. void check_keybag(PKCS12_BUILDER *pb, const unsigned char *bytes, int len,
  76. const PKCS12_ATTR *attrs, const PKCS12_ENC *enc);
  77. void check_secretbag(PKCS12_BUILDER *pb, int secret_nid, const char *secret,
  78. const PKCS12_ATTR *attrs);