Skip to content

Commit 80dbaa4

Browse files
committed
refactor: rm unused cloudflare pq code
1 parent b8c41e9 commit 80dbaa4

13 files changed

+19
-173
lines changed

auth.go

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ import (
1515
"fmt"
1616
"hash"
1717
"io"
18-
19-
circlPki "github.com/cloudflare/circl/pki"
20-
circlSign "github.com/cloudflare/circl/sign"
2118
)
2219

2320
// verifyHandshakeSignature verifies a signature against pre-hashed
@@ -58,20 +55,7 @@ func verifyHandshakeSignature(sigType uint8, pubkey crypto.PublicKey, hashFunc c
5855
return err
5956
}
6057
default:
61-
// [UTLS SECTION BEGINS]
62-
// Ported from cloudflare/go
63-
scheme := circlSchemeBySigType(sigType)
64-
if scheme == nil {
65-
return errors.New("internal error: unknown signature type")
66-
}
67-
pubKey, ok := pubkey.(circlSign.PublicKey)
68-
if !ok {
69-
return fmt.Errorf("expected a %s public key, got %T", scheme.Name(), pubkey)
70-
}
71-
if !scheme.Verify(pubKey, signed, sig, nil) {
72-
return fmt.Errorf("%s verification failure", scheme.Name())
73-
}
74-
// [UTLS SECTION ENDS]
58+
return errors.New("internal error: unknown signature type")
7559
}
7660
return nil
7761
}
@@ -122,18 +106,7 @@ func typeAndHashFromSignatureScheme(signatureAlgorithm SignatureScheme) (sigType
122106
case Ed25519:
123107
sigType = signatureEd25519
124108
default:
125-
// [UTLS SECTION BEGINS]
126-
// Ported from cloudflare/go
127-
scheme := circlPki.SchemeByTLSID(uint(signatureAlgorithm))
128-
if scheme == nil {
129-
return 0, 0, fmt.Errorf("unsupported signature algorithm: %v", signatureAlgorithm)
130-
}
131-
sigType = sigTypeByCirclScheme(scheme)
132-
if sigType == 0 {
133-
return 0, 0, fmt.Errorf("circl scheme %s not supported",
134-
scheme.Name())
135-
}
136-
// [UTLS SECTION ENDS]
109+
return 0, 0, fmt.Errorf("unsupported signature algorithm: %v", signatureAlgorithm)
137110
}
138111
switch signatureAlgorithm {
139112
case PKCS1WithSHA1, ECDSAWithSHA1:
@@ -147,14 +120,7 @@ func typeAndHashFromSignatureScheme(signatureAlgorithm SignatureScheme) (sigType
147120
case Ed25519:
148121
hash = directSigning
149122
default:
150-
// [UTLS SECTION BEGINS]
151-
// Ported from cloudflare/go
152-
scheme := circlPki.SchemeByTLSID(uint(signatureAlgorithm))
153-
if scheme == nil {
154-
return 0, 0, fmt.Errorf("unsupported signature algorithm: %v", signatureAlgorithm)
155-
}
156-
hash = directSigning
157-
// [UTLS SECTION ENDS]
123+
return 0, 0, fmt.Errorf("unsupported signature algorithm: %v", signatureAlgorithm)
158124
}
159125
return sigType, hash, nil
160126
}
@@ -174,11 +140,6 @@ func legacyTypeAndHashFromPublicKey(pub crypto.PublicKey) (sigType uint8, hash c
174140
// full signature, and not even OpenSSL bothers with the
175141
// complexity, so we can't even test it properly.
176142
return 0, 0, fmt.Errorf("tls: Ed25519 public keys are not supported before TLS 1.2")
177-
// [UTLS SECTION BEGINS]
178-
// Ported from cloudflare/go
179-
case circlSign.PublicKey:
180-
return 0, 0, fmt.Errorf("tls: circl public keys are not supported before TLS 1.2")
181-
// [UTLS SECTION ENDS]
182143
default:
183144
return 0, 0, fmt.Errorf("tls: unsupported public key: %T", pub)
184145
}
@@ -249,16 +210,6 @@ func signatureSchemesForCertificate(version uint16, cert *Certificate) []Signatu
249210
}
250211
case ed25519.PublicKey:
251212
sigAlgs = []SignatureScheme{Ed25519}
252-
// [UTLS SECTION BEGINS]
253-
// Ported from cloudflare/go
254-
case circlSign.PublicKey:
255-
scheme := pub.Scheme()
256-
tlsScheme, ok := scheme.(circlPki.TLSScheme)
257-
if !ok {
258-
return nil
259-
}
260-
sigAlgs = []SignatureScheme{SignatureScheme(tlsScheme.TLSIdentifier())}
261-
// [UTLS SECTION ENDS]
262213
default:
263214
return nil
264215
}

