"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "zookeeper-server/src/test/java/org/apache/zookeeper/common/X509TestContext.java" between
apache-zookeeper-3.5.5.tar.gz and apache-zookeeper-3.5.6.tar.gz

About: Apache ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services (was a sub-project of Hadoop).

X509TestContext.java  (apache-zookeeper-3.5.5):X509TestContext.java  (apache-zookeeper-3.5.6)
skipping to change at line 56 skipping to change at line 56
private final File tempDir; private final File tempDir;
private final X509KeyType trustStoreKeyType; private final X509KeyType trustStoreKeyType;
private final KeyPair trustStoreKeyPair; private final KeyPair trustStoreKeyPair;
private final long trustStoreCertExpirationMillis; private final long trustStoreCertExpirationMillis;
private final X509Certificate trustStoreCertificate; private final X509Certificate trustStoreCertificate;
private final String trustStorePassword; private final String trustStorePassword;
private File trustStoreJksFile; private File trustStoreJksFile;
private File trustStorePemFile; private File trustStorePemFile;
private File trustStorePkcs12File;
private final X509KeyType keyStoreKeyType; private final X509KeyType keyStoreKeyType;
private final KeyPair keyStoreKeyPair; private final KeyPair keyStoreKeyPair;
private final long keyStoreCertExpirationMillis; private final long keyStoreCertExpirationMillis;
private final X509Certificate keyStoreCertificate; private final X509Certificate keyStoreCertificate;
private final String keyStorePassword; private final String keyStorePassword;
private File keyStoreJksFile; private File keyStoreJksFile;
private File keyStorePemFile; private File keyStorePemFile;
private File keyStorePkcs12File;
private final Boolean hostnameVerification; private final Boolean hostnameVerification;
/** /**
* Constructor is intentionally private, use the Builder class instead. * Constructor is intentionally private, use the Builder class instead.
* @param tempDir the directory in which key store and trust store temp file s will be written. * @param tempDir the directory in which key store and trust store temp file s will be written.
* @param trustStoreKeyPair the key pair for the trust store. * @param trustStoreKeyPair the key pair for the trust store.
* @param trustStoreCertExpirationMillis the expiration of the trust store c ert, in milliseconds from now. * @param trustStoreCertExpirationMillis the expiration of the trust store c ert, in milliseconds from now.
* @param trustStorePassword the password to protect a JKS trust store (igno red for PEM trust stores). * @param trustStorePassword the password to protect a JKS trust store (igno red for PEM trust stores).
* @param keyStoreKeyPair the key pair for the key store. * @param keyStoreKeyPair the key pair for the key store.
skipping to change at line 119 skipping to change at line 121
trustStoreCertExpirationMillis); trustStoreCertExpirationMillis);
X500NameBuilder nameBuilder = new X500NameBuilder(BCStyle.INSTANCE); X500NameBuilder nameBuilder = new X500NameBuilder(BCStyle.INSTANCE);
nameBuilder.addRDN(BCStyle.CN, MethodHandles.lookup().lookupClass().getC anonicalName() + " Zookeeper Test"); nameBuilder.addRDN(BCStyle.CN, MethodHandles.lookup().lookupClass().getC anonicalName() + " Zookeeper Test");
keyStoreCertificate = X509TestHelpers.newCert( keyStoreCertificate = X509TestHelpers.newCert(
trustStoreCertificate, trustStoreCertificate,
trustStoreKeyPair, trustStoreKeyPair,
nameBuilder.build(), nameBuilder.build(),
keyStoreKeyPair.getPublic(), keyStoreKeyPair.getPublic(),
keyStoreCertExpirationMillis); keyStoreCertExpirationMillis);
trustStorePemFile = trustStoreJksFile = keyStorePemFile = keyStoreJksFil trustStorePkcs12File = trustStorePemFile = trustStoreJksFile = null;
e = null; keyStorePkcs12File = keyStorePemFile = keyStoreJksFile = null;
this.hostnameVerification = hostnameVerification; this.hostnameVerification = hostnameVerification;
} }
/** /**
* Returns the X509KeyType of the given key pair. * Returns the X509KeyType of the given key pair.
* @param keyPair the key pair. * @param keyPair the key pair.
* @return <code>X509KeyType.RSA</code> if given an RSA key pair, and <code> X509KeyType.EC</code> otherwise. * @return <code>X509KeyType.RSA</code> if given an RSA key pair, and <code> X509KeyType.EC</code> otherwise.
*/ */
private X509KeyType keyPairToType(KeyPair keyPair) { private X509KeyType keyPairToType(KeyPair keyPair) {
skipping to change at line 174 skipping to change at line 177
* @param storeFileType the store file type (JKS or PEM). * @param storeFileType the store file type (JKS or PEM).
* @return the path to the trust store file. * @return the path to the trust store file.
* @throws IOException if there is an error creating the trust store file. * @throws IOException if there is an error creating the trust store file.
*/ */
public File getTrustStoreFile(KeyStoreFileType storeFileType) throws IOExcep tion { public File getTrustStoreFile(KeyStoreFileType storeFileType) throws IOExcep tion {
switch (storeFileType) { switch (storeFileType) {
case JKS: case JKS:
return getTrustStoreJksFile(); return getTrustStoreJksFile();
case PEM: case PEM:
return getTrustStorePemFile(); return getTrustStorePemFile();
case PKCS12:
return getTrustStorePkcs12File();
default: default:
throw new IllegalArgumentException("Invalid trust store type: " + storeFileType + ", must be one of: " + throw new IllegalArgumentException("Invalid trust store type: " + storeFileType + ", must be one of: " +
Arrays.toString(KeyStoreFileType.values())); Arrays.toString(KeyStoreFileType.values()));
} }
} }
private File getTrustStoreJksFile() throws IOException { private File getTrustStoreJksFile() throws IOException {
if (trustStoreJksFile == null) { if (trustStoreJksFile == null) {
try { File trustStoreJksFile = File.createTempFile(
File trustStoreJksFile = File.createTempFile( TRUST_STORE_PREFIX, KeyStoreFileType.JKS.getDefaultFileExtension
TRUST_STORE_PREFIX, KeyStoreFileType.JKS.getDefaultFileE (), tempDir);
xtension(), tempDir); trustStoreJksFile.deleteOnExit();
trustStoreJksFile.deleteOnExit(); try (final FileOutputStream trustStoreOutputStream = new FileOutputS
final FileOutputStream trustStoreOutputStream = new FileOutputSt tream(trustStoreJksFile)) {
ream(trustStoreJksFile); byte[] bytes = X509TestHelpers.certToJavaTrustStoreBytes(trustSt
try { oreCertificate, trustStorePassword);
byte[] bytes = X509TestHelpers.certToJavaTrustStoreBytes(tru trustStoreOutputStream.write(bytes);
stStoreCertificate, trustStorePassword); trustStoreOutputStream.flush();
trustStoreOutputStream.write(bytes);
trustStoreOutputStream.flush();
} finally {
trustStoreOutputStream.close();
}
this.trustStoreJksFile = trustStoreJksFile;
} catch (GeneralSecurityException e) { } catch (GeneralSecurityException e) {
throw new IOException(e); throw new IOException(e);
} }
this.trustStoreJksFile = trustStoreJksFile;
} }
return trustStoreJksFile; return trustStoreJksFile;
} }
private File getTrustStorePemFile() throws IOException { private File getTrustStorePemFile() throws IOException {
if (trustStorePemFile == null) { if (trustStorePemFile == null) {
File trustStorePemFile = File.createTempFile( File trustStorePemFile = File.createTempFile(
TRUST_STORE_PREFIX, KeyStoreFileType.PEM.getDefaultFileExten sion(), tempDir); TRUST_STORE_PREFIX, KeyStoreFileType.PEM.getDefaultFileExten sion(), tempDir);
trustStorePemFile.deleteOnExit(); trustStorePemFile.deleteOnExit();
FileUtils.writeStringToFile( FileUtils.writeStringToFile(
trustStorePemFile, trustStorePemFile,
X509TestHelpers.pemEncodeX509Certificate(trustStoreCertifica te), X509TestHelpers.pemEncodeX509Certificate(trustStoreCertifica te),
StandardCharsets.US_ASCII, StandardCharsets.US_ASCII,
false); false);
this.trustStorePemFile = trustStorePemFile; this.trustStorePemFile = trustStorePemFile;
} }
return trustStorePemFile; return trustStorePemFile;
} }
private File getTrustStorePkcs12File() throws IOException {
if (trustStorePkcs12File == null) {
File trustStorePkcs12File = File.createTempFile(
TRUST_STORE_PREFIX, KeyStoreFileType.PKCS12.getDefaultFileExtens
ion(), tempDir);
trustStorePkcs12File.deleteOnExit();
try (final FileOutputStream trustStoreOutputStream = new FileOutputS
tream(trustStorePkcs12File)) {
byte[] bytes = X509TestHelpers.certToPKCS12TrustStoreBytes(trust
StoreCertificate, trustStorePassword);
trustStoreOutputStream.write(bytes);
trustStoreOutputStream.flush();
} catch (GeneralSecurityException e) {
throw new IOException(e);
}
this.trustStorePkcs12File = trustStorePkcs12File;
}
return trustStorePkcs12File;
}
public X509KeyType getKeyStoreKeyType() { public X509KeyType getKeyStoreKeyType() {
return keyStoreKeyType; return keyStoreKeyType;
} }
public KeyPair getKeyStoreKeyPair() { public KeyPair getKeyStoreKeyPair() {
return keyStoreKeyPair; return keyStoreKeyPair;
} }
public long getKeyStoreCertExpirationMillis() { public long getKeyStoreCertExpirationMillis() {
return keyStoreCertExpirationMillis; return keyStoreCertExpirationMillis;
skipping to change at line 254 skipping to change at line 271
* @param storeFileType the store file type (JKS or PEM). * @param storeFileType the store file type (JKS or PEM).
* @return the path to the key store file. * @return the path to the key store file.
* @throws IOException if there is an error creating the key store file. * @throws IOException if there is an error creating the key store file.
*/ */
public File getKeyStoreFile(KeyStoreFileType storeFileType) throws IOExcepti on { public File getKeyStoreFile(KeyStoreFileType storeFileType) throws IOExcepti on {
switch (storeFileType) { switch (storeFileType) {
case JKS: case JKS:
return getKeyStoreJksFile(); return getKeyStoreJksFile();
case PEM: case PEM:
return getKeyStorePemFile(); return getKeyStorePemFile();
case PKCS12:
return getKeyStorePkcs12File();
default: default:
throw new IllegalArgumentException("Invalid key store type: " + storeFileType + ", must be one of: " + throw new IllegalArgumentException("Invalid key store type: " + storeFileType + ", must be one of: " +
Arrays.toString(KeyStoreFileType.values())); Arrays.toString(KeyStoreFileType.values()));
} }
} }
private File getKeyStoreJksFile() throws IOException { private File getKeyStoreJksFile() throws IOException {
if (keyStoreJksFile == null) { if (keyStoreJksFile == null) {
try { File keyStoreJksFile = File.createTempFile(
File keyStoreJksFile = File.createTempFile( KEY_STORE_PREFIX, KeyStoreFileType.JKS.getDefaultFileExtension()
KEY_STORE_PREFIX, KeyStoreFileType.JKS.getDefaultFileExt , tempDir);
ension(), tempDir); keyStoreJksFile.deleteOnExit();
keyStoreJksFile.deleteOnExit(); try (final FileOutputStream keyStoreOutputStream = new FileOutputStr
final FileOutputStream keyStoreOutputStream = new FileOutputStre eam(keyStoreJksFile)) {
am(keyStoreJksFile); byte[] bytes = X509TestHelpers.certAndPrivateKeyToJavaKeyStoreBy
try { tes(
byte[] bytes = X509TestHelpers.certAndPrivateKeyToJavaKeySto keyStoreCertificate, keyStoreKeyPair.getPrivate(), keyStoreP
reBytes( assword);
keyStoreCertificate, keyStoreKeyPair.getPrivate(), k keyStoreOutputStream.write(bytes);
eyStorePassword); keyStoreOutputStream.flush();
keyStoreOutputStream.write(bytes);
keyStoreOutputStream.flush();
} finally {
keyStoreOutputStream.close();
}
this.keyStoreJksFile = keyStoreJksFile;
} catch (GeneralSecurityException e) { } catch (GeneralSecurityException e) {
throw new IOException(e); throw new IOException(e);
} }
this.keyStoreJksFile = keyStoreJksFile;
} }
return keyStoreJksFile; return keyStoreJksFile;
} }
private File getKeyStorePemFile() throws IOException { private File getKeyStorePemFile() throws IOException {
if (keyStorePemFile == null) { if (keyStorePemFile == null) {
try { try {
File keyStorePemFile = File.createTempFile( File keyStorePemFile = File.createTempFile(
KEY_STORE_PREFIX, KeyStoreFileType.PEM.getDefaultFileExt ension(), tempDir); KEY_STORE_PREFIX, KeyStoreFileType.PEM.getDefaultFileExt ension(), tempDir);
keyStorePemFile.deleteOnExit(); keyStorePemFile.deleteOnExit();
skipping to change at line 303 skipping to change at line 317
StandardCharsets.US_ASCII, StandardCharsets.US_ASCII,
false); false);
this.keyStorePemFile = keyStorePemFile; this.keyStorePemFile = keyStorePemFile;
} catch (OperatorCreationException e) { } catch (OperatorCreationException e) {
throw new IOException(e); throw new IOException(e);
} }
} }
return keyStorePemFile; return keyStorePemFile;
} }
private File getKeyStorePkcs12File() throws IOException {
if (keyStorePkcs12File == null) {
File keyStorePkcs12File = File.createTempFile(
KEY_STORE_PREFIX, KeyStoreFileType.PKCS12.getDefaultFileExtensio
n(), tempDir);
keyStorePkcs12File.deleteOnExit();
try (final FileOutputStream keyStoreOutputStream = new FileOutputStr
eam(keyStorePkcs12File)) {
byte[] bytes = X509TestHelpers.certAndPrivateKeyToPKCS12Bytes(
keyStoreCertificate, keyStoreKeyPair.getPrivate(), keyStoreP
assword);
keyStoreOutputStream.write(bytes);
keyStoreOutputStream.flush();
} catch (GeneralSecurityException e) {
throw new IOException(e);
}
this.keyStorePkcs12File = keyStorePkcs12File;
}
return keyStorePkcs12File;
}
/** /**
* Sets the SSL system properties such that the given X509Util object can be used to create SSL Contexts that * Sets the SSL system properties such that the given X509Util object can be used to create SSL Contexts that
* will use the trust store and key store files created by this test context . Example usage: * will use the trust store and key store files created by this test context . Example usage:
* <pre> * <pre>
* X509TestContext testContext = ...; // create the test context * X509TestContext testContext = ...; // create the test context
* X509Util x509Util = new QuorumX509Util(); * X509Util x509Util = new QuorumX509Util();
* testContext.setSystemProperties(x509Util, KeyStoreFileType.JKS, KeySt oreFileType.JKS); * testContext.setSystemProperties(x509Util, KeyStoreFileType.JKS, KeySt oreFileType.JKS);
* // The returned context will use the key store and trust store create d by the test context. * // The returned context will use the key store and trust store create d by the test context.
* SSLContext ctx = x509Util.getDefaultSSLContext(); * SSLContext ctx = x509Util.getDefaultSSLContext();
* </pre> * </pre>
 End of changes. 11 change blocks. 
36 lines changed or deleted 73 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)