CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
ssl_stream.h
1
2#pragma once
3
4#include <cstdint>
5#include <security/cryptography/x509_certificates/x509_certificate.h>
6#include <security/cryptography/x509_certificates/x509_certificate_collection.h>
7#include <security/cryptography/x509_certificates/x509_chain.h>
8#include <system/array.h>
9#include <system/async_callback.h>
10#include <system/enum_helpers.h>
11#include <system/iasyncresult.h>
12#include <system/io/seekorigin.h>
13#include <system/multicast_delegate.h>
14#include <system/object.h>
15#include <system/shared_ptr.h>
16#include <system/string.h>
17
18#include <net/secure_protocols/authentificated_stream.h>
19#include <net/secure_protocols/ssl_enum_types.h>
20#include <net/secure_protocols/ssl_policy_errors.h>
21
22namespace System { namespace Net { namespace Details {
23class TlsStreamImplStream;
24class TlsStreamImplSocket;
25}}} // namespace System::Net::Details
26
27namespace System { namespace Net { namespace Security {
28
31{
38};
39
41using RemoteCertificateValidationCallback = System::MulticastDelegate<bool(
44
47 System::MulticastDelegate<System::SharedPtr<System::Security::Cryptography::X509Certificates::X509Certificate>(
52
53class TlsStreamAsyncResult;
54
56class ASPOSECPP_SHARED_CLASS SslStream : public System::Net::Security::AuthenticatedStream
57{
58 friend class TlsStreamAsyncResult;
59
61 typedef SslStream ThisType;
64
66 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
68 ASPOSECPP_SHARED_RTTI_INFO_DECL();
69public:
71 typedef TlsStreamAsyncResult AsyncResultType;
73 typedef std::shared_ptr<System::Net::Details::TlsStreamImplSocket> StreamImplementationPtr;
74
75
77 ASPOSECPP_SHARED_API bool get_IsAuthenticated() const override;
79 ASPOSECPP_SHARED_API bool get_IsMutuallyAuthenticated() const override;
81 ASPOSECPP_SHARED_API bool get_IsEncrypted() const override;
83 ASPOSECPP_SHARED_API bool get_IsSigned() const override;
85 ASPOSECPP_SHARED_API bool get_IsServer() const override;
92 // process.
93 virtual ASPOSECPP_SHARED_API bool get_CheckCertRevocationStatus();
107 virtual ASPOSECPP_SHARED_API int32_t get_CipherStrength();
113 virtual ASPOSECPP_SHARED_API int32_t get_HashStrength();
116 virtual ASPOSECPP_SHARED_API int32_t get_KeyExchangeStrength();
118 ASPOSECPP_SHARED_API bool get_CanSeek() const override;
120 ASPOSECPP_SHARED_API bool get_CanRead() const override;
122 ASPOSECPP_SHARED_API bool get_CanTimeout() const override;
124 ASPOSECPP_SHARED_API bool get_CanWrite() const override;
126 ASPOSECPP_SHARED_API int32_t get_ReadTimeout() const override;
128 ASPOSECPP_SHARED_API void set_ReadTimeout(int32_t value) override;
130 ASPOSECPP_SHARED_API int32_t get_WriteTimeout() const override;
132 ASPOSECPP_SHARED_API void set_WriteTimeout(int32_t value) override;
134 ASPOSECPP_SHARED_API int64_t get_Length() const override;
136 ASPOSECPP_SHARED_API int64_t get_Position() const override;
138 ASPOSECPP_SHARED_API void set_Position(int64_t value) override;
139
142 ASPOSECPP_SHARED_API SslStream(System::SharedPtr<IO::Stream> innerStream);
146 ASPOSECPP_SHARED_API SslStream(System::SharedPtr<IO::Stream> innerStream, bool leaveInnerStreamOpen);
152 ASPOSECPP_SHARED_API SslStream(System::SharedPtr<IO::Stream> innerStream, bool leaveInnerStreamOpen,
153 RemoteCertificateValidationCallback userCertificateValidationCallback);
161 ASPOSECPP_SHARED_API SslStream(System::SharedPtr<IO::Stream> innerStream, bool leaveInnerStreamOpen,
162 RemoteCertificateValidationCallback userCertificateValidationCallback,
163 LocalCertificateSelectionCallback userCertificateSelectionCallback);
172 ASPOSECPP_SHARED_API SslStream(System::SharedPtr<IO::Stream> innerStream, bool leaveInnerStreamOpen,
173 RemoteCertificateValidationCallback userCertificateValidationCallback,
174 LocalCertificateSelectionCallback userCertificateSelectionCallback,
175 EncryptionPolicy encryptionPolicy);
176
179 virtual ASPOSECPP_SHARED_API void AuthenticateAsClient(String targetHost);
186 virtual ASPOSECPP_SHARED_API void AuthenticateAsClient(
187 String targetHost,
189 clientCertificates,
190 System::Security::Authentication::SslProtocols enabledSslProtocols, bool checkCertificateRevocation);
191
193 ASPOSECPP_SHARED_API void SetLength(int64_t value) override;
195 ASPOSECPP_SHARED_API int64_t Seek(int64_t offset, IO::SeekOrigin origin) override;
197 ASPOSECPP_SHARED_API void Flush() override;
199 ASPOSECPP_SHARED_API int32_t Read(const ArrayPtr<uint8_t>& buffer, int32_t offset, int32_t count) override;
202 ASPOSECPP_SHARED_API void Write(const ArrayPtr<uint8_t>& buffer);
204 ASPOSECPP_SHARED_API void Write(const ArrayPtr<uint8_t>& buffer, int32_t offset, int32_t count) override;
206 ASPOSECPP_SHARED_API int32_t Read(const System::Details::ArrayView<uint8_t>& buffer, int32_t offset, int32_t count) override;
209 ASPOSECPP_SHARED_API void Write(const System::Details::ArrayView<uint8_t>& buffer);
211 ASPOSECPP_SHARED_API void Write(const System::Details::ArrayView<uint8_t>& buffer, int32_t offset, int32_t count) override;
219 ASPOSECPP_SHARED_API System::SharedPtr<IAsyncResult> BeginRead(System::ArrayPtr<uint8_t> buffer, int32_t offset,
220 int32_t count, AsyncCallback asyncCallback,
221 System::SharedPtr<Object> asyncState) override;
223 ASPOSECPP_SHARED_API int32_t EndRead(System::SharedPtr<IAsyncResult> asyncResult) override;
231 ASPOSECPP_SHARED_API System::SharedPtr<IAsyncResult> BeginWrite(System::ArrayPtr<uint8_t> buffer, int32_t offset,
232 int32_t count, AsyncCallback asyncCallback,
233 System::SharedPtr<Object> asyncState) override;
235 ASPOSECPP_SHARED_API void EndWrite(System::SharedPtr<IAsyncResult> asyncResult) override;
236
238 ASPOSECPP_SHARED_API void Dispose(bool disposing) override;
240 ASPOSECPP_SHARED_API void Close() override;
241
242private:
247 size_t read(uint8_t buffer[], size_t size);
251 void write(const uint8_t buffer[], size_t size);
252
254 StreamImplementationPtr stream_impl;
255};
256}}} // namespace System::Net::Security
257
258DECLARE_USING_ENUM_OPERATORS(System::Net::Security);
A base class for a variety of stream implementations. Objects of this class should only be allocated ...
Definition: stream.h:24
Contains the methods for passing credentials across a stream. Objects of this class should only be al...
Definition: authentificated_stream.h:14
A stream that uses the SSL protocol to authenticate the server and optionally the client.
Definition: ssl_stream.h:57
int32_t get_WriteTimeout() const override
Gets a value, in milliseconds, that determines how long the stream will attempt to write before timin...
virtual void AuthenticateAsClient(String targetHost, System::SharedPtr< System::Security::Cryptography::X509Certificates::X509CertificateCollection > clientCertificates, System::Security::Authentication::SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
Authenticates the client-side of the connection.
void Write(const System::Details::ArrayView< uint8_t > &buffer, int32_t offset, int32_t count) override
Writes the specified subrange of bytes from the specified byte array to the stream.
int64_t Seek(int64_t offset, IO::SeekOrigin origin) override
Sets the position of the stream represented by the current object.
bool get_IsServer() const override
Returns a value that indicates if the local side of the connection is the server.
int32_t Read(const ArrayPtr< uint8_t > &buffer, int32_t offset, int32_t count) override
Reads the specified number of bytes from the stream and writes them to the specified byte array.
virtual System::Security::Authentication::CipherAlgorithmType get_CipherAlgorithm()
Returns the encryption algorithm.
int64_t get_Position() const override
Returns the current position of the stream.
bool get_CanWrite() const override
Determines if the stream is writable.
void set_Position(int64_t value) override
Sets the stream's position.
System::SharedPtr< IAsyncResult > BeginWrite(System::ArrayPtr< uint8_t > buffer, int32_t offset, int32_t count, AsyncCallback asyncCallback, System::SharedPtr< Object > asyncState) override
Initiates an asynchronous write operation.
void Write(const ArrayPtr< uint8_t > &buffer)
Writes the specified byte array to the stream.
SslStream(System::SharedPtr< IO::Stream > innerStream)
Constructs a new instance.
void Dispose(bool disposing) override
Releases all resources used by the current object and closes the stream.
SslStream(System::SharedPtr< IO::Stream > innerStream, bool leaveInnerStreamOpen)
Constructs a new instance.
bool get_IsSigned() const override
Returns a value that indicates if the data sent using this stream is signed.
void Write(const System::Details::ArrayView< uint8_t > &buffer)
Writes the specified byte array to the stream.
void set_ReadTimeout(int32_t value) override
Sets a value that determines whether the current stream can time out.
SslStream(System::SharedPtr< IO::Stream > innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback, LocalCertificateSelectionCallback userCertificateSelectionCallback, EncryptionPolicy encryptionPolicy)
Constructs a new instance.
TlsStreamAsyncResult AsyncResultType
Type of AsyncResultType.
Definition: ssl_stream.h:71
virtual System::SharedPtr< System::Security::Cryptography::X509Certificates::X509Certificate > get_RemoteCertificate()
Returns the certificate that is used to authenticate the remote endpoint.
SslStream(System::SharedPtr< IO::Stream > innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback)
Constructs a new instance.
virtual int32_t get_KeyExchangeStrength()
Returns the strength of the used key exchange algorithm.
virtual int32_t get_HashStrength()
Returns the strength of the used hash algorithm.
virtual System::Security::Authentication::HashAlgorithmType get_HashAlgorithm()
Returns the hash algorithm.
void Flush() override
Clears this stream's buffers and writes all buffered data to the underlying storage.
int32_t EndRead(System::SharedPtr< IAsyncResult > asyncResult) override
Waits until the specified asynchronous read operation completes.
void SetLength(int64_t value) override
Sets the length of the stream represented by the current object.
std::shared_ptr< System::Net::Details::TlsStreamImplSocket > StreamImplementationPtr
Type of pointer to the implementation.
Definition: ssl_stream.h:73
bool get_CanSeek() const override
Determines if the stream supports seeking.
SslStream(System::SharedPtr< IO::Stream > innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback, LocalCertificateSelectionCallback userCertificateSelectionCallback)
Constructs a new instance.
int32_t Read(const System::Details::ArrayView< uint8_t > &buffer, int32_t offset, int32_t count) override
Reads the specified number of bytes from the stream and writes them to the specified byte array.
bool get_CanRead() const override
Determines if the stream is readable.
void set_WriteTimeout(int32_t value) override
Sets a value, in milliseconds, that determines how long the stream will attempt to read before timing...
bool get_CanTimeout() const override
Gets a value that determines whether the current stream can time out.
System::SharedPtr< IAsyncResult > BeginRead(System::ArrayPtr< uint8_t > buffer, int32_t offset, int32_t count, AsyncCallback asyncCallback, System::SharedPtr< Object > asyncState) override
Initiates an asynchronous read operation.
void Write(const ArrayPtr< uint8_t > &buffer, int32_t offset, int32_t count) override
Writes the specified subrange of bytes from the specified byte array to the stream.
void Close() override
Closes the stream.
bool get_IsMutuallyAuthenticated() const override
Returns a value that indicates if a server and a client are authenticated.
bool get_IsAuthenticated() const override
Returns a value that indicates if authentication is successfully passed.
int32_t get_ReadTimeout() const override
Gets a value, in milliseconds, that determines how long the stream will attempt to read before timing...
void EndWrite(System::SharedPtr< IAsyncResult > asyncResult) override
Ends an asynchronous write operation. Waits until the specified asynchronous write operation complete...
virtual System::Security::Authentication::SslProtocols get_SslProtocol()
Returns the SSL protocol.
bool get_IsEncrypted() const override
Returns a value that indicates if the data sent using this stream is encrypted.
virtual System::SharedPtr< System::Security::Cryptography::X509Certificates::X509Certificate > get_LocalCertificate()
Returns the certificate that is used to authenticate the local endpoint.
virtual bool get_CheckCertRevocationStatus()
Returns a value that indicates if the certificate revocation list is checked during the certificate v...
int64_t get_Length() const override
Returns the length of the stream in bytes.
virtual void AuthenticateAsClient(String targetHost)
Authenticates the client-side of the connection.
virtual int32_t get_CipherStrength()
Returns the strength of the used encryption algorithm.
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
String class used across the library. Is a substitute for C# System.String when translating code....
Definition: string.h:122
SeekOrigin
Specifies the reference position in the stream relative to which the position to seek to is specified...
Definition: seekorigin.h:11
Definition: authentificated_stream.h:7
SslPolicyErrors
Enumerates the policy errors of SSL.
Definition: ssl_policy_errors.h:12
System::MulticastDelegate< bool(System::SharedPtr< Object >, System::SharedPtr< System::Security::Cryptography::X509Certificates::X509Certificate >, System::SharedPtr< System::Security::Cryptography::X509Certificates::X509Chain >, SslPolicyErrors)> RemoteCertificateValidationCallback
A user delegate used to verify remote SSL certificate.
Definition: ssl_stream.h:43
EncryptionPolicy
Enumerates the encryption policies.
Definition: ssl_stream.h:31
@ RequireEncryption
Require encryption and never allow a 'Null' cipher.
@ NoEncryption
Allow no encryption and request that a 'Null' cipher be used if the other endpoint can handle a 'Null...
@ AllowNoEncryption
Prefer using full encryption but a 'Null' cipher can be used if the server agrees.
System::MulticastDelegate< System::SharedPtr< System::Security::Cryptography::X509Certificates::X509Certificate >(System::SharedPtr< Object >, String, System::SharedPtr< System::Security::Cryptography::X509Certificates::X509CertificateCollection >, System::SharedPtr< System::Security::Cryptography::X509Certificates::X509Certificate >, System::ArrayPtr< String >)> LocalCertificateSelectionCallback
A user delegate used to select local SSL certificate.
Definition: ssl_stream.h:51
CipherAlgorithmType
Enumerates the cipher algorithms.
Definition: ssl_enum_types.h:28
HashAlgorithmType
Enumerates the hash algorithms.
Definition: ssl_enum_types.h:53
SslProtocols
Enumerates the cryptographic protocols.
Definition: ssl_enum_types.h:9
Definition: db_command.h:9
System::MulticastDelegate< void(SharedPtr< IAsyncResult >)> AsyncCallback
A delegate type that represents a method to be called when asynchronous operation completes.
Definition: async_callback.h:13