@@ -9,6 +9,9 @@ required by the SMB protocol for signing and encrypting a message.
9
9
10
10
Draft IETF document for these extensions can be found at
11
11
https://tools.ietf.org/html/draft-engert-ggf-gss-extensions-00
12
+
13
+ Draft IETF document for the gss_set_cred_option can be found at
14
+ https://tools.ietf.org/html/draft-williams-kitten-channel-bound-flag-00
12
15
"""
13
16
GSSAPI= " BASE" # This ensures that a full module is generated by Cython
14
17
@@ -32,6 +35,17 @@ cdef extern from "python_gssapi_ext.h":
32
35
const gss_OID desired_object,
33
36
gss_buffer_set_t * data_set) nogil
34
37
38
+ # not in GGF draft but usually lumped together with the others
39
+ OM_uint32 gss_set_cred_option(OM_uint32 * minor_status,
40
+ gss_cred_id_t * cred,
41
+ const gss_OID desired_object,
42
+ const gss_buffer_t value) nogil
43
+
44
+ OM_uint32 gss_set_sec_context_option(OM_uint32 * minor_status,
45
+ gss_ctx_id_t * context_handle,
46
+ const gss_OID desired_object,
47
+ const gss_buffer_t value) nogil
48
+
35
49
36
50
def inquire_cred_by_oid (Creds cred_handle not None ,
37
51
OID desired_aspect not None ):
@@ -93,7 +107,7 @@ def inquire_sec_context_by_oid(SecurityContext context not None,
93
107
94
108
Args:
95
109
context (SecurityContext): the Security Context to query
96
- desired_aspect (OID): the desired aspected of the Security Context to
110
+ desired_aspect (OID): the desired aspect of the Security Context to
97
111
inquire about.
98
112
99
113
Returns:
@@ -127,3 +141,113 @@ def inquire_sec_context_by_oid(SecurityContext context not None,
127
141
return py_tokens
128
142
else :
129
143
raise GSSError(maj_stat, min_stat)
144
+
145
+
146
+ def set_cred_option (OID desired_aspect not None , Creds creds = None , value = None ):
147
+ """
148
+ set_cred_option(desired_aspect, creds=None, value=None)
149
+
150
+ This method is used to set options of a :class:`Creds` object based on
151
+ an OID key. The options that can be set depends on the mech the credentials
152
+ were created with.
153
+
154
+ An example of how this can be used would be to set the
155
+ GSS_KRB5_CRED_NO_CI_FLAGS_X on a Kerberos credential. The OID string for
156
+ this flag is '1.2.752.43.13.29' and it requires no value to be set. This
157
+ must be set before the SecurityContext was initialised with the
158
+ credentials.
159
+
160
+ Args:
161
+ desired_aspect (OID): the desired aspect of the Credential to set.
162
+ cred_handle (Creds): the Credentials to set, or None to create a new
163
+ credential.
164
+ value (bytes): the value to set on the desired aspect of the Credential
165
+ or None to send GSS_C_EMPTY_BUFFER.
166
+
167
+ Returns:
168
+ Creds: The output credential.
169
+
170
+ Raises:
171
+ GSS_ERROR
172
+ """
173
+
174
+ cdef gss_buffer_desc value_buffer
175
+ if value is not None :
176
+ value_buffer = gss_buffer_desc(len (value), value)
177
+ else :
178
+ # GSS_C_EMPTY_BUFFER
179
+ value_buffer = gss_buffer_desc(0 , NULL )
180
+
181
+ cdef Creds output_creds = creds
182
+ if output_creds is None :
183
+ output_creds = Creds()
184
+
185
+
186
+ cdef OM_uint32 maj_stat, min_stat
187
+
188
+ with nogil:
189
+ maj_stat = gss_set_cred_option(& min_stat,
190
+ & output_creds.raw_creds,
191
+ & desired_aspect.raw_oid,
192
+ & value_buffer)
193
+
194
+ if maj_stat == GSS_S_COMPLETE:
195
+ return output_creds
196
+ else :
197
+ raise GSSError(maj_stat, min_stat)
198
+
199
+
200
+ def set_sec_context_option (OID desired_aspect not None ,
201
+ SecurityContext context = None ,
202
+ value = None ):
203
+ """
204
+ set_sec_context_option(desired_aspect, context=None, value=None)
205
+
206
+ This method is used to set a value for a specific OID of a
207
+ :class:`SecurityContext` object. The OID and value to pass in depends on
208
+ the mech the SecurityContext backs.
209
+
210
+ An example of how this can be used would be to reset the NTLM crypto engine
211
+ used in gss-ntlmssp. The OID that controls this value is
212
+ '1.3.6.1.4.1.7165.655.1.3' and it takes it a byte value that represents
213
+ an int32 where 1 reset's the verifier handle and any other int resets the
214
+ sender handle.
215
+
216
+ Args:
217
+ desired_aspect (OID): the desired aspect of the Security Context to set
218
+ the value for.
219
+ context (SecurityContext): the Security Context to set, or None to
220
+ create a new context.
221
+ value (bytes): the value to set on the desired aspect of the Security
222
+ Context or None to send GSS_C_EMPTY_BUFFER.
223
+
224
+ Returns:
225
+ SecurityContext: The output security context.
226
+
227
+ Raises:
228
+ GSS_ERROR
229
+ """
230
+
231
+ cdef gss_buffer_desc value_buffer
232
+ if value is not None :
233
+ value_buffer = gss_buffer_desc(len (value), value)
234
+ else :
235
+ # GSS_C_EMPTY_BUFFER
236
+ value_buffer = gss_buffer_desc(0 , NULL )
237
+
238
+ cdef SecurityContext output_context = context
239
+ if output_context is None :
240
+ output_context = SecurityContext()
241
+
242
+ cdef OM_uint32 maj_stat, min_stat
243
+
244
+ with nogil:
245
+ maj_stat = gss_set_sec_context_option(& min_stat,
246
+ & output_context.raw_ctx,
247
+ & desired_aspect.raw_oid,
248
+ & value_buffer)
249
+
250
+ if maj_stat == GSS_S_COMPLETE:
251
+ return output_context
252
+ else :
253
+ raise GSSError(maj_stat, min_stat)
0 commit comments