Whether it's verifying the integrity of a message's source, a software license file, or a download, employing digital signatures is imperative.
So just what is a digital signature anyway?
A digital signature is the digital era's equivalent of yesterday's hand-written signature. That is, each time we sign that receipt after using our debit or credit card, we are effectively telling our financial institution that we agreed to pay a given price for a given item. In the event that an alleged fraudulent charge is made, authorities can perform signature comparisons to help determine the validity of the claim. Digital signatures work in a similar fashion for electronic messages. That is, they use a form of asymmetric algorithms whereby the message's sender applies a digital signing algorithm to the message using a private key (asymmetric algorithms use public- and private-key technology in which each user has a private key that is known only to the user and a public key that is publicly known). The output is referred to as the digital signature. When the message is received by its target recipient, the sender's authenticity is determined by using a signature verification algorithm coupled with the sender's public key. Through the employment of this scheme, digital signatures offer two very important benefits to their users:
- Integrity: The message's recipient can confidently assume that the message, as constructed by the sender, has not been altered in any manner during transmission.
- Authentication: The message's recipient can confidently assume that the source of the message is as it appears. That is, it would be extremely difficult for an attacker to spoof the identity of the message's source.
It's because of these benefits that digital signatures are so widely used today, especially given the nature of activities for which society uses its computers (e.g., online shopping, online banking, etc.). Without the use of digital signatures, it would be trivial for an attacker to forge a message or alter the contents of a message, actions that are just not acceptable by today's standards.
Why Are Digital Signatures Important?
It shouldn't be difficult to see why employing digital signatures is imperative in today's world. For example, imagine that we send instructions to a financial institution to transfer a large sum of money into another account. We'd definitely hope there's some sort of digital signature accompanying that transfer request! Or imagine sending emails within our organization; in the absence of digitally signing our emails (which most email clients now support), it would be (relatively) easy for an attacker to forge emails on our behalf.
Implications
While digital signatures play an integral role in today's digital security, there are some disguised drawbacks. For example, what happens if a party's private key is inadvertently compromised? In essence, that would allow an attacker to forge the party's signature. This also leads to problems in the area of repudiation. In this context, "repudiation" refers to the act of disclaiming responsibility for a message. That is, a signer states that he or she did not sign the message, but the recipient claims that the message was verified. If signers make such claims, they're repudiating their signature key. In a nutshell, it's of utmost importance that private keys are kept private. In the event of any suspected compromise of that key, the owner of the key should immediately inform potential recipients of the compromise and then generate a new pair of keys.
Digital Signatures in Java
Because Java is widely used for many enterprise-level applications, it should come as no surprise that it supports a wide spectrum of cryptographic capabilities, one of which just happens to be out-of-the-box JDK support for digital signatures. Java supports the notion of a SignedObject, which is an authentic runtime object whose integrity cannot be compromised without being detected. This special object contains a serializable object (i.e., the to-be-signed object) and its signature. The signed object is a deep copy, a "clone" of sorts of the original to-be-signed object. It must be a deep copy for integrity's sake; manipulation of the original object has no effect on the copy.
Related Java Classes
There are a wide variety of objects with which we might work when performing digital signature-type operations in Java. The following paragraphs will make a brief attempt to summarize some of the commonly used objects (note that all objects mentioned exist within the java.security package) and explain how they might be used.
- KeyPairGenerator: As the name suggests, this is the object that's responsible for algorithm-specific key generation. It allows us to also specify the key length; typically, longer key lengths lead to harder-to-break digital signatures. The output of this object is a KeyPair.
- KeyPair: This is the output from a KeyPairGenerator for a specific algorithm. It contains two accessor methods to retrieve both the public and private keys.
- Key: The Key interface is the top-level interface for all keys, namely PrivateKey and PublicKey. Every key is tied to a specific algorithm (e.g., DSA or RSA) and has an encoding format (e.g., X.509) for representation outside of the JVM.
- PrivateKey: This is a special Key implementation, most notably used for type safety (e.g., we wouldn't want to accidentally use a PublicKey where a PrivateKey was expected). This key should be kept secret to the party performing the digital signature. Failure to keep this key private will provide a malicious user with the ability to forge the user's signature.
- PublicKey: Like PrivateKey, PublicKey is a special Key used primarily for type safety. This key should be made publicly known; users will use this key, coupled with the appropriate verification algorithm, to determine the validity of a digital signature.
- Signature: Based on a user-specified signing algorithm, this is the "engine" that actually performs the signing and verification of digital signatures.
- SignedObject: Per the JDK specifications, a SignedObject is used for creating runtime authentic objects whose integrity cannot be compromised without being detected. A signed object is created by effectively coupling a serializable object (i.e., the user object to digitally sign) with a PrivateKey and a Signature (i.e., the two objects used to create the digital signature). This object can also be serialized and deserialized for object persistence.
As you can see, there are many pieces involved when working with digital signatures in Java, ranging from key generation to digital signature verification. Each piece plays an instrumental role in the end-to-end process, so it's important to study each component.
Another item worth touching on is the notion of cryptographic providers. As we study many of the classes encompassed by the java.security package, we will encounter many instances in which their methods accept a provider parameter. This parameter refers to whose implementation of the various algorithms is used. For example, both Company A and Company B might provide implementations of the DSA algorithm; this allows us to choose whose implementation to select.
Example: Digitally Signing a License File
A common instance in which a digital signature is used is in the area of software-license file generation and verification. Often, software vendors will use a (vendor-generated) license file of sorts to determine, at runtime, the features available to the customer. At the very least, the license verifier engine should be able to detect when the license file has been changed from its original state (e.g., a mischievous customer tries to alter the license file so that features they didn't pay for are available). The following steps outline the procedure to create a license file (it's assumed that the software features are stored in an instance of java.util.Properties, although any serializable object would suffice):
- Using KeyPairGenerator, generate a public- and private-key pair and serialize them for future use. Be sure to store the private key in a "secure" area of the file system (this step needs to be performed only once across all license file generation).
- Deserialize the PrivateKey generated as part of step 1.
- Construct an instance of java.util.Properties such that its key-value pairs represent feature-enabled Booleans.
- Construct an instance of SignedObject (this object represents the license in its entirety), passing the Properties instance, the PrivateKey instance, and a Signature instance. The algorithm used for the signature should pair with the algorithm used to generate the keys (e.g., if "DSA" was used to generate the keys, then "SHA/DSA" should be used for the signature).
- Serialize the SignedObject instance and transmit it, along with the PublicKey generated in step 1, to the customer. Any future modification to the signed object will be detected by the (forthcoming) verification steps.
Note: Although it's less flexible, the PublicKey could also be hard-coded (e.g., as a hexadecimal sequence) into the application. And since it's (by definition) in the public domain, we're not concerned with anyone decompiling the application and looking for private information.
Now that we've seen how to generate and transmit a signed license file, let's take a look at how we can verify its integrity before using it.
- Deserialize the PublicKey as generated in the previous set of steps; this key is an integral part in verifying the contents of the license file.
- Deserialize the SignedObject as generated in the previous set of steps; this is the object whose integrity we want to verify (e.g., to ensure that the customer hasn't tried to alter the license).
- Invoke signedObject.verify(publicKey, signature) and ensure the value true is returned; if not (or if exceptions occur), the license file's integrity has been compromised and processing should not continue.
Take Note
As with any programming project, there are always traps to look for while coding. One such trap in Java is the signing engine's provider. As mentioned previously, most of the APIs that have been referenced will also accept a provider (e.g., SUN, IBM, etc.) argument, specifying which vendor's implementation of the signing engine to use. For example, a malicious implementation of the SignedObject::verify(...) method could always return true, tricking a program into thinking the signature was verified. As such, this is definitely something worth keeping your eyes open for (i.e., always use a trusted provider).
Get Digitized
Digital signatures serve a wide array of purposes in today's world of computing. Whether it's verifying the integrity of a message's source, a software license file, or a download, employing digital signatures is imperative. They provide effective solutions to the previously mentioned common problems. A wide variety of programming language libraries provide digital-signature support, and as we've seen from the Java pseudo-examples, their use is relatively simple when compared with their added benefits.
LATEST COMMENTS
MC Press Online