Debian Codegraph @

server/websocket_go125.go

raw
1 // Copyright 2026 The NATS Authors
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 //go:build !go1.26
15
16 package server
17
18 import (
19 "crypto/fips140"
20 "crypto/sha1"
21 "encoding/base64"
22 )
23
24 func wsAllowedFIPS() bool {
25 // SHA-1 is not permitted on Go 1.25 FIPS builds because we cannot avoid its
26 // enforcement for Sec-WebSocket-Key and Sec-WebSocket-Accept, it will result
27 // in a panic.
28 return !fips140.Enabled()
29 }
30
31 // Concatenate the key sent by the client with the GUID, then computes the SHA1 hash
32 // and returns it as a based64 encoded string.
33 func wsAcceptKey(key string) string {
34 h := sha1.New()
35 h.Write([]byte(key))
36 h.Write(wsGUID)
37 return base64.StdEncoding.EncodeToString(h.Sum(nil))
38 }