Пример #1
0
    async def get(self, request, request_type, certificate_type):
        ca = CAService(self._DEFAULT_PATH, None)
        result = dict()

        if request_type == self.__REQUEST_TYPE['CERT_LIST']:
            if certificate_type == self.__CERTIFICATE_TYPE['CA']:
                certificate = ca.get_ca_certificate()
                result['response_code'] = message_code.Response.success
                result['data'] = ca.get_certificate_json(certificate)

            elif certificate_type == self.__CERTIFICATE_TYPE['PEER']:
                certificate = ca.get_peer_certificate_list()
                cert_json = []

                for cert_key in certificate:
                    cert_peer = ca.get_peer_certificate(cert_key)
                    cert_json.append(ca.get_certificate_json(cert_peer))

                result['response_code'] = message_code.Response.success
                result['data'] = cert_json

            else:
                return ServerComponents().abort_if_url_doesnt_exist(
                    certificate_type, self.__CERTIFICATE_TYPE)

        elif request_type == self.__REQUEST_TYPE['ISSUE']:
            if certificate_type == self.__CERTIFICATE_TYPE['CA']:
                ca.generate_ca_cert(cn=self._DEFAULT_COMMON_NAME,
                                    ou=self._DEFAULT_ORGANIZATION_UNIT,
                                    o=self._DEFAULT_ORGANIZATION,
                                    expire_period=self._DEFAULT_PERIOD,
                                    password=None)

                return ServerComponents().response_simple_success()

            elif certificate_type == self.__CERTIFICATE_TYPE['PEER']:
                if ca.is_secure is False:
                    return self.__abort_if_CA_certificate_loading_fails()

                else:
                    ca.generate_peer_cert(self._DEFAULT_COMMON_NAME, None)
                    return ServerComponents().response_simple_success()

            else:
                return ServerComponents().abort_if_url_doesnt_exist(
                    certificate_type, self.__CERTIFICATE_TYPE)

        else:
            return ServerComponents().abort_if_url_doesnt_exist(
                request_type, self.__REQUEST_TYPE)

        return response.json(result)
Пример #2
0
    def test_ca_service(self):
        """CA 인증서 생성 및 검증
        """
        if os.path.exists(self.__CERT_DIR) is False:
            os.mkdir(self.__CERT_DIR, mode=0o0755)
            logging.debug("Create DEFAULT Path : %s", self.__CERT_DIR)

        # ########################## CA 인증서 신규 발급 시에만 아래 주석 제거 ########################
        ca = CAService(self.__CERT_DIR, self.__PASSWD)
        cn = "loopchain CA(1)"
        ou = "DEV"
        o = "theloop"
        period = 30

        logging.debug("New CA Certificate")
        ca.generate_ca_cert(cn=cn, ou=ou, o=o, expire_period=period, password=self.__PASSWD)
        # ####################################################################################

        new_ca = CAService(self.__CERT_DIR, self.__PASSWD)
        self.assertTrue(new_ca.sign_test())