AbstractTlsServer.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto;
  7. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  8. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls
  9. {
  10. /// <summary>Base class for a TLS server.</summary>
  11. public abstract class AbstractTlsServer
  12. : AbstractTlsPeer, TlsServer
  13. {
  14. protected TlsServerContext m_context;
  15. protected ProtocolVersion[] m_protocolVersions;
  16. protected int[] m_cipherSuites;
  17. protected int[] m_offeredCipherSuites;
  18. protected IDictionary<int, byte[]> m_clientExtensions;
  19. protected bool m_encryptThenMACOffered;
  20. protected short m_maxFragmentLengthOffered;
  21. protected bool m_truncatedHMacOffered;
  22. protected bool m_clientSentECPointFormats;
  23. protected CertificateStatusRequest m_certificateStatusRequest;
  24. protected IList<CertificateStatusRequestItemV2> m_statusRequestV2;
  25. protected IList<TrustedAuthority> m_trustedCAKeys;
  26. protected int m_selectedCipherSuite;
  27. protected IList<ProtocolName> m_clientProtocolNames;
  28. protected ProtocolName m_selectedProtocolName;
  29. protected readonly IDictionary<int, byte[]> m_serverExtensions = new Dictionary<int, byte[]>();
  30. public AbstractTlsServer(TlsCrypto crypto)
  31. : base(crypto)
  32. {
  33. }
  34. protected virtual bool AllowCertificateStatus()
  35. {
  36. return true;
  37. }
  38. protected virtual bool AllowEncryptThenMac()
  39. {
  40. return true;
  41. }
  42. protected virtual bool AllowMultiCertStatus()
  43. {
  44. return false;
  45. }
  46. protected virtual bool AllowTruncatedHmac()
  47. {
  48. return false;
  49. }
  50. protected virtual bool AllowTrustedCAIndication()
  51. {
  52. return false;
  53. }
  54. protected virtual int GetMaximumNegotiableCurveBits()
  55. {
  56. int[] clientSupportedGroups = m_context.SecurityParameters.ClientSupportedGroups;
  57. if (clientSupportedGroups == null)
  58. {
  59. /*
  60. * RFC 4492 4. A client that proposes ECC cipher suites may choose not to include these
  61. * extensions. In this case, the server is free to choose any one of the elliptic curves
  62. * or point formats [...].
  63. */
  64. return NamedGroup.GetMaximumCurveBits();
  65. }
  66. int maxBits = 0;
  67. for (int i = 0; i < clientSupportedGroups.Length; ++i)
  68. {
  69. maxBits = System.Math.Max(maxBits, NamedGroup.GetCurveBits(clientSupportedGroups[i]));
  70. }
  71. return maxBits;
  72. }
  73. protected virtual int GetMaximumNegotiableFiniteFieldBits()
  74. {
  75. int[] clientSupportedGroups = m_context.SecurityParameters.ClientSupportedGroups;
  76. if (clientSupportedGroups == null)
  77. {
  78. return NamedGroup.GetMaximumFiniteFieldBits();
  79. }
  80. int maxBits = 0;
  81. for (int i = 0; i < clientSupportedGroups.Length; ++i)
  82. {
  83. maxBits = System.Math.Max(maxBits, NamedGroup.GetFiniteFieldBits(clientSupportedGroups[i]));
  84. }
  85. return maxBits;
  86. }
  87. protected virtual IList<ProtocolName> GetProtocolNames()
  88. {
  89. return null;
  90. }
  91. protected virtual bool IsSelectableCipherSuite(int cipherSuite, int availCurveBits, int availFiniteFieldBits,
  92. IList<short> sigAlgs)
  93. {
  94. // TODO[tls13] The version check should be separated out (eventually select ciphersuite before version)
  95. return TlsUtilities.IsValidVersionForCipherSuite(cipherSuite, m_context.ServerVersion)
  96. && availCurveBits >= TlsEccUtilities.GetMinimumCurveBits(cipherSuite)
  97. && availFiniteFieldBits >= TlsDHUtilities.GetMinimumFiniteFieldBits(cipherSuite)
  98. && TlsUtilities.IsValidCipherSuiteForSignatureAlgorithms(cipherSuite, sigAlgs);
  99. }
  100. protected virtual bool PreferLocalCipherSuites()
  101. {
  102. return false;
  103. }
  104. /// <exception cref="IOException"/>
  105. protected virtual bool SelectCipherSuite(int cipherSuite)
  106. {
  107. this.m_selectedCipherSuite = cipherSuite;
  108. return true;
  109. }
  110. protected virtual int SelectDH(int minimumFiniteFieldBits)
  111. {
  112. int[] clientSupportedGroups = m_context.SecurityParameters.ClientSupportedGroups;
  113. if (clientSupportedGroups == null)
  114. return SelectDHDefault(minimumFiniteFieldBits);
  115. // Try to find a supported named group of the required size from the client's list.
  116. for (int i = 0; i < clientSupportedGroups.Length; ++i)
  117. {
  118. int namedGroup = clientSupportedGroups[i];
  119. if (NamedGroup.GetFiniteFieldBits(namedGroup) >= minimumFiniteFieldBits)
  120. return namedGroup;
  121. }
  122. return -1;
  123. }
  124. protected virtual int SelectDHDefault(int minimumFiniteFieldBits)
  125. {
  126. return minimumFiniteFieldBits <= 2048 ? NamedGroup.ffdhe2048
  127. : minimumFiniteFieldBits <= 3072 ? NamedGroup.ffdhe3072
  128. : minimumFiniteFieldBits <= 4096 ? NamedGroup.ffdhe4096
  129. : minimumFiniteFieldBits <= 6144 ? NamedGroup.ffdhe6144
  130. : minimumFiniteFieldBits <= 8192 ? NamedGroup.ffdhe8192
  131. : -1;
  132. }
  133. protected virtual int SelectECDH(int minimumCurveBits)
  134. {
  135. int[] clientSupportedGroups = m_context.SecurityParameters.ClientSupportedGroups;
  136. if (clientSupportedGroups == null)
  137. return SelectECDHDefault(minimumCurveBits);
  138. // Try to find a supported named group of the required size from the client's list.
  139. for (int i = 0; i < clientSupportedGroups.Length; ++i)
  140. {
  141. int namedGroup = clientSupportedGroups[i];
  142. if (NamedGroup.GetCurveBits(namedGroup) >= minimumCurveBits)
  143. return namedGroup;
  144. }
  145. return -1;
  146. }
  147. protected virtual int SelectECDHDefault(int minimumCurveBits)
  148. {
  149. return minimumCurveBits <= 256 ? NamedGroup.secp256r1
  150. : minimumCurveBits <= 384 ? NamedGroup.secp384r1
  151. : minimumCurveBits <= 521 ? NamedGroup.secp521r1
  152. : -1;
  153. }
  154. protected virtual ProtocolName SelectProtocolName()
  155. {
  156. IList<ProtocolName> serverProtocolNames = GetProtocolNames();
  157. if (null == serverProtocolNames || serverProtocolNames.Count < 1)
  158. return null;
  159. ProtocolName result = SelectProtocolName(m_clientProtocolNames, serverProtocolNames);
  160. if (null == result)
  161. throw new TlsFatalAlert(AlertDescription.no_application_protocol);
  162. return result;
  163. }
  164. protected virtual ProtocolName SelectProtocolName(IList<ProtocolName> clientProtocolNames,
  165. IList<ProtocolName> serverProtocolNames)
  166. {
  167. foreach (ProtocolName serverProtocolName in serverProtocolNames)
  168. {
  169. if (clientProtocolNames.Contains(serverProtocolName))
  170. return serverProtocolName;
  171. }
  172. return null;
  173. }
  174. protected virtual bool ShouldSelectProtocolNameEarly()
  175. {
  176. return true;
  177. }
  178. protected virtual bool PreferLocalClientCertificateTypes()
  179. {
  180. return false;
  181. }
  182. protected virtual short[] GetAllowedClientCertificateTypes()
  183. {
  184. return null;
  185. }
  186. public virtual void Init(TlsServerContext context)
  187. {
  188. this.m_context = context;
  189. this.m_protocolVersions = GetSupportedVersions();
  190. this.m_cipherSuites = GetSupportedCipherSuites();
  191. }
  192. public override ProtocolVersion[] GetProtocolVersions()
  193. {
  194. return m_protocolVersions;
  195. }
  196. public override int[] GetCipherSuites()
  197. {
  198. return m_cipherSuites;
  199. }
  200. public override void NotifyHandshakeBeginning()
  201. {
  202. base.NotifyHandshakeBeginning();
  203. this.m_offeredCipherSuites = null;
  204. this.m_clientExtensions = null;
  205. this.m_encryptThenMACOffered = false;
  206. this.m_maxFragmentLengthOffered = 0;
  207. this.m_truncatedHMacOffered = false;
  208. this.m_clientSentECPointFormats = false;
  209. this.m_certificateStatusRequest = null;
  210. this.m_selectedCipherSuite = -1;
  211. this.m_selectedProtocolName = null;
  212. this.m_serverExtensions.Clear();
  213. }
  214. public virtual TlsSession GetSessionToResume(byte[] sessionID)
  215. {
  216. return null;
  217. }
  218. public virtual byte[] GetNewSessionID()
  219. {
  220. return null;
  221. }
  222. public virtual TlsPskExternal GetExternalPsk(IList<PskIdentity> identities)
  223. {
  224. return null;
  225. }
  226. public virtual void NotifySession(TlsSession session)
  227. {
  228. }
  229. public virtual void NotifyClientVersion(ProtocolVersion clientVersion)
  230. {
  231. }
  232. public virtual void NotifyFallback(bool isFallback)
  233. {
  234. /*
  235. * RFC 7507 3. If TLS_FALLBACK_SCSV appears in ClientHello.cipher_suites and the highest
  236. * protocol version supported by the server is higher than the version indicated in
  237. * ClientHello.client_version, the server MUST respond with a fatal inappropriate_fallback
  238. * alert [..].
  239. */
  240. if (isFallback)
  241. {
  242. ProtocolVersion[] serverVersions = GetProtocolVersions();
  243. ProtocolVersion clientVersion = m_context.ClientVersion;
  244. ProtocolVersion latestServerVersion;
  245. if (clientVersion.IsTls)
  246. {
  247. latestServerVersion = ProtocolVersion.GetLatestTls(serverVersions);
  248. }
  249. else if (clientVersion.IsDtls)
  250. {
  251. latestServerVersion = ProtocolVersion.GetLatestDtls(serverVersions);
  252. }
  253. else
  254. {
  255. throw new TlsFatalAlert(AlertDescription.internal_error);
  256. }
  257. if (null != latestServerVersion && latestServerVersion.IsLaterVersionOf(clientVersion))
  258. {
  259. throw new TlsFatalAlert(AlertDescription.inappropriate_fallback);
  260. }
  261. }
  262. }
  263. public virtual void NotifyOfferedCipherSuites(int[] offeredCipherSuites)
  264. {
  265. this.m_offeredCipherSuites = offeredCipherSuites;
  266. }
  267. public virtual void ProcessClientExtensions(IDictionary<int, byte[]> clientExtensions)
  268. {
  269. this.m_clientExtensions = clientExtensions;
  270. if (null != clientExtensions)
  271. {
  272. this.m_clientProtocolNames = TlsExtensionsUtilities.GetAlpnExtensionClient(clientExtensions);
  273. if (ShouldSelectProtocolNameEarly())
  274. {
  275. if (null != m_clientProtocolNames && m_clientProtocolNames.Count > 0)
  276. {
  277. this.m_selectedProtocolName = SelectProtocolName();
  278. }
  279. }
  280. // TODO[tls13] Don't need these if we have negotiated (D)TLS 1.3+
  281. {
  282. this.m_encryptThenMACOffered = TlsExtensionsUtilities.HasEncryptThenMacExtension(clientExtensions);
  283. this.m_truncatedHMacOffered = TlsExtensionsUtilities.HasTruncatedHmacExtension(clientExtensions);
  284. this.m_statusRequestV2 = TlsExtensionsUtilities.GetStatusRequestV2Extension(clientExtensions);
  285. this.m_trustedCAKeys = TlsExtensionsUtilities.GetTrustedCAKeysExtensionClient(clientExtensions);
  286. // We only support uncompressed format, this is just to validate the extension, and note its presence.
  287. this.m_clientSentECPointFormats =
  288. null != TlsExtensionsUtilities.GetSupportedPointFormatsExtension(clientExtensions);
  289. }
  290. this.m_certificateStatusRequest = TlsExtensionsUtilities.GetStatusRequestExtension(clientExtensions);
  291. this.m_maxFragmentLengthOffered = TlsExtensionsUtilities.GetMaxFragmentLengthExtension(clientExtensions);
  292. if (m_maxFragmentLengthOffered >= 0 && !MaxFragmentLength.IsValid(m_maxFragmentLengthOffered))
  293. throw new TlsFatalAlert(AlertDescription.illegal_parameter);
  294. }
  295. }
  296. public virtual ProtocolVersion GetServerVersion()
  297. {
  298. ProtocolVersion[] serverVersions = GetProtocolVersions();
  299. ProtocolVersion[] clientVersions = m_context.ClientSupportedVersions;
  300. foreach (ProtocolVersion clientVersion in clientVersions)
  301. {
  302. if (ProtocolVersion.Contains(serverVersions, clientVersion))
  303. return clientVersion;
  304. }
  305. throw new TlsFatalAlert(AlertDescription.protocol_version);
  306. }
  307. public virtual int[] GetSupportedGroups()
  308. {
  309. // TODO[tls13] The rest of this class assumes all named groups are supported
  310. return new int[]{ NamedGroup.x25519, NamedGroup.x448, NamedGroup.secp256r1, NamedGroup.secp384r1,
  311. NamedGroup.ffdhe2048, NamedGroup.ffdhe3072, NamedGroup.ffdhe4096 };
  312. }
  313. public virtual int GetSelectedCipherSuite()
  314. {
  315. SecurityParameters securityParameters = m_context.SecurityParameters;
  316. ProtocolVersion negotiatedVersion = securityParameters.NegotiatedVersion;
  317. if (TlsUtilities.IsTlsV13(negotiatedVersion))
  318. {
  319. int commonCipherSuite13 = TlsUtilities.GetCommonCipherSuite13(negotiatedVersion, m_offeredCipherSuites,
  320. GetCipherSuites(), PreferLocalCipherSuites());
  321. if (commonCipherSuite13 >= 0 && SelectCipherSuite(commonCipherSuite13))
  322. {
  323. return commonCipherSuite13;
  324. }
  325. }
  326. else
  327. {
  328. /*
  329. * RFC 5246 7.4.3. In order to negotiate correctly, the server MUST check any candidate
  330. * cipher suites against the "signature_algorithms" extension before selecting them. This is
  331. * somewhat inelegant but is a compromise designed to minimize changes to the original
  332. * cipher suite design.
  333. */
  334. var sigAlgs = TlsUtilities.GetUsableSignatureAlgorithms(securityParameters.ClientSigAlgs);
  335. /*
  336. * RFC 4429 5.1. A server that receives a ClientHello containing one or both of these
  337. * extensions MUST use the client's enumerated capabilities to guide its selection of an
  338. * appropriate cipher suite. One of the proposed ECC cipher suites must be negotiated only
  339. * if the server can successfully complete the handshake while using the curves and point
  340. * formats supported by the client [...].
  341. */
  342. int availCurveBits = GetMaximumNegotiableCurveBits();
  343. int availFiniteFieldBits = GetMaximumNegotiableFiniteFieldBits();
  344. int[] cipherSuites = TlsUtilities.GetCommonCipherSuites(m_offeredCipherSuites, GetCipherSuites(),
  345. PreferLocalCipherSuites());
  346. for (int i = 0; i < cipherSuites.Length; ++i)
  347. {
  348. int cipherSuite = cipherSuites[i];
  349. if (IsSelectableCipherSuite(cipherSuite, availCurveBits, availFiniteFieldBits, sigAlgs)
  350. && SelectCipherSuite(cipherSuite))
  351. {
  352. return cipherSuite;
  353. }
  354. }
  355. }
  356. throw new TlsFatalAlert(AlertDescription.handshake_failure, "No selectable cipher suite");
  357. }
  358. // IDictionary is (Int32 -> byte[])
  359. public virtual IDictionary<int, byte[]> GetServerExtensions()
  360. {
  361. bool isTlsV13 = TlsUtilities.IsTlsV13(m_context);
  362. if (isTlsV13)
  363. {
  364. if (null != m_certificateStatusRequest && AllowCertificateStatus())
  365. {
  366. /*
  367. * TODO[tls13] RFC 8446 4.4.2.1. OCSP Status and SCT Extensions.
  368. *
  369. * OCSP information is carried in an extension for a CertificateEntry.
  370. */
  371. }
  372. }
  373. else
  374. {
  375. if (m_encryptThenMACOffered && AllowEncryptThenMac())
  376. {
  377. /*
  378. * RFC 7366 3. If a server receives an encrypt-then-MAC request extension from a client
  379. * and then selects a stream or Authenticated Encryption with Associated Data (AEAD)
  380. * ciphersuite, it MUST NOT send an encrypt-then-MAC response extension back to the
  381. * client.
  382. */
  383. if (TlsUtilities.IsBlockCipherSuite(m_selectedCipherSuite))
  384. {
  385. TlsExtensionsUtilities.AddEncryptThenMacExtension(m_serverExtensions);
  386. }
  387. }
  388. if (m_truncatedHMacOffered && AllowTruncatedHmac())
  389. {
  390. TlsExtensionsUtilities.AddTruncatedHmacExtension(m_serverExtensions);
  391. }
  392. if (m_clientSentECPointFormats && TlsEccUtilities.IsEccCipherSuite(m_selectedCipherSuite))
  393. {
  394. /*
  395. * RFC 4492 5.2. A server that selects an ECC cipher suite in response to a ClientHello
  396. * message including a Supported Point Formats Extension appends this extension (along
  397. * with others) to its ServerHello message, enumerating the point formats it can parse.
  398. */
  399. TlsExtensionsUtilities.AddSupportedPointFormatsExtension(m_serverExtensions,
  400. new short[]{ ECPointFormat.uncompressed });
  401. }
  402. // TODO[tls13] See RFC 8446 4.4.2.1
  403. if (null != m_statusRequestV2 && AllowMultiCertStatus())
  404. {
  405. /*
  406. * RFC 6961 2.2. If a server returns a "CertificateStatus" message in response to a
  407. * "status_request_v2" request, then the server MUST have included an extension of type
  408. * "status_request_v2" with empty "extension_data" in the extended server hello..
  409. */
  410. TlsExtensionsUtilities.AddEmptyExtensionData(m_serverExtensions, ExtensionType.status_request_v2);
  411. }
  412. else if (null != this.m_certificateStatusRequest && AllowCertificateStatus())
  413. {
  414. /*
  415. * RFC 6066 8. If a server returns a "CertificateStatus" message, then the server MUST
  416. * have included an extension of type "status_request" with empty "extension_data" in
  417. * the extended server hello.
  418. */
  419. TlsExtensionsUtilities.AddEmptyExtensionData(m_serverExtensions, ExtensionType.status_request);
  420. }
  421. if (null != m_trustedCAKeys && AllowTrustedCAIndication())
  422. {
  423. TlsExtensionsUtilities.AddTrustedCAKeysExtensionServer(m_serverExtensions);
  424. }
  425. }
  426. if (m_maxFragmentLengthOffered >= 0 && MaxFragmentLength.IsValid(m_maxFragmentLengthOffered))
  427. {
  428. TlsExtensionsUtilities.AddMaxFragmentLengthExtension(m_serverExtensions, m_maxFragmentLengthOffered);
  429. }
  430. // RFC 7250 4.2 for server_certificate_type
  431. short[] serverCertTypes = TlsExtensionsUtilities.GetServerCertificateTypeExtensionClient(
  432. m_clientExtensions);
  433. if (serverCertTypes != null)
  434. {
  435. TlsCredentials credentials = GetCredentials();
  436. if (credentials == null || !Arrays.Contains(serverCertTypes, credentials.Certificate.CertificateType))
  437. {
  438. // outcome 2: we support the extension but have no common types
  439. throw new TlsFatalAlert(AlertDescription.unsupported_certificate);
  440. }
  441. // outcome 3: we support the extension and have a common type
  442. TlsExtensionsUtilities.AddServerCertificateTypeExtensionServer(m_serverExtensions,
  443. credentials.Certificate.CertificateType);
  444. }
  445. // RFC 7250 4.2 for client_certificate_type
  446. short[] remoteClientCertTypes = TlsExtensionsUtilities.GetClientCertificateTypeExtensionClient(
  447. m_clientExtensions);
  448. if (remoteClientCertTypes != null)
  449. {
  450. short[] localClientCertTypes = GetAllowedClientCertificateTypes();
  451. if (localClientCertTypes != null)
  452. {
  453. short[] preferredTypes;
  454. short[] nonPreferredTypes;
  455. if (PreferLocalClientCertificateTypes())
  456. {
  457. preferredTypes = localClientCertTypes;
  458. nonPreferredTypes = remoteClientCertTypes;
  459. }
  460. else
  461. {
  462. preferredTypes = remoteClientCertTypes;
  463. nonPreferredTypes = localClientCertTypes;
  464. }
  465. short selectedType = -1;
  466. for (int i = 0; i < preferredTypes.Length; i++)
  467. {
  468. if (Arrays.Contains(nonPreferredTypes, preferredTypes[i]))
  469. {
  470. selectedType = preferredTypes[i];
  471. break;
  472. }
  473. }
  474. if (selectedType == -1)
  475. {
  476. // outcome 2: we support the extension but have no common types
  477. throw new TlsFatalAlert(AlertDescription.unsupported_certificate);
  478. }
  479. // outcome 3: we support the extension and have a common type
  480. TlsExtensionsUtilities.AddClientCertificateTypeExtensionServer(m_serverExtensions, selectedType);
  481. } // else outcome 1: we don't support the extension
  482. }
  483. return m_serverExtensions;
  484. }
  485. public virtual void GetServerExtensionsForConnection(IDictionary<int, byte[]> serverExtensions)
  486. {
  487. if (!ShouldSelectProtocolNameEarly())
  488. {
  489. if (null != m_clientProtocolNames && m_clientProtocolNames.Count > 0)
  490. {
  491. this.m_selectedProtocolName = SelectProtocolName();
  492. }
  493. }
  494. /*
  495. * RFC 7301 3.1. When session resumption or session tickets [...] are used, the previous
  496. * contents of this extension are irrelevant, and only the values in the new handshake
  497. * messages are considered.
  498. */
  499. if (null == m_selectedProtocolName)
  500. {
  501. serverExtensions.Remove(ExtensionType.application_layer_protocol_negotiation);
  502. }
  503. else
  504. {
  505. TlsExtensionsUtilities.AddAlpnExtensionServer(serverExtensions, m_selectedProtocolName);
  506. }
  507. }
  508. public virtual IList<SupplementalDataEntry> GetServerSupplementalData()
  509. {
  510. return null;
  511. }
  512. public abstract TlsCredentials GetCredentials();
  513. public virtual CertificateStatus GetCertificateStatus()
  514. {
  515. return null;
  516. }
  517. public virtual CertificateRequest GetCertificateRequest()
  518. {
  519. return null;
  520. }
  521. public virtual TlsPskIdentityManager GetPskIdentityManager()
  522. {
  523. return null;
  524. }
  525. public virtual TlsSrpLoginParameters GetSrpLoginParameters()
  526. {
  527. return null;
  528. }
  529. public virtual TlsDHConfig GetDHConfig()
  530. {
  531. int minimumFiniteFieldBits = TlsDHUtilities.GetMinimumFiniteFieldBits(m_selectedCipherSuite);
  532. int namedGroup = SelectDH(minimumFiniteFieldBits);
  533. return TlsDHUtilities.CreateNamedDHConfig(m_context, namedGroup);
  534. }
  535. public virtual TlsECConfig GetECDHConfig()
  536. {
  537. int minimumCurveBits = TlsEccUtilities.GetMinimumCurveBits(m_selectedCipherSuite);
  538. int namedGroup = SelectECDH(minimumCurveBits);
  539. return TlsEccUtilities.CreateNamedECConfig(m_context, namedGroup);
  540. }
  541. public virtual void ProcessClientSupplementalData(IList<SupplementalDataEntry> clientSupplementalData)
  542. {
  543. if (clientSupplementalData != null)
  544. throw new TlsFatalAlert(AlertDescription.unexpected_message);
  545. }
  546. public virtual void NotifyClientCertificate(Certificate clientCertificate)
  547. {
  548. throw new TlsFatalAlert(AlertDescription.internal_error);
  549. }
  550. public virtual NewSessionTicket GetNewSessionTicket()
  551. {
  552. /*
  553. * RFC 5077 3.3. If the server determines that it does not want to include a ticket after it
  554. * has included the SessionTicket extension in the ServerHello, then it sends a zero-length
  555. * ticket in the NewSessionTicket handshake message.
  556. */
  557. return new NewSessionTicket(0L, TlsUtilities.EmptyBytes);
  558. }
  559. }
  560. }
  561. #pragma warning restore
  562. #endif