Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit778611c

Browse files
committed
Merge remote-tracking branch 'origin/master' into fix-rand-0.9-deprecations
2 parents02463b1 +c104b23 commit778611c

File tree

27 files changed

+203
-56
lines changed

27 files changed

+203
-56
lines changed

‎docker-compose.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version:'2'
22
services:
33
postgres:
4-
image:postgres:14
4+
image:docker.io/postgres:17
55
ports:
66
-5433:5433
77
volumes:

‎postgres-native-tls/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ default = ["runtime"]
1616
runtime = ["tokio-postgres/runtime"]
1717

1818
[dependencies]
19-
native-tls ="0.2"
19+
native-tls ={version ="0.2",features = ["alpn"] }
2020
tokio ="1.0"
2121
tokio-native-tls ="0.3"
2222
tokio-postgres = {version ="0.7.11",path ="../tokio-postgres",default-features =false }

‎postgres-native-tls/src/lib.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
//! ```
5454
#![warn(rust_2018_idioms, clippy::all, missing_docs)]
5555

56+
use native_tls::TlsConnectorBuilder;
5657
use std::future::Future;
5758
use std::io;
5859
use std::pin::Pin;
@@ -180,3 +181,10 @@ where
180181
}
181182
}
182183
}
184+
185+
/// Set ALPN for `TlsConnectorBuilder`
186+
///
187+
/// This is required when using `sslnegotiation=direct`
188+
pubfnset_postgresql_alpn(builder:&mutTlsConnectorBuilder){
189+
builder.request_alpns(&["postgresql"]);
190+
}

‎postgres-native-tls/src/test.rs‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use tokio_postgres::tls::TlsConnect;
55

66
#[cfg(feature ="runtime")]
77
usecrate::MakeTlsConnector;
8-
usecrate::TlsConnector;
8+
usecrate::{set_postgresql_alpn,TlsConnector};
99

1010
asyncfnsmoke_test<T>(s:&str,tls:T)
1111
where
@@ -42,6 +42,21 @@ async fn require() {
4242
.await;
4343
}
4444

45+
#[tokio::test]
46+
asyncfndirect(){
47+
letmut builder = native_tls::TlsConnector::builder();
48+
builder.add_root_certificate(
49+
Certificate::from_pem(include_bytes!("../../test/server.crt")).unwrap(),
50+
);
51+
set_postgresql_alpn(&mut builder);
52+
let connector = builder.build().unwrap();
53+
smoke_test(
54+
"user=ssl_user dbname=postgres sslmode=require sslnegotiation=direct",
55+
TlsConnector::new(connector,"localhost"),
56+
)
57+
.await;
58+
}
59+
4560
#[tokio::test]
4661
asyncfnprefer(){
4762
let connector = native_tls::TlsConnector::builder()

‎postgres-openssl/src/lib.rs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ use openssl::hash::MessageDigest;
5353
use openssl::nid::Nid;
5454
#[cfg(feature ="runtime")]
5555
use openssl::ssl::SslConnector;
56-
use openssl::ssl::{self,ConnectConfiguration,SslRef};
56+
use openssl::ssl::{self,ConnectConfiguration,SslConnectorBuilder,SslRef};
5757
use openssl::x509::X509VerifyResult;
5858
use std::error::Error;
5959
use std::fmt::{self,Debug};
@@ -250,3 +250,10 @@ fn tls_server_end_point(ssl: &SslRef) -> Option<Vec<u8>> {
250250
};
251251
cert.digest(md).ok().map(|b| b.to_vec())
252252
}
253+
254+
/// Set ALPN for `SslConnectorBuilder`
255+
///
256+
/// This is required when using `sslnegotiation=direct`
257+
pubfnset_postgresql_alpn(builder:&mutSslConnectorBuilder) ->Result<(),ErrorStack>{
258+
builder.set_alpn_protos(b"\x0apostgresql")
259+
}

‎postgres-openssl/src/test.rs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ async fn require() {
3737
.await;
3838
}
3939

