gss_eap_shib_attr_provider::gss_eap_shib_attr_provider(void)
{
+ m_initialized = false;
m_authenticated = false;
}
}
bool
-gss_eap_shib_attr_provider::initFromExistingContext(const gss_eap_attr_ctx *manager,
+gss_eap_shib_attr_provider::initWithExistingContext(const gss_eap_attr_ctx *manager,
const gss_eap_attr_provider *ctx)
{
const gss_eap_shib_attr_provider *shib;
- if (!gss_eap_attr_provider::initFromExistingContext(manager, ctx)) {
+ if (!gss_eap_attr_provider::initWithExistingContext(manager, ctx)) {
return false;
}
m_authenticated = shib->authenticated();
}
+ m_initialized = true;
+
return true;
}
-bool
-addRadiusAttribute(const gss_eap_attr_provider *provider,
- const gss_buffer_t attribute,
- void *data)
+static OM_uint32
+exportMechSecContext(OM_uint32 *minor,
+ gss_ctx_id_t gssCtx,
+ gss_buffer_t mechContext)
{
- const gss_eap_shib_attr_provider *shib;
- const gss_eap_radius_attr_provider *radius;
- int authenticated, complete, more = -1;
- vector <string> attributeIds(1);
- SimpleAttribute *a;
-
- radius = static_cast<const gss_eap_radius_attr_provider *>(provider);
- shib = static_cast<const gss_eap_shib_attr_provider *>(data);
-
- assert(radius != NULL && shib != NULL);
-
- string attributeName =
- gss_eap_attr_ctx::composeAttributeName(ATTR_TYPE_RADIUS, attribute);
-
- attributeIds.push_back(attributeName);
- a = new SimpleAttribute(attributeIds);
- if (a == NULL)
- return false;
-
- while (more != 0) {
- gss_buffer_desc value = GSS_C_EMPTY_BUFFER;
- OM_uint32 minor;
-
- if (!radius->getAttribute(attribute,
- &authenticated,
- &complete,
- &value,
- NULL,
- &more))
- return false;
-
- string attributeValue((char *)value.value, value.length);
- a->getValues().push_back(attributeValue);
-
- gss_release_buffer(&minor, &value);
+ OM_uint32 major;
+ gss_buffer_desc exportedCtx;
+ unsigned char *p;
+
+ assert(gssCtx->mechanismUsed != GSS_C_NO_OID);
+
+ major = gssEapExportSecContext(minor, gssCtx, &exportedCtx);
+ if (GSS_ERROR(major))
+ return major;
+
+ /*
+ * gss_import_sec_context expects the exported security context token
+ * to be tagged with the mechanism OID; in Heimdal and MIT, this is
+ * done by the mechglue, so if we are subverting the mechglue we need
+ * to add it ourselves.
+ */
+ mechContext->length = 4 + gssCtx->mechanismUsed->length + exportedCtx.length;
+ mechContext->value = p = (unsigned char *)GSSEAP_MALLOC(mechContext->length);
+ if (mechContext->value == NULL) {
+ gss_release_buffer(minor, &exportedCtx);
+ throw std::bad_alloc();
}
- shib->getAttributes().push_back(a);
+ p = store_oid(gssCtx->mechanismUsed, p);
+ memcpy(p, exportedCtx.value, exportedCtx.length);
- return true;
+ gss_release_buffer(minor, &exportedCtx);
+
+ return GSS_S_COMPLETE;
}
bool
-gss_eap_shib_attr_provider::initFromGssContext(const gss_eap_attr_ctx *manager,
+gss_eap_shib_attr_provider::initWithGssContext(const gss_eap_attr_ctx *manager,
const gss_cred_id_t gssCred,
const gss_ctx_id_t gssCtx)
{
- const gss_eap_saml_assertion_provider *saml;
- const gss_eap_radius_attr_provider *radius;
- gss_buffer_desc nameBuf = GSS_C_EMPTY_BUFFER;
- ShibbolethResolver *resolver;
- OM_uint32 minor;
-
- if (!gss_eap_attr_provider::initFromGssContext(manager, gssCred, gssCtx))
+ if (!gss_eap_attr_provider::initWithGssContext(manager, gssCred, gssCtx))
return false;
- saml = static_cast<const gss_eap_saml_assertion_provider *>
- (m_manager->getProvider(ATTR_TYPE_SAML_ASSERTION));
- radius = static_cast<const gss_eap_radius_attr_provider *>
- (m_manager->getProvider(ATTR_TYPE_RADIUS));
-
- resolver = ShibbolethResolver::create();
+ auto_ptr<ShibbolethResolver> resolver(ShibbolethResolver::create());
+ /*
+ * For now, leave ApplicationID defaulted.
+ * Later on, we could allow this via config option to the mechanism
+ * or rely on an SPRequest interface to pass in a URI identifying the
+ * acceptor.
+ */
+#if 0
+ gss_buffer_desc nameBuf = GSS_C_EMPTY_BUFFER;
if (gssCred != GSS_C_NO_CREDENTIAL &&
gssEapDisplayName(&minor, gssCred->name, &nameBuf, NULL) == GSS_S_COMPLETE) {
resolver->setApplicationID((const char *)nameBuf.value);
gss_release_buffer(&minor, &nameBuf);
}
+#endif
- m_authenticated = false;
-
- if (radius != NULL) {
- radius->getAttributeTypes(addRadiusAttribute, (void *)this);
- m_authenticated = radius->authenticated();
+ gss_buffer_desc mechContext = GSS_C_EMPTY_BUFFER;
+ OM_uint32 major, minor;
+ major = exportMechSecContext(&minor, gssCtx, &mechContext);
+ if (major == GSS_S_COMPLETE) {
+ resolver->addToken(&mechContext);
+ gss_release_buffer(&minor, &mechContext);
}
+ const gss_eap_saml_assertion_provider *saml;
+ saml = static_cast<const gss_eap_saml_assertion_provider *>
+ (m_manager->getProvider(ATTR_TYPE_SAML_ASSERTION));
if (saml != NULL && saml->getAssertion() != NULL) {
resolver->addToken(saml->getAssertion());
- if (m_authenticated)
- m_authenticated = saml->authenticated();
}
try {
m_attributes = resolver->getResolvedAttributes();
resolver->getResolvedAttributes().clear();
} catch (exception &e) {
-#if 0
- delete resolver;
- throw e;
-#endif
+ return false;
}
- delete resolver;
+ m_authenticated = true;
+ m_initialized = true;
+
return true;
}
{
int i = 0;
+ assert(m_initialized);
+
for (vector<Attribute *>::const_iterator a = m_attributes.begin();
a != m_attributes.end();
++a)
vector <string> ids(1, attrStr);
SimpleAttribute *a = new SimpleAttribute(ids);
+ assert(m_initialized);
+
if (value->length != 0) {
string valueStr((char *)value->value, value->length);
{
int i;
+ assert(m_initialized);
+
i = getAttributeIndex(attr);
if (i >= 0)
m_attributes.erase(m_attributes.begin() + i);
gss_eap_shib_attr_provider::getAttributeTypes(gss_eap_attr_enumeration_cb addAttribute,
void *data) const
{
+ assert(m_initialized);
+
for (vector<Attribute*>::const_iterator a = m_attributes.begin();
a != m_attributes.end();
++a)
attribute.value = (void *)((*a)->getId());
attribute.length = strlen((char *)attribute.value);
- if (!addAttribute(this, &attribute, data))
+ if (!addAttribute(m_manager, this, &attribute, data))
return false;
}
{
const Attribute *ret = NULL;
+ assert(m_initialized);
+
for (vector<Attribute *>::const_iterator a = m_attributes.begin();
a != m_attributes.end();
++a)
gss_buffer_desc buf;
int nvalues, i = *more;
+ assert(m_initialized);
+
*more = 0;
shibAttr = getAttribute(attr);
if (i == -1)
i = 0;
- else if (i >= nvalues)
+ if (i >= nvalues)
return false;
- buf.value = (void *)shibAttr->getString(*more);
+ buf.value = (void *)shibAttr->getSerializedValues()[*more].c_str();
buf.length = strlen((char *)buf.value);
if (buf.length != 0) {
{
gss_any_t output;
+ assert(m_initialized);
+
if (authenticated && !m_authenticated)
return (gss_any_t)NULL;
gss_eap_shib_attr_provider::releaseAnyNameMapping(gss_buffer_t type_id GSSEAP_UNUSED,
gss_any_t input) const
{
+ assert(m_initialized);
+
vector <Attribute *> *v = ((vector <Attribute *> *)input);
delete v;
}
-void
-gss_eap_shib_attr_provider::exportToBuffer(gss_buffer_t buffer) const
+const char *
+gss_eap_shib_attr_provider::prefix(void) const
{
- DDF obj(NULL);
- DDF attrs(NULL);
+ return NULL;
+}
- buffer->length = 0;
- buffer->value = NULL;
+const char *
+gss_eap_shib_attr_provider::name(void) const
+{
+ return "local";
+}
+
+JSONObject
+gss_eap_shib_attr_provider::jsonRepresentation(void) const
+{
+ JSONObject obj;
- obj.addmember("version").integer(1);
- obj.addmember("authenticated").integer(m_authenticated);
+ if (m_initialized == false)
+ return obj; /* don't export incomplete context */
+
+ JSONObject jattrs = JSONObject::array();
- attrs = obj.addmember("attributes").list();
for (vector<Attribute*>::const_iterator a = m_attributes.begin();
a != m_attributes.end(); ++a) {
DDF attr = (*a)->marshall();
- attrs.add(attr);
+ JSONObject jattr = JSONObject::ddf(attr);
+ jattrs.append(jattr);
}
- ostringstream sink;
- sink << attrs;
- string str = sink.str();
+ obj.set("attributes", jattrs);
- duplicateBuffer(str, buffer);
+ obj.set("authenticated", m_authenticated);
- attrs.destroy();
+ return obj;
}
bool
-gss_eap_shib_attr_provider::initFromBuffer(const gss_eap_attr_ctx *ctx,
- const gss_buffer_t buffer)
+gss_eap_shib_attr_provider::initWithJsonObject(const gss_eap_attr_ctx *ctx,
+ JSONObject &obj)
{
- if (!gss_eap_attr_provider::initFromBuffer(ctx, buffer))
+ if (!gss_eap_attr_provider::initWithJsonObject(ctx, obj))
return false;
- if (buffer->length == 0)
- return true;
-
assert(m_authenticated == false);
assert(m_attributes.size() == 0);
- DDF obj(NULL);
- string str((const char *)buffer->value, buffer->length);
- istringstream source(str);
-
- source >> obj;
+ JSONObject jattrs = obj["attributes"];
+ size_t nelems = jattrs.size();
- if (obj["version"].integer() != 1)
- return false;
-
- m_authenticated = (obj["authenticated"].integer() != 0);
+ for (size_t i = 0; i < nelems; i++) {
+ JSONObject jattr = jattrs.get(i);
- DDF attrs = obj["attributes"];
- DDF attr = attrs.first();
- while (!attr.isnull()) {
+ DDF attr = jattr.ddf();
Attribute *attribute = Attribute::unmarshall(attr);
m_attributes.push_back(attribute);
- attr = attrs.next();
}
- attrs.destroy();
+ m_authenticated = obj["authenticated"].integer();
+ m_initialized = true;
return true;
}
bool
gss_eap_shib_attr_provider::init(void)
{
- if (!ShibbolethResolver::init())
+ if (SPConfig::getConfig().getFeatures() == 0 &&
+ ShibbolethResolver::init() == false)
return false;
- gss_eap_attr_ctx::registerProvider(ATTR_TYPE_LOCAL, NULL, createAttrContext);
+ gss_eap_attr_ctx::registerProvider(ATTR_TYPE_LOCAL, createAttrContext);
return true;
}
else
return GSS_S_CONTINUE_NEEDED;
+ gssEapSaveStatusInfo(*minor, "%s", e.what());
+
return GSS_S_FAILURE;
}