-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from shanielh/ssl_sup
Added SSL Support!
- Loading branch information
Showing
12 changed files
with
207 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.IO; | ||
using System.Net; | ||
using System.Net.Security; | ||
using System.Security.Authentication; | ||
using System.Security.Cryptography.X509Certificates; | ||
|
||
namespace uhttpsharp.Clients | ||
{ | ||
public class ClientSslDecorator : IClient | ||
{ | ||
private readonly IClient _child; | ||
private readonly SslStream _sslStream; | ||
|
||
public ClientSslDecorator(IClient child, X509Certificate certificate) | ||
{ | ||
_child = child; | ||
_sslStream = new SslStream(_child.Stream); | ||
_sslStream.AuthenticateAsServer(certificate, false, SslProtocols.Tls, true); | ||
} | ||
|
||
public Stream Stream | ||
{ | ||
get { return _sslStream; } | ||
} | ||
|
||
public bool Connected | ||
{ | ||
get { return _child.Connected; } | ||
} | ||
|
||
public void Close() | ||
{ | ||
_child.Close(); | ||
} | ||
|
||
public EndPoint RemoteEndPoint | ||
{ | ||
get { return _child.RemoteEndPoint; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.IO; | ||
using System.Net; | ||
|
||
namespace uhttpsharp.Clients | ||
{ | ||
public interface IClient | ||
{ | ||
|
||
Stream Stream { get; } | ||
|
||
bool Connected { get; } | ||
void Close(); | ||
|
||
EndPoint RemoteEndPoint { get; } | ||
|
||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.IO; | ||
using System.Net; | ||
using System.Net.Sockets; | ||
|
||
namespace uhttpsharp.Clients | ||
{ | ||
public class TcpClientAdapter : IClient | ||
{ | ||
private readonly TcpClient _client; | ||
|
||
public TcpClientAdapter(TcpClient client) | ||
{ | ||
_client = client; | ||
} | ||
|
||
public Stream Stream | ||
{ | ||
get { return _client.GetStream(); } | ||
} | ||
|
||
public bool Connected | ||
{ | ||
get { return _client.Connected; } | ||
} | ||
|
||
public void Close() | ||
{ | ||
_client.Close(); | ||
} | ||
|
||
|
||
public EndPoint RemoteEndPoint | ||
{ | ||
get { return _client.Client.RemoteEndPoint; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Threading.Tasks; | ||
using uhttpsharp.Clients; | ||
|
||
namespace uhttpsharp.Listeners | ||
{ | ||
public interface IHttpListener | ||
{ | ||
|
||
Task<IClient> GetClient(); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Security.Cryptography.X509Certificates; | ||
using System.Threading.Tasks; | ||
using uhttpsharp.Clients; | ||
|
||
namespace uhttpsharp.Listeners | ||
{ | ||
public class ListenerSslDecorator : IHttpListener | ||
{ | ||
private readonly IHttpListener _child; | ||
private readonly X509Certificate _certificate; | ||
|
||
public ListenerSslDecorator(IHttpListener child, X509Certificate certificate) | ||
{ | ||
_child = child; | ||
_certificate = certificate; | ||
} | ||
|
||
public async Task<IClient> GetClient() | ||
{ | ||
return new ClientSslDecorator(await _child.GetClient().ConfigureAwait(false), _certificate); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Net.Sockets; | ||
using System.Threading.Tasks; | ||
using uhttpsharp.Clients; | ||
|
||
namespace uhttpsharp.Listeners | ||
{ | ||
public class TcpListenerAdapter : IHttpListener | ||
{ | ||
private readonly TcpListener _listener; | ||
|
||
public TcpListenerAdapter(TcpListener listener) | ||
{ | ||
_listener = listener; | ||
_listener.Start(); | ||
} | ||
public async Task<IClient> GetClient() | ||
{ | ||
return new TcpClientAdapter(await _listener.AcceptTcpClientAsync().ConfigureAwait(false)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters