mongo_kerberos 1.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +1 -0
- data/LICENSE +190 -0
- data/VERSION +1 -0
- data/ext/csasl/csasl.c +167 -0
- data/ext/csasl/extconf.rb +8 -0
- data/lib/mongo_kerberos/sasl_c.rb +42 -0
- data/lib/mongo_kerberos/sasl_java.rb +51 -0
- data/lib/mongo_kerberos.rb +41 -0
- data/mongo_kerberos.gemspec +35 -0
- data.tar.gz.sig +2 -0
- metadata +91 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 79c23c7614d09732f00db6103ec0877455d66743
|
4
|
+
data.tar.gz: 9883f5c92b47fc02914d48e10a3d2f9d3cb6ae67
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4031614bbd5767a7833001be86d24b55f88a5d7834e065d811f7d86b2185472fca192580fdd07311ad4fb6f5f62f489f62a006ff526977e8a3de06ce3d18b13d
|
7
|
+
data.tar.gz: f0985c8618636de1c5877fa5948672630c85b578fe44cf064794f67688155e2313e2d5fb04b8ad5137121bb6c674d5faab94c31595d069d211901b768aa873c5
|
checksums.yaml.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pG��@|��߲vz�'�f����Q�w� ���y��hYp��*�ABM�Ё+ҿ,:�w�Қ�� ŕ�rn(F�v����H��� -`��F|Gj`�-2
|
data/LICENSE
ADDED
@@ -0,0 +1,190 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
Copyright (C) 2008-2013 MongoDB, Inc.
|
179
|
+
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
181
|
+
you may not use this file except in compliance with the License.
|
182
|
+
You may obtain a copy of the License at
|
183
|
+
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
185
|
+
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
189
|
+
See the License for the specific language governing permissions and
|
190
|
+
limitations under the License.
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.11.1
|
data/ext/csasl/csasl.c
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
// Copyright (C) 2014 MongoDB, Inc.
|
2
|
+
//
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
// you may not use this file except in compliance with the License.
|
5
|
+
// You may obtain a copy of the License at
|
6
|
+
//
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
//
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
// See the License for the specific language governing permissions and
|
13
|
+
// limitations under the License.
|
14
|
+
|
15
|
+
#include <ruby.h>
|
16
|
+
#include <sasl/sasl.h>
|
17
|
+
#include <sasl/saslutil.h>
|
18
|
+
|
19
|
+
static void mongo_sasl_conn_free(void* data) {
|
20
|
+
sasl_conn_t *conn = (sasl_conn_t*) data;
|
21
|
+
// Ideally we would use sasl_client_done() but that's only available as of cyrus sasl 2.1.25
|
22
|
+
if(conn) sasl_done();
|
23
|
+
}
|
24
|
+
|
25
|
+
static sasl_conn_t* mongo_sasl_context(VALUE self) {
|
26
|
+
sasl_conn_t* conn;
|
27
|
+
VALUE context;
|
28
|
+
context = rb_iv_get(self, "@context");
|
29
|
+
Data_Get_Struct(context, sasl_conn_t, conn);
|
30
|
+
return conn;
|
31
|
+
}
|
32
|
+
|
33
|
+
static VALUE a_init(VALUE self, VALUE user_name, VALUE host_name, VALUE service_name, VALUE canonicalize_host_name)
|
34
|
+
{
|
35
|
+
if (sasl_client_init(NULL) == SASL_OK) {
|
36
|
+
rb_iv_set(self, "@valid", Qtrue);
|
37
|
+
rb_iv_set(self, "@user_name", user_name);
|
38
|
+
rb_iv_set(self, "@host_name", host_name);
|
39
|
+
rb_iv_set(self, "@service_name", service_name);
|
40
|
+
rb_iv_set(self, "@canonicalize_host_name", canonicalize_host_name);
|
41
|
+
}
|
42
|
+
|
43
|
+
else {
|
44
|
+
rb_iv_set(self, "@valid", Qfalse);
|
45
|
+
}
|
46
|
+
|
47
|
+
return self;
|
48
|
+
}
|
49
|
+
|
50
|
+
static VALUE valid(VALUE self) {
|
51
|
+
return rb_iv_get(self, "@valid");
|
52
|
+
}
|
53
|
+
|
54
|
+
int is_sasl_failure(int result)
|
55
|
+
{
|
56
|
+
if (result < 0) {
|
57
|
+
return 1;
|
58
|
+
}
|
59
|
+
|
60
|
+
return 0;
|
61
|
+
}
|
62
|
+
|
63
|
+
static int sasl_interact(VALUE self, int id, const char **result, unsigned *len) {
|
64
|
+
switch (id) {
|
65
|
+
case SASL_CB_AUTHNAME:
|
66
|
+
case SASL_CB_USER:
|
67
|
+
{
|
68
|
+
VALUE user_name;
|
69
|
+
user_name = rb_iv_get(self, "@user_name");
|
70
|
+
*result = RSTRING_PTR(user_name);
|
71
|
+
if (len) {
|
72
|
+
*len = RSTRING_LEN(user_name);
|
73
|
+
}
|
74
|
+
return SASL_OK;
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
return SASL_FAIL;
|
79
|
+
}
|
80
|
+
|
81
|
+
static VALUE initialize_challenge(VALUE self) {
|
82
|
+
int result;
|
83
|
+
char encoded_payload[4096];
|
84
|
+
const char *raw_payload;
|
85
|
+
unsigned int raw_payload_len, encoded_payload_len;
|
86
|
+
const char *mechanism_list = "GSSAPI";
|
87
|
+
const char *mechanism_selected = "GSSAPI";
|
88
|
+
VALUE context;
|
89
|
+
sasl_conn_t *conn;
|
90
|
+
sasl_callback_t client_interact [] = {
|
91
|
+
{ SASL_CB_AUTHNAME, (int (*)(void))sasl_interact, (void*)self },
|
92
|
+
{ SASL_CB_USER, (int (*)(void))sasl_interact, (void*)self },
|
93
|
+
{ SASL_CB_LIST_END, NULL, NULL }
|
94
|
+
};
|
95
|
+
|
96
|
+
const char *servicename = RSTRING_PTR(rb_iv_get(self, "@service_name"));
|
97
|
+
const char *hostname = RSTRING_PTR(rb_iv_get(self, "@host_name"));
|
98
|
+
|
99
|
+
result = sasl_client_new(servicename, hostname, NULL, NULL, client_interact, 0, &conn);
|
100
|
+
|
101
|
+
if (result != SASL_OK) {
|
102
|
+
sasl_dispose(&conn);
|
103
|
+
return Qfalse;
|
104
|
+
}
|
105
|
+
|
106
|
+
context = Data_Wrap_Struct(rb_cObject, NULL, mongo_sasl_conn_free, conn);
|
107
|
+
rb_iv_set(self, "@context", context);
|
108
|
+
|
109
|
+
result = sasl_client_start(conn, mechanism_list, NULL, &raw_payload, &raw_payload_len, &mechanism_selected);
|
110
|
+
if (is_sasl_failure(result)) {
|
111
|
+
return Qfalse;
|
112
|
+
}
|
113
|
+
|
114
|
+
if (result != SASL_CONTINUE) {
|
115
|
+
return Qfalse;
|
116
|
+
}
|
117
|
+
|
118
|
+
result = sasl_encode64(raw_payload, raw_payload_len, encoded_payload, sizeof(encoded_payload), &encoded_payload_len);
|
119
|
+
if (is_sasl_failure(result)) {
|
120
|
+
return Qfalse;
|
121
|
+
}
|
122
|
+
|
123
|
+
encoded_payload[encoded_payload_len] = 0;
|
124
|
+
return rb_str_new(encoded_payload, encoded_payload_len);
|
125
|
+
}
|
126
|
+
|
127
|
+
static VALUE evaluate_challenge(VALUE self, VALUE rb_payload) {
|
128
|
+
char base_payload[4096], payload[4096];
|
129
|
+
const char *step_payload, *out;
|
130
|
+
unsigned int step_payload_len, payload_len, base_payload_len, outlen;
|
131
|
+
int result;
|
132
|
+
sasl_conn_t *conn = mongo_sasl_context(self);
|
133
|
+
|
134
|
+
StringValue(rb_payload);
|
135
|
+
step_payload = RSTRING_PTR(rb_payload);
|
136
|
+
step_payload_len = RSTRING_LEN(rb_payload);
|
137
|
+
|
138
|
+
result = sasl_decode64(step_payload, step_payload_len, base_payload, sizeof(base_payload), &base_payload_len);
|
139
|
+
if (is_sasl_failure(result)) {
|
140
|
+
return Qfalse;
|
141
|
+
}
|
142
|
+
|
143
|
+
result = sasl_client_step(conn, base_payload, base_payload_len, NULL, &out, &outlen);
|
144
|
+
if (is_sasl_failure(result)) {
|
145
|
+
return Qfalse;
|
146
|
+
}
|
147
|
+
|
148
|
+
result = sasl_encode64(out, outlen, payload, sizeof(payload), &payload_len);
|
149
|
+
if (is_sasl_failure(result)) {
|
150
|
+
return Qfalse;
|
151
|
+
}
|
152
|
+
|
153
|
+
return rb_str_new(payload, payload_len);
|
154
|
+
}
|
155
|
+
|
156
|
+
VALUE c_GSSAPI_authenticator;
|
157
|
+
|
158
|
+
void Init_csasl() {
|
159
|
+
VALUE mongo, sasl;
|
160
|
+
mongo = rb_const_get(rb_cObject, rb_intern("Mongo"));
|
161
|
+
sasl = rb_const_get(mongo, rb_intern("Sasl"));
|
162
|
+
c_GSSAPI_authenticator = rb_define_class_under(sasl, "GSSAPIAuthenticator", rb_cObject);
|
163
|
+
rb_define_method(c_GSSAPI_authenticator, "initialize", a_init, 4);
|
164
|
+
rb_define_method(c_GSSAPI_authenticator, "initialize_challenge", initialize_challenge, 0);
|
165
|
+
rb_define_method(c_GSSAPI_authenticator, "evaluate_challenge", evaluate_challenge, 1);
|
166
|
+
rb_define_method(rb_cObject, "valid?", valid, 0);
|
167
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Copyright (C) 2009-2014 MongoDB, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module Mongo
|
16
|
+
module Sasl
|
17
|
+
module GSSAPI
|
18
|
+
|
19
|
+
def self.authenticate(username, client, socket, opts={})
|
20
|
+
db = client.db('$external')
|
21
|
+
hostname = socket.pool.host
|
22
|
+
servicename = opts[:gssapi_service_name] || 'mongodb'
|
23
|
+
canonicalize = opts[:canonicalize_host_name] ? opts[:canonicalize_host_name] : false
|
24
|
+
authenticator = Mongo::Sasl::GSSAPIAuthenticator.new(username, hostname, servicename, canonicalize)
|
25
|
+
|
26
|
+
return { } unless authenticator.valid?
|
27
|
+
|
28
|
+
token = authenticator.initialize_challenge
|
29
|
+
cmd = BSON::OrderedHash['saslStart', 1, 'mechanism', 'GSSAPI', 'payload', token, 'autoAuthorize', 1]
|
30
|
+
response = db.command(cmd, :check_response => false, :socket => socket)
|
31
|
+
|
32
|
+
until response['done'] do
|
33
|
+
break unless Support.ok?(response)
|
34
|
+
token = authenticator.evaluate_challenge(response['payload'])
|
35
|
+
cmd = BSON::OrderedHash['saslContinue', 1, 'conversationId', response['conversationId'], 'payload', token]
|
36
|
+
response = db.command(cmd, :check_response => false, :socket => socket)
|
37
|
+
end
|
38
|
+
response
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Copyright (C) 2009-2014 MongoDB, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'jruby'
|
16
|
+
|
17
|
+
include Java
|
18
|
+
|
19
|
+
jar_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../ext/jsasl'))
|
20
|
+
require File.join(jar_dir, 'target/jsasl.jar')
|
21
|
+
|
22
|
+
module Mongo
|
23
|
+
module Sasl
|
24
|
+
module GSSAPI
|
25
|
+
|
26
|
+
def self.authenticate(username, client, socket, opts={})
|
27
|
+
db = client.db('$external')
|
28
|
+
hostname = socket.pool.host
|
29
|
+
servicename = opts[:gssapi_service_name] || 'mongodb'
|
30
|
+
canonicalize = opts[:canonicalize_host_name] ? opts[:canonicalize_host_name] : false
|
31
|
+
|
32
|
+
begin
|
33
|
+
authenticator = org.mongodb.sasl.GSSAPIAuthenticator.new(JRuby.runtime, username, hostname, servicename, canonicalize)
|
34
|
+
token = BSON::Binary.new(authenticator.initialize_challenge)
|
35
|
+
cmd = BSON::OrderedHash['saslStart', 1, 'mechanism', 'GSSAPI', 'payload', token, 'autoAuthorize', 1]
|
36
|
+
response = db.command(cmd, :check_response => false, :socket => socket)
|
37
|
+
|
38
|
+
until response['done'] do
|
39
|
+
break unless Support.ok?(response)
|
40
|
+
token = BSON::Binary.new(authenticator.evaluate_challenge(response['payload'].to_s))
|
41
|
+
cmd = BSON::OrderedHash['saslContinue', 1, 'conversationId', response['conversationId'], 'payload', token]
|
42
|
+
response = db.command(cmd, :check_response => false, :socket => socket)
|
43
|
+
end
|
44
|
+
response
|
45
|
+
rescue Java::OrgMongodbSasl::MongoSecurityException
|
46
|
+
return { }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Copyright (C) 2014 MongoDB, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'mongo'
|
16
|
+
|
17
|
+
begin
|
18
|
+
if RUBY_PLATFORM =~ /java/
|
19
|
+
require 'mongo_kerberos/sasl_java'
|
20
|
+
else
|
21
|
+
require 'mongo_kerberos/sasl_c'
|
22
|
+
require "csasl/csasl"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module Mongo
|
27
|
+
module Authentication
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
# Handles issuing authentication commands for the GSSAPI auth mechanism.
|
32
|
+
#
|
33
|
+
# @param auth [Hash] The authentication credentials to be used.
|
34
|
+
# @param opts [Hash] Hash of optional settings and configuration values.
|
35
|
+
#
|
36
|
+
# @private
|
37
|
+
def issue_gssapi(auth, opts={})
|
38
|
+
Mongo::Sasl::GSSAPI.authenticate(auth[:username], self, opts[:socket], auth[:extra] || {})
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'mongo_kerberos'
|
3
|
+
s.version = File.read(File.join(File.dirname(__FILE__), 'VERSION'))
|
4
|
+
s.platform = Gem::Platform::RUBY
|
5
|
+
s.authors = [ 'Emily Stolfo', 'Durran Jordan' ]
|
6
|
+
s.email = 'mongodb-dev@googlegroups.com'
|
7
|
+
s.homepage = 'http://www.mongodb.org'
|
8
|
+
s.summary = 'Kerberos authentication support for the MongoDB Ruby driver'
|
9
|
+
s.description = 'Adds kerberos authentication via libsasl to the MongoDB Ruby Driver on MRI and JRuby'
|
10
|
+
s.rubyforge_project = 'mongo_kerberos'
|
11
|
+
s.license = 'Apache License Version 2.0'
|
12
|
+
|
13
|
+
if File.exists?('gem-private_key.pem')
|
14
|
+
s.signing_key = 'gem-private_key.pem'
|
15
|
+
s.cert_chain = ['gem-public_cert.pem']
|
16
|
+
else
|
17
|
+
warn 'Warning: No private key present, creating unsigned gem.'
|
18
|
+
end
|
19
|
+
|
20
|
+
s.files = [ 'mongo_kerberos.gemspec', 'LICENSE', 'VERSION' ]
|
21
|
+
s.files += [ 'lib/mongo_kerberos.rb' ]
|
22
|
+
s.files += Dir[ 'lib/mongo_kerberos/**/*.rb' ]
|
23
|
+
|
24
|
+
if RUBY_PLATFORM =~ /java/
|
25
|
+
s.platform = 'java'
|
26
|
+
s.files << 'ext/jsasl/target/jsasl.jar'
|
27
|
+
else
|
28
|
+
s.files += Dir.glob('ext/csasl/**/*.{c,h,rb}')
|
29
|
+
s.extensions = [ 'ext/csasl/extconf.rb' ]
|
30
|
+
end
|
31
|
+
|
32
|
+
s.add_dependency('mongo', "#{s.version}")
|
33
|
+
s.require_paths = ['lib']
|
34
|
+
s.has_rdoc = 'yard'
|
35
|
+
end
|
data.tar.gz.sig
ADDED
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mongo_kerberos
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.11.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Emily Stolfo
|
8
|
+
- Durran Jordan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain:
|
12
|
+
- |
|
13
|
+
-----BEGIN CERTIFICATE-----
|
14
|
+
MIIDfDCCAmSgAwIBAgIBATANBgkqhkiG9w0BAQUFADBCMRQwEgYDVQQDDAtkcml2
|
15
|
+
ZXItcnVieTEVMBMGCgmSJomT8ixkARkWBTEwZ2VuMRMwEQYKCZImiZPyLGQBGRYD
|
16
|
+
Y29tMB4XDTE0MDIxOTE1MTEyNloXDTE1MDIxOTE1MTEyNlowQjEUMBIGA1UEAwwL
|
17
|
+
ZHJpdmVyLXJ1YnkxFTATBgoJkiaJk/IsZAEZFgUxMGdlbjETMBEGCgmSJomT8ixk
|
18
|
+
ARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANFdSAa8fRm1
|
19
|
+
bAM9za6Z0fAH4g02bqM1NGnw8zJQrE/PFrFfY6IFCT2AsLfOwr1maVm7iU1+kdVI
|
20
|
+
IQ+iI/9+E+ArJ+rbGV3dDPQ+SLl3mLT+vXjfjcxMqI2IW6UuVtt2U3Rxd4QU0kdT
|
21
|
+
JxmcPYs5fDN6BgYc6XXgUjy3m+Kwha2pGctdciUOwEfOZ4RmNRlEZKCMLRHdFP8j
|
22
|
+
4WTnJSGfXDiuoXICJb5yOPOZPuaapPSNXp93QkUdsqdKC32I+KMpKKYGBQ6yisfA
|
23
|
+
5MyVPPCzLR1lP5qXVGJPnOqUAkvEUfCahg7EP9tI20qxiXrR6TSEraYhIFXL0EGY
|
24
|
+
u8KAcPHm5KkCAwEAAaN9MHswCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0O
|
25
|
+
BBYEFFt3WbF+9JpUjAoj62cQBgNb8HzXMCAGA1UdEQQZMBeBFWRyaXZlci1ydWJ5
|
26
|
+
QDEwZ2VuLmNvbTAgBgNVHRIEGTAXgRVkcml2ZXItcnVieUAxMGdlbi5jb20wDQYJ
|
27
|
+
KoZIhvcNAQEFBQADggEBALGvdxHF+CnH6QO4PeIce3S8EHuHsYiGLk4sWgNGZkjD
|
28
|
+
V3C4XjlI8rQZxalwQwcauacOGj9x94flWUXruEF7+rjUtig7OIrQK2+uVg86vl8r
|
29
|
+
xy1n2s1d31KsuazEVExe5o19tnVbI9+30P9qPkS+NgaellXpj5c5qnJUGn5BJtzo
|
30
|
+
3D001zXpVnuZvCcE/A4fQ+BEM0zm0oOmA/gWIAFrufOL9oYg1881dRZ+kQytF/9c
|
31
|
+
JrZM8w8wGbIOeLtoQqa7HB/jOYbTahH7KMNh2LHAbOR93hNIJxVRa4iwxiMQ75tN
|
32
|
+
9WUIAJ4AEtjwRg1Bz0OwDo3aucPCBpx77+/FWhv7JYY=
|
33
|
+
-----END CERTIFICATE-----
|
34
|
+
date: 2014-09-15 00:00:00.000000000 Z
|
35
|
+
dependencies:
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: mongo
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - '='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.11.1
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - '='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 1.11.1
|
50
|
+
description: Adds kerberos authentication via libsasl to the MongoDB Ruby Driver on
|
51
|
+
MRI and JRuby
|
52
|
+
email: mongodb-dev@googlegroups.com
|
53
|
+
executables: []
|
54
|
+
extensions:
|
55
|
+
- ext/csasl/extconf.rb
|
56
|
+
extra_rdoc_files: []
|
57
|
+
files:
|
58
|
+
- LICENSE
|
59
|
+
- VERSION
|
60
|
+
- ext/csasl/csasl.c
|
61
|
+
- ext/csasl/extconf.rb
|
62
|
+
- lib/mongo_kerberos.rb
|
63
|
+
- lib/mongo_kerberos/sasl_c.rb
|
64
|
+
- lib/mongo_kerberos/sasl_java.rb
|
65
|
+
- mongo_kerberos.gemspec
|
66
|
+
homepage: http://www.mongodb.org
|
67
|
+
licenses:
|
68
|
+
- Apache License Version 2.0
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project: mongo_kerberos
|
86
|
+
rubygems_version: 2.2.2
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: Kerberos authentication support for the MongoDB Ruby driver
|
90
|
+
test_files: []
|
91
|
+
has_rdoc: yard
|
metadata.gz.sig
ADDED
Binary file
|