Exemplo n.º 1
0
        private void WriteHeader(XmlDictionaryWriter writer)
        {
            var nonce = new byte[64];
            RandomNumberGenerator.Create().GetBytes(nonce);
            string created = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.mszzzz");

            writer.WriteStartElement("wsse", "UsernameToken", null);
            writer.WriteAttributeString("wsu:Id", "UsernameToken-1");
            writer.WriteStartElement("wsse", "Username", null);
            writer.WriteString(SystemUser);
            writer.WriteEndElement();//End Username 
            writer.WriteStartElement("wsse", "Password", null);
            writer.WriteAttributeString("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest");
            writer.WriteString(ComputePasswordDigest(SystemPassword, nonce, created));
            writer.WriteEndElement();//End Password 
            writer.WriteStartElement("wsse", "Nonce", null);
            writer.WriteAttributeString("EncodingType", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary");
            writer.WriteBase64(nonce, 0, nonce.Length);
            writer.WriteEndElement();//End Nonce 
            writer.WriteStartElement("wsu", "Created", null);
            writer.WriteString(created);
            writer.WriteEndElement();//End Created
            writer.WriteEndElement();//End UsernameToken
            writer.Flush();
        }
 /// <summary>
 /// Writes the body of an object in the output
 /// </summary>
 public override void WriteObjectContent(System.Xml.XmlDictionaryWriter writer, object graph)
 {
     if (writer == null)
     {
         throw new ArgumentNullException("writer");
     }
     if (graph == null)
     {
         writer.WriteAttributeString("nil", "true");
     }
     else
     {
         using (MemoryStream ms = new MemoryStream())
         {
             if (isList)
             {
                 model.Serialize(ms, graph, null);
             }
             else
             {
                 using (ProtoWriter protoWriter = new ProtoWriter(ms, model, null))
                 {
                     model.Serialize(key, graph, protoWriter);
                 }
             }
             byte[] buffer = ms.GetBuffer();
             writer.WriteBase64(buffer, 0, (int)ms.Length);
         }
     }
 }
Exemplo n.º 3
0
 public override void WriteObject(XmlDictionaryWriter writer, object graph)
 {
     var data = EncodeObject(graph);
     writer.WriteStartElement("Data");
     writer.WriteBase64(data, 0, data.Length);
     writer.WriteEndElement();
 }
Exemplo n.º 4
0
 void WriteChunkCallback(XmlDictionaryWriter writer, object state)
 {
     ChunkState chunkState = (ChunkState)state;
     writer.WriteStartElement(ChunkingUtils.ChunkElement, ChunkingUtils.ChunkNs);
     writer.WriteBase64(chunkState.Buffer, 0, chunkState.Count);
     writer.WriteEndElement();
 }
Exemplo n.º 5
0
            protected override void OnWriteBodyContents(System.Xml.XmlDictionaryWriter writer)
            {
                // TODO:  RawMessageEncoder.StreamElementName should be public.
                writer.WriteStartElement("Binary");  // the expected Raw encoder "<Binary>" virtual xml tag

                if (bodyAsString != null)
                {
                    byte[] buf = Encoding.UTF8.GetBytes(bodyAsString);
                    writer.WriteBase64(buf, 0, buf.Length);
                }
                else
                {
                    writer.WriteBase64(this.bodyAsBytes, this.offset, this.count);
                }

                writer.WriteEndElement();
            }
        /// <summary>
        /// Writes the given content to output writer.
        /// </summary>
        /// <param name="writer">Output writer instance.</param>
        protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
        {
            var buffer = this.contentEncoding.GetBytes(this.content);

            writer.WriteStartElement("Binary");
            writer.WriteBase64(buffer, 0, buffer.Length);
            writer.WriteEndElement();
        }
Exemplo n.º 7
0
        protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
        {
            writer.WriteStartElement("Binary");

            FileStream fs = new FileStream(this.testFileName, FileMode.Open);
            byte[] tmp = new byte[fs.Length];
            fs.Read(tmp, 0, tmp.Length);
            writer.WriteBase64(tmp, 0, (int)tmp.Length);

            writer.WriteEndElement();
            fs.Close();
        }
 public void WriteTo(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString ns, XmlDictionaryString valueTypeLocalName, XmlDictionaryString valueTypeNs)
 {
     writer.WriteStartElement(prefix, localName, ns);
     writer.WriteStartAttribute(valueTypeLocalName, valueTypeNs);
     if (valueTypeUriDictionaryString != null)
         writer.WriteString(valueTypeUriDictionaryString);
     else
         writer.WriteString(valueTypeUri);
     writer.WriteEndAttribute();
     writer.WriteStartAttribute(XD.SecurityJan2004Dictionary.EncodingType, null);
     writer.WriteString(XD.SecurityJan2004Dictionary.EncodingTypeValueBase64Binary);
     writer.WriteEndAttribute();
     writer.WriteBase64(this.negotiationData, 0, this.negotiationData.Length);
     writer.WriteEndElement();
 }
Exemplo n.º 9
0
        /// <summary>
        /// Writes the body to the stream.
        /// </summary>
        protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
        {
            if (m_isRequest)
            {
                writer.WriteStartElement("InvokeServiceRequest", Namespaces.OpcUaXsd);
            }
            else
            {
                writer.WriteStartElement("InvokeServiceResponse", Namespaces.OpcUaXsd);
            }

            if (m_data != null)
            {
                writer.WriteBase64(m_data, 0, m_data.Length);
            }

            writer.WriteEndElement();
        }
Exemplo n.º 10
0
 protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
 {
     writer.WriteStartElement("Binary");
     writer.WriteBase64(this.messageBytes, 0, this.messageBytes.Length);
     writer.WriteEndElement();
 }
Exemplo n.º 11
0
 public void WriteValue(XmlDictionaryWriter writer, object value)
 {
     if (_isArray)
     {
         switch (_typeCode)
         {
             case TypeCode.Byte:
                 {
                     byte[] arrayValue = (byte[])value;
                     writer.WriteBase64(arrayValue, 0, arrayValue.Length);
                 }
                 break;
             case TypeCode.Boolean:
                 {
                     bool[] arrayValue = (bool[])value;
                     writer.WriteArray(null, _itemName, _itemNamespace, arrayValue, 0, arrayValue.Length);
                 }
                 break;
             case TypeCode.DateTime:
                 {
                     DateTime[] arrayValue = (DateTime[])value;
                     writer.WriteArray(null, _itemName, _itemNamespace, arrayValue, 0, arrayValue.Length);
                 }
                 break;
             case TypeCode.Decimal:
                 {
                     decimal[] arrayValue = (decimal[])value;
                     writer.WriteArray(null, _itemName, _itemNamespace, arrayValue, 0, arrayValue.Length);
                 }
                 break;
             case TypeCode.Int32:
                 {
                     Int32[] arrayValue = (Int32[])value;
                     writer.WriteArray(null, _itemName, _itemNamespace, arrayValue, 0, arrayValue.Length);
                 }
                 break;
             case TypeCode.Int64:
                 {
                     Int64[] arrayValue = (Int64[])value;
                     writer.WriteArray(null, _itemName, _itemNamespace, arrayValue, 0, arrayValue.Length);
                 }
                 break;
             case TypeCode.Single:
                 {
                     float[] arrayValue = (float[])value;
                     writer.WriteArray(null, _itemName, _itemNamespace, arrayValue, 0, arrayValue.Length);
                 }
                 break;
             case TypeCode.Double:
                 {
                     double[] arrayValue = (double[])value;
                     writer.WriteArray(null, _itemName, _itemNamespace, arrayValue, 0, arrayValue.Length);
                 }
                 break;
             default:
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxInvalidUseOfPrimitiveOperationFormatter));
         }
     }
     else
     {
         switch (_typeCode)
         {
             case TypeCode.Boolean:
                 writer.WriteValue((bool)value);
                 break;
             case TypeCode.DateTime:
                 writer.WriteValue((DateTime)value);
                 break;
             case TypeCode.Decimal:
                 writer.WriteValue((Decimal)value);
                 break;
             case TypeCode.Double:
                 writer.WriteValue((double)value);
                 break;
             case TypeCode.Int32:
                 writer.WriteValue((int)value);
                 break;
             case TypeCode.Int64:
                 writer.WriteValue((long)value);
                 break;
             case TypeCode.Single:
                 writer.WriteValue((float)value);
                 break;
             case TypeCode.String:
                 writer.WriteString((string)value);
                 break;
             default:
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxInvalidUseOfPrimitiveOperationFormatter));
         }
     }
 }
