First off, I’m providing it and the source for free… so feel free to modify, enhance, distribute, etc. Secondly, it hasn’t been thoroughly tested (just roughly). Thirdly, don’t judge on the way I code (hahaha…). I’m sure there are many optimizations and other things that could be done different.
I’m currently in the works of creating a complete ASN.1 encoder/decoder that will work within Xojo. Until then, the way I get the information out of the certificate binary information that is passed is pretty rough (ie. using inStr, etc.); however, it works. Once I’m complete with the ASN.1 encoder/decoder, I will update the source and re-share; however, it’s a HUGE project and will be sometime before I’m done (only doing it on a part of my free time).
Anyhow, I’ve left some source comments, but it’s very limited (I quickly created this in a couple of hours today). I constructed this mainly because I have a few hundred devices that connect to a server. All the data it transmits is IP and very sensitive (meters for utility billing). The way Xojo currently handles SSL, you can’t verify the certificate. This increases the chances of a man-in-the-middle attack (or somebody simply putting any invalid (even self-generated) SSL on their server, running the traffic through a proxy, and process the information on their server) which would completely bypass ours. I found that to be a huge security concern. This solution I provided should only be used as a temporary solution until Xojo incorporates something that works into their solution. Using the socket is pretty simple:
// - secureSocket.connect() function
// -
// - isSecured
// - true - attempts to establish a secured connection w/ verified SSL
// - false - attempts to establish a standard non-secured connection
// - remoteAddress
// - remote address of the connection; must be a DNS name for certificate verification purposes
// - remotePort (optional)
// - remote port of the connection
// - NOTE: defaults to 443 for secured, and 80 for non-secured connections if ‘0’ or not provided
// - unverifiedHandler (optional)
// - secureSocket.SSL_ON_INVALID - attempts to establish a ‘secured’ connection even if the SSL certificate is invalid
// - secureSocket.NOSSL_ON_INVALID - attempts to fall-back to a standard non-secured connection if the SSL certificate is invalid
// - secureSocket.DISCONNECT_ON_INVALID - will disconnect the connection if the SSL certificate is invalid
// - NOTE: defaults to coreTcp.DISCONNECT_ON_INVALID if not provided
// - connectBypass (optional)
// used by the verification process to re-establish a secure connection using the super.construct of connect (shouldn’t be used manually)
// - secureSocket.verificationStatus property
// -
// - secureSocket.VERIFYING_SSL
// - ssl verification process is still pending
// - secureSocket.UNABLE_TO_VERIFY
// - unable to verify an ssl certificate for the connection (address may not contain one)
// - secureSocket.VALID_SSL
// - connection has a valid ssl certificate
// - NOTE: currently only validates based on domain verification, issued date, and expiration date
// - secureSocket.INVALID_SSL
// - connection has an invalid ssl certificate
// - NOTE: currently only validates based on domain verification, issued date, and expiration date
here is the .connect function:
secureSocket.connect(isSecured as boolean, remoteAddress as memoryBlock, optional remotePort as uInt16, optional unverifiedHandler as memoryBlock, optional connectBypass as boolean)
So, if you use something like:
secureSocket.connect(true, "tv.eurosport.com", 0, secureSocket.NOSSL_ON_INVALID)
it will attempt to make a secure connection and fall back to a standard non-secured (http, port 80) connection if the ssl certificate is invalid
secureSocket.connect(true, "tv.eurosport.com", 0, secureSocket.SSL_ON_INVALID)
it will attempt to make a secure connection; however, is the ssl certificate is invalid it will still use the invalid certificate to secure the connection
secureSocket.connect(true, "tv.eurosport.com", 0, secureSocket.DISCONNECT_ON_INVALID)
it will attempt to make a secure connection and disconnect if the ssl certificate is invalid
download link:
https://dl.dropboxusercontent.com/u/13574877/sslVerification.xojo_binary_project