The Hecklers
"Two roads diverged in a wood, and I took the one less traveled by and that has made all the difference."

I don’t know whether it’s sentimentality or practicality – or maybe both – but I love Radio Shack. While there are stores and/or online vendors who offer a wider assortment of embedded devices and electronic components, their Radio Shack stores are everywhere, and the selection is good. And although the prices are higher than ordering directly from China, I can have a part or board in hand in 15 minutes if Radio Shack carries it. You’re buying the item + unbeatable convenience, and all things considered, it’s a pretty great deal.

 

Years ago, I bought a little multimeter kit from Radio Shack. I needed a multimeter, and I kind of wanted to “build it myself”. The ArcherKits are easy to assemble, with just enough soldering and small work to give you immense satisfaction every time you use it.  :-)

 

Archer Kit Multimeter

 

I’ve since upgraded multimeters to a nice digital model, but you know what I keep in my embedded device toolbox? My trusty old analog ArcherKit multimeter. It’s not fancy, but it’s nearly indestructible and it just works.

 

Just today, I couldn’t remember how to take a measurement that I rarely have call to make, and when I went to look for the operator’s manual, I couldn’t find it. Searching online didn’t help, either. I finally did locate it…but it occurred to me that others may find themselves in the same bind. And no one should have a great tool without having the instructions handy. So…below is a snapshot of the basic foldout of operating instructions. Simple, straightforward, and essential!

Archer Kit MultiMeter 28-4012A

If you have an ArcherKit 28-4012A multimeter, I hope you’re still enjoying it as much as I am. When absolute digital precision is required, this little guy gets a well-deserved rest…but guess what sees the most action?  ;-)

Keep MAKING,
Mark

 

Share

Tags: , , , , , , ,

If you’ve worked (or played) much with Arduinos, you’ve probably run into “dead pins” – or wondered if you had. How can you tell which pins, if any, are unusable on an otherwise perfectly good board?

 

There are probably more precise ways of determining what is wrong, and perhaps even ways to repair some defects…but for those of us embedded folk who work far more with software than hardware, this is a quick way to confirm which pins don’t work properly with sufficient precision so you can label the board and move on. To quote Steve Jobs, “Real artists ship.”  :-)

To test digital pins, you need to test both pinModes: INPUT and OUTPUT. (There is also INPUT_PULLUP, but that is only relevant if using the internal resistors vs. external ones.) I created two sketches, one to test pins with a call to digitalWrite() to light up connected LEDs, and one to read a switch using digitalRead(). Those are the software components necessary, and they’re available at my ArduinoPinTests GitHub repository.

The hardware portion of the test can be easily assembled as well. Here are the items I used; feel free to substitute similar components as desired:

  • Solderless breadboards (2, one for each: input & output)
  • LEDs (6)
  • Resistors, 220 Ohm (6) (for output test board)
  • Resistors, 10k Ohm (2) (for input test board)
  • microtivity IM211 push-and-lock switch (for input test board)
  • Necessary wires to put it all together

It has been said that a picture is worth a thousand words. Here are two thousand for you!

Digital Pins (In) Test Board

ArduinoInPinsPhysicalConfigAnnotated

Digital Pins (Out) Test Board

ArduinoOutPinsPhysicalConfigAnnotated

The Bottom Line

If you have pins you think may be dead on your Arduino or clone board, grab some spare parts, visit my GitHub repo, and within minutes you can find out if/which pins are out of commission and get back to configuring devices and pounding out code. Now…back to business!

All the best,

Mark

Share

Tags: , , , , , , , , , ,

I’ve been working recently with a client to do some rather useful things with notifications, and one of them involved sending a secure email from within a Java program. We encountered some interesting (translation: weird!) challenges, and in overcoming them, I worked out a reasonably straightforward path through the minefield. If you’ve been thinking about secure-email-enabling your Java app but aren’t sure where to start, hopefully this will serve as a fairly quick and mostly painless primer.  :-)

The Problem

Let me first say that if you only want to send a plain-text email from Java, there are ways to do that without much fuss and without any external players. If you want to sign or encrypt your emails, though, you’ll need a couple of extra components:

  1. A digital certificate (private/public key pair issued by a recognized Certificate Authority, or “CA”)
  2. A means of using the certificate to sign and/or encrypt the email
The goal is to digitally sign an email to assure recipients that the sender of the mail is indeed me (or you, if you’re following along at work/home). Let’s get started!

Getting Your Tools in Order

Getting a Certificate

