Skip to content

Fabric-X orderer local config does not parse uppercase PKCS11 BCCSP fields #995

Description

@tinystone007

Summary

Fabric-X orderer local YAML config does not parse common uppercase PKCS11 BCCSP leaf keys such as Library, Pin, Label, Hash, and Security under General.BCCSP.PKCS11.

The same values are parsed successfully when those PKCS11 leaf keys are lowercase (library, pin, label, hash, security).

Affected versions

I reproduced this with:

  • hyperledger/fabric-x-orderer v1.0.0
  • current main at 3f71d848a2b93c4614de7dfc24a13af924f4fbe8

The vendored/current github.com/hyperledger/fabric-lib-go/bccsp/pkcs11.PKCS11Opts has JSON tags such as json:"library" but no YAML tags for the uppercase field names.

Reproducer

Given a local orderer config fragment like:

General:
  BCCSP:
    Default: PKCS11
    PKCS11:
      Library: /usr/local/lib/libkms_pkcs11.so
      Pin: test-pin
      Label: test-token
      Hash: SHA2
      Security: 256

loading it through config.LoadLocalConfigYaml leaves the nested PKCS11 values empty. For example, cfg.GeneralConfig.BCCSP.PKCS11.Library is "".

A minimal test showing the failure:

func TestPKCS11UppercaseYAML(t *testing.T) {
	path := filepath.Join(t.TempDir(), "node_config.yaml")
	content := []byte(`General:
  BCCSP:
    Default: PKCS11
    PKCS11:
      Library: /usr/local/lib/libkms_pkcs11.so
      Pin: test-pin
      Label: test-token
      Hash: SHA2
      Security: 256
`)
	require.NoError(t, os.WriteFile(path, content, 0o600))

	cfg, err := LoadLocalConfigYaml(path)
	require.NoError(t, err)
	require.Equal(t, "/usr/local/lib/libkms_pkcs11.so", cfg.GeneralConfig.BCCSP.PKCS11.Library)
}

The same test passes if the PKCS11 leaf keys are changed to lowercase:

General:
  BCCSP:
    Default: PKCS11
    PKCS11:
      library: /usr/local/lib/libkms_pkcs11.so
      pin: test-pin
      label: test-token
      hash: SHA2
      security: 256

Expected behavior

Fabric-X orderer should either:

  1. parse the common uppercase PKCS11 BCCSP fields (Library, Pin, Label, Hash, Security), or
  2. document that Fabric-X orderer local YAML config requires lowercase PKCS11 leaf keys.

Actual behavior

LoadLocalConfigYaml uses yaml.Unmarshal directly:

err = yaml.Unmarshal(yamlFile, config)

The orderer config struct reaches factory.FactoryOpts, where PKCS11 is tagged for YAML, but the nested pkcs11.PKCS11Opts fields only have JSON tags. As a result, the uppercase YAML leaf keys are not populated.

Why this is surprising

Other Fabric-related config paths commonly accept uppercase PKCS11 fields. For example, fabric-lib-go factory tests use Viper/mapstructure with uppercase Library, Pin, and Label, and Fabric documentation also shows uppercase Library, Pin, and Label in HSM examples.

Fabric-X committer also reads service config through Viper/mapstructure, so the same uppercase PKCS11 fields work there. This creates an inconsistency between Fabric-X orderer local config and committer config.

Workaround

Downstream users can either:

  • generate orderer PKCS11 leaf keys in lowercase, or
  • patch fabric-lib-go/bccsp/pkcs11.PKCS11Opts to add YAML tags such as yaml:"Library", yaml:"Pin", etc.

I verified locally that an orderer image built from fabric-x-orderer v1.0.0 with -tags pkcs11 and no local YAML-tag patch starts successfully when the generated orderer config uses lowercase PKCS11 leaf keys.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions