Click here to Skip to main content
15,899,679 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Check for changes on Windows form Pin
Eddy Vluggen2-Oct-18 21:49
professionalEddy Vluggen2-Oct-18 21:49 
SuggestionRe: Check for changes on Windows form Pin
Richard Deeming3-Oct-18 1:47
mveRichard Deeming3-Oct-18 1:47 
QuestionRe: Check for changes on Windows form Pin
dan!sh 3-Oct-18 2:09
professional dan!sh 3-Oct-18 2:09 
QuestionIndex and length must refer to a location within the string vb.net Pin
Victoryy Hisar Sitanggang2-Oct-18 4:14
Victoryy Hisar Sitanggang2-Oct-18 4:14 
AnswerRe: Index and length must refer to a location within the string vb.net Pin
Richard Deeming2-Oct-18 4:34
mveRichard Deeming2-Oct-18 4:34 
QuestionRegisterHotKey Pin
JR2122-Oct-18 1:58
JR2122-Oct-18 1:58 
AnswerRe: RegisterHotKey Pin
JR2126-Oct-18 12:53
JR2126-Oct-18 12:53 
QuestionProblems with SSLstream.Read (VB.NET/VS2017) Pin
Member 1185690428-Sep-18 21:58
Member 1185690428-Sep-18 21:58 
I'm connecting to an EPP server via TCPclient and it's protected by SSL certificate authentication. The company that provides the EPP server said I needed to get a certificate (not self-signed), upload the CRT file into my user account, and then combine the CRT and KEY files into one (I choose PFX) that I will need to pass with each message in order to invoke an authorization / certificate combination. I've upload the CRT and created the PFX files fine.

I've tested this several ways (SSLstream, NetworkStream, StreamWriter/StreamReader) and none of them have been able to produce me with a readable response. At the same time, neither method produces any exceptions. From my testing it appears that I connect to the server okay, convert my string and write okay, but then either get a blank response or a jibberish response that looks like it might be encrypted? Below are two ways I've tried to do this (SSLstream & NetworkStream). You can see my code, plus a screenshot of the response.


SSLstream
VB
'Create a collection and add the certificate
Dim collection = New X509Certificate2Collection()
collection.Import("C:\\Users\\Drew\\Desktop\\testcert\\FIcert.pfx", "password", X509KeyStorageFlags.DefaultKeySet)
Dim store = New X509Store(StoreName.My)
store.Open(OpenFlags.ReadWrite)

Try
    For Each certificate As X509Certificate2 In collection
        store.Add(certificate)
    Next
Finally
    store.Close()
End Try


'Create the Hello EPP request and put it into a String
Dim hello As XElement = <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
                            <hello/>
                        </epp>


'Create client, convert XML element to string and pass it with certificate collection
Try
    Dim client As New TcpClient(DRShost, 700)
    Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(hello.ToString)
    Dim callback As New RemoteCertificateValidationCallback(AddressOf CertificateValidationCallback)
    Dim sslStream As New Security.SslStream(client.GetStream(), False, callback)
    sslStream.AuthenticateAsClient(DRShost, collection, SslProtocols.[Default], False)

    If sslStream.IsAuthenticated Then
        'All of these return TRUE except the last one
        MsgBox("IsAuthenticated: " & sslStream.IsAuthenticated)
        MsgBox("IsMutuallyAuthenticated: " & sslStream.IsMutuallyAuthenticated)
        MsgBox("IsEncrypted: " & sslStream.IsEncrypted)
        MsgBox("IsSigned: " & sslStream.IsSigned)
        MsgBox("IsServer: " & sslStream.IsServer)
    End If
    sslStream.Write(data, 0, data.Length)
    MsgBox("Sent: " & hello.ToString)
    data = New [Byte](256) {}
    Dim bytes As Integer = sslStream.Read(data, 0, data.Length)
    Dim responseData As String = System.Text.Encoding.ASCII.GetString(data, 0, bytes)
    MsgBox("Received: " & responseData)
Catch ex As AuthenticationException
    MsgBox(ex.Message)
Catch ex As SocketException
    MsgBox(ex.Message)
Catch ex As IOException
    MsgBox(ex.Message)
Finally
    If sslStream IsNot Nothing Then
        sslStream.Close()
    End If
End Try


Response:
Screenshot Here


NetworkStream
VB
'Create a collection and add the certificate
Dim collection = New X509Certificate2Collection()
collection.Import("C:\\Users\\Drew\\Desktop\\testcert\\FIcert.pfx", "password", X509KeyStorageFlags.DefaultKeySet)
Dim store = New X509Store(StoreName.My)
store.Open(OpenFlags.ReadWrite)

