示例#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)
    def test_peer_service(self):
        """2개 Peer 인증서 생성 후 테스트
        """
        ca = CAService(self.__CERT_DIR, self.__PASSWD)

        # 2개 Peer 인증서 생성
        for i in range(1, 2):
            cn = "TestPeer" + str(i)
            ca.generate_peer_cert(cn=cn, password=self.__PASSWD)

        # 생성된 인증서에 대한 검증
        validation_result = False
        for i in range(1, 2):
            cn = "TestPeer" + str(i)
            logging.debug("----- (%d)번째 인증서 검증 -----", i)
            validation_result = self.__test_certificate(cn, ca_servive=ca)
            logging.debug("----- (%d)번째 인증서 검증 결과 : %s -----", i, validation_result)
            if validation_result is False:
                break

        self.assertTrue(validation_result)