TIdSSLIOHandlerSocketOpenSSL access violation

Giganews Newsgroups
Subject: TIdSSLIOHandlerSocketOpenSSL access violation
Posted by:  Hans de Vries (hans4…@yahoo.com)
Date: Tue, 18 Mar 2008

Hi,

I'm trying to setup an SSL connection through a SOCKS-interface. I already
succeeded in communicating through the SOCKS interface, but the SSL
connection doesn't work yet.
I get an access violation as soon as the IOHandler of a TIdTCPClient
component tries to read data.
Could anyone explain this to me?

Here is part of the code:

< BEGIN CODE>

type
  TIdMySmtp = class(TIdTCPClient)
  private
    fThreadId: integer;
    fMixmasterMessIsBeingSent: boolean;
    procedure SendAndWait(aLines: TStringList; aExpectedAnswer: string);
  public
    procedure Connect; override;
    procedure Send(aHeader: TStringList; aBody: TStringList; aEmailAddress:
string; aFromAddressHeader: string);
    property ThreadId: integer read fThreadId write fThreadId;
//    property HeloName: string read fHeloName write fHeloName;
//    property MailFromAddress: string read fMailFromAddress write
fMailFromAddress;
  end;

implementation

{ TIdMySmtp }

uses
  UnitLog;

procedure TIdMySmtp.Connect;
var
  Answer: string;
  Socks: TIdSocksInfo;
begin
  inherited;

  IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(Self);

  Socks := TIdSocksInfo.Create;
  Socks.Version := svSocks4A;
  Socks.Host := '127.0.0.1';
  Socks.Port := 9050;

  TIdSSLIOHandlerSocketOpenSSL(IOHandler).TransparentProxy := Socks;
  TIdSSLIOHandlerSocketOpenSSL(IOHandler).SSLOptions.CertFile :=
    'C:\Program Files\stunnel\stunnel.pem';
  TIdSSLIOHandlerSocketOpenSSL(IOHandler).SSLOptions.KeyFile :=
    'C:\Program Files\stunnel\stunnel.pem';
  IOHandler.ReadTimeout := 300000; // 5 minutes

  Answer := IOHandler.ReadLn;
  fMixmasterMessIsBeingSent := false;
end;

<END CODE>

The application crashes once the command 'Answer := IOHandler.ReadLn;' is
executed.

Maybe it has to do with the SSLOptions. The file 'C:\Program
Files\stunnel\stunnel.pem' should contain the keys necessary for setting up
a SSL connection. I'm not sure about this though.
Afaik the program stunnel uses this file...
Here's the contents:

-----BEGIN RSA PRIVATE KEY-----

MIICXAIBAAKBgQCxUFMuqJJbI9KnB8VtwSbcvwNOltWBtWyaSmp7yEnqwWel5TFf
cOObCuLZ69sFi1ELi5C91qRaDMow7k5Gj05DZtLDFfICD0W1S+n2Kql2o8f2RSvZ
qD2W9l8i59XbCz1oS4l9S09L+3RTZV9oer/Unby/QmicFLNM0WgrVNiKywIDAQAB
AoGAKX4KeRipZvpzCPMgmBZi6bUpKPLS849o4pIXaO/tnCm1/3QqoZLhMB7UBvrS
PfHj/Tejn0jjHM9xYRHi71AJmAgzI+gcN1XQpHiW6kATNDz1r3yftpjwvLhuOcp9
tAOblojtImV8KrAlVH/21rTYQI+Q0m9qnWKKCoUsX9Yu8UECQQDlbHL38rqBvIMk
zK2wWJAbRvVf4Fs47qUSef9pOo+p7jrrtaTqd99irNbVRe8EWKbSnAod/B04d+cQ
ci8W+nVtAkEAxdqPOnCISW4MeS+qHSVtaGv2kwvfxqfsQw+zkwwHYqa+ueg4wHtG

/9+UgxcXyCXrj0ciYCqURkYhQoPbWP82FwJAWWkjgTgqsYcLQRs3kaNiPg8wb7Yb
NxviX0oGXTdCaAJ9GgGHjQ08lNMxQprnpLT8BtZjJv5rUOeBuKoXagggHQJAaUAF
91GLvnwzWHg5p32UgPsF1V14siX8MgR1Q6EfgKQxS5Y0Mnih4VXfnAi51vgNIk/2
AnBEJkoCQW8BTYueCwJBALvz2JkaUfCJc18E7jCP7qLY4+6qqsq+wr0t18+ogOM9
JIY9r6e1qwNxQ/j1Mud6gn6cRrObpRtEad5z2FtcnwY=

-----END RSA PRIVATE KEY-----

-----BEGIN CERTIFICATE-----

MIICDzCCAXigAwIBAgIBADANBgkqhkiG9w0BAQQFADBCMQswCQYDVQQGEwJQTDEf
MB0GA1UEChMWU3R1bm5lbCBEZXZlbG9wZXJzIEx0ZDESMBAGA1UEAxMJbG9jYWxo
b3N0MB4XDTk5MDQwODE1MDkwOFoXDTAwMDQwNzE1MDkwOFowQjELMAkGA1UEBhMC
UEwxHzAdBgNVBAoTFlN0dW5uZWwgRGV2ZWxvcGVycyBMdGQxEjAQBgNVBAMTCWxv
Y2FsaG9zdDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAsVBTLqiSWyPSpwfF
bcEm3L8DTpbVgbVsmkpqe8hJ6sFnpeUxX3Djmwri2evbBYtRC4uQvdakWgzKMO5O
Ro9OQ2bSwxXyAg9FtUvp9iqpdqPH9kUr2ag9lvZfIufV2ws9aEuJfUtPS/t0U2Vf
aHq/1J28v0JonBSzTNFoK1TYissCAwEAAaMVMBMwEQYJYIZIAYb4QgEBBAQDAgZA
MA0GCSqGSIb3DQEBBAUAA4GBAAhYFTngWc3tuMjVFhS4HbfFF/vlOgTu44/rv2F+
ya1mEB93htfNxx3ofRxcjCdorqONZFwEba6xZ8/UujYfVmIGCBy4X8+aXd83TJ9A

eSjTzV9UayOoGtmg8Dv2aj/5iabNeK1Qf35ouvlcTezVZt2ZeJRhqUHcGaE+apCNTC9Y

-----END CERTIFICATE-----

If anyone knows what's wrong, please let me know!

Thanks in advance!

Replies