Try
    For Each certificate As X509Certificate2 In collection
        store.Add(certificate)
    Next
Finally
    store.Close()
End Try


'Create the Hello EPP request and put it into a String
Dim hello As XElement = <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
                            <hello/>
                        </epp>


'Create client and networkstream, convert XML and write it
Dim client As TcpClient = New TcpClient(DRShost, 700)
Dim tcpNetStream As NetworkStream = client.GetStream()
Dim sslStream As New Security.SslStream(tcpNetStream, False, New RemoteCertificateValidationCallback(AddressOf CertificateValidationCallback), Nothing)
sslStream.AuthenticateAsClient(DRShost, collection, SslProtocols.[Default], False)
Dim encodedBytes As Byte() = ASCIIEncoding.ASCII.GetBytes(hello.ToString)

tcpNetStream.Write(encodedBytes, 0, encodedBytes.Length)

Dim bytesToReceive As Byte() = New Byte(client.ReceiveBufferSize - 1) {}
Dim bytesRead As Integer = tcpNetStream.Read(bytesToReceive, 0, client.ReceiveBufferSize)
MsgBox("Received : " & Encoding.ASCII.GetString(bytesToReceive, 0, bytesRead))
client.Close()


Response:
Screenshot Here

I thought maybe the response from the second set of code was coming back encrypted, so I changed this line:
VB
Dim bytesRead As Integer = tcpNetStream.Read(bytesToReceive, 0, client.ReceiveBufferSize)


To read from the sslStream instead. However, this just leads to once again receiving a blank response:
VB
Dim bytesRead As Integer = sslStream.Read(bytesToReceive, 0, client.ReceiveBufferSize)


Any help on this would be greatly appreciated. I've scoured the web and tried everything I could think of, but to no avail. I do notice that when I view the string I'm sending it does not contain "". However, I believe that is added automatically by XElement?
QuestionProblem with SHGetFolderPath(): Problem Closed. Pin
mo149228-Sep-18 11:30
mo149228-Sep-18 11:30 
AnswerRe: Problem with SHGetFolderPath(): Problem Closed. Pin
Richard MacCutchan28-Sep-18 21:45
mveRichard MacCutchan28-Sep-18 21:45 
GeneralRe: Problem with SHGetFolderPath(): Problem Closed. Pin
mo149228-Sep-18 23:44
mo149228-Sep-18 23:44 
SuggestionRe: Problem with SHGetFolderPath(): Problem Closed. Pin
Richard Deeming1-Oct-18 8:13
mveRichard Deeming1-Oct-18 8:13 
GeneralRe: Problem with SHGetFolderPath(): Problem Closed. Pin
mo14921-Oct-18 9:45
mo14921-Oct-18 9:45 
Questionhow to get corresponding values of particular column from database to text field Pin
Member 1400114828-Sep-18 5:45
Member 1400114828-Sep-18 5:45 
AnswerRe: how to get corresponding values of particular column from database to text field Pin
Richard MacCutchan28-Sep-18 6:14
mveRichard MacCutchan28-Sep-18 6:14 
AnswerRe: how to get corresponding values of particular column from database to text field Pin
Eddy Vluggen28-Sep-18 6:38
professionalEddy Vluggen28-Sep-18 6:38 
QuestionScreen size and form size Pin
desanti27-Sep-18 18:58
desanti27-Sep-18 18:58 
AnswerRe: Screen size and form size Pin
dan!sh 27-Sep-18 20:45
professional dan!sh 27-Sep-18 20:45 
AnswerRe: Screen size and form size Pin
Richard MacCutchan27-Sep-18 21:07
mveRichard MacCutchan27-Sep-18 21:07 
GeneralRe: Screen size and form size Pin
desanti28-Sep-18 8:59
desanti28-Sep-18 8:59 
GeneralRe: Screen size and form size Pin
Mycroft Holmes28-Sep-18 12:00
professionalMycroft Holmes28-Sep-18 12:00 
QuestionIs c++ worth learning? Pin
Member 1398247125-Sep-18 4:10
Member 1398247125-Sep-18 4:10 
AnswerRe: Is c++ worth learning? Pin
Richard MacCutchan25-Sep-18 5:41
mveRichard MacCutchan25-Sep-18 5:41 
QuestionVBA code to automatically pass credentials to windows security pop up Pin
Roberto64_Ge19-Sep-18 4:33
Roberto64_Ge19-Sep-18 4:33 
QuestionLooking for a copy of VB.net can anyone help. I'm willing to pay. Pin
Member 1398247117-Sep-18 3:49
Member 1398247117-Sep-18 3:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.