{"record":{"id":"0f88e444fb9be31d","repo":"nats-io/nats-server","slug":"errbadrsahashalgorithm","errorCode":"ErrBadRSAHashAlgorithm","errorMessage":"unsupported RSA hash algorithm","messagePattern":"unsupported RSA hash algorithm","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/certstore/errors.go","lineNumber":12,"sourceCode":"package certstore\n\nimport (\n\t\"errors\"\n)\n\nvar (\n\t// ErrBadCryptoStoreProvider represents inablity to establish link with a certificate store\n\tErrBadCryptoStoreProvider = errors.New(\"unable to open certificate store or store not available\")\n\n\t// ErrBadRSAHashAlgorithm represents a bad or unsupported RSA hash algorithm\n\tErrBadRSAHashAlgorithm = errors.New(\"unsupported RSA hash algorithm\")\n\n\t// ErrBadSigningAlgorithm represents a bad or unsupported signing algorithm\n\tErrBadSigningAlgorithm = errors.New(\"unsupported signing algorithm\")\n\n\t// ErrStoreRSASigningError represents an error returned from store during RSA signature\n\tErrStoreRSASigningError = errors.New(\"unable to obtain RSA signature from store\")\n\n\t// ErrStoreECDSASigningError represents an error returned from store during ECDSA signature\n\tErrStoreECDSASigningError = errors.New(\"unable to obtain ECDSA signature from store\")\n\n\t// ErrNoPrivateKeyStoreRef represents an error getting a handle to a private key in store\n\tErrNoPrivateKeyStoreRef = errors.New(\"unable to obtain private key handle from store\")\n\n\t// ErrExtractingPrivateKeyMetadata represents a family of errors extracting metadata about the private key in store\n\tErrExtractingPrivateKeyMetadata = errors.New(\"unable to extract private key metadata\")\n\n\t// ErrExtractingECCPublicKey represents an error exporting ECC-type public key from store\n\tErrExtractingECCPublicKey = errors.New(\"unable to extract ECC public key from store\")","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/certstore/errors.go#L1-L30","documentation":"ErrBadRSAHashAlgorithm is returned by the Windows certificate-store signer when the requested crypto.Hash has no entry in the winAlgIDs lookup table mapping Go hash functions to Windows CNG algorithm identifiers. The library only supports a fixed set of RSA hash algorithms (e.g. SHA-256/384/512) when signing via the Windows certificate store; anything else cannot be mapped to an BCrypt algorithm ID. It is thrown before any Windows API call is made, so the certificate is never contacted.","triggerScenarios":"Calling the certificate-store signing path (via TLSConfig with a store-backed private key on Windows) with a Signer_opts value whose crypto.Hash is not in winAlgIDs — e.g. crypto.MD5, crypto.SHA1 if excluded, or crypto.Hash(0) (no hash) — passed to the signer's Sign method, hitting the `algID, ok := winAlgIDs[hf]; if !ok` check at certstore_windows.go:549.","commonSituations":"Passing crypto.Hash(0) because the caller hashed the data itself and forgot opts; using a legacy hash like MD5/SHA-1 in custom signing code; wiring the store signer into crypto/tls with unusual signature algorithms; running custom hash enums on Windows where the CNG mapping table lacks an entry.","solutions":["Use a supported hash: crypto.SHA256, crypto.SHA384, or crypto.SHA512 when calling Sign (or let crypto/tls pick one).","If you pre-hashed the data, still pass the corresponding crypto.Hash constant in opts rather than crypto.Hash(0).","Check the winAlgIDs map in server/certstore/certstore_windows.go to see exactly which hash functions the build supports.","If you need an unmapped algorithm, add the CNG algorithm ID to winAlgIDs or hash with a supported algorithm instead."],"exampleFix":"// before\nsig, err := signer.Sign(rand, digest, crypto.SHA1)\n// after\nsig, err := signer.Sign(rand, digest, crypto.SHA256)","handlingStrategy":"validation","validationCode":"// before signing, ensure the hash is one the store supports\nswitch opts.(type) {\n}\n// map check (mirrors winAlgIDs)\nvar supported = map[crypto.Hash]bool{crypto.SHA256: true, crypto.SHA384: true, crypto.SHA512: true}\nif hf != 0 && !supported[hf] {\n    return fmt.Errorf(\"hash %v not supported by Windows cert store\", hf)\n}","typeGuard":"func isSupportedRSAHash(hf crypto.Hash) bool {\n    switch hf {\n    case crypto.SHA256, crypto.SHA384, crypto.SHA512:\n        return true\n    }\n    return false\n}","tryCatchPattern":"sig, err := signer.Sign(rand, digest, opts)\nif errors.Is(err, certstore.ErrBadRSAHashAlgorithm) {\n    // fall back to SHA-256\n    sig, err = signer.Sign(rand, digest, crypto.SHA256)\n}","preventionTips":["Always pass a concrete crypto.Hash (SHA-256/384/512) to Sign; never crypto.Hash(0).","Let crypto/tls drive signing so standard hash options are chosen automatically.","Check winAlgIDs in server/certstore before using unusual hashes on Windows."],"tags":["windows","certificate-store","rsa","hash-algorithm","signing"],"backgroundTag":"unsupported-hash-algorithm","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}