Frameworks/libpurple.framework/Versions/0.6.2/Headers/nexus.h
author Zachary West <zacw@adium.im>
Fri Aug 21 13:25:11 2009 -0700 (2009-08-21)
changeset 2592 e8d15275025e
parent 1739 Frameworks/libpurple.framework/Versions/0.6.0/Headers/nexus.h@8b0daad9656c
permissions -rw-r--r--
im.pidgin.adium.1-4 at 267c6165e02e34318a1823960bd04c0639952f73
     1 /**
     2  * @file nexus.h MSN Nexus functions
     3  *
     4  * purple
     5  *
     6  * Purple is the legal property of its developers, whose names are too numerous
     7  * to list here.  Please refer to the COPYRIGHT file distributed with this
     8  * source distribution.
     9  *
    10  * This program is free software; you can redistribute it and/or modify
    11  * it under the terms of the GNU General Public License as published by
    12  * the Free Software Foundation; either version 2 of the License, or
    13  * (at your option) any later version.
    14  *
    15  * This program is distributed in the hope that it will be useful,
    16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    18  * GNU General Public License for more details.
    19  *
    20  * You should have received a copy of the GNU General Public License
    21  * along with this program; if not, write to the Free Software
    22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
    23  */
    24 #ifndef _MSN_NEXUS_H_
    25 #define _MSN_NEXUS_H_
    26 
    27 /* Index into ticket_tokens in nexus.c Keep updated! */
    28 typedef enum
    29 {
    30 	MSN_AUTH_MESSENGER     = 0,
    31 	MSN_AUTH_MESSENGER_WEB = 1,
    32 	MSN_AUTH_CONTACTS      = 2,
    33 	MSN_AUTH_LIVE_SECURE   = 3,
    34 	MSN_AUTH_SPACES        = 4,
    35 	MSN_AUTH_LIVE_CONTACTS = 5,
    36 	MSN_AUTH_STORAGE       = 6
    37 } MsnAuthDomains;
    38 
    39 #define MSN_SSO_SERVER	"login.live.com"
    40 #define SSO_POST_URL	"/RST.srf"
    41 
    42 #define MSN_SSO_RST_TEMPLATE \
    43 "<wst:RequestSecurityToken xmlns=\"http://schemas.xmlsoap.org/ws/2004/04/trust\" Id=\"RST%d\">"\
    44 	"<wst:RequestType>http://schemas.xmlsoap.org/ws/2004/04/security/trust/Issue</wst:RequestType>"\
    45 	"<wsp:AppliesTo xmlns=\"http://schemas.xmlsoap.org/ws/2002/12/policy\">"\
    46 		"<wsa:EndpointReference xmlns=\"http://schemas.xmlsoap.org/ws/2004/03/addressing\">"\
    47 			"<wsa:Address>%s</wsa:Address>"\
    48 		"</wsa:EndpointReference>"\
    49 	"</wsp:AppliesTo>"\
    50 	"<wsse:PolicyReference xmlns=\"http://schemas.xmlsoap.org/ws/2003/06/secext\" URI=\"%s\"></wsse:PolicyReference>"\
    51 "</wst:RequestSecurityToken>"
    52 
    53 #define MSN_SSO_TEMPLATE "<?xml version='1.0' encoding='utf-8'?>"\
    54 "<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\""\
    55 	" xmlns:wsse=\"http://schemas.xmlsoap.org/ws/2003/06/secext\""\
    56 	" xmlns:saml=\"urn:oasis:names:tc:SAML:1.0:assertion\""\
    57 	" xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2002/12/policy\""\
    58 	" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\""\
    59 	" xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/03/addressing\""\
    60 	" xmlns:wssc=\"http://schemas.xmlsoap.org/ws/2004/04/sc\""\
    61 	" xmlns:wst=\"http://schemas.xmlsoap.org/ws/2004/04/trust\">"\
    62 	"<Header>"\
    63 		"<ps:AuthInfo"\
    64 			" xmlns:ps=\"http://schemas.microsoft.com/Passport/SoapServices/PPCRL\""\
    65 			" Id=\"PPAuthInfo\">"\
    66 			"<ps:HostingApp>{7108E71A-9926-4FCB-BCC9-9A9D3F32E423}</ps:HostingApp>"\
    67 			"<ps:BinaryVersion>4</ps:BinaryVersion>"\
    68 			"<ps:UIVersion>1</ps:UIVersion>"\
    69 			"<ps:Cookies></ps:Cookies>"\
    70 			"<ps:RequestParams>AQAAAAIAAABsYwQAAAAxMDMz</ps:RequestParams>"\
    71 		"</ps:AuthInfo>"\
    72 		"<wsse:Security>"\
    73 			"<wsse:UsernameToken Id=\"user\">"\
    74 				"<wsse:Username>%s</wsse:Username>"\
    75 				"<wsse:Password>%s</wsse:Password>"\
    76 			"</wsse:UsernameToken>"\
    77 		"</wsse:Security>"\
    78 	"</Header>"\
    79 	"<Body>"\
    80 		"<ps:RequestMultipleSecurityTokens"\
    81 			" xmlns:ps=\"http://schemas.microsoft.com/Passport/SoapServices/PPCRL\""\
    82 			" Id=\"RSTS\">"\
    83 			"<wst:RequestSecurityToken Id=\"RST0\">"\
    84 				"<wst:RequestType>http://schemas.xmlsoap.org/ws/2004/04/security/trust/Issue</wst:RequestType>"\
    85 				"<wsp:AppliesTo>"\
    86 					"<wsa:EndpointReference>"\
    87 						"<wsa:Address>http://Passport.NET/tb</wsa:Address>"\
    88 					"</wsa:EndpointReference>"\
    89 				"</wsp:AppliesTo>"\
    90 			"</wst:RequestSecurityToken>"\
    91 			"%s"	/* Other RSTn tokens */\
    92 		"</ps:RequestMultipleSecurityTokens>"\
    93 	"</Body>"\
    94 "</Envelope>"
    95 
    96 #define MSN_SSO_AUTHINFO_TEMPLATE \
    97 "<ps:AuthInfo xmlns:ps=\"http://schemas.microsoft.com/Passport/SoapServices/PPCRL\" Id=\"PPAuthInfo\">"\
    98 	"<ps:HostingApp>{7108E71A-9926-4FCB-BCC9-9A9D3F32E423}</ps:HostingApp>"\
    99 	"<ps:BinaryVersion>4</ps:BinaryVersion>"\
   100 	"<ps:UIVersion>1</ps:UIVersion>"\
   101 	"<ps:Cookies></ps:Cookies>"\
   102 	"<ps:RequestParams>AQAAAAIAAABsYwQAAAA0MTA1</ps:RequestParams>"\
   103 "</ps:AuthInfo>"
   104 /* Not sure what's editable here, so I'll just hard-code the SHA1 hash */
   105 #define MSN_SSO_AUTHINFO_SHA1_BASE64 "d2IeTF4DAkPEa/tVETHznsivEpc="
   106 
   107 #define MSN_SSO_TIMESTAMP_TEMPLATE \
   108 "<wsu:Timestamp xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" Id=\"Timestamp\">"\
   109 	"<wsu:Created>%s</wsu:Created>"\
   110 	"<wsu:Expires>%s</wsu:Expires>"\
   111 "</wsu:Timestamp>"
   112 
   113 #define MSN_SSO_SIGNEDINFO_TEMPLATE \
   114 "<SignedInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\">"\
   115 	"<CanonicalizationMethod Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\"></CanonicalizationMethod>"\
   116 	"<SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#hmac-sha1\"></SignatureMethod>"\
   117 	"<Reference URI=\"#RST%d\">"\
   118 		"<Transforms>"\
   119 			"<Transform Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\"></Transform>"\
   120 		"</Transforms>"\
   121 		"<DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"></DigestMethod>"\
   122 		"<DigestValue>%s</DigestValue>"\
   123 	"</Reference>"\
   124 	"<Reference URI=\"#Timestamp\">"\
   125 		"<Transforms>"\
   126 			"<Transform Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\"></Transform>"\
   127 		"</Transforms>"\
   128 		"<DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"></DigestMethod>"\
   129 		"<DigestValue>%s</DigestValue>"\
   130 	"</Reference>"\
   131 	"<Reference URI=\"#PPAuthInfo\">"\
   132 		"<Transforms>"\
   133 			"<Transform Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\"></Transform>"\
   134 		"</Transforms>"\
   135 		"<DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"></DigestMethod>"\
   136 		"<DigestValue>" MSN_SSO_AUTHINFO_SHA1_BASE64 "</DigestValue>"\
   137 	"</Reference>"\
   138 "</SignedInfo>"
   139 
   140 #define MSN_SSO_TOKEN_UPDATE_TEMPLATE "<?xml version=\"1.0\" encoding=\"utf-8\"?>"\
   141 "<Envelope"\
   142 	" xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\""\
   143 	" xmlns:wsse=\"http://schemas.xmlsoap.org/ws/2003/06/secext\""\
   144 	" xmlns:saml=\"urn:oasis:names:tc:SAML:1.0:assertion\""\
   145 	" xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2002/12/policy\""\
   146 	" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\""\
   147 	" xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/03/addressing\""\
   148 	" xmlns:wssc=\"http://schemas.xmlsoap.org/ws/2004/04/sc\""\
   149 	" xmlns:wst=\"http://schemas.xmlsoap.org/ws/2004/04/trust\">"\
   150 	"<Header>"\
   151 		MSN_SSO_AUTHINFO_TEMPLATE /* ps:AuthInfo */ \
   152 		"<wsse:Security>"\
   153 			"<EncryptedData xmlns=\"http://www.w3.org/2001/04/xmlenc#\" Id=\"BinaryDAToken0\" Type=\"http://www.w3.org/2001/04/xmlenc#Element\">"\
   154 				"<EncryptionMethod Algorithm=\"http://www.w3.org/2001/04/xmlenc#tripledes-cbc\"></EncryptionMethod>"\
   155 				"<ds:KeyInfo xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\">"\
   156 					"<ds:KeyName>http://Passport.NET/STS</ds:KeyName>"\
   157 				"</ds:KeyInfo>"\
   158 				"<CipherData>"\
   159 					"<CipherValue>%s</CipherValue>"\
   160 				"</CipherData>"\
   161 			"</EncryptedData>"\
   162 			"<wssc:DerivedKeyToken Id=\"SignKey\">"\
   163 				"<wsse:RequestedTokenReference>"\
   164 					"<wsse:KeyIdentifier ValueType=\"http://docs.oasis-open.org/wss/2004/XX/oasis-2004XX-wss-saml-token-profile-1.0#SAMLAssertionID\" />"\
   165 					"<wsse:Reference URI=\"#BinaryDAToken0\" />"\
   166 				"</wsse:RequestedTokenReference>"\
   167 				"<wssc:Nonce>%s</wssc:Nonce>"\
   168 			"</wssc:DerivedKeyToken>"\
   169 			"%s" /* wsu:Timestamp */\
   170 			"<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\">"\
   171 				"%s" /* SignedInfo */\
   172 				"<SignatureValue>%s</SignatureValue>"\
   173 				"<KeyInfo>"\
   174 					"<wsse:SecurityTokenReference>"\
   175 						"<wsse:Reference URI=\"#SignKey\" />"\
   176 					"</wsse:SecurityTokenReference>"\
   177 				"</KeyInfo>"\
   178 			"</Signature>"\
   179 		"</wsse:Security>"\
   180 	"</Header>"\
   181 	"<Body>"\
   182 		"%s" /* wst:RequestSecurityToken */ \
   183 	"</Body>"\
   184 "</Envelope>"
   185 
   186 typedef struct _MsnUsrKey MsnUsrKey;
   187 struct _MsnUsrKey
   188 {
   189 	int size; /* 28. Does not count data */
   190 	int crypt_mode; /* CRYPT_MODE_CBC (1) */
   191 	int cipher_type; /* TripleDES (0x6603) */
   192 	int hash_type; /* SHA1 (0x8004) */
   193 	int iv_len;    /* 8 */
   194 	int hash_len;  /* 20 */
   195 	int cipher_len; /* 72 */
   196 	/* Data */
   197 	char iv[8];
   198 	char hash[20];
   199 	char cipher[72];
   200 };
   201 
   202 typedef struct _MsnTicketToken MsnTicketToken;
   203 struct _MsnTicketToken {
   204 	GHashTable *token;
   205 	char *secret;
   206 	time_t expiry;
   207 	GSList *updates;
   208 };
   209 
   210 typedef struct _MsnNexus MsnNexus;
   211 
   212 struct _MsnNexus
   213 {
   214 	MsnSession *session;
   215 
   216 	/* From server via USR command */
   217 	char *policy;
   218 	char *nonce;
   219 
   220 	/* From server via SOAP stuff */
   221 	char *cipher;
   222 	char *secret;
   223 	MsnTicketToken *tokens;
   224 	int token_len;
   225 };
   226 
   227 void msn_nexus_connect(MsnNexus *nexus);
   228 MsnNexus *msn_nexus_new(MsnSession *session);
   229 void msn_nexus_destroy(MsnNexus *nexus);
   230 GHashTable *msn_nexus_get_token(MsnNexus *nexus, MsnAuthDomains id);
   231 const char *msn_nexus_get_token_str(MsnNexus *nexus, MsnAuthDomains id);
   232 void msn_nexus_update_token(MsnNexus *nexus, int id, GSourceFunc cb, gpointer data);
   233 #endif /* _MSN_NEXUS_H_ */
   234