Site Navigation

Favorite Links Feed

May 1, 2015

Site Updates

Info Icon

A couple of quick updates on the site. First, to make the site more responsive I have made it into a single column site. At the top of the page is a link blog featuring my favorite tech stories. The section is loaded using JavaScript so it may take a moment to load. But this is where most of my activity will be for the near future. Also I have updated to links so that the How-to part of my site is using HTTPS. Links to the main blog are still HTTP.

Main blog posts on Blogger, like this one, now appear under the link blog.

I am making progress on my blogging software. I have the page builder working, now I just need to get the page merger going. Will keep you updated when there is more progress.

Mike W.

Secure Coding with Java Native Interface (JNI) Tutorial

Duke Waving

My coworker Anjana Shenoy has finished a new secure coding tutorial for the Java Native Interface. The content is based on this hand on lab from JavaOne 2014: Java Native Interface: Harden Your Native Code [HOL6325].

Lots of cool stuff to work on. Here are the links to the content.

Mar 25, 2015

Simple Command Line File Encryption with 7zip

This is a brief write up on how perform simple file encryption of a directory using the 7zip program. After TrueCrypt was abandoned by its developers, I have looked around a bit for a really simple, easy to use tool for lightweight ecryption. Simple and easy are my goals, not the most secure. You can use something like Gnu Privacy Guard if you want a really full featured suite of security tools.

7zip is a free, open source file compression tool for Windows, OS X, and Linux. Most folks use 7zip to zip and unzip .zip files. But 7zip has its own 7z file format which provides better compression and better encryption than standard .zip files. The 7zip program uses strong AES-256 encryption based on a password you provide when you compress files. Thusly, the goal of quick and easy is met. The password will keep nosy relatives out the file, but I am sure, given enough time, the NSA could get in if they really wanted to. :)

7zip Installation

You can get 7zip from the 7zip web site. That works best for Windows, but for other operating systems you can use a package manager.

Windows

For windows, just go to the main site to download and install the software. The files are:

  • 7zip.exe (Windows 32-bit)
  • 7zip.msi (Windows 64-bit)

OS X

For OS X, the easiest way to install is to use HomeBrew. If you do not have HomeBrew, get it. You can thank me later. It is a fantastic tool for OS X. To install, just use the following from a terminal:

  • brew install p7zip

Ubuntu Linux

For Debian Linux, just use apt. For example:

  • apt-get install p7zip-full

Encrypting your Stuff

The following steps outline how to encrypt your stuff from the command line. The command line options should be the same on any platform, but there could be minor differences. The note was written using OS X.

Compress a Directory

To compress a directory named temp, use the following command:

7z a temp.7z temp/ -pSECRET -mhe

or alternatively

7z a temp.7z temp/ -p -mhe

The second option prompts you for the password to type in. The longer the password, the harder it would be for someone to decrypt the file. But of course, that will also make it hard to remember.

Here is a quick breakdown of the command line options:

  • a – Append files to the archive. Will just update the archive if it exists, so best to make sure the file does not exist.
  • temp.7z – The name of the archive file.
  • temp/ – The directory to be zipped.
  • -p – Prompt for the password.
  • -mhe – Encrypt the archive headers.

On OS X or Linux, the password is case sensitive by default. On Windows, the password is case insensitive by default.

Decompress the Archive

To decompress the archive just use:

7z x temp.7z

You will be prompted to enter your password and the file is uncomressed. For more information on 7zip see this 7zip tutorial which was a big help in writing this post.

That is it. An easy way to encrypt a directory.

Mar 11, 2015

Glassfish 4 Admin Passwords with NetBeans

Question: Where can I find the Admin Password for GlassFish 4?

Most of the time when working with NetBeans and Glassfish for development, you don’t need to know what the password is for the GlassFish server. Starting and stopping the server as well as open in the admin console is automatic. However, if like me, sometimes you work with multiple versions of NetBeans and you may be prompted for a password in the GlassFish admin console. So the username is "admin", but where is the darn password stored?

Usually in one of two the places.

Location 1

The first place to look is in the GlassFish configuration directory.

glassfish-4.0/glassfish/domains/domain1/config/local-password

Location 2

The second place to look is in NetBeans

  1. Click on the Services Tab
  2. Right click on the GlassFish Server
  3. Select Properties
  4. Too see the password, check the Show Password in this Form option

Caveats

Do not change these passwords! GlassFish has to be running to change admin passwords. If you “lose” the passwords for some reason, you will need to re-install.

If you want to change the password, look up the asadmin documentation for more details.

GlassFish 4 Reports a JNDI Lookup Exception for a NetBeans Project

Duke Waving

Here is a quick word around to a problem I ran into at work.

Problem: Calling a Java Servlet with JNDI code results in this error

Other Exception: Lookup failed for 'jdbc/yournamehere' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}

The initialization code is similar to the following:

    try {
        Context ctx = new InitialContext();
        DataSource ds = (DataSource) ctx.lookup("jdbc/yournamehere");
        Connection con = ds.getConnection();

You have setup a connection pool and JDBC resource for your NetBeans project. All the configuration data appears to be correct.

Solution

The problem occurs when GlassFish fails to create a JDBC Connection Pool and JDBC Resource on the server when your application deploys. To wordaround the problem, manually create the pool and resource on the Glassfish server using the admin console.

Creating the JDBC Resource is pretty easy, so no additional comments on that.

When you create the JDBC Connection Pool, only include the required properties for your database in the Additional Properties tab. In this case, JavaDB (Derby) was used so the only required properties are:

  • User: YourUsername
  • Password: YourPassword
  • DatabaseName: YourDBName
  • ServerName: localhost
  • PortNumber: 1527

Some of the automatically added properties may cause your connection pool to fail to connect. Use the Ping feature of GlassFish to ensure the server is connecting to the database.

Feb 16, 2015

Website/Blog Update in the Works

Just a quick heads up. Google has mandated that all web sites must use SSL (HTTPS) or risk being down ranked sometime in the near future. I can find no evidence that Google has any interest in updating blogger.com to support their own mandate. So I am in the process of migrating this blog to my blueskyworkshop.com site. For me, this involves creating some very simple blogging software to run both my blog and my site. Consequently, I have not been posting as often as I would like.

I have looked at a number of static site blogging engines like Jekyll, but they all seem to be a bit complicated. So my goal is to create something really simple that supports Markdown with YAML front matter. My hope is to create Ruby and Java versions. So watch this space for updates.

In the meantime, I haved added a section for my favorite links a below the main posts. This is a feed of bookmarks of interest I am posting on https://pinboard.in. So the posts are sorta like a twitter feed except they are organized and indexed in a useful way by Pinboard.