XML DSig, signing with external keys

Hello,

is there any way how I can use the the new XML DSig APIs in Java 6 to sign an XML document using an external key -- that is, a key that is not available as a Java PrivateKey object?

What I am trying to do is to use a private key stored on a smart card to sign an XML document. The key being stored on a smart card, I can't access the key data at all. But I can have the card sign a digest internally.

In terms of XML DSig APIs, I'd like to create an XMLSignature and use it to calculate the reference data (digest), then sign the digest using the SC, and store the resulting signature in the XMLSignature object.

As far as I can see, XML DSig APIs do not support this. In order to sign an XML document, I need to call XMLSignature.sign with an XMLSignContext, which is used to select a key. But, as I said, I don't have a key. The API does not say, but perhaps the digest value is calculated even before sign() is called -- I don't know. However, XMLSignatureFactory does not contain methods to create a SignatureValue object, nor can one be added to XMLSignature after it has been created, so I won't be able to store one in XMLSignature object anyway.

Apparently this use case has not been considered in JSR 105 at all?

[1270 byte] By [artoha] at [2007-11-27 9:29:37]
# 1

Replying to myself, the obvious hack, unless there is a better way, to accomplish what I'm trying to do is

- sign the document with a dummy key first

- pull digest from the resulting XMLSignature and sign it using the SC

- dump XMLSignature to DOM tree

- replace resulting SignatureValue element contents with the real signature (and fix KeyInfo)

Which is not nice.

artoha at 2007-7-12 22:38:37 > top of Java-index,Security,Other Security APIs, Tools, and Issues...
# 2

Have you tried using a PKCS#11 JCE provider to access the keys on the smart card? I believe this will work with the XML DSig API, as long as the provider is configured appropriately and is registered so that it is tried before other providers. See the following document for more information about Sun's PKCS11 provider: http://java.sun.com/javase/6/docs/technotes/guides/security/p11guide.html

smullana at 2007-7-12 22:38:37 > top of Java-index,Security,Other Security APIs, Tools, and Issues...