Skip to content

Commit 69190c8

Browse files
Fix deprecations and github workflow
1 parent 0a8898a commit 69190c8

6 files changed

Lines changed: 66 additions & 91 deletions

File tree

.github/workflows/maven.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- uses: actions/checkout@v4
11-
- name: Set up JDK 11
11+
- name: Set up JDK 17
1212
uses: actions/setup-java@v4
1313
with:
1414
distribution: 'temurin'
15-
java-version: 11
15+
java-version: 17
1616

1717
- name: Install libfaketime on Ubuntu
1818
run: |
@@ -46,4 +46,4 @@ jobs:
4646
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
4747
restore-keys: ${{ runner.os }}-m2
4848
- name: Build with Maven
49-
run: mvn -B clean package
49+
run: mvn -B clean package

src/main/java/org/italiangrid/voms/request/SSLSocketFactoryProvider.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030

3131
import eu.emi.security.authn.x509.X509CertChainValidatorExt;
3232
import eu.emi.security.authn.x509.X509Credential;
33-
import eu.emi.security.authn.x509.impl.SocketFactoryCreator;
33+
import eu.emi.security.authn.x509.helpers.ssl.DisabledNameMismatchCallback;
34+
import eu.emi.security.authn.x509.helpers.ssl.EnforcingNameMismatchCallback;
35+
import eu.emi.security.authn.x509.impl.SocketFactoryCreator2;
3436

