{"record":{"id":"fa8fd50b40448219","repo":"fatedier/frp","slug":"generate-crypto-random-w","errorCode":null,"errorMessage":"generate crypto random: %w","messagePattern":"generate crypto random: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/proto/wire/crypto.go","lineNumber":189,"sourceCode":"}\n\nfunc SelectAEADAlgorithm(clientAlgorithms []string) (string, bool) {\n\tfor _, algorithm := range clientAlgorithms {\n\t\tif IsSupportedAEADAlgorithm(algorithm) {\n\t\t\treturn algorithm, true\n\t\t}\n\t}\n\treturn \"\", false\n}\n\nfunc IsSupportedAEADAlgorithm(algorithm string) bool {\n\treturn Supports(supportedAEADAlgorithms, algorithm)\n}\n\nfunc newCryptoRandom() ([]byte, error) {\n\tb := make([]byte, CryptoRandomSize)\n\tif _, err := rand.Read(b); err != nil {\n\t\treturn nil, fmt.Errorf(\"generate crypto random: %w\", err)\n\t}\n\treturn b, nil\n}\n\nfunc hasFastAESGCM() bool {\n\tswitch runtime.GOARCH {\n\tcase \"amd64\":\n\t\treturn cpu.X86.HasAES &&\n\t\t\tcpu.X86.HasPCLMULQDQ &&\n\t\t\tcpu.X86.HasSSE41 &&\n\t\t\tcpu.X86.HasSSSE3\n\tcase \"arm64\":\n\t\treturn cpu.ARM64.HasAES && cpu.ARM64.HasPMULL\n\tcase \"s390x\":\n\t\treturn cpu.S390X.HasAES &&\n\t\t\tcpu.S390X.HasAESCTR &&\n\t\t\tcpu.S390X.HasGHASH\n\tcase \"ppc64\", \"ppc64le\":","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/fatedier/frp/blob/6c8a8d0a97d03b44e9528d30b30c70cb9d61b405/pkg/proto/wire/crypto.go#L171-L207","documentation":"Thrown by newCryptoRandom when crypto/rand.Read fails while generating the 32-byte ClientRandom or ServerRandom. This is an OS-level entropy source failure; the code refuses to continue rather than use a weak random. Almost always an environment problem, not a logic bug.","triggerScenarios":"crypto/rand.Read returns an error — extremely rare on Linux (getrandom(2) failure), more plausible on constrained containers, broken /dev/urandom setups, or exotic platforms during early boot before the CRNG is initialized.","commonSituations":"Minimal container images or VMs booted with low entropy; sandboxes/seccomp profiles that block getrandom; embedded targets where the kernel entropy pool initializes late.","solutions":["Check the host/kernel: on Linux ensure the kernel is >= 3.17 so getrandom() is available and never blocks after init.","Loosen overly strict seccomp/gVisor profiles that deny getrandom syscalls to the frp process.","As a last resort in early-boot scenarios, delay service start until the entropy pool is initialized (e.g. after random: crng init done in dmesg)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if _, err := newCryptoRandom(); err != nil {\n    // OS entropy failure: abort startup with a clear message; do not fall back to math/rand\n    log.Fatalf(\"crypto/rand unavailable, cannot secure handshake: %v\", err)\n}","preventionTips":["Verify getrandom() is permitted in container seccomp profiles.","On embedded/early-boot systems, wait for kernel CRNG initialization before starting frp.","Never downgrade to pseudo-random sources on this error."],"tags":["crypto","environment","entropy","go"],"backgroundTag":null,"analyzedSha":"6c8a8d0a97d03b44e9528d30b30c70cb9d61b405","analyzedAt":"2026-08-15T06:53:27.215Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}