Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
Crypto.h
Go to the documentation of this file.
1//
2// Crypto.h
3//
4// Library: Crypto
5// Package: CryptoCore
6// Module: Crypto
7//
8// Basic definitions for the Poco Crypto library.
9// This file must be the first file included by every other Crypto
10// header file.
11//
12// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
13// and Contributors.
14//
15// SPDX-License-Identifier: BSL-1.0
16//
17
18
19#ifndef Crypto_Crypto_INCLUDED
20#define Crypto_Crypto_INCLUDED
21
22
23#define POCO_EXTERNAL_OPENSSL_DEFAULT 1
24#define POCO_EXTERNAL_OPENSSL_SLPRO 2
25
26
27#include "Poco/Foundation.h"
28#include <openssl/opensslv.h>
29
30
31#ifndef OPENSSL_VERSION_PREREQ
32 #if defined(OPENSSL_VERSION_MAJOR) && defined(OPENSSL_VERSION_MINOR)
33 #define OPENSSL_VERSION_PREREQ(maj, min)
34 ((OPENSSL_VERSION_MAJOR << 16) + OPENSSL_VERSION_MINOR >= ((maj) << 16) + (min))
35 #else
36 #define OPENSSL_VERSION_PREREQ(maj, min)
37 (OPENSSL_VERSION_NUMBER >= (((maj) << 28) | ((min) << 20)))
38 #endif
39#endif
40
41
43 /// The padding mode used for RSA public key encryption.
44{
46 /// PKCS #1 v1.5 padding. This currently is the most widely used mode.
47
49 /// EME-OAEP as defined in PKCS #1 v2.0 with SHA-1, MGF1 and an empty
50 /// encoding parameter. This mode is recommended for all new applications.
51
53 /// Raw RSA encryption. This mode should only be used to implement cryptographically
54 /// sound padding modes in the application code. Encrypting user data directly with RSA
55 /// is insecure.
56};
57
58
59//
60// The following block is the standard way of creating macros which make exporting
61// from a DLL simpler. All files within this DLL are compiled with the Crypto_EXPORTS
62// symbol defined on the command line. this symbol should not be defined on any project
63// that uses this DLL. This way any other project whose source files include this file see
64// Crypto_API functions as being imported from a DLL, whereas this DLL sees symbols
65// defined with this macro as being exported.
66//
67#if defined(_WIN32)
68 #if defined(POCO_DLL)
69 #if defined(Crypto_EXPORTS)
70 #define Crypto_API __declspec(dllexport)
71 #else
72 #define Crypto_API __declspec(dllimport)
73 #endif
74 #endif
75#endif
76
77
78#if !defined(Crypto_API)
79 #if !defined(POCO_NO_GCC_API_ATTRIBUTE) && defined (__GNUC__) && (__GNUC__ >= 4)
80 #define Crypto_API __attribute__ ((visibility ("default")))
81 #else
82 #define Crypto_API
83 #endif
84#endif
85
86
87//
88// Automatically link Crypto and OpenSSL libraries.
89//
90#if defined(_MSC_VER)
91 #if !defined(POCO_NO_AUTOMATIC_LIBS)
92 #if defined(POCO_INTERNAL_OPENSSL_MSVC_VER)
93 #if defined(POCO_EXTERNAL_OPENSSL)
94 #pragma message("External OpenSSL defined but internal headers used - possible mismatch!")
95 #endif // POCO_EXTERNAL_OPENSSL
96 #if !defined(_DEBUG)
97 #define POCO_DEBUG_SUFFIX ""
98 #if !defined (_DLL)
99 #define POCO_STATIC_SUFFIX "mt"
100 #else // _DLL
101 #define POCO_STATIC_SUFFIX ""
102 #endif
103 #else // _DEBUG
104 #define POCO_DEBUG_SUFFIX "d"
105 #if !defined (_DLL)
106 #define POCO_STATIC_SUFFIX "mt"
107 #else // _DLL
108 #define POCO_STATIC_SUFFIX ""
109 #endif
110 #endif
111 #pragma comment(lib, "libcrypto" POCO_STATIC_SUFFIX POCO_DEBUG_SUFFIX ".lib")
112 #pragma comment(lib, "libssl" POCO_STATIC_SUFFIX POCO_DEBUG_SUFFIX ".lib")
113 #if !defined(_WIN64) && !defined (_DLL) &&
114 (POCO_INTERNAL_OPENSSL_MSVC_VER == 120) &&
115 (POCO_MSVC_VERSION < POCO_INTERNAL_OPENSSL_MSVC_VER)
116 #pragma comment(lib, "libPreVS2013CRT" POCO_STATIC_SUFFIX POCO_DEBUG_SUFFIX ".lib")
117 #endif
118 #if !defined (_DLL) && (POCO_MSVS_VERSION >= 2015)
119 #pragma comment(lib, "legacy_stdio_definitions.lib")
120 #pragma comment(lib, "legacy_stdio_wide_specifiers.lib")
121 #endif
122 #elif defined(POCO_EXTERNAL_OPENSSL)
124 #if defined(POCO_DLL)
125 #if OPENSSL_VERSION_PREREQ(1,1)
126 #pragma comment(lib, "libcrypto.lib")
127 #pragma comment(lib, "libssl.lib")
128 #else
129 #pragma comment(lib, "libeay32.lib")
130 #pragma comment(lib, "ssleay32.lib")
131 #endif
132 #else
134 #if defined(_WIN64)
135 #pragma comment(lib, "libcrypto")
136 #pragma comment(lib, "libssl")
137 #else
138 #pragma comment(lib, "libcrypto32" POCO_LIB_SUFFIX)
139 #pragma comment(lib, "libssl32" POCO_LIB_SUFFIX)
140 #endif
141 #else
142 #pragma comment(lib, "libeay32" POCO_LIB_SUFFIX)
143 #pragma comment(lib, "ssleay32" POCO_LIB_SUFFIX)
144 #endif
145 #endif
146 #elif POCO_EXTERNAL_OPENSSL == POCO_EXTERNAL_OPENSSL_DEFAULT
147 #if OPENSSL_VERSION_PREREQ(1,1)
148 #pragma comment(lib, "libcrypto.lib")
149 #pragma comment(lib, "libssl.lib")
150 #else
151 #pragma comment(lib, "libeay32.lib")
152 #pragma comment(lib, "ssleay32.lib")
153 #endif
154 #endif
155 #endif // POCO_INTERNAL_OPENSSL_MSVC_VER
156 #if !defined(Crypto_EXPORTS)
157 #pragma comment(lib, "PocoCrypto" POCO_LIB_SUFFIX)
158 #endif
159 #endif // POCO_NO_AUTOMATIC_LIBS
160#endif
161
162
163namespace Poco {
164namespace Crypto {
165
166
168 /// Initialize the Crypto library, as well as the underlying OpenSSL
169 /// libraries, by calling OpenSSLInitializer::initialize().
170 ///
171 /// Should be called before using any class from the Crypto library.
172 /// The Crypto library will be initialized automatically, through
173 /// OpenSSLInitializer instances held by various Crypto classes
174 /// (Cipher, CipherKey, RSAKey, X509Certificate).
175 /// However, it is recommended to call initializeCrypto()
176 /// in any case at application startup.
177 ///
178 /// Can be called multiple times; however, for every call to
179 /// initializeCrypto(), a matching call to uninitializeCrypto()
180 /// must be performed.
181
182
184 /// Uninitializes the Crypto library by calling
185 /// OpenSSLInitializer::uninitialize().
186
187
188} } // namespace Poco::Crypto
189
190
191#endif // Crypto_Crypto_INCLUDED
#define ARK_API
Definition Base.h:9
#define POCO_EXTERNAL_OPENSSL
Definition Config.h:189
#define POCO_NO_SOO
Definition Config.h:82
#define POCO_DO_JOIN2(X, Y)
Definition Foundation.h:134
#define POCO_DO_JOIN(X, Y)
Definition Foundation.h:133
#define Foundation_API
Definition Foundation.h:60
#define POCO_JOIN(X, Y)
Definition Foundation.h:132
#define Net_API
Definition Net.h:47
#define NetSSL_API
Definition NetSSL.h:48
#define POCO_OS_WINDOWS_NT
Definition Platform.h:43
#define POCO_UNUSED
Definition Platform.h:274
#define POCO_OS_ANDROID
Definition Platform.h:41
#define POCO_OS_QNX
Definition Platform.h:37
#define POCO_OS_LINUX
Definition Platform.h:31
#define POCO_OS_SOLARIS
Definition Platform.h:36
#define POCO_ARCH_AMD64
Definition Platform.h:129
#define OPENSSL_VERSION_PREREQ(maj, min)
Definition Crypto.h:36
#define Crypto_API
Definition Crypto.h:82
RSAPaddingMode
The padding mode used for RSA public key encryption.
Definition Crypto.h:44
@ RSA_PADDING_PKCS1_OAEP
PKCS #1 v1.5 padding. This currently is the most widely used mode.
Definition Crypto.h:48
@ RSA_PADDING_NONE
Definition Crypto.h:52
@ RSA_PADDING_PKCS1
Definition Crypto.h:45
#define POCO_EXTERNAL_OPENSSL_SLPRO
Definition Crypto.h:24
virtual std::unique_ptr< ArkApi::ICommands > & GetCommands()=0
std::mutex RequestMutex_
Definition Requests.cpp:47
void WriteRequest(std::function< void(bool, std::string)> callback, bool success, std::string result)
Definition Requests.cpp:73
std::string GetResponse(Poco::Net::HTTPClientSession *session, Poco::Net::HTTPResponse &response)
Definition Requests.cpp:107
Poco::Net::HTTPRequest ConstructRequest(const std::string &url, Poco::Net::HTTPClientSession *&session, const std::vector< std::string > &headers, const std::string &request_type)
Definition Requests.cpp:79
std::vector< RequestData > RequestsVec_
Definition Requests.cpp:46
Requests(Requests &&)=delete
ARK_API bool CreateGetRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, std::vector< std::string > headers={})
Creates an async GET Request that runs in another thread but calls the callback from the main thread.
Definition Requests.cpp:129
ARK_API bool CreatePostRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, const std::vector< std::string > &post_ids, const std::vector< std::string > &post_data, std::vector< std::string > headers={})
Creates an async POST Request that runs in another thread but calls the callback from the main thread...
Definition Requests.cpp:238
Requests & operator=(Requests &&)=delete
ARK_API bool CreateDeleteRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, std::vector< std::string > headers={})
Creates an async DELETE Request that runs in another thread but calls the callback from the main thre...
Definition Requests.cpp:292
Requests & operator=(const Requests &)=delete
ARK_API bool CreatePostRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, const std::string &post_data, std::vector< std::string > headers={})
Creates an async POST Request with application/x-www-form-urlencoded content type that runs in anothe...
Definition Requests.cpp:162
static ARK_API Requests & Get()
Definition Requests.cpp:67
ARK_API bool CreatePostRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, const std::string &post_data, const std::string &content_type, std::vector< std::string > headers={})
Creates an async POST Request that runs in another thread but calls the callback from the main thread...
Definition Requests.cpp:200
std::unique_ptr< impl > pimpl
Definition Requests.h:84
Requests(const Requests &)=delete
virtual void AddOnTickCallback(const FString &id, const std::function< void(float)> &callback)=0
Added function will be called every frame.
virtual bool RemoveOnTickCallback(const FString &id)=0
Removes a on-tick callback.
Definition Logger.h:9
static std::shared_ptr< spdlog::logger > & GetLog()
Definition Logger.h:22
static std::string what(const char *msg, const char *file, int line, const char *text=0)
static void bugcheck(const char *msg, const char *file, int line)
static void nullPointer(const char *ptr, const char *file, int line)
static void debugger(const char *msg, const char *file, int line)
static void debugger(const char *file, int line)
static void bugcheck(const char *file, int line)
static void assertion(const char *cond, const char *file, int line, const char *text=0)
static void unexpected(const char *file, int line)
std::string displayText() const
Returns the exception code if defined.
virtual std::istream & receiveResponse(HTTPResponse &response)
virtual std::ostream & sendRequest(HTTPRequest &request)
Returns the connection timeout for HTTP connections.
static const std::string HTTP_1_1
void setContentLength(std::streamsize length)
Returns the HTTP version for this message.
HTTPRequest(const std::string &method, const std::string &uri, const std::string &version)
Creates a HTTP/1.0 request with the given method and URI.
static const std::string HTTP_GET
static const std::string HTTP_DELETE
static const std::string HTTP_POST
const std::string & getReason() const
Sets the HTTP reason phrase.
HTTPResponse(HTTPStatus status)
HTTPStatus getStatus() const
HTTPSClientSession(const std::string &host, Poco::UInt16 port, Context::Ptr pContext, Session::Ptr pSession)
std::string proxyRequestPrefix() const
Sends the given HTTPRequest over an existing connection.
HTTPSClientSession(Context::Ptr pContext, Session::Ptr pSession)
HTTPSClientSession(Context::Ptr pContext)
Creates a HTTPSClientSession using the given host and port.
void proxyAuthenticate(HTTPRequest &request)
Checks if we can reuse a persistent connection.
int read(char *buffer, std::streamsize length)
HTTPSClientSession(const HTTPSClientSession &)
void connect(const SocketAddress &address)
Refills the internal buffer.
HTTPSClientSession(const SecureStreamSocket &socket, Session::Ptr pSession)
X509Certificate serverCertificate()
HTTPSClientSession & operator=(const HTTPSClientSession &)
HTTPSClientSession(const std::string &host, Poco::UInt16 port=HTTPS_PORT)
HTTPSClientSession(const SecureStreamSocket &socket)
Creates an unconnected HTTPSClientSession.
HTTPSClientSession(const std::string &host, Poco::UInt16 port, Context::Ptr pContext)
RejectCertificateHandler(bool handleErrorsOnServerSide)
void initializeClient(PrivateKeyPassphraseHandlerPtr ptrPassphraseHandler, InvalidCertificateHandlerPtr ptrHandler, Context::Ptr ptrContext)
static SSLManager & instance()
This stream discards all characters written to it.
Definition NullStream.h:77
static std::streamsize copyStream(std::istream &istr, std::ostream &ostr, std::size_t bufferSize=8192)
const std::string & getHost() const
Sets the user-info part of the URI.
Definition URI.h:385
const std::string & getScheme() const
Definition URI.h:373
URI(const std::string &uri)
Creates an empty URI.
unsigned short getPort() const
Sets the host part of the URI.
std::string getPathAndQuery() const
Returns the encoded path, query and fragment parts of the URI.
void error(const T &)
Definition IBaseApi.h:9
std::unique_ptr< IBaseApi > game_api
Definition IBaseApi.h:25
void Crypto_API uninitializeCrypto()
void Crypto_API initializeCrypto()
void NetSSL_API initializeSSL()
void Net_API uninitializeNetwork()
void Net_API initializeNetwork()
void NetSSL_API uninitializeSSL()
Definition format.h:408
Definition json.hpp:4518
#define OPENSSL_VERSION_NUMBER
Definition opensslv.h:42
std::function< void(bool, std::string)> callback
Definition Requests.cpp:41
static std::string escape(const std::string &s, bool strictJSON=false)