Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consuming new certificate API #6

Merged
merged 12 commits into from
Nov 7, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -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;
25 changes: 25 additions & 0 deletions lib/amplia-client.js
Original file line number Diff line number Diff line change
@@ -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
rufiss marked this conversation as resolved.
Show resolved Hide resolved
*/
issueSoftwareCertificate(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)
rufiss marked this conversation as resolved.
Show resolved Hide resolved
.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
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() {
rufiss marked this conversation as resolved.
Show resolved Hide resolved
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;
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",
rufiss marked this conversation as resolved.
Show resolved Hide resolved
"version": "1.3.3",
"description": "Classes to consume Lacuna Software's Amplia",
"main": "index.js",
"scripts": {