Paso 2: crear la función de conexión de revocación - Amazon CloudFront

Paso 2: crear la función de conexión de revocación

Cree una función de conexión que compruebe los números de serie de los certificados con los de KeyValueStore para determinar si los certificados se revocan.

Cree una función de conexión que compruebe los números de serie de los certificados con el KeyValueStore:

aws cloudfront create-connection-function \ --name "revocation-control" \ --connection-function-config file://connection-function-config.json \ --connection-function-code file://connection-function-code.txt

El archivo de configuración especifica la asociación de KeyValueStore:

{ "Runtime": "cloudfront-js-2.0", "Comment": "A function that implements revocation control via KVS", "KeyValueStoreAssociations": { "Quantity": 1, "Items": [ { "KeyValueStoreArn": "arn:aws:cloudfront::account-id:key-value-store/kvs-id" } ] } }

El código de la función de conexión comprueba KeyValueStore por si hay certificados revocados:

import cf from 'cloudfront'; async function connectionHandler(connection) { const kvsHandle = cf.kvs(); // Get parsed client serial number from client certificate const clientSerialNumber = connection.clientCertInfo.serialNumber; // Check KVS to see if serial number exists as a key const serialNumberExistsInKvs = await kvsHandle.exists(clientSerialNumber); // Deny connection if serial number exists in KVS if (serialNumberExistsInKvs) { console.log("Connection denied - certificate revoked"); return connection.deny(); } // Allow connections that don't exist in kvs console.log("Connection allowed"); return connection.allow(); }