WSSecurityOneDotOneSendSecurityHeader.cs 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //----------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.Security
  5. {
  6. using System.Collections.Generic;
  7. using System.ServiceModel.Channels;
  8. using System.ServiceModel;
  9. using System.ServiceModel.Description;
  10. using System.Diagnostics;
  11. using System.IO;
  12. using System.IdentityModel.Tokens;
  13. using System.Security.Cryptography;
  14. using System.ServiceModel.Security.Tokens;
  15. using System.Xml;
  16. using System.ServiceModel.Diagnostics;
  17. using ISignatureValueSecurityElement = System.IdentityModel.ISignatureValueSecurityElement;
  18. sealed class WSSecurityOneDotOneSendSecurityHeader : WSSecurityOneDotZeroSendSecurityHeader
  19. {
  20. public WSSecurityOneDotOneSendSecurityHeader(Message message, string actor, bool mustUnderstand, bool relay,
  21. SecurityStandardsManager standardsManager,
  22. SecurityAlgorithmSuite algorithmSuite,
  23. MessageDirection direction)
  24. : base(message, actor, mustUnderstand, relay, standardsManager, algorithmSuite, direction)
  25. {
  26. }
  27. protected override ISignatureValueSecurityElement[] CreateSignatureConfirmationElements(SignatureConfirmations signatureConfirmations)
  28. {
  29. if (signatureConfirmations == null || signatureConfirmations.Count == 0)
  30. {
  31. return null;
  32. }
  33. ISignatureValueSecurityElement[] result = new ISignatureValueSecurityElement[signatureConfirmations.Count];
  34. for (int i = 0; i < signatureConfirmations.Count; ++i)
  35. {
  36. byte[] sigValue;
  37. bool isEncrypted;
  38. signatureConfirmations.GetConfirmation(i, out sigValue, out isEncrypted);
  39. result[i] = new SignatureConfirmationElement(this.GenerateId(), sigValue, this.StandardsManager.SecurityVersion);
  40. }
  41. return result;
  42. }
  43. protected override EncryptedHeader EncryptHeader(MessageHeader plainTextHeader, SymmetricAlgorithm algorithm,
  44. SecurityKeyIdentifier keyIdentifier, MessageVersion version, string id, MemoryStream stream)
  45. {
  46. // We are not reading EncryptedData from the wire here, hence pass false.
  47. EncryptedHeaderXml encryptedHeaderXml = new EncryptedHeaderXml(version, false);
  48. encryptedHeaderXml.SecurityTokenSerializer = this.StandardsManager.SecurityTokenSerializer;
  49. encryptedHeaderXml.EncryptionMethod = this.EncryptionAlgorithm;
  50. encryptedHeaderXml.EncryptionMethodDictionaryString = this.EncryptionAlgorithmDictionaryString;
  51. encryptedHeaderXml.KeyIdentifier = keyIdentifier;
  52. encryptedHeaderXml.Id = id;
  53. // The Encrypted Headers MustUnderstand, Relay and Actor attributes will always match the
  54. // Security Headers value. The values for these on the Encrypted Header and its decrypted
  55. // form can be different.
  56. encryptedHeaderXml.MustUnderstand = this.MustUnderstand;
  57. encryptedHeaderXml.Relay = this.Relay;
  58. encryptedHeaderXml.Actor = this.Actor;
  59. encryptedHeaderXml.SetUpEncryption(algorithm, stream);
  60. return new EncryptedHeader(plainTextHeader, encryptedHeaderXml, EncryptedHeaderXml.ElementName.Value, EncryptedHeaderXml.NamespaceUri.Value, version);
  61. }
  62. }
  63. }