2015-06-22 13:47:27 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular.module('lemur')
|
2016-05-09 17:17:00 -07:00
|
|
|
.controller('CertificateExportController', function ($scope, $uibModalInstance, CertificateApi, CertificateService, PluginService, FileSaver, Blob, toaster, editId) {
|
2015-11-27 13:27:14 -08:00
|
|
|
CertificateApi.get(editId).then(function (certificate) {
|
|
|
|
$scope.certificate = certificate;
|
|
|
|
});
|
|
|
|
|
|
|
|
PluginService.getByType('export').then(function (plugins) {
|
|
|
|
$scope.plugins = plugins;
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.cancel = function () {
|
2016-05-09 17:17:00 -07:00
|
|
|
$uibModalInstance.dismiss('cancel');
|
2015-11-27 13:27:14 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.save = function (certificate) {
|
|
|
|
CertificateService.export(certificate).then(
|
2015-11-30 09:47:36 -08:00
|
|
|
function (response) {
|
|
|
|
var byteCharacters = atob(response.data);
|
|
|
|
var byteArrays = [];
|
|
|
|
|
|
|
|
for (var offset = 0; offset < byteCharacters.length; offset += 512) {
|
|
|
|
var slice = byteCharacters.slice(offset, offset + 512);
|
|
|
|
|
|
|
|
var byteNumbers = new Array(slice.length);
|
|
|
|
for (var i = 0; i < slice.length; i++) {
|
|
|
|
byteNumbers[i] = slice.charCodeAt(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
var byteArray = new Uint8Array(byteNumbers);
|
|
|
|
|
|
|
|
byteArrays.push(byteArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
var blob = new Blob(byteArrays, {type: 'application/octet-stream'});
|
2015-11-30 10:24:53 -08:00
|
|
|
FileSaver.saveAs(blob, certificate.name + '.' + response.extension);
|
2015-11-30 09:47:36 -08:00
|
|
|
$scope.passphrase = response.passphrase;
|
2015-11-27 13:27:14 -08:00
|
|
|
},
|
|
|
|
function (response) {
|
|
|
|
toaster.pop({
|
|
|
|
type: 'error',
|
|
|
|
title: certificate.name,
|
2016-05-05 12:52:08 -07:00
|
|
|
body: 'lemur-bad-request',
|
|
|
|
bodyOutputType: 'directive',
|
|
|
|
directiveData: response.data,
|
2015-11-27 13:27:14 -08:00
|
|
|
timeout: 100000
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
})
|
2016-05-09 17:17:00 -07:00
|
|
|
.controller('CertificateEditController', function ($scope, $uibModalInstance, CertificateApi, CertificateService, DestinationService, NotificationService, toaster, editId) {
|
2015-07-29 17:13:06 -07:00
|
|
|
CertificateApi.get(editId).then(function (certificate) {
|
2015-06-22 13:47:27 -07:00
|
|
|
$scope.certificate = certificate;
|
|
|
|
});
|
|
|
|
|
2015-07-29 17:13:06 -07:00
|
|
|
$scope.cancel = function () {
|
2016-05-09 17:17:00 -07:00
|
|
|
$uibModalInstance.dismiss('cancel');
|
2015-07-29 17:13:06 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.save = function (certificate) {
|
2015-11-23 14:30:23 -08:00
|
|
|
CertificateService.update(certificate).then(
|
|
|
|
function () {
|
|
|
|
toaster.pop({
|
|
|
|
type: 'success',
|
|
|
|
title: certificate.name,
|
|
|
|
body: 'Successfully updated!'
|
|
|
|
});
|
2016-05-09 17:17:00 -07:00
|
|
|
$uibModalInstance.close();
|
2015-11-23 14:30:23 -08:00
|
|
|
},
|
|
|
|
function (response) {
|
|
|
|
toaster.pop({
|
|
|
|
type: 'error',
|
|
|
|
title: certificate.name,
|
2016-05-05 12:52:08 -07:00
|
|
|
body: 'lemur-bad-request',
|
|
|
|
bodyOutputType: 'directive',
|
|
|
|
directiveData: response.data,
|
2015-11-23 14:30:23 -08:00
|
|
|
timeout: 100000
|
|
|
|
});
|
|
|
|
});
|
2015-07-29 17:13:06 -07:00
|
|
|
};
|
2015-06-22 13:47:27 -07:00
|
|
|
|
2015-11-24 14:53:22 -08:00
|
|
|
$scope.certificateService = CertificateService;
|
2015-07-29 17:13:06 -07:00
|
|
|
$scope.destinationService = DestinationService;
|
|
|
|
$scope.notificationService = NotificationService;
|
2015-06-22 13:47:27 -07:00
|
|
|
})
|
|
|
|
|
2016-05-09 17:17:00 -07:00
|
|
|
.controller('CertificateCreateController', function ($scope, $uibModalInstance, CertificateApi, CertificateService, DestinationService, AuthorityService, AuthorityApi, PluginService, MomentService, WizardHandler, LemurRestangular, NotificationService, toaster) {
|
2015-06-22 13:47:27 -07:00
|
|
|
$scope.certificate = LemurRestangular.restangularizeElement(null, {}, 'certificates');
|
2015-08-27 12:59:40 -07:00
|
|
|
// set the defaults
|
|
|
|
CertificateService.getDefaults($scope.certificate);
|
|
|
|
|
2016-04-01 13:01:56 -07:00
|
|
|
$scope.cancel = function () {
|
2016-05-09 17:17:00 -07:00
|
|
|
$uibModalInstance.dismiss('cancel');
|
2016-04-01 13:01:56 -07:00
|
|
|
};
|
|
|
|
|
2016-05-23 18:38:04 -07:00
|
|
|
$scope.getAuthoritiesByName = function (value) {
|
2017-09-26 01:34:49 +03:00
|
|
|
return AuthorityService.findActiveAuthorityByName(value).then(function (authorities) {
|
2016-05-23 18:38:04 -07:00
|
|
|
$scope.authorities = authorities;
|
|
|
|
});
|
2016-05-09 17:17:00 -07:00
|
|
|
};
|
2016-10-31 11:00:15 -07:00
|
|
|
|
2016-05-09 17:17:00 -07:00
|
|
|
$scope.dateOptions = {
|
|
|
|
formatYear: 'yy',
|
|
|
|
maxDate: new Date(2020, 5, 22),
|
|
|
|
minDate: new Date(),
|
|
|
|
startingDay: 1
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.open1 = function() {
|
|
|
|
$scope.popup1.opened = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.open2 = function() {
|
|
|
|
$scope.popup2.opened = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
|
|
|
|
$scope.format = $scope.formats[0];
|
|
|
|
$scope.altInputFormats = ['M!/d!/yyyy'];
|
|
|
|
|
|
|
|
$scope.popup1 = {
|
|
|
|
opened: false
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.popup2 = {
|
|
|
|
opened: false
|
|
|
|
};
|
2016-07-04 16:08:16 -07:00
|
|
|
|
|
|
|
$scope.clearDates = function () {
|
|
|
|
$scope.certificate.validityStart = null;
|
|
|
|
$scope.certificate.validityEnd = null;
|
|
|
|
$scope.certificate.validityYears = null;
|
|
|
|
};
|
2016-05-09 17:17:00 -07:00
|
|
|
|
2018-04-20 14:49:54 -07:00
|
|
|
CertificateService.getDnsProviders().then(function (providers) {
|
|
|
|
$scope.dnsProviders = providers;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2015-07-10 17:08:39 -07:00
|
|
|
$scope.create = function (certificate) {
|
2020-08-31 18:19:32 -07:00
|
|
|
if(certificate.validityType === 'customDates' &&
|
2020-08-26 19:30:12 -07:00
|
|
|
(!certificate.validityStart || !certificate.validityEnd)) { // these are not mandatory fields in schema, thus handling validation in js
|
|
|
|
return showMissingDateError();
|
|
|
|
}
|
2020-08-31 18:19:32 -07:00
|
|
|
if(certificate.validityType === 'defaultDays') {
|
|
|
|
populateValidityDateAsPerDefault(certificate);
|
|
|
|
}
|
2020-08-26 19:30:12 -07:00
|
|
|
|
2015-07-10 17:08:39 -07:00
|
|
|
WizardHandler.wizard().context.loading = true;
|
2015-11-23 14:30:23 -08:00
|
|
|
CertificateService.create(certificate).then(
|
|
|
|
function () {
|
|
|
|
toaster.pop({
|
|
|
|
type: 'success',
|
|
|
|
title: certificate.name,
|
|
|
|
body: 'Successfully created!'
|
|
|
|
});
|
2016-05-09 17:17:00 -07:00
|
|
|
$uibModalInstance.close();
|
2015-11-23 14:30:23 -08:00
|
|
|
},
|
|
|
|
function (response) {
|
|
|
|
toaster.pop({
|
|
|
|
type: 'error',
|
|
|
|
title: certificate.name,
|
2016-05-05 12:52:08 -07:00
|
|
|
body: 'lemur-bad-request',
|
|
|
|
bodyOutputType: 'directive',
|
|
|
|
directiveData: response.data,
|
2015-11-23 14:30:23 -08:00
|
|
|
timeout: 100000
|
|
|
|
});
|
2016-05-05 12:52:08 -07:00
|
|
|
|
2015-11-23 14:30:23 -08:00
|
|
|
WizardHandler.wizard().context.loading = false;
|
|
|
|
});
|
2015-06-22 13:47:27 -07:00
|
|
|
};
|
|
|
|
|
2020-08-26 19:30:12 -07:00
|
|
|
function showMissingDateError() {
|
|
|
|
let error = {};
|
2020-08-31 18:19:32 -07:00
|
|
|
error.message = '';
|
|
|
|
error.reasons = {};
|
|
|
|
error.reasons.validityRange = 'Valid start and end dates are needed, else select Default option';
|
|
|
|
|
|
|
|
toaster.pop({
|
|
|
|
type: 'error',
|
|
|
|
title: 'Validation Error',
|
|
|
|
body: 'lemur-bad-request',
|
|
|
|
bodyOutputType: 'directive',
|
|
|
|
directiveData: error,
|
|
|
|
timeout: 100000
|
|
|
|
});
|
|
|
|
}
|
2020-08-26 19:30:12 -07:00
|
|
|
|
2020-08-31 18:19:32 -07:00
|
|
|
function populateValidityDateAsPerDefault(certificate) {
|
|
|
|
// calculate start and end date as per default validity
|
|
|
|
let startDate = new Date(), endDate = new Date();
|
|
|
|
endDate.setDate(startDate.getDate() + certificate.authority.authorityCertificate.defaultValidityDays);
|
|
|
|
certificate.validityStart = startDate;
|
|
|
|
certificate.validityEnd = endDate;
|
2020-08-26 19:30:12 -07:00
|
|
|
}
|
|
|
|
|
2015-06-22 13:47:27 -07:00
|
|
|
$scope.templates = [
|
|
|
|
{
|
|
|
|
'name': 'Client Certificate',
|
|
|
|
'description': '',
|
|
|
|
'extensions': {
|
|
|
|
'basicConstraints': {},
|
|
|
|
'keyUsage': {
|
|
|
|
'useDigitalSignature': true
|
|
|
|
},
|
|
|
|
'extendedKeyUsage': {
|
|
|
|
'useClientAuthentication': true
|
|
|
|
},
|
|
|
|
'subjectKeyIdentifier': {
|
|
|
|
'includeSKI': true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'Server Certificate',
|
|
|
|
'description': '',
|
|
|
|
'extensions' : {
|
|
|
|
'basicConstraints': {},
|
|
|
|
'keyUsage': {
|
|
|
|
'useKeyEncipherment': true,
|
|
|
|
'useDigitalSignature': true
|
|
|
|
},
|
|
|
|
'extendedKeyUsage': {
|
|
|
|
'useServerAuthentication': true
|
|
|
|
},
|
|
|
|
'subjectKeyIdentifier': {
|
|
|
|
'includeSKI': true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
|
2015-07-29 17:13:06 -07:00
|
|
|
PluginService.getByType('destination').then(function (plugins) {
|
2015-07-10 17:08:39 -07:00
|
|
|
$scope.plugins = plugins;
|
|
|
|
});
|
|
|
|
|
2015-11-24 14:53:22 -08:00
|
|
|
$scope.certificateService = CertificateService;
|
2015-06-22 13:47:27 -07:00
|
|
|
$scope.authorityService = AuthorityService;
|
2015-07-10 17:08:39 -07:00
|
|
|
$scope.destinationService = DestinationService;
|
2015-07-29 17:13:06 -07:00
|
|
|
$scope.notificationService = NotificationService;
|
2016-11-17 16:19:52 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
.controller('CertificateCloneController', function ($scope, $uibModalInstance, CertificateApi, CertificateService, DestinationService, AuthorityService, AuthorityApi, PluginService, MomentService, WizardHandler, LemurRestangular, NotificationService, toaster, editId) {
|
2020-08-03 19:22:13 -07:00
|
|
|
$scope.certificate = LemurRestangular.restangularizeElement(null, {}, 'certificates');
|
2016-11-17 16:19:52 -08:00
|
|
|
CertificateApi.get(editId).then(function (certificate) {
|
|
|
|
$scope.certificate = certificate;
|
2020-08-03 19:23:24 -07:00
|
|
|
// prepare the certificate for cloning
|
2016-11-29 17:15:39 -08:00
|
|
|
$scope.certificate.name = ''; // we should prefer the generated name
|
2018-10-11 16:29:35 -07:00
|
|
|
$scope.certificate.csr = null; // should not clone CSR in case other settings are changed in clone
|
2016-12-27 11:35:53 -08:00
|
|
|
$scope.certificate.validityStart = null;
|
|
|
|
$scope.certificate.validityEnd = null;
|
2020-08-03 19:22:13 -07:00
|
|
|
$scope.certificate.keyType = 'RSA2048'; // default algo to show during clone
|
2020-08-03 19:24:06 -07:00
|
|
|
$scope.certificate.description = 'Cloning from cert ID ' + editId;
|
2020-08-03 19:23:24 -07:00
|
|
|
$scope.certificate.replacedBy = []; // should not clone 'replaced by' info
|
|
|
|
$scope.certificate.removeReplaces(); // should not clone 'replacement cert' info
|
2016-11-17 16:19:52 -08:00
|
|
|
CertificateService.getDefaults($scope.certificate);
|
2015-06-22 13:47:27 -07:00
|
|
|
});
|
2016-11-17 16:19:52 -08:00
|
|
|
|
|
|
|
$scope.cancel = function () {
|
|
|
|
$uibModalInstance.dismiss('cancel');
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.getAuthoritiesByName = function (value) {
|
|
|
|
return AuthorityService.findAuthorityByName(value).then(function (authorities) {
|
|
|
|
$scope.authorities = authorities;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.dateOptions = {
|
|
|
|
formatYear: 'yy',
|
|
|
|
maxDate: new Date(2020, 5, 22),
|
|
|
|
minDate: new Date(),
|
|
|
|
startingDay: 1
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
$scope.open1 = function() {
|
|
|
|
$scope.popup1.opened = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.open2 = function() {
|
|
|
|
$scope.popup2.opened = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
|
|
|
|
$scope.format = $scope.formats[0];
|
|
|
|
$scope.altInputFormats = ['M!/d!/yyyy'];
|
|
|
|
|
|
|
|
$scope.popup1 = {
|
|
|
|
opened: false
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.popup2 = {
|
|
|
|
opened: false
|
|
|
|
};
|
|
|
|
|
2018-05-25 11:07:26 -07:00
|
|
|
CertificateService.getDnsProviders().then(function (providers) {
|
|
|
|
$scope.dnsProviders = providers;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2016-11-17 16:19:52 -08:00
|
|
|
$scope.clearDates = function () {
|
|
|
|
$scope.certificate.validityStart = null;
|
|
|
|
$scope.certificate.validityEnd = null;
|
|
|
|
$scope.certificate.validityYears = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.create = function (certificate) {
|
2020-08-31 18:19:32 -07:00
|
|
|
if(certificate.validityType === 'customDates' &&
|
|
|
|
(!certificate.validityStart || !certificate.validityEnd)) { // these are not mandatory fields in schema, thus handling validation in js
|
|
|
|
return showMissingDateError();
|
|
|
|
}
|
|
|
|
if(certificate.validityType === 'defaultDays') {
|
|
|
|
populateValidityDateAsPerDefault(certificate);
|
|
|
|
}
|
|
|
|
|
2016-11-17 16:19:52 -08:00
|
|
|
WizardHandler.wizard().context.loading = true;
|
|
|
|
CertificateService.create(certificate).then(
|
|
|
|
function () {
|
|
|
|
toaster.pop({
|
|
|
|
type: 'success',
|
|
|
|
title: certificate.name,
|
|
|
|
body: 'Successfully created!'
|
|
|
|
});
|
|
|
|
$uibModalInstance.close();
|
|
|
|
},
|
|
|
|
function (response) {
|
|
|
|
toaster.pop({
|
|
|
|
type: 'error',
|
|
|
|
title: certificate.name,
|
|
|
|
body: 'lemur-bad-request',
|
|
|
|
bodyOutputType: 'directive',
|
|
|
|
directiveData: response.data,
|
|
|
|
timeout: 100000
|
|
|
|
});
|
|
|
|
|
|
|
|
WizardHandler.wizard().context.loading = false;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-08-31 18:19:32 -07:00
|
|
|
function showMissingDateError() {
|
|
|
|
let error = {};
|
|
|
|
error.message = '';
|
|
|
|
error.reasons = {};
|
|
|
|
error.reasons.validityRange = 'Valid start and end dates are needed, else select Default option';
|
|
|
|
|
|
|
|
toaster.pop({
|
|
|
|
type: 'error',
|
|
|
|
title: 'Validation Error',
|
|
|
|
body: 'lemur-bad-request',
|
|
|
|
bodyOutputType: 'directive',
|
|
|
|
directiveData: error,
|
|
|
|
timeout: 100000
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function populateValidityDateAsPerDefault(certificate) {
|
|
|
|
// calculate start and end date as per default validity
|
|
|
|
let startDate = new Date(), endDate = new Date();
|
|
|
|
endDate.setDate(startDate.getDate() + certificate.authority.authorityCertificate.defaultValidityDays);
|
|
|
|
certificate.validityStart = startDate;
|
|
|
|
certificate.validityEnd = endDate;
|
|
|
|
}
|
|
|
|
|
2016-11-17 16:19:52 -08:00
|
|
|
$scope.templates = [
|
|
|
|
{
|
|
|
|
'name': 'Client Certificate',
|
|
|
|
'description': '',
|
|
|
|
'extensions': {
|
|
|
|
'basicConstraints': {},
|
|
|
|
'keyUsage': {
|
|
|
|
'useDigitalSignature': true
|
|
|
|
},
|
|
|
|
'extendedKeyUsage': {
|
|
|
|
'useClientAuthentication': true
|
|
|
|
},
|
|
|
|
'subjectKeyIdentifier': {
|
|
|
|
'includeSKI': true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'Server Certificate',
|
|
|
|
'description': '',
|
|
|
|
'extensions' : {
|
|
|
|
'basicConstraints': {},
|
|
|
|
'keyUsage': {
|
|
|
|
'useKeyEncipherment': true,
|
|
|
|
'useDigitalSignature': true
|
|
|
|
},
|
|
|
|
'extendedKeyUsage': {
|
|
|
|
'useServerAuthentication': true
|
|
|
|
},
|
|
|
|
'subjectKeyIdentifier': {
|
|
|
|
'includeSKI': true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
PluginService.getByType('destination').then(function (plugins) {
|
|
|
|
$scope.plugins = plugins;
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.certificateService = CertificateService;
|
|
|
|
$scope.authorityService = AuthorityService;
|
|
|
|
$scope.destinationService = DestinationService;
|
|
|
|
$scope.notificationService = NotificationService;
|
2017-09-28 18:27:56 -07:00
|
|
|
})
|
|
|
|
|
|
|
|
.controller('CertificateRevokeController', function ($scope, $uibModalInstance, CertificateApi, CertificateService, LemurRestangular, NotificationService, toaster, revokeId) {
|
|
|
|
CertificateApi.get(revokeId).then(function (certificate) {
|
|
|
|
$scope.certificate = certificate;
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.cancel = function () {
|
|
|
|
$uibModalInstance.dismiss('cancel');
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.revoke = function (certificate) {
|
|
|
|
CertificateService.revoke(certificate).then(
|
|
|
|
function () {
|
|
|
|
toaster.pop({
|
|
|
|
type: 'success',
|
|
|
|
title: certificate.name,
|
|
|
|
body: 'Successfully revoked!'
|
|
|
|
});
|
|
|
|
$uibModalInstance.close();
|
|
|
|
},
|
|
|
|
function (response) {
|
|
|
|
toaster.pop({
|
|
|
|
type: 'error',
|
|
|
|
title: certificate.name,
|
|
|
|
body: 'lemur-bad-request',
|
|
|
|
bodyOutputType: 'directive',
|
|
|
|
directiveData: response.data,
|
|
|
|
timeout: 100000
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2019-12-13 14:33:39 +01:00
|
|
|
})
|
|
|
|
.controller('CertificateInfoController', function ($scope, CertificateApi) {
|
|
|
|
$scope.fetchFullCertificate = function (certId) {
|
|
|
|
CertificateApi.get(certId).then(function (certificate) {
|
|
|
|
$scope.certificate = certificate;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
})
|
|
|
|
;
|