From 0f9d732667b03d2a746a87ac9183f9bf0a275d82 Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Mon, 15 Jul 2024 13:18:49 +0000 Subject: [PATCH 1/3] feat: add cryptography app with createHmac action --- .../cryptography/actions/create-hmac/index.js | 50 +++++++++++++++++++ .../src/apps/cryptography/actions/index.js | 3 ++ .../src/apps/cryptography/assets/favicon.svg | 3 ++ .../backend/src/apps/cryptography/index.js | 14 ++++++ packages/docs/pages/.vitepress/config.js | 9 ++++ .../docs/pages/apps/cryptography/actions.md | 12 +++++ .../pages/apps/cryptography/connection.md | 3 ++ .../pages/public/favicons/cryptography.svg | 3 ++ 8 files changed, 97 insertions(+) create mode 100644 packages/backend/src/apps/cryptography/actions/create-hmac/index.js create mode 100644 packages/backend/src/apps/cryptography/actions/index.js create mode 100644 packages/backend/src/apps/cryptography/assets/favicon.svg create mode 100644 packages/backend/src/apps/cryptography/index.js create mode 100644 packages/docs/pages/apps/cryptography/actions.md create mode 100644 packages/docs/pages/apps/cryptography/connection.md create mode 100644 packages/docs/pages/public/favicons/cryptography.svg diff --git a/packages/backend/src/apps/cryptography/actions/create-hmac/index.js b/packages/backend/src/apps/cryptography/actions/create-hmac/index.js new file mode 100644 index 00000000..5d4d71f4 --- /dev/null +++ b/packages/backend/src/apps/cryptography/actions/create-hmac/index.js @@ -0,0 +1,50 @@ +import { createHmac } from 'node:crypto'; +import defineAction from '../../../../helpers/define-action.js'; + +export default defineAction({ + name: 'Create HMAC', + key: 'createHmac', + description: 'Create a Hash-based Message Authentication Code (HMAC) using the specified algorithm, secret key, and message data.', + arguments: [ + { + label: 'Algorithm', + key: 'algorithm', + type: 'dropdown', + required: true, + value: 'sha256', + description: 'Specifies the cryptographic hash function to use for HMAC generation.', + options: [ + { label: 'SHA-256 ', value: 'sha256' }, + ], + variables: true, + }, + { + label: 'Secret key', + key: 'secretKey', + type: 'string', + required: true, + description: 'The secret key used to create the HMAC.', + variables: true, + }, + { + label: 'Message data', + key: 'data', + type: 'string', + required: true, + description: 'The input data or message to be hashed. This is the data that will be processed to generate the HMAC.', + variables: true, + }, + ], + + async run($) { + const hash = createHmac($.step.parameters.algorithm, $.step.parameters.secretKey) + .update($.step.parameters.data) + .digest('hex'); + + $.setActionItem({ + raw: { + hash + }, + }); + }, +}); diff --git a/packages/backend/src/apps/cryptography/actions/index.js b/packages/backend/src/apps/cryptography/actions/index.js new file mode 100644 index 00000000..55f2ca82 --- /dev/null +++ b/packages/backend/src/apps/cryptography/actions/index.js @@ -0,0 +1,3 @@ +import createHmac from './create-hmac/index.js'; + +export default [createHmac]; diff --git a/packages/backend/src/apps/cryptography/assets/favicon.svg b/packages/backend/src/apps/cryptography/assets/favicon.svg new file mode 100644 index 00000000..da529327 --- /dev/null +++ b/packages/backend/src/apps/cryptography/assets/favicon.svg @@ -0,0 +1,3 @@ + + + diff --git a/packages/backend/src/apps/cryptography/index.js b/packages/backend/src/apps/cryptography/index.js new file mode 100644 index 00000000..23e57b2e --- /dev/null +++ b/packages/backend/src/apps/cryptography/index.js @@ -0,0 +1,14 @@ +import defineApp from '../../helpers/define-app.js'; +import actions from './actions/index.js'; + +export default defineApp({ + name: 'Cryptography', + key: 'cryptography', + iconUrl: '{BASE_URL}/apps/cryptography/assets/favicon.svg', + authDocUrl: '{DOCS_URL}/apps/cryptography/connection', + supportsConnections: false, + baseUrl: '', + apiBaseUrl: '', + primaryColor: '001F52', + actions, +}); diff --git a/packages/docs/pages/.vitepress/config.js b/packages/docs/pages/.vitepress/config.js index 219a1d51..216b6514 100644 --- a/packages/docs/pages/.vitepress/config.js +++ b/packages/docs/pages/.vitepress/config.js @@ -59,6 +59,15 @@ export default defineConfig({ { text: 'Connection', link: '/apps/carbone/connection' }, ], }, + { + text: 'Cryptography', + collapsible: true, + collapsed: true, + items: [ + { text: 'Actions', link: '/apps/cryptography/actions' }, + { text: 'Connection', link: '/apps/cryptography/connection' }, + ], + }, { text: 'Datastore', collapsible: true, diff --git a/packages/docs/pages/apps/cryptography/actions.md b/packages/docs/pages/apps/cryptography/actions.md new file mode 100644 index 00000000..9b28d7c4 --- /dev/null +++ b/packages/docs/pages/apps/cryptography/actions.md @@ -0,0 +1,12 @@ +--- +favicon: /favicons/cryptography.svg +items: + - name: Create HMAC + desc: Create a Hash-based Message Authentication Code (HMAC) using the specified algorithm, secret key, and message data. +--- + + + + diff --git a/packages/docs/pages/apps/cryptography/connection.md b/packages/docs/pages/apps/cryptography/connection.md new file mode 100644 index 00000000..5cf28566 --- /dev/null +++ b/packages/docs/pages/apps/cryptography/connection.md @@ -0,0 +1,3 @@ +# Cryptography + +Cryptography is a built-in app shipped with Automatisch, allowing you to perform cryptographic operations without needing to connect to any external services. diff --git a/packages/docs/pages/public/favicons/cryptography.svg b/packages/docs/pages/public/favicons/cryptography.svg new file mode 100644 index 00000000..da529327 --- /dev/null +++ b/packages/docs/pages/public/favicons/cryptography.svg @@ -0,0 +1,3 @@ + + + From 949a2543f59a9741c355b22beee68644d834c2e1 Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Tue, 16 Jul 2024 11:24:52 +0000 Subject: [PATCH 2/3] feat(cryptography): add create signature action --- .../cryptography/actions/create-hmac/index.js | 22 ++++---- .../create-rsa-sha256-signature/index.js | 51 +++++++++++++++++++ .../src/apps/cryptography/actions/index.js | 3 +- .../docs/pages/apps/cryptography/actions.md | 4 +- 4 files changed, 67 insertions(+), 13 deletions(-) create mode 100644 packages/backend/src/apps/cryptography/actions/create-rsa-sha256-signature/index.js diff --git a/packages/backend/src/apps/cryptography/actions/create-hmac/index.js b/packages/backend/src/apps/cryptography/actions/create-hmac/index.js index 5d4d71f4..0058f27c 100644 --- a/packages/backend/src/apps/cryptography/actions/create-hmac/index.js +++ b/packages/backend/src/apps/cryptography/actions/create-hmac/index.js @@ -4,7 +4,7 @@ import defineAction from '../../../../helpers/define-action.js'; export default defineAction({ name: 'Create HMAC', key: 'createHmac', - description: 'Create a Hash-based Message Authentication Code (HMAC) using the specified algorithm, secret key, and message data.', + description: 'Create a Hash-based Message Authentication Code (HMAC) using the specified algorithm, secret key, and message.', arguments: [ { label: 'Algorithm', @@ -14,10 +14,18 @@ export default defineAction({ value: 'sha256', description: 'Specifies the cryptographic hash function to use for HMAC generation.', options: [ - { label: 'SHA-256 ', value: 'sha256' }, + { label: 'SHA-256', value: 'sha256' }, ], variables: true, }, + { + label: 'Message', + key: 'message', + type: 'string', + required: true, + description: 'The input message to be hashed. This is the value that will be processed to generate the HMAC.', + variables: true, + }, { label: 'Secret key', key: 'secretKey', @@ -26,19 +34,11 @@ export default defineAction({ description: 'The secret key used to create the HMAC.', variables: true, }, - { - label: 'Message data', - key: 'data', - type: 'string', - required: true, - description: 'The input data or message to be hashed. This is the data that will be processed to generate the HMAC.', - variables: true, - }, ], async run($) { const hash = createHmac($.step.parameters.algorithm, $.step.parameters.secretKey) - .update($.step.parameters.data) + .update($.step.parameters.message) .digest('hex'); $.setActionItem({ diff --git a/packages/backend/src/apps/cryptography/actions/create-rsa-sha256-signature/index.js b/packages/backend/src/apps/cryptography/actions/create-rsa-sha256-signature/index.js new file mode 100644 index 00000000..e7847ba5 --- /dev/null +++ b/packages/backend/src/apps/cryptography/actions/create-rsa-sha256-signature/index.js @@ -0,0 +1,51 @@ +import crypto from 'node:crypto'; +import defineAction from '../../../../helpers/define-action.js'; + +export default defineAction({ + name: 'Create Signature', + key: 'createSignature', + description: 'Create a digital signature using the specified algorithm, secret key, and message.', + arguments: [ + { + label: 'Algorithm', + key: 'algorithm', + type: 'dropdown', + required: true, + value: 'RSA-SHA256', + description: 'Specifies the cryptographic hash function to use for HMAC generation.', + options: [ + { label: 'RSA-SHA256', value: 'RSA-SHA256' }, + ], + variables: true, + }, + { + label: 'Message', + key: 'message', + type: 'string', + required: true, + description: 'The input message to be signed.', + variables: true, + }, + { + label: 'Private key', + key: 'privateKey', + type: 'string', + required: true, + description: 'The RSA private key in PEM format used for signing.', + variables: true, + } + ], + + async run($) { + const signer = crypto.createSign($.step.parameters.algorithm); + signer.update($.step.parameters.message); + signer.end(); + const signature = signer.sign($.step.parameters.privateKey, 'hex'); + + $.setActionItem({ + raw: { + signature + }, + }); + }, +}); diff --git a/packages/backend/src/apps/cryptography/actions/index.js b/packages/backend/src/apps/cryptography/actions/index.js index 55f2ca82..ab2da71e 100644 --- a/packages/backend/src/apps/cryptography/actions/index.js +++ b/packages/backend/src/apps/cryptography/actions/index.js @@ -1,3 +1,4 @@ import createHmac from './create-hmac/index.js'; +import createRsaSha256Signature from './create-rsa-sha256-signature/index.js'; -export default [createHmac]; +export default [createHmac, createRsaSha256Signature]; diff --git a/packages/docs/pages/apps/cryptography/actions.md b/packages/docs/pages/apps/cryptography/actions.md index 9b28d7c4..a7aa2a77 100644 --- a/packages/docs/pages/apps/cryptography/actions.md +++ b/packages/docs/pages/apps/cryptography/actions.md @@ -2,7 +2,9 @@ favicon: /favicons/cryptography.svg items: - name: Create HMAC - desc: Create a Hash-based Message Authentication Code (HMAC) using the specified algorithm, secret key, and message data. + desc: Create a Hash-based Message Authentication Code (HMAC) using the specified algorithm, secret key, and message. + - name: Create Signature + desc: Create a digital signature using the specified algorithm, secret key, and message. ---