murgatroid99 | 749666e | 2015-01-12 18:25:58 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
murgatroid99 | 25269f0 | 2016-03-16 16:00:07 -0700 | [diff] [blame] | 3 | * Copyright 2015-2016, Google Inc. |
murgatroid99 | 749666e | 2015-01-12 18:25:58 -0800 | [diff] [blame] | 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above |
| 13 | * copyright notice, this list of conditions and the following disclaimer |
| 14 | * in the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google Inc. nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
| 32 | */ |
| 33 | |
murgatroid99 | 5f709ca | 2015-09-30 14:22:54 -0700 | [diff] [blame] | 34 | #ifndef GRPC_NODE_CALL_CREDENTIALS_H_ |
| 35 | #define GRPC_NODE_CALL_CREDENTIALS_H_ |
murgatroid99 | e506151 | 2015-01-12 18:14:35 -0800 | [diff] [blame] | 36 | |
murgatroid99 | 734c8db | 2016-03-16 11:39:15 -0700 | [diff] [blame] | 37 | #include <list> |
| 38 | |
murgatroid99 | e506151 | 2015-01-12 18:14:35 -0800 | [diff] [blame] | 39 | #include <node.h> |
| 40 | #include <nan.h> |
murgatroid99 | 734c8db | 2016-03-16 11:39:15 -0700 | [diff] [blame] | 41 | #include <uv.h> |
murgatroid99 | e506151 | 2015-01-12 18:14:35 -0800 | [diff] [blame] | 42 | #include "grpc/grpc_security.h" |
| 43 | |
| 44 | namespace grpc { |
| 45 | namespace node { |
| 46 | |
murgatroid99 | 5f709ca | 2015-09-30 14:22:54 -0700 | [diff] [blame] | 47 | class CallCredentials : public Nan::ObjectWrap { |
murgatroid99 | e506151 | 2015-01-12 18:14:35 -0800 | [diff] [blame] | 48 | public: |
murgatroid99 | 2b09783 | 2015-09-17 13:56:25 -0700 | [diff] [blame] | 49 | static void Init(v8::Local<v8::Object> exports); |
| 50 | static bool HasInstance(v8::Local<v8::Value> val); |
murgatroid99 | 7c0dbf8 | 2015-10-20 16:10:20 -0700 | [diff] [blame] | 51 | /* Wrap a grpc_call_credentials struct in a javascript object */ |
| 52 | static v8::Local<v8::Value> WrapStruct(grpc_call_credentials *credentials); |
murgatroid99 | e506151 | 2015-01-12 18:14:35 -0800 | [diff] [blame] | 53 | |
murgatroid99 | 7c0dbf8 | 2015-10-20 16:10:20 -0700 | [diff] [blame] | 54 | /* Returns the grpc_call_credentials struct that this object wraps */ |
| 55 | grpc_call_credentials *GetWrappedCredentials(); |
murgatroid99 | e506151 | 2015-01-12 18:14:35 -0800 | [diff] [blame] | 56 | |
| 57 | private: |
murgatroid99 | 7c0dbf8 | 2015-10-20 16:10:20 -0700 | [diff] [blame] | 58 | explicit CallCredentials(grpc_call_credentials *credentials); |
murgatroid99 | 5f709ca | 2015-09-30 14:22:54 -0700 | [diff] [blame] | 59 | ~CallCredentials(); |
murgatroid99 | e506151 | 2015-01-12 18:14:35 -0800 | [diff] [blame] | 60 | |
| 61 | // Prevent copying |
murgatroid99 | 5f709ca | 2015-09-30 14:22:54 -0700 | [diff] [blame] | 62 | CallCredentials(const CallCredentials &); |
| 63 | CallCredentials &operator=(const CallCredentials &); |
murgatroid99 | e506151 | 2015-01-12 18:14:35 -0800 | [diff] [blame] | 64 | |
| 65 | static NAN_METHOD(New); |
murgatroid99 | e506151 | 2015-01-12 18:14:35 -0800 | [diff] [blame] | 66 | static NAN_METHOD(CreateSsl); |
murgatroid99 | ada3f61 | 2015-09-23 10:47:35 -0700 | [diff] [blame] | 67 | static NAN_METHOD(CreateFromPlugin); |
murgatroid99 | 5f709ca | 2015-09-30 14:22:54 -0700 | [diff] [blame] | 68 | |
| 69 | static NAN_METHOD(Compose); |
murgatroid99 | 2b09783 | 2015-09-17 13:56:25 -0700 | [diff] [blame] | 70 | static Nan::Callback *constructor; |
murgatroid99 | e506151 | 2015-01-12 18:14:35 -0800 | [diff] [blame] | 71 | // Used for typechecking instances of this javascript class |
murgatroid99 | 2b09783 | 2015-09-17 13:56:25 -0700 | [diff] [blame] | 72 | static Nan::Persistent<v8::FunctionTemplate> fun_tpl; |
murgatroid99 | e506151 | 2015-01-12 18:14:35 -0800 | [diff] [blame] | 73 | |
murgatroid99 | 7c0dbf8 | 2015-10-20 16:10:20 -0700 | [diff] [blame] | 74 | grpc_call_credentials *wrapped_credentials; |
murgatroid99 | e506151 | 2015-01-12 18:14:35 -0800 | [diff] [blame] | 75 | }; |
| 76 | |
murgatroid99 | ada3f61 | 2015-09-23 10:47:35 -0700 | [diff] [blame] | 77 | /* Auth metadata plugin functionality */ |
| 78 | |
murgatroid99 | 8d4aec3 | 2015-09-24 10:54:55 -0700 | [diff] [blame] | 79 | typedef struct plugin_callback_data { |
murgatroid99 | 8d4aec3 | 2015-09-24 10:54:55 -0700 | [diff] [blame] | 80 | const char *service_url; |
| 81 | grpc_credentials_plugin_metadata_cb cb; |
| 82 | void *user_data; |
| 83 | } plugin_callback_data; |
| 84 | |
murgatroid99 | 734c8db | 2016-03-16 11:39:15 -0700 | [diff] [blame] | 85 | typedef struct plugin_state { |
| 86 | Nan::Callback *callback; |
| 87 | std::list<plugin_callback_data*> *pending_callbacks; |
| 88 | uv_mutex_t plugin_mutex; |
| 89 | // async.data == this |
| 90 | uv_async_t plugin_async; |
| 91 | } plugin_state; |
| 92 | |
Julien Boeuf | 35b6b94 | 2015-11-18 22:12:29 -0800 | [diff] [blame] | 93 | void plugin_get_metadata(void *state, grpc_auth_metadata_context context, |
murgatroid99 | 8d4aec3 | 2015-09-24 10:54:55 -0700 | [diff] [blame] | 94 | grpc_credentials_plugin_metadata_cb cb, |
| 95 | void *user_data); |
murgatroid99 | ada3f61 | 2015-09-23 10:47:35 -0700 | [diff] [blame] | 96 | |
| 97 | void plugin_destroy_state(void *state); |
| 98 | |
murgatroid99 | 153b09d | 2015-09-25 16:04:03 -0700 | [diff] [blame] | 99 | NAN_METHOD(PluginCallback); |
murgatroid99 | ada3f61 | 2015-09-23 10:47:35 -0700 | [diff] [blame] | 100 | |
murgatroid99 | 153b09d | 2015-09-25 16:04:03 -0700 | [diff] [blame] | 101 | NAUV_WORK_CB(SendPluginCallback); |
murgatroid99 | 8d4aec3 | 2015-09-24 10:54:55 -0700 | [diff] [blame] | 102 | |
murgatroid99 | e506151 | 2015-01-12 18:14:35 -0800 | [diff] [blame] | 103 | } // namespace node |
murgatroid99 | 5f709ca | 2015-09-30 14:22:54 -0700 | [diff] [blame] | 104 | } // namepsace grpc |
murgatroid99 | e506151 | 2015-01-12 18:14:35 -0800 | [diff] [blame] | 105 | |
murgatroid99 | 5f709ca | 2015-09-30 14:22:54 -0700 | [diff] [blame] | 106 | #endif // GRPC_NODE_CALL_CREDENTIALS_H_ |