Exemplo n.º 12
0
        protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
        {
            writer.WriteStartElement(StreamBodyWriter.StreamElementName);

            byte[] buffer = new byte[BufferSize];
            while (true)
            {
                int actual = this.stream.Read(buffer, 0, buffer.Length);
                if (actual == 0)
                {
                    break;
                }
                writer.WriteBase64(buffer, 0, actual);
            }

            //this.stream.Close();

            writer.WriteEndElement();
        }
 protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
 {
     writer.WriteStartElement("Binary");
     byte[] bytes = Encoding.UTF8.GetBytes(this.contents);
     writer.WriteBase64(bytes, 0, bytes.Length);
     writer.WriteEndElement();
 }
        public override void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager)
        {
            string prefix = XmlSignatureStrings.Prefix;
            XmlDictionaryString ns = dictionaryManager.XmlSignatureDictionary.Namespace;

            writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.SignedInfo, ns);
            if (this.Id != null)
            {
                writer.WriteAttributeString(dictionaryManager.UtilityDictionary.IdAttribute, null, this.Id);
            }
            WriteCanonicalizationMethod(writer, dictionaryManager);
            WriteSignatureMethod(writer, dictionaryManager);
            for (int i = 0; i < this.count; i++)
            {
                writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Reference, ns);
                writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.URI, null);
                writer.WriteString("#");
                writer.WriteString(this.references[i].id);
                writer.WriteEndAttribute();

                writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transforms, ns);
                if (this.addEnvelopedSignatureTransform)
                {
                    writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transform, ns);
                    writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
                    writer.WriteString(dictionaryManager.XmlSignatureDictionary.EnvelopedSignature);
                    writer.WriteEndAttribute();
                    writer.WriteEndElement(); // Transform
                }

                if (this.references[i].useStrTransform)
                {
                    writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transform, ns);
                    writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
                    writer.WriteString(SecurityAlgorithms.StrTransform);
                    writer.WriteEndAttribute();
                    writer.WriteStartElement(XmlSignatureStrings.SecurityJan2004Prefix, XmlSignatureStrings.TransformationParameters, XmlSignatureStrings.SecurityJan2004Namespace);  //<wsse:TransformationParameters>
                    writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.CanonicalizationMethod, ns);
                    writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
                    writer.WriteString(dictionaryManager.SecurityAlgorithmDictionary.ExclusiveC14n);
                    writer.WriteEndAttribute();
                    writer.WriteEndElement(); //CanonicalizationMethod 
                    writer.WriteEndElement(); // TransformationParameters
                    writer.WriteEndElement(); // Transform
                }
                else
                {
                    writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transform, ns);
                    writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
                    writer.WriteString(dictionaryManager.SecurityAlgorithmDictionary.ExclusiveC14n);
                    writer.WriteEndAttribute();
                    writer.WriteEndElement(); // Transform
                }

                writer.WriteEndElement(); // Transforms

                writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.DigestMethod, ns);
                writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
                if (this.digestMethodDictionaryString != null)
                {
                    writer.WriteString(this.digestMethodDictionaryString);
                }
                else
                {
                    writer.WriteString(this.digestMethod);
                }
                writer.WriteEndAttribute();
                writer.WriteEndElement(); // DigestMethod

                byte[] digest = this.references[i].digest;
                writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.DigestValue, ns);
                writer.WriteBase64(digest, 0, digest.Length);
                writer.WriteEndElement(); // DigestValue

                writer.WriteEndElement(); // Reference
            }
            writer.WriteEndElement(); // SignedInfo
        }
