Author Topic: Learning to program internet connections  (Read 9781 times)

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 597
  • Liked:
  • Likes Given: 0
Learning to program internet connections
« on: March 01, 2016, 06:35:00 AM »
I'm learning to program internet connections with Real Basic 5.5.5.
The manual/help is not always accurate.
For example, it says that you can call the functions of the internet classes synchronously if you use the timeOut parameter, but if you try this then it will complain that you used too many parameters.
It says also that you can listen at an SSLSocket, but if you try this then it will make an unencrypted connection.
I tried that and it was encrypted.

I tried a HTTP client, HTTP server and MAIL client some time ago.
I've just finished a HTTP proxy.
I want to extend it with HTTPS using the CONNECT command.
Then I want to do filtering of HTTP as well as HTTPS, starting with URL blocking, but I plan also to change HTML by deleting undesired scripts, frames and ads.

The problem is that I can't test it.
I have Apache on XP but I don't get the SSL installed and I prefer to write the program on OS 9.
I search server software which supports SSL and a browser which supports the CONNECT method.

Offline MacTron

  • Global Moderator
  • Platinum Member (500+ Posts)
  • *****
  • Posts: 2118
  • keep it simple
  • Liked:
  • Likes Given: 2
Re: Learning to program internet connections
« Reply #1 on: March 01, 2016, 11:04:35 AM »
Real Basic is not for *real* development. IMHO.
You should consider Codewarrior in Pascal or C fashion, even the old Symantec stuff do a better job than Real Basic.
Please don't PM about things that are not private.

Offline nanopico

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 742
  • Liked:
  • Likes Given: 3
Re: Learning to program internet connections
« Reply #2 on: March 01, 2016, 08:33:20 PM »
I would agree with MacTron on his sentiments completely.

But I can offer a bit of help in this specific instance.
For example, it says that you can call the functions of the internet classes synchronously if you use the timeOut parameter, but if you try this then it will complain that you used too many parameters.

Are you using the HttpSocket class?
If you are how many parameters are you passing 1, 2 or 3? I assume 2 or 3 since you are setting a timeout?

if 2 parameters the Get method returns a string of what was retrieved.  If 3 parameters it returns a boolean if the call succeeded or failed.  In either case,  the compiler expects that return value to be assigned to something.  Failure to do so will result int the too many parameters error. 

So this will work and put the results in the string result.
Code: [Select]
Dim h as new HTTPSocker
Dim result as string
result = h.Get("www.macos9lives.com", 30)

This will fail to compile with the too many parameters error.
Code: [Select]
Dim h as new HTTPSocker
h.Get("www.macos9lives.com", 30)

This will also fail like the one above
Code: [Select]
Dim h as new HTTPSocker
Dim f as FolderItem
f = GetFolderItem("Drive:SomeFile")
h.Get("www.macos9lives.com", f, 30)

But this will work
Code: [Select]
Dim h as new HTTPSocker
Dim f as FolderItem
Dim result as Boolean
f = GetFolderItem("Drive:SomeFile")
result = h.Get("www.macos9lives.com", f, 30)

I want to extend it with HTTPS using the CONNECT command.

Using the HttpSocket won't help you with trying to use the CONNECT command.
That just creates a sort of man in the middle proxy where the raw tcp stream is marshaled between the two end points through the proxy.  The HttpSocket runs and connects at the Application level of the OSI stack.  For using Connect you need to control the stream at the Transport level of the OSI stack (TCP).
If it ain't broke, don't fix it, or break it so you can fix it!

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 597
  • Liked:
  • Likes Given: 0
Re: Learning to program internet connections
« Reply #3 on: March 02, 2016, 09:23:15 AM »
But this will work
Code: [Select]
Dim h as new HTTPSocker
Dim f as FolderItem
Dim result as Boolean
f = GetFolderItem("Drive:SomeFile")
result = h.Get("www.macos9lives.com", f, 30)
This might indeed work. I'll try it.

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 597
  • Liked:
  • Likes Given: 0
Re: Learning to program internet connections
« Reply #4 on: March 02, 2016, 09:35:30 AM »
Using the HttpSocket won't help you with trying to use the CONNECT command.
That just creates a sort of man in the middle proxy where the raw tcp stream is marshaled between the two end points through the proxy.  The HttpSocket runs and connects at the Application level of the OSI stack.  For using Connect you need to control the stream at the Transport level of the OSI stack (TCP).
I'm using an SSLSocket.
I tried this on XP with Firefox:
Window1 has an SSLSocket a
a.secure=false
a.port=444
a.Listen()

Firefox has proxy settings 192.168.1.4:444

I type "https://192.168.1.4"

Then I get the Connected event in a.

s=ReadAll()

=> s = "CONNECT 192.168.1.4:443 HTTP/1.0"

At this point I have an unencrypted connection between Firefox and my program, which is what I wanted.

Then I want an encrypted connection between my program and the server.

So I type:

dim b as HTTPSecureSocket
b=new HTTPSecureSocket
b.Get("https://192.168.1.4",f)

