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

obscure private device provenance #7249

Merged
merged 6 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 7 additions & 7 deletions lib/api/entries/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ function configure (app, wares, ctx, env) {
res.entries_err = err;
return next();
});
}, format_entries);
}, wares.obscure_device, format_entries);

/**
* @module get#/entries/:spec
Expand Down Expand Up @@ -389,7 +389,7 @@ function configure (app, wares, ctx, env) {
prepReqModel(req, req.params.model);
query_models(req, res, next);
}
}, format_entries);
}, wares.obscure_device, format_entries);

/**
* @module get#/entries
Expand All @@ -400,7 +400,7 @@ function configure (app, wares, ctx, env) {
* `find[date]`.
*
*/
api.get('/entries', ifModifiedSinceCTX, query_models, format_entries);
api.get('/entries', ifModifiedSinceCTX, query_models, wares.obscure_device, format_entries);

/**
* @function echo_query
Expand Down Expand Up @@ -738,7 +738,7 @@ function configure (app, wares, ctx, env) {
* @routed
* @response 200 /definitions/Entries
*/
api.get('/times/:prefix?/:regex?', prep_storage, prep_pattern_field, prep_patterns, prep_patterns, query_models, format_entries);
api.get('/times/:prefix?/:regex?', prep_storage, prep_pattern_field, prep_patterns, prep_patterns, query_models, wares.obscure_device, format_entries);

api.get('/count/:storage/where', prep_storage, count_records, format_results);

Expand All @@ -753,7 +753,7 @@ function configure (app, wares, ctx, env) {
/api/v1/slice/entries/dateString/mbg/2015.json
```
*/
api.get('/slice/:storage/:field/:type?/:prefix?/:regex?', prep_storage, prep_pattern_field, prep_patterns, query_models, format_entries);
api.get('/slice/:storage/:field/:type?/:prefix?/:regex?', prep_storage, prep_pattern_field, prep_patterns, query_models, wares.obscure_device, format_entries);

/**
* @module post#/entries/preview
Expand All @@ -765,7 +765,7 @@ function configure (app, wares, ctx, env) {
// setting this flag tells insert_entries to not actually store the results
req.persist_entries = false;
next();
}, insert_entries, format_entries);
}, insert_entries, wares.obscure_device, format_entries);

// Protect endpoints with authenticated api.
if (app.enabled('api')) {
Expand All @@ -780,7 +780,7 @@ function configure (app, wares, ctx, env) {
// setting this flag tells insert_entries to store the results
req.persist_entries = true;
next();
}, insert_entries, format_entries);
}, insert_entries, wares.obscure_device, format_entries);

/**
* @module delete#/entries/:spec
Expand Down
6 changes: 4 additions & 2 deletions lib/middleware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
var wares = {
sendJSONStatus : require('./send-json-status'),
bodyParser : require('body-parser'),
compression : require('compression')
compression : require('compression'),
obscureDeviceProvenance: require('./obscure-provenance')
};

function extensions (list) {
Expand All @@ -26,7 +27,8 @@ function configure (env) {
limit: '1Mb'
}),
compression: wares.compression,
extensions: extensions
extensions: extensions,
obscure_device: wares.obscureDeviceProvenance(env)
};
}

Expand Down
12 changes: 12 additions & 0 deletions lib/middleware/obscure-provenance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

module.exports = function create_device_obscurity (env) {
function obscure_device (req, res, next) {
if (res.entries && env.settings.obscureDeviceProvenance) {
for (var i = 0; i < res.entries.length; i++) {
res.entries[i].device = env.settings.obscureDeviceProvenance;
bewest marked this conversation as resolved.
Show resolved Hide resolved
}
}
next( );
}
return obscure_device;
}
9 changes: 9 additions & 0 deletions lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ function init () {
, frameName8: ''
, authFailDelay: 5000
, adminNotifiesEnabled: true
, obscured: ''
, obscureDeviceProvenance: ''
};

var secureSettings = [
Expand All @@ -78,6 +80,8 @@ function init () {
, 'developerTeamId'
, 'userName'
, 'password'
, 'obscured'
, 'obscureDeviceProvenance'
];

var valueMappers = {
Expand Down Expand Up @@ -129,6 +133,9 @@ function init () {

function filteredSettings(settingsObject) {
let so = _.cloneDeep(settingsObject);
if (so.obscured) {
so.enable = _.difference(so.enable, so.obscured);
}
return filterObj(so, secureSettings);
}

Expand Down Expand Up @@ -244,6 +251,7 @@ function init () {

var enable = getAndPrepare('enable');
var disable = getAndPrepare('disable');
var obscured = getAndPrepare('obscured');

settings.alarmTypes = prepareAlarmTypes();

Expand All @@ -266,6 +274,7 @@ function init () {

//all enabled feature, without any that have been disabled
settings.enable = _.difference(enable, disable);
settings.obscured = obscured;

var thresholds = settings.thresholds;

Expand Down