Using Delphi 7 and the chilkat library, I'm trying to authenticate using a smartcard to a site and post a pdf file in order to get an upload index. I got lost in all that chilkat has to offer and I'm kind of brand new to this part of programming (using smartcards, SSL/TLS, certificates, REST, etc). How do I do this?
Here's part of my code, I got stuck at the post part.
http := CkHttp_Create();
cert := CkCert_Create();
success := CkCert_LoadFromSmartcard(cert, '');
if (success = False) then
begin
Memo1.Lines.Add(CkCert__lastErrorText(cert));
Memo1.Lines.Add('Certificate not loaded.');
Exit;
end;
if (CkCert_HasPrivateKey(cert) <> True) then
begin
Memo1.Lines.Add('A private key is needed for TLS client authentication.');
Memo1.Lines.Add('This certificate has no private key.');
Exit;
end;
sock := CkSocket_Create();
success := CkSocket_SetSslClientCert(sock, cert);
if (success <> True) then
begin
Memo1.Lines.Add(CkSocket__lastErrorText(sock));
Exit;
end;
bTls := True;
port := 443;
maxWaitMs := 5000;
success := CkSocket_Connect(sock, mysite, port, bTls, maxWaitMs);
if (success <> True) then
begin
Memo1.Lines.Add('Connect Failure Error Code: ' + IntToStr(CkSocket_getConnectFailReason(sock)));
Memo1.Lines.Add(CkSocket__lastErrorText(sock));
Exit;
end;
rest := CkRest_Create();
success := CkRest_UseConnection(rest, socket, bAutoReconnect);
if (success <> True) then
begin
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
Here I need to upload the file using POST.
I tried to use httprequest
, but failed, because I need to authenticate with the smartcard.
I updated the example to include the following:
You'll want to set the PIN before calling LoadFromSmartcard.