Differences From Artifact [1500596709]:
- File src/XMPPSCRAMAuth.m — part of check-in [88dd1b11ee] at 2011-09-16 13:11:54 on branch trunk — Fix salt generation code (user: florob@babelmonkeys.de, size: 13650) [annotate] [blame] [check-ins using]
To Artifact [6cfa1bc3c0]:
- File
src/XMPPSCRAMAuth.m
— part of check-in
[0aab2fde67]
at
2011-09-18 19:33:19
on branch trunk
— Fix XMPPAuthenticator to support non-optimized message flow
While RFC6120 allows and encourages sending data with the success
message it is also legal to send the same data as a challenge and
await an empty response. This rework honors that fact. (user: florob@babelmonkeys.de, size: 14068) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
139 140 141 142 143 144 145 | authcid = [new retain]; } else authcid = nil; [old release]; } | | > > > > > > < < > > > > > | > > > > > > > > > > > > < | | | | 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | authcid = [new retain]; } else authcid = nil; [old release]; } - (OFDataArray*)initialMessage { OFDataArray *ret = [OFDataArray dataArrayWithItemSize: 1]; /* New authentication attempt, reset status */ [cNonce release]; cNonce = nil; [GS2Header release]; GS2Header = nil; [serverSignature release]; serverSignature = nil; authenticated = NO; if (authzid) GS2Header = [[OFString alloc] initWithFormat: @"%@,a=%@,", (plusAvailable ? @"p=tls-unique" : @"y"), authzid]; else GS2Header = (plusAvailable ? @"p=tls-unique,," : @"y,,"); cNonce = [[self XMPP_genNonce] retain]; [clientFirstMessageBare release]; clientFirstMessageBare = nil; clientFirstMessageBare = [[OFString alloc] initWithFormat: @"n=%@,r=%@", authcid, cNonce]; [ret addNItems: [GS2Header UTF8StringLength] fromCArray: [GS2Header UTF8String]]; [ret addNItems: [clientFirstMessageBare UTF8StringLength] fromCArray: [clientFirstMessageBare UTF8String]]; return ret; } - (OFDataArray*)continueWithData: (OFDataArray*)data { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFDataArray *ret; if (!serverSignature) ret = [self XMPP_parseServerFirstMessage: data]; else ret = [self XMPP_parseServerFinalMessage: data]; [ret retain]; [pool release]; return [ret autorelease]; } - (OFDataArray*)XMPP_parseServerFirstMessage: (OFDataArray*)data { size_t i; uint8_t *clientKey, *serverKey, *clientSignature; intmax_t iterCount = 0; OFHash *hash; OFDataArray *ret, *authMessage, *tmpArray, *salt = nil, *saltedPassword; OFString *tmpString, *sNonce = nil; OFEnumerator *enumerator; OFString *comp; enum { GOT_SNONCE = 0x01, GOT_SALT = 0x02, GOT_ITERCOUNT = 0x04 } got = 0; hash = [[[hashType alloc] init] autorelease]; ret = [OFDataArray dataArrayWithItemSize: 1]; authMessage = [OFDataArray dataArrayWithItemSize: 1]; OFString *chal = [OFString stringWithUTF8String: [data cArray] length: [data count] * [data itemSize]]; enumerator = [[chal componentsSeparatedByString: @","] objectEnumerator]; while ((comp = [enumerator nextObject]) != nil) { OFString *entry = [comp substringWithRange: of_range(2, [comp length] - 2)]; |
︙ | ︙ | |||
249 250 251 252 253 254 255 256 257 258 259 | // Add r=<nonce> [ret addItem: ","]; [ret addNItems: 2 fromCArray: "r="]; [ret addNItems: [sNonce UTF8StringLength] fromCArray: [sNonce UTF8String]]; tmpArray = [OFDataArray dataArrayWithItemSize: 1]; [tmpArray addNItems: [password UTF8StringLength] fromCArray: [password UTF8String]]; | > > > > < < < < | | | 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | // Add r=<nonce> [ret addItem: ","]; [ret addNItems: 2 fromCArray: "r="]; [ret addNItems: [sNonce UTF8StringLength] fromCArray: [sNonce UTF8String]]; /* * IETF RFC 5802: * SaltedPassword := Hi(Normalize(password), salt, i) */ tmpArray = [OFDataArray dataArrayWithItemSize: 1]; [tmpArray addNItems: [password UTF8StringLength] fromCArray: [password UTF8String]]; saltedPassword = [self XMPP_hiWithData: tmpArray salt: salt iterationCount: iterCount]; /* * IETF RFC 5802: * AuthMessage := client-first-message-bare + "," + * server-first-message + "," + * client-final-message-without-proof */ [authMessage addNItems: [clientFirstMessageBare UTF8StringLength] fromCArray: [clientFirstMessageBare UTF8String]]; [authMessage addItem: ","]; [authMessage addNItems: [data count] * [data itemSize] fromCArray: [data cArray]]; [authMessage addItem: ","]; [authMessage addNItems: [ret count] fromCArray: [ret cArray]]; /* * IETF RFC 5802: * ClientKey := HMAC(SaltedPassword, "Client Key") |
︙ | ︙ | |||
343 344 345 346 347 348 349 | [ret addItem: ","]; [ret addNItems: 2 fromCArray: "p="]; tmpString = [tmpArray stringByBase64Encoding]; [ret addNItems: [tmpString UTF8StringLength] fromCArray: [tmpString UTF8String]]; | | < | < | > | | | > > > > > > | | | | < | > | | 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | [ret addItem: ","]; [ret addNItems: 2 fromCArray: "p="]; tmpString = [tmpArray stringByBase64Encoding]; [ret addNItems: [tmpString UTF8StringLength] fromCArray: [tmpString UTF8String]]; return ret; } - (OFDataArray*)XMPP_parseServerFinalMessage: (OFDataArray*)data { OFString *mess, *value; /* * server-final-message already received, * we were just waiting for the last word from the server */ if (authenticated) return nil; mess = [OFString stringWithUTF8String: [data cArray] length: [data count] * [data itemSize]]; value = [mess substringWithRange: of_range(2, [mess length] - 2)]; if ([mess hasPrefix: @"v="]) { if (![value isEqual: [serverSignature stringByBase64Encoding]]) @throw [XMPPAuthFailedException newWithClass: isa connection: nil reason: @"Received wrong ServerSignature"]; authenticated = YES; } else @throw [XMPPAuthFailedException newWithClass: isa connection: nil reason: value]; return nil; } - (OFString*)XMPP_genNonce { uint8_t buf[64]; size_t i; |
︙ | ︙ |