Making Things With Light Killing pixels for nickels since 1994

25Oct/110

Corona project template for xcode

Posted by actionscriptguy

I was poking around the web for some eclipse or xcode templates to help speed new project setup and there was not a whole lot out there that told me what I wanted to know. I figured posting my own method might be of use to others.

I like to use xcode for my atmega328p and Make Controller firmware projects and I have a few custom project templates for them so I figured it could not be too hard to make some cor Corona development.

Start by creating a directory /Developer/Library/Xcode/Project Templates/Other/Corona Application and place the contents of this zip file in it. If you would like to have your template show up in a different category you can move it.

Now when you fire up xcode and create a new project you will see your Corona Application project type in the "other" category. Give it whatever name you like. If everything went well, you will have a few image icon files, a main.lua file and build target with the same name as your project. Double click the build target and make sure that the path to your Corona terminal is correct.

That's it! run the build target and you should see a hello world application running in the Corona Simulator. The main.lua file can be edited in the template project to contain anything you want to be in place each time you create a new project. You can also edit the build settings file in order to alter your Corona SDK path for future projects as well.

To get nice, colorful syntax highlighting for your Lua files just download and install this:
http://www.capgo.com/Resources/SoftwareDev/LuaXcode3SyntaxColor.zip

I Hope this helps get some people off to an easy start using xcode for Corona development.

Filed under: Uncategorized No Comments
24Oct/110

as3crypto: How to get the TLS Engine socket working over SSH/OpenVPN Tunnel

Posted by actionscriptguy

Over the years I have worked on some games/systems that utilize AS3 + sockets and occasionally I needed/wanted to work remotely with VPN over SSH. Ouch. Well Recently I found myself in the same situation except that instead of being a "nice to have" for working remotely, my company quickly promoted its necessity from a feature enhancement to a requirement for the next release of the software. After some coaxing from our engineering manager I did some debugging in the as3crypto TLSEngine class. I discovered why our client could not get/stay connected to our VPN for more than a few minutes. This is the solution I hacked out.

I am going to try and keep the explanation simple, mostly because while I understand the problem, I do not have an intimate understanding of the packet structures for handshakes, application data or certificates.

The following is the function that reads from the socket and forms the packets and parses records. The while loop wants to read bytes off the wire as long as we have 4 bytes. If we have 4 bytes then we try and create a packet and parse a record from the data. For some reason over a standard http connection this works just fine, and the remainder of any packet bytes come in sets of 4.

Excerpt from com.hurlant.crypto.tls.TLSEngine.as (v1.3)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
private function parseRecord(stream:IDataInput):void {
    var p:ByteArray;
    while(_state!=STATE_CLOSED && stream.bytesAvailable>4) {
       
        if (_packetQueue.length>0) {
            var packet:Object = _packetQueue.shift();
            p = packet.data;
            if (stream.bytesAvailable+p.length>=packet.length) {
                // we have a whole packet. put together.
                stream.readBytes(p, p.length, packet.length-p.length);
                parseOneRecord(packet.type, packet.length, p);
                // do another loop to parse any leftover record
                continue;
            } else {
                // not enough. grab the data and park it.
                stream.readBytes(p, p.length, stream.bytesAvailable);
                _packetQueue.push(packet);
                continue;
            }
        }
       
        var type:uint = stream.readByte();
        var ver:uint = stream.readShort();
        var length:uint = stream.readShort();
        if (length>16384+2048) { // support compression and encryption overhead.
            throw new TLSError("Excessive TLS Record length: "+length, TLSError.record_overflow);
        }
        if (ver != TLS_VERSION) {
            throw new TLSError("Unsupported TLS version: "+ver.toString(16), TLSError.protocol_version);
        }
        if (stream.bytesAvailable<length) {
           
        }
        p = new ByteArray;
        var actualLength:uint = Math.min(stream.bytesAvailable, length);
        stream.readBytes(p, 0, actualLength);
        if (actualLength == length) {
            parseOneRecord(type, length, p);
        } else {
            _packetQueue.push({type:type, length:length, data:p});
        }
    }
}

I debugged the function and saw that I had 2 bytes left to create the needed packet and that it was being blocked by the while statement. I hastily changed the while statement to run as long as the availableBytes property is > 0. This allowed my last 2 bytes to be read off the wire and get added to the packet. But not so fast! Now we get an error in the second half of the function around line 24 reading the length. Okay, makes sense. So we should not run the second half of the function (line 21 on) unless we have the 4 bytes needed. Okay, makes sense: allow anything > 0 bytes in order to get our 4, then parse some fancy secure records for reading. So this is what my function looked like afterward:

