Skip to content

Commit

Permalink
登录页:增加CA地址输入。 #201
Browse files Browse the repository at this point in the history
Signed-off-by: Yi DENG <[email protected]>
  • Loading branch information
dengyi9 committed Mar 21, 2019
1 parent 246d7fb commit 3325964
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 33 deletions.
1 change: 1 addition & 0 deletions src/common/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Common.LOGIN_PEER_TLS_CA_CERT = 'Peer TLS CA Cert';
Common.LOGIN_ORDERER_TLS_CA_CERT = 'Orderer TLS CA Cert';
Common.LOGIN_PEER_SSL_TARGET = 'Peer SSL Target';
Common.LOGIN_ORDERER_SSL_TARGET = 'Orderer SSL Target';
Common.LOGIN_CA_SERVER_URL = 'CA Server Url';


Common.WARN = {
Expand Down
1 change: 1 addition & 0 deletions src/common/common_cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Common.LOGIN_PEER_TLS_CA_CERT = '组织节点TLS证书';
Common.LOGIN_ORDERER_TLS_CA_CERT = '排序节点TLS证书';
Common.LOGIN_PEER_SSL_TARGET = '组织节点SSL域名';
Common.LOGIN_ORDERER_SSL_TARGET = '排序节点SSL域名';
Common.LOGIN_CA_SERVER_URL = 'CA节点地址';


Common.WARN = {
Expand Down
41 changes: 24 additions & 17 deletions src/components/UserLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default class UserLayout extends React.Component {
keylabel: ' choose a private key',
tlsPeerLabel: ' choose a peer tls ca cert',
tlsOrdererLabel: 'choose a orderer tls ca cert',
caServerUrl: 'http://localhost:7054', // TODO: 待实现
Common: localStorage.getItem('language') === 'cn' ? require('../common/common_cn') : require('../common/common'),
};

Expand All @@ -53,6 +54,7 @@ export default class UserLayout extends React.Component {
this.mspidChange = this.mspidChange.bind(this);
this.peerSSLTargetChange = this.peerSSLTargetChange.bind(this);
this.ordererSSLTargetChange = this.ordererSSLTargetChange.bind(this);
this.caServerUrlChange = this.caServerUrlChange.bind(this);
this.changeLangtoEn = this.changeLangtoEn.bind(this);
this.changeLangtoCn = this.changeLangtoCn.bind(this);
}
Expand Down Expand Up @@ -94,6 +96,10 @@ export default class UserLayout extends React.Component {
this.setState({ peerEventUrl: event.target.value });
}

caServerUrlChange(event) {
this.setState({ caServerUrl: event.target.value });
}

cerImport() {
const selectedFile = document.getElementById('cerFiles').files[0];// 获取读取的File对象
this.setState({ certPath: selectedFile.path });
Expand Down Expand Up @@ -310,35 +316,36 @@ export default class UserLayout extends React.Component {

<div style={firstDivStyle}>
<span style={asteriskStyle}>*&nbsp;</span>
<span style={spanStyle}>{this.state.Common.LOGIN_PEER_GRPC_URL}:</span>
<Input type="text" style={InputStyle} value={this.state.peerGrpcUrl} onChange={this.peerGrpcUrlChange} />
</div>
<div style={divStyle}>
<span style={asteriskStyle}>*&nbsp;</span>
<span style={spanStyle}>{this.state.Common.LOGIN_PEER_EVENT_URL}:</span>
<Input type="text" style={InputStyle} value={this.state.peerEventUrl} onChange={this.peerEventUrlChange} />
<span style={spanStyle}>{this.state.Common.LOGIN_CERTIFICATE}:</span>
<input type="file" id="cerFiles" name="cerFiles" style={fileStyle}onChange={this.cerImport} />
<label htmlFor="cerFiles" style={labelStyle} ><Icon type="folder-open" theme="outlined" style={{ color: '#0083FA', padding: '0 7px 0 0' }} />&thinsp;{this.state.certlabel} </label>
</div>
<div style={divStyle}>
<span style={asteriskStyle}>*&nbsp;</span>
<span style={spanStyle}>{this.state.Common.LOGIN_ORDERER_URL}:</span>
<Input type="text" style={InputStyle} value={this.state.ordererUrl} onChange={this.ordererChange} />
<span style={spanStyle}>{this.state.Common.LOGIN_PRIVATE_KEY}:</span>
<input type="file" id="priFiles" name="priFiles" style={fileStyle} onChange={this.priImport} />
<label htmlFor="priFiles" style={labelStyle} ><Icon type="folder-open" theme="outlined" style={{ color: '#0083FA', padding: '0 7px 0 0' }} />&thinsp;{this.state.keylabel}</label>
</div>
<div style={divStyle}>
<span style={asteriskStyle}>*&nbsp;</span>
<span style={spanStyle}>{this.state.Common.LOGIN_MSP_ID}:</span>
<Input type="text" style={InputStyle} value={this.state.mspid} onChange={this.mspidChange} />
</div>
<div style={divStyle}>
<span style={asteriskStyle}>*&nbsp;</span>
<span style={spanStyle}>{this.state.Common.LOGIN_CERTIFICATE}:</span>
<input type="file" id="cerFiles" name="cerFiles" style={fileStyle}onChange={this.cerImport} />
<label htmlFor="cerFiles" style={labelStyle} ><Icon type="folder-open" theme="outlined" style={{ color: '#0083FA', padding: '0 7px 0 0' }} />&thinsp;{this.state.certlabel} </label>
<span style={spanStyle}>&nbsp; {this.state.Common.LOGIN_PEER_GRPC_URL}:</span>
<Input type="text" style={InputStyle} value={this.state.peerGrpcUrl} onChange={this.peerGrpcUrlChange} />
</div>
<div style={divStyle}>
<span style={asteriskStyle}>*&nbsp;</span>
<span style={spanStyle}>{this.state.Common.LOGIN_PRIVATE_KEY}:</span>
<input type="file" id="priFiles" name="priFiles" style={fileStyle} onChange={this.priImport} />
<label htmlFor="priFiles" style={labelStyle} ><Icon type="folder-open" theme="outlined" style={{ color: '#0083FA', padding: '0 7px 0 0' }} />&thinsp;{this.state.keylabel}</label>
<span style={spanStyle}>&nbsp; {this.state.Common.LOGIN_PEER_EVENT_URL}:</span>
<Input type="text" style={InputStyle} value={this.state.peerEventUrl} onChange={this.peerEventUrlChange} />
</div>
<div style={divStyle}>
<span style={spanStyle}>&nbsp; {this.state.Common.LOGIN_ORDERER_URL}:</span>
<Input type="text" style={InputStyle} value={this.state.ordererUrl} onChange={this.ordererChange} />
</div>
<div style={divStyle}>
<span style={spanStyle}>&nbsp; {this.state.Common.LOGIN_CA_SERVER_URL}:</span>
<Input type="text" style={InputStyle} value={this.state.caServerUrl} onChange={this.caServerUrlChange} />
</div>
<div style={divStyle}>
<span style={spanStyle}>&nbsp; {this.state.Common.LOGIN_PEER_TLS_CA_CERT}:</span>
Expand Down
29 changes: 14 additions & 15 deletions src/util/fabric.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ class FabricClient {
return new Promise((resolve) => {
logger.info('config:', config);

if (config.tlsPeerPath === '' || config.tlsOrdererPath === '') {
logger.info('+++++++++++++++++');
self.isTlsEnabled = false;
self.peer = fabricClient.newPeer(config.peerGrpcUrl);
self.order = fabricClient.newOrderer(config.ordererUrl);
} else {
logger.info('------------------');
self.peerCert = fs.readFileSync(config.tlsPeerPath);
self.ordererCert = fs.readFileSync(config.tlsOrdererPath);
self.isTlsEnabled = true;
self.peer = fabricClient.newPeer(config.peerGrpcUrl,
{ pem: Buffer.from(this.peerCert).toString(), 'ssl-target-name-override': config.peerSSLTarget });
self.order = fabricClient.newOrderer(config.ordererUrl,
{ pem: Buffer.from(this.ordererCert).toString(), 'ssl-target-name-override': config.ordererSSLTarget });
if (config.peerGrpcUrl) {
if (config.tlsPeerPath === '' || config.tlsOrdererPath === '') {
self.isTlsEnabled = false;
self.peer = fabricClient.newPeer(config.peerGrpcUrl);
self.order = fabricClient.newOrderer(config.ordererUrl);
} else {
self.peerCert = fs.readFileSync(config.tlsPeerPath);
self.ordererCert = fs.readFileSync(config.tlsOrdererPath);
self.isTlsEnabled = true;
self.peer = fabricClient.newPeer(config.peerGrpcUrl,
{ pem: Buffer.from(this.peerCert).toString(), 'ssl-target-name-override': config.peerSSLTarget });
self.order = fabricClient.newOrderer(config.ordererUrl,
{ pem: Buffer.from(this.ordererCert).toString(), 'ssl-target-name-override': config.ordererSSLTarget });
}
}

// TODO: 考虑 ca管理 与 peer管理,分别维护两套用户
Expand Down Expand Up @@ -100,7 +100,6 @@ class FabricClient {
logger.info('almost done');
return self.fabricClient.getUserContext(usrName, true) // FIXME: usernaem和mspid可能要分开
.then((user) => {
logger.info('loginUser: ', user.toString());
self.user = user;
return Promise.resolve(user);
});
Expand Down
2 changes: 1 addition & 1 deletion test/resources/persistence/config.db
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"id":0,"isSign":1,"_id":"0RYjfGm5ZQNGBcxV","peerGrpcUrl":"grpc://localhost:7051","peerEventUrl":"grpc://localhost:7053","ordererUrl":"grpc://localhost:7050","mspid":"Org1MSP","tlsPeerPath":"","tlsOrdererPath":"","path":"test/resources/key/users/","caServerUrl":"http://localhost:7054"}
{"id":0,"isSign":1,"_id":"0RYjfGm5ZQNGBcxV","peerGrpcUrl":"grpc://localhost:7051","peerEventUrl":"grpc://localhost:7053","ordererUrl":"grpc://localhost:7050","mspid":"Org1MSP","tlsPeerPath":"","tlsOrdererPath":"","path":"test/resources/key/users/","caServerUrl":""}i

0 comments on commit 3325964

Please sign in to comment.