3537
/**
3638
* Provider for a SSL socket factory configured using CAnL.
@@ -40,22 +42,26 @@
4042
*
4143
*/
4244
public class SSLSocketFactoryProvider {
43-
45+
4446
private X509Credential credential;
4547
private X509CertChainValidatorExt validator;
48+
private boolean skipHostnameChecks;
4649

47-
public SSLSocketFactoryProvider(X509Credential credential,
48-
X509CertChainValidatorExt validator) {
50+
public SSLSocketFactoryProvider(X509Credential credential, X509CertChainValidatorExt validator, boolean skipHostnameChecks) {
4951

5052
this.credential = credential;
5153
this.validator = validator;
54+
this.skipHostnameChecks = skipHostnameChecks;
55+
}
5256

57+
public SSLSocketFactoryProvider(X509Credential credential, X509CertChainValidatorExt validator) {
58+
59+
this(credential, validator, false);
5360
}
5461

5562
public SSLSocketFactoryProvider(X509Credential credential) {
5663

57-
this(credential, new CertificateValidatorBuilder()
58-
.trustAnchorsUpdateInterval(60000L).build());
64+
this(credential, new CertificateValidatorBuilder().trustAnchorsUpdateInterval(60000L).build());
5965
}
6066

6167
/**
@@ -76,21 +82,22 @@ public SSLSocketFactory getSSLSockectFactory() {
7682
throw new VOMSError(e.getMessage(), e);
7783
}
7884

79-
KeyManager[] keyManagers = new KeyManager[] { credential.getKeyManager() };
80-
81-
X509TrustManager trustManager = SocketFactoryCreator
82-
.getSSLTrustManager(validator);
85+
KeyManager[] keyManagers = new KeyManager[] {credential.getKeyManager()};
8386

84-
TrustManager[] trustManagers = new TrustManager[] { trustManager };
87+
SocketFactoryCreator2 factory =
88+
new SocketFactoryCreator2(credential, validator,
89+
skipHostnameChecks ? new DisabledNameMismatchCallback()
90+
: new EnforcingNameMismatchCallback());
91+
X509TrustManager trustManager = factory.getSSLTrustManager();
8592

86-
SecureRandom secureRandom = null;
93+
TrustManager[] trustManagers = new TrustManager[] {trustManager};
8794

8895
/* http://bugs.sun.com/view_bug.do?bug_id=6202721 */
8996
/*
90-
* Use new SecureRandom instead of SecureRandom.getInstance("SHA1PRNG") to
91-
* avoid unnecessary blocking
97+
* Use new SecureRandom instead of SecureRandom.getInstance("SHA1PRNG") to avoid unnecessary
98+
* blocking
9299
*/
93-
secureRandom = new SecureRandom();
100+
SecureRandom secureRandom = new SecureRandom();
94101

95102
try {
96103

src/main/java/org/italiangrid/voms/request/impl/AbstractVOMSProtocol.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public AbstractVOMSProtocol(X509CertChainValidatorExt validator,
119119
protected SSLSocketFactory getSSLSocketFactory(X509Credential credential) {
120120

121121
SSLSocketFactoryProvider sslSocketFactoryProvider = new SSLSocketFactoryProvider(
122-
credential, validator);
122+
credential, validator, skipHostnameChecks);
123123
return sslSocketFactoryProvider.getSSLSockectFactory();
124124
}
125125

src/main/java/org/italiangrid/voms/request/impl/LegacyProtocol.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
import java.io.InputStream;
2020
import java.net.InetSocketAddress;
2121
import java.net.SocketAddress;
22+
import java.security.cert.CertificateException;
2223
import java.security.cert.X509Certificate;
2324

24-
import javax.net.ssl.SSLException;
2525
import javax.net.ssl.SSLSocket;
2626
import javax.net.ssl.SSLSocketFactory;
2727

@@ -36,16 +36,15 @@
3636
import eu.emi.security.authn.x509.X509Credential;
3737
import eu.emi.security.authn.x509.impl.CertificateUtils;
3838
import eu.emi.security.authn.x509.impl.FormatMode;
39-
import eu.emi.security.authn.x509.impl.HostnameMismatchCallback;
40-
import eu.emi.security.authn.x509.impl.SocketFactoryCreator;
39+
import eu.emi.security.authn.x509.impl.HostnameMismatchCallback2;
4140

4241
/**
4342
* Protocol implementing the legacy interface.
4443
*
4544
*
4645
*/
4746
public class LegacyProtocol extends AbstractVOMSProtocol implements
48-
VOMSProtocol, HostnameMismatchCallback {
47+
VOMSProtocol, HostnameMismatchCallback2 {
4948

5049
public LegacyProtocol(X509CertChainValidatorExt validator,
5150
VOMSProtocolListener listener, int connectTimeout, int readTimeout) {
@@ -70,9 +69,6 @@ public synchronized VOMSResponse doRequest(VOMSServerInfo endpoint,
7069
endpoint.getURL().getPort());
7170

7271
sslSocket.connect(sa, connectTimeout);
73-
if (!isSkipHostnameChecks()) {
74-
SocketFactoryCreator.connectWithHostnameChecking(sslSocket, this);
75-
}
7672

7773
} catch (Throwable t) {
7874

@@ -105,17 +101,17 @@ public synchronized VOMSResponse doRequest(VOMSServerInfo endpoint,
105101
return response;
106102
}
107103

108-
public void nameMismatch(SSLSocket socket, X509Certificate peerCertificate,
109-
String hostName) throws SSLException {
104+
@Override
105+
public void nameMismatch(X509Certificate peerCertificate, String hostName)
106+
throws CertificateException {
110107

111108
String peerCertString = CertificateUtils.format(peerCertificate,
112-
FormatMode.MEDIUM_ONE_LINE);
113-
String message = String
114-
.format(
115-
"No subject alternative DNS name matching %s found. Peer certificate : %s",
116-
hostName, peerCertString);
117-
throw new SSLException(message);
118-
109+
FormatMode.MEDIUM_ONE_LINE);
110+
String message = String
111+
.format(
112+
"No subject alternative DNS name matching %s found. Peer certificate : %s",
113+
hostName, peerCertString);
114+
throw new CertificateException(message);
119115
}
120116

121117
}

src/test/java/org/italiangrid/voms/test/TestOpensslHashFunction.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ public void testMD5HashFailsOnSHA1Dir() {
9292
"Trusted issuer of this certificate was not established",
9393
result.getErrors().get(1).getMessage());
9494

95-
Assert.assertEquals(cred.getCertificate().getSubjectDN(),
96-
result.getErrors().get(1).getChain()[0].getSubjectDN());
95+
Assert.assertEquals(cred.getCertificate().getSubjectX500Principal(),
96+
result.getErrors().get(1).getChain()[0].getSubjectX500Principal());
9797

9898
}
9999

@@ -117,8 +117,8 @@ public void testSHA1FailsOnMD5Dir() {
117117
"Trusted issuer of this certificate was not established",
118118
result.getErrors().get(1).getMessage());
119119

120-
Assert.assertEquals(cred.getCertificate().getSubjectDN(),
121-
result.getErrors().get(1).getChain()[0].getSubjectDN());
120+
Assert.assertEquals(cred.getCertificate().getSubjectX500Principal(),
121+
result.getErrors().get(1).getChain()[0].getSubjectX500Principal());
122122

123123
}
124124

src/test/java/org/italiangrid/voms/test/TestVOMSESLineParser.java

Lines changed: 24 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
import static org.junit.Assert.assertEquals;
1919
import static org.junit.Assert.assertNotNull;
2020
import static org.junit.Assert.assertNull;
21-
import static org.junit.Assert.assertThat;
21+
import static org.junit.Assert.assertTrue;
2222
import static org.junit.Assert.fail;
2323

2424
import java.net.URISyntaxException;
2525

26-
import org.hamcrest.CoreMatchers;
2726
import org.italiangrid.voms.VOMSError;
2827
import org.italiangrid.voms.request.VOMSServerInfo;
2928
import org.italiangrid.voms.request.impl.VOMSESLineParser;
@@ -68,9 +67,7 @@ public void emptyAlias() {
6867
fail("No error raised.");
6968
} catch (VOMSError e) {
7069
assertNotNull("Got a null error message", e.getMessage());
71-
assertThat(e.getMessage(),
72-
CoreMatchers
73-
.containsString("Invalid VOMSES line: empty 'vo alias' field."));
70+
assertTrue(e.getMessage().contains("Invalid VOMSES line: empty 'vo alias' field."));
7471
}
7572
}
7673

@@ -84,9 +81,7 @@ public void incompleteAlias() {
8481
fail("No error raised.");
8582
} catch (VOMSError e) {
8683
assertNotNull("Got a null error message", e.getMessage());
87-
assertThat(e.getMessage(),
88-
CoreMatchers
89-
.containsString("Invalid VOMSES line: incomplete 'vo alias' field."));
84+
assertTrue(e.getMessage().contains("Invalid VOMSES line: incomplete 'vo alias' field."));
9085
}
9186
}
9287

@@ -100,9 +95,7 @@ public void incompleteHost() {
10095
fail("No error raised.");
10196
} catch (VOMSError e) {
10297
assertNotNull("Got a null error message", e.getMessage());
103-
assertThat(e.getMessage(),
104-
CoreMatchers
105-
.containsString("Invalid VOMSES line: incomplete 'voms host' field."));
98+
assertTrue(e.getMessage().contains("Invalid VOMSES line: incomplete 'voms host' field."));
10699
}
107100
}
108101