Exemplo n.º 15
0
    private static void SimulateWriteFragment(XmlDictionaryWriter writer, bool useFragmentAPI, int nestedLevelsLeft)
    {
        if (nestedLevelsLeft <= 0)
        {
            return;
        }

        Random rndGen = new Random(nestedLevelsLeft);
        int signatureLen = rndGen.Next(100, 200);
        byte[] signature = new byte[signatureLen];
        rndGen.NextBytes(signature);

        MemoryStream fragmentStream = new MemoryStream();

        if (!useFragmentAPI) // simulating in the writer itself
        {
            writer.WriteStartElement("SignatureValue_" + nestedLevelsLeft);
            writer.WriteBase64(signature, 0, signatureLen);
            writer.WriteEndElement();
        }

        if (useFragmentAPI)
        {
            FragmentHelper.Start(writer, fragmentStream);
        }

        writer.WriteStartElement("Fragment" + nestedLevelsLeft);
        for (int i = 0; i < 5; i++)
        {
            writer.WriteStartElement(String.Format("Element{0}_{1}", nestedLevelsLeft, i));
            writer.WriteAttributeString("attr1", "value1");
            writer.WriteAttributeString("attr2", "value2");
        }
        writer.WriteString("This is a text with unicode characters: <>&;\u0301\u2234");
        for (int i = 0; i < 5; i++)
        {
            writer.WriteEndElement();
        }

        // write other nested fragments...
        SimulateWriteFragment(writer, useFragmentAPI, nestedLevelsLeft - 1);

        writer.WriteEndElement(); // Fragment{nestedLevelsLeft}
        writer.Flush();

        if (useFragmentAPI)
        {
            FragmentHelper.End(writer);
            writer.WriteStartElement("SignatureValue_" + nestedLevelsLeft);
            writer.WriteBase64(signature, 0, signatureLen);
            writer.WriteEndElement();

            FragmentHelper.Write(writer, fragmentStream.GetBuffer(), 0, (int)fragmentStream.Length);

            writer.Flush();
        }
    }
