From 44b0b04feb2ef8ccf75c731f71becdbcad1dc10c Mon Sep 17 00:00:00 2001 From: DanielRufino Date: Thu, 2 Nov 2023 14:42:48 -0300 Subject: [PATCH] Consuming new certificate API --- index.js | 4 + lib/amplia-client.js | 25 +++ lib/issue-software-certificate-request.js | 79 ++++++++ lib/issue-software-certificate-response.js | 224 +++++++++++++++++++++ package.json | 2 +- 5 files changed, 333 insertions(+), 1 deletion(-) create mode 100644 lib/issue-software-certificate-request.js create mode 100644 lib/issue-software-certificate-response.js diff --git a/index.js b/index.js index 95602a2..342a05a 100644 --- a/index.js +++ b/index.js @@ -37,6 +37,8 @@ const { HttpMethods, } = require('./lib/enums'); const { IssueCertificateRequest } = require('./lib/issue-certificate-request'); +const { IssueSoftwareCertificateRequest } = require('./lib/issue-software-certificate-request'); +const { IssueSoftwareCertificateResponse } = require('./lib/issue-software-certificate-response'); const { IssuePkcs12CertificateRequest } = require('./lib/issue-pkcs12-cert-request'); const { IssuePkcs12CertificateResponse } = require('./lib/issue-pkcs12-cert-response'); const { KeyModel } = require('./lib/key-model'); @@ -92,6 +94,8 @@ exports.PaginationOrders = PaginationOrders; exports.AmpliaErrorCodes = AmpliaErrorCodes; exports.HttpMethods = HttpMethods; exports.IssueCertificateRequest = IssueCertificateRequest; +exports.IssueSoftwareCertificateRequest = IssueSoftwareCertificateRequest; +exports.IssueSoftwareCertificateResponse = IssueSoftwareCertificateResponse; exports.IssuePkcs12CertificateRequest = IssuePkcs12CertificateRequest; exports.IssuePkcs12CertificateResponse = IssuePkcs12CertificateResponse; exports.Order = Order; diff --git a/lib/amplia-client.js b/lib/amplia-client.js index 65e5be9..f5680b1 100644 --- a/lib/amplia-client.js +++ b/lib/amplia-client.js @@ -9,6 +9,8 @@ const { PaginatedSearchResponse } = require('./paginated-search-response'); const { RestClient } = require('./rest-client'); const { SignHashResponse } = require('./sign-hash-response'); const { KeyModel } = require('./key-model'); +const { IssueSoftwareCertificateRequest} = require( './issue-software-certificate-request'); +const { IssueSoftwareCertificateResponse} = require( './issue-software-certificate-response'); const { IssuePkcs12CertificateResponse } = require('./issue-pkcs12-cert-response'); const { IssuePkcs12CertificateRequest } = require('./issue-pkcs12-cert-request'); @@ -232,6 +234,29 @@ class AmpliaClient { .catch((err) => reject(err)); }); } + /** + * Issues a Certificate order from Amplia + * + * @param {string} orderId the ID of the desired order + * @param {string} password the password for the certificate + * @param {number} keySize the size of the key for this certificate + * @returns {IssueSoftwareCertificateResponse} the response containing the certificate in many formats + */ + issuePkcs12Certificate(orderId, password, keySize = null) { + return new Promise((resolve, reject) => { + let client = this._getRestClient(); + let request = new IssueSoftwareCertificateRequest({ orderId, password, keySize }); + + client + .post('api/certificates/software', request) + .then((response) => { + let model = response.getBody(); + let cert = new IssueSoftwareCertificateResponse(model); + resolve(cert); + }) + .catch((err) => reject(err)); + }); + } /** * Issues a PKCS#12 certificate order from Amplia diff --git a/lib/issue-software-certificate-request.js b/lib/issue-software-certificate-request.js new file mode 100644 index 0000000..4b1b216 --- /dev/null +++ b/lib/issue-software-certificate-request.js @@ -0,0 +1,79 @@ +'use strict'; + +class IssueSoftwareCertificateRequest{ + + constructor({ orderId, password, keySize } = {}) { + this._orderId = orderId || null; + this._password = password || null; + this._keySize = keySize || null; + } + + //region "orderId" Accessors + + getOrderId() { + return this._orderId; + } + + get orderId() { + return this._orderId; + } + + setOrderId(value) { + this._orderId = value; + } + + set orderId(value) { + this._orderId = value; + } + + //endregion + + //region "password" Accessors + + getPassword() { + return this._password; + } + + get password() { + return this._password; + } + + setPassword(value) { + this._password = value; + } + + set password(value) { + this._password = value; + } + + //endregion + + //region "keySize" Accessors + + getKeySize() { + return this._keySize; + } + + get keySize() { + return this._keySize; + } + + setKeySize(value) { + this._keySize = value; + } + + set keySize(value) { + this._keySize = value; + } + + //endregion + + toModel() { + return { + orderId: this._orderId || '00000000-0000-0000-0000-000000000000', + password: this._password, + keySize: this._keySize || 2048 + }; + } +} +exports.IssueSoftwareCertificateRequest = IssueSoftwareCertificateRequest; \ No newline at end of file diff --git a/lib/issue-software-certificate-response.js b/lib/issue-software-certificate-response.js new file mode 100644 index 0000000..175f6ca --- /dev/null +++ b/lib/issue-software-certificate-response.js @@ -0,0 +1,224 @@ +'use strict'; + +class IssueSoftwareCertificateResponse { + + constructor({ model, + certificateDer, + certificatePem, + publicKeyDer, + publicKeyPem, + privateKeyPkcs8Der, + privateKeyPkcs8Pem, + privateKeyPkcs12Der, + privateKeyPkcs12Pem } = {}) { + this._model = model || null; + this._certificateDer = certificateDer || null; + this._certificatePem = certificatePem || null; + this._publicKeyDer = publicKeyDer || null; + this._publicKeyPem = publicKeyPem || null; + this._privateKeyPkcs8Der = privateKeyPkcs8Der || null; + this._privateKeyPkcs8Pem = privateKeyPkcs8Pem || null; + this._privateKeyPkcs12Der = privateKeyPkcs12Der || null; + this._privateKeyPkcs12Pem = privateKeyPkcs12Pem || null; + } + + //endregion + + //region "model" Accessors + + getModel() { + return this._model; + } + + get model() { + return this._model; + } + + setModel(value) { + this._model = value; + } + + set model(value) { + this._model = value; + } + + //endregion + + //endregion + + //region "certificateDer" Accessors + + getCertificateDer() { + return this._certificateDer; + } + + get certificateDer() { + return this._certificateDer; + } + + setDertificateDer(value) { + this._certificateDer = value; + } + + set certificateDer(value) { + this._certificateDer = value; + } + + //endregion + + //region "certificatePem" Accessors + + getCertificatePem() { + return this._certificatePem; + } + + get certificatePem() { + return this._certificatePem; + } + + setCertificatePem(value) { + this._certificatePem = value; + } + + set certificatePem(value) { + this._certificatePem = value; + } + + //endregion + + //region "publicKeyDer" Accessors + + getPublicKeyDer() { + return this._publicKeyDer; + } + + get publicKeyDer() { + return this._publicKeyDer; + } + + setPublicKeyDer(value) { + this._publicKeyDer = value; + } + + set publicKeyDer(value) { + this._publicKeyDer = value; + } + + //endregion + + //region "publicKeyPem" Accessors + + getPublicKeyPem() { + return this._publicKeyDer; + } + + get publicKeyPem() { + return this._publicKeyPem; + } + + setPublicKeyPem(value) { + this._publicKeyPem = value; + } + + set publicKeyPem(value) { + this._publicKeyPem = value; + } + + //endregion + + //region "privateKeyPkcs8Der" Accessors + + getPrivateKeyPkcs8Der() { + return this._publicKeyDer; + } + + get privateKeyPkcs8Der() { + return this._privateKeyPkcs8Der; + } + + setPrivateKeyPkcs8Der(value) { + this._privateKeyPkcs8Der = value; + } + + set privateKeyPkcs8Der(value) { + this._privateKeyPkcs8Der = value; + } + + //endregion + + //region "privateKeyPkcs8Pem" Accessors + + getPrivateKeyPkcs8Pem() { + return this._publicKeyPem; + } + + get privateKeyPkcs8Pem() { + return this._privateKeyPkcs8Pem; + } + + setPrivateKeyPkcs8Pem(value) { + this._privateKeyPkcs8Pem = value; + } + + set privateKeyPkcs8Pem(value) { + this._privateKeyPkcs8Pem = value; + } + + //endregion + + //region "privateKeyPkcs8Pem" Accessors + + getPrivateKeyPkcs12Pem() { + return this._publicKeyPem; + } + + get privateKeyPkcs12Pem() { + return this._privateKeyPkcs12Pem; + } + + setPrivateKeyPkcs12Pem(value) { + this._privateKeyPkcs12Pem = value; + } + + set privateKeyPkcs12Pem(value) { + this._privateKeyPkcs12Pem = value; + } + + //endregion + + //region "privateKeyPkcs8Der" Accessors + + getPrivateKeyPkcs12Der() { + return this._publicKeyDer; + } + + get privateKeyPkcs12Der() { + return this._privateKeyPkcs12Der; + } + + setPrivateKeyPkcs12Der(value) { + this._privateKeyPkcs12Der = value; + } + + set privateKeyPkcs12Der(value) { + this._privateKeyPkcs12Der = value; + } + + //endregion + + toModel() { + return { + model: this._model, + certificateDer: this_certificateDer, + certificatePem: this_certificatePem, + publicKeyDer: this_publicKeyDer, + publicKeyPem: this_publicKeyPem, + privateKeyPkcs8Der: this_privateKeyPkcs8Der, + privateKeyPkcs8Pem: this_privateKeyPkcs8Pem, + privateKeyPkcs12Der: this_privateKeyPkcs12Der, + privateKeyPkcs12Pem: this_privateKeyPkcs12Pem + }; + } +} + +exports.IssueSoftwareCertificateResponse = IssueSoftwareCertificateResponse; \ No newline at end of file diff --git a/package.json b/package.json index 717735c..ca36384 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "amplia-client", - "version": "1.3.2", + "version": "1.3.3", "description": "Classes to consume Lacuna Software's Amplia", "main": "index.js", "scripts": {