!269 Use secure padding to obtain the cipher
Merge pull request !269 from luren/fix-security-key
This commit is contained in:
commit
e40b8033c3
|
|
@ -102,6 +102,12 @@
|
|||
<groupId>io.hetu.core</groupId>
|
||||
<artifactId>presto-main</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
|||
|
|
@ -127,6 +127,10 @@
|
|||
<groupId>com.sun</groupId>
|
||||
<artifactId>tools</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
|
|
|
|||
|
|
@ -135,6 +135,12 @@
|
|||
<groupId>io.hetu.core</groupId>
|
||||
<artifactId>presto-main</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
|||
|
|
@ -370,6 +370,12 @@
|
|||
<artifactId>jjwt</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
<version>1.60</version>
|
||||
</dependency>
|
||||
|
||||
<!-- for testing -->
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ package io.prestosql.security;
|
|||
|
||||
import io.prestosql.spi.security.CipherTextDecrypt;
|
||||
import io.prestosql.spi.security.SecurityKeyManager;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
import javax.crypto.Cipher;
|
||||
|
|
@ -27,6 +28,7 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.Security;
|
||||
import java.security.interfaces.RSAPublicKey;
|
||||
import java.security.spec.X509EncodedKeySpec;
|
||||
import java.util.Base64;
|
||||
|
|
@ -38,12 +40,15 @@ public final class RsaCipherTextDecrypt
|
|||
{
|
||||
private static final Charset CHARSET = UTF_8;
|
||||
private static final String RSA = "RSA";
|
||||
private static final String RSA_PADDING = "RSA/NONE/OAEPWITHSHA256AndMGF1Padding";
|
||||
private static final String BC_PROVIDER = "BC";
|
||||
private final SecurityKeyManager keyManager;
|
||||
|
||||
@Inject
|
||||
public RsaCipherTextDecrypt(SecurityKeyManager keyManagerProvider)
|
||||
{
|
||||
this.keyManager = keyManagerProvider;
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -56,7 +61,7 @@ public final class RsaCipherTextDecrypt
|
|||
// generate the public key
|
||||
X509EncodedKeySpec spec = new X509EncodedKeySpec(key);
|
||||
RSAPublicKey publicKey = (RSAPublicKey) factory.generatePublic(spec);
|
||||
Cipher cipher = Cipher.getInstance(RSA);
|
||||
Cipher cipher = Cipher.getInstance(RSA_PADDING, BC_PROVIDER);
|
||||
cipher.init(Cipher.DECRYPT_MODE, publicKey);
|
||||
// decode base64 of cipher text
|
||||
byte[] content = Base64.getDecoder().decode(cipherText);
|
||||
|
|
|
|||
|
|
@ -36,13 +36,13 @@ public class TestPasswordDecryption
|
|||
throws Exception
|
||||
{
|
||||
// save the key
|
||||
String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCKRJEeAPEuVjwTRB8htuPxMJ7K/HVs8PmtWwsPlwF3YCQX37aICblM7/rCbaEDd1B6kWI0D2QVp9vPnjsme951FmuNtzsN9lxfwCXyKp0Zus9YncUuZimztb+EYjm9GHGBYIgk+BgJ8y6imSzkI/d0H3twtSGVSC/YSnmYBc3LpwIDAQAB";
|
||||
String publicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArEhOFoAk46GQzet7C/tmod5Sju91+dDl28TtuFXqOvSz5vvjuEkIK6NI411Lb11vF2P1a9J4ctcA3V3VvXk+H9IsW2jzuXZ774RaACNfMyslmHB+JOoPbTzUSVLyNfb3eSmEhkfYYUrKqlz4tvXUm5FJRX2Xh83yYX1FAnOpuMwzbwaMVLqb8k7LP2uI9+2dTTocE51K3SDH0KoFMyW/uSF9Jj9HLQ1rI9DxCH8UIf7SEwSZ0Pq42fxNW1qjjanYF5tHIp/5l2/O4LUNnZaMTISmT9m9lYt8FTudMtWCMNWarTk8JNkui4x7cSbmE5QaP+s994LK2umBXl95esUSsQIDAQAB";
|
||||
String catalogName = "mysql001";
|
||||
securityKeyManager.saveKey(publicKey, catalogName);
|
||||
|
||||
// set parameters
|
||||
String connectionPasswordCipherText = "U3Z3bfIxliTU7Avh+Uzu30Whc9rb2fqQN23SF0gz0U+L0+jrfrke6ONzzZsdzqUIBlod6Y4D0ESS9wJFdMeRX+YPofsoxOWSDjhxY4IoxNFGQqYK0xxgxpuekBbJwetLHFBmdFGXKfFUAL6EdPbsWbH/cXfot+3FJfziisxXJhE=";
|
||||
String sslPasswordCipherText = "cAI9ZAbdS5QvTUf3ix6m4CPU3XNIy4HjoJhj1chucH7U2J5+CfJ+xi+nf+jwUWD4VJMGvRDxbYr5XNlZsYqUz0/uekcRu8z5c7kKNo1KJalkufQp0OSqFEgGzKaAOxlDcP33oSxo+/Ea3XXxiX4pBfpqw6wsGXDq3X/678pU7fM=";
|
||||
String connectionPasswordCipherText = "huOJCr35k6K2Dgn4InAMJHTyzGvcg+bgOvG+eUxcefML5jPBc3nWc4Wm0nedt1c6g/CKbQksUps/6KP1bcirdkBVwlfpmABwdfGMWuqAQLSUKyi4N1i0zexwDGRgTz0/FuTudlPFDF0XM3iJODB5XfStjxptBPGNAwnRxlmVYnxP2hXHxmY0wmFzk9ZbOj8fLM88dft5T03zBSnErftZ71MNyyskmksI+l9CVB7QDGEaMvhVDb9gSz1t8wTDrxlb0MTmJVl7n7Kw0B1MGmMqWKJA49YhfJJG8ZUPSMkrgTeIGwMqCDs1y2KOZORx5IXYdMJtL01td25OjcKenTuNwQ==";
|
||||
String sslPasswordCipherText = "cjLGNZadxWTIZTQRHkDeu4dBD79M4sKZ1fgWf39NvgBCiYflr/rvcUyCVlNQYV7WXFpl853bInMnzc+FaGk8039T+k7haK3uTk0o3itCAom2HtYcJzh3dhy8ZzsPLXsEldarYlTpFUbCNl3gepiZY98253Nn8J4n+eZidyfSGzecJC00Snfj6Ry7QiwqP90w5/CszMkAg97Ri0z28e5RN+xeM+wlXut2ap7hptpj5sbvJzaU9tjUJJZVxmkPdUk1jy48EpnG7YAtJftxLo6AcEaV7iK/7QaXOLGWUWeOAvGM4e8YIgJdxk8ptqvTAGw+9agRkKLP6Ujic+pPoHnnNA==";
|
||||
Map<String, String> properties = new HashMap<String, String>();
|
||||
properties.put("connection-url", "jdbc:mysql://localhost:3306");
|
||||
properties.put("connection-user", "root");
|
||||
|
|
|
|||
|
|
@ -120,6 +120,12 @@
|
|||
<dependency>
|
||||
<groupId>io.hetu.core</groupId>
|
||||
<artifactId>presto-main</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
|
|
|||
|
|
@ -87,6 +87,12 @@
|
|||
<groupId>io.hetu.core</groupId>
|
||||
<artifactId>presto-main</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
|||
|
|
@ -29,12 +29,24 @@
|
|||
<dependency>
|
||||
<groupId>io.hetu.core</groupId>
|
||||
<artifactId>presto-main</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.hetu.core</groupId>
|
||||
<artifactId>presto-main</artifactId>
|
||||
<type>test-jar</type>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
|||
Loading…
Reference in New Issue