Skip to content
Browse files

native js hashlib, fixes to CS stuff, remove protege

  • Loading branch information...
1 parent 3994eef commit bea602772d1fb9071b1055224957e02fee023482 @contra contra committed
Showing with 15 additions and 39 deletions.
  1. +0 −16 CHANGELOG.md
  2. +0 −9 TODO.md
  3. +1 −1 examples/test.coffee
  4. +9 −9 lib/main.coffee
  5. +2 −0 lib/main.js
  6. +3 −4 package.json
View
16 CHANGELOG.md
@@ -1,16 +0,0 @@
-0.0.4 / October 3, 2011
-==================
- * JS bug fix
-
-0.0.3 / September 17, 2011
-==================
- * Dependency clean
-
-0.0.2 / September 5, 2011
-==================
- * Change project ownership from Contra to Fractal
-
-0.0.1 / September 5, 2011
-==================
- * Start of the project
-
View
9 TODO.md
@@ -1,9 +0,0 @@
-# TODO
-
-### Minor
-
- * Support for multiple logins
-
-### Major
-
- * Nothing here yet
View
2 examples/test.coffee
@@ -1,4 +1,4 @@
-digest = require '../lib/main.coffee'
+digest = require '../lib/main.js'
server = digest.createServer 'username', 'password', (req, res) ->
res.writeHead 200, 'Content-Type': 'text/plain'
View
18 lib/main.coffee
@@ -1,8 +1,7 @@
require('coffee-script');
-require 'protege'
http = require 'http'
config = require './config'
-hashlib = require 'hashlib'
+md5 = require 'MD5'
nonces = {}
@@ -11,19 +10,20 @@ parseHeader = (header) ->
# Check for inconsistencies
if !header?
return false
- unless header.startsWithIgnoreCase 'digest'
+ unless header.toLowerCase().indexOf(String('digest').toLowerCase()) is 0
return false
out = {}
# Remove 'Digest ' from the string
- header = header.downcase().replace 'digest ', ''
+ header = header.toLowerCase().replace 'digest ', ''
chunks = header.split ', '
for piece in chunks
val = piece.trim().split '='
if val.length < 2
return false
- out[val[0]] = val[1].replaceAll '"', ''
+ val[1] = val[1].replace('"', '') for x in val[1]
+ out[val[0]] = val[1]
return out
authenticate = (request, header, username, password) ->
@@ -45,12 +45,12 @@ authenticate = (request, header, username, password) ->
methodAuth = request.method + ':' + authinfo.uri
if !authinfo.qop?
- digest = hashlib.md5 [hashlib.md5(userAuth), authinfo.nonce, hashlib.md5(methodAuth)].join(':')
+ digest = md5 [md5(userAuth), authinfo.nonce, md5(methodAuth)].join(':')
else
if authinfo.nc <= nonces[authinfo.nonce].count
return false
nonces[authinfo.nonce].count = authinfo.nc
- digest = hashlib.md5 [hashlib.md5(userAuth), authinfo.nonce, authinfo.nc, authinfo.cnonce, authinfo.qop, hashlib.md5(methodAuth)].join(':')
+ digest = md5 [md5(userAuth), authinfo.nonce, authinfo.nc, authinfo.cnonce, authinfo.qop, md5(methodAuth)].join(':')
return digest is authinfo.response
digest = (request, response, username, password, callback) ->
@@ -62,10 +62,10 @@ digest = (request, response, username, password, callback) ->
if authenticate request, header, username, password
callback request, response
else
- nonce = hashlib.md5 new Date().getTime() + config.key
+ nonce = md5 new Date().getTime() + config.key
nonces[nonce] = count: 0
setTimeout nonces.remove, config.timeout, nonce
- opaque = hashlib.md5 config.opaque
+ opaque = md5 config.opaque
response.writeHead 401, {'WWW-Authenticate': 'Digest realm="' + config.realm + '", qop="auth", nonce="' + nonce + '", opaque="' + opaque + '"'}
response.end '401 Unauthorized'
View
2 lib/main.js
@@ -0,0 +1,2 @@
+require('coffee-script');
+module.exports = require('./main.coffee');
View
7 package.json
@@ -1,16 +1,15 @@
{
"name":"digest",
"description":"HTTP Digest authentication for NodeJS",
- "version":"0.0.4",
+ "version":"0.0.5",
"homepage":"http://github.com/wearefractal/node-digest",
"repository":"git://github.com/wearefractal/node-digest.git",
"author":"Fractal <contact@wearefractal.com> (http://wearefractal.com/)",
- "main":"./lib/main.coffee",
+ "main":"./lib/main.js",
"dependencies":{
"coffee-script":"*",
- "protege":">= 0.0.7",
- "hashlib":"*"
+ "MD5":"*"
},
"engines":{
"node":">= 0.4.0"

0 comments on commit bea6027

Please sign in to comment.
Something went wrong with that request. Please try again.