2

I have a legacy Visual Studio 2010 vb.net application that I need to update the SSL TLS channeling to support TLS 1.2. I have tried a couple of different options (see commented code for attempts) and all lead me to the same error, "Could not create SSL/TLS secure channel." What am I missing?

Public Shared Function processCCRequest(ByVal strRequest As String) As String
    'declare the web request object and set its path to the PayTrace API

    Dim ThisRequest As WebRequest = WebRequest.Create("https://beta.paytrace.com/api/default.pay")
    'configure web request object attributes
    ThisRequest.ContentType = "application/x-www-form-urlencoded"
    ThisRequest.Method = "POST"

    'encode the request
    Dim Encoder As New System.Text.ASCIIEncoding
    Dim BytesToSend As Byte() = Encoder.GetBytes(strRequest)

    'declare the text stream and send the request to PayTrace's API
    Dim StreamToSend As Stream = ThisRequest.GetRequestStream
    StreamToSend.Write(BytesToSend, 0, BytesToSend.Length)
    StreamToSend.Close()

    ''ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
    ''allows for validation of SSL conversations
    ''ServicePointManager.ServerCertificateValidationCallback = New System.Net.Security.RemoteCertificateValidationCallback(AddressOf)
    ServicePointManager.Expect100Continue = True
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
    System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
     ''| SecurityProtocolType.Tls11 | SecurityProtocolType.Tls
    ''var(response = WebRequest.Create("https://www.howsmyssl.com/").GetResponse())
    ''var(body = New StreamReader(response.GetResponseStream()).ReadToEnd())


    'Catch the response from the webrequest object
    Dim TheirResponse As HttpWebResponse = ThisRequest.GetResponse

    Dim sr As New StreamReader(TheirResponse.GetResponseStream)
    Dim strResponse As String = sr.ReadToEnd

    'Out put the string to a message box - application should parse the request instead
    ' MsgBox(strResponse)

    sr.Close()
    Return strResponse
End Function

Thank you in advance for your suggestions!

2
  • 1
    I think that TLS 1.2 support was added in .NET 4.5, so you need that installed and then use the ServicePointManager.SecurityProtocol = DirectCast(3072, SecurityProtocolType) work-around for 4.0 code.
    – Mark
    Mar 15, 2017 at 20:01
  • Yes and in my answer I went a few steps further based upon this information to complete my task. Mar 26, 2017 at 19:40

2 Answers 2

4

If You used .net 3.5, use this script

ServicePointManager.SecurityProtocol = DirectCast(3072, SecurityProtocolType)
0

I was completely successful after downloading and installing the .net 4.6 Targeting Pack from Microsoft. This added the full .net upgrade that includes TLS 1.2 support and added .Net 4.6 as a publishing option. Once I upgraded and published, the code above worked with the security protocol set to TLS 1.2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.