How To Create A Java Keystore Containing A Self Signed Certifate Generated With OpenSSL

A small shell script to generate a private key, a self signed certificate using OpenSSL and finally importing them into a Java keystore. A self signed certificate is usually used during development and test phases, so to make your life easier, the key created is not protected by password. The .p12 file being created by openssl is password protected because lot of users reported that otherwise keytool would refuse to import it. The self signed certificate will expire after 9999 days, I hope it is enough time to complete your development.

# generating private key without password
openssl genrsa -out server.private.key 2048

# generating a certificate signing request
openssl req -new -key server.private.key -out server.csr -subj "/C=IT/ST=Milan/L=Milan/O=MyOffice/OU=IT Department/CN=mywebsite"

# self signing the certificate
openssl x509 -req -days 9999 -in server.csr -signkey server.private.key -out server.crt

# including private key and certificate to a pkcs12, needed to import them into a keystore
openssl pkcs12 -export -in server.crt -inkey server.private.key -out server.p12 -name mywebsite -CAfile ca.crt -caname root -password pass:pazzword

# importing it into a newly created Java keystore
keytool -importkeystore \
        -deststorepass pazzword -destkeypass pazzword -destkeystore keystore \
        -srckeystore server.p12 -srcstoretype PKCS12 -srcstorepass pazzword \
        -alias mywebsite


Obtain the root logger programmatically in log4net

If you use log4net, you could have the need to configure the loggers programamtically. The problem arise when you want access to the root logger, since the documentation does not explain well how to obtain it.
So, here’s a snippet that show how to do it. Don’t forget to imort the log4net namespaces.

  1. using log4net;
  2. using log4net.Core;
  3. using log4net.Appender;
  4. using log4net.Layout;
  5. using log4net.Repository.Hierarchy;
  6. using log4net.Config;
  1. Hierarchy h = (Hierarchy)log4net.LogManager.GetRepository();
  2. Logger rootLogger = h.Root;

Good environment variable values during iPhone development

Directly from GHUnit, a small note about which environment variables to set while developing for the iPhone.

Environment Variable:                 Default:  Set to:
NSDebugEnabled                           NO       YES
NSZombieEnabled                          NO       YES
NSDeallocateZombies                      NO       NO (or YES)
NSHangOnUncaughtException                NO       YES
NSAutoreleaseFreedObjectCheckEnabled     NO       YES

Actually, I keep forgetting them, so I hope this will be useful to me.

Here an example that shows how to set those environment variables.

Setting iPhone development variables in XCode

Rails ans SQLite3 on Ubuntu

To configure a Rails application in order to use SQLite3 please follow the following steps:

sudo apt-get install  sqlite3 swig libsqlite3-ruby libsqlite3-dev
 sudo gem install sqlite3-ruby

Then create a Rails application as usual and update the environment.rb file in the following way do |config|
config.gem 'sqlite3-ruby', :lib => "sqlite3"

Get rid of folder that should not be versioned

If you work with subversion, for sure you had the problem to tell to subversion to ignore a folder inside your working copy. This happens for example if your IDE builds the sources in a folder inside your working copy. From the very first commit you’ll start noticing that subversion wants to add that “build” folder to your repository. But, obviously, this is not a good practice.

So you can tell subversion to ignore a folder. Just move in the folder that contains the folder you want to be ignored by subversion and type the following command.

svn propset svn:ignore <dir_you_want_to_be_ignored> .

The “dot” at the end is important! It means you’re specifying which folders of the current folder you want to be ignored.

Please note that <dir_you_want_to_be_ignored> should be written without trailing slashes. So for example if you want the build directory not to be managed by subversion, type…

svn propset svn:ignore build .

And not…

svn propset svn:ignore build/ .

This is a quick tip. I always forget how to do it, so I wrote that little note.