Skip to content

Commit

Permalink
send lk and secret hash in /me (#306)
Browse files Browse the repository at this point in the history
* Send lkhash = sha256sum(SUBSCRIPTION_SYSTEMID:SUBSCRIPTION_SECRET in /user/me (#305)

nethesis/ns8-nethvoice#125
  • Loading branch information
Stell0 authored Mar 5, 2024
1 parent 59b2e67 commit 4f4ed09
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
13 changes: 13 additions & 0 deletions createlinks
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ event_templates('nethcti-server3-update', qw(
/etc/nethcti/chat.json
/etc/nethcti/phone_urls.json
/etc/httpd/conf.d/nethcti-server.conf
/etc/sysconfig/subscription
));

event_actions('nethcti-server3-update', qw(
Expand Down Expand Up @@ -99,3 +100,15 @@ $event = "post-restore-data";
event_actions($event,
'nethcti-server-fix-rsync-perms' => '10',
);

#
# nethserver-subscription-save
#
$event = "nethserver-subscription-save";
event_templates($event, qw(
/etc/sysconfig/subscription
));

event_services($event, qw(
nethcti-server restart
));
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
#
# 10subscription
#
my $systemId = $subscription{'SystemId'} || '';
my $secret = $subscription{'Secret'} || '';
$enabled = ($systemId eq '' || $secret eq '') ? 0 : 1;

$OUT = "SUBSCRIPTION_SYSTEMID=$systemId\nSUBSCRIPTION_SECRET=$secret\n";
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var crypto = require('crypto');

/**
* Provides user functions through REST API.
*
Expand Down Expand Up @@ -705,6 +707,17 @@ function setCompUtil(comp) {
logger.log.info(IDLOG, 'send user info to user "' + username + '"');
res.send(200, result);
});

// get LK and secret hash
var subscription_systemid = process.env.SUBSCRIPTION_SYSTEMID;
var subscription_secret = process.env.SUBSCRIPTION_SECRET;
if (subscription_systemid && subscription_secret) {
var hash = crypto.createHash('sha256');
hash.update(subscription_systemid + ":" + subscription_secret);
result.lkhash = hash.digest('hex');
} else {
logger.log.info(IDLOG, "LK not enabled");
}
} else {
var strerr = 'sending user info to user "' + username + '": wrong format';
logger.log.error(IDLOG, strerr);
Expand Down
1 change: 1 addition & 0 deletions root/usr/lib/systemd/system/nethcti-server.service
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ After=asterisk.service

[Service]
Type=simple
EnvironmentFile=/etc/sysconfig/subscription
WorkingDirectory=/usr/lib/node/nethcti-server
User=asterisk
Restart=always
Expand Down

0 comments on commit 4f4ed09

Please sign in to comment.