@@ -16,6 +16,7 @@ import (
16
16
"crypto/rsa"
17
17
"crypto/sha512"
18
18
"crypto/x509"
19
+ "crypto/x509/pkix"
19
20
"encoding/binary"
20
21
"errors"
21
22
"fmt"
@@ -26,6 +27,7 @@ import (
26
27
"sort"
27
28
"time"
28
29
30
+ "github.com/cloudflare/circl/sign/mldsa/mldsa65"
29
31
"github.com/xtls/reality/fips140tls"
30
32
"github.com/xtls/reality/hpke"
31
33
"github.com/xtls/reality/tls13"
@@ -70,19 +72,26 @@ type serverHandshakeStateTLS13 struct {
70
72
}
71
73
72
74
var (
73
- ed25519Priv ed25519.PrivateKey
74
- signedCert []byte
75
+ ed25519Priv ed25519.PrivateKey
76
+ signedCert []byte
77
+ signedCertMldsa65 []byte
75
78
)
76
79
77
80
func init () {
78
81
certificate := x509.Certificate {SerialNumber : & big.Int {}}
82
+ certificateMldsa65 := x509.Certificate {SerialNumber : & big.Int {}, ExtraExtensions : []pkix.Extension {{Id : []int {0 , 0 }, Value : empty [:3309 ]}}}
79
83
_ , ed25519Priv , _ = ed25519 .GenerateKey (rand .Reader )
80
84
signedCert , _ = x509 .CreateCertificate (rand .Reader , & certificate , & certificate , ed25519 .PublicKey (ed25519Priv [32 :]), ed25519Priv )
85
+ signedCertMldsa65 , _ = x509 .CreateCertificate (rand .Reader , & certificateMldsa65 , & certificateMldsa65 , ed25519 .PublicKey (ed25519Priv [32 :]), ed25519Priv )
81
86
}
82
87
83
88
func (hs * serverHandshakeStateTLS13 ) handshake () error {
84
89
c := hs .c
85
-
90
+ if c .config .Show {
91
+ remoteAddr := c .RemoteAddr ().String ()
92
+ fmt .Printf ("REALITY remoteAddr: %v\t is using X25519MLKEM768 for TLS' communication: %v\n " , remoteAddr , hs .hello .serverShare .group == X25519MLKEM768 )
93
+ fmt .Printf ("REALITY remoteAddr: %v\t is using ML-DSA-65 for cert's extra signature: %v\n " , remoteAddr , len (c .config .Mldsa65Key ) > 0 )
94
+ }
86
95
// For an overview of the TLS 1.3 handshake, see RFC 8446, Section 2.
87
96
/*
88
97
if err := hs.processClientHello(); err != nil {
@@ -130,14 +139,26 @@ func (hs *serverHandshakeStateTLS13) handshake() error {
130
139
}
131
140
*/
132
141
{
133
- signedCert := append ([]byte {}, signedCert ... )
142
+ var cert []byte
143
+ if len (c .config .Mldsa65Key ) > 0 {
144
+ cert = bytes .Clone (signedCertMldsa65 )
145
+ } else {
146
+ cert = bytes .Clone (signedCert )
147
+ }
134
148
135
149
h := hmac .New (sha512 .New , c .AuthKey )
136
150
h .Write (ed25519Priv [32 :])
137
- h .Sum (signedCert [:len (signedCert )- 64 ])
151
+ h .Sum (cert [:len (cert )- 64 ])
152
+
153
+ if len (c .config .Mldsa65Key ) > 0 {
154
+ h .Write (hs .clientHello .original )
155
+ h .Write (hs .hello .original )
156
+ key , _ := mldsa65 .Scheme ().UnmarshalBinaryPrivateKey (c .config .Mldsa65Key )
157
+ mldsa65 .SignTo (key .(* mldsa65.PrivateKey ), h .Sum (nil ), nil , false , cert [126 :]) // fixed location
158
+ }
138
159
139
160
hs .cert = & Certificate {
140
- Certificate : [][]byte {signedCert },
161
+ Certificate : [][]byte {cert },
141
162
PrivateKey : ed25519Priv ,
142
163
}
143
164
hs .sigAlg = Ed25519
0 commit comments