OpenNHP/opennhp · error

master key is not set, please execuute setup command first

Error message

master key is not set, please execuute setup command first

What it means

Raised by NewKGCImplFromConfig after successfully reading and TOML-parsing etc/config.toml next to the executable: the MasterPrivateKeyBase64 or MasterPublicKeyBase64 field (or both) is the empty string. The KGC daemon cannot start because identity-based cryptography requires the master key pair before it can issue user keys or sign/verify. Note the message itself contains a typo ('execuute').

Solutions

  1. Run the kgc 'setup' subcommand to generate the system parameters and master key pair
  2. Verify the generated keys were written to the config.toml the binary actually reads (etc/ under the executable's directory, not the working directory)
  3. If keys exist elsewhere, copy the MasterPrivateKeyBase64/MasterPublicKeyBase64 values into config.toml
  4. After setup, restart the kgc service
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at endpoints/kgc/kgc.go:232 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of OpenNHP/opennhp@6e04ca5ff0 (2026-09-07). Data as JSON: /api/errors/3baa5135297e0ca8. Report an issue: GitHub.

Appendix: source

Thrown at endpoints/kgc/kgc.go:232

func NewKGCImplFromConfig() (*KGCImpl, error) {
	dirPath, err := GetExeDirPath()
	if err != nil {
		return nil, err
	}

	configFilePath := filepath.Join(dirPath, "etc", "config.toml")
	content, err := os.ReadFile(configFilePath)
	if err != nil {
		return nil, err
	}

	var config Config
	if unmarshalErr := toml.Unmarshal(content, &config); unmarshalErr != nil {
		return nil, unmarshalErr
	}

	if config.MasterPrivateKeyBase64 == "" || config.MasterPublicKeyBase64 == "" {
		return nil, fmt.Errorf("master key is not set, please execuute setup command first")
	}

	masterPrivateKey, err := base64.StdEncoding.DecodeString(config.MasterPrivateKeyBase64)
	if err != nil {
		return nil, err
	}

	masterPublicKey, err := base64.StdEncoding.DecodeString(config.MasterPublicKeyBase64)
	if err != nil {
		return nil, err
	}

	if config.DefaultCipherScheme == 0 {
		k := SM2.NewKGCImpl()
		k.masterKey = &MasterKey{
			Ms:    new(big.Int).SetBytes(masterPrivateKey),
			PpubX: new(big.Int).SetBytes(masterPublicKey[0:32]),
			PpubY: new(big.Int).SetBytes(masterPublicKey[32:]),

View on GitHub (pinned to 6e04ca5ff0)