Skip to content

Commit a2cac0e

Browse files
committed
Remove tls-unique from blocking postgres crate
1 parent 39e2723 commit a2cac0e

File tree

4 files changed

+14
-38
lines changed

4 files changed

+14
-38
lines changed

postgres-openssl/src/lib.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ pub extern crate openssl;
22
extern crate postgres;
33

44
use openssl::error::ErrorStack;
5-
use openssl::ssl::{ConnectConfiguration, SslConnector, SslMethod, SslRef, SslStream};
5+
use openssl::hash::MessageDigest;
6+
use openssl::nid::Nid;
7+
use openssl::ssl::{ConnectConfiguration, SslConnector, SslMethod, SslStream};
68
use postgres::tls::{Stream, TlsHandshake, TlsStream};
79
use std::error::Error;
810
use std::fmt;
@@ -85,16 +87,14 @@ impl TlsStream for OpenSslStream {
8587
self.0.get_mut()
8688
}
8789

88-
fn tls_unique(&self) -> Option<Vec<u8>> {
89-
let f = if self.0.ssl().session_reused() {
90-
SslRef::peer_finished
91-
} else {
92-
SslRef::finished
90+
fn tls_server_end_point(&self) -> Option<Vec<u8>> {
91+
let cert = self.0.ssl().peer_certificate()?;
92+
let algo_nid = cert.signature_algorithm().object().nid();
93+
let signature_algorithms = algo_nid.signature_algorithms()?;
94+
let md = match signature_algorithms.digest {
95+
Nid::MD5 | Nid::SHA1 => MessageDigest::sha256(),
96+
nid => MessageDigest::from_nid(nid)?,
9397
};
94-
95-
let len = f(self.0.ssl(), &mut []);
96-
let mut buf = vec![0; len];
97-
f(self.0.ssl(), &mut buf);
98-
Some(buf)
98+
cert.digest(md).ok().map(|b| b.to_vec())
9999
}
100100
}

postgres-protocol/src/authentication/sasl.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ fn hi(str: &[u8], salt: &[u8], i: u32) -> GenericArray<u8, U32> {
5959
enum ChannelBindingInner {
6060
Unrequested,
6161
Unsupported,
62-
TlsUnique(Vec<u8>),
6362
TlsServerEndPoint(Vec<u8>),
6463
}
6564

@@ -77,11 +76,6 @@ impl ChannelBinding {
7776
ChannelBinding(ChannelBindingInner::Unsupported)
7877
}
7978

80-
/// The server requested channel binding and the client will use the `tls-unique` method.
81-
pub fn tls_unique(finished: Vec<u8>) -> ChannelBinding {
82-
ChannelBinding(ChannelBindingInner::TlsUnique(finished))
83-
}
84-
8579
/// The server requested channel binding and the client will use the `tls-server-end-point`
8680
/// method.
8781
pub fn tls_server_end_point(signature: Vec<u8>) -> ChannelBinding {
@@ -92,16 +86,14 @@ impl ChannelBinding {
9286
match self.0 {
9387
ChannelBindingInner::Unrequested => "y,,",
9488
ChannelBindingInner::Unsupported => "n,,",
95-
ChannelBindingInner::TlsUnique(_) => "p=tls-unique,,",
9689
ChannelBindingInner::TlsServerEndPoint(_) => "p=tls-server-end-point,,",
9790
}
9891
}
9992

10093
fn cbind_data(&self) -> &[u8] {
10194
match self.0 {
10295
ChannelBindingInner::Unrequested | ChannelBindingInner::Unsupported => &[],
103-
ChannelBindingInner::TlsUnique(ref buf)
104-
| ChannelBindingInner::TlsServerEndPoint(ref buf) => buf,
96+
ChannelBindingInner::TlsServerEndPoint(ref buf) => buf,
10597
}
10698
}
10799
}

postgres/src/lib.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -435,14 +435,8 @@ impl InnerConnection {
435435
let channel_binding = self
436436
.stream
437437
.get_ref()
438-
.tls_unique()
439-
.map(ChannelBinding::tls_unique)
440-
.or_else(|| {
441-
self.stream
442-
.get_ref()
443-
.tls_server_end_point()
444-
.map(ChannelBinding::tls_server_end_point)
445-
});
438+
.tls_server_end_point()
439+
.map(ChannelBinding::tls_server_end_point);
446440

447441
let (channel_binding, mechanism) = if has_scram_plus {
448442
match channel_binding {

postgres/src/tls.rs

-10
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@ pub trait TlsStream: fmt::Debug + Read + Write + Send {
1313
/// Returns a mutable reference to the underlying `Stream`.
1414
fn get_mut(&mut self) -> &mut Stream;
1515

16-
/// Returns the data associated with the `tls-unique` channel binding type as described in
17-
/// [RFC 5929], if supported.
18-
///
19-
/// An implementation only needs to support one of this or `tls_server_end_point`.
20-
///
21-
/// [RFC 5929]: https://tools.ietf.org/html/rfc5929
22-
fn tls_unique(&self) -> Option<Vec<u8>> {
23-
None
24-
}
25-
2616
/// Returns the data associated with the `tls-server-end-point` channel binding type as
2717
/// described in [RFC 5929], if supported.
2818
///

0 commit comments

Comments
 (0)