diff --git a/Code/Lib/ActivityStreams.php b/Code/Lib/ActivityStreams.php index 33aa0216b..98b354f0d 100644 --- a/Code/Lib/ActivityStreams.php +++ b/Code/Lib/ActivityStreams.php @@ -73,8 +73,35 @@ class ActivityStreams $this->valid = false; } } + + // verify and unpack JSalmon signature if present + // This will only be the case for Zot6 packets + // JSalmon will be deprecated going forward. + + if ($this->valid && is_array($this->data) && array_key_exists('signed', $this->data)) { + $ret = JSalmon::verify($this->data); + $tmp = JSalmon::unpack($this->data['data']); + if ($ret && $ret['success'] && $tmp) { + if ($ret['signer']) { + logger('Unpacked: ' . json_encode($tmp, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT), LOGGER_DATA, LOG_DEBUG); + $saved = json_encode($this->data, JSON_UNESCAPED_SLASHES); + $this->data = $tmp; + $this->raw = json_encode($tmp, JSON_UNESCAPED_SLASHES); + $this->meta['signer'] = $ret['signer']; + $this->meta['signed_data'] = $saved; + if ($ret['hubloc']) { + $this->meta['hubloc'] = $ret['hubloc']; + } + } + } + else { + logger('JSalmon verification failure.'); + $this->valid = false; + } + } } + // Attempt to assemble an Activity from what we were given. if ($this->is_valid()) {