40+
#[tokio::test]
41+
asyncfndirect(){
42+
letmut builder =SslConnector::builder(SslMethod::tls()).unwrap();
43+
builder.set_ca_file("../test/server.crt").unwrap();
44+
set_postgresql_alpn(&mut builder).unwrap();
45+
let ctx = builder.build();
46+
smoke_test(
47+
"user=ssl_user dbname=postgres sslmode=require sslnegotiation=direct",
48+
TlsConnector::new(ctx.configure().unwrap(),"localhost"),
49+
)
50+
.await;
51+
}
52+
4053
#[tokio::test]
4154
asyncfnprefer(){
4255
letmut builder =SslConnector::builder(SslMethod::tls()).unwrap();

‎postgres-protocol/src/message/backend.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ pub struct ColumnFormats<'a> {
475475
remaining:u16,
476476
}
477477

478-
impl<'a>FallibleIteratorforColumnFormats<'a>{
478+
implFallibleIteratorforColumnFormats<'_>{
479479
typeItem =u16;
480480
typeError = io::Error;
481481

@@ -557,7 +557,7 @@ pub struct DataRowRanges<'a> {
557557
remaining:u16,
558558
}
559559

560-
impl<'a>FallibleIteratorforDataRowRanges<'a>{
560+
implFallibleIteratorforDataRowRanges<'_>{
561561
typeItem =Option<Range<usize>>;
562562
typeError = io::Error;
563563

@@ -645,7 +645,7 @@ pub struct ErrorField<'a> {
645645
value:&'a[u8],
646646
}
647647

