salvadordf / CEF4Delphi

CEF4Delphi is an open source project to embed Chromium-based browsers in applications made with Delphi or Lazarus/FPC for Windows, Linux and MacOS.
https://www.briskbard.com/forum/
Other
1.2k stars 365 forks source link

cef+openssl #454

Closed supermay554 closed 1 year ago

supermay554 commented 1 year ago

generate MD5WithRSAKEY with openssl,av error function Sign(priKey, Msg: String; _type: KEY_ALGORITHM): String; var ctx: EVP_MD_CTX; pkey: pEVP_PKEY; key_type: pEVP_MD;

SigBuf: array [0 .. 4095] of Byte; SigLen: Cardinal; Buf: TStringStream; buf_len: Integer; err: Integer; begin Result := '';

pkey := LoadPrivateKey(priKey);

if pkey = nil then begin RaiseOpenSSLError('RSA load stream error'); Exit; end;

try

Buf := TStringStream.Create(Trim(Msg), TEncoding.UTF8);

try
  buf_len := Buf.Size;

  try
    key_type := getAlgorithm(_type);
    if Assigned(key_type) then
    begin
      try
        EVP_SignInit(@ctx, key_type); // 将需要使用的摘要算法存入ctxl中

        EVP_SignUpdate(@ctx, Buf.Memory, buf_len);
        err := EVP_SignFinal(@ctx, @SigBuf, SigLen, pkey);
        if (err <> 1) then
        begin
          RaiseOpenSSLError('Sign error');
          Result := '';
        end;
        Result := TNetEncoding.base64.EncodeBytesToString(@SigBuf, SigLen);

      finally
        EVP_MD_CTX_cleanup(@ctx);
        { TODO -o YBChao -c : 这里可能还存在内存泄漏,但不知如何解决 2021-12-27 9:45:32 }
        // CRYPTO_free(key_type);

//CRYPTO_free or OPENSSL_free av error OPENSSL_free(key_type); end; end; except RaiseOpenSSLError('Sign error'); end; finally Buf.Free; end; finally EVP_PKEY_free(pkey); end; end;

salvadordf commented 1 year ago

Hi,

This is the documentation about ICefX509Certificate : https://cef-builds.spotifycdn.com/docs/114.2/classCefX509Certificate.html

See the MiniBrowser demo to know how to get the available certificates : https://github.com/salvadordf/CEF4Delphi/blob/784edfca3486f635e73450d4d086b3d8a0790fbb/demos/Delphi_VCL/MiniBrowser/uMiniBrowser.pas#L1260 https://github.com/salvadordf/CEF4Delphi/blob/784edfca3486f635e73450d4d086b3d8a0790fbb/demos/Delphi_VCL/MiniBrowser/uMiniBrowser.pas#L796

Use the PEM or DER data for the certificate as a ICefBinaryValue instance and copy the the data using the ICefBinaryValue.GetData method : https://cef-builds.spotifycdn.com/docs/114.2/classCefBinaryValue.html

Please, use our forums for more questions.