News  [SoftwareSite

Latest News
Older News
RSS Feed
 
Complete Projects
Useful Classes
Top Downloads
Message Board
AllAPI.net
 
Send Comments
Software License
Mentalis.org Buttons
Donate
 
Forums -> Security Library Forum
 
Index was outside the bounds of the array  
by Curt Wu [curt at droc dot ca]
posted on 2004/06/15

I am using version 1.1 for communicating with RRP server, this is my code:
<%@ Page Language="C#"%>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Net" %>
<%@ import Namespace="System.Net.Sockets" %>
<%@ import Namespace="Org.Mentalis.Security.Ssl" %>
<%@ import Namespace="Org.Mentalis.Security.Certificates" %>
<script runat=server>
private SecureSocket m_Socket;
private byte[] m_DataBuffer;
void page_load(){
// The path to the certificate.
string Certificatefile = Server.MapPath("droa.pfx");

// Load the certificate into an X509Certificate object.
Certificate cert = Certificate.CreateFromPfxFile(Certificatefile,"password",false);

m_Socket=getConnection(cert);
Response.Write(receive(m_Socket));
m_Socket.Close();
}
private void send(string data,SecureSocket con) {
byte[] toSend = Encoding.ASCII.GetBytes(data);
int sent = con.Send(toSend);
while(sent != toSend.Length) {
sent += con.Send(toSend, sent, toSend.Length - sent, SocketFlags.None);
}
}
private string receive(SecureSocket con) {
byte[] buffer = new byte[8192];
string ret = "";
int r = con.Receive(buffer);
ret += Encoding.ASCII.GetString(buffer, 0, r);
//while(ret.IndexOf("\r\n.\r\n")<=0) {
while(false){
r = con.Receive(buffer);
ret += Encoding.ASCII.GetString(buffer, 0, r);
}
return ret;
}
private SecureSocket getConnection(Certificate cer){
SecurityOptions options = new SecurityOptions(
SecureProtocol.Ssl3 | SecureProtocol.Tls1, // use SSL3 or TLS1
cer, // do not use client authentication
ConnectionEnd.Client, // this is the client side
CredentialVerification.None, // do not check the certificate -- this should not be used in a real-life application :-)
null, // not used with automatic certificate verification
"www.droa.com", // this is the common name of the Microsoft web server
SecurityFlags.Default, // use the default security flags
SslAlgorithms.SECURE_CIPHERS, // only use secure ciphers
null); // do not process certificate requests.
// create the securesocket with the specified security options
SecureSocket m_Socket = new SecureSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp, options);
// resolve www.microsoft.com
IPEndPoint endpoint = new IPEndPoint(Dns.Resolve("trrp1.verisign-grs.net").AddressList[0], 648);
// start connecting to www.microsoft.com
m_Socket.Connect(endpoint);
Response.Write(receive(m_Socket));
return m_Socket;
}


</script>

and I got the following error:
[IndexOutOfRangeException: Index was outside the bounds of the array.]
Org.Mentalis.Security.Ssl.Shared.CompatibilityLayer.ProcessServerHello(Byte[] bytes, Int32 offset, Int32 size) +615
Org.Mentalis.Security.Ssl.Shared.CompatibilityLayer.ProcessHello(Byte[] bytes, Int32 offset, Int32 size) +28
Org.Mentalis.Security.Ssl.Shared.SocketController.OnReceive(IAsyncResult ar) +110

[SecurityException: An error occurs while communicating with the remote host.
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Org.Mentalis.Security.Ssl.Shared.CompatibilityLayer.ProcessServerHello(Byte[] bytes, Int32 offset, Int32 size)
at Org.Mentalis.Security.Ssl.Shared.CompatibilityLayer.ProcessHello(Byte[] bytes, Int32 offset, Int32 size)
at Org.Mentalis.Security.Ssl.Shared.SocketController.OnReceive(IAsyncResult ar)]
Org.Mentalis.Security.Ssl.SecureSocket.EndReceive(IAsyncResult asyncResult) +230
Org.Mentalis.Security.Ssl.SecureSocket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) +72
Org.Mentalis.Security.Ssl.SecureSocket.Receive(Byte[] buffer) +19
ASP.test_aspx.receive(SecureSocket con) +39
ASP.test_aspx.getConnection(Certificate cer) +170
ASP.test_aspx.page_load() +50
System.Web.Util.ArglessEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +10
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731

anybody can help?

by Pieter Philippaerts [Pieter at mentalis dot org]
posted on 2004/07/04

Thanks for reporting this bug. We've uploaded a fixed version of the library.

 

Copyright © 2002-2007, The Mentalis.org Team. All rights reserved.
This site is located at http://www.mentalis.org/
Send comments to the webmaster.