@@ -8,15 +8,30 @@ from gssapi.raw.sec_contexts cimport SecurityContext
8
8
9
9
from gssapi.raw.misc import GSSError
10
10
from gssapi.raw import types as gssapi_types
11
- from gssapi.raw.named_tuples import IOVUnwrapResult, WrapResult, UnwrapResult
11
+ from gssapi.raw.named_tuples import IOVUnwrapResult
12
12
from collections import namedtuple
13
13
from collections.abc import Sequence
14
14
15
15
from enum import IntEnum
16
16
from gssapi.raw._enum_extensions import ExtendableEnum
17
17
18
+ # Kept for backwards compatibility - functions used to be declared here
19
+ try :
20
+ from gssapi.raw.ext_dce_aead import wrap_aead, unwrap_aead
21
+ except ImportError :
22
+ pass
23
+
18
24
19
25
cdef extern from " python_gssapi_ext.h" :
26
+ """
27
+ #ifdef OSX_HAS_GSS_FRAMEWORK
28
+ #define gss_wrap_iov __ApplePrivate_gss_wrap_iov
29
+ #define gss_unwrap_iov __ApplePrivate_gss_unwrap_iov
30
+ #define gss_wrap_iov_length __ApplePrivate_gss_wrap_iov_length
31
+ #define gss_release_iov_buffer __ApplePrivate_gss_release_iov_buffer
32
+ #endif
33
+ """
34
+
20
35
# NB(directxman12): this wiki page has a different argument order
21
36
# than the header file, and uses size_t instead of int
22
37
# (this file matches the header file)
@@ -37,18 +52,6 @@ cdef extern from "python_gssapi_ext.h":
37
52
gss_iov_buffer_desc * iov,
38
53
int iov_count) nogil
39
54
40
- OM_uint32 gss_wrap_aead(OM_uint32 * min_stat, gss_ctx_id_t ctx_handle,
41
- int conf_req, gss_qop_t qop_req,
42
- gss_buffer_t input_assoc_buffer,
43
- gss_buffer_t input_payload_buffer, int * conf_ret,
44
- gss_buffer_t output_message_buffer) nogil
45
-
46
- OM_uint32 gss_unwrap_aead(OM_uint32 * min_stat, gss_ctx_id_t ctx_handle,
47
- gss_buffer_t input_message_buffer,
48
- gss_buffer_t input_assoc_buffer,
49
- gss_buffer_t output_payload_buffer,
50
- int * conf_ret, gss_qop_t * qop_ret) nogil
51
-
52
55
gss_iov_buffer_t GSS_C_NO_IOV_BUFFER
53
56
54
57
OM_uint32 GSS_IOV_BUFFER_TYPE_EMPTY
@@ -447,109 +450,3 @@ def wrap_iov_length(SecurityContext context not None, IOV message not None,
447
450
return < bint> conf_used
448
451
else :
449
452
raise GSSError(maj_stat, min_stat)
450
-
451
-
452
- def wrap_aead (SecurityContext context not None , bytes message not None ,
453
- bytes associated = None , confidential = True , qop = None ):
454
- """
455
- wrap_aead(context, message, associated=None, confidential=True, qop=None)
456
- Wrap/Encrypt an AEAD message.
457
-
458
- This method takes an input message and associated data,
459
- and outputs and AEAD message.
460
-
461
- Args:
462
- context (SecurityContext): the current security context
463
- message (bytes): the message to wrap or encrypt
464
- associated (bytes): associated data to go with the message
465
- confidential (bool): whether or not to encrypt the message (True),
466
- or just wrap it with a MIC (False)
467
- qop (int): the desired Quality of Protection
468
- (or None for the default QoP)
469
-
470
- Returns:
471
- WrapResult: the wrapped/encrypted total message, and whether or not
472
- encryption was actually used
473
-
474
- Raises:
475
- GSSError
476
- """
477
-
478
- cdef int conf_req = confidential
479
- cdef gss_qop_t qop_req = qop if qop is not None else GSS_C_QOP_DEFAULT
480
- cdef gss_buffer_desc message_buffer = gss_buffer_desc(len (message),
481
- message)
482
-
483
- cdef gss_buffer_t assoc_buffer_ptr = GSS_C_NO_BUFFER
484
- cdef gss_buffer_desc assoc_buffer
485
- if associated is not None :
486
- assoc_buffer = gss_buffer_desc(len (associated), associated)
487
- assoc_buffer_ptr = & assoc_buffer
488
-
489
- cdef int conf_used
490
- # GSS_C_EMPTY_BUFFER
491
- cdef gss_buffer_desc output_buffer = gss_buffer_desc(0 , NULL )
492
-
493
- cdef OM_uint32 maj_stat, min_stat
494
-
495
- with nogil:
496
- maj_stat = gss_wrap_aead(& min_stat, context.raw_ctx, conf_req, qop_req,
497
- assoc_buffer_ptr, & message_buffer,
498
- & conf_used, & output_buffer)
499
-
500
- if maj_stat == GSS_S_COMPLETE:
501
- output_message = (< char * > output_buffer.value)[:output_buffer.length]
502
- gss_release_buffer(& min_stat, & output_buffer)
503
- return WrapResult(output_message, < bint> conf_used)
504
- else :
505
- raise GSSError(maj_stat, min_stat)
506
-
507
-
508
- def unwrap_aead (SecurityContext context not None , bytes message not None ,
509
- bytes associated = None ):
510
- """
511
- unwrap_aead(context, message, associated=None)
512
- Unwrap/Decrypt an AEAD message.
513
-
514
- This method takes an encrpyted/wrapped AEAD message and some associated
515
- data, and returns an unwrapped/decrypted message.
516
-
517
- Args:
518
- context (SecurityContext): the current security context
519
- message (bytes): the AEAD message to unwrap or decrypt
520
- associated (bytes): associated data that goes with the message
521
-
522
- Returns:
523
- UnwrapResult: the unwrapped/decrypted message, whether or on
524
- encryption was used, and the QoP used
525
-
526
- Raises:
527
- GSSError
528
- """
529
-
530
- cdef gss_buffer_desc input_buffer = gss_buffer_desc(len (message), message)
531
-
532
- cdef gss_buffer_t assoc_buffer_ptr = GSS_C_NO_BUFFER
533
- cdef gss_buffer_desc assoc_buffer
534
- if associated is not None :
535
- assoc_buffer = gss_buffer_desc(len (associated), associated)
536
- assoc_buffer_ptr = & assoc_buffer
537
-
538
- # GSS_C_EMPTY_BUFFER
539
- cdef gss_buffer_desc output_buffer = gss_buffer_desc(0 , NULL )
540
- cdef int conf_state
541
- cdef gss_qop_t qop_state
542
-
543
- cdef OM_uint32 maj_stat, min_stat
544
-
545
- with nogil:
546
- maj_stat = gss_unwrap_aead(& min_stat, context.raw_ctx, & input_buffer,
547
- assoc_buffer_ptr, & output_buffer,
548
- & conf_state, & qop_state)
549
-
550
- if maj_stat == GSS_S_COMPLETE:
551
- output_message = (< char * > output_buffer.value)[:output_buffer.length]
552
- gss_release_buffer(& min_stat, & output_buffer)
553
- return UnwrapResult(output_message, < bint> conf_state, qop_state)
554
- else :
555
- raise GSSError(maj_stat, min_stat)
0 commit comments