Python Fabric SDK, CA register user

Viewed 188

I want to add the register method to the Fabric CA (Here swagger definition) similar to the enroll function here.

The CA documentation point out:

Authorization:
An enrollment token consisting of two base 64 encoded parts separated by a period:

- an enrollment certificate;
- a signature over the certificate and body of request.

Looking at the NodeJS counterpart here and the auth header generation I ended up with the following python code:

 def register(self, enrollment_id, enrollment_secret, enrollment, crypto):

        req = {
            "caname": self._ca_name,
            "id": enrollment_id,
            "secret": enrollment_secret
        }

        signature = base64.encode(crypto.sign(enrollment.private_key, str(enrollment.cert) +'.'+ json.dumps(req, ensure_ascii=False)))

        response = self._send_ca_post(path="register", json=req,
                headers={'Authorization' : base64.encode(str(enrollment.cert) + '.' + str(signature))},
                verify=self._ca_certs_path)

I receive TypeError: data must be bytes. in this signature = base64.encode(crypto.sign(enrollment.private_key, str(enrollment.cert) +'.'+ json.dumps(req, ensure_ascii=False))) line.

Can someone help out?

0 Answers
Related