Skip to content

Commit 705ef7d

Browse files
committed
Implement tls-unique for postgres-openssl
While it's a bit sketchier than tls-server-end-point, it is supported on the backend with all OpenSSL versions.
1 parent 369f6e0 commit 705ef7d

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

postgres-openssl/src/lib.rs

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

44
use openssl::error::ErrorStack;
5-
use openssl::hash::MessageDigest;
6-
use openssl::nid::Nid;
7-
use openssl::ssl::{ConnectConfiguration, SslConnector, SslMethod, SslStream};
5+
use openssl::ssl::{ConnectConfiguration, SslConnector, SslMethod, SslRef, SslStream};
86
use postgres::tls::{Stream, TlsHandshake, TlsStream};
97
use std::error::Error;
108
use std::fmt;
@@ -87,18 +85,16 @@ impl TlsStream for OpenSslStream {
8785
self.0.get_mut()
8886
}
8987

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-
95-
let md = match signature_algorithms.digest {
96-
Nid::MD5 | Nid::SHA1 => MessageDigest::sha256(),
97-
nid => MessageDigest::from_nid(nid)?,
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
9893
};
9994

100-
let digest = cert.digest(md).ok()?;
101-
102-
Some(digest.to_vec())
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)
10399
}
104100
}

0 commit comments

Comments
 (0)