Skip to content

Commit

Permalink
Consuming new certificate API
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielRufino committed Nov 2, 2023
1 parent 0e62436 commit 44b0b04
Show file tree
Hide file tree
Showing 5 changed files with 333 additions and 1 deletion.
4 changes: 4 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 { 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');
Expand Down Expand Up @@ -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;
Expand Down
25 changes: 25 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 { 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');

Expand Down Expand Up @@ -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
Expand Down
79 changes: 79 additions & 0 deletions lib/issue-software-certificate-request.js
Original file line number Diff line number Diff line change
@@ -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;
224 changes: 224 additions & 0 deletions lib/issue-software-certificate-response.js
Original file line number Diff line number Diff line change
@@ -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,

Check failure on line 212 in lib/issue-software-certificate-response.js

View workflow job for this annotation

GitHub Actions / lint (12.x)

'this_certificateDer' is not defined

Check failure on line 212 in lib/issue-software-certificate-response.js

View workflow job for this annotation

GitHub Actions / lint (14.x)

'this_certificateDer' is not defined

Check failure on line 212 in lib/issue-software-certificate-response.js

View workflow job for this annotation

GitHub Actions / lint (16.x)

'this_certificateDer' is not defined
certificatePem: this_certificatePem,

Check failure on line 213 in lib/issue-software-certificate-response.js

View workflow job for this annotation

GitHub Actions / lint (12.x)

'this_certificatePem' is not defined

Check failure on line 213 in lib/issue-software-certificate-response.js

View workflow job for this annotation

GitHub Actions / lint (14.x)

'this_certificatePem' is not defined

Check failure on line 213 in lib/issue-software-certificate-response.js

View workflow job for this annotation

GitHub Actions / lint (16.x)

'this_certificatePem' is not defined
publicKeyDer: this_publicKeyDer,

Check failure on line 214 in lib/issue-software-certificate-response.js

View workflow job for this annotation

GitHub Actions / lint (12.x)

'this_publicKeyDer' is not defined

Check failure on line 214 in lib/issue-software-certificate-response.js

View workflow job for this annotation

GitHub Actions / lint (14.x)

'this_publicKeyDer' is not defined

Check failure on line 214 in lib/issue-software-certificate-response.js

View workflow job for this annotation

GitHub Actions / lint (16.x)

'this_publicKeyDer' is not defined
publicKeyPem: this_publicKeyPem,

Check failure on line 215 in lib/issue-software-certificate-response.js

View workflow job for this annotation

GitHub Actions / lint (12.x)

'this_publicKeyPem' is not defined

Check failure on line 215 in lib/issue-software-certificate-response.js

View workflow job for this annotation

GitHub Actions / lint (14.x)

'this_publicKeyPem' is not defined

Check failure on line 215 in lib/issue-software-certificate-response.js

View workflow job for this annotation

GitHub Actions / lint (16.x)

'this_publicKeyPem' is not defined
privateKeyPkcs8Der: this_privateKeyPkcs8Der,

Check failure on line 216 in lib/issue-software-certificate-response.js

View workflow job for this annotation

GitHub Actions / lint (12.x)

'this_privateKeyPkcs8Der' is not defined

Check failure on line 216 in lib/issue-software-certificate-response.js

View workflow job for this annotation

GitHub Actions / lint (14.x)

'this_privateKeyPkcs8Der' is not defined

Check failure on line 216 in lib/issue-software-certificate-response.js

View workflow job for this annotation

GitHub Actions / lint (16.x)

'this_privateKeyPkcs8Der' is not defined
privateKeyPkcs8Pem: this_privateKeyPkcs8Pem,

Check failure on line 217 in lib/issue-software-certificate-response.js

View workflow job for this annotation

GitHub Actions / lint (12.x)

'this_privateKeyPkcs8Pem' is not defined

Check failure on line 217 in lib/issue-software-certificate-response.js

View workflow job for this annotation

GitHub Actions / lint (14.x)

'this_privateKeyPkcs8Pem' is not defined

Check failure on line 217 in lib/issue-software-certificate-response.js

View workflow job for this annotation

GitHub Actions / lint (16.x)

'this_privateKeyPkcs8Pem' is not defined
privateKeyPkcs12Der: this_privateKeyPkcs12Der,

Check failure on line 218 in lib/issue-software-certificate-response.js

View workflow job for this annotation

GitHub Actions / lint (12.x)

'this_privateKeyPkcs12Der' is not defined

Check failure on line 218 in lib/issue-software-certificate-response.js

View workflow job for this annotation

GitHub Actions / lint (14.x)

'this_privateKeyPkcs12Der' is not defined

Check failure on line 218 in lib/issue-software-certificate-response.js

View workflow job for this annotation

GitHub Actions / lint (16.x)

'this_privateKeyPkcs12Der' is not defined
privateKeyPkcs12Pem: this_privateKeyPkcs12Pem

Check failure on line 219 in lib/issue-software-certificate-response.js

View workflow job for this annotation

GitHub Actions / lint (12.x)

'this_privateKeyPkcs12Pem' is not defined

Check failure on line 219 in lib/issue-software-certificate-response.js

View workflow job for this annotation

GitHub Actions / lint (14.x)

'this_privateKeyPkcs12Pem' is not defined

Check failure on line 219 in lib/issue-software-certificate-response.js

View workflow job for this annotation

GitHub Actions / lint (16.x)

'this_privateKeyPkcs12Pem' is not defined
};
}
}

exports.IssueSoftwareCertificateResponse = IssueSoftwareCertificateResponse;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 44b0b04

Please sign in to comment.