Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

OpenSSL upgrading connection to TLS

All I want to do is connect to an SMTP server, talk to it and then request it to perform a handshake mid connection. How would I go about doing that? I believe it has something to do with creating a SSL_BIO and then pushing it onto original connection bio.

Oversimplifed example of what I am trying to do.
EDIT
The code represents what I did to promote the bio to a secure connection.
Code
#include <openssl/bio.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <vector>

int main(){
    
    std::string HelloString = "ehlo 127.0.0.1\r\n";
    std::vector<char> buffer(5000);

    //Connect to gmail SMTP server
    BIO * bio = BIO_new_connect("smtp.gmail.com:587");
    BIO_do_connect(bio);
    
    //Read server hello
    BIO_read(bio, buffer.data(), buffer.size());

    //write client hello
    BIO_write(bio, HelloString.c_str(), HelloString.length());

    //read server ack and commands
    BIO_read(bio, buffer.data(), buffer.size());

    //Tell the server I want to upgrade the connection
    BIO_write(bio, "STARTTLS\r\n", 10);

    //Upgrade the connection some how
    //Edited Version
    SSL_CTX * ctx = SSL_CTX_new(SSLv23_client_method());
    BIO * ssl_bio = BIO_new_ssl(ctx, 1);

    BIO * ssl_chain = BIO_push(ssl_bio, bio);
    BIO_do_handshake(ssl_chain);

    //Completed - Start sending data as TLS


    return 0;
}

Edit
I found the answer to my problem by reading some OpenSSL source code, what you can do is create a SSL_BIO with BIO_NEW_SSL and then append the BIO to the SSL_BIO and then call bio_do_handshake with the SSL_BIO.
C++ Enthusiast

[Image: 14%2B-%2B1]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by evlmonsterSep 5, 2020 02:19 PM 2 197 Sep 5, 2020 02:19 PM
Last Post: Pernat1y
[.NET] by RAF97May 1, 2020 05:18 AM 3 275 May 1, 2020 05:18 AM
Last Post: RAF97
[.NET] by SIM-2362662Mar 20, 2020 06:52 PM 0 120 Mar 20, 2020 06:52 PM
Last Post: SIM-2362662