8212261: Add SSLSession accessors to HttpsURLConnection and SecureCacheResponse

Reviewed-by: mullan, chegar
This commit is contained in:
Xue-Lei Andrew Fan 2018-11-09 08:24:38 -08:00
parent 7e17764cd3
commit 3e9941ea2b
8 changed files with 520 additions and 7 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -31,6 +31,8 @@ import java.net.SecureCacheResponse;
import java.security.Principal;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLPeerUnverifiedException;
import sun.net.www.http.*;
import sun.net.www.protocol.http.HttpURLConnection;
@ -296,4 +298,19 @@ public abstract class AbstractDelegateHttpsURLConnection extends
}
}
SSLSession getSSLSession() {
if (cachedResponse != null) {
Optional<SSLSession> option =
((SecureCacheResponse)cachedResponse).getSSLSession();
if (option.isPresent()) {
return option.orElseThrow();
}
}
if (http == null) {
throw new IllegalStateException("connection not yet open");
}
return ((HttpsClient)http).getSSLSession();
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -738,6 +738,13 @@ final class HttpsClient extends HttpClient
return principal;
}
/**
* Returns the {@code SSLSession} in use on this connection.
*/
SSLSession getSSLSession() {
return session;
}
/**
* This method implements the SSL HandshakeCompleted callback,
* remembering the resulting session so that it may be queried

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -46,6 +46,7 @@ import java.security.Permission;
import java.security.Principal;
import java.util.Map;
import java.util.List;
import java.util.Optional;
import sun.net.www.http.HttpClient;
/**
@ -533,4 +534,9 @@ public class HttpsURLConnectionImpl
public void setAuthenticator(Authenticator auth) {
delegate.setAuthenticator(auth);
}
@Override
public Optional<SSLSession> getSSLSession() {
return Optional.ofNullable(delegate.getSSLSession());
}
}