<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>Hi I’m Rob Blake. 

A software entrepreneur by daytime, I’m one half of the team behind www.thelawwizard.com

I’m a specialist in JEE technologies and Cloud computing. If you want to talk Cloud, I’m your man.

Outside of work, I’m an aspiring economist who likes to run and read a lot. 

I live in York, England.</description><title>I'm Rob Blake</title><generator>Tumblr (3.0; @robblake)</generator><link>http://robblake.net/</link><item><title>Using a PEM private key and SSL certificate with Tomcat</title><description>&lt;p&gt;This is the first in a series of posts of useful titbits that I have completed in my work over the last few months getting &lt;a href="http://www.thelawwizard.com" title="The Law Wizard" target="_self"&gt;The Law Wizard&lt;/a&gt; live. These are a reminder for me as to how I did things, but also they may be useful for others as documentation elsewhere is pretty lacking&lt;/p&gt;
&lt;p&gt;In this post I will walk you through importing a PEM private key and CA issued SSL certificate into a Java key store so that it can be used with Tomcat. These instructions are for UNIX users, but I&amp;#8217;m sure something similar will work on Windows. To get started, you will need the following:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;Your PEM private key that you used to generate your CSR&lt;/li&gt;
&lt;li&gt;Your PEM SSL certificate issued by your CA&lt;/li&gt;
&lt;li&gt;Any intermediate CA certificates if required&lt;/li&gt;
&lt;li&gt;Tomcat&lt;/li&gt;
&lt;li&gt;Java 6 with keytool on your path&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.openssl.org/" title="OpenSSL"&gt;openssl&lt;/a&gt; installed &lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;For the record, my CA was GoDaddy and I required 2 intermediate certificates. However I&amp;#8217;m reasonably confident these instructions will work with certificates issued by other CAs.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1: Exporting your private key and certificate to PKCS12&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Your first task is to export your PEM private key and PEM CA issued certificate to a format that can be handled by the Java keystore. In this case I am going to convert them to &lt;a href="http://en.wikipedia.org/wiki/PKCS12"&gt;PKCS12&lt;/a&gt; format. This is recommended by the Tomcat 7 docs. To do this you will need the following:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;openssl pkcs12 -export -in &amp;lt;your_CA_signed_PEM_cert&amp;gt; -inkey &amp;lt;your_PEM_private.key&amp;gt; -out &amp;lt;your_certificate_name&amp;gt;.p12 -name tomcat -chain -CAFile &amp;lt;your_root_CA_certificate&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You will be asked for a password at this point. Use something that you can remember as you&amp;#8217;re going to need it in a minute.&lt;/p&gt;
&lt;p&gt;In the above there are few important points:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;The &amp;#8220;chain&amp;#8221; option ensures that the full certificate chain for your certificate is included. This is a must if there are intermediary certificates to your root CA&lt;/li&gt;
&lt;li&gt;The &amp;#8220;name&amp;#8221; option &lt;em&gt;must&lt;/em&gt; be tomcat. This is the alias that tomcat will use to search in the keystore to identify the certificate is should present to clients&lt;/li&gt;
&lt;li&gt;The &amp;#8220;CAFile&amp;#8221; option allows the chain option to work correctly. If you have intermediary certificates before your root CA, then this should be a bundle of all those certificates. Your CA should provide this. GoDaddy certainly did. If there are not intermediary certificates, then this is the root certificate for your CA.&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;2: Importing your new PKCS12 certificate and key bundle into a Java keystore&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Java keystores are just a flat file in a particular format. This makes it super easy to create new ones. What we need to do now is take the PKCS12 key and certificate bundle we just exported and create a brand new keystore from it. This is where we need the Java keytool command. &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;keytool -importkeystore -deststorepass &amp;lt;a_password_for_your_java_keystore&amp;gt; -destkeypass &amp;lt;a_password_for_the_key_in_the_keystore&amp;gt;-destkeystore tomcat.keystore -srckeystore &amp;lt;exported_private_key_and_cert.p12&amp;gt; -srcstoretype PKCS12 -srcstorepass &amp;lt;the_password_I_told_you_to_remember&amp;gt; -alias tomcat&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;Once this completes, you should see a file called &amp;#8220;tomcat.keystore&amp;#8221; in the same directory from where you issued the command. This is your brand new Java keystore with the PKCS12 version of your PEM private key and certificate in it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3: Importing intermediate keys into the keystore if required&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If like me your CA has intermediate certificates, now is the time to import them into the new keystore we just created. It is highly likely that your CA will provide instructions on how to do this and how the certificates should be named. In my case I need to import a few from GoDaddy. Just to give you an example, I needed the following:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;keytool -import -alias cross -keystore tomcat.keystore -trustcacerts -file gd_cross_intermediate.crt&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;keytool -import -alias intermed -keystore tomcat.keystore -trustcacerts -file gd_intermediate.crt&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You *may* also need to import the root CA certificate into the keystore. You shouldn&amp;#8217;t have to as most systems these days come with a pre-configured store of well known root CA certificates. You can give it a try and if the system already knows about it, keytool will ask you if you really want to import it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;4: Move the keystore to a known location&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Next you just need to move the keystore to a known location and ensure that the process under which Tomcat will be running has access to it. I created a directory called &lt;em&gt;/usr/local/keystore &lt;/em&gt;and stored my keystore in there.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;5: Configure Tomcat to use your new keystore&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Next we need to configure Tomcat to use your new keystore. Go to the &lt;em&gt;~conf&lt;/em&gt; directory of your Tomcat installation. Open server.xml for editing. Find the SSL connector and ensure that it is enabled. In addition make sure the configuration looks something like the following:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;Connector port="8443" maxThreads="200" scheme="https" secure="true" SSLEnabled="true" keystoreFile="path_to_your_keystore_file" keystorePass="the_password_you_created_for_your_keystore" clientAuth="false" sslProtocol="TLS"/&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will enable SSL on port 8443. If you need 443 instead, change the port number accordingly.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;6. Test&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Boot Tomcat and then go to &lt;em&gt;&amp;lt;your_hostname&amp;gt;:8443&lt;/em&gt;. If you have done everything correctly the padlock symbol should now show in the browser. You can inspect your SSL certificate using any of the browser built-in tools.&lt;/p&gt;</description><link>http://robblake.net/post/18945733710</link><guid>http://robblake.net/post/18945733710</guid><pubDate>Thu, 08 Mar 2012 12:40:52 +0000</pubDate></item><item><title>JPA: Ensuring versioning of entities when using Query.executeUpdate </title><description>&lt;p&gt;The persistence layer for our code at The Law Wizard makes use of optimistic locking to determine if an entity has changed during the period where a user has been working on it. This helps to ensure that the view the user sees is always consistent with what is in the database. &lt;/p&gt;
&lt;p&gt;One problem I came across is how to update multiple versioned entities in a single query whilst ensuring the benefits of optimistic locking are maintained. It turns out the answer is extremely simple, yet it took me while to find it. I thought I would share in case others have the same problem.&lt;/p&gt;
&lt;p&gt;First off I&amp;#8217;m assuming you&amp;#8217;re using Hibernate as your persistence provider.&lt;/p&gt;
&lt;p&gt;Imagine you have an entity such as this:&lt;/p&gt;
&lt;pre&gt;&lt;code class="javascript"&gt;
public class MyEntity 
{
       @ManyToOne(fetch=FetchType.Lazy, optional=true)
       private OtherEntity otherEntity;

