Пример #1
0
DSIGReferenceList *DSIGReference::loadReferenceListFromXML(const XSECEnv * env, DOMNode *firstReference) {

	// Have the first reference element in the document,
	// so want to find and load them all

	DOMNode *tmpRef = firstReference;
	DSIGReferenceList * refList;
	DSIGReference * r;

	XSECnew(refList, DSIGReferenceList());
	Janitor<DSIGReferenceList> j_refList(refList);

	while (tmpRef != 0) {

		// Must be an element node

		if (tmpRef->getNodeType() != DOMNode::ELEMENT_NODE ||
			!strEquals(getDSIGLocalName(tmpRef), "Reference")) {

			throw XSECException(XSECException::ExpectedDSIGChildNotFound,
				"Expected <Reference> as child of <SignedInfo>");

		}

		XSECnew(r, DSIGReference(env, tmpRef));

		refList->addReference(r);

		// Load the reference before moving on
		r->load();

		// Find next element Node
		tmpRef = tmpRef->getNextSibling();

		while (tmpRef != 0 && tmpRef->getNodeType() != DOMNode::ELEMENT_NODE) {
			if (tmpRef->getNodeType() == DOMNode::ENTITY_REFERENCE_NODE) {
				throw XSECException(XSECException::ExpectedDSIGChildNotFound,
					"EntityReference nodes in <Reference> are unsupported.");
			}
			tmpRef = tmpRef->getNextSibling();
		}

	}

	j_refList.release();
	return refList;

}
Пример #2
0
DOMElement *DSIGSignedInfo::createBlankSignedInfo(canonicalizationMethod cm,
			signatureMethod	sm,
			hashMethod hm) {

	safeBuffer str;
	safeBuffer prefixNS = mp_parentSignature->getDSIGNSPrefix();

	makeQName(str, prefixNS, "SignedInfo");

	DOMElement *ret = mp_doc->createElementNS(DSIGConstants::s_unicodeStrURIDSIG, 
								str.sbStrToXMLCh());
	
	mp_signedInfoNode = ret;

	// Now create the algorithm parts
	m_canonicalizationMethod = cm;
	m_signatureMethod = sm;
	m_hashMethod = hm;

	// Canonicalisation

	DOMElement *canMeth = mp_doc->createElementNS(DSIGConstants::s_unicodeStrURIDSIG, 
			makeQName(str, prefixNS, "CanonicalizationMethod").sbStrToXMLCh());

	mp_signedInfoNode->appendChild(mp_doc->createTextNode(DSIGConstants::s_unicodeStrNL));
	mp_signedInfoNode->appendChild(canMeth);
	mp_signedInfoNode->appendChild(mp_doc->createTextNode(DSIGConstants::s_unicodeStrNL));

	if (!canonicalizationMethod2URI(str, cm)) {
	
		throw XSECException(XSECException::SignatureCreationError,
			"Attempt to use undefined Canonicalisation Algorithm in SignedInfo Creation");

	}

	canMeth->setAttribute(DSIGConstants::s_unicodeStrAlgorithm, str.sbStrToXMLCh());

	// Now the SignatureMethod

	DOMElement *sigMeth = mp_doc->createElementNS(DSIGConstants::s_unicodeStrURIDSIG, 
			makeQName(str, prefixNS, "SignatureMethod").sbStrToXMLCh());

	mp_signedInfoNode->appendChild(sigMeth);
	mp_signedInfoNode->appendChild(mp_doc->createTextNode(DSIGConstants::s_unicodeStrNL));

	if (!signatureHashMethod2URI(str, sm, hm)) {
	
		throw XSECException(XSECException::SignatureCreationError,
			"Attempt to use undefined Signature/Algorithm combination in SignedInfo Creation");

	}

	sigMeth->setAttribute(DSIGConstants::s_unicodeStrAlgorithm, str.sbStrToXMLCh());

	// Create an empty reference list

	XSECnew(mp_referenceList, DSIGReferenceList());

	return ret;

}