Skip to content
This repository was archived by the owner on Feb 24, 2024. It is now read-only.

Commit 78f1420

Browse files
committed
Add MIC Sign/Verify operations
1 parent 430a12b commit 78f1420

File tree

4 files changed

+291
-57
lines changed

4 files changed

+291
-57
lines changed

pysrc/kerberos.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def getServerPrincipalDetails(service, hostname):
137137
GSS_C_PROT_READY_FLAG = 128
138138
GSS_C_TRANS_FLAG = 256
139139

140+
GSS_EXT_HAVE_PASSWORD = True
140141

141142

142143
def authGSSClientInit(service, **kwargs):
@@ -181,6 +182,29 @@ def authGSSClientClean(context):
181182
"""
182183

183184

185+
def authGSSSign(context, message, qop=0):
186+
"""
187+
Creates MIC (signature) of the message
188+
189+
@param context: The context object returned from L{authGSSClientInit}.
190+
191+
@param message: The text message (base64 encoded)
192+
193+
@return: The MIC of the message (base64 encoded).
194+
"""
195+
196+
197+
def authGSSVerify(context, message, token, qop=0):
198+
"""
199+
Verify MIC (signature) of the message
200+
201+
@param context: The context object returned from L{authGSSClientInit}.
202+
203+
@param message: The text message (base64 encoded)
204+
205+
@param token: The MIC of the message (base64 encoded).
206+
"""
207+
184208

185209
def authGSSClientInquireCred(context):
186210
"""

src/kerberos.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,76 @@ static PyObject *channelBindings(PyObject *self, PyObject *args, PyObject* keywd
275275
return Py_BuildValue("N", pychan_bindings);
276276
}
277277

278+
static PyObject *authGSSSign(PyObject *self, PyObject *args, PyObject* keywds)
279+
{
280+
gss_client_state *state = NULL;
281+
PyObject *pystate = NULL;
282+
PyObject *pytoken = NULL;
283+
char *message = NULL;
284+
char *token = NULL;
285+
static char *kwlist[] = {"context", "message", "qop", NULL};
286+
int result = 0;
287+
unsigned int qop = 0;
288+
289+
if (! PyArg_ParseTupleAndKeywords(args, keywds, "Os|I", kwlist, &pystate, &message, &qop)) {
290+
return NULL;
291+
}
292+
293+
if (! PyCObject_Check(pystate)) {
294+
PyErr_SetString(PyExc_TypeError, "Expected a context object");
295+
return NULL;
296+
}
297+
298+
state = (gss_client_state *)PyCObject_AsVoidPtr(pystate);
299+
300+
if (state == NULL) {
301+
return NULL;
302+
}
303+
304+
result = authenticate_gss_sign(state, message, qop, &token);
305+
if (result == AUTH_GSS_ERROR) {
306+
return NULL;
307+
}
308+
309+
pytoken = PyString_FromString(token);
310+
free(token);
311+
312+
return pytoken;
313+
}
314+
315+
static PyObject *authGSSVerify(PyObject *self, PyObject *args, PyObject* keywds)
316+
{
317+
gss_client_state *state = NULL;
318+
PyObject *pystate = NULL;
319+
char *message = NULL;
320+
char *token = NULL;
321+
static char *kwlist[] = {"context", "message", "token", "qop", NULL};
322+
int result = 0;
323+
unsigned int qop = 0;
324+
325+
if (! PyArg_ParseTupleAndKeywords(args, keywds, "Oss|I", kwlist, &pystate, &message, &token, &qop)) {
326+
return NULL;
327+
}
328+
329+
if (! PyCObject_Check(pystate)) {
330+
PyErr_SetString(PyExc_TypeError, "Expected a context object");
331+
return NULL;
332+
}
333+
334+
state = (gss_client_state *)PyCObject_AsVoidPtr(pystate);
335+
336+
if (state == NULL) {
337+
return NULL;
338+
}
339+
340+
result = authenticate_gss_verify(state, message, token, qop);
341+
if (result == AUTH_GSS_ERROR) {
342+
return NULL;
343+
}
344+
345+
return Py_BuildValue("i", result);
346+
}
347+
278348
static PyObject *authGSSClientStep(PyObject *self, PyObject *args, PyObject* keywds)
279349
{
280350
gss_client_state *state = NULL;
@@ -725,6 +795,16 @@ static PyMethodDef KerberosMethods[] = {
725795
getServerPrincipalDetails, METH_VARARGS,
726796
"Return the service principal for a given service and hostname."
727797
},
798+
{
799+
"authGSSSign",
800+
(PyCFunction)authGSSSign, METH_VARARGS | METH_KEYWORDS,
801+
"Compute MIC of the message",
802+
},
803+
{
804+
"authGSSVerify",
805+
(PyCFunction)authGSSVerify, METH_VARARGS | METH_KEYWORDS,
806+
"Verify MIC of the message",
807+
},
728808
{
729809
"authGSSClientInit",
730810
(PyCFunction)authGSSClientInit, METH_VARARGS | METH_KEYWORDS,

0 commit comments

Comments
 (0)