Closed Bug 869951 Opened 11 years ago Closed 11 years ago

Add support for an HMAC+SHA1 authentication scheme on payloads

Categories

(Webmaker Graveyard :: MakeAPI, enhancement)

x86
macOS
enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: humph, Assigned: cade)

References

Details

(Whiteboard: s=20130722 p=1)

Attachments

(7 files)

From email:

"I think the one thing we should all be aware of is that the payload for each request isn't being signed. This means that if someone can sniff any authenticated call, they'll be able to issue authenticated requests.

I'd like to see an HMAC+SHA1 authentication scheme done. This ensures that the payload for the request is signed and immutable. It is also something we have to do in order to support external clients of the MakeAPI. -- Something that I think is coming very soon."
I was just about to paste that in. +1.
Assignee: nobody → chris
Status: NEW → ASSIGNED
Hey :cade, let me know if you've got any questions on this one? -- I'm happy to be a beta tester.
:wex Sure thing!

Over the next few weeks I'm going to move into an API Key authentication model for API consuming Apps. Those authenticated requests will probably make use of Hawk.
Blocks: 888285
Whiteboard: s=2013w29
Whiteboard: s=2013w29 → s=2013w29 p=1
So I took a (successful) first stab at this:

https://github.com/cadecairos/MakeAPI/commits/bug869951
https://github.com/cadecairos/make-api-client/commits/bug869951

The Create, Update and Delete Routes on the makeapi in this patch are no longer protected with basic auth - they're using Hawk.

