public override SecurityKeyIdentifierClause CreateKeyIdentifierClauseFromTokenXmlCore(XmlElement issuedTokenXml,
                                                                                                  SecurityTokenReferenceStyle tokenReferenceStyle)
            {
                TokenReferenceStyleHelper.Validate(tokenReferenceStyle);

                switch (tokenReferenceStyle)
                {
                case SecurityTokenReferenceStyle.Internal:
                    return(CreateDirectReference(issuedTokenXml, UtilityStrings.IdAttribute, UtilityStrings.Namespace, TokenType));

                case SecurityTokenReferenceStyle.External:
                    string encoding    = issuedTokenXml.GetAttribute(EncodingTypeAttributeString, null);
                    string encodedData = issuedTokenXml.InnerText;

                    byte[] binaryData;
                    if (encoding == null || encoding == EncodingTypeValueBase64Binary)
                    {
                        binaryData = Convert.FromBase64String(encodedData);
                    }
                    else if (encoding == EncodingTypeValueHexBinary)
                    {
                        binaryData = HexBinary.Parse(encodedData).Value;
                    }
                    else
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.UnknownEncodingInBinarySecurityToken));
                    }

                    return(CreateKeyIdentifierClauseFromBinaryCore(binaryData));

                default:
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(tokenReferenceStyle)));
                }
            }
Esempio n. 2
0
            public override SecurityKeyIdentifierClause ReadClause(XmlDictionaryReader reader, byte[] derivationNonce, int derivationLength, string tokenType)
            {
                string encodingType = reader.GetAttribute(XD.SecurityJan2004Dictionary.EncodingType, null);

                if (encodingType == null)
                {
                    encodingType = DefaultEncodingType;
                }

                reader.ReadStartElement();

                byte[] bytes;
                if (encodingType == EncodingTypeValueBase64Binary)
                {
                    bytes = reader.ReadContentAsBase64();
                }
                else if (encodingType == EncodingTypeValueHexBinary)
                {
                    bytes = HexBinary.Parse(reader.ReadContentAsString()).Value;
                }
                else if (encodingType == EncodingTypeValueText)
                {
                    bytes = new UTF8Encoding().GetBytes(reader.ReadContentAsString());
                }
                else
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityMessageSerializationException(SR.GetString(SR.UnknownEncodingInKeyIdentifier)));
                }

                reader.ReadEndElement();

                return(CreateClause(bytes, derivationNonce, derivationLength));
            }
Esempio n. 3
0
        // преобразование массива байт в строку, где каждый символ представлен двумя 16-ричными цифрами
        // {0xFF, 0xD1, 0xFF, 0xD2}  -->  "FFD1FFD2"
        public static string ToHexString(this byte[] value)
        {
            if ((value == null) || (value.Length == 0))
            {
                return(null);
            }

            System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary shb = new System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary(value);
            return(shb.ToString());
        }
Esempio n. 4
0
        private String IDToString()
        {
            String res = "";

            res = new System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary(this.ID).ToString();
            res = res.Insert(2, ":");
            res = res.Insert(5, ":");
            res = res.Insert(8, ":");
            res = res.Insert(11, ":");
            return(res);
        }
