+
+string SAMLInternalConfig::hashSHA1(const char* s, bool toHex)
+{
+ static char DIGITS[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
+
+ auto_ptr<XSECCryptoHash> hasher(XSECPlatformUtils::g_cryptoProvider->hashSHA1());
+ if (hasher.get()) {
+ unsigned char buf[21];
+ hasher->hash(reinterpret_cast<unsigned char*>(const_cast<char*>(s)),strlen(s));
+ if (hasher->finish(buf,20)==20) {
+ string ret;
+ if (toHex) {
+ for (unsigned int i=0; i<20; i++) {
+ ret+=(DIGITS[((unsigned char)(0xF0 & buf[i])) >> 4 ]);
+ ret+=(DIGITS[0x0F & buf[i]]);
+ }
+ }
+ else {
+ for (unsigned int i=0; i<20; i++) {
+ ret+=buf[i];
+ }
+ }
+ return ret;
+ }
+ }
+ throw XMLSecurityException("Unable to generate SHA-1 hash.");
+}
+
+using namespace saml2p;
+using namespace saml2md;
+
+void opensaml::annotateException(XMLToolingException* e, const EntityDescriptor* entity, const Status* status, bool rethrow)
+{
+ const RoleDescriptor* role = NULL;
+ if (entity) {
+ const list<XMLObject*>& roles=entity->getOrderedChildren();
+ for (list<XMLObject*>::const_iterator child=roles.begin(); !role && child!=roles.end(); ++child) {
+ role=dynamic_cast<RoleDescriptor*>(*child);
+ if (role && !role->isValid())
+ role = NULL;
+ }
+ }
+ annotateException(e, role, status, rethrow);
+}
+
+void opensaml::annotateException(XMLToolingException* e, const RoleDescriptor* role, const Status* status, bool rethrow)
+{
+ if (role) {
+ auto_ptr_char id(dynamic_cast<EntityDescriptor*>(role->getParent())->getEntityID());
+ e->addProperty("entityID",id.get());
+
+ const vector<ContactPerson*>& contacts=role->getContactPersons();
+ for (vector<ContactPerson*>::const_iterator c=contacts.begin(); c!=contacts.end(); ++c) {
+ const XMLCh* ctype=(*c)->getContactType();
+ if (ctype && (XMLString::equals(ctype,ContactPerson::CONTACT_SUPPORT)
+ || XMLString::equals(ctype,ContactPerson::CONTACT_TECHNICAL))) {
+ GivenName* fname=(*c)->getGivenName();
+ SurName* lname=(*c)->getSurName();
+ auto_ptr_char first(fname ? fname->getName() : NULL);
+ auto_ptr_char last(lname ? lname->getName() : NULL);
+ if (first.get() && last.get()) {
+ string contact=string(first.get()) + ' ' + last.get();
+ e->addProperty("contactName",contact.c_str());
+ }
+ else if (first.get())
+ e->addProperty("contactName",first.get());
+ else if (last.get())
+ e->addProperty("contactName",last.get());
+ const vector<EmailAddress*>& emails=const_cast<const ContactPerson*>(*c)->getEmailAddresss();
+ if (!emails.empty()) {
+ auto_ptr_char email(emails.front()->getAddress());
+ if (email.get())
+ e->addProperty("contactEmail",email.get());
+ }
+ break;
+ }
+ }
+
+ auto_ptr_char eurl(role->getErrorURL());
+ if (eurl.get()) {
+ e->addProperty("errorURL",eurl.get());
+ }
+ }
+
+ if (status) {
+ auto_ptr_char sc(status->getStatusCode() ? status->getStatusCode()->getValue() : NULL);
+ if (sc.get() && *sc.get())
+ e->addProperty("statusCode", sc.get());
+ if (status->getStatusCode()->getStatusCode()) {
+ auto_ptr_char sc2(status->getStatusCode()->getStatusCode()->getValue());
+ if (sc2.get() && *sc.get())
+ e->addProperty("statusCode2", sc2.get());
+ }
+ if (status->getStatusMessage()) {
+ auto_ptr_char msg(status->getStatusMessage()->getMessage());
+ if (msg.get() && *msg.get())
+ e->addProperty("statusMessage", msg.get());
+ }
+ }
+
+ if (rethrow)
+ e->raise();
+}