diff --git a/index.js b/index.js index 61759b1..2ceb6d6 100644 --- a/index.js +++ b/index.js @@ -37,6 +37,8 @@ const { HttpMethods, } = require('./lib/enums'); const { IssueCertificateRequest } = require('./lib/issue-certificate-request'); +const { IssuePkcs12CertificateRequest } = require('./lib/issue-pkcs12-cert-request'); +const { IssuePkcs12CertificateResponse } = require('./lib/issue-pkcs12-cert-response'); const { KeyModel } = require('./lib/key-model'); const { NameModel } = require('./lib/name-model'); const { @@ -90,6 +92,7 @@ exports.PaginationOrders = PaginationOrders; exports.AmpliaErrorCodes = AmpliaErrorCodes; exports.HttpMethods = HttpMethods; exports.IssueCertificateRequest = IssueCertificateRequest; +exports.IssuePkcs12CertificateRequest = IssuePkcs12CertificateRequest; exports.Order = Order; exports.OrderLocketError = OrderLocketError; exports.BaseOrder = BaseOrder; diff --git a/lib/amplia-client.js b/lib/amplia-client.js index 7cf8a7f..ac84124 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 { IssuePkcs12CertificateResponse } = require('./issue-pkcs12-cert-response'); +const { IssuePkcs12CertificateRequest } = require('./issue-pkcs12-cert-request'); const TypedApiRoutes = { [CertificateFormats.PKI_BRAZIL]: 'pki-brazil', @@ -231,6 +233,30 @@ class AmpliaClient { }); } + /** + * Issues a PKCS#12 certificate order from Amplia + * + * @param {string} orderId the ID of the desired order + * @param {string} password the password for the PKCS#12 certificate + * @param {number} keySize the size of the key for this certificate + * @returns {IssuePkcs12CertificateResponse} the response containing the .PFX file + */ + issuePkcs12Certificate(orderId, password, keySize = null) { + return new Promise((resolve, reject) => { + let client = this._getRestClient(); + let request = new IssuePkcs12CertificateRequest({orderId, password, keySize}); + + client + .post('api/certificates/pkcs12', request) + .then((response) => { + let model = response.getBody(); + let cert = new IssuePkcs12CertificateResponse(model); + resolve(cert); + }) + .catch((err) => reject(err)); + }); + } + listCertificates( searchParams = null, validOnly = false, diff --git a/lib/certificate-model2.js b/lib/certificate-model2.js new file mode 100644 index 0000000..7b88d89 --- /dev/null +++ b/lib/certificate-model2.js @@ -0,0 +1,303 @@ +'use strict' + +class CertificateModel2 { + constructor({parameters, info, content, hasSignedAgreement, id, subscriptionId, caId, keyId, + dateIssued, dateEffective, dateExpires, dateRevoked, alias, subjectDisplayName, serialNumber, + isCA, kind, format, isPendingApproval} = {}) { + this._parameters = parameters || null; + this._info = info || null; + this._content = content || null; + this._hasSignedAgreement = hasSignedAgreement || null; + this._id = id || null; + this._subscriptionId = subscriptionId || null; + this._caId = caId || null; + this._keyId = keyId || null; + this._dateIssued = dateIssued || null; + this._dateEffective = dateEffective || null; + this._dateExpires = dateExpires || null; + this._dateRevoked = dateRevoked || null; + this._alias = alias || null; + this._subjectDisplayName = subjectDisplayName || null; + this._serialNumber = serialNumber || null; + this._isCA = isCA || null; + this._kind = kind || null; + this._format = format || null; + this._isPendingApproval = isPendingApproval || null; + } + + +/** + * @return {Object} + */ + getParameters() { + return this._parameters; + } + + /** + * @param {Object} parameters + */ + setParameters(parameters) { + this._parameters = parameters; + } +/** + * @return {module:dist/amplia-client/CertificateInfo2} + */ + getInfo() { + return this._info; + } + + /** + * @param {module:dist/amplia-client/CertificateInfo2} info + */ + setInfo(info) { + this._info = info; + } +/** + * @return {Blob} + */ + getContent() { + return this._content; + } + + /** + * @param {Blob} content + */ + setContent(content) { + this._content = content; + } +/** + * @return {Boolean} + */ + getHasSignedAgreement() { + return this._hasSignedAgreement; + } + + /** + * @param {Boolean} hasSignedAgreement + */ + setHasSignedAgreement(hasSignedAgreement) { + this._hasSignedAgreement = hasSignedAgreement; + } +/** + * @return {String} + */ + getId() { + return this._id; + } + + /** + * @param {String} id + */ + setId(id) { + this._id = id; + } +/** + * @return {String} + */ + getSubscriptionId() { + return this._subscriptionId; + } + + /** + * @param {String} subscriptionId + */ + setSubscriptionId(subscriptionId) { + this._subscriptionId = subscriptionId; + } +/** + * @return {String} + */ + getCaId() { + return this._caId; + } + + /** + * @param {String} caId + */ + setCaId(caId) { + this._caId = caId; + } +/** + * @return {String} + */ + getKeyId() { + return this._keyId; + } + + /** + * @param {String} keyId + */ + setKeyId(keyId) { + this._keyId = keyId; + } +/** + * @return {Date} + */ + getDateIssued() { + return this._dateIssued; + } + + /** + * @param {Date} dateIssued + */ + setDateIssued(dateIssued) { + this._dateIssued = dateIssued; + } +/** + * @return {Date} + */ + getDateEffective() { + return this._dateEffective; + } + + /** + * @param {Date} dateEffective + */ + setDateEffective(dateEffective) { + this._dateEffective = dateEffective; + } +/** + * @return {Date} + */ + getDateExpires() { + return this._dateExpires; + } + + /** + * @param {Date} dateExpires + */ + setDateExpires(dateExpires) { + this._dateExpires = dateExpires; + } +/** + * @return {Date} + */ + getDateRevoked() { + return this._dateRevoked; + } + + /** + * @param {Date} dateRevoked + */ + setDateRevoked(dateRevoked) { + this._dateRevoked = dateRevoked; + } +/** + * @return {String} + */ + getAlias() { + return this._alias; + } + + /** + * @param {String} alias + */ + setAlias(alias) { + this._alias = alias; + } +/** + * @return {String} + */ + getSubjectDisplayName() { + return this._subjectDisplayName; + } + + /** + * @param {String} subjectDisplayName + */ + setSubjectDisplayName(subjectDisplayName) { + this._subjectDisplayName = subjectDisplayName; + } +/** + * @return {String} + */ + getSerialNumber() { + return this._serialNumber; + } + + /** + * @param {String} serialNumber + */ + setSerialNumber(serialNumber) { + this._serialNumber = serialNumber; + } +/** + * @return {Boolean} + */ + getIsCA() { + return this._isCA; + } + + /** + * @param {Boolean} isCA + */ + setIsCA(isCA) { + this._isCA = isCA; + } +/** + * @return {module:dist/amplia-client/CertificateKinds} + */ + getKind() { + return this._kind; + } + + /** + * @param {module:dist/amplia-client/CertificateKinds} kind + */ + setKind(kind) { + this._kind = kind; + } +/** + * @return {module:dist/amplia-client/CertificateFormats} + */ + getFormat() { + return this._format; + } + + /** + * @param {module:dist/amplia-client/CertificateFormats} format + */ + setFormat(format) { + this._format = format; + } +/** + * @return {Boolean} + */ + getIsPendingApproval() { + return this._isPendingApproval; + } + + /** + * @param {Boolean} isPendingApproval + */ + setIsPendingApproval(isPendingApproval) { + this._isPendingApproval = isPendingApproval; + } + + toModel() { + return { + parameters: this._parameters, + info: this._info, + content: this._content, + hasSignedAgreement: this._hasSignedAgreement, + id: this._id, + subscriptionId: this._subscriptionId, + caId: this._caId, + keyId: this._keyId, + dateIssued: this._dateIssued, + dateEffective: this._dateEffective, + dateExpires: this._dateExpires, + dateRevoked: this._dateRevoked, + alias: this._alias, + subjectDisplayName: this._subjectDisplayName, + serialNumber: this._serialNumber, + isCA: this._isCA, + kind: this._kind, + format: this._format, + isPendingApproval: this._isPendingApproval + } + } +} + +exports.CertificateModel2 = CertificateModel2; + diff --git a/lib/issue-pkcs12-cert-request.js b/lib/issue-pkcs12-cert-request.js new file mode 100644 index 0000000..02d7002 --- /dev/null +++ b/lib/issue-pkcs12-cert-request.js @@ -0,0 +1,80 @@ +'use strict'; + +class IssuePkcs12CertificateRequest { + + 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 || 0 + }; + } +} + +exports.IssuePkcs12CertificateRequest = IssuePkcs12CertificateRequest; \ No newline at end of file diff --git a/lib/issue-pkcs12-cert-response.js b/lib/issue-pkcs12-cert-response.js new file mode 100644 index 0000000..6064c88 --- /dev/null +++ b/lib/issue-pkcs12-cert-response.js @@ -0,0 +1,58 @@ +'use strict'; + +class IssuePkcs12CertificateResponse { + + constructor({ pfxContent, model } = {}) { + this._pfxContent = pfxContent || null; + this._model = model || null; + } + + //region "pfxContent" Accessors + + getPfxContent() { + return this._pfxContent; + } + + get pfxContent() { + return this._pfxContent; + } + + setPfxContent(value) { + this._pfxContent = value; + } + + set pfxContent(value) { + this._pfxContent = value; + } + + //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 + + toModel() { + return { + pfxContent: this._pfxContent, + model: this._model, + }; + } +} + +exports.IssuePkcs12CertificateResponse = IssuePkcs12CertificateResponse; \ No newline at end of file diff --git a/package.json b/package.json index 4746660..717735c 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { "name": "amplia-client", - "version": "1.3.1", + "version": "1.3.2", "description": "Classes to consume Lacuna Software's Amplia", "main": "index.js", "scripts": { "test": "jest", "test:unit": "jest -c jest.config.unit.json", "test:integration": "jest -c jest.config.integration.json", - "test:test-cases": "jest -c jest.config.testcases.json", + "test:test-cases": "jest -c jest.config.testcases.json --verbose", "lint": "eslint .", "lint:fix": "eslint . --fix" },