当前位置: 首页>>代码示例>>C#>>正文


C# SecurityToken.ResolveKeyIdentifierClause方法代码示例

本文整理汇总了C#中System.IdentityModel.Tokens.SecurityToken.ResolveKeyIdentifierClause方法的典型用法代码示例。如果您正苦于以下问题:C# SecurityToken.ResolveKeyIdentifierClause方法的具体用法?C# SecurityToken.ResolveKeyIdentifierClause怎么用?C# SecurityToken.ResolveKeyIdentifierClause使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IdentityModel.Tokens.SecurityToken的用法示例。


在下文中一共展示了SecurityToken.ResolveKeyIdentifierClause方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateSignature

        Signature CreateSignature (XmlDocument doc, XmlElement body, 
                                           XmlNamespaceManager nsmgr,
                                           SupportingTokenInfoCollection tokenInfos,
                                           SecurityKeyIdentifierClause actualClause,
                                           SymmetricAlgorithm actualKey,
                                           SecurityToken signToken,
                                           bool includeSigToken,
                                           bool signatureProtection,
                                           WSSecurityMessageHeader header,
                                           Collection<WSSignedXml> endorsedSignatures,
                                           ref string bodyId)
        {
            // sign
            // see clause 8 of WS-SecurityPolicy C.2.2
            WSSignedXml sxml = new WSSignedXml (doc);
            SecurityTokenReferenceKeyInfo sigKeyInfo;
            XmlElement secElem = null;
            var sigSpec = SignaturePart;
            var serializer = security.TokenSerializer;
            var suite = security.Element.DefaultAlgorithmSuite;

            var sig = sxml.Signature;
            sig.SignedInfo.CanonicalizationMethod =
                suite.DefaultCanonicalizationAlgorithm;
            foreach (XmlElement elem in doc.SelectNodes ("/s:Envelope/s:Header/o:Security/u:Timestamp", nsmgr))
                CreateReference(sig, elem, elem.GetAttribute ("Id", Constants.WsuNamespace));
            foreach (XmlElement elem in doc.SelectNodes ("/s:Envelope/s:Header/o:Security/o11:SignatureConfirmation", nsmgr))
                CreateReference(sig, elem, elem.GetAttribute ("Id", Constants.WsuNamespace));
            foreach (SupportingTokenInfo tinfo in tokenInfos)
                if (tinfo.Mode != SecurityTokenAttachmentMode.Endorsing) {
                    XmlElement el = sxml.GetIdElement (doc, tinfo.Token.Id);
                    CreateReference (sig, el, el.GetAttribute ("Id", Constants.WsuNamespace));
                }
            XmlNodeList nodes = doc.SelectNodes ("/s:Envelope/s:Header/*", nsmgr);
            for (int i = 0; i < msg.Headers.Count; i++) {
                MessageHeaderInfo h = msg.Headers [i];
                if (h.Name == "Security" && h.Namespace == Constants.WssNamespace)
                    secElem = nodes [i] as XmlElement;
                else if ((sigSpec.HeaderTypes.Count == 0 ||
                    sigSpec.HeaderTypes.Contains (new XmlQualifiedName(h.Name, h.Namespace))) &&
                    (msg.Version.Addressing != AddressingVersion.None ||
                    !String.Equals (h.Name, "Action", StringComparison.Ordinal))) {
                    string id = GenerateId (doc);
                    h.Id = id;
                    CreateReference (sig, nodes [i] as XmlElement, id);
                }
            }
            if (sigSpec.IsBodyIncluded) {
                bodyId = GenerateId (doc);
                CreateReference (sig, body.ParentNode as XmlElement, bodyId);
            }


            if (security.DefaultSignatureAlgorithm == SignedXml.XmlDsigHMACSHA1Url) {
                // FIXME: use appropriate hash algorithm
                sxml.ComputeSignature (new HMACSHA1(actualKey.Key));
                sigKeyInfo = new SecurityTokenReferenceKeyInfo (actualClause, serializer, doc);
            } else  {
                SecurityKeyIdentifierClause signClause =
                    CounterParameters.CallCreateKeyIdentifierClause (signToken, includeSigToken ? CounterParameters.ReferenceStyle : SecurityTokenReferenceStyle.External);
                AsymmetricSecurityKey signKey = (AsymmetricSecurityKey)signToken.ResolveKeyIdentifierClause (signClause);
                sxml.SigningKey = signKey.GetAsymmetricAlgorithm (security.DefaultSignatureAlgorithm, true);
                sxml.ComputeSignature ();
                sigKeyInfo = new SecurityTokenReferenceKeyInfo (signClause, serializer, doc);
            }

            sxml.KeyInfo = new KeyInfo ();
            sxml.KeyInfo.AddClause (sigKeyInfo);

            if (!signatureProtection)
                header.AddContent (sig);

            // endorse the signature with (signed)endorsing
            // supporting tokens.

            foreach (SupportingTokenInfo tinfo in tokenInfos) {
                switch (tinfo.Mode) {
                case SecurityTokenAttachmentMode.Endorsing:
                case SecurityTokenAttachmentMode.SignedEndorsing:
                    if (sxml.Signature.Id == null) {
                        sig.Id = GenerateId (doc);
                        secElem.AppendChild (sxml.GetXml ());
                    }
                    WSSignedXml ssxml = new WSSignedXml (doc);
                    ssxml.Signature.SignedInfo.CanonicalizationMethod = suite.DefaultCanonicalizationAlgorithm;
                    CreateReference (ssxml.Signature, doc, sig.Id);
                    SecurityToken sst = tinfo.Token;
                    SecurityKey ssk = sst.SecurityKeys [0]; // FIXME: could be different?
                    SecurityKeyIdentifierClause tclause = new LocalIdKeyIdentifierClause (sst.Id); // FIXME: could be different?
                    if (ssk is SymmetricSecurityKey) {
                        SymmetricSecurityKey signKey = (SymmetricSecurityKey)ssk;
                        ssxml.ComputeSignature (signKey.GetKeyedHashAlgorithm(suite.DefaultSymmetricSignatureAlgorithm));
                    } else {
                        AsymmetricSecurityKey signKey = (AsymmetricSecurityKey)ssk;
                        ssxml.SigningKey = signKey.GetAsymmetricAlgorithm (suite.DefaultAsymmetricSignatureAlgorithm, true);
                        ssxml.ComputeSignature ();
                    }
                    ssxml.KeyInfo.AddClause (new SecurityTokenReferenceKeyInfo (tclause, serializer, doc));
                    if (!signatureProtection)
                        header.AddContent (ssxml.Signature);
//.........这里部分代码省略.........
开发者ID:nlhepler,项目名称:mono,代码行数:101,代码来源:SecureMessageGenerator.cs


注:本文中的System.IdentityModel.Tokens.SecurityToken.ResolveKeyIdentifierClause方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。