-
Notifications
You must be signed in to change notification settings - Fork 0
/
gss.el
92 lines (79 loc) · 3.27 KB
/
gss.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
;;; -*- lexical-binding: t -*-
(require 'cl)
(require 'eieio)
(require 'emacs-gssapi)
(defclass gss-name ()
((ptr :initarg :ptr
:reader gss-name/ptr)))
(defclass gss-context ()
((ptr :initarg :ptr
:reader gss-context/ptr)))
(defun gss--make-string-from-result (content)
(if content
(with-temp-buffer
(loop for ch across content
do (insert ch))
(buffer-string))
nil))
(cl-defun gss-make-name (name &key (type :hostbased-service))
(check-type name string)
(check-type type (member :user-name :machine-uid-name :string-uid-name :hostbased-service))
(make-instance 'gss-name :ptr (gss--internal-import-name name type)))
(defun gss--token-to-vector (string)
(let ((vector (make-vector (length string) 0)))
(loop for ch across string
for i from 0
do (setf (aref vector i) ch))
vector))
(defun gss-name-to-string (name)
(check-type name gss-name)
(gss--internal-name-to-string (gss-name/ptr name)))
(cl-defun gss-init-sec-context (name &key flags (time-req 0) context input-token)
(check-type name (or string gss-name))
(check-type flags list)
(check-type time-req integer)
(check-type context (or null gss-context))
(check-type input-token (or null string))
(let ((name-native (etypecase name
(string (gss-make-name name))
(gss-name name))))
(destructuring-bind (continue-needed context content flags)
(gss--internal-init-sec-context (gss-name/ptr name-native)
flags
(if context (gss-context/ptr context) nil)
time-req
(gss--token-to-vector input-token))
(list continue-needed
(make-instance 'gss-context :ptr context)
(gss--make-string-from-result content)
flags))))
(cl-defun gss-accept-sec-context (content &key context)
(check-type content string)
(check-type context (or null gss-context))
(destructuring-bind (continue-needed context name output-token flags time-rec delegated-cred-handle)
(gss--internal-accept-sec-context (gss--token-to-vector content) (if context (gss-context/ptr context) nil))
(list continue-needed
(make-instance 'gss-context :ptr context)
(make-instance 'gss-name :ptr name)
(gss--make-string-from-result output-token)
flags
time-rec
delegated-cred-handle)))
(defun gss-krb5-register-acceptor-identity (file)
(check-type file string)
(unless (file-exists-p file)
(error "Could not find keytab file: %s" file))
(gss--internal-krb5-register-acceptor-identity (expand-file-name file)))
(cl-defun gss-wrap (context data &key conf)
(check-type context gss-context)
(check-type data string)
(destructuring-bind (data conf)
(gss--internal-wrap (gss-context/ptr context) (gss--token-to-vector data) conf)
(list (gss--make-string-from-result data) conf)))
(cl-defun gss-unwrap (context data)
(check-type context gss-context)
(check-type data string)
(destructuring-bind (data conf)
(gss--internal-unwrap (gss-context/ptr context) (gss--token-to-vector data))
(list (gss--make-string-from-result data) conf)))
(provide 'gss)