Home > OS >  HandshakeException (HandshakeException: Handshake error in client (OS Error:CERTIFICATE_VERIFY_FAILE
HandshakeException (HandshakeException: Handshake error in client (OS Error:CERTIFICATE_VERIFY_FAILE

Time:07-21

While creating the agora video call application I am getting errors like this

HandshakeException (HandshakeException: Handshake error in client (OS Error:CERTIFICATE_VERIFY_FAILED: certificate has expired(handshake.cc:393)))

This is the line where its throwing error

Response _response = await get(Uri.parse(link));

And my code is

import 'dart:convert';
import 'package:agora_uikit/agora_uikit.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart'; 
class VedioCall extends StatefulWidget {
  String channelName = "test";
  VedioCall({required this.channelName});
  @override
  State<VedioCall> createState() => _VedioCallState();
}

class _VedioCallState extends State<VedioCall> {
 late final AgoraClient _client;
  bool _loading = true;
  String tempToken = "";

  @override
  void initState() {
    getToken();
    super.initState();
  }

  Future<void> getToken() async {
    String link =
        "https://Agora-Node-TokenServer.vinaym4.repl.co/access_token?channelName=${widget.channelName}";

    Response _response = await get(Uri.parse(link));
    Map data = jsonDecode(_response.body);
    setState(() {
      tempToken = data["token"];
    });
    _client = AgoraClient(
        agoraConnectionData: AgoraConnectionData(
          appId: "5a4c1108a1af4a76924c9461d120dc47",
          tempToken: tempToken,
          channelName: widget.channelName,
        ),
        enabledPermission: [Permission.camera, Permission.microphone]);
    Future.delayed(Duration(seconds: 1)).then(
      (value) => setState(() => _loading = false),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: _loading
            ? Center(
                child: CircularProgressIndicator(),
              )
            : Stack(
                children: [
                  AgoraVideoViewer(
                    client: _client,
                  ),
                  AgoraVideoButtons(client: _client)
                ],
              ),
      ),
    );
    ;
  }
} 

CodePudding user response:

The certificate has just changed today. Looks like Android is not reading the initial date correctly as an inclusive date. I think if you try tomorrow it's going to work.

Solution 1

In the meantime, you can try testing on another platform like Windows that's working.

Solution 2

Or you can override the certificate validation with:

class MyHttpOverrides extends HttpOverrides {
  @override
  HttpClient createHttpClient(SecurityContext? context) {
    return super.createHttpClient(context)
      ..badCertificateCallback =
          (X509Certificate cert, String host, int port) => true;
  }
}

And set HttpOverrides.global in the main method like this:

void main() {
  HttpOverrides.global = MyHttpOverrides();
  runApp(const MyApp());
}

Note: This is a security risk as every invalid certificate is going to be accepted. So, in production please remove this code.


Screenshot

  • Related