Skip to content

Commit 94d0cfb

Browse files
authored
Correctly override equals and hashCode for our OpenSslSession sub-types (#13829)
Motivation: We did not correct override equals and hashcode methods for some of the OpenSslSession implementations Modifications: Override methods Result: Be able to correctly understand if a session is equal or not
1 parent f0e9b40 commit 94d0cfb

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

handler/src/main/java/io/netty/handler/ssl/ExtendedOpenSslSession.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.security.cert.Certificate;
2929
import java.util.Collections;
3030
import java.util.List;
31-
import java.util.Map;
3231

3332
/**
3433
* Delegates all operations to a wrapped {@link OpenSslSession} except the methods defined by {@link ExtendedSSLSession}
@@ -249,6 +248,16 @@ public void handshakeFinished(byte[] id, String cipher, String protocol, byte[]
249248
wrapped.handshakeFinished(id, cipher, protocol, peerCertificate, peerCertificateChain, creationTime, timeout);
250249
}
251250

251+
@Override
252+
public boolean equals(Object o) {
253+
return wrapped.equals(o);
254+
}
255+
256+
@Override
257+
public int hashCode() {
258+
return wrapped.hashCode();
259+
}
260+
252261
@Override
253262
public String toString() {
254263
return "ExtendedOpenSslSession{" +

handler/src/main/java/io/netty/handler/ssl/ReferenceCountedOpenSslEngine.java

+17
Original file line numberDiff line numberDiff line change
@@ -2714,6 +2714,23 @@ public String toString() {
27142714
", id=" + id +
27152715
'}';
27162716
}
2717+
2718+
@Override
2719+
public int hashCode() {
2720+
return sessionId().hashCode();
2721+
}
2722+
2723+
@Override
2724+
public boolean equals(Object o) {
2725+
if (o == this) {
2726+
return true;
2727+
}
2728+
// We trust all sub-types as we use different types but the interface is package-private
2729+
if (!(o instanceof OpenSslSession)) {
2730+
return false;
2731+
}
2732+
return sessionId().equals(((OpenSslSession) o).sessionId());
2733+
}
27172734
}
27182735

27192736
private interface NativeSslException {

0 commit comments

Comments
 (0)