How do I create a connection with the equivalent of `-starttls smtp` using rust-openssl?










0















When I run the following command in the terminal



openssl s_client -connect gmail-smtp-in.l.google.com:25 -starttls smtp


I get a CONNECTED(00000005) response.



I am trying to achieve the same connection with Rust using rust-openssl (I am open to other libraries though), and here's what I have:



extern crate openssl;

use openssl::ssl::SslConnector, SslMethod;

use std::net::TcpStream;

fn main()
let connector = SslConnector::builder(SslMethod::tls()).unwrap().build();
let stream = TcpStream::connect("gmail-smtp-in.l.google.com:25").unwrap();
let e = connector
.connect("gmail-smtp-in.l.google.com", stream)
.unwrap_err();
eprintln!(":#?", e);



However, the response I get is:



Failure(
MidHandshakeSslStream
stream: SslStream
stream: TcpStream
addr: V6(
[2001:41d0:a:2346::1]:57190
),
peer: V6(
[2a00:1450:400c:c0c::1b]:25
),
fd: 3
,
ssl: Ssl
state: "SSLv3/TLS write client hello",
verify_result: X509VerifyResult
code: 0,
error: "ok"


,
error: Error
code: ErrorCode(
1
),
cause: Some(
Ssl(
ErrorStack(
[
Error
code: 336130315,
library: "SSL routines",
function: "ssl3_get_record",
reason: "wrong version number",
file: "ssl/record/ssl3_record.c",
line: 252

]
)
)
)


)


I'm guessing I'm missing the -starttls smtp part in the Rust code, but can't figure out how to add it.










share|improve this question
























  • I think you should open an issue, they could help you more than us.

    – Stargateur
    Nov 12 '18 at 20:21















0















When I run the following command in the terminal



openssl s_client -connect gmail-smtp-in.l.google.com:25 -starttls smtp


I get a CONNECTED(00000005) response.



I am trying to achieve the same connection with Rust using rust-openssl (I am open to other libraries though), and here's what I have:



extern crate openssl;

use openssl::ssl::SslConnector, SslMethod;

use std::net::TcpStream;

fn main()
let connector = SslConnector::builder(SslMethod::tls()).unwrap().build();
let stream = TcpStream::connect("gmail-smtp-in.l.google.com:25").unwrap();
let e = connector
.connect("gmail-smtp-in.l.google.com", stream)
.unwrap_err();
eprintln!(":#?", e);



However, the response I get is:



Failure(
MidHandshakeSslStream
stream: SslStream
stream: TcpStream
addr: V6(
[2001:41d0:a:2346::1]:57190
),
peer: V6(
[2a00:1450:400c:c0c::1b]:25
),
fd: 3
,
ssl: Ssl
state: "SSLv3/TLS write client hello",
verify_result: X509VerifyResult
code: 0,
error: "ok"


,
error: Error
code: ErrorCode(
1
),
cause: Some(
Ssl(
ErrorStack(
[
Error
code: 336130315,
library: "SSL routines",
function: "ssl3_get_record",
reason: "wrong version number",
file: "ssl/record/ssl3_record.c",
line: 252

]
)
)
)


)


I'm guessing I'm missing the -starttls smtp part in the Rust code, but can't figure out how to add it.










share|improve this question
























  • I think you should open an issue, they could help you more than us.

    – Stargateur
    Nov 12 '18 at 20:21













0












0








0








When I run the following command in the terminal



openssl s_client -connect gmail-smtp-in.l.google.com:25 -starttls smtp


I get a CONNECTED(00000005) response.



I am trying to achieve the same connection with Rust using rust-openssl (I am open to other libraries though), and here's what I have:



extern crate openssl;

use openssl::ssl::SslConnector, SslMethod;

use std::net::TcpStream;

fn main()
let connector = SslConnector::builder(SslMethod::tls()).unwrap().build();
let stream = TcpStream::connect("gmail-smtp-in.l.google.com:25").unwrap();
let e = connector
.connect("gmail-smtp-in.l.google.com", stream)
.unwrap_err();
eprintln!(":#?", e);



However, the response I get is:



