Tag Archives: xcode

Create a Self-Signed wildcard SSL Certificate

Justification

Are you a developer that commonly uses SSL / HTTPS communications on your websites? Do you have multiple development environments hosted on the same domain (such as separate client demo/eval/testing VirtualHosts?), then a wildcarded SSL cert might be for you.

Generating one is very simple process. You will need to have the OpenSSL libraries installed on your computer. All but the worst of Operating systems is likely to have this already installed. If not, you can always go here and get a package: [OpenSSL.org]

Enough reasoning and rationalization, time to get down to business.

Overview

First you must have a private key generated and installed. Second that key is then used to generate a simultaneous signing request and cert signing operation.

Once you have your files created, reference them in the Webserver of your choice (such as nginX or Apach2, if you are using IIS… my heart aches for your plight), using the documentation for that webserver. I’m not going to go into there here, because I’m just taking the time to share this simple process fore generating the CERT.

Step 1 – Generate your private key

If you do not have a private key generated, I’m going to show you have to do it. If you have one that you want to use already, and you know where it is, move onto the next step.

Open a termnal window and execute the following openssl command to generate a private key. For my own installations I never use a key shorter than 2048. Most of the time, I use one that is quite a bit longer. That said, 2048 should provide a sufficiently long key for any practical SSL purposes. Yes, SSL has security issues and a motivated hacker can likely piggy-back it, regardless of your key size… but for the sake of argument and getting through this post, we’ll pretend the Interwebs are a safe place.

Move to the location where you will store your private key (this is a typical location, you can use whatever you want):

cd /etc/ssl/private

Run the command to generate the key:

openssl genrsa 2048 > my.super-awesome.hostname.key

Generating RSA private key, 2048 bit long modulus
......................................+++
.........+++
e is 65537 (0x10001)

So, now we have a key:

ls -l
-rw-r--r-- 1 root wheel 1679 Jan 9 09:41 my.super-awesome.hostname.key

Step 2 – Generate your CERT

This is the fun part, and the 2nd of the super easy steps. To complete this you’ll want to know up front, some important pieces of data, such as the hostname for your site (I’m going to use super-awesome.net for this example). You want to have the address you want to use handy, including the country. Also want to have an e-mail address that will be published in the SSL cert to contact you, and a department and company name if so inclined. Below the actual command and responses will be in bold:


openssl req -new -x509 -nodes -sha1 -days 3650 -key my.super-awesome.hostname.key > my.super-awesome.hostname.cert

You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]: US
State or Province Name (full name) [Some-State]: Kellyfornia
Locality Name (eg, city) []: Sac-of-Tomatoes
Organization Name (eg, company) [Internet Widgits Pty Ltd]: Crazy Assembly House
Organizational Unit Name (eg, section) []: Committee on wasting tax payer money
Common Name (eg, YOUR name) []: *.super-awesome.net
Email Address []: admin@super-awesome.net

Verify that you have the file:

ls -l
-rw-r--r-- 1 root wheel 1927 Jan 9 09:50 my.super-awesome.hostname.cert

That’s all there is to it! You’re done. Now you have a Self-Signed SSL wildcard sert for super-awesome.net. This would allow you to secure (and I always use the word secure with a certain degree of sarcasm) any sub-domain / hostname under super-awesome.net. Examples of what it would handle:

  https://www.super-awesome.net
  https://qa-server.super-awesome.net
  https://some-client.super-awesome.net
  https://another-client.super-awesome.net
  https://ya-client.super-awesome.net

Now, it’s important to note that this DOES NOT secure anything beyond that first level.. here are a couple more examples:

  https://www.super-awesome.net --  OK
  https://qa-server.super-awesome.net -- OK
  https://some.client.super-awesome.net -- FAILS
  https://another-client.super-awesome.net -- OK
  https://test.ya-client.super-awesome.net -- FAILS
Extra Credit – viewing the contents of your CERT

