I am busy evaluating SecureBridge's SSL component and I've run in to some issues which I hope you'll be able to help me with.
I am running Delphi 5 in Windows Vista.
I created a small client app that connects to a server which is developed in Java using SSLv3. I got everything set up, but when I attempt to connect after it adds the cert, it indicates that it is connected and on the Java side the exception below is thrown. When I connect a second time (this time the storage component reads the certs from the file system, namely cert.cer.crt file is present on the file system), I get the error message "Wrong certificate context".
The cert isn't damaged or anything like that since I simply exported it from a keystore using Portacle. Basically, I selected the only entry in the keystore and exported it as a Head Certificate DER encoded.
The cert is read in by SecureBridge without any issues, but when I attempt to connect, that is when it fails with the above mentioned error.
On the Java side, I get the following exception
I know the Java side isn't at fault since we have been doing SSL for ages and it is working fine.javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
Here is the code that I wrote below.
I hope you'll be able to help me.
Thanks
~Glen
Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
var
  cert : TScCertificate;
  storage : TScFileStorage;
  client : TScSSLClient;
  i : Integer;
  b : boolean;
  certName : String;
begin
  storage := TScFileStorage.Create(Self);
  client := TScSSLClient.Create(Self);
  try
    client.HostName := 'localHost';
    client.Port := 7777;
    client.Protocols := [spSsl3, spTls1];
    storage.Path := 'C:\temp\Cert';
    certName := 'cert.cer';
    b := False;
    for i := 0 to storage.Certificates.Count - 1 do begin
      cert := storage.Certificates[i];
      if (cert.CertName = certName) then begin
        b := True;
      end;
    end;
    if (not b) then begin
      cert := TScCertificate.Create(storage.Certificates);
      cert.CertName := CertName;
      cert.ImportFrom(CertName);
      cert.Ready := True;
    end;
    client.Storage := storage;
    client.CACertName := certName;
    client.Connect;
    if (client.Connected) then begin
      client.IsSecure := True;
      ShowMessage ('Connected');
      // now we do the communication we need to.
    end;
  except
    on E:Exception do begin
      ShowMessage (e.Message);
    end;
  end;
  client.Disconnect;
  client.Free;
  storage.Free;
end;