在flutter中,我尝试使用dio实现SSL锁定:^4.0.4,但每次都出现此错误
握手异常:客户端中的握手错误(操作系统错误:证书验证失败:无法获取本地颁发者证书(handshake.cc:393))
String pem = "";
延迟字节数据_字节数据;
“开发者”:BUILD_ENV == 1?“阶段”:BUILD_ENV == 3?“测试”:“realize”;返回等待根捆绑包加载(“资产/证书/$_部分/sslCertificate. pem”);}
“开发者”:BUILD_ENV == 1?“阶段”:BUILD_ENV == 3?“测试”:“证书/$_part/sslCertificate. pem”);}
方法1:
(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (client) {
SecurityContext securityContext = SecurityContext();
securityContext.setTrustedCertificatesBytes(_byteData.buffer.asUint8List());
HttpClient httpClient = HttpClient(context: securityContext);
return httpClient;
};
方法2:
(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (client) {
debugPrint("badCertificateCallback :: xx");
client.badCertificateCallback=(X509Certificate cert, String host, int port){
debugPrint("badCertificateCallback :: yy ::${cert.pem}");
if(cert.pem==pem){ // Verify the certificate
return true;
}
return false;
};
return client;
};
方法1持续给出握手错误(如上所述)
方法2(错误证书回调::yy::)行从未执行(此方法从未起作用)
还有一件事,我的证书是通配符证书 *. example.com,我的API基本URL是api.example.com
有人能帮我解决这个问题吗
先谢了
1条答案
按热度按时间iyr7buue1#
字符 串 指纹 _ DEV = ' 45 ED 46 4E 79 3D F6 A7 FD 5F 34 14 5B DF FD B6 B3 EE 7A C1 5C 3D E6 0A 21 45 C7 A1 87 C6 80 23 ' ;
字符 串 指纹 _ 阶段 = ' 45 22 D3 FD 31 15 74 DA FA 27 1C 88 61 C1 D3 7D A9 00 8C 3F E4 D0 86 1A 8B 45 04 17 68 25 0E E8 ' ;
字符 串 指纹 测试 = ' 45 AE FB E8 E4 20 8C CD B4 9D EB 51 CD 1D 57 81 61 97 90 46 6F 26 B1 F1 0E BC 45 11 52 5C 1A D7 ' ;
字符 串 指纹 _ LIVE = ' 5B 45 78 A0 96 AC 97 12 05 35 92 4B 25 FD AB 7E A1 42 B2 FE 12 BF AD 4C 45 5A C4 D0 BA 5A AB 14 ' ;
拦截 器 ( 允许 的 SHAFingerprint :[ 构建 包络 = = 0 ? 指纹 偏差 :构建 _ 包络 = = 1 ? 指纹 _ 阶段 :构建 _ 包络 = = 3 ? 指纹 _ 测试 :实时 指纹 ] ) ) ;