Cielo Checkout - Certificate error

Asked

Viewed 413 times

1

I am deploying your java checkout solution on my local machine for testing purposes. The code I am using is available in the developer at Cielo.

Follows the code:

  public String envia() {

    String responseLine = "";
    try {
        String json = "{"
                + "    \"OrderNumber\": \"12344\","
                + "    \"SoftDescriptor\": \"Nome que aparecerá na fatura\","
                + "    \"Cart\": {"
                + "        \"Discount\": {"
                + "            \"Type\": \"Percent\","
                + "            \"Value\": 10"
                + "        },"
                + "        \"Items\": ["
                + "            {"
                + "                \"Name\": \"Nome do produto\","
                + "                \"Description\": \"Descrição do produto\","
                + "                \"UnitPrice\": 100,"
                + "                \"Quantity\": 2,"
                + "                \"Type\": \"Asset\","
                + "                \"Sku\": \"Sku do item no carrinho\","
                + "                \"Weight\": 200"
                + "            }"
                + "        ]"
                + "    },"
                + "    \"Shipping\": {"
                + "        \"Type\": \"Correios\","
                + "        \"SourceZipCode\": \"14400000\","
                + "        \"TargetZipCode\": \"11000000\","
                + "        \"Address\": {"
                + "            \"Street\": \"Endereço de entrega\","
                + "            \"Number\": \"123\","
                + "            \"Complement\": \"\","
                + "            \"District\": \"Bairro da entrega\","
                + "            \"City\": \"Cidade de entrega\","
                + "            \"State\": \"SP\""
                + "        },"
                + "        \"Services\": ["
                + "            {"
                + "                \"Name\": \"Serviço de frete\","
                + "                \"Price\": 123,"
                + "                \"Deadline\": 15"
                + "            }"
                + "        ]"
                + "    },"
                + "    \"Payment\": {"
                + "        \"BoletoDiscount\": 0,"
                + "        \"DebitDiscount\": 0,"
                + "        \"RecurrentPayment\": {"
                + "            \"Interval\": \"Monthly\","
                + "            \"EndDate\": \"2015-12-31\""
                + "         }"
                + "     },"
                + "     \"Customer\": {"
                + "         \"Identity\": 11111111111,"
                + "         \"FullName\": \"Fulano Comprador da Silva\","
                + "         \"Email\": \"[email protected]\","
                + "         \"Phone\": \"11999999999\""
                + "     },"
                + "     \"Options\": {"
                + "         \"AntifraudEnabled\": false"
                + "     }"
                + "}";

        BufferedReader bufferedReader;

        URL url = new URL("https://cieloecommerce.cielo.com.br/api/public/v1/orders");

        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("POST");
        connection.addRequestProperty("MerchantId", "xxxx-xxxx-xxxx-xxxx-xxxx");
        connection.setRequestProperty("Content-Type", "application/json; charset=utf-8");
        connection.setDoOutput(true);

        DataOutputStream jsonRequest = new DataOutputStream(
                connection.getOutputStream());

        jsonRequest.writeBytes(json);
        jsonRequest.flush();
        jsonRequest.close();

        bufferedReader = new BufferedReader(new InputStreamReader(
                connection.getInputStream()));

        StringBuffer jsonResponse = new StringBuffer();

        while ((responseLine = bufferedReader.readLine()) != null) {
            jsonResponse.append(responseLine);
        }

        bufferedReader.close();

        connection.disconnect();
    } catch (Exception ex) {
        return ex.getMessage();
    }
    return responseLine;
}

When executing the code the following error is returned:

sun.security.Validator.Validatorexception: PKIX path building failed: sun.security.Provider.certpath.Suncertpathbuilderexception: Unable to find Valid Certification path to requested target

I make it clear that I have imported the certificate ecommerce.cielo.com.br to the browser as indicated. Also, I imported the other certificates, Raiz.crt and Intermediaria.crt, besides the ecommerce.cielo.com.br.crt to my Truststore with the following commands:

keytool -keystore cacerts -import -alias ecommerce -file ecommerce.cielo.com.br.crt -trustcacerts

keytool -keystore cacerts -import -alias intermediaria -file Intermediaria.crt -trustcacerts

keytool -keystore cacerts -import -alias raiz -file Raiz.crt -trustcacerts

What can I do to remedy the error already described?

1 answer

-3

#!/bin/bash
if [ $EUID != 0 ]; then
    echo 'Você precisa ser root para instalar certificados.'
    exit $?
fi

# Diretório onde os certificados serão instalados
cert_path=`openssl version -d|sed 's/.*\"\(.*\)\"/\1/g'`/certs

# Path para o certificado da Cielo
ecommerce=$cert_path/ecommerce-cielo.crt
# Path para o certificado da intermediária
intermediaria=$cert_path/intermediaria-cielo.ca
# Path para o certificado raiz
raiz=$cert_path/raiz-cielo.crt

# Instalação do certificado raiz
echo "Criando certificado raiz em $raiz"

