小编Lau*_*ent的帖子

用于在iOS上运行HTTPS服务器的SSL身份证书

我正在尝试在iOS应用程序中构建HTTPS服务器,以便充当我的Web应用程序和外部服务器之间的代理.

我已经设法通过监听套接字来创建HTTP服务器,这要归功于CFSocketRef或使用GCDAsyncSocket库.我还成功地使用GCDAsyncSocket库制作运行HTTPS服务器的Mac应用程序,并且感谢我的方法"secureSocket:",它可以保护连接:

- (void)socket:(GCDAsyncSocket *)sock didAcceptNewSocket:(GCDAsyncSocket *)newSocket
{
    // (...)
    // secure the connection
    [self secureSocket:newSocket];
    // (...)
}

- (void)secureSocket:(GCDAsyncSocket *)sock
{
    // The root self-signed certificate I have created
    NSString *certificatePath = [[NSBundle mainBundle] pathForResource:@"certificate" ofType:@"cer"];
    NSData *certData = [[NSData alloc] initWithContentsOfFile:certificatePath];
    CFDataRef certDataRef = (CFDataRef)certData;
    SecCertificateRef cert = SecCertificateCreateWithData(NULL, certDataRef);
    [certData release];

    // the "identity" certificate
    SecIdentityRef identityRef;
    SecIdentityCreateWithCertificate(NULL, cert, &identityRef);

    // the certificates array, containing the identity then the root certificate
    NSArray …
Run Code Online (Sandbox Code Playgroud)

ssl https networking ios

6
推荐指数
1
解决办法
5838
查看次数

标签 统计

https ×1

ios ×1

networking ×1

ssl ×1