Ver Mensaje Individual
  #452  
Antiguo 29-03-2017
PepCat PepCat is offline
Miembro
 
Registrado: mar 2017
Posts: 96
Reputación: 8
PepCat Va por buen camino
Cita:
Empezado por keys Ver Mensaje
Hola a Todos. Ahora voy yo con una duda o problema por si le ha pasado a alguien.

Estomos desarrollando en delphi y a al hora de presentar mostramos todos los certificados disponibles en el equipo. En el equipo teníamos tres certificados, los cuales nos salian a la hora de obtenerlos. Uno de ellos estaba caducado y lo eliminamos del sistema, es decir ahora solo hay dos. Pero a la hora de obtener en delphi cuantos certificados hay me siguen saliendo tres, los dos que me quedan y uno en blanco.

A alguien le ha pasado esto o sabe por que es. La lista de certificados la estamos obteniendo de la siguiente forma.

Código Delphi [-]
   

function ObtenerCertificados(aList:TStringList):integer;
var
  hStore: HCERTSTORE;
  PrevContext, CurContext: PCERT_CONTEXT;
  cbSize: DWORD;
  sNombre: String;
begin
  aList.Clear;
  Result := 0;
  hStore := CertOpenSystemStore(0, PChar('MY'));
  if hStore <> nil then begin
     PrevContext := nil;
     CurContext := CertEnumCertificatesInStore(hStore, PrevContext);
     while CurContext <> nil do begin
       sNombre := '';
       cbSize := CertGetNameString(CurContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, nil, nil, 0);
       if cbSize > 0 then
       begin
          SetLength(sNombre, cbSize-1);
          CertGetNameString(CurContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, nil, PChar(sNombre), cbSize);
          aList.Add(sNombre);
       end;
       PrevContext := CurContext;
       CurContext  := CertEnumCertificatesInStore(hStore, PrevContext);
     end;
  end;
  result:=aList.count;
end;

Un Saludo.
Hola Keys,

Después de ver todos los problemas que se han comentado en este foro con el envió de más de 13 facturas con la librería de certificados que incluye Delphi he optado por utilizar la librería CAPICOM y abrir directamente el fichero con el certificado.

Código Delphi [-]

procedure SetCertificate(const FileName, Password: string; var Data: Pointer);
var
  Cert : ICertificate2;
  CertContext : ICertContext;
  PCertContext : PCCERT_CONTEXT;
begin
  try
    Cert := CoCertificate.Create;
  except
    on E: EOleSysError  do
      raise Exception.Create('CAPICOM.DLL is not registered')
  end;

  Cert.Load(FileName, Password, CAPICOM_KEY_STORAGE_EXPORTABLE, CAPICOM_LOCAL_MACHINE_KEY);
  CertContext := Cert as ICertContext;
  CertContext.Get_CertContext(Integer(PCertContext));
  if InternetSetOption(Data, INTERNET_OPTION_CLIENT_CERT_CONTEXT, PCertContext, Sizeof(CERT_CONTEXT)) = False then
    raise Exception.Create ( 'Error setting "' + FileName + '" certificate in web service' )
end;

procedure TfEmitidas.emitidasHTTPWebNode1BeforePost(const HTTPReqResp: THTTPReqResp; Data: Pointer);
begin
  SetCertificate('C:\Cetificados\FicheroConCertificado.p12', '1234', Data);
end;
Responder Con Cita