Java – Using the Dropbox Java API: DropboxSSLException: peer not authenticated

Using the Dropbox Java API: DropboxSSLException: peer not authenticated… here is a solution to the problem.

Using the Dropbox Java API: DropboxSSLException: peer not authenticated

I’m trying to get my java app to upload files using the Dropbox java API. Somehow I ended up with the same SSL error that I couldn’t fix. Any suggestions?

I used this code (

    public class DropboxTest {

 App key & secret that Dropbox's developer website gives your app
    private static final String APP_KEY = "myAppKey";
    private static final String APP_SECRET = "myAppSecret";
     Define AccessType for DropboxAPI object
    final static private AccessType ACCESS_TYPE = AccessType.APP_FOLDER;
    private static DropboxAPI<WebAuthSession> mDBApi;

public static void main(String[] args) throws Exception{

 Initialize the goods/session
        AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
        WebAuthSession session = new WebAuthSession(appKeys, ACCESS_TYPE);

 Initialize DropboxAPI object
        mDBApi = new DropboxAPI<WebAuthSession>(session);

 Get ready for user input
        Scanner input = new Scanner(;

 Open file that stores tokens, MUST exist as a blank file
        File tokensFile = new File("TOKENS");

System.out.println("Enter 'a' to authenticate, or 't' to test reauthentication: ");
        String command =;


try {

 Present user with URL to allow app access to Dropbox account on
                System.out.println("Please go to this URL and hit \"Allow\": " + mDBApi.getSession().getAuthInfo().url);
                AccessTokenPair tokenPair = mDBApi.getSession().getAccessTokenPair();

 Wait for user to Allow app in browser
                System.out.println("Finished allowing?  Enter 'next' if so: ");
                    RequestTokenPair tokens = new RequestTokenPair(tokenPair.key, tokenPair.secret);
                    PrintWriter tokenWriter = new PrintWriter(tokensFile);
                    System.out.println("Authentication Successful!");


} catch (DropboxException e) {
                 TODO Auto-generated catch block

else if(command.equals("t")){

Scanner tokenScanner = new Scanner(tokensFile);        Initiate Scanner to read tokens from TOKEN file
            String ACCESS_TOKEN_KEY = tokenScanner.nextLine();     Read key
            String ACCESS_TOKEN_SECRET = tokenScanner.nextLine();  Read secret
            tokenScanner.close(); Close Scanner 

            AccessTokenPair reAuthTokens = new AccessTokenPair(ACCESS_TOKEN_KEY, ACCESS_TOKEN_SECRET);
            System.out.println("Re-authentication Sucessful!");

Run test command
            System.out.println("Hello there, " + mDBApi.accountInfo().displayName);


End with SSL exception:

com.dropbox.client2.exception.DropboxSSLException: peer not authenticated
    at com.dropbox.client2.RESTUtility.execute(
    at com.dropbox.client2.RESTUtility.execute(
    at com.dropbox.client2.RESTUtility.streamRequest(
    at com.dropbox.client2.session.WebAuthSession.setUpToken(
    at com.dropbox.client2.session.WebAuthSession.getAuthInfo(
    at com.dropbox.client2.session.WebAuthSession.getAuthInfo(
    at DropboxTest.main(
Caused by: peer not authenticated
    at org.apache.http.conn.ssl.AbstractVerifier.verify(
    at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(
    at org.apache.http.impl.client.DefaultRequestDirector.execute(
    at org.apache.http.impl.client.AbstractHttpClient.execute(
    at org.apache.http.impl.client.AbstractHttpClient.execute(
    at org.apache.http.impl.client.AbstractHttpClient.execute(
    at com.dropbox.client2.RESTUtility.execute(
    ... 6 more


Figured it out. I use OpenJDK on OSX.
I ran the JVM with for debugging and ended up with a root exception the trustAnchors parameter must be non-empty

After some research, I found a solution here:

Works fine now!

Related Problems and Solutions