|
26 | 26 | import io.r2dbc.postgresql.client.MultiHostConfiguration; |
27 | 27 | import io.r2dbc.postgresql.client.SSLConfig; |
28 | 28 | import io.r2dbc.postgresql.client.SSLMode; |
| 29 | +import io.r2dbc.postgresql.client.SSLNegotiation; |
29 | 30 | import io.r2dbc.postgresql.client.SingleHostConfiguration; |
30 | 31 | import io.r2dbc.postgresql.codec.Codec; |
31 | 32 | import io.r2dbc.postgresql.codec.Codecs; |
@@ -406,6 +407,8 @@ public static final class Builder { |
406 | 407 |
|
407 | 408 | private SSLMode sslMode = SSLMode.DISABLE; |
408 | 409 |
|
| 410 | + private SSLNegotiation sslNegotiation = SSLNegotiation.POSTGRES; |
| 411 | + |
409 | 412 | @Nullable |
410 | 413 | private CharSequence sslPassword = null; |
411 | 414 |
|
@@ -971,6 +974,18 @@ public Builder sslMode(SSLMode sslMode) { |
971 | 974 | return this; |
972 | 975 | } |
973 | 976 |
|
| 977 | + /** |
| 978 | + * Configure ssl negotiation. Useful if the server is known to support SSL directly (e.g. Postgres 17+ or a SSL tunnel). |
| 979 | + * |
| 980 | + * @param sslNegotiation the SSL negotiation mechanism to use. |
| 981 | + * @return this {@link Builder} |
| 982 | + * @since 1.1 |
| 983 | + */ |
| 984 | + public Builder sslNegotiation(SSLNegotiation sslNegotiation) { |
| 985 | + this.sslNegotiation = Assert.requireNonNull(sslNegotiation, "sslNegotiation must be not be null"); |
| 986 | + return this; |
| 987 | + } |
| 988 | + |
974 | 989 | /** |
975 | 990 | * Configure ssl password. |
976 | 991 | * |
@@ -1168,19 +1183,23 @@ private SSLConfig createSslConfig(boolean sslSni) { |
1168 | 1183 | return SSLConfig.disabled(); |
1169 | 1184 | } |
1170 | 1185 |
|
1171 | | - Function<SocketAddress, SSLParameters> sslParametersFunctionToUse = getSslParametersFactory(sslSni, this.sslParametersFactory); |
1172 | | - return new SSLConfig(this.sslMode, createSslProvider(), this.sslEngineCustomizer, sslParametersFunctionToUse, this.sslHostnameVerifier); |
| 1186 | + Function<SocketAddress, SSLParameters> sslParametersFunctionToUse = getSslParametersFactory(sslSni, this.sslNegotiation, this.sslParametersFactory); |
| 1187 | + return new SSLConfig(this.sslNegotiation, this.sslMode, createSslProvider(), this.sslEngineCustomizer, sslParametersFunctionToUse, this.sslHostnameVerifier); |
1173 | 1188 | } |
1174 | 1189 |
|
1175 | | - private static Function<SocketAddress, SSLParameters> getSslParametersFactory(boolean sslSni, Function<SocketAddress, SSLParameters> sslParametersFunction) { |
1176 | | - if (!sslSni) { |
| 1190 | + private static Function<SocketAddress, SSLParameters> getSslParametersFactory(boolean sslSni, SSLNegotiation sslNegotiation, Function<SocketAddress, SSLParameters> sslParametersFunction) { |
| 1191 | + if (!sslSni && sslNegotiation != SSLNegotiation.DIRECT) { |
1177 | 1192 | return sslParametersFunction; |
1178 | 1193 | } |
1179 | 1194 |
|
1180 | 1195 | return socket -> { |
1181 | 1196 |
|
1182 | 1197 | SSLParameters sslParameters = sslParametersFunction.apply(socket); |
1183 | 1198 |
|
| 1199 | + if (sslNegotiation == SSLNegotiation.DIRECT) { |
| 1200 | + sslParameters.setApplicationProtocols(new String[]{"postgresql"}); |
| 1201 | + } |
| 1202 | + |
1184 | 1203 | if (socket instanceof InetSocketAddress) { |
1185 | 1204 |
|
1186 | 1205 | InetSocketAddress inetSocketAddress = (InetSocketAddress) socket; |
|
0 commit comments