Cache-Only

Cache-Only is the simple Node js project that provides APIs for Salesforce Platform Encryption Cache-Only keys.

Following are the APIs exposed

/

This API just provides Readme document as response.

Sample Request

/

/:keyid

This API is used to fetch key material based on Key Id. This is the API which Salesforce will call for fetching Cache-only keys. Please note there are only 4 pre-generated Keys and newly generated keys are not stored anywhere in this App.

The 4 pregenerated and stored key ids are with these key ids:

pdo25-byok-cert-dec24-1
pdo25-byok-cert-dec24-2
pdo25-byok-cert-dec24-3
pdo25-byok-cert-dec24-4

Sample Request

GET /pdo25-byok-cert-dec24-1

Sample Response

{
  "kid": "pdo25-byok-cert-dec24-1",
  "jwe": "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00iLCJraWQiOiJwZG8yNS1ieW9rLWNlcnQtZGVjMjQtMSJ9.iLE7FoTl2OjMRPPXhTFbOAkxVQ9SqIODaFIzYRxN1I2Vtf1TH_C78KQXQS6ZDauKPqvccGr8AWu-Mu-I0TZsgMKKQl_yiUeXar3uryFJ5WcbSuYtfz9OxWTUnIX_977v_cwDVNv8Gnce3Oz2MIY0TUmdTSLww7WQEU9ku38eWaS1et5x9UCotT8O0CtABJ4om4dcemmemvLcwA4cl9lVjOQ_3HATld1OkqE-dlonV3Shtx982FIlnxLzrMW8oenljYEsR_RXsutWDEmcHnuvqlsP0CdJWCWP-WmSKkGHo9fBQs27N6-7gVN_oV-jTnLiT4ULKgaysgDLZiIs8lN1L8PCLOqer-Ug6GHFq8RYmq61R5cVGQAHjOlyFQUWysxBuULtuJxra01S89SmEVrrmUG-o_-o_3y4p30r-AjC6al6pmH09xB1zw5rEqGEtA8jSZK_VLqA0HTzZaTF8iVPQHanxxVT_tLOr4Yjw9zxdC7T9e7jQ2AHoemBxHVyf2A4LkEwwPPbJSiTl5vO22g_4ow5CvN6FzmklOWz2086eMuEitlXf9Jv6aw9FpqrxFzZsaY6JmEMj8kqSvSMDYm-sLVI_YBISlbHIZbGbkQyy_c0xBzO0if5PJWmmih-uMS2AZI27GwnqkEC_SOYEpsZJ007kHfFscZNIjur2F6ge-M.Y7P6OVuui_sQ3aTo.Q-iM1YzFrPL3GsMGOQrXZvzk682LjOWusv6cMxw6CPY.pfThBXz8GjcdPwSJEz8UPw"
}

/generate

This API is used to generate new key material based on Key Id. Please note that newly generated keys are not stored anywhere in this App.

Sample Request

POST /generate

Form Body

"kid" = "pdo25-byok-cert-dec24-1"
"cert" = "-----BEGIN CERTIFICATE-----
MIIGhDCCBGygAwIBAgIOAZPzg92/AAAAAEc4B1YwDQYJKoZIhvcNAQELBQAwgYMx
GzAZBgNVBAMMEkJZT0tfQ2VydF9EZWNfMjAyNDEYMBYGA1UECwwPMDBESVIwMDAw
MDFiMVlVMRcwFQYDVQQKDA5TYWxlc2ZvcmNlLmNvbTEWMBQGA1UEBwwNU2FuIEZy
YW5jaXNjbzELMAkGA1UECAwCQ0ExDDAKBgNVBAYTA1VTQTAeFw0yNDEyMjMxMjM1
MjVaFw0yNjEyMjMxMjAwMDBaMIGDMRswGQYDVQQDDBJCWU9LX0NlcnRfRGVjXzIw
MjQxGDAWBgNVBAsMDzAwRElSMDAwMDAxYjFZVTEXMBUGA1UECgwOU2FsZXNmb3Jj
ZS5jb20xFjAUBgNVBAcMDVNhbiBGcmFuY2lzY28xCzAJBgNVBAgMAkNBMQwwCgYD
VQQGEwNVU0EwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQC5xZL1tk+e
2jLhJW6LA0oCkIcJ18HLZjvnksLYh5xC4WAPs2g6Z7XsWTL9yNEkFBDQ1JWaokW4
eWUjnu+UQp0yxVAqkB6JDlxvoAggWbs0/HfMqT5qucc4G+GUN+OhmoNPiSlIBuNl
UumUM3ESAyBovMT151TtKxC5sBFgU9UR4dIAwCzJhh+R4Y8gqCWOpF27dEG2yYWs
jOUHYFx67OJrimV5+CLSBQ6ZweRBXUIfHtooe7zdjjkO5MCPzMfk5gmCeq5WozwZ
b5FZoWEsKj4EXIS9Oi3Rn49qcCH/C5Unj0v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xV12YebFxavZe_d_qsO5Fa8wwziCoPi1bEq9AH7QWDgmvCan87U17rzg9vbFpaTYOU60E-iriQH4HAqqwSbB6gGG5H5UtFCTh67JnqqQ.yGHi7M_6b2UbTkJs.wMm7oHYj4myXMdsVQGG0JaTP285VDXoYdP36zCHvlfQ.FdLFpWHV_pAd1T1RNFX3zg"
}

