14
14
import sys
15
15
import json
16
16
import ldap
17
- from flask import request , Response
17
+ from flask import request , Response , send_from_directory
18
18
from flask import current_app as app
19
19
from marshmallow import fields , Schema
20
20
from marshmallow .validate import Length
21
21
from datetime import datetime
22
22
from . import public
23
23
from ..resources .errors import KeyperError , errors
24
24
from ..utils import operations
25
+ from ..utils .sshca import SSHCA
25
26
from ..admin .users import search_users , cn_from_dn
26
27
from ..admin .hosts import searchHosts
27
28
from ldapDefn import *
@@ -45,12 +46,22 @@ def get_authkeys():
45
46
username = request .values .get ('username' )
46
47
host = request .values .get ('host' )
47
48
fingerprint = request .values .get ('fingerprint' )
49
+ key = request .values .get ('key' )
48
50
49
51
app .logger .debug ("username/host: " + username + "/" + host )
50
52
53
+ sshca = SSHCA ()
54
+
51
55
sshPublicKeys = []
52
56
result = ""
53
57
58
+ if (key is None ):
59
+ app .logger .debug ("Key is None" )
60
+ else :
61
+ if (sshca .is_key_revoked (key .replace ('#' ,' ' ,1 ))):
62
+ app .logger .info ("Key in KRL" )
63
+ return Response (result , mimetype = 'text/plain' )
64
+
54
65
con = operations .open_ldap_connection ()
55
66
56
67
users = []
@@ -66,8 +77,6 @@ def get_authkeys():
66
77
else :
67
78
app .logger .debug ("User not allowed to access host: " + user [LDAP_ATTR_CN ] + "/" + host )
68
79
69
- # for sshPublicKey in sshPublicKeys:
70
- # result = sshPublicKey + "\n"
71
80
result = '\n ' .join (sshPublicKeys )
72
81
73
82
operations .close_ldap_connection (con )
@@ -92,12 +101,22 @@ def get_authprinc():
92
101
username = request .values .get ('username' )
93
102
host = request .values .get ('host' )
94
103
fingerprint = request .values .get ('fingerprint' )
104
+ cert = request .values .get ('cert' )
95
105
96
106
app .logger .debug ("username/host/fingerprint: " + username + "/" + host + "/" + fingerprint )
97
107
98
108
sshPublicCerts = []
99
109
result = ""
100
110
111
+ sshca = SSHCA ()
112
+
113
+ if (cert is None ):
114
+ app .logger .debug ("Cert is None" )
115
+ else :
116
+ if (sshca .is_key_revoked (cert .replace ('#' ,' ' ,1 ))):
117
+ app .logger .info ("Cert in KRL" )
118
+ return Response (result , mimetype = 'text/plain' )
119
+
101
120
con = operations .open_ldap_connection ()
102
121
103
122
users = []
@@ -232,6 +251,17 @@ def get_userca():
232
251
app .logger .debug ("Exit" )
233
252
return Response (ca_key , mimetype = 'text/plain' )
234
253
254
+ @public .route ('/cakrl' , methods = ['GET' , 'POST' ])
255
+ def get_cakrl ():
256
+ ''' Get KRL File '''
257
+ app .logger .debug ("Enter" )
258
+
259
+ try :
260
+ return send_from_directory (directory = app .config ["SSH_CA_DIR" ], filename = app .config ["SSH_CA_KRL_FILE" ], as_attachment = True )
261
+ except FileNotFoundError :
262
+ app .logger .error ("KRL FIle Not Found Exception" )
263
+ raise KeyperError ("KRL File Not Found Exception" ,404 )
264
+
235
265
@public .route ('/usercert' , methods = ['GET' ])
236
266
def get_usercert ():
237
267
''' Get Cert for a user '''
@@ -397,17 +427,19 @@ class AuthKeySchema(Schema):
397
427
username = fields .Str (required = True , validate = Length (max = 100 ))
398
428
host = fields .Str (required = True , validate = Length (max = 100 ))
399
429
fingerprint = fields .Str (required = False , validate = Length (max = 100 ))
430
+ key = fields .Str (required = False , validate = Length (max = 5000 ))
400
431
401
432
class Meta :
402
- fields = ("username" , "host" , "fingerprint" )
433
+ fields = ("username" , "host" , "fingerprint" , "key" )
403
434
404
435
class AuthPrincSchema (Schema ):
405
436
username = fields .Str (required = True , validate = Length (max = 100 ))
406
437
host = fields .Str (required = True , validate = Length (max = 100 ))
407
438
fingerprint = fields .Str (required = True , validate = Length (max = 100 ))
439
+ cert = fields .Str (required = False , validate = Length (max = 5000 ))
408
440
409
441
class Meta :
410
- fields = ("username" , "host" , "fingerprint" )
442
+ fields = ("username" , "host" , "fingerprint" , "cert" )
411
443
412
444
class HostCertSchema (Schema ):
413
445
hostname = fields .Str (required = True , validate = Length (max = 100 ))
0 commit comments