Ticket #4452: starttls.patch
File starttls.patch, 2.3 KB (added by , 15 years ago) |
---|
-
src/add-ons/mail_daemon/outbound_protocols/smtp/smtp.cpp
358 358 359 359 #ifdef USE_SSL 360 360 use_ssl = (fSettings->FindInt32("flavor") == 1); 361 use_STARTTLS = (fSettings->FindInt32("flavor") == 2); 361 362 ssl = NULL; 362 363 ctx = NULL; 363 364 #endif … … 458 459 return B_ERROR; 459 460 } 460 461 462 463 464 #ifdef USE_SSL 465 // Check for STARTTLS 466 if(use_STARTTLS) 467 { 468 const char *res = fLog.String(); 469 char *p; 470 471 SSL_library_init(); 472 RAND_seed(this,sizeof(SMTPProtocol)); 473 ::sprintf(cmd, "STARTTLS"CRLF); 474 475 if ((p = ::strstr(res, "STARTTLS")) != NULL) 476 { 477 // Server advertises STARTTLS support 478 if(SendCommand(cmd) != B_OK) 479 { 480 delete[] cmd; 481 return B_ERROR; 482 } 483 484 // We should start TLS negotiation 485 use_ssl = true; 486 ctx = SSL_CTX_new(TLSv1_method()); 487 ssl = SSL_new(ctx); 488 sbio = BIO_new_socket(_fd,BIO_NOCLOSE); 489 BIO_set_nbio(sbio, 0); 490 SSL_set_bio(ssl, sbio, sbio); 491 SSL_set_connect_state(ssl); 492 if(SSL_do_handshake(ssl) != 1) 493 return B_ERROR; 494 495 // Should send EHLO command again 496 if(!esmtp) 497 ::sprintf(cmd, "HELO %s"CRLF, localhost); 498 else 499 ::sprintf(cmd, "EHLO %s"CRLF, localhost); 500 501 if(SendCommand(cmd) != B_OK) 502 { 503 delete[] cmd; 504 return B_ERROR; 505 } 506 } 507 508 } 509 #endif 510 461 511 delete[] cmd; 462 512 463 513 // Check auth type 464 514 if (esmtp) { 465 515 const char *res = fLog.String(); … … 1055 1105 B_MAIL_PROTOCOL_HAS_FLAVORS); 1056 1106 view->AddFlavor("Unencrypted"); 1057 1107 view->AddFlavor("SSL"); 1108 view->AddFlavor("STARTTLS"); 1058 1109 #else 1059 1110 BMailProtocolConfigView *view = new BMailProtocolConfigView(B_MAIL_PROTOCOL_HAS_AUTH_METHODS | 1060 1111 B_MAIL_PROTOCOL_HAS_USERNAME | -
src/add-ons/mail_daemon/outbound_protocols/smtp/smtp.h
51 51 BIO *sbio; 52 52 53 53 bool use_ssl; 54 bool use_STARTTLS; 54 55 #endif 55 56 56 57 status_t fStatus;