-
Notifications
You must be signed in to change notification settings - Fork 874
Expand file tree
/
Copy pathTransportSecurityHandler.cs
More file actions
40 lines (31 loc) · 2.07 KB
/
TransportSecurityHandler.cs
File metadata and controls
40 lines (31 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Threading.Tasks;
using Npgsql.Properties;
using Npgsql.Util;
namespace Npgsql.Internal;
class TransportSecurityHandler
{
public virtual bool SupportEncryption => false;
public virtual Func<X509Certificate2Collection?>? RootCertificatesCallback
{
get => throw new NotSupportedException(string.Format(NpgsqlStrings.TransportSecurityDisabled, nameof(NpgsqlSlimDataSourceBuilder.EnableTransportSecurity)));
set => throw new NotSupportedException(string.Format(NpgsqlStrings.TransportSecurityDisabled, nameof(NpgsqlSlimDataSourceBuilder.EnableTransportSecurity)));
}
public virtual Task NegotiateEncryption(bool async, NpgsqlConnector connector, SslMode sslMode, NpgsqlTimeout timeout, CancellationToken cancellationToken)
=> throw new NotSupportedException(string.Format(NpgsqlStrings.TransportSecurityDisabled, nameof(NpgsqlSlimDataSourceBuilder.EnableTransportSecurity)));
public virtual void AuthenticateSASLSha256Plus(NpgsqlConnector connector, ref string mechanism, ref string cbindFlag, ref string cbind,
ref bool successfulBind)
=> throw new NotSupportedException(string.Format(NpgsqlStrings.TransportSecurityDisabled, nameof(NpgsqlSlimDataSourceBuilder.EnableTransportSecurity)));
}
sealed class RealTransportSecurityHandler : TransportSecurityHandler
{
public override bool SupportEncryption => true;
public override Func<X509Certificate2Collection?>? RootCertificatesCallback { get; set; }
public override Task NegotiateEncryption(bool async, NpgsqlConnector connector, SslMode sslMode, NpgsqlTimeout timeout, CancellationToken cancellationToken)
=> connector.NegotiateEncryption(sslMode, timeout, async, cancellationToken);
public override void AuthenticateSASLSha256Plus(NpgsqlConnector connector, ref string mechanism, ref string cbindFlag, ref string cbind,
ref bool successfulBind)
=> connector.AuthenticateSASLSha256Plus(ref mechanism, ref cbindFlag, ref cbind, ref successfulBind);
}