internal.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* Copyright (c) 2014, Google Inc.
  2. *
  3. * Permission to use, copy, modify, and/or distribute this software for any
  4. * purpose with or without fee is hereby granted, provided that the above
  5. * copyright notice and this permission notice appear in all copies.
  6. *
  7. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  10. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  12. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
  14. #ifndef OPENSSL_HEADER_TOOL_INTERNAL_H
  15. #define OPENSSL_HEADER_TOOL_INTERNAL_H
  16. #include <openssl/base.h>
  17. #include <string>
  18. #include <vector>
  19. OPENSSL_MSVC_PRAGMA(warning(push))
  20. // MSVC issues warning C4702 for unreachable code in its xtree header when
  21. // compiling with -D_HAS_EXCEPTIONS=0. See
  22. // https://connect.microsoft.com/VisualStudio/feedback/details/809962
  23. OPENSSL_MSVC_PRAGMA(warning(disable: 4702))
  24. #include <map>
  25. OPENSSL_MSVC_PRAGMA(warning(pop))
  26. #if defined(OPENSSL_WINDOWS)
  27. #define BORINGSSL_OPEN _open
  28. #define BORINGSSL_FDOPEN _fdopen
  29. #define BORINGSSL_CLOSE _close
  30. #define BORINGSSL_READ _read
  31. #define BORINGSSL_WRITE _write
  32. #else
  33. #define BORINGSSL_OPEN open
  34. #define BORINGSSL_FDOPEN fdopen
  35. #define BORINGSSL_CLOSE close
  36. #define BORINGSSL_READ read
  37. #define BORINGSSL_WRITE write
  38. #endif
  39. struct FileCloser {
  40. void operator()(FILE *file) {
  41. fclose(file);
  42. }
  43. };
  44. using ScopedFILE = std::unique_ptr<FILE, FileCloser>;
  45. enum ArgumentType {
  46. kRequiredArgument,
  47. kOptionalArgument,
  48. kBooleanArgument,
  49. };
  50. struct argument {
  51. const char *name;
  52. ArgumentType type;
  53. const char *description;
  54. };
  55. bool ParseKeyValueArguments(std::map<std::string, std::string> *out_args, const
  56. std::vector<std::string> &args, const struct argument *templates);
  57. void PrintUsage(const struct argument *templates);
  58. bool GetUnsigned(unsigned *out, const std::string &arg_name,
  59. unsigned default_value,
  60. const std::map<std::string, std::string> &args);
  61. bool ReadAll(std::vector<uint8_t> *out, FILE *in);
  62. bool Ciphers(const std::vector<std::string> &args);
  63. bool Client(const std::vector<std::string> &args);
  64. bool DoPKCS12(const std::vector<std::string> &args);
  65. bool GenerateEd25519Key(const std::vector<std::string> &args);
  66. bool GenerateRSAKey(const std::vector<std::string> &args);
  67. bool MD5Sum(const std::vector<std::string> &args);
  68. bool Rand(const std::vector<std::string> &args);
  69. bool SHA1Sum(const std::vector<std::string> &args);
  70. bool SHA224Sum(const std::vector<std::string> &args);
  71. bool SHA256Sum(const std::vector<std::string> &args);
  72. bool SHA384Sum(const std::vector<std::string> &args);
  73. bool SHA512Sum(const std::vector<std::string> &args);
  74. bool Server(const std::vector<std::string> &args);
  75. bool Sign(const std::vector<std::string> &args);
  76. bool Speed(const std::vector<std::string> &args);
  77. // These values are DER encoded, RSA private keys.
  78. extern const uint8_t kDERRSAPrivate2048[];
  79. extern const size_t kDERRSAPrivate2048Len;
  80. extern const uint8_t kDERRSAPrivate4096[];
  81. extern const size_t kDERRSAPrivate4096Len;
  82. #endif // !OPENSSL_HEADER_TOOL_INTERNAL_H