Whatever data arrives now in b can be sent to a.
They are both unencrypted.
That should work, but I can't test it.
First I need a server with secure connections.

Offline nanopico

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 742
  • Liked:
  • Likes Given: 3
Re: Learning to program internet connections
« Reply #5 on: March 02, 2016, 11:29:05 AM »
First I need a server with secure connections.

Do you just need a web site that runs over https?

Google does this by default on most modern browsers.

You could try that just as a test.
If it ain't broke, don't fix it, or break it so you can fix it!

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 597
  • Liked:
  • Likes Given: 0
Re: Learning to program internet connections
« Reply #6 on: March 03, 2016, 06:50:14 AM »
But this will work
Code: [Select]
Dim h as new HTTPSocker
Dim f as FolderItem
Dim result as Boolean
f = GetFolderItem("Drive:SomeFile")
result = h.Get("www.macos9lives.com", f, 30)
This might indeed work. I'll try it.
It works if result is a string.

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 597
  • Liked:
  • Likes Given: 0
Re: Learning to program internet connections
« Reply #7 on: March 03, 2016, 06:55:56 AM »
I just copied IIS Express and NGINX. As I can read on Wikipedia, IIS 5.1 was shipped with Windows XP Pro and IIS 6.0 was included with Windows XP Pro x64 Edition so I should have both of them, except I don't remember having seen them. Apache is included in OSX so I should have that too. But still no server with SSL for OS 9.

Offline nanopico

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 742
  • Liked:
  • Likes Given: 3
Re: Learning to program internet connections
« Reply #8 on: March 03, 2016, 07:41:56 AM »
I just copied IIS Express and NGINX. As I can read on Wikipedia, IIS 5.1 was shipped with Windows XP Pro and IIS 6.0 was included with Windows XP Pro
IIS is not installed by default and needs to be added through add/remove features.
Since IIS runs as a service there is nothing to see so you need to use the IIS Managment Console to configure it.

I had found at one time someone had ported apache/php to mac os 9.  They did it by creating an entire posix runtime environment.
I downloaded it once but have never found it again and no longer have it.  I wish I did as it would be fun to play with.

I don't believe MacHTTP supported SSL, but the source is now available at https://sourceforge.net/projects/machttp
so you could add that functionality in.

Or you could try to find a copy of WebStar which I do believe supported SSL.

Keep in mind though that any web server for OS 9 that does support SSL will probably not support the current versions high encryption bit levels and algorithms.
If it ain't broke, don't fix it, or break it so you can fix it!

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 597
  • Liked:
  • Likes Given: 0
Re: Learning to program internet connections
« Reply #9 on: March 04, 2016, 05:54:17 AM »
Real Basic is not for *real* development. IMHO.
From Wikipedia:
Quote
After REALbasic had gained a reputation for enabling unexperienced developers to release poorly-written software, the name was changed once more from REALbasic to Real Studio.
I think the problem with REALbasic is that you will write a program which is much too slow if you don't understand it quite right.

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 597
  • Liked:
  • Likes Given: 0
Re: Learning to program internet connections
« Reply #10 on: March 04, 2016, 05:59:25 AM »
I don't believe MacHTTP supported SSL, but the source is now available at https://sourceforge.net/projects/machttp
so you could add that functionality in.

Or you could try to find a copy of WebStar which I do believe supported SSL.
I copied it and I'll look for WebStar.

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 597
  • Liked:
  • Likes Given: 0
Re: Learning to program internet connections
« Reply #11 on: March 04, 2016, 06:00:32 AM »
I tried my test program with NGINX.
The first data that arrives in the SSLSocket is unencrypted, the rest is encrypted, even with secure=false.
I can't decrypt it and I can't send an encrypted reply.
I need an SSLStreamReader and SSLStreamWriter or else an newer version of Real Basic with full SSL support.
Which is the first version with full SSL support?

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 597
  • Liked:
  • Likes Given: 0
Re: Learning to program internet connections
« Reply #12 on: March 04, 2016, 06:09:38 AM »
Here they have an open source webserver in REALbasic:
http://www.boredomsoft.org/webserver.bs

They say a modern version (e.g. 2008 and newer) of REALbasic is needed.

Offline nanopico

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 742
  • Liked:
  • Likes Given: 3
Re: Learning to program internet connections
« Reply #13 on: March 04, 2016, 06:20:16 AM »
Real Basic is not for *real* development. IMHO.
From Wikipedia:
Quote
After REALbasic had gained a reputation for enabling unexperienced developers to release poorly-written software, the name was changed once more from REALbasic to Real Studio.
I think the problem with REALbasic is that you will write a program which is much too slow if you don't understand it quite right.

This is probably true, but I also found that RealBasic forced the user to program in very Windows way and I felt that if you were doing Mac development it just leaves out some of the things specific to Mac. 

I tried my test program with NGINX.
The first data that arrives in the SSLSocket is unencrypted, the rest is encrypted, even with secure=false.
I can't decrypt it and I can't send an encrypted reply.
I need an SSLStreamReader and SSLStreamWriter or else an newer version of Real Basic with full SSL support.
Which is the first version with full SSL support?

