WSSecurityOneDotOneReceiveSecurityHeader.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //----------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.Security
  5. {
  6. using System.IdentityModel.Tokens;
  7. using System.Security.Cryptography;
  8. using System.ServiceModel;
  9. using System.ServiceModel.Channels;
  10. using System.ServiceModel.Description;
  11. using System.ServiceModel.Security.Tokens;
  12. using System.Xml;
  13. class WSSecurityOneDotOneReceiveSecurityHeader : WSSecurityOneDotZeroReceiveSecurityHeader
  14. {
  15. public WSSecurityOneDotOneReceiveSecurityHeader(Message message, string actor, bool mustUnderstand, bool relay,
  16. SecurityStandardsManager standardsManager,
  17. SecurityAlgorithmSuite algorithmSuite,
  18. int headerIndex, MessageDirection direction)
  19. : base(message, actor, mustUnderstand, relay, standardsManager, algorithmSuite, headerIndex, direction)
  20. {
  21. }
  22. protected override DecryptedHeader DecryptHeader(XmlDictionaryReader reader, WrappedKeySecurityToken wrappedKeyToken)
  23. {
  24. // If it is the client, then we may need to read the GenericXmlSecurityKeyIdentoifoer clause while reading EncryptedData.
  25. EncryptedHeaderXml headerXml = new EncryptedHeaderXml(this.Version, this.MessageDirection == MessageDirection.Output);
  26. headerXml.SecurityTokenSerializer = this.StandardsManager.SecurityTokenSerializer;
  27. headerXml.ReadFrom(reader, MaxReceivedMessageSize);
  28. // The Encrypted Headers MustUnderstand, Relay and Actor attributes should match the
  29. // Security Headers value.
  30. if (headerXml.MustUnderstand != this.MustUnderstand)
  31. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.GetString(SR.EncryptedHeaderAttributeMismatch, XD.MessageDictionary.MustUnderstand.Value, headerXml.MustUnderstand, this.MustUnderstand)));
  32. if (headerXml.Relay != this.Relay)
  33. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.GetString(SR.EncryptedHeaderAttributeMismatch, XD.Message12Dictionary.Relay.Value, headerXml.Relay, this.Relay)));
  34. if (headerXml.Actor != this.Actor)
  35. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.GetString(SR.EncryptedHeaderAttributeMismatch, this.Version.Envelope.DictionaryActor, headerXml.Actor, this.Actor)));
  36. SecurityToken token;
  37. if (wrappedKeyToken == null)
  38. {
  39. token = ResolveKeyIdentifier(headerXml.KeyIdentifier, this.CombinedPrimaryTokenResolver, false);
  40. }
  41. else
  42. {
  43. token = wrappedKeyToken;
  44. }
  45. RecordEncryptionToken(token);
  46. using (SymmetricAlgorithm algorithm = CreateDecryptionAlgorithm(token, headerXml.EncryptionMethod, this.AlgorithmSuite))
  47. {
  48. headerXml.SetUpDecryption(algorithm);
  49. return new DecryptedHeader(
  50. headerXml.GetDecryptedBuffer(),
  51. this.SecurityVerifiedMessage.GetEnvelopeAttributes(), this.SecurityVerifiedMessage.GetHeaderAttributes(),
  52. this.Version, this.StandardsManager.IdManager, this.ReaderQuotas);
  53. }
  54. }
  55. }
  56. }