Author Topic: FTP Certificates  (Read 1255 times)

ddddd13

  • Full Member
  • ***
  • Posts: 118
    • View Profile
FTP Certificates
« on: June 21, 2019, 07:51:23 PM »
Archie;

The code you wrote to read the FTP site worked great. But now they turned on the certificates and I get alarms stating that. The following is the code you wrote and the 5 lines I removed the ' from. With that I get a alarm, CertLocation is not declared. I tried DIM CertLocation as String and it returns an alarm text is not a string.   


 Private Sub FtpRead_Tomorrow()
        'GET TODAYS DIRECTORY
        'LOAD EPICOR DATA
        ' Get the object used to communicate with the server.

         Dim request As Net.FtpWebRequest = DirectCast(WebRequest.Create(FtpAddress & Tomorrow & "*.*"), FtpWebRequest)
     
     
        request.Method = WebRequestMethods.Ftp.ListDirectoryDetails
        'THE FOLLOWING 5 LINES WILL NEED TO BE TURNED ON IF CERTIFICATES ARE REQUIRED
        request.EnableSsl = True
        Dim cert As X509Certificate = X509Certificate.CreateFromCertFile(CertLocation.Text)
        Dim certCollection As X509CertificateCollection = New X509CertificateCollection()
        certCollection.Add(cert)
        request.ClientCertificates = certCollection
        ' This example assumes the FTP site uses anonymous logon.
        request.Credentials = New NetworkCredential(FtpUserName, FtpPassword)
        Using response As FtpWebResponse = DirectCast(request.GetResponse(), FtpWebResponse)
            Dim responseStream As IO.Stream = response.GetResponseStream()
            Using reader As New IO.StreamReader(responseStream)
                RichTextBox1.Text = (reader.ReadToEnd())

            End Using
        End Using



    End Sub
with that I get a alarm, CertLocation is not declared. I tried DIM CertLocation as String and it returns an alarm text is not a string.

Will this code handle certificates?

Thanks,
Dave


ddddd13

  • Full Member
  • ***
  • Posts: 118
    • View Profile
Re: FTP Certificates
« Reply #1 on: June 22, 2019, 09:31:05 PM »
Archie;

In looking deeper at the code CertLocation.Text I assume is a location on my computer where the certifications are or an address where they are on the site I am trying to connect to?

Dave


ddddd13

  • Full Member
  • ***
  • Posts: 118
    • View Profile
Re: FTP Certificates
« Reply #3 on: June 24, 2019, 11:57:17 PM »
Thanks for the links but...

It still doesn't make sense! I downloaded File Zilla, and it connects, allows me to upload and download files.
When it connects it shows initalizing tls, Verifying certificate, TLS connection established, Logged in.

By this I assume the certificate is established before the Login. Where is File Zilla getting the certificate from?
In looking at the code.
Dim cert As X509Certificate = X509Certificate.CreateFromCertFile(CertLocation)
CertLocation returns the error undefined
It looks like a certificate would be generated from the file located at CertLocation.
In running the program certmgr I can see the certificates, but I don't know which one File Zilla is using if any or what the location would be.

Lost again,
Dave

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: FTP Certificates
« Reply #4 on: June 25, 2019, 12:19:11 AM »
Try using Google search and check some of the results, like this one:

https://forum.filezilla-project.org/viewtopic.php?t=10212

That's pretty much what I do with your questions.
« Last Edit: June 25, 2019, 12:31:42 AM by Godra »

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: FTP Certificates
« Reply #5 on: June 25, 2019, 12:40:47 AM »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5320
    • View Profile
    • AdvancedHMI
Re: FTP Certificates
« Reply #6 on: June 25, 2019, 08:56:42 AM »
Dim cert As X509Certificate = X509Certificate.CreateFromCertFile(CertLocation)
I am no expert on this, but I interpret it as CertLocation would be the file path and name of the certificate:

Dim cert As X509Certificate = X509Certificate.CreateFromCertFile("C:\MyCertificates\Cert1.cer")

ddddd13

  • Full Member
  • ***
  • Posts: 118
    • View Profile
Re: FTP Certificates
« Reply #7 on: June 25, 2019, 09:50:57 AM »
I found the certificate in File Zilla.  I put the following in the dim line. and I still get a path alarm.

 Dim cert As X509Certificate = X509Certificate.CreateFromCertFile("C:\Users\Dave\AppData\Roaming\FileZilla\trustedcerts.xml")

System.Security.Cryptography.CryptographicException
  HResult=0x80070003
  Message=The system cannot find the path specified.

  Source=mscorlib
  StackTrace:
   at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
   at System.Security.Cryptography.X509Certificates.X509Utils._QueryCertFileType(String fileName)
   at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromFile(String fileName, Object password, X509KeyStorageFlags keyStorageFlags)
   at System.Security.Cryptography.X509Certificates.X509Certificate.CreateFromCertFile(String filename)
   at MfgControl.AdvancedHMI.MainForm.FtpRead_Tomorrow() in C:\AERO3\V399yBeta\AdvancedHMI\MainForm2.vb:line 130
   at MfgControl.AdvancedHMI.MainForm.Timer2_Tick(Object sender, EventArgs e) in C:\AERO3\V399yBeta\AdvancedHMI\MainForm2.vb:line 213
   at System.Windows.Forms.Timer.OnTick(EventArgs e)
   at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
   at MfgControl.AdvancedHMI.My.MyApplication.Main(String[] Args) in :line 81

I tried it your way too, same result. The following is the entire routine.

   Private Sub FtpRead_Tomorrow()
        'GET TODAYS DIRECTORY
        'LOAD EPICOR DATA
        ' Get the object used to communicate with the server.
        Dim request As Net.FtpWebRequest = DirectCast(WebRequest.Create(FtpAddress & "/*.*"), FtpWebRequest)
        request.Method = WebRequestMethods.Ftp.ListDirectoryDetails
        'THE FOLLOWING 5 LINES WILL NEED TO BE TURNED ON IF CERTIFICATES ARE REQUIRED
        request.EnableSsl = True
        Dim cert As X509Certificate = X509Certificate.CreateFromCertFile("C:\MyCertificates\Cert1.cer")
        Dim certCollection As X509CertificateCollection = New X509CertificateCollection()
        certCollection.Add(cert)
        request.ClientCertificates = certCollection

        ' This example assumes the FTP site uses anonymous logon.

        request.Credentials = New NetworkCredential(FtpUserName, FtpPassword)
        Using response As FtpWebResponse = DirectCast(request.GetResponse(), FtpWebResponse)
            Dim responseStream As IO.Stream = response.GetResponseStream()
            Using reader As New IO.StreamReader(responseStream)
                RichTextBox1.Text = (reader.ReadToEnd())

            End Using
        End Using



Thanks,
Dave


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5320
    • View Profile
    • AdvancedHMI
Re: FTP Certificates
« Reply #8 on: June 25, 2019, 10:03:13 AM »
It should specify an certificate file, so something like this:

Dim cert As X509Certificate = X509Certificate.CreateFromCertFile("C:\Users\Dave\AppData\Roaming\FileZilla\certificate.crt")

Using the directory where the actual .crt file is stored.

ddddd13

  • Full Member
  • ***
  • Posts: 118
    • View Profile
Re: FTP Certificates
« Reply #9 on: June 25, 2019, 10:56:03 PM »
To anyone else trying to get a certificate do not use the example given at Boomi. They use a software called Openssl. It does not install correctly, has several different you tube examples of how to install it but they are all out of date, and has horrible documentation. Trust me I wasted the entire day.

Dave