Skip to content

Certificate Signature Mismatch Error When Using EdjCase.ICP.Agent with HttpAgent #142

@aggarwalMohit30

Description

@aggarwalMohit30

I am encountering an issue while using the EdjCase.ICP.Agent package (version [7.0.1}) in a Unity project. The error message Certificate signature does not match the IC public key appears during the execution of the create_user which is a public shared function written in Motoko call when using the HttpAgent. This issue seems to occur intermittently, and the code includes retry logic with a delay, but the problem persists after multiple attempts.
Steps to Reproduce
Integrate the EdjCase.ICP.Agent package into a Unity project.
Use the provided code (see below) to set up an HttpAgent with a DelegationIdentity or anonymous identity.
Call the CallAsync method on the agent to invoke a canister method (e.g., create_user).
Observe the Logcat output, where the error Certificate signature does not match the IC public key is logged.

Expected Behavior
The HttpAgent should successfully authenticate and execute the canister call without certificate signature mismatches, allowing the create_user method to complete successfully.

Actual Behavior
The application throws a Certificate signature does not match the IC public key exception, causing the CallAsync operation to fail. The retry logic in the code attempts to handle this by delaying and retrying, but the issue persists.
`using UnityEngine;
using UnityEngine.UI;
using EdjCase.ICP.Agent.Agents;
using EdjCase.ICP.Agent.Agents.Http;
using EdjCase.ICP.Agent.Identities;
using EdjCase.ICP.Candid.Models;
using System;
using UnityEngine.SceneManagement;
using System.Threading.Tasks;
using System.Collections;
using System.Net.Http;

namespace IC.GameKit
{
public class TestICPAgent : MonoBehaviour
{
// [Previous code omitted for brevity]

    private async Task AutoCreateUserAsync(bool useAnonymous = false)
    {
        Debug.Log("1️⃣ Initializing AutoCreateUserAsync...");

        using var underlyingHttpClient = new HttpClient { BaseAddress = new Uri(icHost) };
        var httpClient = new DefaultHttpClient(underlyingHttpClient);
        var agent = useAnonymous ? new HttpAgent(httpClient) : new HttpAgent(httpClient, DelegationIdentity);
        Debug.Log($"✅ HttpAgent created with host: {icHost}");

        var canisterId = Principal.FromText(greetBackendCanister);
        var client = new GreetingClient.GreetingClient(agent, canisterId);
        Debug.Log("✅ GreetingClient created with DefaultHttpClient.");

        // [Other initialization code omitted]

        try
        {
            Debug.Log("7️⃣ Preparing create_user call...");
            CandidArg arg = CandidArg.FromCandid(
                CandidTypedValue.FromObject(userPrincipal),
                CandidTypedValue.FromObject(uuid)
            );
            Debug.Log("🔄 Calling create_user on canister...");
            const int maxRetries = 3;
            for (int attempt = 1; attempt <= maxRetries; attempt++)
            {
                try
                {
                    CandidArg reply = await agent.CallAsync(canisterId, "create_user", arg);
                    Debug.Log($"✅ create_user response: {reply}");
                    break;
                }
                catch (Exception ex)
                {
                    Debug.LogError($"❌ Attempt {attempt}/{maxRetries} Failed to call create_user: {ex.Message}\nStackTrace: {ex.StackTrace}");
                    if (attempt == maxRetries)
                    {
                        Debug.LogWarning("⚠ Max retries reached. Skipping create_user...");
                        break;
                    }
                    else if (ex.Message.Contains("Certificate signature does not match"))
                    {
                        Debug.LogWarning("⚠ Certificate mismatch detected. Retrying after delay...");
                        await Task.Delay(1000);
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            // [Remaining code omitted]
        }
        catch (Exception e)
        {
            Debug.LogError($"❌ Unexpected error in AutoCreateUserAsync: {e.Message}\nStackTrace: {e.StackTrace}");
        }
    }

    // [Other methods omitted]
}

}`

This is only happen when i try to use any update method of Motoko query method is completely working

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions