void DSIGKeyInfoX509::load()

in xsec/dsig/DSIGKeyInfoX509.cpp [120:297]


void DSIGKeyInfoX509::load(void) {

	// Assuming we have a valid DOM_Node to start with, load the signing key so that it can
	// be used later on

	if (mp_keyInfoDOMNode == NULL) {

		// Attempt to load an empty signature element
		throw XSECException(XSECException::LoadEmptyX509);

	}

	if (!strEquals(getDSIGLocalName(mp_keyInfoDOMNode), "X509Data")) {

		throw XSECException(XSECException::LoadNonX509);

	}

	// Now check for an X509 Data Element we understand

	DOMNode *tmpElt = mp_keyInfoDOMNode->getFirstChild();
	DOMNode *child;	// Worker

	while (tmpElt != 0) {

		if (tmpElt->getNodeType() == DOMNode::ELEMENT_NODE) {

			// See if it's a known element type
			if (strEquals(getDSIGLocalName(tmpElt), "X509Certificate")) {

			    // Loop over Text nodes until we successfully load a certificate.
			    // If we run out, throw out the last exception raised.

				X509Holder * h;
                XSECCryptoX509* cryptoX509 = XSECPlatformUtils::g_cryptoProvider->X509();
				DOMNode *certElt = findFirstChildOfType(tmpElt, DOMNode::TEXT_NODE);
				while (certElt) {
                    XSECAutoPtrChar charX509(certElt->getNodeValue());
				    try {
                        cryptoX509->loadX509Base64Bin(charX509.get(), (int) strlen(charX509.get()));

	                    // Add to the list
                        XSECnew(h, X509Holder);
	                    m_X509List.push_back(h);
	                    h->mp_encodedX509 = certElt->getNodeValue();
	                    h->mp_cryptoX509 = cryptoX509;
	                    break;
				    }
			catch (const XSECCryptoException&) {
	                    certElt = findNextChildOfType(certElt, DOMNode::TEXT_NODE);
	                    if (!certElt) {
	                        delete cryptoX509;
	                        throw;
	                    }
				    }
				}
			}

			else if (strEquals(getDSIGLocalName(tmpElt), "X509SubjectName")) {

				child = findFirstChildOfType(tmpElt, DOMNode::TEXT_NODE);

				if (child == NULL) {

					throw XSECException(XSECException::ExpectedDSIGChildNotFound,
						"Expected TEXT_NODE child of <X509SubjectName>");

				}

				mp_X509SubjectName = decodeDName(child->getNodeValue());

			}

			else if (strEquals(getDSIGLocalName(tmpElt), "X509IssuerSerial")) {

				child = tmpElt->getFirstChild();
				while (child != 0 && child->getNodeType() != DOMNode::ELEMENT_NODE &&
					!strEquals(getDSIGLocalName(child), "X509IssuerName"))
					child = child->getNextSibling();

				if (child == NULL) {

					throw XSECException(XSECException::ExpectedDSIGChildNotFound,
						"Expected <X509IssuerName> child of <X509IssuerSerial>");

				}

				child = child->getFirstChild();
				while (child != 0 && child->getNodeType() != DOMNode::TEXT_NODE)
					child = child->getNextSibling();

				if (child == NULL) {

					throw XSECException(XSECException::ExpectedDSIGChildNotFound,
						"Expected TEXT_NODE child of <X509IssuerSerial>");

				}

				mp_X509IssuerName = decodeDName(child->getNodeValue());

				// Now find the serial number
				child = tmpElt->getFirstChild();
				while (child != 0 && (child->getNodeType() != DOMNode::ELEMENT_NODE ||
					!strEquals(getDSIGLocalName(child), "X509SerialNumber")))
					child = child->getNextSibling();

				if (child == NULL) {

					throw XSECException(XSECException::ExpectedDSIGChildNotFound,
						"Expected <X509SerialNumber> child of <X509IssuerSerial>");

				}

				child = child->getFirstChild();
				while (child != 0 && child->getNodeType() != DOMNode::TEXT_NODE)
					child = child->getNextSibling();

				if (child == NULL) {

					throw XSECException(XSECException::ExpectedDSIGChildNotFound,
						"Expected TEXT_NODE child of <X509IssuerSerial>");

				}

				mp_X509SerialNumber = child->getNodeValue();

			}

			else if (strEquals(getDSIGLocalName(tmpElt), "X509CRL")) {

                DOMNode *crlElt = findFirstChildOfType(tmpElt, DOMNode::TEXT_NODE);

                if (crlElt != 0) {

                    // Add to the list
                    m_X509CRLList.push_back(crlElt->getNodeValue());

                }

			}
			else if (strEquals(getDSIGLocalName(tmpElt), "X509SKI")) {

				child = findFirstChildOfType(tmpElt, DOMNode::TEXT_NODE);

				if (child == NULL) {

					throw XSECException(XSECException::ExpectedDSIGChildNotFound,
						"Expected TEXT_NODE child of <X509SKI>");

				}

				mp_X509SKITextNode = child;
				mp_X509SKI = child->getNodeValue();

			}
            else if (strEquals(getDSIG11LocalName(tmpElt), "X509Digest")) {

                child = findFirstChildOfType(tmpElt, DOMNode::TEXT_NODE);

                if (child == NULL) {

                    throw XSECException(XSECException::ExpectedDSIGChildNotFound,
                        "Expected TEXT_NODE child of <X509Digest>");

                }

                mp_X509DigestTextNode = child;

            }
		}

		// Go to next data element to load if we understand

		tmpElt = tmpElt->getNextSibling();

	}

}