IBM-Blockchain-Archive / car-lease-demo

A demonstration using IBM Blockchain to show how the lifecycle of vehicles can be recorded on a blockchain
Other
169 stars 304 forks source link

Strange behavior in 'get_caller_data' and 'check_affiliation'. #32

Closed iv10 closed 7 years ago

iv10 commented 8 years ago

Hi. Our team has been struggling with trying to run the demo. When creating an asset via web-UI, we get a 'nil' pointer error. We've debugged it and found the problem to be the following:

func (t *SimpleChaincode) get_caller_data(stub *shim.ChaincodeStub) (string, int, error){   

    user, err := t.get_username(stub) // here user is returned as 'Transaction Certificate' for some reason
                                                                        if err != nil { return "", -1, err }

    ecert, err := t.get_ecert(stub, user); // ecert is 'nil' because no certificate can be found for such user with name ''Transaction Certificate'         
                                                                if err != nil { return "", -1, err }

    affiliation, err := t.check_affiliation(stub,string(ecert));            
                                                                        if err != nil { return "", -1, err }

    return user, affiliation, nil
}

Why is user passed as 'Transaction Certificate', when we're logged in inside web-UI as 'DVLA'? Furthermore, when we hardcode the value of the user as 'DVLA' the corresponding certificate is being found by "get_ecert" but we get a problem later on in "check_affiliation".

func (t *SimpleChaincode) check_affiliation(stub *shim.ChaincodeStub, cert string) (int, error) {                                                                                                                                                                                                                   

    decodedCert, err := url.QueryUnescape(cert);                    // make % etc normal //

                                                            if err != nil { return -1, errors.New("Could not decode certificate") }

    pem, _ := pem.Decode([]byte(decodedCert))                           // Make Plain text   //

    x509Cert, err := x509.ParseCertificate(pem.Bytes);              // Extract Certificate from argument //

                                                    if err != nil { return -1, errors.New("Couldn't parse certificate") }

    cn := x509Cert.Subject.CommonName

    res := strings.Split(cn,"\\")

    affiliation, _ := strconv.Atoi(res[2]) // here res[2] results in 'an index out of bounds' 

    return affiliation, nil

It seems that the affiliation cannot be derived from the certificate Subject. We've parsed the certificate and it indeed doesn't have affiliation role inside the "CN". The CN inside the certificate looks as follows: "DVLA\group1". But the third part with the affiliation role is missing. According to the parsing code in your demo, the CN has to be of form "DVLA\group1\1". The sample certificates are produced by the demo code, we didn't touch the logic.

Could you point out the problem? PS. We're using the 'master' branch.

Best Regards, Isgandar

liam-grace commented 8 years ago

Hi, @iv10,

Which version of hyperledger are you currently using and how have you deployed it? Are you running it locally? We will try and recreate the issue and get back to you with an answer

Thanks

Jakeeyturner commented 8 years ago

Hi @iv10,

We've realised that you must be using Fabric v0.6 (or master branch), as this has changes to the transaction certificate model which is giving you the error.

If you check the Installation Guide there will be instructions on which commit level of Fabric v0.5 you should use.

Hope this helps

iv10 commented 8 years ago

Hello. Thank you for such quick response.

@14gracel We have used "zSystemsFabricBuild.sh" (Version from 21.07.2016) of GitHub to install fabric. It does 'git clone https://github.com/hyperledger/fabric.git', which pulls the HEAD of the 'master' branch. In our case it pulled 'master' code of 21.07.2016.

@Jakeeyturner Thanks for clarification. I guess we'll have to try it out to see if it works. Does it imply that anything higher than '3e0e80a898b259fe463295eabff80ee64f20695e' of fabric's 'master' branch is not compatible with the car-lease-demo?

liam-grace commented 7 years ago

Hi iv10,

Currently the only version of fabric that works with the car lease demo is commit level '3e0e80a898b259fe463295eabff80ee64f20695e'. This commit level is not available from the regular hyperledger repo, but is available here https://github.com/hyperledger-archives/fabric.git

Regarding the "zSystemsFabricBuild.sh", when trying to run fabric with the car lease demo, you will have to checkout the working commit level

iv10 commented 7 years ago

Hi. I can confirm the reason now. We've set up our fabric from '3e0e80a898b259fe463295eabff80ee64f20695e' and it works. Thanks again, you can consider the issue as 'closed'.