| 200 | } |
| 201 | |
| 202 | func (s *ProxyHandler) HandleGetRandom(wr http.ResponseWriter, req *http.Request, username string) { |
| 203 | if len(req.URL.Path) <= 1 || req.URL.Path[0] != '/' { |
| 204 | http.Error(wr, "Incorrect requested random data length", http.StatusBadRequest) |
| 205 | } |
| 206 | length, err := strconv.ParseInt(req.URL.Path[1:], 10, 64) |
| 207 | if err != nil || length < 0 { |
| 208 | http.Error(wr, "Incorrect requested random data length", http.StatusBadRequest) |
| 209 | } |
| 210 | var seed [32]byte |
| 211 | binary.NativeEndian.PutUint64(seed[0:], rand.Uint64()) |
| 212 | binary.NativeEndian.PutUint64(seed[8:], rand.Uint64()) |
| 213 | binary.NativeEndian.PutUint64(seed[16:], rand.Uint64()) |
| 214 | binary.NativeEndian.PutUint64(seed[24:], rand.Uint64()) |
| 215 | rng := rand.NewChaCha8(seed) |
| 216 | wr.Header().Set("Content-Length", strconv.FormatInt(length, 10)) |
| 217 | wr.WriteHeader(http.StatusOK) |
| 218 | io.Copy(wr, io.LimitReader(rng, length)) |
| 219 | } |
| 220 | |
| 221 | func (s *ProxyHandler) isLoopback(req *http.Request) (string, bool) { |
| 222 | s.outboundMux.RLock() |