ot4i / ace-docker

73 stars 167 forks source link

How to fix PKIX path building failed in java 6 #182

Closed AbdullaElshourbagy closed 2 years ago

AbdullaElshourbagy commented 2 years ago

try to call rest postman service with the code below

it works fine in Java 8 but java 6 returns this error.

error returns in java 6

`` public class Test { public static void main(String[] args) throws Exception { // TODO Auto-generated method stub String userName = "postman"; String password = "password";

try {
        String encodedCredintals =
            "Basic " + Base64.encode((userName + ":" + password).getBytes());  

URL url = new URL("https://postman-echo.com/basic-auth");

HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setDoInput(true);

        conn.setRequestMethod("GET");
        // conn.setRequestProperty("Authorization", "Basic cG9zdG1hbjpwYXNzd29yZA==");
        conn.setRequestProperty("Authorization", encodedCredintals);
        conn.setRequestProperty("Content-Type", "application/json");
        System.out.println(conn.getResponseCode() + "  " + conn.getResponseMessage());

        InputStream inputStream = null;
        try {
            inputStream = conn.getInputStream();
            System.out.println(inputStream);
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }

        InputStreamReader isReader = new InputStreamReader(inputStream);
        //Creating a BufferedReader object
        BufferedReader reader = new BufferedReader(isReader);
        StringBuffer sb = new StringBuffer();
        String str;
        while ((str = reader.readLine()) != null) {
            sb.append(str);
        }
        System.out.println(sb.toString());

        conn.disconnect();
        JSONParser parser = new JSONParser();
        JSONObject jsonOject = (JSONObject) parser.parse(sb.toString());
        String value = jsonOject.get("authenticated").toString();
        System.out.println(value + "");

    } catch (Exception e) {
        e.printStackTrace();
    }
}

} ``

I added certificates to java 6 home through these command keytool -import -noprompt -trustcacerts -alias postman -file C:\ME\PostmanCer.cer -keystore "C:/Program Files/Java/jdk1.6.0_45/jre/lib/security/cacerts" -storepass changeit

and check the whole list to ensure that is added successfully keytool -list -v -keystore "C:/Program Files/Java/jdk1.6.0_45/jre/lib/security/cacerts"

and it's added



Alias name: postman Creation date: May 6, 2022 Entry type: trustedCertEntry

Owner: CN=postman-echo.com Issuer: CN=Amazon, OU=Server CA 1B, O=Amazon, C=US Serial number: 1d28e731ad13c59327f0460b6ab6021 Valid from: Thu Mar 10 02:00:00 EET 2022 until: Sun Apr 09 01:59:59 EET 2023 Certificate fingerprints: MD5: CE:FA:B7:E0:E3:4F:CB:30:0F:D7:F0:18:04:BE:A0:4C SHA1: 99:C3:89:D6:54:04:82:A3:FD:E2:FF:8E:9D:C0:78:73:08:30:F0:68 Signature algorithm name: SHA256withRSA Version: 3

Extensions:

1: ObjectId: 2.5.29.15 Criticality=true

KeyUsage [ DigitalSignature Key_Encipherment ]

2: ObjectId: 2.5.29.19 Criticality=true

BasicConstraints:[ CA:false PathLen: undefined ]

3: ObjectId: 1.3.6.1.4.1.11129.2.4.2 Criticality=false

4: ObjectId: 1.3.6.1.5.5.7.1.1 Criticality=false

AuthorityInfoAccess [ [ accessMethod: 1.3.6.1.5.5.7.48.1 accessLocation: URIName: http://ocsp.sca1b.amazontrust.com, accessMethod: 1.3.6.1.5.5.7.48.2 accessLocation: URIName: http://crt.sca1b.amazontrust.com/sca1b.crt] ]

5: ObjectId: 2.5.29.14 Criticality=false

SubjectKeyIdentifier [ KeyIdentifier [ 0000: B2 AF 0D E8 62 E5 B6 D7 D1 28 6C 2E 75 BD 02 75 ....b....(l.u..u 0010: 3D F7 D1 B0 =... ] ]

6: ObjectId: 2.5.29.17 Criticality=false

SubjectAlternativeName [ DNSName: postman-echo.com DNSName: *.postman-echo.com ]

7: ObjectId: 2.5.29.31 Criticality=false

CRLDistributionPoints [ [DistributionPoint: [URIName: http://crl.sca1b.amazontrust.com/sca1b-1.crl] ]]

8: ObjectId: 2.5.29.32 Criticality=false

CertificatePolicies [ [CertificatePolicyId: [2.23.140.1.2.1] [] ] ]

9: ObjectId: 2.5.29.35 Criticality=false

AuthorityKeyIdentifier [ KeyIdentifier [ 0000: 59 A4 66 06 52 A0 7B 95 92 3C A3 94 07 27 96 74 Y.f.R....<...'.t 0010: 5B F9 3D D0 [.=. ]

]

10: ObjectId: 2.5.29.37 Criticality=false

ExtendedKeyUsages [ serverAuth clientAuth ]



how can i solve this issue.

IBMRob commented 2 years ago

Please use https://community.ibm.com/community/user/integration/communities/community-home/digestviewer?communitykey=77544459-9fda-40da-ae0b-fc8c76f0ce18 for general ACE questions.