I created an ApiUser Database model for mongo that stores an API key, an app id (username) and a few other things. keys and user names can be generated using a really crude tool I added to the Make Editor (its at the bottom of the page) API keys are generated using node-uuid ( https://github.com/shtylman/node-uuid ).

Hawk uses Mongoose to find the API key for a given user, and attempts to authenticate the call.

The makeapi-client code can ONLY do create/update/delete calls if in a node context. Along with the apiURL, you must pass the Make Constructor a hawk object that contains the API key, username and algorithm.
Time to get some eyes on this.

NOTE: This doesn't mean we're ready for third party access.  We still need to figure out how to handle the identity of creator and tag filtering.
Attachment #778527 - Flags: review?(schranz.m)
Attachment #778531 - Flags: review?(schranz.m)
Whiteboard: s=2013w29 p=1 → s=20130722 p=1
Comment on attachment 778527 [details] [review]
https://github.com/mozilla/MakeAPI/pull/113

See pull request comments.
Attachment #778527 - Flags: review?(schranz.m) → review-
Comment on attachment 778531 [details] [review]
https://github.com/mozilla/makeapi-client/pull/6

See pull request comments.
Attachment #778531 - Flags: review?(schranz.m) → review-
Attachment #778527 - Flags: review- → review?(schranz.m)
Attachment #778531 - Flags: review- → review?(schranz.m)
Comment on attachment 778531 [details] [review]
https://github.com/mozilla/makeapi-client/pull/6

Again, get others to review.
Attachment #778531 - Flags: review?(schranz.m) → review+
Comment on attachment 778527 [details] [review]
https://github.com/mozilla/MakeAPI/pull/113

There seems to be an issue with your hawk error handling. The error object I get in my callbacks is null for some reason.
Attachment #778527 - Flags: review?(schranz.m) → review-
STRs?
Flags: needinfo?(schranz.m)
I was just trying to send a new make to my local make server with these patches running.

Now, the error itself isn't important. It happened because it wasn't getting passed new hawk authorization credentials. However the error object I got back was null, making the make itself null and then causing the popcorn maker server to crash.
Flags: needinfo?(schranz.m)
(In reply to Matthew Schranz [:mjschranz] from comment #13)
> I was just trying to send a new make to my local make server with these
> patches running.

How were you sending it? pastebin plz

> Now, the error itself isn't important. It happened because it wasn't getting
> passed new hawk authorization credentials. However the error object I got

"getting passed new hawk autorization credentials" <- wat?

> back was null, making the make itself null and then causing the popcorn
> maker server to crash.
This patch updates Thimble to use the new API Key Authentication model in the MakeAPI
Updates webmaker.org with API Key Authentication (for delete operations)
(In reply to Chris DeCairos (:cade) from comment #14)
> (In reply to Matthew Schranz [:mjschranz] from comment #13)
> > I was just trying to send a new make to my local make server with these
> > patches running.
> 
> How were you sending it? pastebin plz

https://github.com/mozilla/popcorn.webmaker.org/blob/master/lib/middleware.js#L64-L81

I used an untouched Popcorn Maker. It wasn't passing any of the new "hawk" credentials. It fails your middleware check (as expected) and hits https://github.com/mozilla/MakeAPI/pull/113/files#L1R96. That responding function doesn't return a proper error object. If you look back at the link for how Popcorn Maker sends new makes to the MakeAPI, it should hit the error check. However it does and crashes on line 96.
It shouldn't even be tested with an out of date makeapi-client version.

I'm working on a patch for popcorn maker. lets test with up to date code.
MakeAPI ... API Key Authentication for Popcorn Maker
NOTE: All of thimble, popcorn maker and webmaker.org will need the hawk supporting branch of makeapi-client.

I discovered the awesomeness of npm link today, https://npmjs.org/doc/link.html (props to @daleee) use the docs there to easily set up each to use a local checked out version of makeapi-client

Also, you'll have to go into the admin console on the MakeAPI and issue a set of keys. Pass those keys to your app .env's or configs (for popcorn maker)
Attachment #778527 - Flags: review- → review?(schranz.m)
Attachment #778527 - Flags: review?(jon)
Attachment #778531 - Flags: review?(jon)
Attachment #778527 - Flags: review?(schranz.m) → review+
Comment on attachment 778527 [details] [review]
https://github.com/mozilla/MakeAPI/pull/113

Some suggestions in the patch, but this looks pretty close
Attachment #778527 - Flags: review?(jon) → review-
Comment on attachment 778531 [details] [review]
https://github.com/mozilla/makeapi-client/pull/6

Three things to look at
Attachment #778531 - Flags: review?(jon) → review-
Comment on attachment 778527 [details] [review]
https://github.com/mozilla/MakeAPI/pull/113

updated too!
Attachment #778527 - Flags: review- → review?(jon)
Comment on attachment 778527 [details] [review]
https://github.com/mozilla/MakeAPI/pull/113

r+, with the potential nit that if you change the path for `makes` vs `make` then it'll need to be updated here
Attachment #778527 - Flags: review?(jon) → review+
I forgot that I tied up a loose end when POSTing a new make. no longer is it 

{ maker: "", make: { /* make data */ } }

it's just:

{ /* make data */ }

I've added some code to make sure we handle both kinds (for now)
Attachment #780503 - Flags: review?(jon)
Attachment #780503 - Flags: review?(jon) → review+
Attachment #779444 - Flags: review+
Attachment #779408 - Flags: review+
Attachment #779402 - Flags: review+
Fix declaring a variable out of scope.
Attachment #780621 - Flags: review?(jon)
Attachment #780621 - Flags: review?(jon) → review+
Shipped MakeAPI, Popcorn Maker, Thimble and Webmaker.org to Production and Enabled API key Authentication.

Filed Bug 898138 to remove the deprecated API
Filed Bug 898139 to add in Response validation in makeapi-client
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Blocks: 898139
Blocks: 898138
Attachment mime type: text/plain text/plain → text/x-github-pull-request text/x-github-pull-request
Attachment mime type: text/plain text/plain text/plain text/plain text/plain → text/x-github-pull-request text/x-github-pull-request text/x-github-pull-request text/x-github-pull-request text/x-github-pull-request
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: