|
1 | 1 | package org.embulk.output.snowflake; |
2 | 2 |
|
3 | | -import net.snowflake.client.jdbc.internal.org.bouncycastle.asn1.pkcs.PrivateKeyInfo; |
4 | | -import net.snowflake.client.jdbc.internal.org.bouncycastle.jce.provider.BouncyCastleProvider; |
5 | | -import net.snowflake.client.jdbc.internal.org.bouncycastle.openssl.PEMParser; |
6 | | -import net.snowflake.client.jdbc.internal.org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter; |
7 | | - |
8 | 3 | import java.io.IOException; |
9 | 4 | import java.io.StringReader; |
10 | 5 | import java.security.PrivateKey; |
11 | 6 | import java.security.Security; |
| 7 | +import net.snowflake.client.jdbc.internal.org.bouncycastle.asn1.pkcs.PrivateKeyInfo; |
| 8 | +import net.snowflake.client.jdbc.internal.org.bouncycastle.jce.provider.BouncyCastleProvider; |
| 9 | +import net.snowflake.client.jdbc.internal.org.bouncycastle.openssl.PEMParser; |
| 10 | +import net.snowflake.client.jdbc.internal.org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter; |
12 | 11 |
|
13 | | -// ref: https://docs.snowflake.com/en/developer-guide/jdbc/jdbc-configure#privatekey-property-in-connection-properties |
14 | | -public class PrivateKeyReader |
15 | | -{ |
16 | | - public static PrivateKey get(String pemString) throws IOException { |
17 | | - Security.addProvider(new BouncyCastleProvider()); |
18 | | - PEMParser pemParser = new PEMParser(new StringReader(pemString)); |
19 | | - Object pemObject = pemParser.readObject(); |
20 | | - pemParser.close(); |
| 12 | +// ref: |
| 13 | +// https://docs.snowflake.com/en/developer-guide/jdbc/jdbc-configure#privatekey-property-in-connection-properties |
| 14 | +public class PrivateKeyReader { |
| 15 | + public static PrivateKey get(String pemString) throws IOException { |
| 16 | + Security.addProvider(new BouncyCastleProvider()); |
| 17 | + PEMParser pemParser = new PEMParser(new StringReader(pemString)); |
| 18 | + Object pemObject = pemParser.readObject(); |
| 19 | + pemParser.close(); |
21 | 20 |
|
22 | | - PrivateKeyInfo privateKeyInfo; |
23 | | - if (pemObject instanceof PrivateKeyInfo) { |
24 | | - privateKeyInfo = (PrivateKeyInfo) pemObject; |
25 | | - } else { |
26 | | - throw new IllegalArgumentException("Provided PEM does not contain a valid Private Key"); |
27 | | - } |
28 | | - JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider(BouncyCastleProvider.PROVIDER_NAME); |
29 | | - return converter.getPrivateKey(privateKeyInfo); |
| 21 | + PrivateKeyInfo privateKeyInfo; |
| 22 | + if (pemObject instanceof PrivateKeyInfo) { |
| 23 | + privateKeyInfo = (PrivateKeyInfo) pemObject; |
| 24 | + } else { |
| 25 | + throw new IllegalArgumentException("Provided PEM does not contain a valid Private Key"); |
30 | 26 | } |
31 | | - |
| 27 | + JcaPEMKeyConverter converter = |
| 28 | + new JcaPEMKeyConverter().setProvider(BouncyCastleProvider.PROVIDER_NAME); |
| 29 | + return converter.getPrivateKey(privateKeyInfo); |
| 30 | + } |
32 | 31 | } |
0 commit comments