use of org.apache.zookeeper.common.QuorumX509Util in project zookeeper by apache.
the class QuorumSSLTest method setup.
@BeforeEach
public void setup() throws Exception {
quorumX509Util = new QuorumX509Util();
ClientBase.setupTestEnv();
tmpDir = createTmpDir().getAbsolutePath();
clientPortQp1 = PortAssignment.unique();
clientPortQp2 = PortAssignment.unique();
clientPortQp3 = PortAssignment.unique();
validKeystorePath = tmpDir + "/valid.jks";
truststorePath = tmpDir + "/truststore.jks";
quorumConfiguration = generateQuorumConfiguration();
Security.addProvider(new BouncyCastleProvider());
certStartTime = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(certStartTime);
cal.add(Calendar.YEAR, 1);
certEndTime = cal.getTime();
rootKeyPair = createKeyPair();
contentSigner = new JcaContentSignerBuilder("SHA256WithRSAEncryption").build(rootKeyPair.getPrivate());
rootCertificate = createSelfSignedCertifcate(rootKeyPair);
// Write the truststore
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, PASSWORD);
trustStore.setCertificateEntry(rootCertificate.getSubjectDN().toString(), rootCertificate);
FileOutputStream outputStream = new FileOutputStream(truststorePath);
trustStore.store(outputStream, PASSWORD);
outputStream.flush();
outputStream.close();
defaultKeyPair = createKeyPair();
X509Certificate validCertificate = buildEndEntityCert(defaultKeyPair, rootCertificate, rootKeyPair.getPrivate(), HOSTNAME, "127.0.0.1", null, null);
writeKeystore(validCertificate, defaultKeyPair, validKeystorePath);
setSSLSystemProperties();
}
use of org.apache.zookeeper.common.QuorumX509Util in project zookeeper by apache.
the class CnxManagerTest method testSSLSocketClosedWhenHandshakeTimeout.
/**
* Test the SSLSocket is explicitly closed when there is IOException
* happened during connect.
*/
@Test
public void testSSLSocketClosedWhenHandshakeTimeout() throws Exception {
final CountDownLatch closeLatch = new CountDownLatch(1);
QuorumX509Util mockedX509Util = new QuorumX509Util() {
@Override
public SSLSocket createSSLSocket() {
return new SSLSocket() {
@Override
public void connect(SocketAddress endpoint, int timeout) {
}
@Override
public void startHandshake() throws IOException {
throw new IOException();
}
@Override
public void close() {
closeLatch.countDown();
}
public String[] getSupportedCipherSuites() {
throw new UnsupportedOperationException();
}
public String[] getEnabledCipherSuites() {
throw new UnsupportedOperationException();
}
public String[] getSupportedProtocols() {
throw new UnsupportedOperationException();
}
public String[] getEnabledProtocols() {
throw new UnsupportedOperationException();
}
public SSLSession getSession() {
throw new UnsupportedOperationException();
}
public void setEnabledCipherSuites(String[] suites) {
}
public void setEnabledProtocols(String[] protocols) {
}
public void addHandshakeCompletedListener(HandshakeCompletedListener listener) {
}
public void removeHandshakeCompletedListener(HandshakeCompletedListener listener) {
}
public void setUseClientMode(boolean mode) {
}
public boolean getUseClientMode() {
return true;
}
public void setNeedClientAuth(boolean need) {
}
public boolean getNeedClientAuth() {
return true;
}
public void setWantClientAuth(boolean want) {
}
public boolean getWantClientAuth() {
return true;
}
public void setEnableSessionCreation(boolean flag) {
}
public boolean getEnableSessionCreation() {
return true;
}
};
}
};
QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[0], peerTmpdir[0], peerClientPort[0], 3, 0, 2000, 2, 2, 2) {
@Override
public QuorumX509Util createX509Util() {
return mockedX509Util;
}
};
peer.setSslQuorum(true);
QuorumCnxManager cnxManager = peer.createCnxnManager();
cnxManager.connectOne(1, peers.get(1L).electionAddr);
assertTrue(closeLatch.await(1, TimeUnit.SECONDS));
}
Aggregations