Skip to content

Commit 4805f5c

Browse files
authored
Fix main by implementing a go1.24 compliant parseRawPrivateKey method (#707)
<!-- Provide a brief summary of your changes --> ## Motivation and Context <!-- Why is this change needed? What problem does it solve? --> The following fixes the currently failing build on main because we reverted to go 1.24 and the last commit was relying on a method solely available in 1.25. The method is quite straightforward so we just reimplemented it. ## How Has This Been Tested? <!-- Have you tested this in a real application? Which scenarios were tested? --> ## Breaking Changes <!-- Will users need to update their code or configurations? --> ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply. --> - [ ] I have read the [MCP Documentation](https://modelcontextprotocol.io) - [ ] My code follows the repository's style guidelines - [ ] New and existing tests pass locally - [ ] I have added appropriate error handling - [ ] I have added or updated documentation as needed ## Additional context <!-- Add any other context, implementation notes, or design decisions --> Signed-off-by: Radoslav Dimitrov <[email protected]>
1 parent 6c0f085 commit 4805f5c

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

cmd/publisher/auth/common.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"encoding/json"
1313
"fmt"
1414
"io"
15+
"math/big"
1516
"net/http"
1617
"time"
1718
)
@@ -86,10 +87,13 @@ func (c *CryptoProvider) signMessage(privateKeyBytes []byte, message []byte) ([]
8687

8788
digest := sha512.Sum384(message)
8889
curve := elliptic.P384()
89-
privateKey, err := ecdsa.ParseRawPrivateKey(curve, privateKeyBytes)
90+
91+
// Parse the raw private key (compatible with Go 1.24)
92+
privateKey, err := parseRawPrivateKey(curve, privateKeyBytes)
9093
if err != nil {
9194
return nil, fmt.Errorf("failed to parse ECDSA private key: %w", err)
9295
}
96+
9397
r, s, err := ecdsa.Sign(rand.Reader, privateKey, digest[:])
9498
if err != nil {
9599
return nil, fmt.Errorf("failed to sign message: %w", err)
@@ -101,6 +105,38 @@ func (c *CryptoProvider) signMessage(privateKeyBytes []byte, message []byte) ([]
101105
}
102106
}
103107

108+
// parseRawPrivateKey parses a raw ECDSA private key from bytes.
109+
// This mimics crypto/ecdsa.ParseRawPrivateKey from Go 1.25+ for compatibility with Go 1.24.
110+
func parseRawPrivateKey(curve elliptic.Curve, privateKeyBytes []byte) (*ecdsa.PrivateKey, error) {
111+
if curve == nil {
112+
return nil, fmt.Errorf("nil curve")
113+
}
114+
115+
// Only standard NIST curves supported
116+
switch curve {
117+
case elliptic.P224(), elliptic.P256(), elliptic.P384(), elliptic.P521():
118+
// ok
119+
default:
120+
return nil, fmt.Errorf("unsupported curve")
121+
}
122+
123+
d := new(big.Int).SetBytes(privateKeyBytes)
124+
params := curve.Params()
125+
if d.Sign() <= 0 || d.Cmp(params.N) >= 0 {
126+
return nil, fmt.Errorf("invalid private scalar")
127+
}
128+
129+
x, y := curve.ScalarBaseMult(d.Bytes())
130+
return &ecdsa.PrivateKey{
131+
PublicKey: ecdsa.PublicKey{
132+
Curve: curve,
133+
X: x,
134+
Y: y,
135+
},
136+
D: d,
137+
}, nil
138+
}
139+
104140
// NeedsLogin always returns false for cryptographic auth since no interactive login is needed
105141
func (c *CryptoProvider) NeedsLogin() bool {
106142
return false

0 commit comments

Comments
 (0)