In an SSL connection the initial communication is always un-encrypted to establish encryption methods and keys from there any data is transferred using that data.  So that behavior sounds correct.

I would have assumed the SSLSocket would take in data and encrypt it and when it receives data it would decrypt it.  If it doesn't then it should provide some properties to retrieve the keys/methods it uses with the remote end for transmission so that you can decrypt it.
I am not at a location right now where I can look up the documentation of the SSLSocket.

If it ain't broke, don't fix it, or break it so you can fix it!

Offline nanopico

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 742
  • Liked:
  • Likes Given: 3
Re: Learning to program internet connections
« Reply #14 on: March 04, 2016, 06:38:16 AM »
Here they have an open source webserver in REALbasic:
http://www.boredomsoft.org/webserver.bs

They say a modern version (e.g. 2008 and newer) of REALbasic is needed.

I think 5.5.5 was the last version to target OS 9 and lower.
If it ain't broke, don't fix it, or break it so you can fix it!

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 597
  • Liked:
  • Likes Given: 0
Re: Learning to program internet connections
« Reply #15 on: March 04, 2016, 06:54:30 AM »
Indeed, REALbasic 2006r1 doesn't have an OS 9 version.
This contains REALbasic 2006r1 for all supported platforms:
http://extras.springer.com/Zip/2006/978-1-59059-634-0.zip
but no password.

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 597
  • Liked:
  • Likes Given: 0
Re: Learning to program internet connections
« Reply #16 on: March 04, 2016, 08:39:18 AM »
There has been a plug-in for SSL sockets from Essentrix:
http://www.macworld.com/article/1018154/ssl.html
This supported Carbon, so probably also OS 9.

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 597
  • Liked:
  • Likes Given: 0
Re: Learning to program internet connections
« Reply #17 on: March 04, 2016, 08:44:15 AM »
It was for REALbasic 3, OS 9 certainly supported:
http://www.macupdate.com/app/mac/6017/ssl-socket

Offline MacTron

  • Global Moderator
  • Platinum Member (500+ Posts)
  • *****
  • Posts: 2118
  • keep it simple
  • Liked:
  • Likes Given: 2
Re: Learning to program internet connections
« Reply #18 on: March 04, 2016, 09:06:35 AM »
Real Basic is not for *real* development. IMHO.
From Wikipedia:
Quote
After REALbasic had gained a reputation for enabling unexperienced developers to release poorly-written software, the name was changed once more from REALbasic to Real Studio.
I think the problem with REALbasic is that you will write a program which is much too slow if you don't understand it quite right.

First of all I have a very little experience as a software programmer. I only felt really comfortable with Think Pascal.
My experience with Real Basic is very short too. I felt very disappointed when I tried it: Too complex for a very choppy result. Any way, it will be suitable for a small utility or for draft application.
But if your  application grows you'll regret to have starting using  Real Basic.

Any way, good luck with your work  ;D
Please don't PM about things that are not private.

Offline nanopico

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 742
  • Liked:
  • Likes Given: 3
Re: Learning to program internet connections
« Reply #19 on: March 04, 2016, 09:12:24 AM »
Are you using SSLSocket to try to transfer data over the HTTP protocol?
If so are you manual sending all the HTTP commands and reading the responses?
If you are using HTTP there is a HTTPSecureSocket class that might work better.
SSLSocket looks to be very limiting supporting only SSLv2 and SSLv3.

If it ain't broke, don't fix it, or break it so you can fix it!

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 597
  • Liked:
  • Likes Given: 0
Re: Learning to program internet connections
« Reply #20 on: March 07, 2016, 08:25:52 AM »
Classilla and MacSSH are open source and contain code for secure connections.
This can be used to write an SSL stream reader and writer.
I found several versions of REALbasic 2007 and 2008 for OSX on a Polish site.
I think that they all can run on OSX 10.4.
Hopefully I find a good password in a serial box.
Then I have several options.

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 597
  • Liked:
  • Likes Given: 0
Re: Learning to program internet connections
« Reply #21 on: March 07, 2016, 08:30:04 AM »
My idea was to use SSL stripping where possible, or else man-in-the-middle (when the URL is built by a script).
So the proxy would replace "https://abc.com/x" with "http://s.abc.com/x" in the HTML.
If the proxy receives a request for "http://s.abc.com/x" then it makes a secure connection to "https://abc.com/x".
If the proxy receives a request for "https://abc.com/x" then it does man-in-the-middle.
What do you think of it?

Offline nanopico

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 742
  • Liked:
  • Likes Given: 3
Re: Learning to program internet connections
« Reply #22 on: March 07, 2016, 11:03:31 AM »
That sounds like how a proxy server should generally work.
Sound like it should work.
If it ain't broke, don't fix it, or break it so you can fix it!

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 597
  • Liked:
  • Likes Given: 0
Re: Learning to program internet connections
« Reply #23 on: March 09, 2016, 05:49:08 AM »
Which is the first version with full SSL support?
From the manual:
Quote
Beginning with version 2006 Release 4, SSLSocket supports secure listening sockets.