aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2017-08-29 18:46:00 -0700
committerzotlabs <mike@macgirvin.com>2017-08-29 18:46:00 -0700
commit1f42d2333271cec8c439abe0ebb0ecd05b1954f5 (patch)
tree4b4d7904d994b42a91c4dcae461f7b6003c30da1 /Zotlabs
parentb80f0b896053f300d1c888719a93ce67c0542ce5 (diff)
downloadvolse-hubzilla-1f42d2333271cec8c439abe0ebb0ecd05b1954f5.tar.gz
volse-hubzilla-1f42d2333271cec8c439abe0ebb0ecd05b1954f5.tar.bz2
volse-hubzilla-1f42d2333271cec8c439abe0ebb0ecd05b1954f5.zip
add reliable signatures
Diffstat (limited to 'Zotlabs')
-rw-r--r--Zotlabs/Lib/LDSignatures.php35
1 files changed, 34 insertions, 1 deletions
diff --git a/Zotlabs/Lib/LDSignatures.php b/Zotlabs/Lib/LDSignatures.php
index 7bc4fe957..ba7025927 100644
--- a/Zotlabs/Lib/LDSignatures.php
+++ b/Zotlabs/Lib/LDSignatures.php
@@ -15,7 +15,10 @@ class LDSignatures {
return rsa_verify($ohash . $dhash,base64_decode($data['signature']['signatureValue']), $pubkey);
}
-
+ static function dopplesign(&$data,$channel) {
+ $data['magicEnv'] = self::salmon_sign($data,$channel);
+ return self::sign($data,$channel);
+ }
static function sign($data,$channel) {
$options = [
@@ -78,4 +81,34 @@ class LDSignatures {
return jsonld_normalize($data,[ 'algorithm' => 'URDNA2015', 'format' => 'application/nquads' ]);
}
+ static function salmon_sign($data,$channel) {
+
+ $data = json_encode($data,JSON_UNESCAPED_SLASHES);
+ $data = base64url_encode($data, false); // do not strip padding
+ $data_type = 'application/activity+json';
+ $encoding = 'base64url';
+ $algorithm = 'RSA-SHA256';
+ $keyhash = base64url_encode(z_root() . '/channel/' . $channel['channel_address']);
+
+ $data = str_replace(array(" ","\t","\r","\n"),array("","","",""),$data);
+
+ // precomputed base64url encoding of data_type, encoding, algorithm concatenated with periods
+
+ $precomputed = '.' . base64url_encode($data_type,false) . '.YmFzZTY0dXJs.UlNBLVNIQTI1Ng==';
+
+ $signature = base64url_encode(rsa_sign($data . $precomputed,$channel['channel_prvkey']));
+
+ return ([
+ 'meData' => $data,
+ 'meDataType' => $data_type,
+ 'meEncoding' => $encoding,
+ 'meAlgorithm' => $algorithm,
+ 'meCreator' => z_root() . '/channel/' . $channel['channel_address'] . '/public_key_pem',
+ 'meSignatureValue' => $signature
+ ]);
+
+ }
+
+
+
} \ No newline at end of file