       @SuppressWarnings("unused")
       @Version
       private long version;

       public OtherEntity getOtherEntity()
       {
               return otherEntity;
       }

       public void setOtherEntity(OtherEntity otherEntity)
       {
               this.otherEntity = otherEntity;
       }
}
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;The relationship between MyEntity and OtherEntity is uni-directional, i.e. OtherEntity doesn&amp;#8217;t know about the MyEntitys that have a reference to it.&lt;/p&gt;
&lt;p&gt;Elsewhere in your application it is possible to delete OtherEntity. If this happens, you would like all MyEntitys with a reference to the OtherEntity being deleted, to have their reference set to null. However you will note that MyEntity is versioned for optimistic locking purposes. If the reference to OtherEntity is set to null, you want the version of MyEntity to be incremented.&lt;/p&gt;
&lt;p&gt;A horrible way to do this is to load all MyEntity into the PersistenceContext where the OtherEntity is the one that is being deleted, set the reference to null and then persist them back into the database. For example:&lt;/p&gt;
&lt;pre&gt;&lt;code class="javascript"&gt;

for(MyEntity m : em.createQuery("select m from MyEntity m where m.otherEntity=:otherEntity").setParameter("otherEntity",otherEntity).getResultList())
{
     m.setOtherEntity(null);
}
&lt;/code&gt;
&lt;/pre&gt;


