101 lines
19 KiB
HTML
101 lines
19 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="SSL/TLS support."><meta name="keywords" content="rust, rustlang, rust-lang, ssl"><title>openssl::ssl - Rust</title><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../../ayu.css" disabled ><script id="default-settings"></script><script src="../../storage.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../../favicon.svg">
|
||
<link rel="alternate icon" type="image/png" href="../../favicon-16x16.png">
|
||
<link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">☰</div><a href='../../openssl/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><p class="location">Module ssl</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#functions">Functions</a></li></ul></div><p class="location"><a href="../index.html">openssl</a></p><div id="sidebar-vars" data-name="ssl" data-ty="mod" data-relpath="../"></div><script defer src="../sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" class="help-button">?</button>
|
||
<a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Module <a href="../index.html">openssl</a>::<wbr><a class="mod" href="">ssl</a></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span><a class="srclink" href="../../src/openssl/ssl/mod.rs.html#1-4182" title="goto source code">[src]</a></span></h1><div class="docblock"><p>SSL/TLS support.</p>
|
||
<p><code>SslConnector</code> and <code>SslAcceptor</code> should be used in most cases - they handle
|
||
configuration of the OpenSSL primitives for you.</p>
|
||
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
|
||
<p>To connect as a client to a remote server:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">openssl</span>::<span class="ident">ssl</span>::{<span class="ident">SslMethod</span>, <span class="ident">SslConnector</span>};
|
||
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">io</span>::{<span class="ident">Read</span>, <span class="ident">Write</span>};
|
||
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">net</span>::<span class="ident">TcpStream</span>;
|
||
|
||
<span class="kw">let</span> <span class="ident">connector</span> <span class="op">=</span> <span class="ident">SslConnector</span>::<span class="ident">builder</span>(<span class="ident">SslMethod</span>::<span class="ident">tls</span>()).<span class="ident">unwrap</span>().<span class="ident">build</span>();
|
||
|
||
<span class="kw">let</span> <span class="ident">stream</span> <span class="op">=</span> <span class="ident">TcpStream</span>::<span class="ident">connect</span>(<span class="string">"google.com:443"</span>).<span class="ident">unwrap</span>();
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">stream</span> <span class="op">=</span> <span class="ident">connector</span>.<span class="ident">connect</span>(<span class="string">"google.com"</span>, <span class="ident">stream</span>).<span class="ident">unwrap</span>();
|
||
|
||
<span class="ident">stream</span>.<span class="ident">write_all</span>(<span class="string">b"GET / HTTP/1.0\r\n\r\n"</span>).<span class="ident">unwrap</span>();
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">res</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[];
|
||
<span class="ident">stream</span>.<span class="ident">read_to_end</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">res</span>).<span class="ident">unwrap</span>();
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">String</span>::<span class="ident">from_utf8_lossy</span>(<span class="kw-2">&</span><span class="ident">res</span>));</pre></div>
|
||
<p>To accept connections as a server from remote clients:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">openssl</span>::<span class="ident">ssl</span>::{<span class="ident">SslMethod</span>, <span class="ident">SslAcceptor</span>, <span class="ident">SslStream</span>, <span class="ident">SslFiletype</span>};
|
||
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">net</span>::{<span class="ident">TcpListener</span>, <span class="ident">TcpStream</span>};
|
||
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">sync</span>::<span class="ident">Arc</span>;
|
||
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">thread</span>;
|
||
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">acceptor</span> <span class="op">=</span> <span class="ident">SslAcceptor</span>::<span class="ident">mozilla_intermediate</span>(<span class="ident">SslMethod</span>::<span class="ident">tls</span>()).<span class="ident">unwrap</span>();
|
||
<span class="ident">acceptor</span>.<span class="ident">set_private_key_file</span>(<span class="string">"key.pem"</span>, <span class="ident">SslFiletype</span>::<span class="ident">PEM</span>).<span class="ident">unwrap</span>();
|
||
<span class="ident">acceptor</span>.<span class="ident">set_certificate_chain_file</span>(<span class="string">"certs.pem"</span>).<span class="ident">unwrap</span>();
|
||
<span class="ident">acceptor</span>.<span class="ident">check_private_key</span>().<span class="ident">unwrap</span>();
|
||
<span class="kw">let</span> <span class="ident">acceptor</span> <span class="op">=</span> <span class="ident">Arc</span>::<span class="ident">new</span>(<span class="ident">acceptor</span>.<span class="ident">build</span>());
|
||
|
||
<span class="kw">let</span> <span class="ident">listener</span> <span class="op">=</span> <span class="ident">TcpListener</span>::<span class="ident">bind</span>(<span class="string">"0.0.0.0:8443"</span>).<span class="ident">unwrap</span>();
|
||
|
||
<span class="kw">fn</span> <span class="ident">handle_client</span>(<span class="ident">stream</span>: <span class="ident">SslStream</span><span class="op"><</span><span class="ident">TcpStream</span><span class="op">></span>) {
|
||
<span class="comment">// ...</span>
|
||
}
|
||
|
||
<span class="kw">for</span> <span class="ident">stream</span> <span class="kw">in</span> <span class="ident">listener</span>.<span class="ident">incoming</span>() {
|
||
<span class="kw">match</span> <span class="ident">stream</span> {
|
||
<span class="prelude-val">Ok</span>(<span class="ident">stream</span>) <span class="op">=</span><span class="op">></span> {
|
||
<span class="kw">let</span> <span class="ident">acceptor</span> <span class="op">=</span> <span class="ident">acceptor</span>.<span class="ident">clone</span>();
|
||
<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span> <span class="op">|</span><span class="op">|</span> {
|
||
<span class="kw">let</span> <span class="ident">stream</span> <span class="op">=</span> <span class="ident">acceptor</span>.<span class="ident">accept</span>(<span class="ident">stream</span>).<span class="ident">unwrap</span>();
|
||
<span class="ident">handle_client</span>(<span class="ident">stream</span>);
|
||
});
|
||
}
|
||
<span class="prelude-val">Err</span>(<span class="ident">e</span>) <span class="op">=</span><span class="op">></span> { <span class="comment">/* connection failed */</span> }
|
||
}
|
||
}</pre></div>
|
||
</div><h2 id="structs" class="section-header"><a href="#structs">Structs</a></h2>
|
||
<table><tr class="module-item"><td><a class="struct" href="struct.AlpnError.html" title="openssl::ssl::AlpnError struct">AlpnError</a></td><td class="docblock-short"><p>An error returned from an ALPN selection callback.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.CipherBits.html" title="openssl::ssl::CipherBits struct">CipherBits</a></td><td class="docblock-short"><p>Information about the state of a cipher.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.ClientHelloResponse.html" title="openssl::ssl::ClientHelloResponse struct">ClientHelloResponse</a></td><td class="docblock-short"><p>The result of a client hello callback.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.ConnectConfiguration.html" title="openssl::ssl::ConnectConfiguration struct">ConnectConfiguration</a></td><td class="docblock-short"><p>A type which allows for configuration of a client-side TLS session before connection.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.Error.html" title="openssl::ssl::Error struct">Error</a></td><td class="docblock-short"><p>An SSL error.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.ErrorCode.html" title="openssl::ssl::ErrorCode struct">ErrorCode</a></td><td class="docblock-short"><p>An error code returned from SSL functions.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.ExtensionContext.html" title="openssl::ssl::ExtensionContext struct">ExtensionContext</a></td><td class="docblock-short"><p>Which messages and under which conditions an extension should be added or expected.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.MidHandshakeSslStream.html" title="openssl::ssl::MidHandshakeSslStream struct">MidHandshakeSslStream</a></td><td class="docblock-short"><p>An SSL stream midway through the handshake process.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.NameType.html" title="openssl::ssl::NameType struct">NameType</a></td><td class="docblock-short"><p>An identifier of a session name type.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.ShutdownState.html" title="openssl::ssl::ShutdownState struct">ShutdownState</a></td><td class="docblock-short"><p>The shutdown state of a session.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.SniError.html" title="openssl::ssl::SniError struct">SniError</a></td><td class="docblock-short"><p>An error returned from the SNI callback.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.Ssl.html" title="openssl::ssl::Ssl struct">Ssl</a></td><td class="docblock-short"><p>The state of an SSL/TLS session.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.SslAcceptor.html" title="openssl::ssl::SslAcceptor struct">SslAcceptor</a></td><td class="docblock-short"><p>A type which wraps server-side streams in a TLS session.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.SslAcceptorBuilder.html" title="openssl::ssl::SslAcceptorBuilder struct">SslAcceptorBuilder</a></td><td class="docblock-short"><p>A builder for <code>SslAcceptor</code>s.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.SslAlert.html" title="openssl::ssl::SslAlert struct">SslAlert</a></td><td class="docblock-short"><p>An SSL/TLS alert.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.SslCipher.html" title="openssl::ssl::SslCipher struct">SslCipher</a></td><td class="docblock-short"><p>Information about a cipher.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.SslCipherRef.html" title="openssl::ssl::SslCipherRef struct">SslCipherRef</a></td><td class="docblock-short"><p>Reference to an <a href="struct.SslCipher.html"><code>SslCipher</code></a>.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.SslConnector.html" title="openssl::ssl::SslConnector struct">SslConnector</a></td><td class="docblock-short"><p>A type which wraps client-side streams in a TLS session.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.SslConnectorBuilder.html" title="openssl::ssl::SslConnectorBuilder struct">SslConnectorBuilder</a></td><td class="docblock-short"><p>A builder for <code>SslConnector</code>s.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.SslContext.html" title="openssl::ssl::SslContext struct">SslContext</a></td><td class="docblock-short"><p>A context object for TLS streams.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.SslContextBuilder.html" title="openssl::ssl::SslContextBuilder struct">SslContextBuilder</a></td><td class="docblock-short"><p>A builder for <code>SslContext</code>s.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.SslContextRef.html" title="openssl::ssl::SslContextRef struct">SslContextRef</a></td><td class="docblock-short"><p>Reference to <a href="struct.SslContext.html"><code>SslContext</code></a></p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.SslFiletype.html" title="openssl::ssl::SslFiletype struct">SslFiletype</a></td><td class="docblock-short"><p>An identifier of the format of a certificate or key file.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.SslMethod.html" title="openssl::ssl::SslMethod struct">SslMethod</a></td><td class="docblock-short"><p>A type specifying the kind of protocol an <code>SslContext</code> will speak.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.SslMode.html" title="openssl::ssl::SslMode struct">SslMode</a></td><td class="docblock-short"><p>Options controlling the behavior of an <code>SslContext</code>.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.SslOptions.html" title="openssl::ssl::SslOptions struct">SslOptions</a></td><td class="docblock-short"><p>Options controlling the behavior of an <code>SslContext</code>.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.SslRef.html" title="openssl::ssl::SslRef struct">SslRef</a></td><td class="docblock-short"><p>Reference to an <a href="struct.Ssl.html"><code>Ssl</code></a>.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.SslSession.html" title="openssl::ssl::SslSession struct">SslSession</a></td><td class="docblock-short"><p>An encoded SSL session.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.SslSessionCacheMode.html" title="openssl::ssl::SslSessionCacheMode struct">SslSessionCacheMode</a></td><td class="docblock-short"><p>Options controlling the behavior of session caching.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.SslSessionRef.html" title="openssl::ssl::SslSessionRef struct">SslSessionRef</a></td><td class="docblock-short"><p>Reference to <a href="struct.SslSession.html"><code>SslSession</code></a>.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.SslStream.html" title="openssl::ssl::SslStream struct">SslStream</a></td><td class="docblock-short"><p>A TLS session over a stream.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.SslStreamBuilder.html" title="openssl::ssl::SslStreamBuilder struct">SslStreamBuilder</a></td><td class="docblock-short"><span class="stab deprecated" title="">Deprecated</span><p>A partially constructed <code>SslStream</code>, useful for unusual handshakes.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.SslVerifyMode.html" title="openssl::ssl::SslVerifyMode struct">SslVerifyMode</a></td><td class="docblock-short"><p>Options controling the behavior of certificate verification.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.SslVersion.html" title="openssl::ssl::SslVersion struct">SslVersion</a></td><td class="docblock-short"><p>An SSL/TLS protocol version.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.StatusType.html" title="openssl::ssl::StatusType struct">StatusType</a></td><td class="docblock-short"><p>An identifier of a certificate status type.</p>
|
||
</td></tr></table><h2 id="enums" class="section-header"><a href="#enums">Enums</a></h2>
|
||
<table><tr class="module-item"><td><a class="enum" href="enum.HandshakeError.html" title="openssl::ssl::HandshakeError enum">HandshakeError</a></td><td class="docblock-short"><p>An error or intermediate state after a TLS handshake attempt.</p>
|
||
</td></tr><tr class="module-item"><td><a class="enum" href="enum.ShutdownResult.html" title="openssl::ssl::ShutdownResult enum">ShutdownResult</a></td><td class="docblock-short"><p>The result of a shutdown request.</p>
|
||
</td></tr></table><h2 id="functions" class="section-header"><a href="#functions">Functions</a></h2>
|
||
<table><tr class="module-item"><td><a class="fn" href="fn.cipher_name.html" title="openssl::ssl::cipher_name fn">cipher_name</a></td><td class="docblock-short"><p>Returns the OpenSSL name of a cipher corresponding to an RFC-standard cipher name.</p>
|
||
</td></tr><tr class="module-item"><td><a class="fn" href="fn.select_next_proto.html" title="openssl::ssl::select_next_proto fn">select_next_proto</a></td><td class="docblock-short"><p>A standard implementation of protocol selection for Application Layer Protocol Negotiation
|
||
(ALPN).</p>
|
||
</td></tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="openssl"></div>
|
||
<script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html> |