Exemplo n.º 16
0
 internal override void WriteSignatureConfirmation(XmlDictionaryWriter writer, string id, byte[] signature)
 {
     if (id == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("id");
     }
     if (signature == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("signature");
     }
     writer.WriteStartElement(XD.SecurityXXX2005Dictionary.Prefix.Value, XD.SecurityXXX2005Dictionary.SignatureConfirmation, XD.SecurityXXX2005Dictionary.Namespace);
     writer.WriteAttributeString(XD.UtilityDictionary.Prefix.Value, XD.UtilityDictionary.IdAttribute, XD.UtilityDictionary.Namespace, id);
     writer.WriteStartAttribute(XD.SecurityXXX2005Dictionary.ValueAttribute, null);
     writer.WriteBase64(signature, 0, signature.Length);
     writer.WriteEndAttribute();
     writer.WriteEndElement();
 }
            public override void WriteTokenCore(XmlDictionaryWriter writer, SecurityToken token)
            {
                string id;
                byte[] rawData;

                WriteBinaryCore(token, out id, out rawData);

                if (rawData == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("rawData");
                }

                writer.WriteStartElement(XD.SecurityJan2004Dictionary.Prefix.Value, ElementName, XD.SecurityJan2004Dictionary.Namespace);
                if (id != null)
                {
                    writer.WriteAttributeString(XD.UtilityDictionary.Prefix.Value, XD.UtilityDictionary.IdAttribute, XD.UtilityDictionary.Namespace, id);
                }
                if (valueTypeUris != null)
                {
                    writer.WriteAttributeString(ValueTypeAttribute, null, this.valueTypeUris[0]);
                }
                if (this.tokenSerializer.EmitBspRequiredAttributes)
                {
                    writer.WriteAttributeString(EncodingTypeAttribute, null, EncodingTypeValueBase64Binary);
                }
                writer.WriteBase64(rawData, 0, rawData.Length);
                writer.WriteEndElement(); // BinarySecurityToken
            }
