x_req.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (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 "internal/cryptlib.h"
  11. #include <openssl/asn1t.h>
  12. #include <openssl/x509.h>
  13. #include "internal/x509_int.h"
  14. /*-
  15. * X509_REQ_INFO is handled in an unusual way to get round
  16. * invalid encodings. Some broken certificate requests don't
  17. * encode the attributes field if it is empty. This is in
  18. * violation of PKCS#10 but we need to tolerate it. We do
  19. * this by making the attributes field OPTIONAL then using
  20. * the callback to initialise it to an empty STACK.
  21. *
  22. * This means that the field will be correctly encoded unless
  23. * we NULL out the field.
  24. *
  25. * As a result we no longer need the req_kludge field because
  26. * the information is now contained in the attributes field:
  27. * 1. If it is NULL then it's the invalid omission.
  28. * 2. If it is empty it is the correct encoding.
  29. * 3. If it is not empty then some attributes are present.
  30. *
  31. */
  32. static int rinf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
  33. void *exarg)
  34. {
  35. X509_REQ_INFO *rinf = (X509_REQ_INFO *)*pval;
  36. if (operation == ASN1_OP_NEW_POST) {
  37. rinf->attributes = sk_X509_ATTRIBUTE_new_null();
  38. if (!rinf->attributes)
  39. return 0;
  40. }
  41. return 1;
  42. }
  43. ASN1_SEQUENCE_enc(X509_REQ_INFO, enc, rinf_cb) = {
  44. ASN1_SIMPLE(X509_REQ_INFO, version, ASN1_INTEGER),
  45. ASN1_SIMPLE(X509_REQ_INFO, subject, X509_NAME),
  46. ASN1_SIMPLE(X509_REQ_INFO, pubkey, X509_PUBKEY),
  47. /* This isn't really OPTIONAL but it gets round invalid
  48. * encodings
  49. */
  50. ASN1_IMP_SET_OF_OPT(X509_REQ_INFO, attributes, X509_ATTRIBUTE, 0)
  51. } ASN1_SEQUENCE_END_enc(X509_REQ_INFO, X509_REQ_INFO)
  52. IMPLEMENT_ASN1_FUNCTIONS(X509_REQ_INFO)
  53. ASN1_SEQUENCE_ref(X509_REQ, 0) = {
  54. ASN1_EMBED(X509_REQ, req_info, X509_REQ_INFO),
  55. ASN1_EMBED(X509_REQ, sig_alg, X509_ALGOR),
  56. ASN1_SIMPLE(X509_REQ, signature, ASN1_BIT_STRING)
  57. } ASN1_SEQUENCE_END_ref(X509_REQ, X509_REQ)
  58. IMPLEMENT_ASN1_FUNCTIONS(X509_REQ)
  59. IMPLEMENT_ASN1_DUP_FUNCTION(X509_REQ)