&lt;p&gt;This ensures that versioning works, but depending on the number of MyEntity referencing OtherEntity, you&amp;#8217;ve potentially got a lot of database traffic.&lt;/p&gt;
&lt;p&gt;Another way to do this would be to use a query to update all OtherEntitys such as the following:&lt;/p&gt;
&lt;pre&gt;em.createQuery("update MyEntity m set m.otherEntity=null where m.otherEntity=:otherEntity).setParameter("otherEntity", otherEntity).executeUpdate();
&lt;/pre&gt;
&lt;p&gt;That works, but with one major problem. The version of all MyEntity affected by the query is not updated. I was considering writing my own query to update the versions of all MyEntity when I found this little nugget buried deep in the Hibernate documentation:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span&gt;In keeping with the EJB3 specification, HQL &lt;code class="literal"&gt;UPDATE&lt;/code&gt; statements, by default, do not effect the &lt;a title="5.1.9. Version (optional)" href="http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-declaration-version"&gt;version&lt;/a&gt; or the &lt;a title="5.1.10. Timestamp (optional)" href="http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-declaration-timestamp"&gt;timestamp&lt;/a&gt; property values for the affected entities. However, you can force Hibernate to reset the &lt;code class="literal"&gt;version&lt;/code&gt; or &lt;code class="literal"&gt;timestamp&lt;/code&gt; property values through the use of a &lt;code class="literal"&gt;versioned update&lt;/code&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;span&gt;So what does that mean? Well simply re-write the above query to the following:&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;em.createQuery("update versioned MyEntity m set m.otherEntity=null where m.otherEntity=:otherEntity).setParameter("otherEntity", otherEntity).executeUpdate();
&lt;/pre&gt;
&lt;p&gt;The versions of any affected entities are incremented ensuring that your optimistic locking strategy will work without a hitch.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;</description><link>http://robblake.net/post/8183156536</link><guid>http://robblake.net/post/8183156536</guid><pubDate>Thu, 28 Jul 2011 21:16:15 +0100</pubDate><category>JPA Hibernate Tech</category></item><item><title>An elegy for the technical book</title><description>&lt;p&gt;I&amp;#8217;ve been doing a lot of technical investigation over the last few months as part of our plans for &lt;a title="The Law Wizard" target="_self" href="http://www.thelawwizard.com"&gt;The Law Wizard&lt;/a&gt;. Part of that means that I&amp;#8217;ve been doing a fair bit of technical reading whilst playing around with lots of new technology.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Brain..not..working&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;For some reason I really struggle to start with a technology when reading a computer screen. My brain seems to shut down and refuse to do anything, so I often resort to printing stuff off and then reading it.&lt;/p&gt;
&lt;p&gt;Printing stuff off works OK, but it often means you have to chase around, finding the articles or pages that interest you. Sometimes you just want everything in once place. Sometimes there is nothing better than getting your hands on a printed manual that really starts to explain the technology to you. My tiny brain can then relax and the information that I need starts to seep in. I&amp;#8217;m sure I&amp;#8217;m not alone here.&lt;/p&gt;
&lt;p&gt;However I&amp;#8217;m finding an increasing problem with technical books these days is that as soon as they are printed and in your hand, they&amp;#8217;re out of date. The technology has moved on, and that nifty new feature you wanted to use doesn&amp;#8217;t even appear in the book. &lt;a target="_self" href="http://www.snailinaturtleneck.com/blog/2011/01/31/a-short-ebook-on-scaling-mongodb/"&gt;I&amp;#8217;m not the only one&lt;/a&gt; who has noticed that problem either&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Goodbye my old friend?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;With Messrs iPad and Kindle on the scene, it is more and more likely that technical books will be delivered in &amp;#8216;e-book&amp;#8217; format. This will also mean that as and when new features are added, the book will be updated and pushed to our &amp;#8216;e-reader&amp;#8217; devices automatically. It will be great, knowing that your manual will never be out-of-date. &lt;/p&gt;
&lt;p&gt;But on the other hand I can feel my brain already starting to revolt. &amp;#8220;You can&amp;#8217;t learn when reading from a screen&amp;#8221;, it taunts. It has me rushing to Amazon to check the availability date on the second edition of the technical book instead.&lt;/p&gt;
&lt;p&gt;Technology brings change to all areas, and technical books are not immune. I&amp;#8217;m looking forward to more up-to-date documentation, and I&amp;#8217;ll convince my brain that reading from a screen isn&amp;#8217;t that hard and it&amp;#8217;s just being lazy.&lt;/p&gt;
&lt;p&gt;But deep down I also yearn for a updated print copy of the technical book in my hands. There is something rewarding about thumbing through the pages and learning the intricacies of the technology. I hope I&amp;#8217;m not alone in feeling that way.  &lt;/p&gt;</description><link>http://robblake.net/post/3250049506</link><guid>http://robblake.net/post/3250049506</guid><pubDate>Sat, 12 Feb 2011 11:29:15 +0000</pubDate></item></channel></rss>