Esempio n. 5
0
        int ReadBinaryContent(byte[] buffer, int offset, int count, bool isBase64)
        {
            CryptoHelper.ValidateBufferBounds(buffer, offset, count);

            //
            // Concatentate text nodes to get entire element value before attempting to convert
            // XmlDictionaryReader.CreateDictionaryReader( XmlReader ) creates a reader that returns base64 in a single text node
            // XmlDictionaryReader.CreateTextReader( Stream ) creates a reader that produces multiple text and whitespace nodes
            // Attribute nodes consist of only a single value
            //
            if (this.contentStream == null)
            {
                string encodedValue;
                if (NodeType == XmlNodeType.Attribute)
                {
                    encodedValue = Value;
                }
                else
                {
                    StringBuilder fullText = new StringBuilder(1000);
                    while (NodeType != XmlNodeType.Element && NodeType != XmlNodeType.EndElement)
                    {
                        switch (NodeType)
                        {
                        // concatenate text nodes
                        case XmlNodeType.Text:
                            fullText.Append(Value);
                            break;

                        // skip whitespace
                        case XmlNodeType.Whitespace:
                            break;
                        }

                        Read();
                    }

                    encodedValue = fullText.ToString();
                }

                byte[] value = isBase64 ? Convert.FromBase64String(encodedValue) : HexBinary.Parse(encodedValue).Value;
                this.contentStream = new MemoryStream(value);
            }

            int read = this.contentStream.Read(buffer, offset, count);

            if (read == 0)
            {
                this.contentStream.Close();
                this.contentStream = null;
            }

            return(read);
        }
            public override SecurityToken ReadTokenCore(XmlDictionaryReader reader, SecurityTokenResolver tokenResolver)
            {
                string wsuId        = reader.GetAttribute(XD.UtilityDictionary.IdAttribute, XD.UtilityDictionary.Namespace);
                string valueTypeUri = reader.GetAttribute(ValueTypeAttribute, null);
                string encoding     = reader.GetAttribute(EncodingTypeAttribute, null);

                byte[] binaryData;
                if (encoding == null || encoding == EncodingTypeValueBase64Binary)
                {
                    binaryData = reader.ReadElementContentAsBase64();
                }
                else if (encoding == EncodingTypeValueHexBinary)
                {
                    binaryData = HexBinary.Parse(reader.ReadElementContentAsString()).Value;
                }
                else
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.UnknownEncodingInBinarySecurityToken));
                }

                return(ReadBinaryCore(wsuId, valueTypeUri, binaryData));
            }
Esempio n. 7
0
        public override void Execute()
        {
            if (InputBin?.Length > 0)
            {
                OutputText = new System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary(InputBin).ToString();
            }
            else
            {
                OutputText = string.Empty;
            }

            if (!string.IsNullOrEmpty(InputText))
            {
                OutputBin = Enumerable.Range(0, InputText.Length)
                            .Where(x => x % 2 == 0)
                            .Select(x => Convert.ToByte(InputText.Substring(x, 2), 16))
                            .ToArray();
            }
            else
            {
                OutputBin = new byte[] { }
            };
        }
    }
Esempio n. 8
0
        private static string BytesToString(byte[] bytes)
        {
            var soapBinary = new System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary(bytes);

            return(soapBinary.ToString());
        }
Esempio n. 9
0
 public static byte[] GetStringToBytes(string value)
 {
     System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary soapHexBinary = System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary.Parse(value);
     return(soapHexBinary.Value);
 }
Esempio n. 10
0
 public static string GetBytesToString(byte[] value)
 {
     System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary soapHexBinary = new System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary(value);
     return(soapHexBinary.ToString());
 }
Esempio n. 11
0
 // преобразование строки, в которой каждый символ представлен двумя 16-ричными цифрами, в массив байтов
 // "FFD1FFD2" --> {0xFF, 0xD1, 0xFF, 0xD2}
 public static byte[] HexToByteArray(this string hexString)
 {
     System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary shb = System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary.Parse(hexString);
     return(shb.Value);
 }
Esempio n. 12
0
        /// <summary>
        /// Parse byte array into a string
        /// </summary>
        /// <param name="ba">Byte array to be converted</param>
        /// <param name="separator">Character to separate bytes on string representation</param>
        /// <returns></returns>
        public static string ByteArrayToString(byte[] ba, string separator = " ")
        {
            var shb = new System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary(ba);

            return(System.Text.RegularExpressions.Regex.Replace(shb.ToString(), @"\w{2}(?!$)", "$0" + separator));
        }
Esempio n. 13
0
 private static string BytesToString(byte[] bytes)
 {
     var soapBinary = new System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary(bytes);
     return soapBinary.ToString();
 }