It’s all well and good to generate the cert, but what if you want to verify it’s properly setup? What if you find a cert on your system and you want to know what it covers, when it expires, whom might own it, etc. Well, that’s possible too. Running a simple command we’ll examine the SSL Cert just created. The important info is in the ‘Issuer’ and ‘Subject’ blocks.

  openssl x509 -noout -text -in my.super-awesome.hostname.cert

Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number:
            c4:3d:66:b4:e3:cc:61:86
        Signature Algorithm: sha1WithRSAEncryption
        Issuer: C=US, ST=Kellyfornia, L=Sac-of-Tomatoes, O=Crazy Assembly House, OU=Committe on wasting tax payer money, CN=*.super-awesome.net/emailAddress=admin@super-awesome.net
        Validity
            Not Before: Jan  9 17:50:56 2012 GMT
            Not After : Jan  6 17:50:56 2022 GMT
        Subject: C=US, ST=Kellyfornia, L=Sac-of-Tomatoes, O=Crazy Assembly House, OU=Committe on wasting tax payer money, CN=*.super-awesome.net/emailAddress=admin@super-awesome.net
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
            RSA Public Key: (2048 bit)
                Modulus (2048 bit):
[...]  /*  removed the modulus to keep the post short */
               Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Subject Key Identifier: 
                9D:72:0C:A0:E6:EB:77:2C:77:EF:E8:9E:B7:BC:9F:53:81:1A:40:9D
            X509v3 Authority Key Identifier: 
                keyid:9D:72:0C:A0:E6:EB:77:2C:77:EF:E8:9E:B7:BC:9F:53:81:1A:40:9D
                DirName:/C=US/ST=Kellyfornia/L=Sac-of-Tomatoes/O=Crazy Assembly House/OU=Committe on wasting tax payer money/CN=*.super-awesome.net/emailAddress=admin@super-awesome.net
                serial:C4:3D:66:B4:E3:CC:61:86

            X509v3 Basic Constraints: 
                CA:TRUE
    Signature Algorithm: sha1WithRSAEncryption
[...]  /*  removed the signature to keep the post short */


Looking at the Subject breaks downs as follows:

  Subject: C=US, ST=Kellyfornia, L=Sac-of-Tomatoes, O=Crazy Assembly House, OU=Committe on wasting tax payer money, CN=*.super-awesome.net/emailAddress=admin@super-awesome.net

  C=US - Country code  'US'
  ST=Kellyfornia  -  State or Provence. 
  Sac-of-Tomatoes   -  City/Location
  O=Crazy Assembly House  -  Company or Organization name
  OU=Committe on wasting tax payer money Organizational Unit (department, etc.)
  CN=*.super-awesome.net  -  Canonical Name (hostname / domain) that
 the CERT services.  In this case it's a wildcard, signfied by the '*'

That's all there is to it. Now, secure those website communications!

Writing an Apple Help Book

Writing and distributing Apps for OSX compared to those written for the iOS environment is mostly an entirely new adventure. The underlying code is the same, but the concepts of UI design are radically different. Then there is the entire topic of Help Files, or in the case of OSX, the Apple Help Book.

Having several decades of experience as a software designer, developer and distributor, the concept is not new territory. Deploying it in OSX is, however a new skill to be learned. To help those that follow boil all this down I’m going to expose my personal notes on the subject. These notes were derived while using XCode 4.2, in January 2010 [ Detailed Online Information at developer.apple.com ]

Why Apple Help Book?

Flexibility — Writing and deploying an Apple Help Book with the application provides indexed search capability of the Help data, via the OSX Help menu while running the App. Once registered in the Application package itself, it integrates smoothly into the user experience.

What is special about Apple Help Books

They are HTML based. — This makes production of help files for the Application simple. HTML editors are widely available for those that do not have the technical chops to produce the file the good old fashioned way.

Rich Content — Help books can contain video content and even Apple Script to automate help navigation or even perform application manipulation directly from the Help construct. Niiiiiice.

What is a Help Book?

