Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RATIS-1542. Support TlsConf in netty streaming. (#619)
- Loading branch information
Showing
24 changed files
with
1,130 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
ratis-common/src/test/java/org/apache/ratis/security/SecurityTestUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.ratis.security; | ||
|
||
import org.apache.ratis.security.TlsConf.Builder; | ||
import org.apache.ratis.security.TlsConf.CertificatesConf; | ||
import org.apache.ratis.security.TlsConf.PrivateKeyConf; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.File; | ||
import java.net.URL; | ||
import java.util.Optional; | ||
|
||
public interface SecurityTestUtils { | ||
Logger LOG = LoggerFactory.getLogger(SecurityTestUtils.class); | ||
|
||
ClassLoader CLASS_LOADER = SecurityTestUtils.class.getClassLoader(); | ||
|
||
static File getResource(String name) { | ||
final File file = Optional.ofNullable(CLASS_LOADER.getResource(name)) | ||
.map(URL::getFile) | ||
.map(File::new) | ||
.orElse(null); | ||
LOG.info("Getting resource {}: {}", name, file); | ||
return file; | ||
} | ||
|
||
static TlsConf newServerTlsConfig(boolean mutualAuthn) { | ||
LOG.info("newServerTlsConfig: mutualAuthn? {}", mutualAuthn); | ||
return new Builder() | ||
.setName("server") | ||
.setPrivateKey(new PrivateKeyConf(getResource("ssl/server.pem"))) | ||
.setKeyCertificates(new CertificatesConf(getResource("ssl/server.crt"))) | ||
.setTrustCertificates(new CertificatesConf(getResource("ssl/client.crt"))) | ||
.setMutualTls(mutualAuthn) | ||
.build(); | ||
} | ||
|
||
static TlsConf newClientTlsConfig(boolean mutualAuthn) { | ||
LOG.info("newClientTlsConfig: mutualAuthn? {}", mutualAuthn); | ||
return new Builder() | ||
.setName("client") | ||
.setPrivateKey(new PrivateKeyConf(getResource("ssl/client.pem"))) | ||
.setKeyCertificates(new CertificatesConf(getResource("ssl/client.crt"))) | ||
.setTrustCertificates(new CertificatesConf(getResource("ssl/ca.crt"))) | ||
.setMutualTls(mutualAuthn) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.