TlsServerSettings.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Transport Security Layer (TLS)
  2. // Copyright (c) 2003-2004 Carlos Guzman Alvarez
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining
  5. // a copy of this software and associated documentation files (the
  6. // "Software"), to deal in the Software without restriction, including
  7. // without limitation the rights to use, copy, modify, merge, publish,
  8. // distribute, sublicense, and/or sell copies of the Software, and to
  9. // permit persons to whom the Software is furnished to do so, subject to
  10. // the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be
  13. // included in all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. //
  23. using System;
  24. using System.Security.Cryptography;
  25. using Mono.Security.Cryptography;
  26. using Mono.Security.X509;
  27. using Mono.Security.Protocol.Tls.Handshake;
  28. namespace Mono.Security.Protocol.Tls
  29. {
  30. internal class TlsServerSettings
  31. {
  32. #region Fields
  33. private X509CertificateCollection certificates;
  34. private RSA certificateRSA;
  35. private RSAParameters rsaParameters;
  36. private byte[] signedParams;
  37. private string[] distinguisedNames;
  38. private bool serverKeyExchange;
  39. private bool certificateRequest;
  40. private ClientCertificateType[] certificateTypes;
  41. #endregion
  42. #region Properties
  43. public bool ServerKeyExchange
  44. {
  45. get { return this.serverKeyExchange; }
  46. set { this.serverKeyExchange = value; }
  47. }
  48. public X509CertificateCollection Certificates
  49. {
  50. get { return this.certificates; }
  51. set { this.certificates = value; }
  52. }
  53. public RSA CertificateRSA
  54. {
  55. get { return this.certificateRSA; }
  56. }
  57. public RSAParameters RsaParameters
  58. {
  59. get { return this.rsaParameters; }
  60. set { this.rsaParameters = value; }
  61. }
  62. public byte[] SignedParams
  63. {
  64. get { return this.signedParams; }
  65. set { this.signedParams = value; }
  66. }
  67. public bool CertificateRequest
  68. {
  69. get { return this.certificateRequest; }
  70. set { this.certificateRequest = value; }
  71. }
  72. public ClientCertificateType[] CertificateTypes
  73. {
  74. get { return this.certificateTypes; }
  75. set { this.certificateTypes = value; }
  76. }
  77. public string[] DistinguisedNames
  78. {
  79. get { return this.distinguisedNames; }
  80. set { this.distinguisedNames = value; }
  81. }
  82. #endregion
  83. #region Constructors
  84. public TlsServerSettings()
  85. {
  86. }
  87. #endregion
  88. #region Methods
  89. public void UpdateCertificateRSA()
  90. {
  91. if (this.certificates == null ||
  92. this.certificates.Count == 0)
  93. {
  94. this.certificateRSA = null;
  95. }
  96. else
  97. {
  98. this.certificateRSA = new RSAManaged(
  99. this.certificates[0].RSA.KeySize);
  100. this.certificateRSA.ImportParameters(
  101. this.certificates[0].RSA.ExportParameters(false));
  102. }
  103. }
  104. #endregion
  105. }
  106. }