Adam Langley | aacec17 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 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 | |
| 15 | #ifndef OPENSSL_HEADER_TOOL_INTERNAL_H |
| 16 | #define OPENSSL_HEADER_TOOL_INTERNAL_H |
| 17 | |
Adam Langley | 3d960e5 | 2015-06-08 14:52:13 -0700 | [diff] [blame] | 18 | #include <openssl/base.h> |
| 19 | |
Adam Langley | aacec17 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 20 | #include <string> |
| 21 | #include <vector> |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 22 | |
David Benjamin | a353cdb | 2016-06-09 16:48:33 -0400 | [diff] [blame] | 23 | OPENSSL_MSVC_PRAGMA(warning(push)) |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 24 | // MSVC issues warning C4702 for unreachable code in its xtree header when |
| 25 | // compiling with -D_HAS_EXCEPTIONS=0. See |
| 26 | // https://connect.microsoft.com/VisualStudio/feedback/details/809962 |
David Benjamin | a353cdb | 2016-06-09 16:48:33 -0400 | [diff] [blame] | 27 | OPENSSL_MSVC_PRAGMA(warning(disable: 4702)) |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 28 | |
Adam Langley | aacec17 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 29 | #include <map> |
| 30 | |
David Benjamin | a353cdb | 2016-06-09 16:48:33 -0400 | [diff] [blame] | 31 | OPENSSL_MSVC_PRAGMA(warning(pop)) |
Adam Langley | aacec17 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 32 | |
nmittler | f0322b2 | 2016-05-19 08:49:59 -0700 | [diff] [blame] | 33 | #if defined(OPENSSL_WINDOWS) |
| 34 | #define BORINGSSL_OPEN _open |
| 35 | #define BORINGSSL_FDOPEN _fdopen |
| 36 | #define BORINGSSL_CLOSE _close |
| 37 | #define BORINGSSL_READ _read |
| 38 | #define BORINGSSL_WRITE _write |
| 39 | #else |
| 40 | #define BORINGSSL_OPEN open |
| 41 | #define BORINGSSL_FDOPEN fdopen |
| 42 | #define BORINGSSL_CLOSE close |
| 43 | #define BORINGSSL_READ read |
| 44 | #define BORINGSSL_WRITE write |
| 45 | #endif |
| 46 | |
Steven Valdez | 1530ef3 | 2017-11-30 12:02:42 -0500 | [diff] [blame] | 47 | struct FileCloser { |
| 48 | void operator()(FILE *file) { |
| 49 | fclose(file); |
| 50 | } |
| 51 | }; |
| 52 | |
| 53 | using ScopedFILE = std::unique_ptr<FILE, FileCloser>; |
| 54 | |
David Benjamin | 0570923 | 2015-03-23 19:01:33 -0400 | [diff] [blame] | 55 | enum ArgumentType { |
| 56 | kRequiredArgument, |
| 57 | kOptionalArgument, |
| 58 | kBooleanArgument, |
| 59 | }; |
| 60 | |
Adam Langley | aacec17 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 61 | struct argument { |
David Benjamin | 0570923 | 2015-03-23 19:01:33 -0400 | [diff] [blame] | 62 | const char *name; |
| 63 | ArgumentType type; |
Adam Langley | aacec17 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 64 | const char *description; |
| 65 | }; |
| 66 | |
| 67 | bool ParseKeyValueArguments(std::map<std::string, std::string> *out_args, const |
| 68 | std::vector<std::string> &args, const struct argument *templates); |
| 69 | |
| 70 | void PrintUsage(const struct argument *templates); |
| 71 | |
Adam Langley | 839b881 | 2015-05-26 11:36:46 -0700 | [diff] [blame] | 72 | bool GetUnsigned(unsigned *out, const std::string &arg_name, |
| 73 | unsigned default_value, |
| 74 | const std::map<std::string, std::string> &args); |
| 75 | |
David Benjamin | 4e78e30 | 2017-03-30 10:16:07 -0500 | [diff] [blame] | 76 | bool ReadAll(std::vector<uint8_t> *out, FILE *in); |
| 77 | |
Piotr Sikora | f932894 | 2016-03-18 18:24:50 -0700 | [diff] [blame] | 78 | bool Ciphers(const std::vector<std::string> &args); |
| 79 | bool Client(const std::vector<std::string> &args); |
| 80 | bool DoPKCS12(const std::vector<std::string> &args); |
| 81 | bool GenerateEd25519Key(const std::vector<std::string> &args); |
| 82 | bool GenerateRSAKey(const std::vector<std::string> &args); |
| 83 | bool MD5Sum(const std::vector<std::string> &args); |
| 84 | bool Rand(const std::vector<std::string> &args); |
| 85 | bool SHA1Sum(const std::vector<std::string> &args); |
| 86 | bool SHA224Sum(const std::vector<std::string> &args); |
| 87 | bool SHA256Sum(const std::vector<std::string> &args); |
| 88 | bool SHA384Sum(const std::vector<std::string> &args); |
| 89 | bool SHA512Sum(const std::vector<std::string> &args); |
| 90 | bool Server(const std::vector<std::string> &args); |
David Benjamin | 4e78e30 | 2017-03-30 10:16:07 -0500 | [diff] [blame] | 91 | bool Sign(const std::vector<std::string> &args); |
Piotr Sikora | f932894 | 2016-03-18 18:24:50 -0700 | [diff] [blame] | 92 | bool Speed(const std::vector<std::string> &args); |
| 93 | |
David Benjamin | 58084af | 2015-06-07 00:25:15 -0400 | [diff] [blame] | 94 | // These values are DER encoded, RSA private keys. |
| 95 | extern const uint8_t kDERRSAPrivate2048[]; |
| 96 | extern const size_t kDERRSAPrivate2048Len; |
| 97 | extern const uint8_t kDERRSAPrivate4096[]; |
| 98 | extern const size_t kDERRSAPrivate4096Len; |
David Benjamin | 58084af | 2015-06-07 00:25:15 -0400 | [diff] [blame] | 99 | |
Adam Langley | aacec17 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 100 | |
David Benjamin | e2daba6 | 2017-08-17 20:12:08 -0400 | [diff] [blame] | 101 | #endif // !OPENSSL_HEADER_TOOL_INTERNAL_H |