472,782 Members | 1,162 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,782 software developers and data experts.

string "changing" length

I've a webservice with a string parameter.

I call this webservice passing a string that is 1129 chars length. On the
webservice, the received string is 1146 length (I tested sizes with
string.length property). String's contents seem be teh same, so I think
there is some encoding difference (is this possibile?). The problem is that
I sign this string, so signature validation fails :(

What can be the problem?

thanks

Aug 13 '06 #1
4 1910
Hello Trapulo,

Glad to see you again. BTW,I've posted my reply in your previous thread
"secure a WS called by GPRS".

As for the string length changing issue you mentioned here, would you
provide some further information about the client and server-side code
logic on how you pass the string into webservice message and where did you
check the string length?

Also, as you mentioned that you're added signing on the string, would you
also provide the code about how to sign the string? You can also test the
behavior by passing the string without performing any signing or encyption
against the SOAP message to see what happens.

Based on my experience, if the value remains the same on both side, it is
likely that the xml encoding make the string lengh different. For example,
for string that passed through SOAP message(xml document), those particular
chars like (<, , / .... ) maybe html encoded to their escaped format
(like &lt;, &rt; ....). So is there any paricular strings in the one
which raise the problem? You can test the behavior through different string
contents.

Please let me know if you have any other finding.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Aug 14 '06 #2
Hi Trapulo,

Have you got any progress or resolved this issue? Please feel free to let
me know if there is anything else we can help.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Aug 16 '06 #3
>Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
>news:eC**************@TK2MSFTNGXA01.phx.gbl...

Hello again, Steven
As for the string length changing issue you mentioned here, would you
provide some further information about the client and server-side code
logic on how you pass the string into webservice message and where did you
check the string length?
So, I read an xml file from disk with this code:
Dim file As IO.TextReader = IO.File.OpenText(f)

Dim command As New LoadLogCommand

command.Content = file.ReadToEnd()

command.ContentOffset = 0

command.OriginalName = IO.Path.GetFileName(f)

command.TotalSize = command.Content.Length
The problem is with "Content". My LoadLogCommand inserts the code in an xml
document, with this internal sub:
Public Overrides Sub WriteXml(ByVal writer As System.Xml.XmlTextWriter)

writer.WriteStartElement("LoadLog")

writer.WriteElementString("OriginalName", Me.OriginalName)

writer.WriteElementString("ContentOffset", Me.ContentOffset.ToString)

writer.WriteElementString("Content", Me.Content)

writer.WriteElementString("TotalSize", Me.TotalSize.ToString)

writer.WriteEndElement() ' ActivityLog

End Sub

Then, the xml code is loaded to a webservice as a string parameter. The
signature is calculated on the string that contains the xml, with this code:
Dim rsa As New System.Security.Cryptography.RSACryptoServiceProvi der

rsa.FromXmlString(xmlKey)

Return rsa.SignData(Text.Encoding.UTF8.GetBytes(_xmlCache ), New
Security.Cryptography.SHA1CryptoServiceProvider)

The signature is passed to the webservice as an other byte() parameter.

The webservice gets the xml and the signature, and checks the signature with
this code:

Dim rsa As New System.Security.Cryptography.RSACryptoServiceProvi der

rsa.FromXmlString(xmlKey)

Dim hashAlg As New Security.Cryptography.SHA1CryptoServiceProvider

Return rsa.VerifyData(Text.Encoding.UTF8.GetBytes(xmlPack et), hashAlg,
signature)
This test fails because the xml I signed, and the xml I received, have
different length.

I noticed this, if can help you: I upload xml files created from .NET with
xml namespace's objects. These file work. Now I've opened a file with MS
Word, changed a value, saved it. This doesn't work, because the signature is
not validated.
Also, as you mentioned that you're added signing on the string, would you
also provide the code about how to sign the string? You can also test the
behavior by passing the string without performing any signing or encyption
against the SOAP message to see what happens.
It is the same. SOAP message is not encrypted, and the xml string and the
signature are passed as two distinct parameters.
Based on my experience, if the value remains the same on both side, it is
likely that the xml encoding make the string lengh different. For example,
for string that passed through SOAP message(xml document), those
particular
chars like (<, , / .... ) maybe html encoded to their escaped format
(like &lt;, &rt; ....). So is there any paricular strings in the one
which raise the problem? You can test the behavior through different
string
contents.
Yes, the are xml documents so I think it's something related to this. But I
can't understant what is the problem, and why some xml files work, and some
others doesn't. The problem howevere is sure with the xml loaded from disk,
because if I remove it and I upload only the general xml (that is the xml I
create at runtime, where the xml loaded from disk is only the
\LoadLog\Content node ), upload works always.
thank you
Aug 28 '06 #4
Hi Trapulo,

Thanks for the followup.

Yes, if you directly write xml document or fragment into webservice SOAP
message as string, the runtime will peform html encoding on the string so
as to escape those particular chars (like < , ....).

I think you can consider manually use HttpUtility.HtmlEncode method to
encode the string before add it into your object which will be transfered
by the SOAP message. thus, the runtime will not do the additional
converting.

#HttpUtility.HtmlEncode Method (String, TextWriter)
http://msdn2.microsoft.com/en-us/library/1ew0dw8s.aspx

Please feel free to let me know if you get any new finding.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Aug 31 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Vic | last post by:
Dear All, I have a database of laboratory records in Access 2000. There is one form which acts as an interface to input experimetal data. This form incorporates information from several tables....
1
by: jphelan | last post by:
I ran a MS Access Analyzer program that suggested changing, "rst.FindFirst strcriteria" to using the, "Seek" instead. I tried making the change. I get a Compile error that says, "Argument is not...
2
by: Steve | last post by:
I am new to this newsgroup & to .NET in general. I have been playing around with Visual Studio .NET, building and rendering web pages using VB "code behind" files. My problem / question is; How...
14
by: Arne | last post by:
A lot of Firefox users I know, says they have problems with validation where the ampersand sign has to be written as &amp; to be valid. I don't have Firefox my self and don't wont to install it only...
5
by: Jeroen van den Broek | last post by:
db2 8.1 fp13 on Linux for zSeries (64-bit) Every invocation of db2pd except for the "-version" and "-osinfo" options gives following message: ======================================= Database...
25
by: william.hooper | last post by:
here is my form: <html> <head></head> <body> <FORM ACTION="code.php" method="post"> <INPUT TYPE=SUBMIT NAME="arty.jpg" VALUE="Action"> </FORM>
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.