Permalink
Browse files

Put aws signing in its own package.

  • Loading branch information...
1 parent bcc33ac commit 3261be4b5d6f45f62b9f50bec18af770cbb70957 @mikeal mikeal committed Mar 1, 2013
Showing with 4 additions and 193 deletions.
  1. +0 โˆ’191 aws.js
  2. +2 โˆ’1 main.js
  3. +2 โˆ’1 package.json
View
@@ -1,191 +0,0 @@
-
-/*!
- * knox - auth
- * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
- * MIT Licensed
- */
-
-/**
- * Module dependencies.
- */
-
-var crypto = require('crypto')
- , parse = require('url').parse
- ;
-
-/**
- * Valid keys.
- */
-
-var keys =
- [ 'acl'
- , 'location'
- , 'logging'
- , 'notification'
- , 'partNumber'
- , 'policy'
- , 'requestPayment'
- , 'torrent'
- , 'uploadId'
- , 'uploads'
- , 'versionId'
- , 'versioning'
- , 'versions'
- , 'website'
- ]
-
-/**
- * Return an "Authorization" header value with the given `options`
- * in the form of "AWS <key>:<signature>"
- *
- * @param {Object} options
- * @return {String}
- * @api private
- */
-
-exports.authorization = function(options){
- return 'AWS ' + options.key + ':' + exports.sign(options)
-}
-
-/**
- * Simple HMAC-SHA1 Wrapper
- *
- * @param {Object} options
- * @return {String}
- * @api private
- */
-
-exports.hmacSha1 = function(options){
- return crypto.createHmac('sha1', options.secret).update(options.message).digest('base64')
-}
-
-/**
- * Create a base64 sha1 HMAC for `options`.
- *
- * @param {Object} options
- * @return {String}
- * @api private
- */
-
-exports.sign = function(options){
- options.message = exports.stringToSign(options)
- return exports.hmacSha1(options)
-}
-
-/**
- * Create a base64 sha1 HMAC for `options`.
- *
- * Specifically to be used with S3 presigned URLs
- *
- * @param {Object} options
- * @return {String}
- * @api private
- */
-
-exports.signQuery = function(options){
- options.message = exports.queryStringToSign(options)
- return exports.hmacSha1(options)
-}
-
-/**
- * Return a string for sign() with the given `options`.
- *
- * Spec:
- *
- * <verb>\n
- * <md5>\n
- * <content-type>\n
- * <date>\n
- * [headers\n]
- * <resource>
- *
- * @param {Object} options
- * @return {String}
- * @api private
- */
-
-exports.stringToSign = function(options){
- var headers = options.amazonHeaders || ''
- if (headers) headers += '\n'
- var r =
- [ options.verb
- , options.md5
- , options.contentType
- , options.date.toUTCString()
- , headers + options.resource
- ]
- return r.join('\n')
-}
-
-/**
- * Return a string for sign() with the given `options`, but is meant exclusively
- * for S3 presigned URLs
- *
- * Spec:
- *
- * <date>\n
- * <resource>
- *
- * @param {Object} options
- * @return {String}
- * @api private
- */
-
-exports.queryStringToSign = function(options){
- return 'GET\n\n\n' + options.date + '\n' + options.resource
-};
-
-/**
- * Perform the following:
- *
- * - ignore non-amazon headers
- * - lowercase fields
- * - sort lexicographically
- * - trim whitespace between ":"
- * - join with newline
- *
- * @param {Object} headers
- * @return {String}
- * @api private
- */
-
-exports.canonicalizeHeaders = function(headers){
- var buf = []
- , fields = Object.keys(headers)
- ;
- for (var i = 0, len = fields.length; i < len; ++i) {
- var field = fields[i]
- , val = headers[field]
- , field = field.toLowerCase()
- ;
- if (0 !== field.indexOf('x-amz')) continue
- buf.push(field + ':' + val)
- }
- return buf.sort().join('\n')
-};
-
-/**
- * Perform the following:
- *
- * - ignore non sub-resources
- * - sort lexicographically
- *
- * @param {String} resource
- * @return {String}
- * @api private
- */
-
-exports.canonicalizeResource = function(resource){
- var url = parse(resource, true)
- , path = url.pathname
- , buf = []
- ;
-
- Object.keys(url.query).forEach(function(key){
- if (!~keys.indexOf(key)) return
- var val = '' == url.query[key] ? '' : '=' + encodeURIComponent(url.query[key])
- buf.push(key + val)
- })
-
- return path + (buf.length ? '?' + buf.sort().join('&') : '')
-};
View
@@ -20,8 +20,10 @@ var http = require('http')
, stream = require('stream')
, qs = require('querystring')
, crypto = require('crypto')
+
, oauth = require('./oauth')
, hawk = require('hawk')
+ , aws = require('aws-sign')
, uuid = require('node-uuid')
, ForeverAgent = require('./forever')
@@ -30,7 +32,6 @@ var http = require('http')
, cookieJar = new CookieJar
, tunnel = require('./tunnel')
- , aws = require('./aws')
, mime = require('mime')
, FormData = require('form-data')
View
@@ -25,7 +25,8 @@
"mime": "~1.2.7",
"hawk": "~0.8.1",
"node-uuid": "~1.4.0",
- "cookie-jar": "~0.2.0"
+ "cookie-jar": "~0.2.0",
+ "aws-sign": "~0.2.0"
},
"scripts": {
"test": "node tests/run.js"

0 comments on commit 3261be4

Please sign in to comment.