コード例 #1
0
    def __init__(self, clientConfig=None, cert_type=None, env=None):
        """
        Yop的      

        Args:
            self: write your description
            clientConfig: write your description
            cert_type: write your description
            env: write your description
        """
        self.logger = yop_logger.get_logger()
        self.env = env
        self.cert_type = cert_type
        if clientConfig is None:
            clientConfig = YopClientConfig()

        # 同时支持RSA、SM两种加密机
        self.yop_encryptor_dict = {}
        for cert_type, yop_public_key_dict in clientConfig.sdk_config[
                'yop_public_key'].items():
            if len(yop_public_key_dict) > 0:
                self.yop_encryptor_dict[cert_type] = self.get_encryptor(
                    cert_type, yop_public_key_dict)

        self.clientConfig = clientConfig
        self.authProvider = SigV3AuthProvider(self.yop_encryptor_dict)
コード例 #2
0
    def __init__(self):
        """
        Initialize the yop logger

        Args:
            self: write your description
        """
        self.logger = yop_logger.get_logger()
コード例 #3
0
ファイル: auth.py プロジェクト: yop-platform/yop-python-sdk
    def __init__(self, yop_encryptor_dict):
        """
        Initialize the YarpEncryptor.

        Args:
            self: write your description
            yop_encryptor_dict: write your description
        """
        self.logger = yop_logger.get_logger()
        self.session_id = str(uuid.uuid4())
        self.yop_encryptor_dict = yop_encryptor_dict
コード例 #4
0
    def __init__(self, config_file='config/yop_sdk_config_rsa_prod.json'):
        """
        Initializes the SDK.

        Args:
            self: write your description
            config_file: write your description
        """
        self.logger = yop_logger.get_logger()
        self.config_file = config_file
        self.sdk_config = self._init_config(config_file)
コード例 #5
0
    def __init__(self, clientConfig=None, env=None):
        """
        Initializes the SDK client

        Args:
            self: self
            clientConfig: config of client
            env: run env
        """
        self.logger = yop_logger.get_logger()
        self.path = clientConfig.sdk_config.get('yop_cert_store', '/tmp').get('path', '/tmp')
        self.env = env
コード例 #6
0
    def __init__(self, private_key=None, public_key=None):
        """
        Initializes the instance with the appropriate logger and private key.

        Args:
            self: write your description
            private_key: write your description
            public_key: write your description
        """
        self.logger = yop_logger.get_logger()
        self.private_key = private_key
        self.public_key = public_key
コード例 #7
0
    def __init__(self, private_key=None, public_key_dict=None):
        """
        YOP  private_key  public_key_dict Y

        Args:
            self: write your description
            private_key: write your description
            public_key_dict: write your description
        """
        self.logger = yop_logger.get_logger()
        self.sm2_crypt = sm2.CryptSM2()

        # 如果是商户自己的加密机
        if private_key is not None:
            self.private_key = str(hex(private_key.secret))[2:-1]
            self.public_key = private_key.publicKey().toStr()

        # 如果是YOP的加密机
        if public_key_dict is not None:
            self.yop_public_key_dict = public_key_dict
コード例 #8
0
# -*- coding: utf-8 -*-

import utils.yop_logger as yop_logger
from auth.v3signer.credentials import YopCredentials

logger = yop_logger.get_logger()

text = b"yop-auth-v3/app_100800095600038/2021-04-23T10:35:23Z/1800\nPOST\n/rest/file/upload\n\ncontent-type:application%2Fx-www-form-urlencoded\nx-yop-appkey:app_100800095600038\nx-yop-request-id:c81634dc-9404-4cbe-8ccb-27269a7ced55"


class Test(object):
    # def test_sign_self(self):
    #     credentials = YopCredentials(
    #         appKey='OPR:10000470992',
    #         priKey='ME0CAQAwEwYHKoZIzj0CAQYIKoEcz1UBgi0EMzAxAgEBBCCSY5qqLNmqfx3/6levxQka50cIGTTny495Pk+rS3A3o6AKBggqgRzPVQGCLQ==',
    #         cert_type='SM')
    #     encryptor = credentials.encryptor

    #     signature, a, ha = encryptor.signature(text)
    #     logger.debug("signature:{}".format(signature))

    #     result = encryptor.verify_signature(text, signature)
    #     assert result

    def test_sign_yop(self, client):
        """
        Verify the signature of the text.

        Args:
            self: write your description
            client: write your description
コード例 #9
0
import base64
from Crypto.PublicKey import RSA
from security.crc64 import Crc64
import utils.yop_logger as yop_logger

try:
    from importlib import reload
except ImportError:
    # fix: 'ascii' codec can't decode byte 0xe6 in position 68
    import sys
    reload(sys)
    sys.setdefaultencoding("utf-8")

# 摘要算法,默认为sha256(参照配置文件)

logger = yop_logger.get_logger(__name__)

# AES根据16位对齐
BS = 16


def parse_rsa_pri_key(private_key_string):
    """
    Parse RSA private key string.

    Args:
        private_key_string: write your description
    """
    private_key = '-----BEGIN PRIVATE KEY-----\n' + private_key_string + '\n-----END PRIVATE KEY-----'
    return RSA.importKey(private_key)