Ticket #4452: starttls.patch

File starttls.patch, 2.3 KB (added by ArCePi, 15 years ago)
  • src/add-ons/mail_daemon/outbound_protocols/smtp/smtp.cpp

     
    358358
    359359        #ifdef USE_SSL
    360360        use_ssl = (fSettings->FindInt32("flavor") == 1);
     361        use_STARTTLS = (fSettings->FindInt32("flavor") == 2);
    361362        ssl = NULL;
    362363        ctx = NULL;
    363364    #endif
     
    458459        return B_ERROR;
    459460    }
    460461
     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   
    461511    delete[] cmd;
    462 
     512   
    463513    // Check auth type
    464514    if (esmtp) {
    465515        const char *res = fLog.String();
     
    10551105                                                                B_MAIL_PROTOCOL_HAS_FLAVORS);
    10561106    view->AddFlavor("Unencrypted");
    10571107    view->AddFlavor("SSL");
     1108    view->AddFlavor("STARTTLS");
    10581109    #else
    10591110    BMailProtocolConfigView *view = new BMailProtocolConfigView(B_MAIL_PROTOCOL_HAS_AUTH_METHODS |
    10601111                                                                B_MAIL_PROTOCOL_HAS_USERNAME |
  • src/add-ons/mail_daemon/outbound_protocols/smtp/smtp.h

     
    5151        BIO *sbio;
    5252
    5353        bool use_ssl;
     54        bool use_STARTTLS;
    5455#endif
    5556
    5657        status_t fStatus;