55import java .util .Hashtable ;
66import java .util .Vector ;
77
8- import junit .framework .TestCase ;
98import org .bouncycastle .crypto .params .Ed25519PrivateKeyParameters ;
109import org .bouncycastle .crypto .util .SubjectPublicKeyInfoFactory ;
1110import org .bouncycastle .tls .Certificate ;
2221import org .bouncycastle .tls .TlsCredentials ;
2322import org .bouncycastle .tls .TlsUtils ;
2423import org .bouncycastle .tls .crypto .TlsCertificate ;
25- import org .bouncycastle .tls .crypto .TlsCrypto ;
2624import org .bouncycastle .tls .crypto .TlsCryptoParameters ;
2725import org .bouncycastle .tls .crypto .impl .bc .BcDefaultTlsCredentialedSigner ;
2826import org .bouncycastle .tls .crypto .impl .bc .BcTlsCrypto ;
2927import org .bouncycastle .tls .crypto .impl .bc .BcTlsRawKeyCertificate ;
3028
29+ import junit .framework .TestCase ;
30+
3131class MockRawKeysTlsServer extends DefaultTlsServer
3232{
33-
3433 private short serverCertType ;
3534 private short clientCertType ;
3635 private short [] allowedClientCertTypes ;
@@ -40,11 +39,11 @@ class MockRawKeysTlsServer extends DefaultTlsServer
4039
4140 Hashtable receivedClientExtensions ;
4241
43- MockRawKeysTlsServer (short serverCertType , short clientCertType ,
44- short [] allowedClientCertTypes , Ed25519PrivateKeyParameters privateKey ,
45- ProtocolVersion tlsVersion ) throws Exception
42+ MockRawKeysTlsServer (short serverCertType , short clientCertType , short [] allowedClientCertTypes ,
43+ Ed25519PrivateKeyParameters privateKey , ProtocolVersion tlsVersion ) throws Exception
4644 {
4745 super (new BcTlsCrypto (new SecureRandom ()));
46+
4847 this .serverCertType = serverCertType ;
4948 this .clientCertType = clientCertType ;
5049 this .allowedClientCertTypes = allowedClientCertTypes ;
@@ -68,47 +67,44 @@ public TlsCredentials getCredentials() throws IOException
6867
6968 protected ProtocolVersion [] getSupportedVersions ()
7069 {
71- return new ProtocolVersion [] { tlsVersion };
70+ return new ProtocolVersion []{ tlsVersion };
7271 }
7372
7473 protected int [] getSupportedCipherSuites ()
7574 {
76- return ProtocolVersion . TLSv13 . equals (tlsVersion ) ?
77- new int [] { CipherSuite .TLS_AES_128_GCM_SHA256 } :
78- new int [] { CipherSuite .TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 };
75+ return TlsUtils . isTLSv13 (tlsVersion )
76+ ? new int []{ CipherSuite .TLS_AES_128_GCM_SHA256 }
77+ : new int []{ CipherSuite .TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 };
7978 }
8079
8180 public void processClientExtensions (Hashtable clientExtensions ) throws IOException
8281 {
83- receivedClientExtensions = clientExtensions ;
82+ this .receivedClientExtensions = clientExtensions ;
83+
8484 super .processClientExtensions (clientExtensions );
8585 }
8686
8787 protected TlsCredentialedSigner getECDSASignerCredentials () throws IOException
8888 {
8989 if (credentials == null )
9090 {
91+ BcTlsCrypto crypto = (BcTlsCrypto )getCrypto ();
92+
9193 switch (serverCertType )
9294 {
9395 case CertificateType .X509 :
94- credentials = TlsTestUtils .loadSignerCredentials (
95- context , context .getSecurityParametersHandshake ().getClientSigAlgs (),
96- SignatureAlgorithm . ed25519 , "x509-client-ed25519.pem" , "x509-client-key-ed25519.pem" );
96+ credentials = TlsTestUtils .loadSignerCredentials (context ,
97+ context .getSecurityParametersHandshake ().getClientSigAlgs (), SignatureAlgorithm . ed25519 ,
98+ "x509-client-ed25519.pem" , "x509-client-key-ed25519.pem" );
9799 break ;
98100 case CertificateType .RawPublicKey :
99- TlsCertificate rawKeyCert = new BcTlsRawKeyCertificate (
100- (BcTlsCrypto )getCrypto (),
101- SubjectPublicKeyInfoFactory .createSubjectPublicKeyInfo (privateKey .generatePublicKey ()));
102- Certificate cert = new Certificate (
103- CertificateType .RawPublicKey ,
104- TlsUtils .isTLSv13 (context ) ? TlsUtils .EMPTY_BYTES : null ,
105- new CertificateEntry [] {new CertificateEntry (rawKeyCert , null )});
106- credentials = new BcDefaultTlsCredentialedSigner (
107- new TlsCryptoParameters (context ),
108- (BcTlsCrypto )getCrypto (),
109- privateKey ,
110- cert ,
111- SignatureAndHashAlgorithm .ed25519 );
101+ TlsCertificate rawKeyCert = new BcTlsRawKeyCertificate (crypto ,
102+ SubjectPublicKeyInfoFactory .createSubjectPublicKeyInfo (privateKey .generatePublicKey ()));
103+ Certificate cert = new Certificate (CertificateType .RawPublicKey ,
104+ TlsUtils .isTLSv13 (context ) ? TlsUtils .EMPTY_BYTES : null ,
105+ new CertificateEntry []{ new CertificateEntry (rawKeyCert , null ) });
106+ credentials = new BcDefaultTlsCredentialedSigner (new TlsCryptoParameters (context ),
107+ crypto , privateKey , cert , SignatureAndHashAlgorithm .ed25519 );
112108 break ;
113109 default :
114110 throw new IllegalArgumentException ("Only supports X509 and raw keys" );
@@ -140,26 +136,21 @@ public CertificateRequest getCertificateRequest() throws IOException
140136 return null ;
141137 }
142138
143- short [] certificateTypes = new short [] { ClientCertificateType .ecdsa_sign };
139+ short [] certificateTypes = new short []{ ClientCertificateType .ecdsa_sign };
144140
145141 Vector serverSigAlgs = null ;
146142 if (TlsUtils .isSignatureAlgorithmsExtensionAllowed (context .getServerVersion ()))
147143 {
148144 serverSigAlgs = TlsUtils .getDefaultSupportedSignatureAlgorithms (context );
149145 }
150146
151- return ProtocolVersion . TLSv13 . equals (tlsVersion ) ?
152- new CertificateRequest (TlsUtils .EMPTY_BYTES , serverSigAlgs , null , null ) :
153- new CertificateRequest (certificateTypes , serverSigAlgs , null );
147+ return TlsUtils . isTLSv13 (tlsVersion )
148+ ? new CertificateRequest (TlsUtils .EMPTY_BYTES , serverSigAlgs , null , null )
149+ : new CertificateRequest (certificateTypes , serverSigAlgs , null );
154150 }
155151
156152 public void notifyClientCertificate (Certificate clientCertificate ) throws IOException
157153 {
158154 TestCase .assertEquals ("client certificate is the wrong type" , clientCertType , clientCertificate .getCertificateType ());
159155 }
160-
161- public TlsCrypto getCrypto ()
162- {
163- return super .getCrypto ();
164- }
165156}
0 commit comments