@@ -116,9 +109,7 @@ public void onlyAlias() {
116109
fail("No error raised.");
117110
} catch (VOMSError e) {
118111
assertNotNull("Got a null error message", e.getMessage());
119-
assertThat(e.getMessage(),
120-
CoreMatchers
121-
.containsString("Invalid VOMSES line: incomplete information"));
112+
assertTrue(e.getMessage().contains("Invalid VOMSES line: incomplete information"));
122113
}
123114
}
124115

@@ -134,9 +125,7 @@ public void minimumInfoFailure() {
134125
} catch (VOMSError e) {
135126

136127
assertNotNull("Got a null error message", e.getMessage());
137-
assertThat(e.getMessage(),
138-
CoreMatchers
139-
.containsString("Invalid VOMSES line: incomplete information"));
128+
assertTrue(e.getMessage().contains("Invalid VOMSES line: incomplete information"));
140129
}
141130
}
142131

@@ -148,14 +137,10 @@ public void minimumInfo() {
148137
VOMSESLineParser p = new VOMSESLineParser();
149138
VOMSServerInfo i = p.parse(line);
150139

151-
assertThat(i.getAlias(), CoreMatchers.equalTo("a"));
152-
153-
assertThat(i.getURL().toString(),
154-
CoreMatchers.equalTo("voms://voms.cern.ch:15000"));
155-
156-
assertThat(i.getVoName(), CoreMatchers.equalTo("alice"));
157-
158-
assertThat(i.getVOMSServerDN(), CoreMatchers.equalTo("DN=Illo"));
140+
assertEquals("a", i.getAlias());
141+
assertEquals("voms://voms.cern.ch:15000", i.getURL().toString());
142+
assertEquals("alice", i.getVoName());
143+
assertEquals("DN=Illo", i.getVOMSServerDN());
159144
}
160145

