eng_fat.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
  4. *
  5. * Licensed under the Apache License 2.0 (the "License"). You may not use
  6. * this file except in compliance with the License. You can obtain a copy
  7. * in the file LICENSE in the source distribution or at
  8. * https://www.openssl.org/source/license.html
  9. */
  10. #include "eng_int.h"
  11. #include <openssl/conf.h>
  12. int ENGINE_set_default(ENGINE *e, unsigned int flags)
  13. {
  14. if ((flags & ENGINE_METHOD_CIPHERS) && !ENGINE_set_default_ciphers(e))
  15. return 0;
  16. if ((flags & ENGINE_METHOD_DIGESTS) && !ENGINE_set_default_digests(e))
  17. return 0;
  18. #ifndef OPENSSL_NO_RSA
  19. if ((flags & ENGINE_METHOD_RSA) && !ENGINE_set_default_RSA(e))
  20. return 0;
  21. #endif
  22. #ifndef OPENSSL_NO_DSA
  23. if ((flags & ENGINE_METHOD_DSA) && !ENGINE_set_default_DSA(e))
  24. return 0;
  25. #endif
  26. #ifndef OPENSSL_NO_DH
  27. if ((flags & ENGINE_METHOD_DH) && !ENGINE_set_default_DH(e))
  28. return 0;
  29. #endif
  30. #ifndef OPENSSL_NO_EC
  31. if ((flags & ENGINE_METHOD_EC) && !ENGINE_set_default_EC(e))
  32. return 0;
  33. #endif
  34. if ((flags & ENGINE_METHOD_RAND) && !ENGINE_set_default_RAND(e))
  35. return 0;
  36. if ((flags & ENGINE_METHOD_PKEY_METHS)
  37. && !ENGINE_set_default_pkey_meths(e))
  38. return 0;
  39. if ((flags & ENGINE_METHOD_PKEY_ASN1_METHS)
  40. && !ENGINE_set_default_pkey_asn1_meths(e))
  41. return 0;
  42. return 1;
  43. }
  44. /* Set default algorithms using a string */
  45. static int int_def_cb(const char *alg, int len, void *arg)
  46. {
  47. unsigned int *pflags = arg;
  48. if (alg == NULL)
  49. return 0;
  50. if (strncmp(alg, "ALL", len) == 0)
  51. *pflags |= ENGINE_METHOD_ALL;
  52. else if (strncmp(alg, "RSA", len) == 0)
  53. *pflags |= ENGINE_METHOD_RSA;
  54. else if (strncmp(alg, "DSA", len) == 0)
  55. *pflags |= ENGINE_METHOD_DSA;
  56. else if (strncmp(alg, "DH", len) == 0)
  57. *pflags |= ENGINE_METHOD_DH;
  58. else if (strncmp(alg, "EC", len) == 0)
  59. *pflags |= ENGINE_METHOD_EC;
  60. else if (strncmp(alg, "RAND", len) == 0)
  61. *pflags |= ENGINE_METHOD_RAND;
  62. else if (strncmp(alg, "CIPHERS", len) == 0)
  63. *pflags |= ENGINE_METHOD_CIPHERS;
  64. else if (strncmp(alg, "DIGESTS", len) == 0)
  65. *pflags |= ENGINE_METHOD_DIGESTS;
  66. else if (strncmp(alg, "PKEY", len) == 0)
  67. *pflags |= ENGINE_METHOD_PKEY_METHS | ENGINE_METHOD_PKEY_ASN1_METHS;
  68. else if (strncmp(alg, "PKEY_CRYPTO", len) == 0)
  69. *pflags |= ENGINE_METHOD_PKEY_METHS;
  70. else if (strncmp(alg, "PKEY_ASN1", len) == 0)
  71. *pflags |= ENGINE_METHOD_PKEY_ASN1_METHS;
  72. else
  73. return 0;
  74. return 1;
  75. }
  76. int ENGINE_set_default_string(ENGINE *e, const char *def_list)
  77. {
  78. unsigned int flags = 0;
  79. if (!CONF_parse_list(def_list, ',', 1, int_def_cb, &flags)) {
  80. ENGINEerr(ENGINE_F_ENGINE_SET_DEFAULT_STRING,
  81. ENGINE_R_INVALID_STRING);
  82. ERR_add_error_data(2, "str=", def_list);
  83. return 0;
  84. }
  85. return ENGINE_set_default(e, flags);
  86. }
  87. int ENGINE_register_complete(ENGINE *e)
  88. {
  89. ENGINE_register_ciphers(e);
  90. ENGINE_register_digests(e);
  91. #ifndef OPENSSL_NO_RSA
  92. ENGINE_register_RSA(e);
  93. #endif
  94. #ifndef OPENSSL_NO_DSA
  95. ENGINE_register_DSA(e);
  96. #endif
  97. #ifndef OPENSSL_NO_DH
  98. ENGINE_register_DH(e);
  99. #endif
  100. #ifndef OPENSSL_NO_EC
  101. ENGINE_register_EC(e);
  102. #endif
  103. ENGINE_register_RAND(e);
  104. ENGINE_register_pkey_meths(e);
  105. ENGINE_register_pkey_asn1_meths(e);
  106. return 1;
  107. }
  108. int ENGINE_register_all_complete(void)
  109. {
  110. ENGINE *e;
  111. for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
  112. if (!(e->flags & ENGINE_FLAGS_NO_REGISTER_ALL))
  113. ENGINE_register_complete(e);
  114. return 1;
  115. }