Can i cache a WSE X509Certificate ? Is it threadsafe?
- From: "Ste" <noemail@xxxxxxxxxx>
- Date: Mon, 14 Nov 2005 21:38:17 -0000
I am using WSE2.0 over a secure SSL connection. Each time i send a request
to the SSL webserver, i retreive a certificate from the certificate store.
To avoid the overhead of retrieving the certificate from the store for each
invocation of the web services method can i cache it?
Would this be safe inside a multithreaded web service environment..?
Can multiple threads use a shared X509Certificate resource?
Pseudo code example of current code and proposed replacement is pasted
below... should i have any reservations about doing this?
//
// Current code..
//
// client will invoke the webservice method HelloWorld, which in turn will
call IssueSecurityToken
[WebService]
void HelloWorld()
{
// do whatever....
MySecurityToken = IssueSecurityToken(SecurityToken securitytoken)
WebServicesClientProtocol wseproxy = new WebServicesClientProtocol
(); // assume allocated correctly in real code!!
wseproxy.ClientCertificates.Add( GetSSLCertificate() );
}
public MySecurityToken IssueSecurityToken(SecurityToken securitytoken)
{
// get the X509 certificate needed for this SSL connection
SoapHttpOutputChannel httpChannel = (SoapHttpOutputChannel)
base.Channel;
httpChannel.Options.ClientCertificates.Add( GetSSLCertificate() ) ;
// cert is retrieved each time
// talk to token service etc..
}
public static X509Certificate GetSSLCertificate()
{
store = X509CertificateStore.LocalMachineStore(
X509CertificateStore.MyStore );
store.OpenRead();
X509CertificateCollection systemCertificateCol =
store.FindCertificateBySubjectString(Configuration.CertificateSubject);
return systemCertificateCol[0];
}
//
// proposed replacement would be
//
static X509Certificate x509Cert = null; // is this safe to cache in a
multithreaded env??
public static X509Certificate GetSSLCertificate()
{
if(x509Cert == null)
{
store = X509CertificateStore.LocalMachineStore(
X509CertificateStore.MyStore );
store.OpenRead();
X509CertificateCollection systemCertificateCol =
store.FindCertificateBySubjectString(Configuration.CertificateSubject);
x509Cert = systemCertificateCol[0];
}
return x509Cert
}
.
- Prev by Date: Re: Session Variables in WSE 3.0
- Next by Date: Frustrations with sample apps
- Previous by thread: Re: X509 WSE Certificate Tool
- Next by thread: Frustrations with sample apps
- Index(es):
Relevant Pages
|