161146
@Test
@@ -166,14 +151,10 @@ public void whitespaceHandling() {
166151
VOMSESLineParser p = new VOMSESLineParser();
167152
VOMSServerInfo i = p.parse(line);
168153

169-
assertThat(i.getAlias(), CoreMatchers.equalTo("a"));
170-
171-
assertThat(i.getURL().toString(),
172-
CoreMatchers.equalTo("voms://voms.cern.ch:15000"));
173-
174-
assertThat(i.getVoName(), CoreMatchers.equalTo("alice"));
175-
176-
assertThat(i.getVOMSServerDN(), CoreMatchers.equalTo("DN=Illo"));
154+
assertEquals("a", i.getAlias());
155+
assertEquals("voms://voms.cern.ch:15000", i.getURL().toString());
156+
assertEquals("alice", i.getVoName());
157+
assertEquals("DN=Illo", i.getVOMSServerDN());
177158
}
178159

179160
@Test
@@ -187,8 +168,7 @@ public void tooManyFields() {
187168
fail("No error raised.");
188169
} catch (VOMSError e) {
189170
assertNotNull("Got a null error message", e.getMessage());
190-
assertThat(e.getMessage(),
191-
CoreMatchers.containsString("Invalid VOMSES line: too many fields!"));
171+
assertTrue(e.getMessage().contains("Invalid VOMSES line: too many fields!"));
192172
}
193173

194174
}
@@ -204,9 +184,7 @@ public void invalidPort() {
204184
fail("No error raised.");
205185
} catch (VOMSError e) {
206186
assertNotNull("Got a null error message", e.getMessage());
207-
assertThat(e.getMessage(),
208-
CoreMatchers
209-
.containsString("Invalid VOMSES line: invalid port number."));
187+
assertTrue(e.getMessage().contains("Invalid VOMSES line: invalid port number."));
210188
}
211189

212190
}
@@ -222,9 +200,7 @@ public void portOutOfRange1() {
222200
fail("No error raised.");
223201
} catch (VOMSError e) {
224202
assertNotNull("Got a null error message", e.getMessage());
225-
assertThat(e.getMessage(),
226-
CoreMatchers
227-
.containsString("Invalid VOMSES line: invalid port number: -1"));
203+
assertTrue(e.getMessage().contains("Invalid VOMSES line: invalid port number: -1"));
228204
}
229205
}
230206

@@ -239,9 +215,7 @@ public void portOutOfRange2() {
239215
fail("No error raised.");
240216
} catch (VOMSError e) {
241217
assertNotNull("Got a null error message", e.getMessage());
242-
assertThat(e.getMessage(),
243-
CoreMatchers
244-
.containsString("Invalid VOMSES line: invalid port number: 65536"));
218+
assertTrue(e.getMessage().contains("Invalid VOMSES line: invalid port number: 65536"));
245219
}
246220
}
247221

@@ -255,14 +229,12 @@ public void tooMultiCall() {
255229
VOMSServerInfo i0 = p.parse(line0);
256230
VOMSServerInfo i1 = p.parse(line1);
257231

258-
assertThat(i0.getAlias(), CoreMatchers.equalTo("a"));
259-
assertThat(i0.getURL().toString(),
260-
CoreMatchers.equalTo("voms://voms.cern.ch:15000"));
261-
assertThat(i0.getVoName(), CoreMatchers.equalTo("alice"));
232+
assertEquals("a", i0.getAlias());
233+
assertEquals("voms://voms.cern.ch:15000", i0.getURL().toString());
234+
assertEquals("alice", i0.getVoName());
262235

263-
assertThat(i1.getAlias(), CoreMatchers.equalTo("b"));
264-
assertThat(i1.getURL().toString(),
265-
CoreMatchers.equalTo("voms://voms.cern.ch:15001"));
266-
assertThat(i1.getVoName(), CoreMatchers.equalTo("bolice"));
236+
assertEquals("b", i1.getAlias());
237+
assertEquals("voms://voms.cern.ch:15001", i1.getURL().toString());
238+
assertEquals("bolice", i1.getVoName());
267239
}
268240
}

0 commit comments

Comments
 (0)