Entwickler-Ecke

Internet / Netzwerk - SOAP https Certificate


nicnac66 - Mi 18.07.07 13:47
Titel: SOAP https Certificate
Hi Leute, Tach allerseits!

ich habe erfolgreich einen WebService zum Test erstellt und einen Client, der darauf zugreift.

Mit http ist alle in Butter.

Nun habe ich vom Admin ein Zertifikat auf dem IIS installieren lassen und den WebService mittels https angesprochen.
Das Zertifikat wird vom Client ausgewählt und ich kann es mit "Cert.Display();" anzeigen aber ich bekomme dann einen Fehler in der Zeite "IF InternetSetOption(Data, INTERNET_OPTION_CLIENT_CERT_CONTEXT, PCertContext, Sizeof(CERT_CONTEXT))":

"An error occured in the secur channel support.."

Ich habe auch noch einen produktiven Webservice getestet - das gleiche Problem. Es liegt also an meinem Client.

Weis da jemand Rat?

Danke
Nic


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
unit unCall;

interface

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, InvokeRegistry, StdCtrls,
  Rio,
  SOAPHTTPClient,
  SOAPHTTPTrans,
  CapicomConst,
  CAPICOM_TLB,
  JwaWinCrypt,
  StrUtils,
  wininet,
  OleServer;

type
  TForm1 = class(TForm)
    Button1: TButton;
    htt: THTTPRIO;
    Edit1: TEdit;
    Button2: TButton;
    Store1: TStore;
    htt2: THTTPRIO;
    procedure Button2Click(Sender: TObject);
    procedure httHTTPWebNode1BeforePost(const HTTPReqResp: THTTPReqResp;
      Data: Pointer);
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
    function FindCert(Store:iStore;FindThumbprint:String):ICertificate2;
  public
    { Public-Deklarationen }
  end;

CONST INTERNET_OPTION_CLIENT_CERT_CONTEXT = 84;

var
  Form1: TForm1;

implementation

uses IMyWebService1;
{$R *.dfm}
//-----------------------------------------------------------------------------
procedure TForm1.Button1Click(Sender: TObject);
begin
 (htt as IMyWebService).SetTxt(edit1.Text);
  showmessage('The text entered is: '+(htt as IMyWebService).GetTxt);
end;
//-----------------------------------------------------------------------------
procedure TForm1.Button2Click(Sender: TObject);
begin
 (htt2 as IMyWebService).SetTxt(edit1.Text);
  showmessage('The text entered is: '+(htt2 as IMyWebService).GetTxt);

end;
//-----------------------------------------------------------------------------
procedure TForm1.httHTTPWebNode1BeforePost(const HTTPReqResp: THTTPReqResp;Data: Pointer);
var
  Cert         : ICertificate2;
  CertContext  : ICertContext;
  PCertContext : PCCERT_CONTEXT;
  s            : String;
  Store: IStore;

begin
  Store := CoStore.Create();
  cert:=form1.FindCert(Store,'fbc9d47b2a7655798c3fcd00002d7b19a33b2bc3'); 

  if cert<>nil then
  begin
//      form1.Memo1.Lines.Add(cert.SubjectName);
      Cert.Display(); // Debugginganzeige

      CertContext := Cert AS ICertContext;
      CertContext.Get_CertContext(Integer(PCertContext));

      SetLength(s, Sizeof(CERT_CONTEXT));
      Move(CertContext, s[1], Sizeof(CERT_CONTEXT));

      // set the certificate to use for the SSL connection
      IF InternetSetOption(Data, INTERNET_OPTION_CLIENT_CERT_CONTEXT, PCertContext, Sizeof(CERT_CONTEXT))
      THEN begin
//            ShowMessage('cooool');
           end
      ELSE begin
//            ShowMessage('brrrr');
        // fehlermeldung
        // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/system_error_codes.asp
        // 12009 = ERROR_INTERNET_INVALID_OPTION
        // 12046 = ERROR_INTERNET_CLIENT_AUTH_NOT_SETUP
        // 12044 = ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED
      END;
   end;
end;
//-----------------------------------------------------------------------------
function TForm1.FindCert(Store:iStore;FindThumbprint:String):ICertificate2;
//function TForm1.FindCert(FindThumbprint:String):ICertificate2;
var
//  Store1:istore;
  mycert:icertificates;
  mycert2:icertificate2;
  certcontext:icertcontext;
  i:integer;
  s,t:string;
  v:olevariant;
begin
//  Store:=costore.create;
//  mycert:=cocertificates.Create;

  Store.Open
  (CAPICOM_CURRENT_USER_STORE,CAPICOM_MY_STORE,CAPICOM_STORE_OPEN_MAXIMUM_ALLOWED);
//  (CAPICOM_LOCAL_MACHINE_STORE, CAPICOM_ROOT_STORE, CAPICOM_STORE_OPEN_MAXIMUM_ALLOWED);
//  (CAPICOM_LOCAL_MACHINE_STORE, CAPICOM_CA_STORE, CAPICOM_STORE_OPEN_MAXIMUM_ALLOWED);
//  (CAPICOM_LOCAL_MACHINE_STORE, CAPICOM_MY_STORE, CAPICOM_STORE_OPEN_MAXIMUM_ALLOWED);
//  (CAPICOM_LOCAL_MACHINE_STORE, CAPICOM_ROOT_STORE, CAPICOM_STORE_OPEN_MAXIMUM_ALLOWED);


//  Memo1.Lines.Add(inttostr(Store1.Certificates.Count));

  if Store.Certificates.Count> 0 then
  begin
    for i:=1 to Store.Certificates.count do
    begin
      mycert2:=IInterface(Store.Certificates.Item[i]) AS ICertificate2;
      if mycert2.Thumbprint=UpperCase(FindThumbprint)
       then Begin
              Result := mycert2;
              Break;
            end;
    end;
  end;
end;

//-----------------------------------------------------------------------------
end.


Ramon B. - Mi 07.09.16 11:47

Hallo,

das Thema ist zwar schon ein paar Jahre alt, aber ich stehe aktuell vor dem gleichen Problem.

Hat dazu irgendjemand eine Lösung gefunden?

mfg

Ramon