Example #1
0
        public Message SetupExecution()
        {
            ThrowIfProcessingStarted();
            SetProcessingStarted();

            bool signBody = false;

            if (ElementContainer.SourceSigningToken != null)
            {
                if (_signatureParts == null)
                {
                    throw TraceUtility.ThrowHelperError(new ArgumentNullException(nameof(SignatureParts)), Message);
                }
                signBody = _signatureParts.IsBodyIncluded;
            }

            bool encryptBody = false;

            if (ElementContainer.SourceEncryptionToken != null)
            {
                if (_encryptionParts == null)
                {
                    throw TraceUtility.ThrowHelperError(new ArgumentNullException(nameof(EncryptionParts)), Message);
                }
                encryptBody = _encryptionParts.IsBodyIncluded;
            }

            SecurityAppliedMessage message = new SecurityAppliedMessage(Message, this, signBody, encryptBody);

            Message = message;
            return(message);
        }
Example #2
0
        public override void ApplyBodySecurity(XmlDictionaryWriter writer, IPrefixGenerator prefixGenerator)
        {
            SecurityAppliedMessage message = SecurityAppliedMessage;

            switch (message.BodyProtectionMode)
            {
            case MessagePartProtectionMode.None:
                return;

            case MessagePartProtectionMode.Sign:
                var ms = new MemoryStream();
                if (CanCanonicalizeAndFragment(writer))
                {
                    message.WriteBodyToSignWithFragments(ms, false, null, writer);
                }
                else
                {
                    message.WriteBodyToSign(ms);
                }

                ms.Position = 0;
                AddReference("#" + message.BodyId, ms);
                return;

            case MessagePartProtectionMode.SignThenEncrypt:
                throw new PlatformNotSupportedException();

            case MessagePartProtectionMode.Encrypt:
                throw new PlatformNotSupportedException();

            case MessagePartProtectionMode.EncryptThenSign:
                throw new PlatformNotSupportedException();

            default:
                Fx.Assert("Invalid MessagePartProtectionMode");
                return;
            }
        }