allquestions.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * \file allquestions.c
  3. *
  4. * \brief Quetions controller.
  5. *
  6. * Implements procedures for addign and removing questions from the global \ref
  7. * questions variable.
  8. */
  9. #include "config.h"
  10. #include <assert.h>
  11. #include <string.h>
  12. #include <bsd/sys/queue.h>
  13. #include <openssl/x509.h>
  14. #include <openssl/rsa.h>
  15. #include <openssl/ssl.h>
  16. #include <mpi.h>
  17. #include "qa/questions/questions.h"
  18. void QA_library_init(void)
  19. {
  20. /* Initialize SSL Library by registering algorithms. */
  21. SSL_library_init();
  22. SSL_load_error_strings();
  23. #ifdef HAVE_OPENMPI
  24. /* OpenMPI initialization */
  25. MPI_Init(0 , NULL);
  26. #endif
  27. }
  28. /**
  29. * \brief Select a single question to be used.
  30. *
  31. */
  32. void select_question(const char *sq)
  33. {
  34. qa_question_t *q, *tmpq;
  35. select_all_questions();
  36. assert(questions.lh_first);
  37. LIST_FOREACH_SAFE(q, &questions, qs, tmpq)
  38. if (strcmp(q->name, sq))
  39. LIST_REMOVE(q, qs);
  40. }
  41. /**
  42. * \brief Run a specific question, returning the measure of security probed.
  43. * \return -1 if the question `q` is not suited for attacking the certificate.
  44. * -2 if there has been a problem setting up the given question
  45. * -3 if there has been a problem shutting down the given question
  46. * 0 if the certificate/key is considered secure.
  47. * 1.. attack measure.
  48. *
  49. */
  50. int run_question(qa_question_t *q, X509 *crt, RSA *pub)
  51. {
  52. RSA *priv;
  53. /* Run setup, if any */
  54. if (q->setup && q->setup() <= 0)
  55. return -2;
  56. /* Run test, if any. */
  57. if (q->test && q->test(crt) < 0)
  58. return -1;
  59. /* Attempt to attack the X509 certificate. */
  60. if (crt && q->ask_crt)
  61. q->ask_crt(crt);
  62. /* Attempt to attack the RSA public key */
  63. if (q->ask_rsa &&
  64. (priv = q->ask_rsa(pub))) {
  65. #ifdef DEBUG
  66. PEM_write_RSAPrivateKey(stdout, priv, NULL, NULL, 0, NULL, NULL);
  67. #endif
  68. RSA_free(priv);
  69. return 1;
  70. }
  71. /* Shut down the given question. */
  72. if (q->teardown && q->teardown() <= 0)
  73. return -3;
  74. return 0;
  75. }
  76. /**
  77. * \brief Puts registered questions into \ref questions.
  78. *
  79. * Disposes all registered questions into a global linked list, so that future
  80. * procedures can iterate over all possible tests.
  81. */
  82. void select_all_questions(void)
  83. {
  84. LIST_INIT(&questions);
  85. REGISTER_QUESTION(ExampleQuestion);
  86. REGISTER_QUESTION(WienerQuestion);
  87. REGISTER_QUESTION(PollardQuestion);
  88. REGISTER_QUESTION(FermatQuestion);
  89. REGISTER_QUESTION(MetadataQuestion);
  90. REGISTER_QUESTION(PollardRhoQuestion);
  91. REGISTER_QUESTION(WilliamsQuestion);
  92. REGISTER_QUESTION(DixonQuestion);
  93. REGISTER_QUESTION(PollardBrentRhoQuestion);
  94. }