Steps to Enable Cache-only key

For latest help article please refer: https://help.salesforce.com/s/articleView?id=sf.securitypebyokcache.htm&language=enUS&type=5

  1. Procure "Shield - Platform Encryption" and "Cache-Only Keys for Platform Encryption" Addon

    Both are two seperate SKUs and are not include Out of the Box with Salesforce Editions. Shield - Platform Encryption provide BYOK capabilities, but to enable KMS and cache-only Keys additional addon "Cache-Only Keys for Platform Encryption" is required.

  2. Enable Cache-Only Key

    Login to your Salesforce Org and go to Setup and then Encryption Settings. Scroll down to "Allow Cache-Only Keys" under "Advanced Encryption Settings" and click on toggle button to enable Cache-Only Keys.

Setup > Platform Encryption > Encryption Settings > "Allow Cache-Only Keys" under "Advanced Encryption Settings"

If you can not find Platform Encryption in Setup, then most likely "Shield - Platform Encryption" license is not enabled. If "Allow Cache-Only Keys" option is disabled or hidden, then most likely "Cache-Only Keys for Platform Encryption" is not enabled. If you have procurred both addons and trying in Sandbox, then do "Match Production License" in Sandbox.

  1. Generate Tenant Secret

    Navigate to Setup > Platform Encryption > Key Management and click "Generate Tenant Secret" button under "Fields and Files (Probabilitistic)" or Fields (Deterministic)". Please note that Cach-Only key does not work for "Search Index" or "Event Bus" encryption.

Setup > Platform Encryption > Key Management and click "Generate Tenant Secret" button

  1. Prepare your Key Service

    Make sure you Key Service is up and running and publically accessible for the next steps.

  2. Create Named Credentials

    In order to make callout from Salesforce to you Key Service, Salesforce will rely on Named Credentials for authorization. Follow the steps mentioned in this article to create named credential to you Key Service.

    Please note:

   String endPoint = 'callout:<named-credential>/<keyid>'; //replace <named-credential> with named credential name and <keyid> with Key Id
   HttpRequest request = new HttpRequest();
   request.setMethod('GET');
   request.setEndpoint(endPoint);
   HttpResponse response = (new Http()).send(request);
   System.debug('Response: ' + response); //Response Code should be 200
   System.debug('Body: ' + response.getBody()); //Body should be something like; {"kid": "passed key id","jwe": "key material"}
  1. Generate Certificate for BYOK In order to generate key material for Cache-Only Keys you will need Certificate provided by your Saleforce Org. Navigate to Setup > Platform Encryption > Key Management and click "Bring Your Own Key" button under "Fields and Files (Probabilitistic)" or Fields (Deterministic)". Please note that Cach-Only key does not work for "Search Index" or "Event Bus" encryption.

Setup > Platform Encryption > Key Management and click "Bring Your Own Key" button

On Bring Your Own Key Page, click on "Create Self-Signed Certificate", provide Label and Unique Name 'without any spaces' and click Save. Please note:

  1. Prepare Key Material

    There are certain specifications and steps required to generate key material that is compatible with cache-only keys, these are explained in detail in this article. In nutshell, steps include generating 256 AES Key and taking Public Key from the Certificate and using JWE compact serialization to generate Key material.

    Code in this project follow these specifications and you can just call generate API as mentioned above to generate a new key material.

  2. Integrate KMS for BYOK

    Navigate to Setup > Platform Encryption > Key Management and click "Bring Your Own Key" button under "Fields and Files (Probabilitistic)" or Fields (Deterministic)". Please note that Cach-Only key does not work for "Search Index" or "Event Bus" encryption.

Setup > Platform Encryption > Key Management and click "Bring Your Own Key" button

On Bring Your Own Key Page, select "Use a Cache-Only Key", provide Key Id and select Named Credential created earlier for Key Service and then click on Save. Process will take some time and it will appear as if nothing is happening. Please be patient and after completion you will start seeing new Key under "Fields and Files (Probabilitistic)" or Fields (Deterministic)".

Please note:

  1. Start using new Key

    Once new key is upload you can see encryption status under Setup > Platform Encryption > Encryption Statistics. It will require "Sync" to re-encrypt old data with new keys, however all new data will start encrypting using new keys.

Setup > Platform Encryption > Encryption Statistics

Please note:

  1. Testing and Debugging

    For more details on debugging Cache-Only Keys please refer this article.

Enjoy!!

Amin Rehman