Failure(
MidHandshakeSslStream
stream: SslStream
stream: TcpStream
addr: V6(
[2001:41d0:a:2346::1]:57190
),
peer: V6(
[2a00:1450:400c:c0c::1b]:25
),
fd: 3
,
ssl: Ssl
state: "SSLv3/TLS write client hello",
verify_result: X509VerifyResult
code: 0,
error: "ok"


,
error: Error
code: ErrorCode(
1
),
cause: Some(
Ssl(
ErrorStack(
[
Error
code: 336130315,
library: "SSL routines",
function: "ssl3_get_record",
reason: "wrong version number",
file: "ssl/record/ssl3_record.c",
line: 252

]
)
)
)


)


I'm guessing I'm missing the -starttls smtp part in the Rust code, but can't figure out how to add it.










share|improve this question
















When I run the following command in the terminal



openssl s_client -connect gmail-smtp-in.l.google.com:25 -starttls smtp


I get a CONNECTED(00000005) response.



I am trying to achieve the same connection with Rust using rust-openssl (I am open to other libraries though), and here's what I have:



extern crate openssl;

use openssl::ssl::SslConnector, SslMethod;

use std::net::TcpStream;

fn main()
let connector = SslConnector::builder(SslMethod::tls()).unwrap().build();
let stream = TcpStream::connect("gmail-smtp-in.l.google.com:25").unwrap();
let e = connector
.connect("gmail-smtp-in.l.google.com", stream)
.unwrap_err();
eprintln!(":#?", e);



However, the response I get is:



Failure(
MidHandshakeSslStream
stream: SslStream
stream: TcpStream
addr: V6(
[2001:41d0:a:2346::1]:57190
),
peer: V6(
[2a00:1450:400c:c0c::1b]:25
),
fd: 3
,
ssl: Ssl
state: "SSLv3/TLS write client hello",
verify_result: X509VerifyResult
code: 0,
error: "ok"


,
error: Error
code: ErrorCode(
1
),
cause: Some(
Ssl(
ErrorStack(
[
Error
code: 336130315,
library: "SSL routines",
function: "ssl3_get_record",
reason: "wrong version number",
file: "ssl/record/ssl3_record.c",
line: 252

]
)
)
)


)


I'm guessing I'm missing the -starttls smtp part in the Rust code, but can't figure out how to add it.







openssl rust smtp starttls






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 15:25









Shepmaster

151k13292431




151k13292431










asked Nov 12 '18 at 16:42









amaurymartinyamaurymartiny

1,84811744




1,84811744












  • I think you should open an issue, they could help you more than us.

    – Stargateur
    Nov 12 '18 at 20:21

















  • I think you should open an issue, they could help you more than us.

    – Stargateur
    Nov 12 '18 at 20:21
















I think you should open an issue, they could help you more than us.

– Stargateur
Nov 12 '18 at 20:21





I think you should open an issue, they could help you more than us.

– Stargateur
Nov 12 '18 at 20:21












1 Answer
1






active

oldest

votes


















0














Take a more detailed look in the openssl-sources on what -starttls smtp actually does, and replay that in Rust? It will just be a few library calls, but first you need to speak STMP to your server, and then switch to TLS. (Maybe that's already bundled up in the openssl-library in a single call.)






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53266542%2fhow-do-i-create-a-connection-with-the-equivalent-of-starttls-smtp-using-rust%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Take a more detailed look in the openssl-sources on what -starttls smtp actually does, and replay that in Rust? It will just be a few library calls, but first you need to speak STMP to your server, and then switch to TLS. (Maybe that's already bundled up in the openssl-library in a single call.)






    share|improve this answer



























      0














      Take a more detailed look in the openssl-sources on what -starttls smtp actually does, and replay that in Rust? It will just be a few library calls, but first you need to speak STMP to your server, and then switch to TLS. (Maybe that's already bundled up in the openssl-library in a single call.)






      share|improve this answer

























        0












        0








        0







        Take a more detailed look in the openssl-sources on what -starttls smtp actually does, and replay that in Rust? It will just be a few library calls, but first you need to speak STMP to your server, and then switch to TLS. (Maybe that's already bundled up in the openssl-library in a single call.)






        share|improve this answer













        Take a more detailed look in the openssl-sources on what -starttls smtp actually does, and replay that in Rust? It will just be a few library calls, but first you need to speak STMP to your server, and then switch to TLS. (Maybe that's already bundled up in the openssl-library in a single call.)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 16:00









        ShiDoiSiShiDoiSi

        6,2392343




        6,2392343



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53266542%2fhow-do-i-create-a-connection-with-the-equivalent-of-starttls-smtp-using-rust%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kleinkühnau

            Makov (Slowakei)

            Deutsches Schauspielhaus