我用IBM的例子enrollUser.js新建了一个用户,在这个工作之前,我已经成功创建了admin。
Fabric_Client.newDefaultKeyValueStore({path: store_path
}).then((state_store) =>{
// assign the store to the fabric client
fabric_client.setStateStore(state_store);
var crypto_suite = Fabric_Client.newCryptoSuite();
// use the same location for the state store (where the users' certification are kept)
// and the crypto store (where the users' keys are kept)
var crypto_store = Fabric_Client.newCryptoKeyStore({path: store_path});
crypto_suite.setCryptoKeyStore(crypto_store);
fabric_client.setCryptoSuite(crypto_suite);
var tlsOptions = {
trustedRoots: [],
verify: false
};
// be sure to change http to https when CA is running TLS enabled
fabric_ca_client = new Fabric_CA_Client('http://localhost:7054', tlsOptions, 'ca.example.com', crypto_suite);
// first check to see if the admin is already enrolled
return fabric_client.getUserContext('admin', true);
}).then((user_from_store) => {
if (user_from_store && user_from_store.isEnrolled()) {
console.log('Successfully loaded admin from persistence');
admin_user = user_from_store;
} else {
throw new Error('Failed to get admin... run enrollAdmin.js');
}
// at this point we should have the admin user
// first need to register the user with the CA server
return fabric_ca_client.register({enrollmentID: 'user1', affiliation: 'org1.department1', role: 'client'}, admin_user);
}).then((secret) => {
// next we need to enroll the user with CA server
console.log('Successfully registered user1 - secret' + secret);
return fabric_ca_client.enroll({ enrollmentID: 'user1', enrollmentSecret: secret } );
}).then((enrollment) => {
console.log('Successfully enrolled member user "user1"');
return fabric_client.createUser({
username: 'user1',
mspid: 'Org1MSP',
cryptoContent: {privateKeyPEM: enrollment.key.toBytes(), signedCertPEM: enrollment.certificate}
});
}).then((user) => {
member_user = user;
return fabric_client.setUserContext(member_user);
}).then(() => {
console.log('User1 was successfully registered and enrolled and is ready to interact with the fabric network');
}).catch((err) => {
console.error('failed to register:' + err);
if (err.toString().indexOf('Authorization') > -1) {
console.error('Authorization failures may be caused by having admin credentials from a previous CA instance.\n' +
'Try again after deleting the contents of the store dircetory' + store_path);
}
});
但是我在终端中遇到了一些错误
Successfully loaded admin from persistence
Failed to register: Error: fabric-ca request register failed with errors [[ { code: 20, message: 'Authorization failure' } ]]
Authorization failures may be caused by having admin credentials from a previous CA instance.
Try again after deleting the contents of the store directory /home/swenw/hyfa/fabric-samples/fish/fishnetwork/webapp/hfc-key-store
我查看了 docker 日志 ca.example.com,我得到了一些信息:
2021/03/13 06:48:59 [DEBUG] Received request for /api/v1/register
2021/03/13 06:49:00 [DEBUG] Received registration request from : { Name:user1 Type:client Secret:**** MaxEnrollments:1 Affiliation:org1.department1 Attributes:[] CAName:ca.example.com }
2021/03/13 06:49:00 [INFO] 172.23.0.1:60634 POST /api/v1/register 401 25 "Invalid token in authorization header: Token signature validation failed"
我不知道如何更正,请帮助我,非常感谢。
答案 0 :(得分:0)
我不知道为什么我现在成功了。我只是
rm -rf hfc-key-store
但是我发誓这种方式我试过很多次了,为什么这次能成功?精疲力竭但感谢。