Click here to Skip to main content
15,885,366 members
Home / Discussions / C#
   

C#

 
GeneralRe: Obtaining a generated hwnd handle without making a window Pin
cimnik0295-Jan-05 10:23
cimnik0295-Jan-05 10:23 
GeneralRe: Obtaining a generated hwnd handle without making a window Pin
Heath Stewart5-Jan-05 14:52
protectorHeath Stewart5-Jan-05 14:52 
GeneralEmail Problem Pin
Julianne_juju4-Jan-05 15:16
Julianne_juju4-Jan-05 15:16 
GeneralRe: Email Problem Pin
Heath Stewart4-Jan-05 20:37
protectorHeath Stewart4-Jan-05 20:37 
GeneralRe: Email Problem Pin
Julianne_juju6-Jan-05 6:17
Julianne_juju6-Jan-05 6:17 
GeneralWSE 2.0 and Encryption Pin
Bill Dean4-Jan-05 14:48
Bill Dean4-Jan-05 14:48 
GeneralRe: WSE 2.0 and Encryption Pin
Heath Stewart4-Jan-05 20:31
protectorHeath Stewart4-Jan-05 20:31 
GeneralRe: WSE 2.0 and Encryption Pin
Bill Dean5-Jan-05 3:26
Bill Dean5-Jan-05 3:26 
Thanks Heath,

I should know better than to post such a detail-bare question. My bad.

My client application is a .net web application, running on the same machine that the web service runs on: a win2kpro development machine. I am trying to: 1) sign the request from the client with an x509 cert. 2) sign the response with an x509 cert, and 3) encrypt the response with an x509 cert.
1) and 2) are no problem. But when I add the code for 3) I get this exception:
System.Web.Services.Protocols.SoapHeaderException: Server unavailable, please try later ---> System.ComponentModel.Win32Exception: Bad Key at Microsoft.Web.Services2.Security.Cryptography.RSACryptoServiceProvider.Encrypt(Byte[] plaintext, Boolean useOAEP) at Microsoft.Web.Services2.Security.Cryptography.RSA15KeyExchangeFormatter.EncryptKey(Byte[] plainKey) at Microsoft.Web.Services2.Security.EncryptedKey.Encrypt() at Microsoft.Web.Services2.Security.EncryptedKey.GetXml(XmlDocument document) at Microsoft.Web.Services2.Security.Security.SerializeXml(SoapEnvelope document) at Microsoft.Web.Services2.Security.SecurityOutputFilter.ProcessHeader(Security security, SoapEnvelope envelope) at Microsoft.Web.Services2.Security.SecurityOutputFilter.ProcessMessage(SoapEnvelope envelope) at Microsoft.Web.Services2.Pipeline.ProcessOutputMessage(SoapEnvelope envelope) at Microsoft.Web.Services2.WebServicesExtension.AfterSerializeServer(SoapServerMessage message) --- End of inner exception stack trace --- 

This exception is reported by the client and occurs sometime after the return in the web method is called.
The stack trace is:
SoapHeaderException: System.Web.Services.Protocols.SoapHeaderException: Server unavailable, please try later ---> System.ComponentModel.Win32Exception: Bad Key
   at Microsoft.Web.Services2.Security.Cryptography.RSACryptoServiceProvider.Encrypt(Byte[] plaintext, Boolean useOAEP)
   at Microsoft.Web.Services2.Security.Cryptography.RSA15KeyExchangeFormatter.EncryptKey(Byte[] plainKey)
   at Microsoft.Web.Services2.Security.EncryptedKey.Encrypt()
   at Microsoft.Web.Services2.Security.EncryptedKey.GetXml(XmlDocument document)
   at Microsoft.Web.Services2.Security.Security.SerializeXml(SoapEnvelope document)
   at Microsoft.Web.Services2.Security.SecurityOutputFilter.ProcessHeader(Security security, SoapEnvelope envelope)
   at Microsoft.Web.Services2.Security.SecurityOutputFilter.ProcessMessage(SoapEnvelope envelope)
   at Microsoft.Web.Services2.Pipeline.ProcessOutputMessage(SoapEnvelope envelope)
   at Microsoft.Web.Services2.WebServicesExtension.AfterSerializeServer(SoapServerMessage message)
   --- End of inner exception stack trace ---]
   System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
   System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   SecureServiceLib.RestekSecureServiceClient2.Invoke(String methodName, Object[] parameters) in c:\projects\securewebservice\secureservicesolution\secureservicelib\clsresteksecureserviceclient2.cs:26
   WSE2Client.localhost.Service2.HelloWorld() in c:\inetpub\wwwroot\WSE2Client\Web References\localhost\Reference.cs:45
   WSE2Client.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\wse2client\webform1.aspx.cs:24
   System.Web.UI.Control.OnLoad(EventArgs e)
   System.Web.UI.Control.LoadRecursive()
   System.Web.UI.Page.ProcessRequestMain()


