3333import org .bouncycastle .util .encoders .Hex ;
3434
3535class MockTlsKemClient
36- extends DefaultTlsClient
36+ extends DefaultTlsClient
3737{
3838 TlsSession session ;
3939
40+ int [] namedGroups = new int []
41+ {
42+ NamedGroup .MLKEM512 ,
43+ NamedGroup .MLKEM768 ,
44+ NamedGroup .MLKEM1024 ,
45+ };
46+
4047 MockTlsKemClient (TlsSession session )
4148 {
4249 super (new BcTlsCrypto ());
@@ -52,25 +59,19 @@ protected Vector getProtocolNames()
5259 return protocolNames ;
5360 }
5461
55- public int [] supportedGroups = new int [] {
56- NamedGroup .MLKEM512 ,
57- NamedGroup .MLKEM768 ,
58- NamedGroup .MLKEM1024 ,
59- };
60-
61- public void setSupportedGroups (int [] supportedGroups )
62+ void setNamedGroups (int [] namedGroups )
6263 {
63- this .supportedGroups = supportedGroups ;
64+ this .namedGroups = namedGroups ;
6465 }
6566
6667 protected Vector getSupportedGroups (Vector namedGroupRoles ) {
6768 TlsCrypto crypto = getCrypto ();
6869 Vector supportedGroups = new Vector ();
6970
70- if (namedGroupRoles .contains (Integers .valueOf (NamedGroupRole .kem ))) {
71- TlsUtils . addIfSupported ( supportedGroups , crypto ,
72- this .supportedGroups );
73- };
71+ if (namedGroupRoles .contains (Integers .valueOf (NamedGroupRole .kem )))
72+ {
73+ TlsUtils . addIfSupported ( supportedGroups , crypto , this .namedGroups );
74+ }
7475 return supportedGroups ;
7576 }
7677
@@ -82,8 +83,8 @@ public TlsSession getSessionToResume()
8283 public void notifyAlertRaised (short alertLevel , short alertDescription , String message , Throwable cause )
8384 {
8485 PrintStream out = (alertLevel == AlertLevel .fatal ) ? System .err : System .out ;
85- out .println ("TLS client raised alert: " + AlertLevel .getText (alertLevel )
86- + ", " + AlertDescription .getText (alertDescription ));
86+ out .println ("TLS KEM client raised alert: " + AlertLevel .getText (alertLevel )
87+ + ", " + AlertDescription .getText (alertDescription ));
8788 if (message != null )
8889 {
8990 out .println ("> " + message );
@@ -98,7 +99,7 @@ public void notifyAlertReceived(short alertLevel, short alertDescription)
9899 {
99100 PrintStream out = (alertLevel == AlertLevel .fatal ) ? System .err : System .out ;
100101 out .println ("TLS KEM client received alert: " + AlertLevel .getText (alertLevel )
101- + ", " + AlertDescription .getText (alertDescription ));
102+ + ", " + AlertDescription .getText (alertDescription ));
102103 }
103104
104105 public Hashtable getClientExtensions () throws IOException
@@ -141,24 +142,24 @@ public void notifyServerCertificate(TlsServerCertificate serverCertificate) thro
141142 Certificate entry = Certificate .getInstance (chain [i ].getEncoded ());
142143 // TODO Create fingerprint based on certificate signature algorithm digest
143144 System .out .println (" fingerprint:SHA-256 " + TlsTestUtils .fingerprint (entry ) + " ("
144- + entry .getSubject () + ")" );
145+ + entry .getSubject () + ")" );
145146 }
146147
147148 boolean isEmpty = serverCertificate == null || serverCertificate .getCertificate () == null
148- || serverCertificate .getCertificate ().isEmpty ();
149+ || serverCertificate .getCertificate ().isEmpty ();
149150
150151 if (isEmpty )
151152 {
152153 throw new TlsFatalAlert (AlertDescription .bad_certificate );
153154 }
154155
155156 String [] trustedCertResources = new String []{ "x509-server-dsa.pem" , "x509-server-ecdh.pem" ,
156- "x509-server-ecdsa.pem" , "x509-server-ed25519.pem" , "x509-server-ed448.pem" ,
157- "x509-server-rsa_pss_256.pem" , "x509-server-rsa_pss_384.pem" , "x509-server-rsa_pss_512.pem" ,
158- "x509-server-rsa-enc.pem" , "x509-server-rsa-sign.pem" };
157+ "x509-server-ecdsa.pem" , "x509-server-ed25519.pem" , "x509-server-ed448.pem" ,
158+ "x509-server-rsa_pss_256.pem" , "x509-server-rsa_pss_384.pem" , "x509-server-rsa_pss_512.pem" ,
159+ "x509-server-rsa-enc.pem" , "x509-server-rsa-sign.pem" };
159160
160161 TlsCertificate [] certPath = TlsTestUtils .getTrustedCertPath (context .getCrypto (), chain [0 ],
161- trustedCertResources );
162+ trustedCertResources );
162163
163164 if (null == certPath )
164165 {
@@ -177,7 +178,7 @@ public TlsCredentials getClientCredentials(CertificateRequest certificateRequest
177178 }
178179
179180 return TlsTestUtils .loadSignerCredentials (context , certificateRequest .getSupportedSignatureAlgorithms (),
180- SignatureAlgorithm .rsa , "x509-client-rsa.pem" , "x509-client-key-rsa.pem" );
181+ SignatureAlgorithm .rsa , "x509-client-rsa.pem" , "x509-client-key-rsa.pem" );
181182 }
182183 };
183184 }
@@ -189,7 +190,7 @@ public void notifyHandshakeComplete() throws IOException
189190 ProtocolName protocolName = context .getSecurityParametersConnection ().getApplicationProtocol ();
190191 if (protocolName != null )
191192 {
192- System .out .println ("KEM Client ALPN: " + protocolName .getUtf8Decoding ());
193+ System .out .println ("Client ALPN: " + protocolName .getUtf8Decoding ());
193194 }
194195
195196 TlsSession newSession = context .getSession ();
@@ -202,11 +203,11 @@ public void notifyHandshakeComplete() throws IOException
202203
203204 if (this .session != null && Arrays .areEqual (this .session .getSessionID (), newSessionID ))
204205 {
205- System .out .println ("KEM Client resumed session: " + hex );
206+ System .out .println ("Client resumed session: " + hex );
206207 }
207208 else
208209 {
209- System .out .println ("KEM Client established session: " + hex );
210+ System .out .println ("Client established session: " + hex );
210211 }
211212
212213 this .session = newSession ;
@@ -215,14 +216,14 @@ public void notifyHandshakeComplete() throws IOException
215216 byte [] tlsServerEndPoint = context .exportChannelBinding (ChannelBinding .tls_server_end_point );
216217 if (null != tlsServerEndPoint )
217218 {
218- System .out .println ("KEM Client 'tls-server-end-point': " + hex (tlsServerEndPoint ));
219+ System .out .println ("Client 'tls-server-end-point': " + hex (tlsServerEndPoint ));
219220 }
220221
221222 byte [] tlsUnique = context .exportChannelBinding (ChannelBinding .tls_unique );
222- System .out .println ("KEM Client 'tls-unique': " + hex (tlsUnique ));
223+ System .out .println ("Client 'tls-unique': " + hex (tlsUnique ));
223224
224225 byte [] tlsExporter = context .exportChannelBinding (ChannelBinding .tls_exporter );
225- System .out .println ("KEM Client 'tls-exporter': " + hex (tlsExporter ));
226+ System .out .println ("Client 'tls-exporter': " + hex (tlsExporter ));
226227 }
227228 }
228229
@@ -240,4 +241,5 @@ protected String hex(byte[] data)
240241 {
241242 return data == null ? "(null)" : Hex .toHexString (data );
242243 }
243- }
244+ }
245+
0 commit comments