allquestions.c 2.6 KB

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