2323import com .google .errorprone .annotations .CanIgnoreReturnValue ;
2424import com .google .protobuf .ByteString ;
2525import io .grpc .stub .StreamObserver ;
26+ import io .grpc .util .CertificateUtils ;
2627import java .io .File ;
28+ import java .io .FileInputStream ;
29+ import java .io .FileNotFoundException ;
2730import java .io .IOException ;
31+ import java .io .UnsupportedEncodingException ;
2832import java .nio .charset .StandardCharsets ;
2933import java .nio .file .Files ;
30- import java .security .KeyFactory ;
3134import java .security .NoSuchAlgorithmException ;
3235import java .security .PrivateKey ;
3336import java .security .Signature ;
3437import java .security .spec .InvalidKeySpecException ;
35- import java .security .spec .PKCS8EncodedKeySpec ;
36- import java .util .Base64 ;
3738
3839/** A fake Writer Class to mock the behavior of S2A server. */
3940final class FakeWriter implements StreamObserver <SessionReq > {
@@ -59,12 +60,8 @@ enum VerificationResult {
5960 new File ("src/test/resources/int_cert2_ec.pem" );
6061 public static final File cert1File =
6162 new File ("src/test/resources/int_cert1_ec.pem" );
62-
63- // src/test/resources/leaf_key_ec.pem
64- private static final String PRIVATE_KEY =
65- "MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgR2HBqtWTWu4NLiow"
66- + "ar8vh+9vAmCONE59C+jXNAb9r8ehRANCAATRM8ozcr8PTOVsZNWh+rTmJ6t+rODu"
67- + "g3LwWpUQq9h7AddjGlLrrTNrceOyO7nh9aEk5plKhs/h7PO8+vkEFsEx" ;
63+ public static final File keyFile =
64+ new File ("src/test/resources/leaf_key_ec.pem" );
6865 private static final ImmutableMap <SignatureAlgorithm , String >
6966 ALGORITHM_TO_SIGNATURE_INSTANCE_IDENTIFIER =
7067 ImmutableMap .of (
@@ -107,10 +104,12 @@ FakeWriter setFailureReason(String failureReason) {
107104 }
108105
109106 @ CanIgnoreReturnValue
110- FakeWriter initializePrivateKey () throws InvalidKeySpecException , NoSuchAlgorithmException {
107+ FakeWriter initializePrivateKey () throws InvalidKeySpecException , NoSuchAlgorithmException ,
108+ IOException , FileNotFoundException , UnsupportedEncodingException {
109+ FileInputStream keyInputStream =
110+ new FileInputStream (keyFile );
111111 privateKey =
112- KeyFactory .getInstance ("EC" )
113- .generatePrivate (new PKCS8EncodedKeySpec (Base64 .getDecoder ().decode (PRIVATE_KEY )));
112+ CertificateUtils .getPrivateKey (keyInputStream );
114113 return this ;
115114 }
116115
0 commit comments