SecureCacheResponse getLocalCertificateChain() in Java

getLocalCertificateChain(): This method is available in the java.net.SecureCacheResponse class of Java.

Syntax:

List<Certificate> java.net.SecureCacheResponse.getLocalCertificateChain()

This method returns the certificate chain that was sent to the server during the handshaking of the original connection that retrieved the network resource.

Note: This method is useful only when using certificate-based cipher suites.

Parameters: NA

Returns: an immutable List of Certificates representing the certificate chain that was sent to the server. If no certificate chain was sent, null will be returned.

Exceptions: NA

Approach

Java

package com.SecureCacheResponse;

import java.io.IOException;
import java.io.InputStream;
import java.net.SecureCacheResponse;
import java.security.Principal;
import java.security.cert.Certificate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.net.ssl.SSLPeerUnverifiedException;

public class SecureCacheResponsegetLocalCertificateChain {
    public static void main(String[] args) throws IOException {

        SecureCacheResponse secureCacheResponse = new SecureCacheResponse() {
            @Override
            public String getCipherSuite() {
                return "Connection established";
            }

            @Override
            public List<Certificate> getLocalCertificateChain() {

                return null;
            }

            @Override
            public List<Certificate> getServerCertificateChain() throws SSLPeerUnverifiedException {
                return null;
            }

            @Override
            public Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
                return null;
            }

            @Override
            public Principal getLocalPrincipal() {
                return null;
            }

            @Override
            public Map<String, List<String>> getHeaders() throws IOException {

                Map<String, List<String>> map = new HashMap<String, List<String>>();
                List<String> value = new ArrayList<String>();
                List<String> value1 = new ArrayList<String>();
                value.add("abcdsdd");
                map.put("Authorization", value);
                value1.add("abcdd");
                map.put("param", value1);
                return map;
            }

            @Override
            public InputStream getBody() throws IOException {
                return new InputStream() {

                    @Override
                    public int read() throws IOException {
                        return 0;
                    }
                };
            }
        };

        System.out.println(secureCacheResponse.getLocalCertificateChain());

    }
}

Output:

null


Some other methods of the SecureCacheResponse class

getCipherSuite(): This method returns the cipher suite in use on the original connection that retrieved the network resource.

getLocalCertificateChain(): This method returns the certificate chain that was sent to the server during the handshaking of the original connection that retrieved the network resource.

getLocalPrincipal(): This method returns the principal that was sent to the server during handshaking in the original connection that retrieved the network resource.

getPeerPrincipal(): This method returns the server's principal which was established as part of defining the session during the original connection that retrieved the network resource.

getServerCertificateChain(): This method returns the server's certificate chain, which was established as part of defining the session in the original connection that retrieved the network resource, from the cache.

getSSLSession(): This method returns an Optional containing the SSLSession in use on the original connection that retrieved the network resource.

No comments:

Post a Comment