HTML Content — The book consists of a collection of HTML files that constitute the Help documentation for your application.

Indexing Help — Apple provides Help Book Indexing tool located in /Developer/Applications/Utilities, when the Developer package is installed. .

Help API — Contextual help is made available, from the Help Book via a provided Apple Help API. You do not need to utilize this capability for basic help function, but it’s available for advanced Help capabilities.

Exact Match Search for small words — A common problem with basic search functions, is that small or common letter groups may product far to general of a response. Example would be searching for the term ‘CD’. A Help Book with the properly configured Exact Match Searching would be able to return targeted help results for ‘CD’.

Can live In the Cloud — Concept of Apple Help supports the ability to access and deliver content from remote servers (aka the cloud), in three different ways; Internet-only, Internet-primary and Local-primary. It also has the ability to signal need to download and updated Help file for local (end-user) storage.

Links to Online Resources — It’s perfectly acceptable to code the Help Book and it’s title items to be links to locations on the web. An example of this might be a link from the Help system back to the producer’s main website for support or additional help content.

Authoring a Help Book

Full Document Online –[ Click Here ] for the full article on Apple’s Developer Website.

Xcode 4 – very simple way to open a website from App

This is going to be a VERY quit little missive. Basically, it’s about knowledge retention. The more I write about something, the better chance I have remembering some detail months or years hence. Today, I’m recording, for posterity (sounds pretty snooty, I know), the Objective-C command for opening a URL.

I won’t pretend to know all the details of this, and why it requires so many messages to be passed. In this case I’m admitting I was a cut-and-paste code monkey, standing on the shoulders of others. So, enough babbling, here is the meat of it. This ASSUMES you have a way to call this, such as a class method, or something. To clarity, this is writting into your implementation (.m) file.


- (IBAction)visitAuthorWebsite {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://apps.daviddemartini.com/icidr"]];
}

The above does NOT maintain context within your app. This tosses the user out into Safari to view the page. Had I added a URL View page to the application, it would have appeared there. Perhaps in version 2.1, but for now, for today, this works. I’ve tested it, verified it, and trust it.

Here it is again, broken out into chunks


- (IBAction)visitAuthorWebsite {
[
[
UIApplication sharedApplication
]
openURL:[
NSURL URLWithString:@"http://apps.daviddemartini.com/icidr"
]
];
}

I was thrilled when the example turned out to be so simple. I hope someone finds this useful.

XCode 4 – Dismissing a Keyboard after UITextField input

I originally ran into this issue back in November of 2010, while writing the original version of my iCIDR tool (hey network admins, you should buy this awesome tool now, before the price goes up!).

It’s trivial to enable a keyboard and to change the button, BUT to make it go away, and then actually wire that event into your code to do something use is not as simple as I had originally hoped!

Strategy entails using the keyboards ‘Return’ key to signal that one is done. Seems useful, but only if you have a single line text input. In my case, that’s what I’m looking at, single line input, so that’s the solution I’m going to try.

First order of business is to highlight your text area (I’m only going to be addressing the text input object), and shift to the properties tab (icon looks like this: ). Change the dropdown to the ‘Return Button’ text you wish to use. I like to use ‘DONE’, so, that’s what this image shows. Oh.. and yeah, you are also getting a little sneak peak at the newest generation of iCIDR.

The tricky part is understanding that you need to make sure your ViewController’s header file is modified to implement UITextFieldDelegate.

This is how that might look:

@interface iPhoneCalculatorViewController : UIViewController {
UITextField* seeTextField;
}
@end

Now, when the view loads, the Text box in the view needs to be addressed and wired up to the Keyboard action. Even though I defined a nice fancy label name for my object, so far I’ve only found this method to address the object ID by it’s ID. I think this is pretty funky but, cest la vie. Here is where I set the tag, also in the same view organizer dialogs:

