2828import com .eatthepath .pushy .apns .util .ApnsPayloadBuilder ;
2929import com .eatthepath .pushy .apns .util .SimpleApnsPushNotification ;
3030import io .netty .channel .nio .NioEventLoopGroup ;
31+ import io .netty .pkitesting .CertificateBuilder ;
32+ import io .netty .pkitesting .X509Bundle ;
3133import io .netty .util .concurrent .Future ;
3234import org .apache .commons .lang3 .RandomStringUtils ;
3335import org .openjdk .jmh .annotations .*;
3436
3537import java .security .KeyPairGenerator ;
3638import java .security .SecureRandom ;
3739import java .security .interfaces .ECPrivateKey ;
40+ import java .time .Duration ;
41+ import java .time .Instant ;
3842import java .util .ArrayList ;
3943import java .util .List ;
4044import java .util .Random ;
@@ -57,9 +61,8 @@ public class ApnsClientBenchmark {
5761 @ Param ({"1" , "4" , "8" })
5862 public int concurrentConnections ;
5963
60- private static final String CA_CERTIFICATE_FILENAME = "/ca.pem" ;
61- private static final String SERVER_CERTIFICATES_FILENAME = "/server_certs.pem" ;
62- private static final String SERVER_KEY_FILENAME = "/server_key.pem" ;
64+ protected static X509Bundle CA_BUNDLE ;
65+ protected static X509Bundle SERVER_CERTIFICATE_BUNDLE ;
6366
6467 private static final String TOPIC = "com.eatthepath.pushy" ;
6568 private static final String TEAM_ID = "benchmark.team" ;
@@ -77,6 +80,27 @@ public void setUp() throws Exception {
7780 this .clientResources = new ApnsClientResources (new NioEventLoopGroup (this .concurrentConnections ));
7881 this .serverEventLoopGroup = new NioEventLoopGroup (this .concurrentConnections );
7982
83+ final Instant now = Instant .now ();
84+
85+ final CertificateBuilder rootCertificateBuilderTemplate = new CertificateBuilder ()
86+ .notBefore (now )
87+ .notAfter (now .plus (Duration .ofHours (8 )));
88+
89+ CA_BUNDLE = rootCertificateBuilderTemplate .copy ()
90+ .subject ("CN=PushyTestRoot" )
91+ .setKeyUsage (true , CertificateBuilder .KeyUsage .digitalSignature , CertificateBuilder .KeyUsage .keyCertSign )
92+ .setIsCertificateAuthority (true )
93+ .buildSelfSigned ();
94+
95+ SERVER_CERTIFICATE_BUNDLE = rootCertificateBuilderTemplate .copy ()
96+ .subject ("CN=com.eatthepath.pushy" )
97+ .setKeyUsage (true , CertificateBuilder .KeyUsage .digitalSignature , CertificateBuilder .KeyUsage .keyEncipherment )
98+ .addExtendedKeyUsage (CertificateBuilder .ExtendedKeyUsage .PKIX_KP_CLIENT_AUTH )
99+ .addExtendedKeyUsage (CertificateBuilder .ExtendedKeyUsage .PKIX_KP_SERVER_AUTH )
100+ .setIsCertificateAuthority (false )
101+ .addSanDnsName ("localhost" )
102+ .buildIssuedBy (CA_BUNDLE );
103+
80104 final ApnsSigningKey signingKey ;
81105 {
82106 final KeyPairGenerator keyPairGenerator = KeyPairGenerator .getInstance ("EC" );
@@ -89,13 +113,13 @@ public void setUp() throws Exception {
89113 .setApnsServer (HOST , PORT )
90114 .setConcurrentConnections (this .concurrentConnections )
91115 .setSigningKey (signingKey )
92- .setTrustedServerCertificateChain (ApnsClientBenchmark . class . getResourceAsStream ( CA_CERTIFICATE_FILENAME ))
116+ .setTrustedServerCertificateChain (CA_BUNDLE . getCertificate ( ))
93117 .setApnsClientResources (this .clientResources )
94118 .build ();
95119
96120 this .server = new BenchmarkApnsServerBuilder ()
97- .setServerCredentials (getClass (). getResourceAsStream ( SERVER_CERTIFICATES_FILENAME ), this . getClass ().getResourceAsStream ( SERVER_KEY_FILENAME ), null )
98- .setTrustedClientCertificateChain (getClass (). getResourceAsStream ( CA_CERTIFICATE_FILENAME ))
121+ .setServerCredentials (SERVER_CERTIFICATE_BUNDLE . getCertificatePathWithRoot ( ), SERVER_CERTIFICATE_BUNDLE . getKeyPair ().getPrivate () )
122+ .setTrustedClientCertificateChain (CA_BUNDLE . getCertificate ( ))
99123 .setEventLoopGroup (this .serverEventLoopGroup )
100124 .build ();
101125
0 commit comments