Archive

Archive for October, 2018

Supporting #IE10 on #AWS #Cloudfront

October 17, 2018 Leave a comment

ie10-1

IE10 may have less than 5% worldwide usage, but if you want to have a inclusive website, then perhaps you shouldn’t confront them with this error message (above) when you try to serve them HTTPS content. – Maybe they should updgrade. but as a developer, that’s not your choice to make.

If you use Amazon Cloudfront over HTTPS, then by default, TLS 1.0 is not supported, and by default, TLS 1.1 and TLS 1.2 are not supported on IE 10. So, if you can’t get your user to upgrade, then you have to make cloudfront more inclusive (and yes. less secure). But if you’re just serving images, then perhaps it’s not a big issue.

So, to fix this, go to Cludfront, and click on your distribution, click edit, and change your security policy to TLSv1_2016 and Edit.

ie10-2

Wait for your distribution to deploy, and you can use SSLscan to verify that TLS 1.0 is now supported, along with TLS 1.1 and TLS 1.2

 

 

Advertisements
Categories: Uncategorized

Make an HTTP request via #TCP over an Authenticated #proxy in C#

October 11, 2018 Leave a comment

working-behind-proxy-network

If you ever find yourself reverting to writing HTTP code using TCPClient, do a double-think, since there is very few situations where you genuinely need to resort to writing TCP/IP code. You can do an Authenticated proxy call using standard HTTP calls, by just setting the networkCredentials on a WebProxy class.

However, if you’ve read this caveat, and you still insist that you need to write code at TCP/IP level, then here’s some code that demonstrates how to make a simple HTTPS get request via an Authenticated HTTP Proxy (Luminati)

The authentication token, which I’ve omitted below, for obvious reasons is a base64 encoded version of your username : your password .

var tcp = new TcpClient(“zproxy.luminati.io”, 22225);
var stream = tcp.GetStream();

var connect = Encoding.ASCII.GetBytes(“CONNECT icanhazip.com:443 HTTP/1.0\n” +
“proxy-authorization: Basic XXXXXX==\n\n”);
stream.Write(connect, 0, connect.Length);
var rawStream = new StreamReader(stream);
rawStream.ReadLine();
var ssl = new SslStream(stream);
ssl.AuthenticateAsClient(“www.icanhazip.com”, null, SslProtocols.Tls12, false);
var strPostString = “GET / HTTP/1.0\r\n” +
“Host:www.icanhazip.com\r\n” +
“\r\n”;
var send = Encoding.ASCII.GetBytes(strPostString);
ssl.Write(send, 0, send.Length);
var sr = new StreamReader(ssl);
var str = sr.ReadToEnd();
tcp.Close();
ssl.Close();
return str;

 

Categories: Uncategorized

Determine the age of a #Spanish Vehicle through it’s number plate

October 9, 2018 Leave a comment

Grid

Take the last three digits of a spanish number plate, and find the closest three letters in the grid above to aproximate the age of the vehicle. This grid also gives an idea of how many cars are sold in spain in any given month.

Need to code this up in C#? here’s a GIT repo that you can clone freely;

https://github.com/infiniteloopltd/MonthAndYearFromSpanishRegistration

Need more info, check our our spanish API at http://www.matriculaapi.com/

Categories: Uncategorized

Creating a #macOS App using HTML and #Javascript

October 6, 2018 Leave a comment

Screenshot 2018-10-06 at 20.38.30

You can create great macOS apps with Swift, and if you’ve got the time to learn a new language, then this is the way to go. But if you already have something cool made with HTML and Javascript, then you can turn it into a macOS app with a few simple steps.

TL;DR;

If you want to skip to the end, you can just clone the GIT repo at https://github.com/infiniteloopltd/UnderTheCryptOSX

But, if you fancy going step by step, – open up XCode and create a new macOS / Cocoa app. Drop a WKWebView onto the form, and set it’s constraints so that it fills the view. Then drag an outlet called;

@IBOutlet weak var webkitview: WKWebView!

You’ll need to add a reference to WebKit as follows;

import WebKit

Then in the viewDidLoad, add the following lines

let url = Bundle.main.url(forResource: “index”, withExtension: “html”)!
webkitview.loadFileURL(url, allowingReadAccessTo: url)
let request = URLRequest(url: url)
webkitview.load(request)

You can then go Add files to … and add your index.html to the project. Now, if you run this now, you may get a white page. To get around this, you will need to go to the project > Capabilities > App Sandbox and click “Outgoing connections (Client)”

Screenshot 2018-10-06 at 20.44.41

Another thing that you may have to do, or else the app may get rejected by apple, is to exit the app when the window is closed. you do this in AppDelegate.swift as follows;

func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool
{
return true
}

 

Categories: Uncategorized

Sending multiple attachments with #SMTPJS

October 6, 2018 Leave a comment

smtpjs

One of the limitations of SMTPJS.com is that you can only send one attachment, this blog post demonstrates a way of sending multiple attachments, by zipping them into one file. It also keeps the size of your email down also.

This uses the JSZip library, which I’ve loaded via the cloudflare CDN. Note the mime type used: application/x-zip-compressed this is important, so that SMTPJS will send the file as a attachment named file.zip, rather than the default file.txt

<html>
src="https://smtpjs.com/v2/smtp.js">
src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.5/jszip.js">
language="javascript">
function uploadFileToServer()
{
  var zip = new JSZip();
  var numberOfFiles = event.srcElement.files.length;
  var numberOfProcessedFiles = 0;
  for(var i=0; inumberOfFiles; i++)
  {
    (function(i){
     var file = event.srcElement.files[i];
     var reader = new FileReader();
     reader.readAsBinaryString(file);
     reader.onload = function () {
        numberOfProcessedFiles++;
        zip.file(file.name,btoa(reader.result), {base64: true} );
        if (numberOfProcessedFiles == numberOfFiles)
        {
          zip.generateAsync({type:"base64"})
          .then(function(content) {
            var datauri = "data:application/x-zip-compressed;base64," + content;
            Email.sendWithAttachment("YOUR@EMAIL.com",
                "THEIR@EMAIL.com",
                "This is the Subject ",
                "This is the Body - see file.zip attachment!",
                "****SMTP HOST****",
                "****SMTP USERNAME****",
                "****SMTP PASSWORD****",
                datauri,
                function done(message)
                {
                   alert("Message sent OK")
                }
              );
          });
        }
     };
     })(i);
  }
}

<input type="file" id="fileupload" onchange="uploadFileToServer()" multiple/>
</html>


 

Categories: Uncategorized

Charging a credit card with #Stripe in C#

October 4, 2018 Leave a comment

twitter

This has been demoed a million times before, but just to show how ridiculously simple it is to bill a card with stripe, here’s a code example in C#

You first open package manager and type

Install-Package Stripe.net

Then use the following code:

var strStripeSecretKey = “sk_live_xxxxxxxxxxxxxx”;
var strCardNumber = “xxxxxxxxxxxxxxxxx”; // Long card number
var strCvCNumber = “xxx”;
var intExpiryMonth = 1;
var intExpiryYear = 2019;
var requestOptions = new StripeRequestOptions() { ApiKey = strStripeSecretKey };
var chargeService = new StripeChargeService();
var chareResponse = chargeService.Create(new StripeChargeCreateOptions()
{
Amount = 1000, // In pence – i.e. £10
Currency = “GBP”,
SourceCard = new SourceCard()
{
Number = strCardNumber,
Cvc = strCvCNumber,
ExpirationMonth = intExpiryMonth,
ExpirationYear = intExpiryYear
}
}, requestOptions);

And that’s all there is!  – wow…

 

Categories: Uncategorized