简体   繁体   English

API响应中的数字证书

[英]Digital certificate in API response

I'm working on an authentication method for my NodeJS API. 我正在为NodeJS API开发一种身份验证方法。 I'm using TLS certificates to verify the client connected to my API server. 我正在使用TLS证书来验证连接到我的API服务器的客户端。 My question is: can we have a way to authenticate the response back to the client? 我的问题是:我们可以采用一种方法来将响应身份验证回客户端吗? Can we use cert for this to(server to client)? 我们可以为此使用cert(服务器到客户端)吗?

eg: When we call an API from our client we send the certificate with the request which is authenticated and if found valid the server sends the response, can we do it vice-versa, send a certificate in response and have the client validate the certificate. 例如:当我们从客户端调用API时,我们将发送带有已验证请求的证书,如果发现有效,服务器将发送响应,反之亦然,发送证书作为响应并让客户端验证证书。

The whole TLS protocol and the certificates are already built around this idea that you trust the server. 整个TLS协议和证书已经围绕您信任服务器的想法而构建。 Ie the server during establishing of TLS connection provides a certificate that client can verify by checking if it trusts the CA that has issued the certificate. 也就是说,在建立TLS连接期间,服务器会提供证书,客户端可以通过检查服务器是否信任已颁发证书的CA来对其进行验证。

Now while this is generally so, you can have libraries that allows to bypass this by not checking the certificate or checking but proceeding anyway, so you have to double check that is not the case. 现在,通常情况如此,您可以拥有一些库,这些库可以通过不检查证书或不检查而是继续进行来绕过此操作,因此您必须仔细检查并非如此。 The browser does this automatically. 浏览器会自动执行此操作。

If you click on a green "Secure" button that is to the left in URL in Chrome eg you can click on "certificate" there and see the certificate that is provided by the server. 如果您单击Chrome中URL左侧的绿色“安全”按钮,例如,您可以在此处单击“证书”,然后查看服务器提供的证书。 If it's green, then it's trusted and all's good. 如果它是绿色的,那么它就是可信赖的,一切都很好。

PS Neither the client not server sends the certificate the whole time back and forth with each request/response. PS无论客户端还是服务器,都不会始终随每个请求/响应来回发送证书。 They do it only once during establishing the connection that is called TLS handshake. 他们在建立称为TLS握手的连接期间仅执行一次。 It's relatively expensive process so you'd better keep the connection. 这是一个相对昂贵的过程,因此您最好保持连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM