The remote certificate is invalid according to the validation procedure

What could be the possible reasons for the following error. Please guide

Exception Type: AuthenticationException
CouchbaseLiteException (NetworkDomain / 8): One or more errors occurred. (The remote certificate is invalid according to the validation procedure.)

This happens only when we try to connect to sync gateway from a TFS build agent machine to run the automation tests.

The code snippet given below.

var dbUrl = new Uri(SyncUrl, DbName);

        var config = new ReplicatorConfiguration(DcfrDatabase.Instance, new URLEndpoint(dbUrl))
            ReplicatorType = ReplicatorType.PushAndPull,
            Continuous = true,
            Authenticator = new SessionAuthenticator(sessionId)

        repl = new Replicator(config);

The OS doesn’t think the server’s TLS certificate is trustworthy. Is something different about the configuration of the machine this happens on? It may be missing the root certificate needed to validate the server’s cert.

Try logging into a shell on that machine and using ‘curl’ to access the replicator URL (as http:).