Modified from com.hurlant.crypto.tls.TLSEngine.as (v1.3)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
private function parseRecord(stream:IDataInput):void {
    var p:ByteArray;
    while(_state!=STATE_CLOSED && stream.bytesAvailable>0) {
       
        if (_packetQueue.length>0) {
            var packet:Object = _packetQueue.shift();
            p = packet.data;
            if (stream.bytesAvailable+p.length>=packet.length) {
                // we have a whole packet. put together.
                stream.readBytes(p, p.length, packet.length-p.length);
                parseOneRecord(packet.type, packet.length, p);
                // do another loop to parse any leftover record
                continue;
            } else {
                // not enough. grab the data and park it.
                stream.readBytes(p, p.length, stream.bytesAvailable);
                _packetQueue.push(packet);
                continue;
            }
           
        }
       
        if(stream.bytesAvailable > 4){
            var type:uint = stream.readByte();
            var ver:uint = stream.readShort();
            var length:uint = stream.readShort();
            if (length>16384+2048) { // support compression and encryption overhead.
                throw new TLSError("Excessive TLS Record length: "+length, TLSError.record_overflow);
            }
            // Can pretty much assume that if I'm here, I've got a default config, so let's use it.
            if (ver != _securityParameters.version ) {
                throw new TLSError("Unsupported TLS version: "+ver.toString(16), TLSError.protocol_version);
            }
           
            p = new ByteArray;
            var actualLength:uint = Math.min(stream.bytesAvailable, length);
            stream.readBytes(p, 0, actualLength);
            if (actualLength == length) {
                parseOneRecord(type, length, p);
            } else {
                _packetQueue.push({type:type, length:length, data:p});
            }
        }
    }
}

The above function stays connected to my OpenVPN like magic! That is much longer than the 60-120 second timeout I was experiencing. This is very similar to Issue 2 reported on the as3crypto repository. This also seems to work as expected over a non VPN connection.

Filed under: Uncategorized No Comments
24Oct/110

Start small, go big!

Posted by actionscriptguy

As my first "practical" post, I present the ultimate USB cable support trick!  I actually use this trick everywhere I go. It has become a ritual.  Never again will I wreck a laptop USB port..EVER.

Check it out here on Instructables.

Filed under: Uncategorized No Comments
24Oct/110

Back to the known

Posted by actionscriptguy

After over 6 years I have decided to get back into community contributions through blogging and tweeting.  So many intense life changes were happening that it became overwhelming to balance it all and maintain a healthy outlook on life.  I became a father 8 years ago, then became a father again 2 years later.  I needed to transition from freelance to salary. I needed to keep skateboarding. I needed to keep painting and creating. I needed to keep hacking and making games. I needed to share and contribute to the RIA community.  I needed to keep playing Sax.  So I did the first thing I needed to do.. then stopped everything else. What a double-edged sword.

Fast forward 6 years after my 2nd daughter was born and here I am, a devoted father, husband and a seasoned application developer.  I am starting to get my painting area set up. I am hacking again at Atmega328s. I am playing Sax in a band. I skate whenever it fits in. I am about to get back into the community that gave so much to me and start sharing my experiences. Then I find out that both of my parents were suffering from dementia.  I rushed to Florida to check on them and ended up moving them back to California to live with my Wife and girls a week later.  We bought a house and then things progressively became tougher and tougher in regards to caring for my parents.  Eventually my father needed to be moved to a care facility and my mother became a full-time visitor.  After 6 months of driving her to see him every morning and picking her up every night, it started to get tough(for my mom) all over again.  My moms dementia had begun to progress quickly due to years of stress from caring for my father for 3 years after his stroke in 2006.  She was getting lost, getting angry and getting depressed.  Needless to say, all of my intentions to get back in my own proverbial saddle again were failing, and once again I found myself putting off personal endeavors.  My mom now lives in an assisted living facility with my father about 20 minutes away.  They are doing as good as can be expected for a couple of hard working folks trying to hold onto the world they knew.  I would be frightened out of my mind, but they have always been very strong and persevering.

Me? Well, I am playing music again every Monday(I am not awesome, but I love to play). I have gotten a couple decent skate session in over at the local schoolyard. I have been hacking at some communication between my Make Controller and some Atmega328s over RF wireless to control stuff attached(using Flex as my client). I am diving deep into Flex4 Mobile and Corona. I am loving my wife.  I am spending time with my girls. I have my parents, who are so dear to me, close...and safe.

So, I am back! I am  tweeting as "actionscriptguy" and will be posting about a lot of (hopefully) interesting things I am messing around with. Long live learning!

Filed under: Uncategorized No Comments