Issue in mutual certificate authentication

69 views
Skip to first unread message

OR

unread,
Feb 11, 2016, 11:21:23 AM2/11/16
to REST assured
So I am trying to implement certificate authentication, here is the code I wrote:

Code:
import java.io.FileInputStream;
import java.io.InputStream;
import java.security.KeyStore;

import com.jayway.restassured.RestAssured;

public class RestAssuredUtil
{
    public static final void setup() throws Exception
    {
        RestAssured.baseURI  = "myRESTAPIURL";
        
        RestAssured.keystore("pathToKeyStoreJKSFile", "Paswd");
        
        String trustStorePath ="pathToTrustStoreJKSFile";
        String trustStorePassword="Paswd";
        KeyStore truststore = KeyStore.getInstance(KeyStore.getDefaultType());
        InputStream truststoreInput = new FileInputStream(trustStorePath);
        
        truststore.load(truststoreInput, trustStorePassword.toCharArray());
        System.out.println("Truststore has " + truststore.size() + " keys");
        
        RestAssured.trustStore(truststore);
        
    }
}

import static com.jayway.restassured.RestAssured.given;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;


public class LanguageWSTest
{
    @BeforeTest
    public void setup() throws Exception
    {
        RestAssuredUtil.setup();
    }

    
    @Test
    public void testRead()
    {

    given()
    .auth().basic("username","password")
        .expect()
              .statusCode(200)
              .log().everything()
        .when()
            .get ("/enpoint");
    }
  }

And I got following error message when I ran it:

Truststore has 3 keys
FAILED: testRead
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.ssl.Alerts.getSSLException(Unknown Source)


My questions:
1. Is my way to implement it correct? Or do I need it use some other packages/methods?
2. If I am doing it right, what's causing the error? I googled but couldn't find a solution that would fix it.

I'm at my wit's end trying to figure the solution. Kindly help.

Thanks,
OR
Reply all
Reply to author
Forward
0 new messages