Ejemplo n.º 1
0
 public SecurityAppliedMessage(Message messageToProcess, SendSecurityHeader securityHeader, bool signBody, bool encryptBody)
     : base(messageToProcess)
 {
     Fx.Assert(!(messageToProcess is SecurityAppliedMessage), "SecurityAppliedMessage should not be wrapped");
     this.securityHeader     = securityHeader;
     this.bodyProtectionMode = MessagePartProtectionModeHelper.GetProtectionMode(signBody, encryptBody, securityHeader.SignThenEncrypt);
 }
 public SecurityAppliedMessage(Message messageToProcess, SendSecurityHeader securityHeader, bool signBody, bool encryptBody)
     : base(messageToProcess)
 {
     Fx.Assert(!(messageToProcess is SecurityAppliedMessage), "SecurityAppliedMessage should not be wrapped");
     this.securityHeader = securityHeader;
     this.bodyProtectionMode = MessagePartProtectionModeHelper.GetProtectionMode(signBody, encryptBody, securityHeader.SignThenEncrypt);
 }
        private void ApplySecurityAndWriteHeader(MessageHeader header, string headerId, XmlDictionaryWriter writer, IPrefixGenerator prefixGenerator)
        {
            if (!RequireMessageProtection && ShouldSignToHeader)
            {
                if ((header.Name == XD.AddressingDictionary.To.Value) &&
                    (header.Namespace == Message.Version.Addressing.Namespace))
                {
                    if (_toHeaderStream == null)
                    {
                        Stream headerStream;
                        headerId        = GetSignatureStream(header, headerId, prefixGenerator, writer, out headerStream);
                        _toHeaderStream = headerStream;
                        _toHeaderId     = headerId;
                    }
                    else
                    {
                        // More than one 'To' header is specified in the message.
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.TransportSecuredMessageHasMoreThanOneToHeader));
                    }

                    return;
                }
            }

            MessagePartProtectionMode protectionMode = GetProtectionMode(header);

            switch (protectionMode)
            {
            case MessagePartProtectionMode.None:
                header.WriteHeader(writer, Version);
                return;

            case MessagePartProtectionMode.Sign:
                AddSignatureReference(header, headerId, prefixGenerator, writer);
                return;

            case MessagePartProtectionMode.SignThenEncrypt:
            case MessagePartProtectionMode.Encrypt:
            case MessagePartProtectionMode.EncryptThenSign:
                throw ExceptionHelper.PlatformNotSupported();

            default:
                Fx.Assert("Invalid MessagePartProtectionMode");
                return;
            }
        }
        void ApplySecurityAndWriteHeader(MessageHeader header, string headerId, XmlDictionaryWriter writer, IPrefixGenerator prefixGenerator)
        {
            if (!this.RequireMessageProtection && this.ShouldSignToHeader)
            {
                if ((header.Name == XD.AddressingDictionary.To.Value) &&
                    (header.Namespace == this.Message.Version.Addressing.Namespace))
                {
                    if (this.toHeaderHash == null)
                    {
                        byte[] headerHash;
                        headerId          = GetSignatureHash(header, headerId, prefixGenerator, writer, out headerHash);
                        this.toHeaderHash = headerHash;
                        this.toHeaderId   = headerId;
                    }
                    else
                    {
                        // More than one 'To' header is specified in the message.
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.GetString(SR.TransportSecuredMessageHasMoreThanOneToHeader)));
                    }

                    return;
                }
            }

            MessagePartProtectionMode protectionMode = GetProtectionMode(header);
            MemoryStream plainTextStream;
            string       encryptedDataId;

            switch (protectionMode)
            {
            case MessagePartProtectionMode.None:
                header.WriteHeader(writer, this.Version);
                return;

            case MessagePartProtectionMode.Sign:
                AddSignatureReference(header, headerId, prefixGenerator, writer);
                return;

            case MessagePartProtectionMode.SignThenEncrypt:
                AddEncryptionReference(header, headerId, prefixGenerator, true, out plainTextStream, out encryptedDataId);
                EncryptAndWriteHeader(header, encryptedDataId, plainTextStream, writer);
                this.hasSignedEncryptedMessagePart = true;
                return;

            case MessagePartProtectionMode.Encrypt:
                AddEncryptionReference(header, headerId, prefixGenerator, false, out plainTextStream, out encryptedDataId);
                EncryptAndWriteHeader(header, encryptedDataId, plainTextStream, writer);
                return;

            case MessagePartProtectionMode.EncryptThenSign:
                AddEncryptionReference(header, headerId, prefixGenerator, false, out plainTextStream, out encryptedDataId);
                EncryptedHeader encryptedHeader = EncryptHeader(
                    header, this.encryptingSymmetricAlgorithm, this.encryptionKeyIdentifier, this.Version, encryptedDataId, plainTextStream);
                AddSignatureReference(encryptedHeader, encryptedDataId, prefixGenerator, writer);
                return;

            default:
                Fx.Assert("Invalid MessagePartProtectionMode");
                return;
            }
        }
 public SecurityAppliedMessage(Message messageToProcess, SendSecurityHeader securityHeader, bool signBody, bool encryptBody) : base(messageToProcess)
 {
     this.bodyPrefix = "s";
     this.securityHeader = securityHeader;
     this.bodyProtectionMode = MessagePartProtectionModeHelper.GetProtectionMode(signBody, encryptBody, securityHeader.SignThenEncrypt);
 }
Ejemplo n.º 6
0
 public SecurityAppliedMessage(Message messageToProcess, SendSecurityHeader securityHeader, bool signBody, bool encryptBody) : base(messageToProcess)
 {
     this.bodyPrefix         = "s";
     this.securityHeader     = securityHeader;
     this.bodyProtectionMode = MessagePartProtectionModeHelper.GetProtectionMode(signBody, encryptBody, securityHeader.SignThenEncrypt);
 }