> From: Berin Lautenbach
> Not so much a function. If you create a Reference with a URI that
> points to the file you want to use, that should do the trick.
trying this and failing
I'm sure I am missing something obvious but I can't see any examples using URI and
mine isn't working
I created a reference with a URI that points to the file and called sign and the sign
function throws
"XPath requires DOM_NODES input type"
The function I use is below
Any idea what I am missing?
I have tried having the URI with and without the root node <DALML/> part with no
difference
I have tried setting or not setting a URI resolver
and I have tried the generic and xerces resolvers
nothing helps
Vin
the string sDocument is "<Start></Start>"
// begin code
void XMLSignature::SignDocument(std::string const& sDocument, std::string& sOutput)
{
XMLPlatformUtils::Initialize();
XSECPlatformUtils::Initialise();
// parse the document
XercesDOMParser domParser;
domParser.setDoNamespaces(true);
MemBufInputSource memIS((const XMLByte*) sDocument.c_str(), sDocument.size(),
"XSECMem");
domParser.parse(memIS);
DOMDocument* doc = domParser.getDocument();
DOMElement *rootElem = doc->getDocumentElement();
// Create a signature object
XSECProvider prov;
DSIGSignature * sig = prov.newSignature();
sig->setDSIGNSPrefix(MAKE_UNICODE_STRING("ds"));
// Insert the signature DOM nodes into the doc
DOMElement *sigNode;
sigNode = sig->createBlankSignature(doc, CANON_C14N_COM, SIGNATURE_HMAC, HASH_SHA1);
rootElem->appendChild(sigNode);
//////////////////////////////
// Here are my attempts at the URI
XMLUri uri(MAKE_UNICODE_STRING("file:///C:/dbs/haha.xml#DALML"));
//XSECURIResolverGenericWin32 theResolver;
XSECURIResolverXerces theResolver;
theResolver.setBaseURI(uri.getUriText());
sig->setURIResolver(&theResolver);
DSIGReference * ref =
sig->createReference(MAKE_UNICODE_STRING("file:///C:/dbs/haha.xml#DALML"));
// Create an envelope reference for the text to be signed
ref->appendEnvelopedSignatureTransform();
// End attempts
//////////////////////////////
// Set the HMAC Key to be our key, the signature will own this so we don't
want an auto_ptr
OpenSSLCryptoKeyHMAC* hmacKey = new OpenSSLCryptoKeyHMAC();
hmacKey->setKey((unsigned char *) g_acKey, strlen(g_acKey));
sig->setSigningKey(hmacKey);
// Sign the document
try{
sig->sign();
}
catch (XSECException &e)
{
std::wstring ws(e.getMsg());
std::cout << "An error occured during a signature load\n Message: "
<< std::endl;
exit(1);
}
prov.releaseSignature(sig);
// write the file
DOMImplementation *impl = doc->getImplementation();
std::auto_ptr<DOMWriter> theSerializer(impl->createDOMWriter());
USES_CONVERSION;
sOutput = W2A(theSerializer->writeToString(*doc));
XSECPlatformUtils::Terminate();
XMLPlatformUtils::Terminate();
}