如何在客户端实现 SSL?
How to implement SSL in client side?
我是网络开发的新手,目前我正在开发一个 Rest API,它将被 IOS 应用程序使用。所以我开发了 API 并在 it.Now 中实现了具有 oauth2 安全性的 jwt 令牌 我想提供 API 供移动设备使用 app.So 我的后端服务器有 SSL 证书.所以消耗的 Rest API 将类似于
https://server:port/dataapiurl
到目前为止,我已经阅读了有关 SSL 和 JWT 的内容,而且我已经出于不同的原因将它们放在了一起
SSL用于客户端服务器通信和之间的加密通道
JWT 用于授权。
因此即使我实现了 JWT 并且通信不在 SSL.So 中也没有意义,以确保在客户端和服务器之间完成必须在客户端(移动应用程序)上完成的通信边?
1.Does移动应用程序需要安装新证书还是我们后台服务器的SSL证书?
2.If 是我们后台服务器的SSL证书,那怎么安装到手机端呢?
感谢任何帮助。
您可以但不必在客户端上设置您的 ssl 证书。
你可以只遵循 NSURLSessionDelegate 协议并实现它:
- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler{
if([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]){
NSArray* netTrusts = @["your hostname here"];
if(netTrusts != nil && [netTrusts containsObject:challenge.protectionSpace.host]){
NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
completionHandler(NSURLSessionAuthChallengeUseCredential,credential);
}
}
}
我是网络开发的新手,目前我正在开发一个 Rest API,它将被 IOS 应用程序使用。所以我开发了 API 并在 it.Now 中实现了具有 oauth2 安全性的 jwt 令牌 我想提供 API 供移动设备使用 app.So 我的后端服务器有 SSL 证书.所以消耗的 Rest API 将类似于
https://server:port/dataapiurl
到目前为止,我已经阅读了有关 SSL 和 JWT 的内容,而且我已经出于不同的原因将它们放在了一起 SSL用于客户端服务器通信和之间的加密通道 JWT 用于授权。
因此即使我实现了 JWT 并且通信不在 SSL.So 中也没有意义,以确保在客户端和服务器之间完成必须在客户端(移动应用程序)上完成的通信边?
1.Does移动应用程序需要安装新证书还是我们后台服务器的SSL证书?
2.If 是我们后台服务器的SSL证书,那怎么安装到手机端呢?
感谢任何帮助。
您可以但不必在客户端上设置您的 ssl 证书。 你可以只遵循 NSURLSessionDelegate 协议并实现它:
- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler{
if([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]){
NSArray* netTrusts = @["your hostname here"];
if(netTrusts != nil && [netTrusts containsObject:challenge.protectionSpace.host]){
NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
completionHandler(NSURLSessionAuthChallengeUseCredential,credential);
}
}
}