Following that I enabled viewDidLoad (boilerplate code normally commented out), created a local variable pointer to the View’s input text box, and then set a delegator to that pointer in the main ViewContoller.

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
UITextField *iPhoneInputText = (UITextField *) [self.view viewWithTag:1001]; // try to locate the object with the tag
iPhoneInputText.delegate = self; // assign a delegation.
[super viewDidLoad];
}

Moving along, I had to implement the The textFieldShouldReturn method in my ViewController class. This had to be defined to execute on the abandonment of the first responder:


// Should trap all Keyboard Return Events
- (BOOL) textFieldShouldReturn:(UITextField*)textField {
[textField resignFirstResponder];
//[self calculateOperation]; // ENTRY POINT
return NO; // default return value is YES, this is changed to NO to.... (sorry, now I've forgotten!)
}

Here is the keyboard that pops up, with the highlighted ‘Done’ button.

iCIDR 2.0 - keyboard in action (still photo)

The method (BOOL) textFieldShouldReturn is now registered to get the text input object the keyboard was typing into.

Now it’s your job (and mine…) do make it do something useful!!


Support the author, buy the App!

iCIDR - David DeMartini

iPhone App2, App3 & App4 compiled – this time in pure Objective-C

App 2


Well, here it is in amazing glory. The 2nd version of that good old programming stallwort, the “Hello World!” example application.

Now this one took me a bit longer to code and implement, HOWEVER, it’s pure Objective-C, not the hybrid app type that I used in Application #1. App1 was interesting, and fast to build, but it relies upon some pretty big external libraries. Not a big deal for a low-intensity application like I’m building right now, but the QuickConnect based hybrid app I first built comes with that (I think is) is a pretty high price to pay (with a couple of hefty line items)

  1. Every time you start the application, I get an unwanted QuickConnect Family Application splash screen. NO THANKS! I’m pretty sure I could hack around it, buy why bother, for now?
  2. It won’t run from XCode! I can get it to start, but it won’t actually Do anything.
  3. The hybrid HTML based application’s style sheets are partially ignored, things like the background and text colors are not honored, BUT the font family is. Very strange
  4. It’s a MAJOR pain in the ass to debug when you create it in DashCode… ‘deploy it’. Have to monkey around with several files to fill the XCode (Objective C based) language into using files it did not expect to need… it’s all very hacky and more kludgy than I like.

Honestly, with XCode view based building, I don’t think I need to mess around with the hybrid application model at all, at least for now. So.. the application that I built purly in HTML, CSS and JavaScript will be shelved for now. Instead I’m going to re-open my Objective C tutorials and work my way into the project I was working on originally.

It might be a pain in the butt to learn Objective-C, but in the end, I benefit. Question is, do I have the time and will to see it all the way through. I believe so. But until such time as I have the first application built and deployed on my phone.. it’s sort of.. moot. No?


App 3

App3

This one is not a View Based Application like number one, but this is what is called a Navigation Based Application.

Now, ever the hacker, I went beyond the code changes to RootViewController.m suggested in the book, and also had to fix some GLARING errors in the text (did they not have an editor look at this??). Anhow, this is the code that I wrote for the cell builder. The enhancements allow line wrap, and I changed the default font size from 17 to 13.


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 0;
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:13.0];
}

cell.textLabel.text = @"This is my second Objective-C application.\nDespite the tutorial having MASSIVE bugs, I got it to run!"; // Configure the cell.

return cell;

}

I’m trying to decide if a View Based (winning so far) or a Navigation Based application will be the way I go for the Real Application. The Navigation Based app is a lot easier to get started with, and does not require that rather odd method of linking elements with the fishing line drag and connect method in the View Application.

Still a lot of code to write before I have enough experience to make a solid choice.


App 4

App4 is a derivative work of App3, but this time by simply enabling this little block of code, I get an Edit button and the ‘Delete’ context, if I need it, for the items. Pretty slick. Apple really went out and did a nice job on this SDK…

- (void)viewDidLoad {
[super viewDidLoad];

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

Application 4 running in the iPhone simulator