From b55e365e5d09b77202ba8504fa1560adca40a2a3 Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Sun, 18 Nov 2012 17:31:33 +0200 Subject: [PATCH] webticket: request RealmInfo for WsFedBearer Before trying to request a Web Ticket from login.microsoftonline.com we first request the RealmInfo XML data for the user account. --- src/core/sipe-svc.c | 21 +++++++++++++++++++++ src/core/sipe-svc.h | 19 +++++++++++++++++++ src/core/sipe-webticket.c | 42 +++++++++++++++++++++++++++++++++++++----- 3 files changed, 77 insertions(+), 5 deletions(-) diff --git a/src/core/sipe-svc.c b/src/core/sipe-svc.c index 4e5c9946..2370cde7 100644 --- a/src/core/sipe-svc.c +++ b/src/core/sipe-svc.c @@ -525,6 +525,27 @@ static void sipe_svc_metadata_response(struct svc_request *data, } } +gboolean sipe_svc_realminfo(struct sipe_core_private *sipe_private, + struct sipe_svc_session *session, + sipe_svc_callback *callback, + gpointer callback_data) +{ + gchar *realminfo_uri = g_strdup_printf("https://login.microsoftonline.com/getuserrealm.srf?login=%s&xml=1", + sipe_private->username); + gboolean ret = sipe_svc_https_request(sipe_private, + HTTP_CONN_GET, + session, + realminfo_uri, + "text", + NULL, + NULL, + sipe_svc_metadata_response, + callback, + callback_data); + g_free(realminfo_uri); + return(ret); +} + gboolean sipe_svc_metadata(struct sipe_core_private *sipe_private, struct sipe_svc_session *session, const gchar *uri, diff --git a/src/core/sipe-svc.h b/src/core/sipe-svc.h index e1b08ea1..71f41d03 100644 --- a/src/core/sipe-svc.h +++ b/src/core/sipe-svc.h @@ -66,6 +66,7 @@ void sipe_svc_session_close(struct sipe_svc_session *session); * Trigger fetch of Get & Publish certificate * * @param sipe_private SIPE core private data + * @param session opaque session pointer * @param uri service URI * @param wsse_security predefined authentication token * @param certreq certificate request (Base64 encoded) @@ -85,6 +86,7 @@ gboolean sipe_svc_get_and_publish_cert(struct sipe_core_private *sipe_private, * Trigger [MS-DLX] address book entry search * * @param sipe_private SIPE core private data + * @param session opaque session pointer * @param uri service URI * @param wsse_security predefined authentication token * @param search [MS-DLX] AbEntryRequest.ChangeSearchQuery in XML @@ -108,6 +110,7 @@ gboolean sipe_svc_ab_entry_request(struct sipe_core_private *sipe_private, * Trigger fetch of WebTicket security token * * @param sipe_private SIPE core private data + * @param session opaque session pointer * @param uri service URI * @param wsse_security predefined authentication token. May be @c NULL * @param service_uri request token for this service URI @@ -129,6 +132,7 @@ gboolean sipe_svc_webticket(struct sipe_core_private *sipe_private, * Trigger fetch of WebTicket security token from login.microsoftonline.com * * @param sipe_private SIPE core private data + * @param session opaque session pointer * @param service_uri request token for this service URI * @param callback callback function * @param callback_data callback data @@ -141,9 +145,24 @@ gboolean sipe_svc_webticket_lmc(struct sipe_core_private *sipe_private, gpointer callback_data); /** + * Trigger fetch of RealmInfo data from login.microsoftonline.com + * + * @param sipe_private SIPE core private data + * @param session opaque session pointer + * @param callback callback function + * @param callback_data callback data + * @return @c TRUE if data fetch was triggered + */ +gboolean sipe_svc_realminfo(struct sipe_core_private *sipe_private, + struct sipe_svc_session *session, + sipe_svc_callback *callback, + gpointer callback_data); + +/** * Trigger fetch of service metadata * * @param sipe_private SIPE core private data + * @param session opaque session pointer * @param uri service URI * @param callback callback function * @param callback_data callback data diff --git a/src/core/sipe-webticket.c b/src/core/sipe-webticket.c index 4a6032ae..3a038d4f 100644 --- a/src/core/sipe-webticket.c +++ b/src/core/sipe-webticket.c @@ -336,14 +336,46 @@ static void webticket_token(struct sipe_core_private *sipe_private, } } +static void realminfo(struct sipe_core_private *sipe_private, + SIPE_UNUSED_PARAMETER const gchar *uri, + SIPE_UNUSED_PARAMETER const gchar *raw, + sipe_xml *realminfo, + gpointer callback_data) +{ + struct webticket_callback_data *wcd = callback_data; + + if (realminfo) { + SIPE_DEBUG_INFO("realminfo: data for user %s retrieved successfully", + sipe_private->username); + + if (sipe_svc_webticket_lmc(sipe_private, + wcd->session, + wcd->webticket_fedbearer_uri, + webticket_token, + wcd)) { + /* callback data passed down the line */ + wcd = NULL; + } + } + + if (wcd) { + wcd->callback(sipe_private, + wcd->service_uri, + uri ? uri : NULL, + NULL, + NULL, + wcd->callback_data); + callback_data_free(wcd); + } +} + static gboolean initiate_fedbearer(struct sipe_core_private *sipe_private, struct webticket_callback_data *wcd) { - gboolean success = sipe_svc_webticket_lmc(sipe_private, - wcd->session, - wcd->webticket_fedbearer_uri, - webticket_token, - wcd); + gboolean success = sipe_svc_realminfo(sipe_private, + wcd->session, + realminfo, + wcd); wcd->tried_fedbearer = TRUE; wcd->webticket_for_service = FALSE; -- 2.11.4.GIT