Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Security / December 2006

Tip: Looking for answers? Try searching our database.

SslStream and Certificates - Not Supported Exception.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
awburns@gmail.com - 18 Dec 2006 11:46 GMT
I'm trying to knock up a simple demonstration for myself to try using
SSL to send and receive a simple message. I've based this on the code
on the MSDN site -
http://msdn2.microsoft.com/en-us/library/system.net.security.sslstream.aspx
- and I'd like to end up with something that sends this text and a
response in encrypted form, between an authenticated client and an
authenticated server.

I keep getting an error though - "The server mode SSL must use a
certificate with the associated private key." I've used MakeCert to
create a .cer file. The command I used was:

makecert -n "CN=Joe Bloggs" test.cer

The relevant code being run (as a server) is:

static void Main(string[] args) {
           X509Certificate cert =
X509Certificate.CreateFromCertFile("test.cer");
           TcpListener tcpServer = new TcpListener(IPAddress.Any,
9988);
           tcpServer.Start();

           while (true) {
               TcpClient tcpClient = tcpServer.AcceptTcpClient();
               SslStream sslStream = new
SslStream(tcpClient.GetStream(), false);
               try {
                   sslStream.AuthenticateAsServer(cert);
...

The exception is beign raised at AuthenticateAsServer(). I can inspect
the 'cert' variable, and it seems to contain my certificate (certainly,
the name 'Joe Bloggs' is in it).

I guess my problem must be in the key, but I'm really not sure what -
could someone shed some light on this.
Eugene Mayevski - 18 Dec 2006 11:54 GMT
Hello!
You wrote  on 18 Dec 2006 03:46:53 -0800:

a> I keep getting an error though - "The server mode SSL must use a
a> certificate with the associated private key." I've used MakeCert to
a> create a .cer file. The command I used was:

.cer file doesn't contain a private key. You need to obtain a private key or
export the certificate and the private key to PFX.

With best regards,
Eugene Mayevski
http://www.SecureBlackbox.com - the comprehensive component suite for
network security
Thos - 23 Dec 2006 05:13 GMT
Using makecert, I got it to work using the info on this page:

http://blogs.technet.com/jhoward/archive/2005/02/02/365323.aspx

I also got it to work using a local CA-signed cert I made in openssl
following the details on this page:

http://sial.org/howto/openssl/

After I had the CA-signed cert, I added the private key to the file

$ cat serverkey.pem >> servercert.pem

and then converted this cert/pkey combo into p12 format for importing
into the windows key store:

$ openssl pkcs12 -export -in servercert.pem -out servercert.p12 -name
"secure.myserver.com"

I then was able to import this in the key store using the certificates
MMC snap-in.

T

> I'm trying to knock up a simple demonstration for myself to try using
> SSL to send and receive a simple message. I've based this on the code
[quoted text clipped - 33 lines]
> I guess my problem must be in the key, but I'm really not sure what -
> could someone shed some light on this.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.