TlsServerCertificateRequest.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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.Text;
  25. using Mono.Security;
  26. namespace Mono.Security.Protocol.Tls.Handshake.Client
  27. {
  28. internal class TlsServerCertificateRequest : HandshakeMessage
  29. {
  30. #region Fields
  31. private ClientCertificateType[] certificateTypes;
  32. private string[] distinguisedNames;
  33. #endregion
  34. #region Constructors
  35. public TlsServerCertificateRequest(Context context, byte[] buffer)
  36. : base(context, HandshakeType.CertificateRequest, buffer)
  37. {
  38. }
  39. #endregion
  40. #region Methods
  41. public override void Update()
  42. {
  43. base.Update();
  44. this.Context.ServerSettings.CertificateTypes = this.certificateTypes;
  45. this.Context.ServerSettings.DistinguisedNames = this.distinguisedNames;
  46. this.Context.ServerSettings.CertificateRequest = true;
  47. }
  48. #endregion
  49. #region Protected Methods
  50. protected override void ProcessAsSsl3()
  51. {
  52. this.ProcessAsTls1();
  53. }
  54. protected override void ProcessAsTls1()
  55. {
  56. // Read requested certificate types
  57. int typesCount = this.ReadByte();
  58. this.certificateTypes = new ClientCertificateType[typesCount];
  59. for (int i = 0; i < typesCount; i++)
  60. {
  61. this.certificateTypes[i] = (ClientCertificateType)this.ReadByte();
  62. }
  63. /*
  64. * Read requested certificate authorities (Distinguised Names)
  65. *
  66. * Name ::= SEQUENCE OF RelativeDistinguishedName
  67. *
  68. * RelativeDistinguishedName ::= SET OF AttributeValueAssertion
  69. *
  70. * AttributeValueAssertion ::= SEQUENCE {
  71. * attributeType OBJECT IDENTIFIER
  72. * attributeValue ANY }
  73. */
  74. if (this.ReadInt16() != 0)
  75. {
  76. ASN1 rdn = new ASN1(this.ReadBytes(this.ReadInt16()));
  77. distinguisedNames = new string[rdn.Count];
  78. for (int i = 0; i < rdn.Count; i++)
  79. {
  80. // element[0] = attributeType
  81. // element[1] = attributeValue
  82. ASN1 element = new ASN1(rdn[i].Value);
  83. distinguisedNames[i] = Encoding.UTF8.GetString(element[1].Value);
  84. }
  85. }
  86. }
  87. #endregion
  88. }
  89. }