Forward API

Cryptographyanchor

availability

Use of the production Forward API is subject to eligibility.

Contact your Account Manager for more information or submit an inquiry to our Business Development team.

Overviewanchor

The Forward API contains a cryptographic toolkit that allows you to encrypt or sign parts of the outgoing request.

All card data emitted by the Forward API is already encrypted by industry-standard TLS so it is fully secured without using these cryptographic functions. However some destination APIs may require further security, necessitating the use of the below features.

AESanchor

important

AES keys are sensitive information and should always be transmitted securely.

You should use the Forward API's PGP public key to encrypt these keys before submitting them for use with Forward API configs.

The Forward API supports encrypting data using AES in Galois Counter Mode (GCM). Taking advantage of this support requires using two functions, aes-gcm and aes-gcm-nonce, and adding an array of keys to the config under keys.

Stepsanchor

  1. Generate an AES nonce to encrypt with, using aes-gcm-nonce. You will probably want to save it in a local variable ($/var/aes-nonce in this example).
  2. Encrypt your data using aes-gcm.
  3. Include the nonce somewhere in the request (so that the destination endpoint can decrypt).

Example partial configanchor

  1. JSON
{
  "keys": ["0e42519c0eda67c22c52b605ff41fde395880ebf6ed40a560b5f5ecc8183d26a"],
  "transformations": [
    {
      "path": "/var/aes-nonce",
      "value": ["aes-gcm-nonce"]
    },
    {
      "path": "/body/aes-nonce",
      "value": ["hex", "$/var/aes-nonce"]
    },
    {
      "path": "/body/payment_method/encrypted-pan",
      "value": ["hex", ["aes-gcm", 0, "$/var/aes-nonce", "$number"]]
    }
  ]
}

RSAanchor

The Forward API supports RSA public key encryption. Taking advantage of this support requires using two functions: rsa-public-key and any one amongst rsa-pkcs1, rsa-oaep-sha1 or rsa-oaep-sha256.

Stepsanchor

  1. Send a PEM-encoded RSA public key on the request.
  2. Encrypt your data using rsa-pkcs1, rsa-oaep-sha1 or rsa-oaep-sha256.

Exampleanchor

  1. bash
curl -i https://forwarding.sandbox.braintreegateway.com/ \
  -H "Content-Type: application/json" \
  -X POST \
  -u "${BRAINTREE_PUBLIC_KEY}:${BRAINTREE_PRIVATE_KEY}" \
  -d '{
    "merchant_id": "'"$BRAINTREE_MERCHANT_ID"'",
    "payment_method_nonce": "fake-valid-nonce",
    "debug_transformations": true,
    "url": "https://httpbin.org/post",
    "method": "POST",
    "data": {"public_key": "-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4c/yKBAkD8wbX7nNfDXL
hL9pMKwBZhEnbPprRjeAX/lelso424gFSZtq4X3LFamrDN59cN2RHqj7so/aK7rW
JJzj9y+lYxocJaNbyFXlZ9ctC0OcoqyqaTlKT0VmAa7EyQXtOsUy0r3nT1emdKTs
vpz/3sFZPyWVIQ2oG/ea+QjzQvUTt8njp3l7D1txGJ+XdtGKrxJ0EuhLJNirDjlY
et33agZOQJTnUzhYA2TJsZNo9zCj9b6DyIfNVeCN0o00r/Hm5d6zlKemKbOKWtSS
dY0wGqSZB+sew+tMZaWfSzij1FzGsfkVaG/VEeMgxZq7fYu+hCcFDDQlElwf1SwJ
qwIDAQAB
-----END PUBLIC KEY-----"},
    "config": {
      "name": "rsa_example",
      "methods": ["POST"],
      "url": "^https://httpbin\.org/post$",
      "request_format": {"/body": "json"},
      "types": ["CreditCard"],
      "transformations": [
        {"path": "/body/card/encrypted_number", "value": ["hex", ["rsa-pkcs1", ["rsa-public-key", "$public_key"], "$number"]]},
      ]
    }
  }'

Note that the result of RSA encryption is non-deterministic.

TLS mutual authenticationanchor

important

Mutual TLS private keys are sensitive information and should always be transmitted securely.

You should use the Forward API's PGP public key to encrypt these certificates before submitting them for use with Forward API configs.

The Forward API supports certificate-based TLS mutual authentication, commonly referred to as "client certificate authentication". In sandbox, a PEM-encoded client_cert and client_key may be passed per-request. In production, a certificate and key will be loaded with the config if necessary.

Exampleanchor

  1. bash
curl -i https://forwarding.sandbox.braintreegateway.com/ \
  -H "Content-Type: application/json" \
  -X POST \
  -u "${BRAINTREE_PUBLIC_KEY}:${BRAINTREE_PRIVATE_KEY}" \
  -d '{
    "merchant_id": "'"$BRAINTREE_MERCHANT_ID"'",
    "payment_method_nonce": "fake-valid-nonce",
    "url": "https://httpbin.org/post",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VATE KEY-----
",
    "config": {
      "name": "tls_mutual_auth_example",
      "methods": ["POST"],
      "url": "^https://httpbin\.org/post$",
      "request_format": {"/body": "json"},
      "types": ["CreditCard"],
      "transformations": []
    }
  }'

Additional Featuresanchor

You can find additional signing and encryption features in the functions reference.


Next Page: PGP Public Key