Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

rootcert.c 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. */
  19. FILE_LICENCE ( GPL2_OR_LATER );
  20. #include <stdlib.h>
  21. #include <ipxe/crypto.h>
  22. #include <ipxe/sha256.h>
  23. #include <ipxe/x509.h>
  24. #include <ipxe/settings.h>
  25. #include <ipxe/dhcp.h>
  26. #include <ipxe/init.h>
  27. #include <ipxe/rootcert.h>
  28. /** @file
  29. *
  30. * Root certificate store
  31. *
  32. */
  33. /** Length of a root certificate fingerprint */
  34. #define FINGERPRINT_LEN SHA256_DIGEST_SIZE
  35. /* Allow trusted certificates to be overridden if not explicitly specified */
  36. #ifdef TRUSTED
  37. #define ALLOW_TRUST_OVERRIDE 0
  38. #else
  39. #define ALLOW_TRUST_OVERRIDE 1
  40. #endif
  41. /* Use iPXE root CA if no trusted certificates are explicitly specified */
  42. #ifndef TRUSTED
  43. #define TRUSTED \
  44. /* iPXE root CA */ \
  45. 0x9f, 0xaf, 0x71, 0x7b, 0x7f, 0x8c, 0xa2, 0xf9, 0x3c, 0x25, \
  46. 0x6c, 0x79, 0xf8, 0xac, 0x55, 0x91, 0x89, 0x5d, 0x66, 0xd1, \
  47. 0xff, 0x3b, 0xee, 0x63, 0x97, 0xa7, 0x0d, 0x29, 0xc6, 0x5e, \
  48. 0xed, 0x1a,
  49. #endif
  50. /** Root certificate fingerprints */
  51. static const uint8_t fingerprints[] = { TRUSTED };
  52. /** Root certificate fingerprint setting */
  53. static struct setting trust_setting __setting ( SETTING_CRYPTO, trust ) = {
  54. .name = "trust",
  55. .description = "Trusted root certificate fingerprints",
  56. .tag = DHCP_EB_TRUST,
  57. .type = &setting_type_hex,
  58. };
  59. /** Root certificates */
  60. struct x509_root root_certificates = {
  61. .digest = &sha256_algorithm,
  62. .count = ( sizeof ( fingerprints ) / FINGERPRINT_LEN ),
  63. .fingerprints = fingerprints,
  64. };
  65. /**
  66. * Initialise root certificate
  67. *
  68. * The list of trusted root certificates can be specified at build
  69. * time using the TRUST= build parameter. If no certificates are
  70. * specified, then the default iPXE root CA certificate is trusted.
  71. *
  72. * If no certificates were explicitly specified, then we allow the
  73. * list of trusted root certificate fingerprints to be overridden
  74. * using the "trust" setting, but only at the point of iPXE
  75. * initialisation. This prevents untrusted sources of settings
  76. * (e.g. DHCP) from subverting the chain of trust, while allowing
  77. * trustworthy sources (e.g. VMware GuestInfo or non-volatile stored
  78. * options) to specify the trusted root certificate without requiring
  79. * a rebuild.
  80. */
  81. static void rootcert_init ( void ) {
  82. void *external = NULL;
  83. int len;
  84. /* Allow trusted root certificates to be overridden only if
  85. * not explicitly specified at build time.
  86. */
  87. if ( ALLOW_TRUST_OVERRIDE ) {
  88. /* Fetch copy of "trust" setting, if it exists. This
  89. * memory will never be freed.
  90. */
  91. if ( ( len = fetch_raw_setting_copy ( NULL, &trust_setting,
  92. &external ) ) >= 0 ) {
  93. root_certificates.fingerprints = external;
  94. root_certificates.count = ( len / FINGERPRINT_LEN );
  95. }
  96. }
  97. DBGC ( &root_certificates, "ROOTCERT using %d %s certificate(s):\n",
  98. root_certificates.count, ( external ? "external" : "built-in" ));
  99. DBGC_HDA ( &root_certificates, 0, root_certificates.fingerprints,
  100. ( root_certificates.count * FINGERPRINT_LEN ) );
  101. }
  102. /** Root certificate initialiser */
  103. struct init_fn rootcert_init_fn __init_fn ( INIT_LATE ) = {
  104. .initialise = rootcert_init,
  105. };