The code that adds the encryption is:
protected virtual void AddSignAndEncryptInformation()
{
	_addResponseEncryption();
	_addResponseSignature(); //omitted from this post
}
private void _addResponseEncryption()
{
	SoapContext responseContext = ResponseSoapContext.Current;
	X509SecurityToken e =this.GetResponseEncryptingSecurtyToken ();
	responseContext.Security.Tokens.Add (e);
	responseContext.Security.Elements.Add (new EncryptedData (e));
}
protected virtual X509SecurityToken GetResponseEncryptingSecurtyToken() 
{            
	X509SecurityToken securityToken = null;
	//localmachine
	X509CertificateStore store = X509CertificateStore.LocalMachineStore(X509CertificateStore.MyStore);

	bool open = store.OpenRead();
	try 
	{
		//this is the thumb print of the cert!
		byte[] certHash=this.GetHash ("RestekClient");
		X509CertificateCollection certs =store.FindCertificateByHash (certHash);		

		X509Certificate cert =
					((X509Certificate) certs[0]);

		if (cert != null) 
		{
			securityToken = new X509SecurityToken(cert);
		}
	} 
	finally 
	{
		if (store != null)
			store.Close();
	}
	bool b=	securityToken.Certificate.SupportsDataEncryption ;
	if (b)
	        return securityToken;
	throw new Exception ("Cert does not support data encryption");
}
private byte[] GetHash(string KeyName)
{
	byte[] b=null;
	if (KeyName=="RestekClient")
		b=new byte[] {0xee, 0x2b, 0xba, 0xb4, 0xeb, 0x6d, 0xff, 0x1e, 0xf2, 0xc4, 0x70, 0xf9, 0x10, 0xa5, 0xfd, 0xf4, 0x03, 0xd8, 0xfb, 0xaf};

	if (KeyName=="RestekServer")
		b=new byte[] {0xab, 0xaf, 0xe2, 0x9d, 0xa2, 0x0a, 0xda, 0xd1, 0x02, 0x0d, 0xee, 0x50, 0xf1, 0xf1, 0xb5, 0xc1, 0x22, 0x4c, 0x1d, 0xe3};

	if (KeyName=="WSEQuickStartServer")
		b=new byte[] {0x87, 0xd9, 0x2c, 0xca, 0xb7, 0x14, 0xc3, 0x0d, 0xb0, 0xe0, 0xba, 0xe6, 0xb9, 0xb0, 0xb6, 0x5b, 0x5d, 0x6d, 0xf7, 0xcf};
	return(b);
}

and the trivial webmethod I am using to test all this stuff is:
[WebMethod]
public string HelloWorld()
{
	this.AssureCredentialsValid (); //omitted from this post
	this.AddSignAndEncryptInformation ();
	return ("Hello World");
}

According to the WSE2 Cert tool, the ASPNET user has full control over the private key file for the RestekClient cert. Yes, the cert is self-signed. Any further guidance anyone can provide will be greatly appreciated.

Thanks again
Bill
GeneralRe: WSE 2.0 and Encryption Pin
Heath Stewart5-Jan-05 7:09
protectorHeath Stewart5-Jan-05 7:09 
GeneralRe: WSE 2.0 and Encryption Pin
Bill Dean5-Jan-05 9:35
Bill Dean5-Jan-05 9:35 
GeneralRe: WSE 2.0 and Encryption Pin
Heath Stewart5-Jan-05 14:51
protectorHeath Stewart5-Jan-05 14:51 
GeneralRe: WSE 2.0 and Encryption Pin
Bill Dean6-Jan-05 4:36
Bill Dean6-Jan-05 4:36 
GeneralSocket receiving too slowly Pin
tantiboh4-Jan-05 13:51
tantiboh4-Jan-05 13:51 
GeneralRe: Socket receiving too slowly Pin
Heath Stewart4-Jan-05 20:17
protectorHeath Stewart4-Jan-05 20:17 
GeneralRe: Socket receiving too slowly Pin
tantiboh5-Jan-05 18:52
tantiboh5-Jan-05 18:52 
GeneralXmodem implimentation Pin
therealmccoy4-Jan-05 12:35
therealmccoy4-Jan-05 12:35 
GeneralRe: Xmodem implimentation Pin
Heath Stewart4-Jan-05 13:37
protectorHeath Stewart4-Jan-05 13:37 
GeneralRe: Xmodem implimentation Pin
therealmccoy4-Jan-05 14:29
therealmccoy4-Jan-05 14:29 
GeneralRe: Xmodem implimentation Pin
Heath Stewart4-Jan-05 20:12
protectorHeath Stewart4-Jan-05 20:12 
GeneralString output in C# from a C++ dll Pin
vinayakdl4-Jan-05 12:29
vinayakdl4-Jan-05 12:29 
GeneralRe: String output in C# from a C++ dll Pin
Heath Stewart4-Jan-05 13:34
protectorHeath Stewart4-Jan-05 13:34 
GeneralRe: String output in C# from a C++ dll Pin
vinayakdl5-Jan-05 4:53
vinayakdl5-Jan-05 4:53 
GeneralRe: String output in C# from a C++ dll Pin
Heath Stewart5-Jan-05 7:04
protectorHeath Stewart5-Jan-05 7:04 
GeneralRe: String output in C# from a C++ dll Pin
vinayakdl6-Jan-05 9:55
vinayakdl6-Jan-05 9:55 
GeneralRe: String output in C# from a C++ dll Pin
Heath Stewart6-Jan-05 12:04
protectorHeath Stewart6-Jan-05 12:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.