Error when getting identity from device by IdentityManager using `dfx-core` v0.19.0

After the following consultation, we are using dfx-core to incorporate into our CLI what we can do with dfx, but we are having problems recovering Identity to incorporate into Agent.

I am running the following code using IdentityManager on dfx-core 0.19.0, but I get an error. What is wrong?

let logger = Logger::root(Discard, slog::o!());
let mut identity_mgr = IdentityManager::new(&logger, &None).unwrap();
println!("{:?}", &identity_mgr);
// IdentityManager { identity_json_path: "/Users/xxx/.config/dfx/identity.json", file_locations: IdentityFileLocations { root_dir: "/Users/xxx/.config/dfx/identity" }, configuration: Configuration { default: "local-1" }, selected_identity: "local-1", selected_identity_principal: None }
let identity_config = identity_mgr.get_identity_config_or_default(identity_mgr.get_selected_identity_name());
println!("{:?}", &identity_config);
// Ok(IdentityConfiguration { hsm: None, encryption: None, keyring_identity_suffix: Some("local-1") })
let identity = identity_mgr.instantiate_selected_identity(&logger).unwrap();
// `Err` value: LoadIdentityFailed(NewIdentityFailed(LoadPemFailed(LoadFromKeyringFailed("local-1", GetPasswordFailed(PlatformFailure(Error { code: -67671, message: "An internal error has occurred." }))))))
# Cargo.toml
[dependencies]
dfx-core = { git = "https://github.com/dfinity/sdk", tag="0.19.0", package = "dfx-core" }
ic-agent = "0.35.0"
ic-utils = "0.35.0"
slog = "2.7.0"
tokio = { version = "1.37.0", features = ["full"] }

And the configuration status of dfx in devise.

% dfx identity new local-1
Your seed phrase for identity 'local-1': ...
This can be used to reconstruct your key in case of emergency, so write it down in a safe place.
Created identity: "local-1".

# execute

% cat ~/.config/dfx/identity.json 
{
  "default": "local-1"
}
% cat ~/.config/dfx/identity/local-1/identity.json 
{
  "hsm": null,
  "encryption": null,
  "keyring_identity_suffix": "local-1"
}

% cargo run
# ...
# `Err` value: LoadIdentityFailed(NewIdentityFailed(LoadPemFailed(LoadFromKeyringFailed("local-1", GetPasswordFailed(PlatformFailure(Error { code: -67671, message: "An internal error has occurred." }))))))
# (Content of output described in rust code)

Incidentally, a similar event occurred when using DfxInterface with the latest dfx-core. (Probably the same error occurs at the initialisation part of the internal identity).

The source error is PlatformFailure(Error { code: -67671, message: "An internal error has occurred." }) from keyring. The docs say The details of the failure can be retrieved from the attached platform error. Maybe you get somewhere if you search for the error code?

1 Like

I see, so it’s not a dfx problem there, but a 3rd party library. So it’s also my local problem with keychain. Thank you very much.