Flutter上gRPC的自签名证书

问题描述 投票:1回答:1

我有一个Flutter应用,该应用使用gRPC与服务器通信。服务器正在使用针对TLS的自签名证书。我已将证书添加到Flutter应用程序中,并且在Android上可以使用。但是,在iOS上,我收到CERTIFICATE_VERIFY_FAILED错误。 iOS是否只允许自签名证书?

我正在如下设置我的gRPC客户端:

    var cert = await rootBundle.load('assets/cert.crt');
    var creds = ChannelCredentials.secure(
        certificates: cert.buffer.asUint8List().toList()
    );
    var channel = ClientChannel(
        host,
        port: port,
        options: new ChannelOptions(credentials: creds));
    return GrpcClient(channel);

ssl flutter dart grpc self-signed
1个回答
0
投票

似乎在iOS上似乎没有明显的解决方案来添加受信任的,自签名的根CA。由于生产可能会有一个公共信任的CA,因此您可以通过禁用TLS验证进行开发来解决问题[[only。

这是我的full example repo的相关代码段:

Future<ClientChannel> makeChannel() async { final caCert = await rootBundle.loadString('assets/pki/ca/ca.crt'); return ClientChannel( 'localhost', port: 13100, options: ChannelOptions( credentials: ChannelCredentials.secure( certificates: utf8.encode(caCert), // --- WORKAROUND FOR SELF-SIGNED DEVELOPMENT CA --- onBadCertificate: (certificate, host) => host == 'localhost:13100', ), ), ); }

在这种情况下,我的服务器正在侦听localhost:13100
© www.soinside.com 2019 - 2024. All rights reserved.