(cat << 'RAIZ-CIELO'
-----BEGIN CERTIF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NzIwMjM0MlqBDzIwMjYxMTI3MjA1MzQyWjAfBgNVHSMEGDAWgBRo
kORnpKZTgMeGZqTx90tD+4S9bTAdBgNVHQ4EFgQUaJDkZ6SmU4DHhmak8fdLQ/uE
vW0wHQYJKoZIhvZ9B0EABBAwDhsIVjcuMTo0LjADAgSQMA0GCSqGSIb3DQEBBQUA
A4IBAQCT1DCw1wMgKtD5Y+iRDAUgqV8ZyntyTtSx29CW+1RaGSwMCPeyvIWonX9t
O1KzKtvn1ISMY/YPyyYBkVBs9F8U4pN0wBOeMDpQ47RgxRzwIkSNcUesyBrJ6Zua
AGAT/3B+XxFNSRuzFVJ7yVTav52Vr2ua2J7p8eRDjeIRRDq/r72DQnNSi6q7pynP
9WQcCk3RvKqsnyrQ/39/2n3qse0wJcGE2jTSW3iDVuycNsMm4hH2Z0kdkquM++v/
eu6FSqdQgPCnXEqULl8FmTxSQeDNtGPPAUO6nIPcj2A781q0tHuu2guQOHXvgR1m
0vdXcDazv/wor3ElhVsT/h5/WrQ8
-----END CERTIFICATE-----
RAIZ-CIELO
) > $raiz

# Criando um link simbólico para o certificado utilizando seu hash
ln -s $raiz $cert_path/`openssl x509 -noout -hash -in $raiz`.0 &> /dev/null

# Verificando se o certificado foi instalado corretamente
openssl verify -CApath $cert_path $raiz

# Instalação do certificado da intermediária
echo "Criando certificado da intermediária em $intermediaria"

(cat << 'INTERMEDIARIA-CIELO'
-----BEGIN CERTIFICATE-----
MIIFDjCCA/agAwIBAgIMDulMwwAAAABR03eFMA0GCSqGSIb3DQEBCwUAMIG+MQsw
CQYDVQQGEwJVUzEWMBQGA1UEChMNRW50cnVzdCwgSW5jLjEoMCYGA1UECxMfU2Vl
IHd3dy5lbnRydXN0Lm5ldC9sZWdhbC10ZXJtczE5MDcGA1UECxMwKGMpIDIwMDkg
RW50cnVzdCwgSW5jLiAtIGZvciBhdXRob3JpemVkIHVzZSBvbmx5MTIwMAYDVQQD
EylFbnRydXN0IFJvb3QgQ2VydGlmaWNhdG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R0jBBgwFoAUanImetAe
733nO2lR1GyNn5ASZqswDQYJKoZIhvcNAQELBQADggEBADnVjpiDYcgsY9NwHRkw
y/YJrMxp1cncN0HyMg/vdMNY9ngnCTQIlZIv19+4o/0OgemknNM/TWgrFTEKFcxS
BJPok1DD2bHi4Wi3Ogl08TRYCj93mEC45mj/XeTIRsXsgdfJghhcg85x2Ly/rJkC
k9uUmITSnKa1/ly78EqvIazCP0kkZ9Yujs+szGQVGHLlbHfTUqi53Y2sAEo1GdRv
c6N172tkw+CNgxKhiucOhk3YtCAbvmqljEtoZuMrx1gL+1YQ1JH7HdMxWBCMRON1
exCdtTix9qrKgWRs6PLigVWXUX/hwidQosk8WwBD9lu51aX8/wdQQGcHsFXwt35u
Lcw=
-----END CERTIFICATE-----
INTERMEDIARIA-CIELO
) > $intermediaria

# Criando um link simbólico para o certificado utilizando seu hash
ln -s $intermediaria $cert_path/`openssl x509 -noout -hash -in $intermediaria`.0 &> /dev/null

# Verificando se o certificado foi instalado corretamente
openssl verify -CApath $cert_path $intermediaria

# Instalação do certificado Cielo
echo "Criando certificado ecommerce da Cielo em $ecommerce"

(cat << 'ECOMMERCE-CIELO'
-----BEGIN CERTIFICATE-----
MIIHZTCCBk2gAwIBAgIRAL7du6n0o80SAAAAAFDhZoAwDQYJKoZIhvcNAQELBQAw
gboxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1FbnRydXN0LCBJbmMuMSgwJgYDVQQL
Ex9TZWUgd3d3LmVudHJ1c3QubmV0L2xlZ2FsLXRlcm1zMTkwNwYDVQQLEzAoYykg
MjAxMiBFbnRydXN0LCBJbmMuIC0gZm9yIGF1dGhvcml6ZWQgdXNlIG9ubHkxLjAs
BgNVBAMTJUVudHJ1c3QgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkgLSBMMUswHhcN
MTgwNDAzMTM0NDQ1WhcNMjAwNDAzMTQxNDQ0WjBwMQswCQYDVQQGEwJCUjESMBAG
A1UECBMJU2FvIFBhdWxvMRAw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UPDpJGWVFHnJQcQ==
-----END CERTIFICATE-----
ECOMMERCE-CIELO
) > $ecommerce

# Criando um link simbólico para o certificado utilizando seu hash
ln -s $ecommerce $cert_path/`openssl x509 -noout -hash -in $ecommerce`.0 &> /dev/null

# Verificando se o certificado foi instalado corretamente
openssl verify -CApath $cert_path $ecommerce

Browser other questions tagged

You are not signed in. Login or sign up in order to post.