Ejemplo n.º 1
0
void DSIGTransformXPath::load(void) {

	// Find the XPath expression
	
	mp_xpathNode = mp_txfmNode->getFirstChild();

	while (mp_xpathNode != 0 && 
		mp_xpathNode->getNodeType() != DOMNode::ELEMENT_NODE && !strEquals(mp_xpathNode->getNodeName(), "XPath"))
		mp_xpathNode = mp_xpathNode->getNextSibling();
	
	if (mp_xpathNode == 0) {

		throw XSECException(XSECException::ExpectedDSIGChildNotFound,
			"Expected <XPath> Node in DSIGTransformXPath::load");
	}
	
	else {
		
		// Check for attributes - in particular any namespaces

		mp_NSMap = mp_xpathNode->getAttributes();
		
		// Find the text node
		mp_exprTextNode = findFirstChildOfType(mp_xpathNode, DOMNode::TEXT_NODE);

		if (mp_exprTextNode == NULL) {
			throw XSECException(XSECException::ExpectedDSIGChildNotFound,
				"Expected Text Node in beneath <XPath> in DSIGTransformXPath::load");
		}

		// Gather the text
		safeBuffer exprSB;

		gatherChildrenText(mp_xpathNode, exprSB);

		m_expr << (*(mp_env->getSBFormatter()) << exprSB.rawXMLChBuffer());

		//m_expr << (*(mp_env->getSBFormatter()) << mp_exprTextNode->getNodeValue());
				
	}

}
Ejemplo n.º 2
0
void XENCEncryptionMethodImpl::load() {

	if (mp_encryptionMethodElement == NULL) {

		// Attempt to load an empty encryptedType element
		throw XSECException(XSECException::EncryptionMethodError,
			"XENCEncryptionMethod::load - called on empty DOM");

	}

	if (!strEquals(getXENCLocalName(mp_encryptionMethodElement), s_EncryptionMethod)) {

		// Attempt to load an empty encryptedData element
		throw XSECException(XSECException::EncryptionMethodError,
			"XENCEncryptionMethod::load - called on non EncryptionMethod node");

	}

	// Find the type
	mp_algorithmAttr = 
		mp_encryptionMethodElement->getAttributeNodeNS(NULL, 
			DSIGConstants::s_unicodeStrAlgorithm);

	// Check for known children
	DOMElement * c = findFirstElementChild(mp_encryptionMethodElement);

	while (c != NULL) {

		if (strEquals(getDSIGLocalName(c), s_DigestMethod)) {

			mp_digestAlgorithmAttr = c->getAttributeNodeNS(NULL, 
				DSIGConstants::s_unicodeStrAlgorithm);

			if (mp_digestAlgorithmAttr == NULL) {
				throw XSECException(XSECException::EncryptionMethodError,
					"XENCEncryptionMethod::load - Cannot find Algorithm Attribute in DigestMethod element");
			}
		}

		else if (strEquals(getXENC11LocalName(c), s_MGF)) {

			mp_mgfAlgorithmAttr = c->getAttributeNodeNS(NULL, 
				DSIGConstants::s_unicodeStrAlgorithm);

			if (mp_mgfAlgorithmAttr == NULL) {
				throw XSECException(XSECException::EncryptionMethodError,
					"XENCEncryptionMethod::load - Cannot find Algorithm Attribute in xenc11:MGF element");
			}
		}

        else if (strEquals(getXENCLocalName(c), s_OAEPparams)) {

			mp_oaepParamsTextNode = NULL;
			mp_oaepParamsTextNode = findFirstChildOfType(c, DOMNode::TEXT_NODE);

			if (mp_oaepParamsTextNode == NULL) {
				throw XSECException(XSECException::EncryptionMethodError,
					"XENCEncryptionMethod::load - Cannot find text value of xenc:OAEPparams element");
			}

		}

		else if (strEquals(getXENCLocalName(c), s_KeySize)) {

			mp_keySizeTextNode = NULL;
			mp_keySizeTextNode = findFirstChildOfType(c, DOMNode::TEXT_NODE);

			if (mp_keySizeTextNode == NULL) {
				throw XSECException(XSECException::EncryptionMethodError,
					"XENCEncryptionMethod::load - Cannot find text value of xenc:KeySize node");
			}

		}
		c = findNextElementChild(c);
	}
}
Ejemplo n.º 3
0
void XKMSStatusImpl::load() {

	if (mp_statusElement == NULL) {

		// Attempt to load an empty element
		throw XSECException(XSECException::StatusError,
			"XKMSStatus::load - called on empty DOM");

	}

	/* Load the StatusValue attribute */

	mp_statusValueAttr = 
		mp_statusElement->getAttributeNodeNS(NULL, XKMSConstants::s_tagStatusValue);

	/* Decode as appropriate*/
	if (mp_statusValueAttr == NULL) {
		// Attempt to load an empty element
		throw XSECException(XSECException::StatusError,
			"XKMSStatus::load - No StatusValue attribute found");
	}

	const XMLCh * res = mp_statusValueAttr->getNodeValue();

	// This is actually an QName, but we cheat and find the ':' character by hand
	// without actually checking the qualifier.
	// TODO - CHECK the qualifier.

	int res2 = XMLString::indexOf(res, chPound);
	if (res2 == -1 || XMLString::compareNString(res, XKMSConstants::s_unicodeStrURIXKMS, res2)) {
			throw XSECException(XSECException::StatusError,
				"XKMSStatus::load - StatusValue not in XKMS Name Space");
	}
	res = &res[res2+1];

	for (m_statusValue = XKMSStatus::Indeterminate; 
		m_statusValue > XKMSStatus::StatusUndefined; 
		m_statusValue = (XKMSStatus::StatusValue) (m_statusValue-1)) {

		if (strEquals(XKMSConstants::s_tagStatusValueCodes[m_statusValue], res))
			break;

		
	}

	if (m_statusValue == XKMSStatus::StatusUndefined) {

		throw XSECException(XSECException::StatusError,
			"XKMSStatus::load - Unknown StatusValue provided");

	}

	/* Now we need to run through the status values */
	DOMElement * e = findFirstElementChild(mp_statusElement);
	while (e != NULL) {

		const XMLCh * vs = getXKMSLocalName(e);

		StatusValue v;

		if (strEquals(vs, XKMSConstants::s_tagValidReason)) {
			v = Valid;
		}
		else if (strEquals(vs, XKMSConstants::s_tagInvalidReason)) {
			v = Invalid;
		}
		else if (strEquals(vs, XKMSConstants::s_tagIndeterminateReason)) {
			v = Indeterminate;
		}
		else {
			throw XSECException(XSECException::StatusError,
				"XKMSStatus::load - Unknown Reason element");
		}

		DOMNode *t = findFirstChildOfType(e, DOMNode::TEXT_NODE);
		if (t == NULL) {
			throw XSECException(XSECException::StatusError,
				"XKMSStatus::load - Expected text node child of reason element");
		}

		/* Strip out the URI prefix */
		const XMLCh * reason = t->getNodeValue();

		int res = XMLString::indexOf(reason, chPound);
		if (res == -1 || XMLString::compareNString(reason, XKMSConstants::s_unicodeStrURIXKMS, res)) {
				throw XSECException(XSECException::StatusError,
					"XKMSStatus::load - StatusReason not in XKMS Name Space");
		}
		reason = &reason[res+1];

		/* Found out what we are! */
		XKMSStatus::StatusReason i;
		for (i = XKMSStatus::Signature; i != XKMSStatus::ReasonUndefined; i = (XKMSStatus::StatusReason) (i-1)) {

			if (strEquals(XKMSConstants::s_tagStatusReasonCodes[i], reason))
				break;

		}

		if (i == XKMSStatus::ReasonUndefined) {
			throw XSECException(XSECException::StatusError,
				"XKMSStatus::load - Unknown StatusReason");
		}

		m_statusReasons[v-1][i-1] = e;

		e = findNextElementChild(e);

	}

}
void DSIGKeyInfoValue::load(void) {

	if (mp_valueNode == NULL || !strEquals(getDSIGLocalName(mp_valueNode), "KeyValue")) {

		throw XSECException(XSECException::ExpectedDSIGChildNotFound,
			"Empty or incorrect node passed to DSIGKeyInfoValue");

	}

	XSECSafeBufferFormatter *formatter;

	formatter = mp_parentSignature->getSBFormatter();

	DOMNode *child, *p, *val;

	child = mp_valueNode->getFirstChild();
	while (child != NULL && child->getNodeType() != DOMNode::ELEMENT_NODE)
		child = child->getNextSibling();
	//child = findFirstChildOfType(mp_valueNode, DOMNode::ELEMENT_NODE);

	if (child == 0) {
		throw XSECException(XSECException::ExpectedDSIGChildNotFound,
			"Empty Expected value node beneath <KeyValue>");

	}

	if (strEquals(getDSIGLocalName(child), "DSAKeyValue")) {

		m_keyInfoType = KEYINFO_VALUE_DSA;

		p = findFirstChildOfType(child, DOMNode::ELEMENT_NODE);

		while (p != NULL) {

			if (strEquals(getDSIGLocalName(p), "P")) {
				val = findFirstChildOfType(p, DOMNode::TEXT_NODE);
				if (val != NULL) {
					mp_PTextNode = val;
					m_P << (*formatter << val->getNodeValue());
				}
			}
			if (strEquals(getDSIGLocalName(p), "Q")) {
				val = findFirstChildOfType(p, DOMNode::TEXT_NODE);
				if (val != NULL) {
					mp_QTextNode = val;
					m_Q << (*formatter << val->getNodeValue());
				}
			}
			if (strEquals(getDSIGLocalName(p), "G")) {
				val = findFirstChildOfType(p, DOMNode::TEXT_NODE);
				if (val != NULL) {
					mp_GTextNode = val;
					m_G << (*formatter << val->getNodeValue());
				}
			}
			if (strEquals(getDSIGLocalName(p), "Y")) {
				val = findFirstChildOfType(p, DOMNode::TEXT_NODE);
				if (val != NULL) {
					mp_YTextNode = val;
					m_Y << (*formatter << val->getNodeValue());
				}
			}

			p = p->getNextSibling();

		}
	}

	else if (strEquals(getDSIGLocalName(child), "RSAKeyValue")) {

		m_keyInfoType = KEYINFO_VALUE_RSA;

		p = findFirstChildOfType(child, DOMNode::ELEMENT_NODE);

		if (p == 0 || !strEquals(getDSIGLocalName(p), "Modulus")) {

			throw XSECException(XSECException::ExpectedDSIGChildNotFound,
				"Expected <Modulus> node beneath <RSAKeyValue>");

		}

		val = findFirstChildOfType(p, DOMNode::TEXT_NODE);

		if (val == 0) {

			throw XSECException(XSECException::ExpectedDSIGChildNotFound,
				"Expected a text node beneath <Modulus>");

		}
		
		m_modulus << (*formatter << val->getNodeValue());
		mp_modulusTextNode = val;

		// Find the Exponent

		p = p->getNextSibling();

		while (p != 0 && p->getNodeType() != DOMNode::ELEMENT_NODE)
			p = p->getNextSibling();

		if (p == 0 || !strEquals(getDSIGLocalName(p), "Exponent")) {

			throw XSECException(XSECException::ExpectedDSIGChildNotFound,
				"Expected <Exponent> node beneath <RSAKeyValue>");

		}

		val = findFirstChildOfType(p, DOMNode::TEXT_NODE);

		if (val == 0) {

			throw XSECException(XSECException::ExpectedDSIGChildNotFound,
				"Expected a text node beneath <Exponent>");

		}
		
		m_exponent << (*formatter << val->getNodeValue());
		mp_exponentTextNode = val;

	}

	else {

		throw XSECException(XSECException::UnknownKeyValue);

	}

}