This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

REST API

Reference for Cloud API authorization and specification

The following sections describe the key concepts in understanding the REST API.

Base URL:

https://{ApiGatewayId}.execute-api.{Region}.amazonaws.com/pty/v1

Once Protegrity Serverless REST API is installed, you can export the OpenAPI documentation file from API Gateway Export API, located in the AWS API Gateway Control Service.

https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-export-api.html

For testing the REST API, we recommend using tools, such as, Postman.

1 - Authorization

Describes the available authorization methods

    Policy Users

    Protegrity Policy roles defines the unique data access privileges for every member. The Protegrity Lambda protects the data with the username sent in either the JWT-formatted authorization header or the request body.

    The lambda behavior can be set in the Lambda environment variables as described in Protect Lambda Configuration

    Authorization/allow_assume_user01
    EmptyUser from the request body. / (Throw an error).User from the request body.
    JWTUser from JWT payloadUser from request body. If not found user from JWT payload.

    JWT Verification

    To ensure the integrity of the user, the lambda protect can verify the JWT.

    1. From your AWS console, navigate to lambda and select the following Lambda: Protegrity_Protect_RESTAPI_<STACK_NAME>
    2. Scroll down to the Environment variables section, select Edit to replace the entries.

    Parameter

    Value

    Notes

    authorization

    JWT

    jwt_verify

    1

     

    jwt_secret_base64

    Secret in base64 encoding. For example, the value of the public key is as follows.

    -----BEGIN PUBLIC KEY-----
    MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC4fkg/JYyN3Skr6RYLiAd/Yhl0
    2TE3/HzHSNPnCaRdUakGp9og7oXBMcoadFDjnoSq1sz+gUHnpoO7s2fwkD5Q4OnC
    BGD3oKP2A4PlOOWD2B2cVmMqX/vf1nAA/343496jsbfgkh1Q7LTzR0IXfdii0o1U
    CbvrVCuaBoyiv4TxWQIDAQAB
    -----END PUBLIC KEY-----
    

    This public key will be stored as follows.

    LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tL
    S0KTUlHZk1BMEdDU3FHU0liM0RRRUJBUV
    VBQTRHTkFEQ0JpUUtCZ1FDNGZrZy9KWXl
    OM1NrcjZSWUxpQWQvWWhsMAoyVEUzL0h6
    SFNOUG5DYVJkVWFrR3A5b2c3b1hCTWNvY
    WRGRGpub1NxMXN6K2dVSG5wb083czJmd2
    tENVE0T25DCkJHRDNvS1AyQTRQbE9PV0Q
    yQjJjVm1NcVgvdmYxbkFBLzM0MzQ5Nmpz
    YmZna2gxUTdMVHpSMElYZmRpaTBvMVUKQ
    2J2clZDdWFCb3lpdjRUeFdRSURBUUFCCi
    0tLS0tRU5EIFBVQkxJQyBLRVktLS0tLQ==
    

    The secret must be in base64. We recommend using RSA public certificates, it is not recommended to keep Hash (symmetric) secrets in the clear.

    2 - HTTP Status Codes

    Describes the Status Codes returned by Cloud API

    The following table explains the different HTTP Status Codes with their corresponding response.

    Status Codes

    Response

    Description

    200

    {"results":["<string>","<string>"],
     "success": true, "encoding":[hex|utf8]}
    

    Success protected data is in results, and success attribute is true

    400

    {
        "error_msg": "<string>",
        "success": false
    }
    

    There was an issue in the request, success is false, check error_msg attribute. For more information check AWS Lambda’s CloudWatch logs.

    For example, the following error appears.

    Authorization header was not found.
    
    1. Required attribute is missing /user, when env authorization is None or empty.
    2. User is missing, check JWT payload for user attribute
    3. Malformed authorization header
    4. Basic Not supported in header: authorization

    403

    {
        "error_msg": "token expired",
        "success": false
    }
    
    {
        "error_msg": "invalid signature",
        "success": false
    }
    {
        "error_msg": " unknown algorithm error",
        "success": false
    }
    
    1. JWT is invalid because secret is wrong or expired.
    2. Get A new JWT or check the base64 secret in AWS Lambda environment variable.
    3. Secret doesn’t match the algorithm type in the JWT header. Secret is symmetric but Algorithm is asymmetric.

    500

    {
        "error_msg": "Invalid json array in jwt_user_claim",
        "success": false
    }
    
    {    "error_msg": "jwt secret is missing ",
        "success": false
    }
    
    1. Configuration error in AWS Lambda.

    Authorization is to JWT and jwt _user_claim is not a valid json array. Example valid input: [“username”, “firstname”].

    1. JWT is set to verify and jwt_secret_base64 is missing.

    3 - Payload Encoding

    Describes the request/response payload encoding

    Payload Encoding

    The following encoding formats are supported in the REST API.

    For every encoding, the resultant protected data is returned in the same encoding. For example, if request is hex-encoded, the response is also hex-encoded.

    For more information about the encoding formats, refer to the Protection Methods Reference.

    Encoding

    Supported by data elements

    Notes

    utf8

    All except binary data elements.

    Default encoding if encoding is not specified.

    hex

    All

    Default encoding for binary data elements.

    base64

    All

    base64_mime

    All

    • Uses RFC 2045 Alphabet.
    • Accepts input on multiple lines.
    • Lines can be separated by any combination of CR and LF characters.
    • Lines must not be longer than 76 characters long.
    • Response lines are separated by CRLF characters.
    • Optional padding.
    • Does not accept any non-base64 characters.

    base64_pem

    All

    • Uses RFC 1421 Alphabet.
    • Accepts input on multiple lines.
    • Lines can be separated by any combination of CR and LF characters.
    • Lines must not be longer than 64 characters long.
    • Response lines are separated by CRLF characters.
    • Optional padding.
    • Does not accept any non-base64 characters.

    base64_url

    All

    The following sections provide the payload schema and its examples.

    4 - TLS Mutual Authentication

    Describes the TLS Mutual Authentication setup for AWS API Gateway

    By default, AWS API Gateway supports HTTPS endpoint and doesn’t allow HTTP protocol.

    For an additional layer of security, you can configure AWS API Gateway TLS Mutual Authentication.

    AWS API Gateway will ensure that the clients with a valid certificate only can call the REST API. Protegrity recommends to setup TLS Mutual Authentication in AWS API Gateway. For more information on how to set AWS API Gateway Mutual TLS go to the following link.

    https://docs.aws.amazon.com/apigateway/latest/developerguide/rest-api-mutual-tls.html

    5 - v4 Specification

    Describes the v4 (SecOps) Protegrity Data Protection API specification

    The Protegrity Data Protection API v4 is the recommended interface for all new integrations. AWS Lambda service limits the maximum size of a payload to 6 MB. Client applications must ensure their payload size is within this limit.

    Overview

    The Protegrity Data Protection API v4 (SecOps v4) lets callers protect, unprotect, and reprotect (unprotect with one data element, then protect with another) sensitive data values according to a configured data security policy.

    This is the new, canonical JSON API and is the recommended interface for all new integrations. It replaces the older v1 and Legacy REST formats, which are now deprecated.

    • Base path: /pty/api/secops/v4
    • Content type: application/json for both request and response
    • Method: all operations are HTTP POST

    Endpoints

    MethodPathPurpose
    POST/pty/api/secops/v4/protectProtect data values using a data element.
    POST/pty/api/secops/v4/unprotectUnprotect previously protected values.
    POST/pty/api/secops/v4/reprotectUnprotect with one data element and protect with another.

    Authentication

    Authentication uses a JWT bearer token supplied in the Authorization header (the scheme keyword is matched case-insensitively):

    Authorization: Bearer <token>
    

    Enforcement is configured at deployment time and controlled by two configuration properties: authorization (set to jwt to enable JWT mode) and jwt_verify (set to 1 to verify the token signature).

    When authorization is set to jwt:

    • A missing, empty, or malformed Authorization header returns HTTP 403, regardless of the jwt_verify setting.
    • Signature and expiry verification runs only when jwt_verify is 1. A failed verification (bad signature, expired token, and so on) returns HTTP 403. When jwt_verify is not 1, the token is decoded for its claims but the signature is not checked.
    • The user identity is taken from a JWT claim (configurable with jwt_user_claim, default cognito:username). See the user field note under Request for how the body user field interacts with this.

    Request

    protect / unprotect

    {
      "user": "alice",
      "payload": [
        {
          "dataElement": "DE_SSN",
          "data": ["675-00-7848", "105-74-8112"],
          "encoding": "utf8",
          "externalIv": "s40de6wf6",
          "externaltweak": "e8wf6s30d",
          "id": "1"
        }
      ]
    }
    

    reprotect

    The reprotect operation adds the new* fields that describe the target data element.

    {
      "user": "alice",
      "payload": [
        {
          "dataElement": "DE_SSN",
          "newDataElement": "DE_SSN_2",
          "data": ["340-75-9971"],
          "externalIv": "s40de6wf6",
          "newExternalIv": "02983hd7sz",
          "externaltweak": "e8wf6s30d",
          "newExternaltweak": "h4egm1hjd"
        }
      ]
    }
    

    Field reference

    FieldLocationTypeRequiredNotes
    usertop-levelstringOptional (conditional at runtime — see note below)Identity performing the operation.
    payloadtop-levelarray (min 1 item)RequiredOne or more work items; each is processed independently.
    dataElementpayload itemstringRequiredPolicy data element. In reprotect this is the source data element.
    newDataElementpayload itemstringRequired for reprotectTarget data element that the values are protected with during reprotect.
    datapayload itemarray of string/number (min 1)RequiredValues to process. null entries are allowed.
    encodingpayload itemenumOptional, default utf8One of: utf8, hex, base64, base64_mime, base64_pem, base64_url.
    externalIvpayload itemstringOptionalExternal initialization vector. In reprotect, the IV for the source data element.
    newExternalIvpayload itemstringOptional (reprotect)IV for the target data element.
    externaltweakpayload itemstringOptionalExternal tweak used with FPE. Source-data-element tweak in reprotect. Note the lowercase t.
    newExternaltweakpayload itemstringOptional (reprotect)Tweak for the target data element. Note the lowercase t.
    idpayload itemstring or numberOptionalClient correlation tag, echoed back in the matching result with its JSON type preserved (a number stays a number, a string stays a string). A string id longer than 128 characters is rejected with an HTTP 400 validation error (maxLength: 128), enforced consistently across protect, unprotect, and reprotect. The number form is unconstrained.

    Response

    Success (HTTP 200)

    Both full success and partial success return HTTP 200. The response envelope is { errorCount, results }, where the order of results matches the order of the input payload.

    {
      "errorCount": 0,
      "results": [
        { "encoding": "utf8", "data": ["340-75-9971", "064-18-7624"], "returnCode": 8 }
      ]
    }
    

    Each result is one of two shapes:

    • Success result (resultSuccess): returnCode (the engine’s success code — 6 for protect, 8 for unprotect, 50 for reprotect, or 11 when an inactive key was used), encoding, data[], and optional id.
    • Failure result (resultFailure): returnCode (a non-success engine code), message, and optional id.

    A partial-success response (one item failed, one succeeded) still returns HTTP 200:

    {
      "errorCount": 1,
      "results": [
        { "id": "1", "message": "Input too short", "returnCode": 22 },
        { "id": "2", "encoding": "base64", "data": ["..."], "returnCode": 8 }
      ]
    }
    

    Error responses

    HTTPWhenBody shape
    200Full or partial success. Per-item failures appear in results and are counted by errorCount.{ errorCount, results[] }
    400A request-level validation error — for example, a missing or empty payload; a missing dataElement (or newDataElement for reprotect) or data; a missing or unresolvable user; an empty data array; an id string longer than 128 characters; or an invalid data item. The request was not processed.{ "message": "..." }
    403An Authorization header or token problem: missing, empty, malformed, or (when jwt_verify=1) a failed signature or expiry verification.{ "message": "..." }
    500A server-side fault — a configuration error (for example, signature verification is enabled but no signing secret is configured), the policy being missing or unavailable, or any other unexpected error.{ "message": "..." }

    Return codes

    returnCode is the protection engine’s return code. A success result carries a success code; a failure result carries a failure code together with a descriptive message.

    Success codes (on a success result):

    returnCodeMeaning
    6Protect succeeded.
    8Unprotect succeeded.
    11Unprotect succeeded using an inactive key.
    50Reprotect succeeded.
    10Access OK; no data transformed.
    27Application authorized.

    Failure codes (on a failure result):

    returnCodeMeaning
    1User not found in the policy.
    2Data element not found in the policy.
    3User lacks permission for the requested operation.
    4Tweak is null.
    5Integrity check failed.
    7Protect operation failed.
    9Unprotect operation failed.
    12Input is null or not within allowed limits.
    13Internal error (also used when an unexpected internal fault has no other engine code).
    14Failed to load the data encryption key.
    15Tweak input is too long.
    19Unsupported tweak for the data element.
    20Out of memory.
    21Input or output buffer too small.
    22Data is too short to protect or unprotect.
    23Data is too long to protect or unprotect.
    26Unsupported algorithm or action for the data element.
    28Application not authorized.
    31Policy not available.
    44Input data content is not valid.
    49Unsupported input encoding for the data element.

    Examples

    protect

    Simple protect call with the minimum required input:

    {
      "user": "alice",
      "payload": [
        { "data": ["George Washington"], "dataElement": "DE_NAME" }
      ]
    }
    

    Response:

    {
      "errorCount": 0,
      "results": [
        { "encoding": "utf8", "data": ["EdVz2X i5a2FXNW5jR"], "returnCode": 6 }
      ]
    }
    

    Protect using FPE with an external tweak:

    {
      "user": "alice",
      "payload": [
        {
          "data": ["675-00-7848", "105-74-8112"],
          "dataElement": "DE_FPE",
          "externaltweak": "e8wf6s30d"
        }
      ]
    }
    

    unprotect

    Simple unprotect call with the minimum required input:

    {
      "user": "alice",
      "payload": [
        { "data": ["EdVz2X i5a2FXNW5jR"], "dataElement": "DE_NAME" }
      ]
    }
    

    Response:

    {
      "errorCount": 0,
      "results": [
        { "encoding": "utf8", "data": ["George Washington"], "returnCode": 8 }
      ]
    }
    

    reprotect

    Simple reprotect call (from one data element to another):

    {
      "user": "alice",
      "payload": [
        {
          "data": ["EdVz2X i5a2FXNW5jR"],
          "dataElement": "DE_NAME",
          "newDataElement": "DE_NAME_2"
        }
      ]
    }
    

    Response:

    {
      "errorCount": 0,
      "results": [
        { "encoding": "utf8", "data": ["m9yGNp v2ZiB2YWx1"], "returnCode": 50 }
      ]
    }
    

    Error examples

    A 400 response for a request-level validation error (for example, a missing payload):

    { "message": "'payload' parameter is missing" }
    

    A 403 response when the authorization token is missing or expired:

    { "message": "Authorization header was not found" }
    

    A 500 response for a configuration error:

    { "message": "JWT secret is missing" }
    

    Headers

    HeaderDirectionNotes
    AuthorizationrequestBearer <jwt> (when JWT authorization is enabled).
    X-Correlation-IDrequest → response (conditional)Optional request-tracking ID. When the request supplies it, it is echoed back on every response — on full-success, partial-success, and all-failure 200 responses, and on 400, 403, and 500 responses. When the request omits it, no header is returned.

    Migrating from v1 / Legacy

    Aspectv1 / LegacySecOps v4
    PathAny path except secopsOnly /pty/api/secops/v4/*
    Operation selectionLast segment of the URL path (…/protect, and so on)Last segment of the URL path (/protect, /unprotect, /reprotect) — same mechanism
    Format selectionBody must contain the arguments arrayRequest path must start with /pty/api/secops/v4
    Request wrapperargumentspayload
    Data element fielddata_element / old_data_elementdataElement / newDataElement
    External IV fieldexternal_iv / old_external_ivexternalIv / newExternalIv
    FPE tweakNot presentexternaltweak / newExternaltweak
    Success envelope{ success, results }{ errorCount, results }
    400 error bodySuccess-shaped envelope{ message } object

    6 - v1 Specification

    Describes the v1 REST API specification

    AWS Lambda service limits maximum size of payload to 6 MB. Client applications of Protegrity Cloud API must ensure their payload size is within this limit. This applies to all types of requests described below.

    Request

    AWS Lambda service limits maximum size of payload to 6 MB. Client applications of Protegrity Cloud API must ensure their payload size is within this limit. This applies to all types of requests described below.

    Performs a policy operation such as protect, unprotect, or reprotect.

    • URI

      /v1/protect or /v1/unprotect or /v1/reprotect

    • Method

      POST

    • Parameters

      data: Input data to the policy operation.

      data_element: Data element to use for the policy operation.

      encoding: Optional, encoding of the data. One of: base64, base64_mime, base64_pem, base64_url, hex, or utf8. Defaults to hex for binary data elements, otherwise defaults to utf8.

      external_iv: Optional, external initialization vector.

      old_data_element: (reprotect) Data element for unprotecting the input.

      old_external_iv: (reprotect) Optional, external initialization vector for the input.

      query_id: Optional, identifier for the request.

      user: User performing the operation.

    • Result

      Returns the output of the policy operation.

    Example 1 - without external IV

    {
      "encoding": "utf8",
      "query_id": "1",
      "user": "user1",
      "data_element": "Alphanum",
      "data":[<data1>,<data2>]
    }
    

    Example 2 - with external IV

    {
      "encoding": "utf8",
      "query_id": "1",
      "user": "user1",
      "data_element": "Alphanum",
      "external_iv": "abc123",
      "data":[<data1>,<data2>]
    }
    

    Example 3 - reprotect

    {
      "encoding": "utf8",
      "query_id": "1",
      "user": "user1",
      "data_element": "deName",
      "old_data_element": "Alphanum",
      "data":[<data1>,<data2>]
    }
    

    Performs policy operations using different data elements for each data set.

    • URI

      /v1/protect or /v1/unprotect or /v1/reprotect

    • Method

      POST

    • Parameters

      encoding: Optional, encoding of the data. One of: base64, base64_mime, base64_pem, base64_url, hex, or utf8. Defaults to hex for binary data elements, otherwise defaults to utf8.

      query_id: Optional, prefix for the request identifier.

      user: User performing the operation.

      arguments[].data: Input data to the policy operation.

      arguments[].data_element: Data element to use for the policy operation.

      arguments[].external_iv: Optional, external initialization vector.

      arguments[].id: Optional, request identifier.

      arguments[].old_data_element: (reprotect) Data element for unprotecting the input.

      arguments[].old_external_iv: (reprotect) Optional, external initialization vector for the input.

    Example 4 - multiple data elements support payload

    {
      "encoding": "utf8",
      "query_id": "query1234", 
      "user": <policy_user>, 
      "arguments": [
        {
          "id": "1", 
          "external_iv": "<external iv>", 
          "data_element": "<data element name>", 
          "data":["<data1>","<data2>"]
        }, 
        {
          "data_element": <data element name>, 
          "data":["<data1>","<data2>"]
        }
      ]
    }
    
    • External IV

      The External IV feature provides an additional level of security by allowing different tokenized results across protectors for the same input data and token element, depending on the External IV set on each protector. External IVs must adhere to certain guardrails and not all data elements support External IV. To read more about the Tokenization model with External IV, refer to the External Initialization Vector (IV) chapter in the Protection Methods Reference.

    Response

    responsePayloadV1:
    type: object
      properties:
        success:
          type: bool
        error_msg:
          type: string
          description: When success is false, error_msg is included
        results:
          type: array
          items:
            type: string
    

    Example success:

    {
      "encoding": "utf8", 
      "results":["str1","str2"], 
      "success": true
    }
    

    If the request was successful, the success flag will always be true.

    Example failure:

    {
      "error_msg": "token expired", 
      "success": false
    }
    

    If the request fails, the success flag will always be false.

    Multi Data Elements Support Payload

    responsePayloadV2:
    type: object
      properties:
        success:
          type: boolean
        results:
          type: array
            items:
              type: object
              properties:
                success:
                  type: bool
                error_msg:
                  type: string
                  description: When success is false, error_msg is included
                id:
                  type: string
                  description: When id is sent in the request payload, id is included in the response
                results:
                  type: array
                  items:
                    type: string
    

    Example success:

    {
      "encoding": "utf8", 
      "results":[
        {
          "encoding": "utf8", 
          "results":["str1","str2"], 
          "success": true
        }, 
        {
          "encoding": "utf8", 
          "results":["str1","str2"], 
          "success": true
        }
      ], 
      "success": true
    }
    

    If the all the subrequests were successful, the success flag will be true.

    Example failure:

    {
      "results": [
        {
          "error_msg": 
          "Protect failed. Data element not found. Refer to audit log for details", 
          "success": false
        }, 
        {
          "encoding": "utf8", 
          "results":["str1","str2"], 
          "success": true
        }
      ], 
      "success": false
    }
    

    It is possible to have a mix of successful and unsuccessful results. In this case, the global success flag will be false.

    7 - Legacy Specification

    Describes the Legacy REST API specification

    Protegrity has multiple products with REST API capabilities, such as Protection Server (out of support), DSG, and the latest product - IAP REST. Each one has its use case. To help you move to cloud-native implementation, Cloud Product REST API supports legacy payload.

    Legacy documentation can be downloaded from AWS console, API, Models, prefix Legacy.

    Request

    Performs a policy operation such as protect, unprotect, or reprotect.

    • Method

      POST

    • Parameters

      dataelementname: (protect/unprotect) Data element to use for the policy operation.

      externaliv: (protect/unprotect) Optional, external initialization vector.

      newdataelementname: (reprotect) Data element to use for the output.

      newexternaliv: (reprotect) Optional, external initialization vector for the output.

      olddataelementname: (reprotect) Data element to use for the input.

      oldexternaliv: (reprotect) Optional, external initialization vector for the input.

      policyusername: User performing the operation.

      bulk.id: Optional, identifier for the request.

      bulk.data[].content: Input data to the policy operation.

    • Result

      Returns the output of the policy operation.

    Example 1 - protect without external IV

    {
      "protect": {
        "policyusername": "user1",
        "dataelementname": "Alphanum",
        "bulk": {
          "id": "1",
          "data": [
            {
              "content": <Data encoded in base64>
            }
          ]
        }
      }
    }
    

    Example 2 - protect with external IV

    {
      "protect": {
        "policyusername": "user1",
        "dataelementname": "Alphanum",
        "externaliv": "abc123",
        "bulk": {
          "id": "1",
          "data": [
            {
              "content": <Data encoded in base64>
            }
          ]
        }
      }
    }
    

    Example 3 - unprotect

    {
      "unprotect": {
        "policyusername": "user1",
        "dataelementname": "Alphanum",
        "bulk": {
          "id": "1",
          "data": [
            {
              "content": <Data encoded in base64>
            }
          ]
        }
      }
    }
    

    Example 4 - reprotect

    {
      "reprotect": {
        "policyusername": "user1",
        "newdataelementname": "deName",
        "olddataelementname": "Alphanum",
        "bulk": {
          "id": "1",
          "data": [
            {
              "content": <Data encoded in base64>
            }
          ]
        }
      }
    }
    

    Response

    Example:

    {"protect":{"bulk":{"returntype":"success","data":[{"returntype":"success","message":"Data
     protection was successful.","content":"RGZBUFR4ODAzejFwNjQ5TWg0TEFpcFNqbA=="},{"returntype":"success",
    "message":"Data protection was successful.","content":"aHNnVVB5QWFDYw=="}]}}}