|
50 | 50 | import io.grpc.Status;
|
51 | 51 | import io.grpc.internal.JsonParser;
|
52 | 52 | import io.grpc.testing.TestMethodDescriptors;
|
| 53 | +import io.grpc.testing.TlsTesting; |
| 54 | +import io.grpc.util.CertificateUtils; |
53 | 55 | import java.io.IOException;
|
| 56 | +import java.io.InputStream; |
54 | 57 | import java.net.URI;
|
55 |
| -import java.security.KeyPair; |
56 |
| -import java.security.KeyPairGenerator; |
| 58 | +import java.security.PrivateKey; |
57 | 59 | import java.util.ArrayList;
|
58 | 60 | import java.util.Date;
|
59 | 61 | import java.util.List;
|
@@ -342,15 +344,18 @@ public void serviceUri() throws Exception {
|
342 | 344 |
|
343 | 345 | @Test
|
344 | 346 | public void serviceAccountToJwt() throws Exception {
|
345 |
| - KeyPair pair = KeyPairGenerator.getInstance("RSA").generateKeyPair(); |
| 347 | + PrivateKey privateKey; |
| 348 | + try (InputStream server1Key = TlsTesting.loadCert("server1.key")) { |
| 349 | + privateKey = CertificateUtils.getPrivateKey(server1Key); |
| 350 | + } |
346 | 351 |
|
347 | 352 | HttpTransportFactory factory = Mockito.mock(HttpTransportFactory.class);
|
348 | 353 | Mockito.when(factory.create()).thenThrow(new AssertionError());
|
349 | 354 |
|
350 | 355 | ServiceAccountCredentials credentials =
|
351 | 356 | ServiceAccountCredentials.newBuilder()
|
352 | 357 | . setClientEmail( "[email protected]")
|
353 |
| - .setPrivateKey(pair.getPrivate()) |
| 358 | + .setPrivateKey(privateKey) |
354 | 359 | .setPrivateKeyId("test-private-key-id")
|
355 | 360 | .setHttpTransportFactory(factory)
|
356 | 361 | .build();
|
@@ -390,13 +395,16 @@ public void oauthClassesNotInClassPath() throws Exception {
|
390 | 395 |
|
391 | 396 | @Test
|
392 | 397 | public void jwtAccessCredentialsInRequestMetadata() throws Exception {
|
393 |
| - KeyPair pair = KeyPairGenerator.getInstance("RSA").generateKeyPair(); |
| 398 | + PrivateKey privateKey; |
| 399 | + try (InputStream server1Key = TlsTesting.loadCert("server1.key")) { |
| 400 | + privateKey = CertificateUtils.getPrivateKey(server1Key); |
| 401 | + } |
394 | 402 |
|
395 | 403 | ServiceAccountCredentials credentials =
|
396 | 404 | ServiceAccountCredentials.newBuilder()
|
397 | 405 | .setClientId("test-client")
|
398 | 406 | . setClientEmail( "[email protected]")
|
399 |
| - .setPrivateKey(pair.getPrivate()) |
| 407 | + .setPrivateKey(privateKey) |
400 | 408 | .setPrivateKeyId("test-private-key-id")
|
401 | 409 | .setQuotaProjectId("test-quota-project-id")
|
402 | 410 | .build();
|
|
0 commit comments