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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
using System;
using System.IO;
using Org.BouncyCastle.Tls.Crypto;
namespace Org.BouncyCastle.Tls
{
public abstract class DefaultTlsServer
: AbstractTlsServer
{
private static readonly int[] DefaultCipherSuites = new int[]
{
/*
* TLS 1.3
*/
CipherSuite.TLS_AES_256_GCM_SHA384,
CipherSuite.TLS_AES_128_GCM_SHA256,
CipherSuite.TLS_CHACHA20_POLY1305_SHA256,
/*
* pre-TLS 1.3
*/
CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
CipherSuite.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,
CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,
CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
CipherSuite.TLS_DHE_RSA_WITH_AES_256_GCM_SHA384,
CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
CipherSuite.TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA256,
CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA256,
CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA,
CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
// TODO[api] Remove RSA key exchange cipher suites from default list
CipherSuite.TLS_RSA_WITH_AES_256_GCM_SHA384,
CipherSuite.TLS_RSA_WITH_AES_128_GCM_SHA256,
CipherSuite.TLS_RSA_WITH_AES_256_CBC_SHA256,
CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA256,
CipherSuite.TLS_RSA_WITH_AES_256_CBC_SHA,
CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA,
};
public DefaultTlsServer(TlsCrypto crypto)
: base(crypto)
{
}
/// <exception cref="IOException"/>
protected virtual TlsCredentialedSigner GetDsaSignerCredentials()
{
throw new TlsFatalAlert(AlertDescription.internal_error);
}
/// <exception cref="IOException"/>
protected virtual TlsCredentialedSigner GetECDsaSignerCredentials()
{
throw new TlsFatalAlert(AlertDescription.internal_error);
}
/// <exception cref="IOException"/>
protected virtual TlsCredentialedDecryptor GetRsaEncryptionCredentials()
{
throw new TlsFatalAlert(AlertDescription.internal_error);
}
/// <exception cref="IOException"/>
protected virtual TlsCredentialedSigner GetRsaSignerCredentials()
{
throw new TlsFatalAlert(AlertDescription.internal_error);
}
protected override int[] GetSupportedCipherSuites()
{
return TlsUtilities.GetSupportedCipherSuites(Crypto, DefaultCipherSuites);
}
public override TlsCredentials GetCredentials()
{
int keyExchangeAlgorithm = m_context.SecurityParameters.KeyExchangeAlgorithm;
switch (keyExchangeAlgorithm)
{
case KeyExchangeAlgorithm.DHE_DSS:
return GetDsaSignerCredentials();
case KeyExchangeAlgorithm.ECDHE_ECDSA:
return GetECDsaSignerCredentials();
case KeyExchangeAlgorithm.DHE_RSA:
case KeyExchangeAlgorithm.ECDHE_RSA:
return GetRsaSignerCredentials();
case KeyExchangeAlgorithm.RSA:
return GetRsaEncryptionCredentials();
default:
// Note: internal error here; selected a key exchange we don't implement!
throw new TlsFatalAlert(AlertDescription.internal_error);
}
}
}
}
|