aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2017-10-05 20:09:21 -0700
committerzotlabs <mike@macgirvin.com>2017-10-05 20:09:21 -0700
commit34a0ec4089ad7bcf730e5399d7e05c119743946d (patch)
tree5c50fba5cec06871efa7684de004a4cc74810846
parent2ed77b598676b1070bd8488fe48666bb25213763 (diff)
downloadvolse-hubzilla-34a0ec4089ad7bcf730e5399d7e05c119743946d.tar.gz
volse-hubzilla-34a0ec4089ad7bcf730e5399d7e05c119743946d.tar.bz2
volse-hubzilla-34a0ec4089ad7bcf730e5399d7e05c119743946d.zip
Add JSalmon signing library for Zot6. See https://macgirvin.com/wiki/mike/Zot%2BVI/Encryption/Signatures
-rw-r--r--Zotlabs/Lib/JSalmon.php38
1 files changed, 38 insertions, 0 deletions
diff --git a/Zotlabs/Lib/JSalmon.php b/Zotlabs/Lib/JSalmon.php
new file mode 100644
index 000000000..763f687fa
--- /dev/null
+++ b/Zotlabs/Lib/JSalmon.php
@@ -0,0 +1,38 @@
+<?php
+
+namespace Zotlabs\Lib;
+
+
+class JSalmon {
+
+ static function sign($data,$key_id,$key) {
+
+ $arr = $data;
+ $data = json_encode($data,JSON_UNESCAPED_SLASHES);
+ $data = base64url_encode($data, false); // do not strip padding
+ $data_type = 'application/x-zot+json';
+ $encoding = 'base64url';
+ $algorithm = 'RSA-SHA256';
+
+ $data = preg_replace('/\s+/','',$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, $key), false);
+
+ return ([
+ 'signed' => true,
+ 'data' => $data,
+ 'data_type' => $data_type,
+ 'encoding' => $encoding,
+ 'alg' => $algorithm,
+ 'sigs' => [
+ 'value' => $signature
+ 'key_id' => base64url_encode($key_id)
+ ]
+ ]);
+
+ }
+} \ No newline at end of file