nats-io/nats-server · error

ErrBadSigningAlgorithm

ErrBadSigningAlgorithm

Error message

unsupported signing algorithm

What it means

ErrBadSigningAlgorithm is returned when the Windows certificate-store signer receives signing options whose concrete type does not match any supported signing option type (RSA PSS/PKCS1 or ECDSA). The switch `switch opts.(type)` in the Sign implementation at certstore_windows.go:558 falls through to the default branch because the option type is unrecognized, so the library cannot determine how to perform the signature.

Source

Thrown at server/certstore/errors.go:15

package certstore

import (
	"errors"
)

var (
	// ErrBadCryptoStoreProvider represents inablity to establish link with a certificate store
	ErrBadCryptoStoreProvider = errors.New("unable to open certificate store or store not available")

	// ErrBadRSAHashAlgorithm represents a bad or unsupported RSA hash algorithm
	ErrBadRSAHashAlgorithm = errors.New("unsupported RSA hash algorithm")

	// ErrBadSigningAlgorithm represents a bad or unsupported signing algorithm
	ErrBadSigningAlgorithm = errors.New("unsupported signing algorithm")

	// ErrStoreRSASigningError represents an error returned from store during RSA signature
	ErrStoreRSASigningError = errors.New("unable to obtain RSA signature from store")

	// ErrStoreECDSASigningError represents an error returned from store during ECDSA signature
	ErrStoreECDSASigningError = errors.New("unable to obtain ECDSA signature from store")

	// ErrNoPrivateKeyStoreRef represents an error getting a handle to a private key in store
	ErrNoPrivateKeyStoreRef = errors.New("unable to obtain private key handle from store")

	// ErrExtractingPrivateKeyMetadata represents a family of errors extracting metadata about the private key in store
	ErrExtractingPrivateKeyMetadata = errors.New("unable to extract private key metadata")

	// ErrExtractingECCPublicKey represents an error exporting ECC-type public key from store
	ErrExtractingECCPublicKey = errors.New("unable to extract ECC public key from store")

	// ErrExtractingRSAPublicKey represents an error exporting RSA-type public key from store
	ErrExtractingRSAPublicKey = errors.New("unable to extract RSA public key from store")

View on GitHub (pinned to 3a66a489d2)

Solutions

  1. Call the signer through crypto/tls (TLSConfig) so it receives standard option types automatically.
  2. If calling Sign directly, pass the correct options type: *rsa.PSSOptions for RSA-PSS, rsa/dsa PKCS1 defaults for RSA, or the ECDSA options type for ECC keys.
  3. Verify the key's algorithm and match options to it (RSA options for RSA keys, ECDSA options for ECC keys).
  4. Check the switch at certstore_windows.go:558 for the exact list of accepted option types in this version.

Example fix

// before
sig, err := signer.Sign(rand, digest, nil)
// after
sig, err := signer.Sign(rand, digest, crypto.SHA256) // let stdlib options flow, or pass *rsa.PSSOptions / ECDSA options
Defensive patterns

Strategy: validation

Validate before calling

// ensure opts is a type the store signer understands before calling
switch opts.(type) {
case *rsa.PSSOptions, *rsa.PrivateKey, *ecdsa.Options, nil:
    // acceptable per signer's switch
default:
    opts = nil // or construct a supported options type
}

Type guard

func isSupportedSignOpts(o crypto.SignerOpts) bool {
    switch o.(type) {
    case nil, crypto.Hash, *rsa.PSSOptions, *ecdsa.Options:
        return true
    }
    return false
}

Try / catch

sig, err := signer.Sign(rand, digest, opts)
if errors.Is(err, certstore.ErrBadSigningAlgorithm) {
    return fmt.Errorf("unsupported sign options %T: %w", opts, err)
}

Prevention

When it happens

Trigger: Calling Sign on a store-backed signer (from TLSConfig's certificate/private key path on Windows) with opts that is neither *rsa.PSSOptions, *rsa.Options-style RSA options, nor *ecdsa.Options — e.g. passing nil opts, crypto.Hash alone in an unsupported shape, or a custom options type.

Common situations: Wrapping or proxying crypto.Signer and forwarding wrong option types; passing nil options where the signer expects typed options; using a newer Go stdlib options type not yet handled by this code; calling the signer directly from application code instead of through crypto/tls.

Related errors


AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02). Data as JSON: /api/errors/6c9cc1bb1649c08b. Report an issue: GitHub.