Esempio n. 1
0
    def test_enroll(self):
        casvc = ca_service("http://" + self._ca_server_address)
        adminEnrollment = casvc.enroll(self._enrollment_id,
                                       self._enrollment_secret)

        new_wallet = wallet.FileSystenWallet()
        user_identity = wallet.Identity(self._enrollment_id, adminEnrollment)
        user_identity.CreateIdentity(new_wallet)

        self.assertTrue(new_wallet.exists(self._enrollment_id))
def enroll_user(
    hf_client: hfc.fabric.Client,
    org_name: str,
    user_name: str,
    user_password: str,
) -> hfc.fabric.user.User:
    """
    Enrolls a user to the Org's Fabric CA Server
    Args:
        hf_client: Network HF Client object
        org_name: Organization's name
        user_name: Username to enroll
        user_password: User's password
    Returns:
        Enrolled User object
    """
    # Create/Open a wallet on a temp path including the org name
    # Org name must be included, otherwise usernames must be unique
    # over all orgs
    wallet_path = os.path.join(os.getcwd(), 'tmp', 'hfc-kvs', org_name)
    cred_wallet = wallet.FileSystenWallet(path=wallet_path)  # [sic]

    # Extract CA info
    network_info = hf_client.get_net_info()
    org_info = network_info['organizations'][org_name]
    ca_name = org_info['certificateAuthorities'][0]
    ca_info = network_info['certificateAuthorities'][ca_name]

    # if user already exists, pull ID from storage
    if cred_wallet.exists(user_name):
        user = cred_wallet.create_user(user_name, org_name, org_info['mspid'])
        #if user.enrollment_secret != user_password:
        #    # TODO: Check passwords in a *much* more secure way than this
        #    raise ValidationError('Invalid username/password')
        return user

    casvc = ca_service(target=ca_info['url'])
    user_enrollment = casvc.enroll(user_name,
                                   user_password,
                                   attr_reqs=[{
                                       'name': 'id',
                                       'optional': True
                                   }])

    # Store credentials in file kvs wallet; will be stored in ./tmp/hfc-kvs
    user_identity = wallet.Identity(user_name, user_enrollment)
    user_identity.CreateIdentity(cred_wallet)

    return cred_wallet.create_user(user_name, org_name, org_info['mspid'])
async def register_user(org_name: str,
                        request: constants.RegisterUserRequest) -> str:
    """
    Registers a user to the Org's Fabric CA Server
    Args:
        org_name: Organization's name
        request: RegisterUserRequest object containing
            registration information
    Returns:
        Pre-generated user secret
    """
    # Create/Open a wallet on a temp path including the org name
    # Org name must be included, otherwise usernames must be unique
    # over all orgs
    wallet_path = os.path.join(os.getcwd(), 'tmp', 'hfc-kvs', org_name)
    cred_wallet = wallet.FileSystenWallet(path=wallet_path)  # [sic]

    # Setup a HF network client
    hf_client = Client(net_profile=constants.config_path)
    hf_client.new_channel(constants.channel_name)

    # Extract CA info
    network_info = hf_client.get_net_info()
    org_info = network_info['organizations'][org_name]
    ca_name = org_info['certificateAuthorities'][0]
    ca_info = network_info['certificateAuthorities'][ca_name]

    # if user already exists, pull ID from storage
    if cred_wallet.exists(request.user_name):
        return None
    casvc = ca_service(target=ca_info['url'])
    admin_enrollment = casvc.enroll(request.admin_user_name,
                                    request.admin_password)

    secret = admin_enrollment.register(enrollmentID=request.user_name,
                                       enrollmentSecret=request.user_password,
                                       role=request.role,
                                       affiliation=request.affiliation,
                                       attrs=[dict(x) for x in request.attrs])

    return secret
Esempio n. 4
0
from hfc.fabric_network import wallet
from hfc.fabric_ca.caservice import CAClient, CAService

# Netherlands user
casvc = CAService(target="http://192.168.39.209:31700")
adminNlEnrollment = casvc.enroll(
    "admin", "adminpw")  # now local will have the admin enrollment
secret = adminNlEnrollment.register("user1Nl")  # register a user to ca
user1NlEnrollment = casvc.enroll(
    "user1Nl", secret)  # now local will have the user enrollment
new_wallet = wallet.FileSystenWallet(
)  # Creates default wallet at ./tmp/hfc-kvs
user_identity_nl = wallet.Identity(
    "user1Nl",
    user1NlEnrollment)  # Creates a new Identity of the enrolled user
user_identity_nl.CreateIdentity(
    new_wallet)  # Stores this identity in the FileSystemWallet
user1Nl = new_wallet.create_user(
    "user1Nl", "Netherlands", "NetherlandsMSP"
)  # Returns an instance of the user object with the newly created credentials

# # Spain user
# casvc = CAService(target="http://172.17.0.2:31701")
# adminEsEnrollment = casvc.enroll("admin", "adminpw") # now local will have the admin enrollment
# secret = adminEsEnrollment.register("user1Es") # register a user to ca
# user1EsEnrollment = casvc.enroll("user1Es", secret) # now local will have the user enrollment
# # new_wallet = wallet.FileSystenWallet() # Creates default wallet at ./tmp/hfc-kvs
# user_identity_es = wallet.Identity("user1Es", user1EsEnrollment) # Creates a new Identity of the enrolled user
# user_identity_es.CreateIdentity(new_wallet) # Stores this identity in the FileSystemWallet
# user1Es = new_wallet.create_user("user1Es", "Spain", "SpainMSP") # Returns an instance of the user object with the newly created credentials
Esempio n. 5
0
import asyncio
from hfc.fabric_ca.caservice import CAClient, CAService
from hfc.fabric import Client
from hfc.fabric_network import wallet
from hfc.fabric.transaction.tx_proposal_request import create_tx_prop_req, CC_INVOKE, CC_TYPE_NODE, CC_INSTANTIATE, CC_INSTALL, TXProposalRequest

loop = asyncio.get_event_loop()

cli = Client(net_profile="connection-profile.json")

# NlClient = cli.get_user('netherlands.nl', 'user1Nl')

fs_wallet = wallet.FileSystenWallet(
    "./tmp/hfc-kvs")  # Opens wallet at ./tmp/hfc-kvs
user1Nl = fs_wallet.create_user(
    "user1Nl", "Netherlands", "NetherlandsMSP"
)  # Returns an instance of the user object with the newly created credentials

# Make the client know there is a channel in the network
cli.new_channel('common')

# Invoke a chaincode
args = []

# The response should be true if succeed
response = loop.run_until_complete(
    cli.chaincode_invoke(
        requestor=user1Nl,
        channel_name='common',
        peers=['peer0.netherlands.nl'],
        args=args,