void AddSignatureReference(SendSecurityHeaderElement[] elements)
        {
            if (elements != null)
            {
                for (int i = 0; i < elements.Length; ++i)
                {
                    SecurityKeyIdentifierClause keyIdentifierClause = null;
                    TokenElement signedEncryptedTokenElement        = elements[i].Item as TokenElement;

                    // signedEncryptedTokenElement can either be a TokenElement ( in SignThenEncrypt case) or EncryptedData ( in !SignThenEncryptCase)
                    // STR-Transform does not make sense in !SignThenEncrypt case .
                    // note: signedEncryptedTokenElement can also be SignatureConfirmation but we do not care about it here.
                    bool useStrTransform = signedEncryptedTokenElement != null &&
                                           SignThenEncrypt &&
                                           this.ShouldUseStrTransformForToken(signedEncryptedTokenElement.Token,
                                                                              i,
                                                                              SecurityTokenAttachmentMode.SignedEncrypted,
                                                                              out keyIdentifierClause);

                    if (!useStrTransform && elements[i].Id == null)
                    {
                        throw TraceUtility.ThrowHelperError(new MessageSecurityException(SR.GetString(SR.ElementToSignMustHaveId)), this.Message);
                    }

                    HashStream          hashStream = TakeHashStream();
                    XmlDictionaryWriter utf8Writer = TakeUtf8Writer();
                    utf8Writer.StartCanonicalization(hashStream, false, null);
                    elements[i].Item.WriteTo(utf8Writer, ServiceModelDictionaryManager.Instance);
                    utf8Writer.EndCanonicalization();

                    if (useStrTransform)
                    {
                        if (keyIdentifierClause != null)
                        {
                            if (String.IsNullOrEmpty(keyIdentifierClause.Id))
                            {
                                keyIdentifierClause.Id = SecurityUniqueId.Create().Value;
                            }

                            this.ElementContainer.MapSecurityTokenToStrClause(signedEncryptedTokenElement.Token, keyIdentifierClause);
                            this.signedInfo.AddReference(keyIdentifierClause.Id, hashStream.FlushHashAndGetValue(), true);
                        }
                        else
                        {
                            throw TraceUtility.ThrowHelperError(new MessageSecurityException(SR.GetString(SR.TokenManagerCannotCreateTokenReference)), this.Message);
                        }
                    }
                    else
                    {
                        this.signedInfo.AddReference(elements[i].Id, hashStream.FlushHashAndGetValue());
                    }
                }
            }
        }
        private void AddSignatureReference(SendSecurityHeaderElement[] elements)
        {
            if (elements != null)
            {
                for (int i = 0; i < elements.Length; ++i)
                {
                    SecurityKeyIdentifierClause keyIdentifierClause = null;
                    TokenElement signedEncryptedTokenElement        = elements[i].Item as TokenElement;

                    // signedEncryptedTokenElement can either be a TokenElement ( in SignThenEncrypt case) or EncryptedData ( in !SignThenEncryptCase)
                    // STR-Transform does not make sense in !SignThenEncrypt case .
                    // note: signedEncryptedTokenElement can also be SignatureConfirmation but we do not care about it here.
                    bool useStrTransform = signedEncryptedTokenElement != null &&
                                           SignThenEncrypt &&
                                           ShouldUseStrTransformForToken(signedEncryptedTokenElement.Token,
                                                                         i,
                                                                         SecurityTokenAttachmentMode.SignedEncrypted,
                                                                         out keyIdentifierClause);

                    if (!useStrTransform && elements[i].Id == null)
                    {
                        throw TraceUtility.ThrowHelperError(new MessageSecurityException(SR.ElementToSignMustHaveId), Message);
                    }

                    MemoryStream        stream     = new MemoryStream();
                    XmlDictionaryWriter utf8Writer = TakeUtf8Writer();
                    utf8Writer.StartCanonicalization(stream, false, null);
                    elements[i].Item.WriteTo(utf8Writer, ServiceModelDictionaryManager.Instance);
                    utf8Writer.EndCanonicalization();
                    stream.Position = 0;
                    if (useStrTransform)
                    {
                        throw new PlatformNotSupportedException("StrTransform not supported yet");
                    }
                    else
                    {
                        AddReference("#" + elements[i].Id, stream);
                    }
                }
            }
        }
Example #3
0
        public override bool Equals(object item)
        {
            TokenElement element = item as TokenElement;

            return(element != null && Token == element.Token && _standardsManager == element._standardsManager);
        }
        public override bool Equals(object item)
        {
            TokenElement element = item as TokenElement;

            return(((element != null) && (this.token == element.token)) && (this.standardsManager == element.standardsManager));
        }