Skip to content

Commit

Permalink
Issue PKCS#12 certificate endpoint added
Browse files Browse the repository at this point in the history
  • Loading branch information
danilobispo committed Oct 27, 2023
1 parent 9947f2b commit 60d5679
Show file tree
Hide file tree
Showing 6 changed files with 472 additions and 2 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
26 changes: 26 additions & 0 deletions lib/amplia-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down
303 changes: 303 additions & 0 deletions lib/certificate-model2.js
Original file line number Diff line number Diff line change
@@ -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;

Loading

0 comments on commit 60d5679

Please sign in to comment.