Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* ***** BEGIN LICENSE BLOCK ***** | 1 /* ***** BEGIN LICENSE BLOCK ***** |
| 2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 3 * | 3 * |
| 4 * The contents of this file are subject to the Mozilla Public License Version | 4 * The contents of this file are subject to the Mozilla Public License Version |
| 5 * 1.1 (the "License"); you may not use this file except in compliance with | 5 * 1.1 (the "License"); you may not use this file except in compliance with |
| 6 * the License. You may obtain a copy of the License at | 6 * the License. You may obtain a copy of the License at |
| 7 * http://www.mozilla.org/MPL/ | 7 * http://www.mozilla.org/MPL/ |
| 8 * | 8 * |
| 9 * Software distributed under the License is distributed on an "AS IS" basis, | 9 * Software distributed under the License is distributed on an "AS IS" basis, |
| 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 { | 310 { |
| 311 unsigned int i; | 311 unsigned int i; |
| 312 for (i = 0; i < NUM_SUITEINFOS; i++) { | 312 for (i = 0; i < NUM_SUITEINFOS; i++) { |
| 313 if (suiteInfo[i].cipherSuite == cipherSuite) { | 313 if (suiteInfo[i].cipherSuite == cipherSuite) { |
| 314 return (PRBool)(suiteInfo[i].isExportable); | 314 return (PRBool)(suiteInfo[i].isExportable); |
| 315 } | 315 } |
| 316 } | 316 } |
| 317 return PR_FALSE; | 317 return PR_FALSE; |
| 318 } | 318 } |
| 319 | 319 |
| 320 /* Export keying material according to RFC 5705. | |
| 321 ** fd must correspond to a TLS 1.0 or higher socket, out must | |
| 322 ** be already allocated. | |
| 323 */ | |
| 324 SECStatus | 320 SECStatus |
| 325 SSL_ExportKeyingMaterial(PRFileDesc *fd, | 321 SSL_ExportKeyingMaterial(PRFileDesc *fd, |
| 326 » » » const char *label, | 322 const char *label, unsigned int labelLen, |
| 327 » » » unsigned int labelLen, | 323 PRBool hasContext, |
| 328 » » » const unsigned char *context, | 324 const unsigned char *context, unsigned int contextLen, |
| 329 » » » unsigned int contextLen, | 325 unsigned char *out, unsigned int outLen) |
| 330 » » » unsigned char *out, | |
| 331 » » » unsigned int outLen) | |
| 332 { | 326 { |
| 333 sslSocket *ss; | 327 sslSocket *ss; |
| 334 unsigned char *val = NULL; | 328 unsigned char *val = NULL; |
| 335 unsigned int valLen, i; | 329 unsigned int valLen, i; |
| 336 SECStatus rv = SECFailure; | 330 SECStatus rv = SECFailure; |
| 337 | 331 |
| 338 ss = ssl_FindSocket(fd); | 332 ss = ssl_FindSocket(fd); |
| 339 if (!ss) { | 333 if (!ss) { |
| 340 SSL_DBG(("%d: SSL[%d]: bad socket in ExportKeyingMaterial", | 334 SSL_DBG(("%d: SSL[%d]: bad socket in ExportKeyingMaterial", |
| 341 SSL_GETPID(), fd)); | 335 SSL_GETPID(), fd)); |
| 342 return SECFailure; | 336 return SECFailure; |
| 343 } | 337 } |
| 344 | 338 |
| 345 if (ss->version < SSL_LIBRARY_VERSION_3_1_TLS) { | 339 if (ss->version < SSL_LIBRARY_VERSION_3_1_TLS) { |
| 346 PORT_SetError(SSL_ERROR_UNSUPPORTED_VERSION); | 340 PORT_SetError(SSL_ERROR_UNSUPPORTED_VERSION); |
| 347 return SECFailure; | 341 return SECFailure; |
| 348 } | 342 } |
| 349 | 343 |
| 344 /* construct PRF arguments */ | |
| 350 valLen = SSL3_RANDOM_LENGTH * 2; | 345 valLen = SSL3_RANDOM_LENGTH * 2; |
| 351 if (contextLen > 0) | 346 if (hasContext) { |
| 352 valLen += 2 /* uint16 length */ + contextLen; | 347 valLen += 2 /* uint16 length */ + contextLen; |
| 348 } | |
| 353 val = PORT_Alloc(valLen); | 349 val = PORT_Alloc(valLen); |
| 354 if (val == NULL) | 350 if (!val) { |
| 355 return SECFailure; | 351 return SECFailure; |
| 352 } | |
| 356 i = 0; | 353 i = 0; |
| 357 PORT_Memcpy(val + i, &ss->ssl3.hs.client_random.rand, SSL3_RANDOM_LENGTH); | 354 PORT_Memcpy(val + i, &ss->ssl3.hs.client_random.rand, SSL3_RANDOM_LENGTH); |
| 358 i += SSL3_RANDOM_LENGTH; | 355 i += SSL3_RANDOM_LENGTH; |
| 359 PORT_Memcpy(val + i, &ss->ssl3.hs.server_random.rand, SSL3_RANDOM_LENGTH); | 356 PORT_Memcpy(val + i, &ss->ssl3.hs.server_random.rand, SSL3_RANDOM_LENGTH); |
| 360 i += SSL3_RANDOM_LENGTH; | 357 i += SSL3_RANDOM_LENGTH; |
| 361 if (contextLen > 0) { | 358 if (hasContext) { |
| 362 val[i++] = contextLen >> 8; | 359 val[i++] = contextLen >> 8; |
| 363 val[i++] = contextLen; | 360 val[i++] = contextLen; |
| 364 » PORT_Memcpy(val + i, context, contextLen); | 361 » if (contextLen > 0) { |
|
agl
2012/03/12 15:22:21
(very minor): I think that this if is superfluous,
| |
| 365 » i += contextLen; | 362 » PORT_Memcpy(val + i, context, contextLen); |
| 363 » i += contextLen; | |
| 364 » } | |
| 366 } | 365 } |
| 367 PORT_Assert(i == valLen); | 366 PORT_Assert(i == valLen); |
| 368 | 367 |
| 368 /* Allow TLS keying material to be exported sooner, when the master | |
| 369 * secret is available and we have sent ChangeCipherSpec. | |
| 370 */ | |
| 369 ssl_GetSpecReadLock(ss); | 371 ssl_GetSpecReadLock(ss); |
| 370 if (!ss->ssl3.cwSpec->master_secret && !ss->ssl3.cwSpec->msItem.len) { | 372 if (!ss->ssl3.cwSpec->master_secret && !ss->ssl3.cwSpec->msItem.len) { |
| 371 PORT_SetError(SSL_ERROR_HANDSHAKE_NOT_COMPLETED); | 373 PORT_SetError(SSL_ERROR_HANDSHAKE_NOT_COMPLETED); |
| 372 rv = SECFailure; | 374 rv = SECFailure; |
| 373 } else { | 375 } else { |
| 374 rv = ssl3_TLSPRFWithMasterSecret(ss->ssl3.cwSpec, label, labelLen, val, | 376 rv = ssl3_TLSPRFWithMasterSecret(ss->ssl3.cwSpec, label, labelLen, val, |
| 375 valLen, out, outLen); | 377 valLen, out, outLen); |
| 376 } | 378 } |
| 377 ssl_ReleaseSpecReadLock(ss); | 379 ssl_ReleaseSpecReadLock(ss); |
| 378 | 380 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 412 sniName = PORT_ZNew(SECItem); | 414 sniName = PORT_ZNew(SECItem); |
| 413 if (!sniName) { | 415 if (!sniName) { |
| 414 PORT_Free(name); | 416 PORT_Free(name); |
| 415 return NULL; | 417 return NULL; |
| 416 } | 418 } |
| 417 sniName->data = (void*)name; | 419 sniName->data = (void*)name; |
| 418 sniName->len = PORT_Strlen(name); | 420 sniName->len = PORT_Strlen(name); |
| 419 } | 421 } |
| 420 return sniName; | 422 return sniName; |
| 421 } | 423 } |
| OLD | NEW |