|
@@ -2023,6 +2023,24 @@ func (s *ServerService) UpdateGeofile(fileName string) error {
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// parseXrayKeyPairOutput reads the two-line "Label: value" output that xray's
|
|
|
|
|
+// key-generation subcommands (x25519, mldsa65, mlkem768) print and returns the
|
|
|
|
|
+// two values. Short or label-less output yields an error instead of panicking
|
|
|
|
|
+// on an out-of-range slice index, so a future xray version that changes the
|
|
|
|
|
+// format degrades to a 500 with a message rather than a crash.
|
|
|
|
|
+func parseXrayKeyPairOutput(output string) (string, string, error) {
|
|
|
|
|
+ lines := strings.Split(output, "\n")
|
|
|
|
|
+ if len(lines) < 2 {
|
|
|
|
|
+ return "", "", common.NewError("unexpected key generator output")
|
|
|
|
|
+ }
|
|
|
|
|
+ first := strings.Split(lines[0], ":")
|
|
|
|
|
+ second := strings.Split(lines[1], ":")
|
|
|
|
|
+ if len(first) < 2 || len(second) < 2 {
|
|
|
|
|
+ return "", "", common.NewError("unexpected key generator output")
|
|
|
|
|
+ }
|
|
|
|
|
+ return strings.TrimSpace(first[1]), strings.TrimSpace(second[1]), nil
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func (s *ServerService) GetNewX25519Cert() (any, error) {
|
|
func (s *ServerService) GetNewX25519Cert() (any, error) {
|
|
|
// Run the command
|
|
// Run the command
|
|
|
cmd := exec.CommandContext(context.Background(), xray.GetBinaryPath(), "x25519")
|
|
cmd := exec.CommandContext(context.Background(), xray.GetBinaryPath(), "x25519")
|
|
@@ -2033,13 +2051,10 @@ func (s *ServerService) GetNewX25519Cert() (any, error) {
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- lines := strings.Split(out.String(), "\n")
|
|
|
|
|
-
|
|
|
|
|
- privateKeyLine := strings.Split(lines[0], ":")
|
|
|
|
|
- publicKeyLine := strings.Split(lines[1], ":")
|
|
|
|
|
-
|
|
|
|
|
- privateKey := strings.TrimSpace(privateKeyLine[1])
|
|
|
|
|
- publicKey := strings.TrimSpace(publicKeyLine[1])
|
|
|
|
|
|
|
+ privateKey, publicKey, err := parseXrayKeyPairOutput(out.String())
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return nil, err
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
keyPair := map[string]any{
|
|
keyPair := map[string]any{
|
|
|
"privateKey": privateKey,
|
|
"privateKey": privateKey,
|
|
@@ -2059,13 +2074,10 @@ func (s *ServerService) GetNewmldsa65() (any, error) {
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- lines := strings.Split(out.String(), "\n")
|
|
|
|
|
-
|
|
|
|
|
- SeedLine := strings.Split(lines[0], ":")
|
|
|
|
|
- VerifyLine := strings.Split(lines[1], ":")
|
|
|
|
|
-
|
|
|
|
|
- seed := strings.TrimSpace(SeedLine[1])
|
|
|
|
|
- verify := strings.TrimSpace(VerifyLine[1])
|
|
|
|
|
|
|
+ seed, verify, err := parseXrayKeyPairOutput(out.String())
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return nil, err
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
keyPair := map[string]any{
|
|
keyPair := map[string]any{
|
|
|
"seed": seed,
|
|
"seed": seed,
|
|
@@ -2381,13 +2393,10 @@ func (s *ServerService) GetNewmlkem768() (any, error) {
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- lines := strings.Split(out.String(), "\n")
|
|
|
|
|
-
|
|
|
|
|
- SeedLine := strings.Split(lines[0], ":")
|
|
|
|
|
- ClientLine := strings.Split(lines[1], ":")
|
|
|
|
|
-
|
|
|
|
|
- seed := strings.TrimSpace(SeedLine[1])
|
|
|
|
|
- client := strings.TrimSpace(ClientLine[1])
|
|
|
|
|
|
|
+ seed, client, err := parseXrayKeyPairOutput(out.String())
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return nil, err
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
keyPair := map[string]any{
|
|
keyPair := map[string]any{
|
|
|
"seed": seed,
|
|
"seed": seed,
|