auth_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"crypto"
99
"testing"
1010

11-
circlPki "github.com/cloudflare/circl/pki"
1211
"github.com/refraction-networking/utls/internal/fips140tls"
1312
)
1413

@@ -169,7 +168,7 @@ func TestSupportedSignatureAlgorithms(t *testing.T) {
169168
if sigType == 0 {
170169
t.Errorf("%v: missing signature type", sigAlg)
171170
}
172-
if hash == 0 && sigAlg != Ed25519 && circlPki.SchemeByTLSID(uint(sigAlg)) == nil { // [UTLS] ported from cloudflare/go
171+
if hash == 0 && sigAlg != Ed25519 {
173172
t.Errorf("%v: missing hash", sigAlg)
174173
}
175174
}

generate_cert.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ import (
2525
"os"
2626
"strings"
2727
"time"
28-
29-
circlSign "github.com/cloudflare/circl/sign"
30-
circlSchemes "github.com/cloudflare/circl/sign/schemes"
3128
)
3229

3330
var (
@@ -38,7 +35,6 @@ var (
3835
rsaBits = flag.Int("rsa-bits", 2048, "Size of RSA key to generate. Ignored if --ecdsa-curve is set")
3936
ecdsaCurve = flag.String("ecdsa-curve", "", "ECDSA curve to use to generate a key. Valid values are P224, P256 (recommended), P384, P521")
4037
ed25519Key = flag.Bool("ed25519", false, "Generate an Ed25519 key")
41-
circlKey = flag.String("circl", "", "Generate a key supported by Circl") // [UTLS] ported from cloudflare/go
4238
)
4339

4440
func publicKey(priv any) any {
@@ -49,11 +45,6 @@ func publicKey(priv any) any {
4945
return &k.PublicKey
5046
case ed25519.PrivateKey:
5147
return k.Public().(ed25519.PublicKey)
52-
// [UTLS SECTION BEGINS]
53-
// Ported from cloudflare/go
54-
case circlSign.PrivateKey:
55-
return k.Public()
56-
// [UTLS SECTION ENDS]
5748
default:
5849
return nil
5950
}
@@ -72,15 +63,6 @@ func main() {
7263
case "":
7364
if *ed25519Key {
7465
_, priv, err = ed25519.GenerateKey(rand.Reader)
75-
// [UTLS SECTION BEGINS]
76-
// Ported from cloudflare/go
77-
} else if *circlKey != "" {
78-
scheme := circlSchemes.ByName(*circlKey)
79-
if scheme == nil {
80-
log.Fatalf("No such Circl scheme: %s", *circlKey)
81-
}
82-
_, priv, err = scheme.GenerateKey()
83-
// [UTLS SECTION ENDS]
8466
} else {
8567
priv, err = rsa.GenerateKey(rand.Reader, *rsaBits)
8668
}

handshake_client.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ import (
2727
"github.com/refraction-networking/utls/internal/fips140tls"
2828
"github.com/refraction-networking/utls/internal/hpke"
2929
"github.com/refraction-networking/utls/internal/tls13"
30-
31-
circlSign "github.com/cloudflare/circl/sign"
3230
)
3331

3432
type clientHandshakeState struct {
@@ -1220,7 +1218,7 @@ func (c *Conn) verifyServerCertificate(certificates [][]byte) error {
12201218
}
12211219

12221220
switch certs[0].PublicKey.(type) {
1223-
case *rsa.PublicKey, *ecdsa.PublicKey, ed25519.PublicKey, circlSign.PublicKey: // [UTLS] ported from cloudflare/go
1221+
case *rsa.PublicKey, *ecdsa.PublicKey, ed25519.PublicKey:
12241222
break
12251223
default:
12261224
c.sendAlert(alertUnsupportedCertificate)

handshake_client_tls13.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ func (hs *clientHandshakeStateTLS13) readServerCertificate() error {
850850
}
851851

852852
// See RFC 8446, Section 4.4.3.
853-
if !isSupportedSignatureAlgorithm(certVerify.signatureAlgorithm, c.config.supportedSignatureAlgorithms()) { // [UTLS] ported from cloudflare/go
853+
if !isSupportedSignatureAlgorithm(certVerify.signatureAlgorithm, supportedSignatureAlgorithms()) {
854854
c.sendAlert(alertIllegalParameter)
855855
return errors.New("tls: certificate used with invalid signature algorithm")
856856
}

handshake_server.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import (
1919
"time"
2020

2121
"github.com/refraction-networking/utls/internal/byteorder"
22-
23-
circlSign "github.com/cloudflare/circl/sign"
2422
)
2523

2624
// serverHandshakeState contains details of a server handshake in progress.
@@ -643,7 +641,7 @@ func (hs *serverHandshakeState) doFullHandshake() error {
643641
}
644642
if c.vers >= VersionTLS12 {
645643
certReq.hasSignatureAlgorithm = true
646-
certReq.supportedSignatureAlgorithms = c.config.supportedSignatureAlgorithms() // [UTLS] ported from cloudflare/go
644+
certReq.supportedSignatureAlgorithms = supportedSignatureAlgorithms()
647645
}
648646

649647
// An empty list of certificateAuthorities signals to
@@ -972,7 +970,7 @@ func (c *Conn) processCertsFromClient(certificate Certificate) error {
972970

973971
if len(certs) > 0 {
974972
switch certs[0].PublicKey.(type) {
975-
case *ecdsa.PublicKey, *rsa.PublicKey, ed25519.PublicKey, circlSign.PublicKey: // [UTLS] ported from cloudflare/go
973+
case *ecdsa.PublicKey, *rsa.PublicKey, ed25519.PublicKey:
976974
default:
977975
c.sendAlert(alertUnsupportedCertificate)
978976
return fmt.Errorf("tls: client certificate contains an unsupported public key of type %T", certs[0].PublicKey)

handshake_server_tls13.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ func (hs *serverHandshakeStateTLS13) sendServerCertificate() error {
833833
certReq := new(certificateRequestMsgTLS13)
834834
certReq.ocspStapling = true
835835
certReq.scts = true
836-
certReq.supportedSignatureAlgorithms = c.config.supportedSignatureAlgorithms() // [UTLS] ported from cloudflare/go
836+
certReq.supportedSignatureAlgorithms = supportedSignatureAlgorithms()
837837
if c.config.ClientCAs != nil {
838838
certReq.certificateAuthorities = c.config.ClientCAs.Subjects()
839839
}
@@ -1089,7 +1089,7 @@ func (hs *serverHandshakeStateTLS13) readClientCertificate() error {
10891089
}
10901090

10911091
// See RFC 8446, Section 4.4.3.
1092-
if !isSupportedSignatureAlgorithm(certVerify.signatureAlgorithm, c.config.supportedSignatureAlgorithms()) { // [UTLS] ported from cloudflare/go
1092+
if !isSupportedSignatureAlgorithm(certVerify.signatureAlgorithm, supportedSignatureAlgorithms()) {
10931093
c.sendAlert(alertIllegalParameter)
10941094
return errors.New("tls: client certificate used with invalid signature algorithm")
10951095
}

key_agreement.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func md5SHA1Hash(slices [][]byte) []byte {
130130
// the sigType (for earlier TLS versions). For Ed25519 signatures, which don't
131131
// do pre-hashing, it returns the concatenation of the slices.
132132
func hashForServerKeyExchange(sigType uint8, hashFunc crypto.Hash, version uint16, slices ...[]byte) []byte {
133-
if sigType == signatureEd25519 || circlSchemeBySigType(sigType) != nil { // [UTLS] ported from cloudflare/go
133+
if sigType == signatureEd25519 {
134134
var signed []byte
135135
for _, slice := range slices {
136136
signed = append(signed, slice...)

prf.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,11 @@ func (h finishedHash) serverSum(masterSecret []byte) []byte {
225225
// hashForClientCertificate returns the handshake messages so far, pre-hashed if
226226
// necessary, suitable for signing by a TLS client certificate.
227227
func (h finishedHash) hashForClientCertificate(sigType uint8, hashAlg crypto.Hash) []byte {
228-
if (h.version >= VersionTLS12 || sigType == signatureEd25519 || circlSchemeBySigType(sigType) != nil) && h.buffer == nil { // [UTLS] ported from cloudflare/go
228+
if (h.version >= VersionTLS12 || sigType == signatureEd25519) && h.buffer == nil {
229229
panic("tls: handshake hash for a client certificate requested after discarding the handshake buffer")
230230
}
231231

232-
if sigType == signatureEd25519 || circlSchemeBySigType(sigType) != nil { // [UTLS] ported from cloudflare/go
232+
if sigType == signatureEd25519 {
233233
return h.buffer
234234
}
235235

tls.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ import (
2525
"net"
2626
"os"
2727
"strings"
28-
29-
circlSign "github.com/cloudflare/circl/sign"
3028
)
3129

3230
// Server returns a new TLS server side connection
@@ -345,20 +343,6 @@ func X509KeyPair(certPEMBlock, keyPEMBlock []byte) (Certificate, error) {
345343
if !bytes.Equal(priv.Public().(ed25519.PublicKey), pub) {
346344
return fail(errors.New("tls: private key does not match public key"))
347345
}
348-
// [UTLS SECTION BEGINS]
349-
// Ported from cloudflare/go
350-
case circlSign.PublicKey:
351-
priv, ok := cert.PrivateKey.(circlSign.PrivateKey)
352-
if !ok {
353-
return fail(errors.New("tls: private key type does not match public key type"))
354-
}
355-
pkBytes, err := priv.Public().(circlSign.PublicKey).MarshalBinary()
356-
pkBytes2, err2 := pub.MarshalBinary()
357-
358-
if err != nil || err2 != nil || !bytes.Equal(pkBytes, pkBytes2) {
359-
return fail(errors.New("tls: private key does not match public key"))
360-
}
361-
// [UTLS SECTION ENDS]
362346
default:
363347
return fail(errors.New("tls: unknown public key algorithm"))
364348
}
@@ -375,7 +359,7 @@ func parsePrivateKey(der []byte) (crypto.PrivateKey, error) {
375359
}
376360
if key, err := x509.ParsePKCS8PrivateKey(der); err == nil {
377361
switch key := key.(type) {
378-
case *rsa.PrivateKey, *ecdsa.PrivateKey, ed25519.PrivateKey, circlSign.PrivateKey: // [uTLS] ported from cloudflare/go
362+
case *rsa.PrivateKey, *ecdsa.PrivateKey, ed25519.PrivateKey:
379363
return key, nil
380364
default:
381365
return nil, errors.New("tls: found unknown private key type in PKCS#8 wrapping")

0 commit comments

Comments
 (0)