Exemplo n.º 18
0
            public static async Task WriteValueAsync(XmlDictionaryWriter writer, OperationStreamProvider value)
            {
                if (value == null)
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("value"));

                Stream stream = value.GetStream();
                if (stream == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.XmlInvalidStream)));
                }

                int blockSize = 256;
                int bytesRead = 0;
                byte[] block = new byte[blockSize];
                while (true)
                {
                    bytesRead = await stream.ReadAsync(block, 0, blockSize);
                    if (bytesRead > 0)
                    {
                        // XmlDictionaryWriter has not implemented WriteBase64Async() yet.
                        writer.WriteBase64(block, 0, bytesRead);
                    }
                    else
                    {
                        break;
                    }

                    if (blockSize < 65536 && bytesRead == blockSize)
                    {
                        blockSize = blockSize * 16;
                        block = new byte[blockSize];
                    }
                }

                value.ReleaseStream(stream);
            }
 public static void SerializeClaim(Claim claim, SctClaimDictionary dictionary, XmlDictionaryWriter writer, XmlObjectSerializer serializer)
 {
     // the order in which known claim types are checked is optimized for use patterns
     if (claim == null)
     {
         writer.WriteElementString(dictionary.NullValue, dictionary.EmptyString, string.Empty);
         return;
     }
     else if (ClaimTypes.Sid.Equals(claim.ClaimType))
     {
         writer.WriteStartElement(dictionary.WindowsSidClaim, dictionary.EmptyString);
         WriteRightAttribute(claim, dictionary, writer);
         SerializeSid((SecurityIdentifier)claim.Resource, dictionary, writer);
         writer.WriteEndElement();
         return;
     }
     else if (ClaimTypes.DenyOnlySid.Equals(claim.ClaimType))
     {
         writer.WriteStartElement(dictionary.DenyOnlySidClaim, dictionary.EmptyString);
         WriteRightAttribute(claim, dictionary, writer);
         SerializeSid((SecurityIdentifier)claim.Resource, dictionary, writer);
         writer.WriteEndElement();
         return;
     }
     else if (ClaimTypes.X500DistinguishedName.Equals(claim.ClaimType))
     {
         writer.WriteStartElement(dictionary.X500DistinguishedNameClaim, dictionary.EmptyString);
         WriteRightAttribute(claim, dictionary, writer);
         byte[] rawData = ((X500DistinguishedName)claim.Resource).RawData;
         writer.WriteBase64(rawData, 0, rawData.Length);
         writer.WriteEndElement();
         return;
     }
     else if (ClaimTypes.Thumbprint.Equals(claim.ClaimType))
     {
         writer.WriteStartElement(dictionary.X509ThumbprintClaim, dictionary.EmptyString);
         WriteRightAttribute(claim, dictionary, writer);
         byte[] thumbprint = (byte[])claim.Resource;
         writer.WriteBase64(thumbprint, 0, thumbprint.Length);
         writer.WriteEndElement();
         return;
     }
     else if (ClaimTypes.Name.Equals(claim.ClaimType))
     {
         writer.WriteStartElement(dictionary.NameClaim, dictionary.EmptyString);
         WriteRightAttribute(claim, dictionary, writer);
         writer.WriteString((string)claim.Resource);
         writer.WriteEndElement();
         return;
     }
     else if (ClaimTypes.Dns.Equals(claim.ClaimType))
     {
         writer.WriteStartElement(dictionary.DnsClaim, dictionary.EmptyString);
         WriteRightAttribute(claim, dictionary, writer);
         writer.WriteString((string)claim.Resource);
         writer.WriteEndElement();
         return;
     }
     else if (ClaimTypes.Rsa.Equals(claim.ClaimType))
     {
         writer.WriteStartElement(dictionary.RsaClaim, dictionary.EmptyString);
         WriteRightAttribute(claim, dictionary, writer);
         writer.WriteString(((RSA)claim.Resource).ToXmlString(false));
         writer.WriteEndElement();
         return;
     }
     else if (ClaimTypes.Email.Equals(claim.ClaimType))
     {
         writer.WriteStartElement(dictionary.MailAddressClaim, dictionary.EmptyString);
         WriteRightAttribute(claim, dictionary, writer);
         writer.WriteString(((MailAddress)claim.Resource).Address);
         writer.WriteEndElement();
         return;
     }
     else if (claim == Claim.System)
     {
         writer.WriteElementString(dictionary.SystemClaim, dictionary.EmptyString, string.Empty);
         return;
     }
     else if (ClaimTypes.Hash.Equals(claim.ClaimType))
     {
         writer.WriteStartElement(dictionary.HashClaim, dictionary.EmptyString);
         WriteRightAttribute(claim, dictionary, writer);
         byte[] hash = (byte[])claim.Resource;
         writer.WriteBase64(hash, 0, hash.Length);
         writer.WriteEndElement();
         return;
     }
     else if (ClaimTypes.Spn.Equals(claim.ClaimType))
     {
         writer.WriteStartElement(dictionary.SpnClaim, dictionary.EmptyString);
         WriteRightAttribute(claim, dictionary, writer);
         writer.WriteString((string)claim.Resource);
         writer.WriteEndElement();
         return;
     }
     else if (ClaimTypes.Upn.Equals(claim.ClaimType))
     {
         writer.WriteStartElement(dictionary.UpnClaim, dictionary.EmptyString);
         WriteRightAttribute(claim, dictionary, writer);
         writer.WriteString((string)claim.Resource);
         writer.WriteEndElement();
         return;
     }
     else if (ClaimTypes.Uri.Equals(claim.ClaimType))
     {
         writer.WriteStartElement(dictionary.UrlClaim, dictionary.EmptyString);
         WriteRightAttribute(claim, dictionary, writer);
         writer.WriteString(((Uri)claim.Resource).AbsoluteUri);
         writer.WriteEndElement();
         return;
     }
     else
     {
         // this is an extensible claim... need to delegate to xml object serializer
         serializer.WriteObject(writer, claim);
     }
 }
 static void SerializeSid(SecurityIdentifier sid, SctClaimDictionary dictionary, XmlDictionaryWriter writer)
 {
     byte[] sidBytes = new byte[sid.BinaryLength];
     sid.GetBinaryForm(sidBytes, 0);
     writer.WriteBase64(sidBytes, 0, sidBytes.Length);
 }
        public static void SerializeClaimSet(ClaimSet claimSet, SctClaimDictionary dictionary, XmlDictionaryWriter writer, XmlObjectSerializer serializer, XmlObjectSerializer claimSerializer)
        {
            if (claimSet is X509CertificateClaimSet)
            {
                X509CertificateClaimSet x509ClaimSet = (X509CertificateClaimSet)claimSet;
                writer.WriteStartElement(dictionary.X509CertificateClaimSet, dictionary.EmptyString);
                byte[] rawData = x509ClaimSet.X509Certificate.RawData;
                writer.WriteBase64(rawData, 0, rawData.Length);
                writer.WriteEndElement();
            }
            else if (claimSet == ClaimSet.System)
            {
                writer.WriteElementString(dictionary.SystemClaimSet, dictionary.EmptyString, String.Empty);
            }
            else if (claimSet == ClaimSet.Windows)
            {
                writer.WriteElementString(dictionary.WindowsClaimSet, dictionary.EmptyString, String.Empty);
            }
            else if (claimSet == ClaimSet.Anonymous)
            {
                writer.WriteElementString(dictionary.AnonymousClaimSet, dictionary.EmptyString, String.Empty);
            }
            else if (claimSet is WindowsClaimSet || claimSet is DefaultClaimSet)
            {
                writer.WriteStartElement(dictionary.ClaimSet, dictionary.EmptyString);
                writer.WriteStartElement(dictionary.PrimaryIssuer, dictionary.EmptyString);
                if (claimSet.Issuer == claimSet)
                {
                    writer.WriteElementString(dictionary.NullValue, dictionary.EmptyString, string.Empty);
                }
                else
                {
                    SerializeClaimSet(claimSet.Issuer, dictionary, writer, serializer, claimSerializer);
                }
                writer.WriteEndElement();

                foreach (Claim claim in claimSet)
                {
                    writer.WriteStartElement(dictionary.Claim, dictionary.EmptyString);
                    SerializeClaim(claim, dictionary, writer, claimSerializer);
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
            }
            else
            {
                serializer.WriteObject(writer, claimSet);
            }
        }
 public override void WriteKeyIdentifierClauseCore(XmlDictionaryWriter writer, SecurityKeyIdentifierClause keyIdentifierClause)
 {
     EncryptedKeyIdentifierClause clause = keyIdentifierClause as EncryptedKeyIdentifierClause;
     writer.WriteStartElement(XD.XmlEncryptionDictionary.Prefix.Value, XD.XmlEncryptionDictionary.EncryptedKey, this.NamespaceUri);
     if (clause.EncryptionMethod != null)
     {
         writer.WriteStartElement(XD.XmlEncryptionDictionary.Prefix.Value, XD.XmlEncryptionDictionary.EncryptionMethod, this.NamespaceUri);
         writer.WriteAttributeString(XD.XmlEncryptionDictionary.AlgorithmAttribute, null, clause.EncryptionMethod);
         if (clause.EncryptionMethod == XD.SecurityAlgorithmDictionary.RsaOaepKeyWrap.Value)
         {
             writer.WriteStartElement("", XD.XmlSignatureDictionary.DigestMethod, XD.XmlSignatureDictionary.Namespace);
             writer.WriteAttributeString(XD.XmlSignatureDictionary.Algorithm, null, "http://www.w3.org/2000/09/xmldsig#sha1");
             writer.WriteEndElement();
         }
         writer.WriteEndElement();
     }
     if (clause.EncryptingKeyIdentifier != null)
     {
         this.tokenSerializer.WriteKeyIdentifier(writer, clause.EncryptingKeyIdentifier);
     }
     writer.WriteStartElement(XD.XmlEncryptionDictionary.Prefix.Value, XD.XmlEncryptionDictionary.CipherData, this.NamespaceUri);
     writer.WriteStartElement(XD.XmlEncryptionDictionary.Prefix.Value, XD.XmlEncryptionDictionary.CipherValue, this.NamespaceUri);
     byte[] encryptedKey = clause.GetEncryptedKey();
     writer.WriteBase64(encryptedKey, 0, encryptedKey.Length);
     writer.WriteEndElement();
     writer.WriteEndElement();
     if (clause.CarriedKeyName != null)
     {
         writer.WriteElementString(XD.XmlEncryptionDictionary.Prefix.Value, XD.XmlEncryptionDictionary.CarriedKeyName, this.NamespaceUri, clause.CarriedKeyName);
     }
     writer.WriteEndElement();
 }
Exemplo n.º 23
0
 protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
 {
     writer.WriteStartElement("Binary");
     JavaScriptSerializer jss = new JavaScriptSerializer();
     string serialized = jss.Serialize(this.result);
     byte[] bytes = Encoding.UTF8.GetBytes(serialized);
     writer.WriteBase64(bytes, 0, bytes.Length);
     writer.WriteEndElement();
 }
 public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager)
 {
     writer.WriteStartElement(this.prefix, dictionaryManager.XmlSignatureDictionary.SignatureValue, dictionaryManager.XmlSignatureDictionary.Namespace);
     if (this.id != null)
     {
         writer.WriteAttributeString(dictionaryManager.UtilityDictionary.IdAttribute, null, this.id);
     }
     if (this.signatureText != null)
     {
         writer.WriteString(this.signatureText);
     }
     else
     {
         writer.WriteBase64(this.signatureValue, 0, this.signatureValue.Length);
     }
     writer.WriteEndElement();
 }
