Skip to content

Commit 116cc59

Browse files
authored
Fixed method that compares SSLParameters for equality, it no longer throws a NPE in some cases. (helidon-io#8570)
Added a test.
1 parent fe02af6 commit 116cc59

2 files changed

Lines changed: 76 additions & 5 deletions

File tree

common/tls/src/main/java/io/helidon/common/tls/Tls.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -286,8 +286,8 @@ private static int hashCode(SSLParameters first) {
286286
return result;
287287
}
288288

289-
private static boolean equals(SSLParameters first, SSLParameters second) {
290-
return first.getAlgorithmConstraints().equals(second.getAlgorithmConstraints())
289+
static boolean equals(SSLParameters first, SSLParameters second) {
290+
return Objects.equals(first.getAlgorithmConstraints(), second.getAlgorithmConstraints())
291291
&& Arrays.equals(first.getApplicationProtocols(), second.getApplicationProtocols())
292292
&& Arrays.equals(first.getCipherSuites(), second.getCipherSuites())
293293
&& (first.getEnableRetransmissions() == second.getEnableRetransmissions())
@@ -297,8 +297,8 @@ private static boolean equals(SSLParameters first, SSLParameters second) {
297297
&& Arrays.equals(first.getProtocols(), second.getProtocols())
298298
&& (first.getUseCipherSuitesOrder() == second.getUseCipherSuitesOrder())
299299
&& (first.getWantClientAuth() == second.getWantClientAuth())
300-
&& first.getServerNames().equals(second.getServerNames())
301-
&& first.getSNIMatchers().equals(second.getSNIMatchers());
300+
&& Objects.equals(first.getServerNames(), second.getServerNames())
301+
&& Objects.equals(first.getSNIMatchers(), second.getSNIMatchers());
302302
}
303303

304304
private void checkEnabled() {
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (c) 2024 Oracle and/or its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.helidon.common.tls;
18+
19+
import java.security.AlgorithmConstraints;
20+
import java.security.AlgorithmParameters;
21+
import java.security.CryptoPrimitive;
22+
import java.security.Key;
23+
import java.util.List;
24+
import java.util.Set;
25+
26+
import javax.net.ssl.SSLParameters;
27+
28+
import org.junit.jupiter.api.Test;
29+
30+
import static org.hamcrest.CoreMatchers.is;
31+
import static org.hamcrest.MatcherAssert.assertThat;
32+
33+
public class TlsTest {
34+
@Test
35+
public void testTlsEquals() {
36+
SSLParameters first = new SSLParameters();
37+
SSLParameters second = new SSLParameters();
38+
39+
assertThat(Tls.equals(first, second), is(true));
40+
41+
AlgorithmConstraints constraints = new AlgorithmConstraints() {
42+
@Override
43+
public boolean permits(Set<CryptoPrimitive> primitives, String algorithm, AlgorithmParameters parameters) {
44+
return false;
45+
}
46+
47+
@Override
48+
public boolean permits(Set<CryptoPrimitive> primitives, Key key) {
49+
return false;
50+
}
51+
52+
@Override
53+
public boolean permits(Set<CryptoPrimitive> primitives, String algorithm, Key key, AlgorithmParameters parameters) {
54+
return false;
55+
}
56+
};
57+
58+
first.setAlgorithmConstraints(constraints);
59+
second.setAlgorithmConstraints(constraints);
60+
61+
assertThat(Tls.equals(first, second), is(true));
62+
63+
first.setServerNames(List.of());
64+
second.setServerNames(List.of());
65+
66+
assertThat(Tls.equals(first, second), is(true));
67+
68+
first.setSNIMatchers(List.of());
69+
second.setSNIMatchers(List.of());
70+
}
71+
}

0 commit comments

Comments
 (0)