You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
calculate-utils-3-core/core/server/post_cert.py

65 lines
2.2 KiB

#-*- coding: utf-8 -*-
# Copyright 2012 Calculate Ltd. http://www.calculate-linux.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import datetime
import os, hashlib
import threading
from threading import Lock
import OpenSSL
from cert_cmd import find_cert_id
# Time life certificate in days
DAY_CERT = 600
def serv_post_cert (self) :
""" transfer the client certificate """
curThread = threading.currentThread()
certificate = curThread.client_cert
results = []
if certificate == None:
return [-3]
lock = Lock()
lock.acquire()
checked_id = find_cert_id(certificate, self.data_path, self.certbase)
try:
if int(checked_id) < 1:
return [-4]
except:
return [-4]
client_cert_file = self.data_path + '/client_certs/' + str(checked_id)
results = []
with open(self.certbase) as fd:
t = fd.read()
# See each line
for line in t.splitlines():
# and each word in line
words = line.split()
# if in line present certificate id
if words[0] == checked_id:
results.append(checked_id)
date = datetime.datetime.strptime \
(words[2]+' '+words[3], '%Y-%m-%d %H:%M:%S.%f')
d = datetime.datetime.now() - date
v = DAY_CERT - d.days # How many days left certificate
if v < 0:
#Method deleted certificate
v = -2 # expiry date has passed
elif v > 60: # For a long time, is not displayed to the client
v = -1
results.append (v)
return results
return [-4]