Exemplo n.º 25
0
 public override void WriteBase64(byte[] buffer, int index, int count)
 {
     writer.WriteBase64(buffer, index, count);
 }
Exemplo n.º 26
0
        /// <summary>
        /// Writes only the content of the object to the XML document or stream using the specified <see cref="T:System.Xml.XmlDictionaryWriter" />.
        /// </summary>
        /// <param name="writer">An <see cref="T:System.Xml.XmlDictionaryWriter" /> used to write the XML document or stream.</param>
        /// <param name="graph">The object that contains the content to write.</param>
        public override void WriteObjectContent(XmlDictionaryWriter writer, object graph)
        {
            Argument.IsNotNull("writer", writer);

            var memoryStream = new MemoryStream();
            BinarySerializerHelper.DiscoverAndSerialize(memoryStream, graph, _type);
            var bytes = memoryStream.ToByteArray();
            writer.WriteBase64(bytes, 0, bytes.Length);
        }
Exemplo n.º 27
0
        // Methods of BodyWriter
        /// <summary>
        /// Writes out an XML representation of the instance.        
        /// </summary>
        /// <param name="writer">The writer to be used to write out the XML content</param>
        protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
        {
            // Write out the wst:RequestSecurityToken start tag
            writer.WriteStartElement(Constants.Trust.Elements.RequestSecurityToken, Constants.Trust.NamespaceUri);

            // If we have a non-null, non-empty tokenType...
            if (this.TokenType != null && this.TokenType.Length > 0)
            {
                // Write out the wst:TokenType start tag
                writer.WriteStartElement(Constants.Trust.Elements.TokenType, Constants.Trust.NamespaceUri);
                // Write out the tokenType string
                writer.WriteString(this.TokenType);
                writer.WriteEndElement(); // wst:TokenType
            }

            // If we have a non-null, non-empty requestType...
            if (this.requestType != null && this.requestType.Length > 0)
            {
                // Write out the wst:RequestType start tag
                writer.WriteStartElement(Constants.Trust.Elements.RequestType, Constants.Trust.NamespaceUri);
                // Write out the requestType string
                writer.WriteString(this.requestType);
                writer.WriteEndElement(); // wst:RequestType
            }

            // If we have a non-null appliesTo
            if (this.AppliesTo != null)
            {
                // Write out the wsp:AppliesTo start tag
                writer.WriteStartElement(Constants.Policy.Elements.AppliesTo, Constants.Policy.NamespaceUri);
                // Write the appliesTo in WS-Addressing 1.0 format
                this.AppliesTo.WriteTo(AddressingVersion.WSAddressing10, writer);
                writer.WriteEndElement(); // wsp:AppliesTo
            }

            if (this.requestorEntropy!=null)
            {
                writer.WriteStartElement(Constants.Trust.Elements.Entropy, Constants.Trust.NamespaceUri);
                BinarySecretSecurityToken bsst = this.requestorEntropy as BinarySecretSecurityToken;
                if (bsst!=null)
                {
                    writer.WriteStartElement(Constants.Trust.Elements.BinarySecret, Constants.Trust.NamespaceUri);
                    byte[] key = bsst.GetKeyBytes();
                    writer.WriteBase64(key, 0, key.Length);
                    writer.WriteEndElement(); // wst:BinarySecret
                }
                writer.WriteEndElement(); // wst:Entropy
            }

            if (this.keyType != null && this.keyType.Length > 0)
            {
                writer.WriteStartElement(Constants.Trust.Elements.KeyType, Constants.Trust.NamespaceUri);
                writer.WriteString(this.keyType);
                writer.WriteEndElement(); // wst:KeyType
            }

            if (this.KeySize> 0)
            {
                writer.WriteStartElement(Constants.Trust.Elements.KeySize, Constants.Trust.NamespaceUri);
                writer.WriteValue(this.KeySize );
                writer.WriteEndElement(); // wst:KeySize
            }

            writer.WriteEndElement(); // wst:RequestSecurityToken
        }
 public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager)
 {
     writer.WriteStartElement(this.prefix ?? "", dictionaryManager.XmlSignatureDictionary.DigestValue, dictionaryManager.XmlSignatureDictionary.Namespace);
     if (this.digestText != null)
     {
         writer.WriteString(this.digestText);
     }
     else
     {
         writer.WriteBase64(this.digestValue, 0, this.digestValue.Length);
     }
     writer.WriteEndElement();
 }
