testPrivateKeyMethod() — netty Function Reference
Architecture documentation for the testPrivateKeyMethod() function in OpenSslPrivateKeyMethodTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 90ad078f_18cd_88ab_2be6_3ed8d8a318ea["testPrivateKeyMethod()"] e0537394_11f7_7d84_df6a_7390455b871b["OpenSslPrivateKeyMethodTest"] 90ad078f_18cd_88ab_2be6_3ed8d8a318ea -->|defined in| e0537394_11f7_7d84_df6a_7390455b871b 1558c9b0_1905_5fc4_ab74_483e05181c96["sign()"] 90ad078f_18cd_88ab_2be6_3ed8d8a318ea -->|calls| 1558c9b0_1905_5fc4_ab74_483e05181c96 1dd89d03_8a52_ce64_f8f1_14c4530dada0["assertThread()"] 90ad078f_18cd_88ab_2be6_3ed8d8a318ea -->|calls| 1dd89d03_8a52_ce64_f8f1_14c4530dada0 64891399_7257_b41d_2d83_0a7379197ce0["decrypt()"] 90ad078f_18cd_88ab_2be6_3ed8d8a318ea -->|calls| 64891399_7257_b41d_2d83_0a7379197ce0 a82618c3_8367_7f44_9004_0168ab968e1c["OpenSslPrivateKeyMethodAdapter()"] 90ad078f_18cd_88ab_2be6_3ed8d8a318ea -->|calls| a82618c3_8367_7f44_9004_0168ab968e1c style 90ad078f_18cd_88ab_2be6_3ed8d8a318ea fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
handler/src/test/java/io/netty/handler/ssl/OpenSslPrivateKeyMethodTest.java lines 195–328
@ParameterizedTest(name = "{index}: delegate = {0}, async = {1}, newThread={2}")
@MethodSource("parameters")
public void testPrivateKeyMethod(final boolean delegate, boolean async, boolean newThread) throws Exception {
final AtomicBoolean signCalled = new AtomicBoolean();
OpenSslPrivateKeyMethod keyMethod = new OpenSslPrivateKeyMethod() {
@Override
public byte[] sign(SSLEngine engine, int signatureAlgorithm, byte[] input) throws Exception {
signCalled.set(true);
assertThread(delegate);
assertEquals(CERT.getKeyPair().getPublic(),
engine.getSession().getLocalCertificates()[0].getPublicKey());
// Delegate signing to Java implementation.
final Signature signature;
// Depending on the Java version it will pick one or the other.
if (signatureAlgorithm == OpenSslPrivateKeyMethod.SSL_SIGN_RSA_PKCS1_SHA256) {
signature = Signature.getInstance("SHA256withRSA");
} else if (signatureAlgorithm == OpenSslPrivateKeyMethod.SSL_SIGN_RSA_PSS_RSAE_SHA256) {
signature = Signature.getInstance("RSASSA-PSS");
signature.setParameter(new PSSParameterSpec("SHA-256", "MGF1", MGF1ParameterSpec.SHA256,
32, 1));
} else {
throw new AssertionError("Unexpected signature algorithm " + signatureAlgorithm);
}
signature.initSign(CERT.getKeyPair().getPrivate());
signature.update(input);
return signature.sign();
}
@Override
public byte[] decrypt(SSLEngine engine, byte[] input) {
throw new UnsupportedOperationException();
}
};
final SslContext sslServerContext = async ? buildServerContext(
new OpenSslPrivateKeyMethodAdapter(keyMethod, newThread)) : buildServerContext(keyMethod);
final SslContext sslClientContext = buildClientContext();
try {
try {
final Promise<Object> serverPromise = GROUP.next().newPromise();
final Promise<Object> clientPromise = GROUP.next().newPromise();
ChannelHandler serverHandler = new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(newSslHandler(sslServerContext, ch.alloc(), delegateExecutor(delegate)));
pipeline.addLast(new SimpleChannelInboundHandler<Object>() {
@Override
public void channelInactive(ChannelHandlerContext ctx) {
serverPromise.cancel(true);
ctx.fireChannelInactive();
}
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) {
if (serverPromise.trySuccess(null)) {
ctx.writeAndFlush(Unpooled.wrappedBuffer(new byte[] {'P', 'O', 'N', 'G'}));
}
ctx.close();
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
if (!serverPromise.tryFailure(cause)) {
ctx.fireExceptionCaught(cause);
}
}
});
}
};
LocalAddress address = new LocalAddress("test-" + SslProvider.OPENSSL
+ '-' + SslProvider.JDK + '-' + RFC_CIPHER_NAME + '-' + delegate);
Channel server = server(address, serverHandler);
try {
Domain
Subdomains
Source
Frequently Asked Questions
What does testPrivateKeyMethod() do?
testPrivateKeyMethod() is a function in the netty codebase, defined in handler/src/test/java/io/netty/handler/ssl/OpenSslPrivateKeyMethodTest.java.
Where is testPrivateKeyMethod() defined?
testPrivateKeyMethod() is defined in handler/src/test/java/io/netty/handler/ssl/OpenSslPrivateKeyMethodTest.java at line 195.
What does testPrivateKeyMethod() call?
testPrivateKeyMethod() calls 4 function(s): OpenSslPrivateKeyMethodAdapter, assertThread, decrypt, sign.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free