handleRealityKeypair 生成 Reality 所需的 X25519 密钥对和 Short ID。
(w http.ResponseWriter, r *http.Request)
| 14 | |
| 15 | // handleRealityKeypair 生成 Reality 所需的 X25519 密钥对和 Short ID。 |
| 16 | func handleRealityKeypair(w http.ResponseWriter, r *http.Request) { |
| 17 | if r.Method != http.MethodGet { |
| 18 | writeMethodNotAllowed(w, http.MethodGet) |
| 19 | return |
| 20 | } |
| 21 | key, err := ecdh.X25519().GenerateKey(rand.Reader) |
| 22 | if err != nil { |
| 23 | internalError(w, r, err) |
| 24 | return |
| 25 | } |
| 26 | var sidBytes [8]byte |
| 27 | if _, err := rand.Read(sidBytes[:]); err != nil { |
| 28 | internalError(w, r, err) |
| 29 | return |
| 30 | } |
| 31 | writeJSON(w, http.StatusOK, map[string]any{ |
| 32 | "private_key": base64.RawURLEncoding.EncodeToString(key.Bytes()), |
| 33 | "public_key": base64.RawURLEncoding.EncodeToString(key.PublicKey().Bytes()), |
| 34 | "short_id": hex.EncodeToString(sidBytes[:]), |
| 35 | }) |
| 36 | } |
nothing calls this directly
no test coverage detected