在关于 Apple Push Notifications 的最新博文中,我将介绍如何使用证书向 Apple 推送服务器进行身份验证。
首先进入您的开发者账户,为 Apple Push Notification 服务创建新证书。
下载证书后,sgcWebSockets HTTP/2 客户端支持使用两种安全 IOHandler(仅限 Windows;其他平台仅支持 OpenSSL)。
- OpenSSL
- SChannel (only for windows)
OpenSSL
若使用 OpenSSL,您必须随应用程序部署 OpenSSL 库。在用 TsgcHTTP2Client 设置证书之前,需先将证书转换为 PEM 格式,因为 OpenSSL 不支持直接导入 P12 证书。
使用以下命令将 P12 证书转换为 PEM 格式证书和私钥文件:
创建 PEM 证书文件
openssl pkcs12 -in INFILE.p12 -out OUTFILE.crt -nokeysCreate Private Key file
openssl pkcs12 -in INFILE.p12 -out OUTFILE.key -nodes -nocertsOnce you have your certificate and private key in PEM format, you can configure the TsgcHTTP2Client as follows.
oHTTP := TsgcHTTP2Client.Create(nil); oHTTP.TLSOptions.IOHandler := iohOpenSSL; oHTTP.TLSOptions.CertFile := 'certificate_file.pem'; oHTTP.TLSOptions.KeyFile := 'private_key.pem'; oHTTP.TLSOptions.Password := 'certificate password'; oHTTP.TLSOptions.Version := tls1_2;
SChannel
若使用 SChannel,无需部署任何库,从 Apple 下载的证书可直接导入,无需预先转换为 PEM 格式。
oHTTP := TsgcHTTP2Client.Create(nil); oHTTP.TLSOptions.IOHandler := iohSChannel; oHTTP.TLSOptions.CertFile := 'certificate_file.p12'; oHTTP.TLSOptions.Password := 'certificate password'; oHTTP.TLSOptions.Version := tls1_2;