First, we have to have a digital certificate. If you already have one, you can skip this step…but if not, StartSSL offers free user/email certificates for personal use. Just point your browser to the StartSSL site and click the large button labeled “Sign-up”. You’ll need to provide them some information, enter the verification code they email to the address you provide, and they do the rest…including installing your new cert and the certificate chain into your web browser.

Freeing the Certificate from your Browser

Perhaps the easiest way to use a certificate is to store it (keys, certificate chain) in a Java Keystore (jks). Extracting your shiny new certificate from your browser is a relatively easy (albeit drawn-out) process. From your browser, export your certificate, including private key. This will produce a .pfx file, which is a PKCS12 keystore. From Chrome, you simply:
  1. Click on the Wrench (or Lines) icon in the upper-right corner
  2. Select “Settings” from the menu
  3. “Show advanced settings…” at the bottom of the page
  4. Scroll down to the section labeled “HTTPS/SSL”
  5. Click the “Manage certificates…” button to display your certificates.
Then, from the certificates window:
  1. Select the target certificate and click the “Export…” button
  2. Click “Next” from the Export Wizard window
  3. Choose “Yes, export the private key” and click “Next”
  4. Under the “Personal Information Exchange – PKCS #12 (.PFX)” entry, select the options to “Include all certificates in the certification path if possible” and “Export all extended properties” (NOTE: Do NOT choose to “Delete the private key if the export is successful”. No no no!) and click “Next”
  5. Enter a password (twice) and click “Next”
  6. Provide a path/filename for the export and click “Next”, and finally…
  7. Confirm the export options and click “Finish”.
Now that we’ve liberated your cert from the browser, let’s make it usable by our (non-browser) Java program.

Creating a Java Keystore

The fastest, easiest way I’ve found to convert a .pfx file to a .jks (Java Keystore) file is with the Oracle 11g database client. The database client can be downloaded by following this link, selecting the “See All” link to the right of your listed operating system, and choosing the 11g client from the OS-specific download page. Once it’s downloaded and installed, you’re ready to proceed.
Like the .pfx file, the Oracle wallet is a PKCS12 keystore, and the orapki utility (and other tools) included with the database client can be used to manipulate it…as long as it thinks it’s dealing with an Oracle wallet. To make that happen, simply rename the .pfx file to ewallet.p12. Since we aren’t dealing with the Oracle Wallet Manager, we don’t have to worry about meeting OWM’s password criteria or other niceties. Yes, that really is all there is to it!
Now, to make a Java Keystore. To do that, you’ll need to open a command prompt and do the following tasks:
  1. Create an ORACLE_HOME environment variable that points to the install location of the Oracle client
  2. Run the following command, pointing to the orapki utility under %ORACLE_HOME%\bin (in Windows) or $ORACLE_HOME/bin (Mac/Linux/UNIX):
orapki wallet pkcs12_to_jks -wallet <wallet_directory> -pwd <wallet_password> -jksKeyStoreLoc <java_key_store_path_and_filename> -jksKeyStorepwd <jks_password>
 
You should now have a brand new Java KeyStore! You can verify its contents with the OpenSSL keytool utility:
keytool -list -keystore <java_key_store>
 

Now that we have our credentials in order, on to the Java side of things!

Building the Solution

There are several Java libraries available that aid in signing and/or encrypting email. Of the non-commercial options I found, all use the Bouncy Castle Crypto API and libraries as their underpinnings. Bouncy Castle (BC) may have a funny name, but it’s all business with regard to encryption.
 
At a very high level, you need to do the following things to create/send a signed email:
  1. Provide the email “essentials”: SMTP server host & port, email addresses (sender & receiver), a subject, content, and the sending user’s password
  2. Add BC as a new crypto provider
  3. Retrieve the cert from your Java Keystore
  4. Create and sign the email using the BC API/libraries
  5. Send the email

There is much more you can do of course, but these are the “must-haves”.

In preparation for developing our secure email module, I created a proof of concept (BCCrypTool) by marrying a Java email program I’d written previously and some BC sample code…code reuse at its lowest level, but still good for the environment. :-) What you see here in my GitHub repo is a bit of streamlined Java code that should be pretty easy to repurpose. Please feel free to take a copy and do just that, and if you make significant changes/improvements and are able and inclined to share them, please feel free to do that as well. Sharing is caring.  :-)
 
A quick note on libraries. You’ll need the following to make this work:
And from Bouncy Castle, the following:
  • The BC provider library (bcprov-jdk15on-147.jar)
  • The BC S/MIME library (bcmail-jdk15on-147.jar)
  • The BC security library (bcpkix-jdk15on-147.jar)
