Click or scroll down Circle me on Google+ Fork me on GitHub Follow me on Twitter Ask me on Stack Overflow Gild me on Reddit Code Ninja, Entrepreneur, Idiot ChalkHQ — consulting, prototyping, mentoring HighF.in — resolve innefficiencies in your startup's workflow DearDrum.org — online open-mic / creative space The Dirac Equation (click to WikiPedia) A maxim Sun Tzu references in his magnum opus The Art of War

If you know the enemy and know yourself, you need not fear the result of a hundred battles.
If you know yourself but not the enemy, for every victory gained you will also suffer a defeat.
If you know neither the enemy nor yourself, you will succumb in every battle.
Fork me on GitHub

Tags

actionscript ad-hoc networks Adobe AIR anonymous Apple array Browsing convert Debugger Error Facebook file permissions Flash Flex fonts function future Google Google Plus grid hackers html javascript logs loop network p2p php privacy regexp Security Server social ssl technology terminal time Twitter upgrade Web 2.0 Web 3.0 Web 4.0 Web 5.0 wordpress

Featured Posts

  • Javascript: Undefined parameters
  • The Web, A Look Forward
  • Let Postfix send mail through your Gmail Account – Snow Leopard
  • Archives

  • April 2013
  • December 2011
  • July 2011
  • June 2011
  • March 2011
  • February 2011
  • January 2011
  • November 2010
  • October 2010
  • September 2010
  • July 2010
  • May 2010
  • Categories

  • Code
  • Design
  • Opinion
  • Security
  • Tools
  • Uncategorized
  • Latest Posts

    Flex 4 Spark Button Weird Label Behaviour

    I'm currently migrating DearDrum.org Desktop to flex 4. Using an embedded font for the main navigation buttons; which are used to switch between states. When you're in a specific state the nav button for that state switches to a "selected button" skin which is just a copy of the regular skin with a few colours changed. The reason for doing that instead of just disabling each nav button in its given state is so they stay interactive, and are used when in the state to refresh/reload the state.

    This worked fine but now in it's spark implementation when moving between random states the button label if it contains a single space will occasionally jump around - providing you've rolled over the button before changing state. It would take a boring while to explain it in more detail so I just recorded the behaviour. Best watched in full screen.

     

    Facebook is Inherently Insecure

    I've talked a lot about their unpleasantly ghostly Privacy Policy and Myspace-esk TOS, you know the ones that sign away equal rights and entitlement to your identity indefinitely just by using their site. But I haven't talked about the intrinsic insecurity of a social network like Facebook.

    Fact: A significant amount of computer users exhibit insecure behaviour online. They don't use strong passwords, they don't opt for https://, they don't work on virus/keylogger free computers, and they answer spam emails(shocking I know).

    Fact: Facebook contains not just a list of all your friends, but all your friends' friends, and a record of your interactions with them. Your social network and scene.

    Think about it like this: If someone gains access to your email account, they can see your contact list, and they can see how you talk to your contacts. If they have a lot of time on their hands they can read huge volumes of emails and piece together your relationships.

    On Facebook, they can see your list of friends, family, your communication with them, but more importantly their communication with each other. A schematic of your social life heavy with descriptions of how you know each person. Assuming you've toggled your privacy settings back so only your friends can see your stuff, and did so before google indexed your profile and friends list. Every one of your Facebook friends is an attack vector for all the personal info you've posted and that your friends and family have posted that doesn't even relate to you. More clearly A is an attack vector for B, A<->B, C, and B<->C.

    In addition 3rd party Facebook app developers also have access to your social circle and information. Your Buddy wants to try an app from some developer he doesn't know? Well they just grabbed your entire social network and know a LOT about you and all your friends.

    On Facebook, you are not the only one responsible for keeping your information safe. Anyone you friend is. Would you trust your Facebook friends with your Facebook username and password?

    It's given birth to a new breed of highly personalized spam. Imagine getting an email from someone you don't know offering you cheap Viagra and even using your first name. Sounds like a scam right? Sounds like if you clicked on the link you'd probably get a virus or some kind of malware installed on your system right? Right.

    Now imagine getting an email from Sarah your old girlfriend, where she talks about something you did the other night at a party (which you posted a photo of on Facebook being careful to only let your friends see) and then telling you she wants you to see a funny youtube video. You click on the link and guess what? It wasn't Sarah at all! "What?!", you say? How's that possible?

    The Spammer, we'll call him Spammer, gains access to Jim(your buddy)'s Facebook account because a) he accidentally typed in FaceBack.com without realizing it and tried to login. His credentials were phished and the Spammer was in his account within 30 seconds, or b) Jim(same Jim) adds an application where the 3rd party developer wrote a bunch of code that scrapes all of Jim's and your information and emails it to him(the Spammer) as a .zip file when it's done. The Spammer goes ahead and looks through Jim's friends list, then through yours. Looks through your photos and descriptions of each of your contacts. Looks at Sarah's profile and write's down her email address, attaches the photo to an email, the email spoofs Sarah's email address(this is astoundingly easy without her login credentials from any computer connected to the internet) and adds an html link that looks like this in code:

    <a href="http://sitewithavirus/silentkeylogger"> http://youtube.com/v=harmlessvideo</a>

    and to you looks like this:

    http://youtube.com/v=harmlessvideo

    Clicking on the link will obviously take you to the virus and not to youtube and if you use Internet Explorer, or the Spammer is using a zero-day exploit for one of the other browsers, you're fucked due to arbitrary code execution.

    A site that gives anyone other than you access to a super detailed schematic of your social circle is inherently insecure. Facebook should not expose your real life social circle to anyone even other people in that circle. But they do and will because a large part of their user retention plays on social needs for acceptance/approval/jealousy/etc. which requires exposing that information to people you normally wouldn't and in a permanent public manner that you normally wouldn't.

     

    Flash Snippets for Flash Builder 4

    I'm getting used to Flash Builder 4, man is it fast. I came across this plugin by Lee Brimlow, it's SnipTreeView adapted to work with .mxml files and in FB4. Just download it from his blog and add it to the plugins folder, then restart. There's a quick video how to, highly recommended.

    Flash Snippets [http://theflashblog.com/?p=1494]

     

    The Future of Flash – Apple’s iPad

    The internet is a buzz with talk of the downfall of FlashFlash, the only web platform with 99%+ penetration rate cross platform, and 90%+ penetration rate for their latest version only 3 months after release. The platform that powers the web's content, games, and more than 75% of all interactive online media. That's now able to power desktop and mobile applications, and with the imminent release of Flash 10.1 will bring far more efficient and lower memory/ram usage. So much lighter on cpu in fact that it's able to play HD Youtube videos on mobile phones and netbooks without a problem. Yes, Flash, the downfall of Flash.

    There are two main arguments to this. The first is the emergence of HTML 5. HTML 5 finally allows video and audio playback without any plugins, and canvas - a tag which allows for complex drawing, embedding fonts, etc. etc. Things Flash has been able to do for years, has a huge head start on, and does really well. Flash has supplied us with everything from video streaming to blackjack, and even website design as a whole, and yet HTML 5 is supposed to just oust the holder of the crown and sceptre when it's finalized? I don't think so. The problem nobody seems to get is that Internet Explorer still has a majority market share, by a lot depending on who you ask - and Microsoft will likely NEVER support standards because it directly counters their business model. Aside from that, and the fact that every browser that will support HTML 5(ie: everyone else), will implement it differently from each other, with different aesthetics, features, code, BUGS, etc. But even more crucial the HTML 5 spec itself is not even complete yet. It's not even finished, and it's unfinished in a deadlock between the web giants who not only can't decide or agree on which video and audio formats are the best performance wise, but also who owns the rights to implement those formats in their browser and who'll have to pay massive royalties should the true patent holders (still somewhat unknown for sure) decide to cash in. No one wants to properly look this up for a variety of reasons and so HTML 5 - supposed to bring the web together and herald a new dawn of the internet can only work if EVERYONE does in fact come together and implement it in exactly the same way; disregarding that ubiquitous HTML 5 means EVERYONE loses something, some everything.

    The other main argument is the Apple iPad - just announced. Which like the iPhone doesn't support Flash. Apple uses the old "Flash is too resource intensive" argument to convince you that limiting you from the full web is a good thing. This simply isn't true. It's false. Both iPhone 3Gs and iPad could happily run the current version of Flash or Adobe AIR just like your laptop/desktop. And it's also entirely up to the developer and how they program and how resource intensive they make their flash app/widget/game/etc. The only reason, listen up, the ONLY reason Apple does not support Flash, is because the Flash platform already powers so many games and useful tools and full blown applications on the internet it threatens Apple's very business model of the Itunes/App Store. Apple wants companies to develop all their apps again specifically for the iPlatform and invest in it. If you could make a Flash app that ran on the iPhone it would also run on Android and every other smart phone. But if you invest in the iPlatform your app will only run on the iPlatform. If Apple was a monopoly the FTC would be pushing them down for their anti-competitive vindictive behaviour.

    Apple doesn't block Flash support in their mobile products because they want to push innovation in HTML 5. If HTML 5 was advanced enough, or popular enough to be worth creating the caliber of applications possible on Flash, Apple would immediately configure mobile Safari to block, impede, and hinder the advancement of standards just like Microsoft with IE. In a heart beat. Apple promotes HTML 5 because they know it'll be years before it's anywhere close to where Flash is today, if ever. In fact Apple is one of the "powers that be" preventing the HTML 5 spec from being finalized in the codec wars. Apple wants you locked into their platform. Apple doesn't care about advancing the web, or a better user experience, they care about the big media companies bringing their content online through Apple's platform. Apple wants the iPad to replace your tv, radio, and other media consumption devices. They do not care about the open web.

    Adobe on the other hand continues to open up the Flash platform and benefits from creating a ubiquitous platform across desktop and mobile. There are fully open source versions of their Streaming and Application servers, and free and open source ways to develop for their platform. Anyone can build a Flash application, for the browser, desktop, Windows, Mac, Linux, Safari, Internet Explorer, Chrome, Firefox, Opera, etc. etc. Build one application and deploy everywhere using an incredibly powerful, scalable, and mature toolset. Apple on the other hand - should you decide to invest in it, puts you in a position where you may or may not after months of development time and costs even get your application onto a device, regardless you'll have payed Apple to be a developer and to submit it in the first place or even get access to their development tools, and should you get through the random and gauntlet of barriers they can still remove your software from their platform and devices at a moments whim. They can and do literally remove your application from people's phones after being downloaded and used without warning to backup the data put into or created by your app. Anytime for any reason. AND if you're lucky enough to get your application through all these extra months of hurdles and costs and lost revenue you're only gaining access to one small subset of mobile devices.

    It is absolutely ridiculous to think the HTML 5 is going anywhere anytime soon, let alone even coming close to eclipsing Flash in any way. Not from Apple, they don't want anything to compete with their platform for getting applications on their devices - Flash or otherwise(HTML, Java, Silverlight), and not from anywhere else because it's just not mature, complete, or will over the next 12-24 months be implemented uniformly or consistently across browsers or operating systems. Even in the event that somehow all these competitors come together to reduce their own profit margins and upset shareholders in the name of benefiting the user and happy popcorn rainbows, it will still only have the capabilities of Flash 8-ish. By then Flash Player 11 will be out and all the best web apps will have an Adobe AIR application front end and you'll use an Adobe AIR application to browse through a market place of Adobe AIR apps. Yes we're moving towards the cloud, and yes the cloud and desktop are becoming indistinguishable, but moving into the browser is only a temporary measure for some companies before they build a desktop front end for their service.

    The iPad, iPhone, and iPod are toasters. Every person with an iMobile device also has a desktop or laptop for work and actually managing their digital life. Every single person I've seen raving for HTML 5 and the downfall of Flash depends heavily on Flash and its phenomenal capabilities. They're all idiots.

     

    Adobe AIR, Flex, and Socket Policy Files

    You probably found this because you're trying to make a socket connection from Flex/Flash and getting the following error:

    SecurityError: Error #2123: Security sandbox violation:

    Adobe went through a number of phases making the rules for serving and checking Policyfiles stricter. There are different security sandboxes. If you publish your flex/flash application on domain.com, and the application attempts to load content from domain2.com, it will look for a Cross Domain Policy File at domain2.com/crossdomain.xml to get permission. It does this automatically, however you could specify the location of the Cross Domain Policy File in your flex application using the following method:

    Security.loadPolicyFile("http://domain.com/remote_content/crossdomain.xml")

    A Cross Domain Policy File only has authority to grant access to content below it in the folder hierarchy. So a policy file in /remote_content/ can't grant access to content in the root folder, and in addition a Policy File at the domain root can override any other policy file. It has maximal authority. Subdomains are considered separate domains - which as a side note most search engines see subdomains that way too.

    Now that's Cross Domain Policy Files, In general Adobe Air applications operate in one of the local system sandboxes and has thus have access to content on any domain. This post is about Socket Policy Files. When you access regular web content you're generally connecting to your server on port 80 and being served content by Apache or whatever web server you happen to be running. When you do this you're using http protocols under the hood and never have to deal directly with that crazy stuff. If you want to make a raw socket connection to your server you will need to serve up a Socket Policy File on a specific port.

    First I just want to stress the difference between a Cross Domain Policy File and a Socket Policy File. For some reason my dyslexia and the ton of misleading, vague, and now out of date and incorrect information I kept thinking they were the same thing. Second there is no way as far as I'm aware to serve a Socket Policy File with Apache.

    The default port for flex/flash to search for a socket policy file on port 843. There are several places on the web that talk about being able to connect to higher port numbers without a Socket Policy File, well that doesn't seem to be the case anymore. Just assume that any raw socket connection from a flex/flash client requires a Socket Policy File.

    You can serve the Socket Policy File from the port you're connecting to, but this is tricky considering the manner in which Flex/Flash goes about loading the Socket Policy File and rewriting the service to serve this up, especially if you're using server software built by someone else, means it's just better to keep the Socket Policy File Server as a separate always running entity on the system.

    Now in the simplest implementations you need a process either written in python, perl, c++, php cli, or whatever. It needs to be listening on port 843. It has to wait for - very specifically - the following string<policy-file-request/> followed by a NULL byte. Upon receiving that it needs to serve up the policy file which needs to at least have allow-access-from domain set to *, and to-ports set to *. You should use the links at the end of this post to familiarize yourself with the differences between and all options you can specify in Policy Files. It's easiest to keep the Policy File as an actual file, instead of adding the text of the file to your custom server code. And that's it!, now you can go on with a better idea of what information out there is out of date or not.

    Here are some important links to help you on your journey:

    Adobe on setting up a Socket Policy File Server

    Adobe on Policy File changes for flash 9 and 10

    Adobe on the structure of Policy Files

    An intro to Sockets

    Working PHP Cli Socket Policy File Server

     

    Running Commands as Root from PHP

    Sometimes you need to automate some terminal commands within your web application. I personally prefer PHP over other server side languages, and in this case its ability to run such commands are fantastinominal. There are a bunch of built in functions for securing/escaping arguments and commands, and a bunch of methods for executing shell commands. The main differences between them are the way output is returned to php. For most cases you should be fine using escapeshellarg() and shell_exec() methods - assuming you're using variables posted to your server code as arguments. You should read up on the various program execution methods over at php.net, and research all the implications and security risks involved in using them.

    This post doesn't focus on their use, but instead on how to give Apache(or whatever web server you're using) root access on your server. In fact what you need to do in order to simplify your scripts is allow the Apache process to run root commandswithout a password. That's RIGHT, without a password. This can be exceptionally dangerous so you may want to limit this root access specifically the no-password-necessary root access only to specific programs you need to run from your scripts. Otherwise a small programming error would let malicious people take full control of your web server with ease.

    The main purpose of enabling no password root access here is so you can easily run programs with a single command and not worry about being challenged for a password or having to deal with that in your server code. It's potentially more dangerous to store your root password in a public facing script than giving it no-password-root-access to a single program. A fair amount of web software and tools will have versions of theircommands that can be run on a single line for this purpose.

    This is for Ubuntu, but should work on most other distros with little tweaking.

    First add the following line to your php script:

    echo shell_exec("whoami");

    This will output the user that Apache, or whatever server is running your php file, is running as on the system. Typically Apache runs as www-data, but your system may be set up differently.

    Now open a terminal and ssh into your web server. Run the following command:

    sudo visudo

    What this does is edit the /etc/sudoers file, however using the visudo command is necessary for changes to properly take effect. Go to the bottom and add the following line to enable the Apache user to sudo without a password:

    www-data ALL=NOPASSWD: ALL

    The first ALL refers to hosts, the second ALL refers to programs/commands. If you only want to grant Apache sudo access to a specific program replace the second ALLwith the full path to the command file. So even though you will be able to call last from your script without worrying about the path, you need to know the actual path here:

    www-data ALL=NOPASSWD: /usr/bin/last

    Now you should have a list of shortcuts at the bottom of the terminal, you want to "WriteOut"(ctrl+o) the file which is the same as saving it, you'll be prompted to choose the path to save to, make sure that you're saving it as /etc/sudoers, otherwise it may try save your changes as a copy.

    You can now try run last from your php script by adding the following to your php script:

    echo shell_exec("sudo last");

    Now that it works you may want to remove the echo lines from your script, or test it with a different command since showing the world who's actually running Apache or the output of last is not something you want.

     

    Flex/Actionscript 3.0 Strip HTML Tags Function

    I needed a function to strip out html tags from a text input, but still let me specify allowable tags.

    Instead of spending time figuring out the regular expressions needed to pull it off and becoming a better programmer, I figured why repeat work someone else has probably already done.. I mean I could be a busy man. Anyway I found this great function on Flexer.info [link]. But after trying it out I noticed that the one tag I really really wanted to be parsed out iframe wasn't. It seems because I had specified i as an allowable tag it was also accepting iframe.

    So with all due respect to Andrei, below is the revised function with the security hole patched.

    All I changed was near the bottom where it determines if it's an allowable tag or not the reg exp was

    <\/?" + tagsToKeep[j] + "[^<>]*?>

    which allowed any character to follow the allowed tag as long as it wasn't a nested tag, which included frame following i. This will also support self closing tags.

     
    // strips htmltags
    // @param html - string to parse
    // @param tags - tags to ignore
    public static function stripHtmlTags(html:String, tags:String = ""):String
    {
        var tagsToBeKept:Array = new Array();
        if (tags.length > 0)
            tagsToBeKept = tags.split(new RegExp("\\s*,\\s*"));
    
        var tagsToKeep:Array = new Array();
        for (var i:int = 0; i < tagsToBeKept.length; i++)
        {
            if (tagsToBeKept[i] != null && tagsToBeKept[i] != "")
                tagsToKeep.push(tagsToBeKept[i]);
        }
    
        var toBeRemoved:Array = new Array();
        var tagRegExp:RegExp = new RegExp("<([^>\\s]+)(\\s[^>]+)*>", "g");
    
        var foundedStrings:Array = html.match(tagRegExp);
        for (i = 0; i < foundedStrings.length; i++)
        {
            var tagFlag:Boolean = false;
            if (tagsToKeep != null)
            {
                for (var j:int = 0; j < tagsToKeep.length; j++)
                {
                    var tmpRegExp:RegExp = new RegExp("<\/?" + tagsToKeep[j] + " ?/?>", "i");
                    var tmpStr:String = foundedStrings[i] as String;
                    if (tmpStr.search(tmpRegExp) != -1)
                        tagFlag = true;
                }
            }
            if (!tagFlag)
                toBeRemoved.push(foundedStrings[i]);
        }
        for (i = 0; i < toBeRemoved.length; i++)
        {
            var tmpRE:RegExp = new RegExp("([\+\*\$\/])","g");
            var tmpRemRE:RegExp = new RegExp((toBeRemoved[i] as String).replace(tmpRE, "\\$1"),"g");
            html = html.replace(tmpRemRE, "");
        }
        return html;
    }

     

    I’m Feeling Lucky Custom Search

    In Firefox, when you type stuff into the main url bar (the "Awesome Bar") it tries to do a GoogleI'm Feeling Lucky search. So if you typed in wiki it would figure out you wanted Wikipedia and take you to Wikipedia.org, it would even take you to the localized version, and when it's in doubt it shows you a standard Google result.

    To get this in Chrome add a custom search engine. Use the following as the url.

    http://www.google.com/search?q=%s&btnI=Im+Feeling+Lucky

    If you make it the default, then any keywords you type into the url bar (the "Omni Bar") will run an I'm Feeling Lucky search. Or you can set the keyword to l. So to use the custom search you would type in l wiki.

     

    HTTPS/SSL/TLS Security Exploit Found – Affects Everyone

    A flaw was discovered in the tls renegotiation process where a 'man in the middle' could take over the connection in a number of ways and perform a number of exploits. Transferring login, credit card, and other important info using https:// is no longer considered secure. The 'man in the middle' could be bumming off your local wireless network, anywhere in between you and your ISP, your ISP and the destination, or on the destinations network. Secure Certificates from the likes of VeriSign can no longer be fully trusted until they find a fix, at which point you'll need to update all your software - browsers, email clients, twitter apps, smart phone firmware, as all the software manufacturers implement and roll out the new(not yet figured out or released) protocol.

    Luckily the vast majority of internet users are stupid and this won't affect activity on the internet a bit, even people that are reading or writing this post will still log into their email accounts and go about their online life relying on sheer improbability of them being exploited by this massive(read: catastrophic) security hole. Once again it's stupidity and recklessness that will keep the world turning cause as we all know if you stop and think about anything too long you'll just give up and go live in the forest like we were originally supposed to.

    If you're interested in a more technical description go here.

    If you're a programmer and you contribute to or write software which implements tls please disable renegotiation a.s.a.p. and push the update to all your users until a new version of the protocol is released.

    via Ars Technica

     

    Let Postfix send mail through your Gmail Account – Snow Leopard

    First of all GRRRRRR!!

    Second, this has been one of those things I randomly get sucked into between projects where I'll spend 5 hours on Google trying to figure it out and getting tiny fragments of info but never actually solving the issue. This is the worst! What the hell am I talking about? Say you use MAMP or whatever as a local testing server. You write some PHP and you need to use the mail() function. You test your new email function to your personal gmail account. Ok so you try it and it doesn't work, or even worse it works a couple times and then never again.  So you go to Applications->Utilities and fire up the Console application. You're shocked to see that there's a message in there saying something about Gmail not accepting mail from your IP address because it's registered as a residential thingy and apparently a lot of spammers use their personal computers to send spam.

    So you say no no there must be some mistake I'm a programmer, not a spammer, I'm just trying to test out my new app. But you quickly realize you're talking to a computer, pleading, and well it doesn't care. typical. After, you cry and try piece together a coherent step by step set of instructions to route all mail sent from your computer through your Gmail account - so it would be from you, and all go through. here's what you do.

    note that $ is used to show a new terminal command, you don't actually type it in:

    Open Terminal - found in Applications->Utilities and type in:

    $ sudo nano /etc/postfix/relay_password

    You'll now be editing a new file called relay_password in the nano Terminal editor, type in the following substituting your login info - it should work with google apps accounts as well:

    smtp.gmail.com example@yourdomain.com:yourpassword

    Press ctrl+o on your keyboard followed by Enter to save the file, then press ctrl+x to exit the editor.

    Now type in:

    $ sudo postmap /etc/postfix/relay_password

    That should tell Postfix to use the relay file you just created. Gmail uses a secure connection so you need to head over to Verisign and download some root certificates. Go to the following url fill out your info and download the .zip file:

    https://www.verisign.com/support/roots.html.

    Now type in the following commands one after another. In the second command it wants the roots.zip you just downloaded, you can just drag the zip file onto the Terminal window and it will fill in it's location, don't do that for the 4th command though. Also note you may have some certificates already on your system, so after the second last command you may be prompted to replace existing certificates, type N so it doesn't replace the ones you have:

    $ sudo mkdir /etc/postfix/certs
    $ sudo cp roots.zip /etc/postfix/certs
    $ cd /etc/postfix/certs/
    $ sudo unzip -j roots.zip
    $ sudo openssl x509 -inform der -in thawte\ Primary\ Root\ CA\ -\ G2_ECC.cer -out thawte\ Primary\ Root\ CA\ -\ G2_ECC.pem
    $ sudo c_rehash /etc/postfix/certs

    Now type in:

    $ sudo nano /etc/postfix/main.cf

    Go to the end of the document, you can delete the MAMP stuff, also note that if you have MAMP Pro and you edit postfix settings from there it'll fuck up what we're doing here. So remember this going into the future and don't do that.

    Paste in the following at the end of the document - note: use the keyboard to get around the document, but use the mouse to right click and paste:

    relayhost = smtp.gmail.com:587
    # auth
    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = hash:/etc/postfix/relay_password
    smtp_sasl_security_options = noanonymous

    # tls
    smtp_tls_security_level = may
    smtp_tls_CApath = /etc/postfix/certs
    smtp_tls_session_cache_database = btree:/etc/postfix/smtp_scache
    smtp_tls_session_cache_timeout = 3600s
    smtp_tls_loglevel = 1
    tls_random_source = dev:/dev/urandom

    Save it like we did before by pressing ctrl+o, then Enter, then ctrl+x.

    Now type in:

    $ sudo nano /etc/postfix/master.cf

    You're now editing master.cf, this is a different file to main.cf we just pasted stuff into. There should be a table in here, find the line in the table that looks something like this:

    #tlsmgr    fifo  -       -       n       -       1       tlsmgr

    Make it look like this - note the comment is removed and fifo should be unix:

    tlsmgr    unix  -       -       n       -       1       tlsmgr

    Save it like the other times pressing ctrl+o, then Enter, then ctrl+x.

    Ok, so at this point you can put the following into terminal and see that it works - put your email address in there twice:

    printf "Subject: blah" | sendmail -f user@gmail.com user@gmail.com

    Postfix is working now. good. You go back to your PHP application and test the mail()function again. If it works then you're done, but if not you panic. You start feeling really hungry. You know that Postfix is working but maybe PHP or Apache haven't gotten the message yet. ok. So you see in Console that sendmail is crashing, you open the crash report in Terminal and it tells you there's an incompatible version of libxml. It wants 10 and you have 9. You begin questioning if any of this is worth it and maybe you should just go sit in front of a tv and forget about doing anything meaningful with the rest of your life.

    After almost installing XCode and registering as an apple developer so you can make and install the newest version of libxml, you wonder if maybe MAMP comes with libxml and find that yes it does. So instead of spending 2 hours upgrading the system libxml only to find it doesn't do anything you just upgrade to the latest version of MAMP (1.8 at the time of writing) and it works. What?? it works? really? yup. so what do you do now?

    REJOICE! with lunch.

    Some of this was scoured from random forums and blogs in the midst of complete frustration and combined into steps that actually work. A chunk however was taken from this post: http://dejan.ranisavljevic.com/2009/05/28/enable-postfix-with-relay-outbound-to-your-gmail-account-on-os-x-leopard/ so check them out.