Exemplo n.º 29
0
            public override void WriteKeyIdentifierClauseCore(XmlDictionaryWriter writer, SecurityKeyIdentifierClause keyIdentifierClause)
            {
                EncryptedKeyIdentifierClause encryptedKeyClause = keyIdentifierClause as EncryptedKeyIdentifierClause;

                writer.WriteStartElement(XD.XmlEncryptionDictionary.Prefix.Value, XD.XmlEncryptionDictionary.EncryptedKey, NamespaceUri);

                if (encryptedKeyClause.EncryptionMethod != null)
                {
                    writer.WriteStartElement(XD.XmlEncryptionDictionary.Prefix.Value, XD.XmlEncryptionDictionary.EncryptionMethod, NamespaceUri);
                    writer.WriteAttributeString(XD.XmlEncryptionDictionary.AlgorithmAttribute, null, encryptedKeyClause.EncryptionMethod);
                    if (encryptedKeyClause.EncryptionMethod == XD.SecurityAlgorithmDictionary.RsaOaepKeyWrap.Value)
                    {
                        writer.WriteStartElement(XmlSignatureStrings.Prefix, XD.XmlSignatureDictionary.DigestMethod, XD.XmlSignatureDictionary.Namespace);
                        writer.WriteAttributeString(XD.XmlSignatureDictionary.Algorithm, null, SecurityAlgorithms.Sha1Digest);
                        writer.WriteEndElement();
                    }
                    writer.WriteEndElement();
                }

                if (encryptedKeyClause.EncryptingKeyIdentifier != null)
                {
                    this.securityTokenSerializer.WriteKeyIdentifier(writer, encryptedKeyClause.EncryptingKeyIdentifier);
                }

                writer.WriteStartElement(XD.XmlEncryptionDictionary.Prefix.Value, XD.XmlEncryptionDictionary.CipherData, NamespaceUri);
                writer.WriteStartElement(XD.XmlEncryptionDictionary.Prefix.Value, XD.XmlEncryptionDictionary.CipherValue, NamespaceUri);
                byte[] encryptedKey = encryptedKeyClause.GetEncryptedKey();
                writer.WriteBase64(encryptedKey, 0, encryptedKey.Length);
                writer.WriteEndElement();
                writer.WriteEndElement();

                if (encryptedKeyClause.CarriedKeyName != null)
                {
                    writer.WriteElementString(XD.XmlEncryptionDictionary.Prefix.Value, XD.XmlEncryptionDictionary.CarriedKeyName, NamespaceUri, encryptedKeyClause.CarriedKeyName);
                }

                writer.WriteEndElement();
            }
 protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
 {
     writer.WriteStartElement("Binary");
     writer.WriteBase64(content, 0, content.Length);
     writer.WriteEndElement();
 }
 protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
 {
     writer.WriteStartElement("Binary");
     byte[] buffer = JSONPSupportInspector.encoding.GetBytes(this.content);
     writer.WriteBase64(buffer, 0, buffer.Length);
     writer.WriteEndElement();
 }
Exemplo n.º 32
0
 protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
 {
     writer.WriteStartElement(BinaryBodyReader.BinaryElementName);
     writer.WriteBase64(_data, 0, _data.Length);
     writer.WriteEndElement();
 }
Exemplo n.º 33
0
 protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
 {
     byte[] binaryContent = Encoding.UTF8.GetBytes("Hello world!");
     writer.WriteStartElement("Binary");
     writer.WriteBase64(binaryContent, 0, binaryContent.Length);
     writer.WriteEndElement();
 }