more work on posting and showing status posts
This commit is contained in:
parent
f73ce7d196
commit
650f107d21
7 changed files with 108 additions and 135 deletions
|
@ -7,40 +7,7 @@ function(URI, CryptoJS) {
|
|||
|
||||
var Hmac = {};
|
||||
|
||||
Hmac.makeAuthHeader = function(url, http_method, mac_key, mac_key_id) {
|
||||
|
||||
debug("makeAuthHeader should not be used anymore, bug!")
|
||||
|
||||
url = URI(url);
|
||||
var nonce = Hmac.makeid(8);
|
||||
var time_stamp = parseInt((new Date).getTime() / 1000, 10);
|
||||
|
||||
var port = url.port();
|
||||
if (!port) {
|
||||
port = url.protocol() == "https" ? "443" : "80";
|
||||
}
|
||||
|
||||
var normalizedRequestString = ""
|
||||
+ time_stamp + '\n'
|
||||
+ nonce + '\n'
|
||||
+ http_method + '\n'
|
||||
+ url.path() + url.search() + url.hash() + '\n'
|
||||
+ url.hostname() + '\n'
|
||||
+ port + '\n'
|
||||
+ '\n' ;
|
||||
|
||||
var hmac = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, mac_key);
|
||||
hmac.update(normalizedRequestString);
|
||||
var hash = hmac.finalize();
|
||||
var mac = hash.toString(CryptoJS.enc.Base64);
|
||||
|
||||
return 'MAC id="' + mac_key_id +
|
||||
'", ts="' + time_stamp +
|
||||
'", nonce="' + nonce +
|
||||
'", mac="' + mac + '"';
|
||||
}
|
||||
|
||||
Hmac.makeHawkAuthHeader = function(url, http_method, hawk_id, key, payload, app_id) {
|
||||
Hmac.makeHawkAuthHeader = function(url, http_method, hawk_id, key, app_id) {
|
||||
|
||||
url = URI(url);
|
||||
var nonce = Hmac.makeid(8);
|
||||
|
@ -58,24 +25,22 @@ function(URI, CryptoJS) {
|
|||
+ url.path() + url.search() + url.hash() + '\n' // request uri
|
||||
+ url.hostname().toLowerCase() + '\n' // host
|
||||
+ port + '\n' // port
|
||||
+ Hmac.calculatePayloadHash(payload) + '\n' // hash
|
||||
+ '\n' // Hmac.calculatePayloadHash(payload) + '\n' // hash // FIXME implement payload validation
|
||||
+ '\n' // ext (we don't use it)
|
||||
|
||||
var app = "";
|
||||
|
||||
if(app_id) {
|
||||
app = ', app="' + app_id + "'";
|
||||
normalizedRequestString += app_id + "\n" + // app
|
||||
'\n'; // dlg should be empty
|
||||
}
|
||||
|
||||
|
||||
var hmac = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key);
|
||||
hmac.update(normalizedRequestString);
|
||||
var hash = hmac.finalize();
|
||||
var mac = hash.toString(CryptoJS.enc.Base64);
|
||||
|
||||
|
||||
|
||||
return 'Hawk id="' + hawk_id +
|
||||
'", mac="' + mac +
|
||||
'", ts="' + time_stamp +
|
||||
|
@ -84,6 +49,8 @@ function(URI, CryptoJS) {
|
|||
}
|
||||
|
||||
Hmac.calculatePayloadHash = function (payload) {
|
||||
if (!payload) return "";
|
||||
|
||||
var hash = CryptoJS.algo.SHA256.create();
|
||||
hash.update('hawk.1.payload\n');
|
||||
hash.update('application/vnd.tent.post.v0+json\n');
|
||||
|
|
Reference in a new issue