There are other BC libraries available here if you’d like to take things even further.
 
All the best to you in your Java secure email adventures!

Mark

Cross-posted from The Java Jungle.

Share

Tags: , , , , , , , , , , , , , , ,

Cross-posted from The Java Jungle by Mark

I recently had the opportunity to spin up a small web application using JSF and MySQL. Having developed JSF apps with Oracle Database back-ends before and possessing some small familiarity with MySQL (sans JSF), I thought this would be a cakewalk. Things did go pretty smoothly…but there was one little “gotcha” that took more time than the few seconds it really warranted.

The Problem

Every DBMS has its own way of automatically generating primary keys, and each has its pros and cons. For the Oracle Database, you use a sequence and point your Java classes to it using annotations that look something like this:

@GeneratedValue(strategy=GenerationType.SEQUENCE, generator=”POC_ID_SEQ”)
@SequenceGenerator(name=”POC_ID_SEQ”, sequenceName=”POC_ID_SEQ”, allocationSize=1)

Between creating the actual sequence in the database and making sure you have your annotations right (watch those typos!), it seems a bit cumbersome. But it typically “just works”, without fuss.

Enter MySQL. Designating an integer-based field as PRIMARY KEY and using the keyword AUTO_INCREMENT makes the same task seem much simpler. And it is, mostly. But while NetBeans cranks out a superb “first cut” for a basic JSF CRUD app, there are a couple of small things you’ll need to bring to the mix in order to be able to actually (C)reate records. The (RUD) performs fine out of the gate.

The Solution

Omitting all design considerations and activity (!), here is the basic sequence of events I followed to create, then resolve, the JSF/MySQL “Primary Key Perfect Storm”:

  1. Fire up NetBeans.
  2. Create JSF project.
  3. Create Entity Classes from Database.
  4. Create JSF Pages from Entity Classes.
  5. Test run. Try to create record and hit error.

It’s a simple fix, but one that was fun to find in its completeness. :-) Even though you’ve told it what to do for a primary key, a MySQL table requires a gentle nudge to actually generate that new key value. Two things are needed to make the magic happen.

First, you need to ensure the following annotation is in place in your Java entity classes:

@GeneratedValue(strategy = GenerationType.IDENTITY)

All well and good, but the real key is this: in your controller class(es), you’ll have a create() function that looks something like this, minus the comment line and the setId() call in bold red type:

    public String create() {
        try {
            // Assign 0 to ID for MySQL to properly auto_increment the primary key.
            current.setId(0);
            getFacade().create(current);
            JsfUtil.addSuccessMessage(ResourceBundle.getBundle(“/Bundle”).getString(“CategoryCreated”));
            return prepareCreate();
        } catch (Exception e) {
            JsfUtil.addErrorMessage(e, ResourceBundle.getBundle(“/Bundle”).getString(“PersistenceErrorOccured”));
            return null;
        }
    }

Setting the current object’s primary key attribute to zero (0) prior to saving it tells MySQL to get the next available value and assign it to that record’s key field. Short and simple…but not inherently obvious if you’ve never used that particular combination of NetBeans/JSF/MySQL before. Hope this helps!

All the best,
Mark

Share

Tags: , , , , , , , ,

I recently ran across a neat concept that I’d really like to see spring up in more places. I’m not sure how to accomplish that exactly, but it does have me thinking.

The Seneca College Linux Club created a kiosk where folks can walk up, select a Free/Open Source Software package, and burn it to a CD or DVD that they bring with them. Based upon the FreedomToaster project in South Africa, this spreads high-quality software throughout the community with very little effort and no real cost (blank CDs and DVDs are typically a few cents apiece). All boats rise with the tide, and this is a huge positive for everyone.

What about commercial software vendors, you may ask? Well, the more people use quality software, the more their use of technology and software increases overall. In short, the more they can do, the more they want to do. Quality commercial software fills gaps, races ahead, provides depth of support, and offers profit opportunities – it’s always been that way and will likely never change. The growth of the software industry often pits commercial against FOSS, but that doesn’t mean that there isn’t room for both.  :-)

Click here to read about the Seneca College Freedom Toaster and see what you think. Ready to start building?

K

Share

Tags: , , , , , , ,

Powered by Wordpress
Theme © 2005 - 2009 FrederikM.de
BlueMod is a modification of the blueblog_DE Theme by Oliver Wunder