@@ -9,6 +9,9 @@ required by the SMB protocol for signing and encrypting a message.
99
1010Draft IETF document for these extensions can be found at
1111https://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
1215"""
1316GSSAPI= " BASE" # This ensures that a full module is generated by Cython
1417
@@ -32,6 +35,17 @@ cdef extern from "python_gssapi_ext.h":
3235 const gss_OID desired_object,
3336 gss_buffer_set_t * data_set) nogil
3437
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+
3549
3650def inquire_cred_by_oid (Creds cred_handle not None ,
3751 OID desired_aspect not None ):
@@ -93,7 +107,7 @@ def inquire_sec_context_by_oid(SecurityContext context not None,
93107
94108 Args:
95109 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
97111 inquire about.
98112
99113 Returns:
@@ -127,3 +141,112 @@ def inquire_sec_context_by_oid(SecurityContext context not None,
127141 return py_tokens
128142 else :
129143 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+ cdef OM_uint32 maj_stat, min_stat
186+
187+ with nogil:
188+ maj_stat = gss_set_cred_option(& min_stat,
189+ & output_creds.raw_creds,
190+ & desired_aspect.raw_oid,
191+ & value_buffer)
192+
193+ if maj_stat == GSS_S_COMPLETE:
194+ return output_creds
195+ else :
196+ raise GSSError(maj_stat, min_stat)
197+
198+
199+ def set_sec_context_option (OID desired_aspect not None ,
200+ SecurityContext context = None ,
201+ value = None ):
202+ """
203+ set_sec_context_option(desired_aspect, context=None, value=None)
204+
205+ This method is used to set a value for a specific OID of a
206+ :class:`SecurityContext` object. The OID and value to pass in depends on
207+ the mech the SecurityContext backs.
208+
209+ An example of how this can be used would be to reset the NTLM crypto engine
210+ used in gss-ntlmssp. The OID that controls this value is
211+ '1.3.6.1.4.1.7165.655.1.3' and it takes it a byte value that represents
212+ an int32 where 1 reset's the verifier handle and any other int resets the
213+ sender handle.
214+
215+ Args:
216+ desired_aspect (OID): the desired aspect of the Security Context to set
217+ the value for.
218+ context (SecurityContext): the Security Context to set, or None to
219+ create a new context.
220+ value (bytes): the value to set on the desired aspect of the Security
221+ Context or None to send GSS_C_EMPTY_BUFFER.
222+
223+ Returns:
224+ SecurityContext: The output security context.
225+
226+ Raises:
227+ GSS_ERROR
228+ """
229+
230+ cdef gss_buffer_desc value_buffer
231+ if value is not None :
232+ value_buffer = gss_buffer_desc(len (value), value)
233+ else :
234+ # GSS_C_EMPTY_BUFFER
235+ value_buffer = gss_buffer_desc(0 , NULL )
236+
237+ cdef SecurityContext output_context = context
238+ if output_context is None :
239+ output_context = SecurityContext()
240+
241+ cdef OM_uint32 maj_stat, min_stat
242+
243+ with nogil:
244+ maj_stat = gss_set_sec_context_option(& min_stat,
245+ & output_context.raw_ctx,
246+ & desired_aspect.raw_oid,
247+ & value_buffer)
248+
249+ if maj_stat == GSS_S_COMPLETE:
250+ return output_context
251+ else :
252+ raise GSSError(maj_stat, min_stat)
0 commit comments