Skip to content

Instantly share code, notes, and snippets.

@shrddr
Last active February 13, 2021 20:42
Show Gist options
  • Save shrddr/c25a1262b12239305b139935475a5989 to your computer and use it in GitHub Desktop.
Save shrddr/c25a1262b12239305b139935475a5989 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using Org.BouncyCastle.Math;
using Org.BouncyCastle.Crypto.Tls;
namespace test_ssl_bouncy
{
class Program
{
static void Main(string[] args)
{
TcpClient client = new TcpClient("api.telegram.org", 443);
NetworkStream targetStream = client.GetStream();
targetStream.ReadTimeout = 10000;
targetStream.WriteTimeout = 10000;
TlsClientProtocol protocol = new TlsClientProtocol(targetStream, new Org.BouncyCastle.Security.SecureRandom());
protocol.Connect(new MyTlsClient()); // error 71 "insufficient_security"
}
private class MyTlsClient : DefaultTlsClient
{
public override TlsAuthentication GetAuthentication() => new MyTlsAuthentication();
public override int[] GetCipherSuites() => new[] { CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 };
public override void NotifyAlertRaised(byte alertLevel, byte alertDescription, string message, Exception cause)
{
base.NotifyAlertRaised(alertLevel, alertDescription, message, cause);
Console.WriteLine("AlertLevel: " + alertLevel);
Console.WriteLine("AlertDescription: " + alertDescription);
Console.WriteLine("Message: " + message);
Console.WriteLine("Exception: " + cause);
}
}
private class MyTlsAuthentication : TlsAuthentication
{
public TlsCredentials GetClientCredentials(CertificateRequest certificateRequest) => null;
public void NotifyServerCertificate(Certificate serverCertificate) { }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment