pkcs12.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright 2020-2021 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. /* -------------------------------------------------------------------------
  19. * PKCS#12 Test structures
  20. */
  21. /* Holds a set of Attributes */
  22. typedef struct pkcs12_attr {
  23. char *oid;
  24. char *value;
  25. } PKCS12_ATTR;
  26. /* Holds encryption parameters */
  27. typedef struct pkcs12_enc {
  28. int nid;
  29. const char *pass;
  30. int iter;
  31. } PKCS12_ENC;
  32. /* Set of variables required for constructing the PKCS#12 structure */
  33. typedef struct pkcs12_builder {
  34. const char *filename;
  35. int success;
  36. BIO *p12bio;
  37. STACK_OF(PKCS7) *safes;
  38. int safe_idx;
  39. STACK_OF(PKCS12_SAFEBAG) *bags;
  40. int bag_idx;
  41. } PKCS12_BUILDER;
  42. /* -------------------------------------------------------------------------
  43. * PKCS#12 Test function declarations
  44. */
  45. /* Global settings */
  46. void PKCS12_helper_set_write_files(int enable);
  47. void PKCS12_helper_set_legacy(int enable);
  48. void PKCS12_helper_set_libctx(OSSL_LIB_CTX *libctx);
  49. void PKCS12_helper_set_propq(const char *propq);
  50. /* Allocate and initialise a PKCS#12 builder object */
  51. PKCS12_BUILDER *new_pkcs12_builder(const char *filename);
  52. /* Finalise and free the PKCS#12 builder object, returning the success/fail flag */
  53. int end_pkcs12_builder(PKCS12_BUILDER *pb);
  54. /* Encode/build functions */
  55. void start_pkcs12(PKCS12_BUILDER *pb);
  56. void end_pkcs12(PKCS12_BUILDER *pb);
  57. void end_pkcs12_with_mac(PKCS12_BUILDER *pb, const PKCS12_ENC *mac);
  58. void start_contentinfo(PKCS12_BUILDER *pb);
  59. void end_contentinfo(PKCS12_BUILDER *pb);
  60. void end_contentinfo_encrypted(PKCS12_BUILDER *pb, const PKCS12_ENC *enc);
  61. void add_certbag(PKCS12_BUILDER *pb, const unsigned char *bytes, int len,
  62. const PKCS12_ATTR *attrs);
  63. void add_keybag(PKCS12_BUILDER *pb, const unsigned char *bytes, int len,
  64. const PKCS12_ATTR *attrs, const PKCS12_ENC *enc);
  65. void add_secretbag(PKCS12_BUILDER *pb, int secret_nid, const char *secret,
  66. const PKCS12_ATTR *attrs);
  67. void add_extra_attr(PKCS12_BUILDER *pb);
  68. /* Decode/check functions */
  69. void start_check_pkcs12(PKCS12_BUILDER *pb);
  70. void start_check_pkcs12_with_mac(PKCS12_BUILDER *pb, const PKCS12_ENC *mac);
  71. void start_check_pkcs12_file(PKCS12_BUILDER *pb);
  72. void start_check_pkcs12_file_with_mac(PKCS12_BUILDER *pb, const PKCS12_ENC *mac);
  73. void end_check_pkcs12(PKCS12_BUILDER *pb);
  74. void start_check_contentinfo(PKCS12_BUILDER *pb);
  75. void start_check_contentinfo_encrypted(PKCS12_BUILDER *pb, const PKCS12_ENC *enc);
  76. void end_check_contentinfo(PKCS12_BUILDER *pb);
  77. void check_certbag(PKCS12_BUILDER *pb, const unsigned char *bytes, int len,
  78. const PKCS12_ATTR *attrs);
  79. void check_keybag(PKCS12_BUILDER *pb, const unsigned char *bytes, int len,
  80. const PKCS12_ATTR *attrs, const PKCS12_ENC *enc);
  81. void check_secretbag(PKCS12_BUILDER *pb, int secret_nid, const char *secret,
  82. const PKCS12_ATTR *attrs);