648-
impl<'a>ErrorField<'a>{
648+
implErrorField<'_>{
649649
#[inline]
650650
pubfntype_(&self) ->u8{
651651
self.type_
@@ -717,7 +717,7 @@ pub struct Parameters<'a> {
717717
remaining:u16,
718718
}
719719

720-
impl<'a>FallibleIteratorforParameters<'a>{
720+
implFallibleIteratorforParameters<'_>{
721721
typeItem =Oid;
722722
typeError = io::Error;
723723

‎postgres-protocol/src/types/mod.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ impl<'a> Array<'a> {
582582
/// An iterator over the dimensions of an array.
583583
pubstructArrayDimensions<'a>(&'a[u8]);
584584

585-
impl<'a>FallibleIteratorforArrayDimensions<'a>{
585+
implFallibleIteratorforArrayDimensions<'_>{
586586
typeItem =ArrayDimension;
587587
typeError =StdBox<dynError +Sync +Send>;
588588

@@ -950,7 +950,7 @@ pub struct PathPoints<'a> {
950950
buf:&'a[u8],
951951
}
952952

953-
impl<'a>FallibleIteratorforPathPoints<'a>{
953+
implFallibleIteratorforPathPoints<'_>{
954954
typeItem =Point;
955955
typeError =StdBox<dynError +Sync +Send>;
956956

‎postgres-types/src/lib.rs‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ pub enum Format {
914914
Binary,
915915
}
916916

917-
impl<'a,T>ToSqlfor&'aT
917+
impl<T>ToSqlfor&T
918918
where
919919
T:ToSql,
920920
{
@@ -963,7 +963,7 @@ impl<T: ToSql> ToSql for Option<T> {
963963
to_sql_checked!();
964964
}
965965

966-
impl<'a,T:ToSql>ToSqlfor&'a[T]{
966+
impl<T:ToSql>ToSqlfor&[T]{
967967
fnto_sql(&self,ty:&Type,w:&mutBytesMut) ->Result<IsNull,Box<dynError +Sync +Send>>{
968968
let member_type =match*ty.kind(){
969969
Kind::Array(ref member) => member,
@@ -1004,7 +1004,7 @@ impl<'a, T: ToSql> ToSql for &'a [T] {
10041004
to_sql_checked!();
10051005
}
10061006

1007-
impl<'a>ToSqlfor&'a[u8]{
1007+
implToSqlfor&[u8]{
10081008
fnto_sql(&self, _:&Type,w:&mutBytesMut) ->Result<IsNull,Box<dynError +Sync +Send>>{
10091009
types::bytea_to_sql(self, w);
10101010
Ok(IsNull::No)
@@ -1064,7 +1064,7 @@ impl<T: ToSql> ToSql for Box<[T]> {
10641064
to_sql_checked!();
10651065
}
10661066

1067-
impl<'a>ToSqlforCow<'a,[u8]>{
1067+
implToSqlforCow<'_,[u8]>{
10681068
fnto_sql(&self,ty:&Type,w:&mutBytesMut) ->Result<IsNull,Box<dynError +Sync +Send>>{
10691069
<&[u8]asToSql>::to_sql(&self.as_ref(), ty, w)
10701070
}
@@ -1088,7 +1088,7 @@ impl ToSql for Vec<u8> {
10881088
to_sql_checked!();
10891089
}
10901090

1091-
impl<'a>ToSqlfor&'astr{
1091+
implToSqlfor&str{
10921092
fnto_sql(&self,ty:&Type,w:&mutBytesMut) ->Result<IsNull,Box<dynError +Sync +Send>>{
10931093
match ty.name(){
10941094
"ltree" => types::ltree_to_sql(self, w),
@@ -1109,7 +1109,7 @@ impl<'a> ToSql for &'a str {
11091109
to_sql_checked!();
11101110
}
11111111

1112-
impl<'a>ToSqlforCow<'a,str>{
1112+
implToSqlforCow<'_,str>{
11131113
fnto_sql(&self,ty:&Type,w:&mutBytesMut) ->Result<IsNull,Box<dynError +Sync +Send>>{
11141114
<&strasToSql>::to_sql(&self.as_ref(), ty, w)
11151115
}
@@ -1256,17 +1256,17 @@ impl BorrowToSql for &dyn ToSql {
12561256
}
12571257
}
12581258

1259-
impl<'a> sealed::SealedforBox<dynToSql +Sync +'a>{}
1259+
impl sealed::SealedforBox<dynToSql +Sync +'_>{}
12601260

1261-
impl<'a>BorrowToSqlforBox<dynToSql +Sync +'a>{
1261+
implBorrowToSqlforBox<dynToSql +Sync +'_>{
12621262
#[inline]
12631263
fnborrow_to_sql(&self) ->&dynToSql{
12641264
self.as_ref()
12651265
}
12661266
}
12671267

1268-
impl<'a> sealed::SealedforBox<dynToSql +Sync +Send +'a>{}
1269-
impl<'a>BorrowToSqlforBox<dynToSql +Sync +Send +'a>{
1268+
impl sealed::SealedforBox<dynToSql +Sync +Send +'_>{}
1269+
implBorrowToSqlforBox<dynToSql +Sync +Send +'_>{
12701270
#[inline]
12711271
fnborrow_to_sql(&self) ->&dynToSql{
12721272
self.as_ref()

‎postgres/src/config.rs‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::time::Duration;
1212
use tokio::runtime;
1313
#[doc(inline)]
1414
pubuse tokio_postgres::config::{
15-
ChannelBinding,Host,LoadBalanceHosts,SslMode,TargetSessionAttrs,
15+
ChannelBinding,Host,LoadBalanceHosts,SslMode,SslNegotiation,TargetSessionAttrs,
1616
};
1717
use tokio_postgres::error::DbError;
1818
use tokio_postgres::tls::{MakeTlsConnect,TlsConnect};
@@ -40,6 +40,9 @@ use tokio_postgres::{Error, Socket};
4040
/// path to the directory containing Unix domain sockets. Otherwise, it is treated as a hostname. Multiple hosts
4141
/// can be specified, separated by commas. Each host will be tried in turn when connecting. Required if connecting
4242
/// with the `connect` method.
43+
/// * `sslnegotiation` - TLS negotiation method. If set to `direct`, the client will perform direct TLS handshake, this only works for PostgreSQL 17 and newer.
44+
/// Note that you will need to setup ALPN of TLS client configuration to `postgresql` when using direct TLS.
45+
/// If set to `postgres`, the default value, it follows original postgres wire protocol to perform the negotiation.
4346
/// * `hostaddr` - Numeric IP address of host to connect to. This should be in the standard IPv4 address format,
4447
/// e.g., 172.28.40.9. If your machine supports IPv6, you can also use those addresses.
4548
/// If this parameter is not specified, the value of `host` will be looked up to find the corresponding IP address,
@@ -230,6 +233,17 @@ impl Config {
230233
self.config.get_ssl_mode()
231234
}
232235

236+
/// Sets the SSL negotiation method
237+
pubfnssl_negotiation(&mutself,ssl_negotiation:SslNegotiation) ->&mutConfig{
238+
self.config.ssl_negotiation(ssl_negotiation);
239+
self
240+
}
241+
242+
/// Gets the SSL negotiation method
243+
pubfnget_ssl_negotiation(&self) ->SslNegotiation{
244+
self.config.get_ssl_negotiation()
245+
}
246+
233247
/// Adds a host to the configuration.
234248
///
235249
/// Multiple hosts can be specified by calling this method multiple times, and each will be tried in order. On Unix

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp