Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix connection config profile #28

Merged
merged 3 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions src/instance/bdkFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,12 @@ export default class BdkFile {
}

public getPeerOrgTlsCertString (number: number, domain: string) {
// TODO 確認資料夾只有一個檔案
return fs.readFileSync(`${this.bdkPath}/peerOrganizations/${domain}/peers/peer${number}.${domain}/tls/ca.crt`).toString()
// TODO: if ca is more then 2 layer
let tlsCert = fs.readFileSync(`${this.bdkPath}/peerOrganizations/${domain}/peers/peer${number}.${domain}/tls/ca.crt`).toString()
if (fs.pathExistsSync(`${this.bdkPath}/peerOrganizations/${domain}/peers/peer${number}.${domain}/tls/tlscacerts`)) {
tlsCert = tlsCert + fs.readFileSync(this.newestFileInFolder(`${this.bdkPath}/peerOrganizations/${domain}/peers/peer${number}.${domain}/tls/tlscacerts`)).toString()
}
return tlsCert
}

public getPeerOrgCaCertString (domain: string) {
Expand Down Expand Up @@ -263,15 +267,15 @@ export default class BdkFile {
`${this.orgPath}/msp`,
)
fs.copyFileSync(
`${this.orgPath}/msp/cacerts/${this.newestFileInFolder(`${this.orgPath}/msp/cacerts`)}`,
this.newestFileInFolder(`${this.orgPath}/msp/cacerts`),
`${this.orgPath}/msp/tlscacerts/tlsca.${hostname}-cert.pem`,
)
fs.copySync(
`${this.orgPath}/msp/intermediatecerts`,
`${this.orgPath}/msp/tlsintermediatecerts`,
)
fs.copyFileSync(
`${this.orgPath}/msp/intermediatecerts/${this.newestFileInFolder(`${this.orgPath}/msp/intermediatecerts`)}`,
this.newestFileInFolder(`${this.orgPath}/msp/intermediatecerts`),
`${this.orgPath}/ca/ca.${hostname}-cert.pem`,
)

Expand Down Expand Up @@ -299,19 +303,19 @@ export default class BdkFile {
)
// TODO 實驗能否直接做成 cachain ,加上 rca cert ../tlscacerts/*.pem
fs.copyFileSync(
`${this.orgPath}/orderers/${ordererName}/tls/tlsintermediatecerts/${this.newestFileInFolder(`${this.orgPath}/orderers/${ordererName}/tls/tlsintermediatecerts`)}`,
this.newestFileInFolder(`${this.orgPath}/orderers/${ordererName}/tls/tlsintermediatecerts`),
`${this.orgPath}/orderers/${ordererName}/tls/ca.crt`,
)
fs.copyFileSync(
`${this.orgPath}/orderers/${ordererName}/tls/signcerts/${this.newestFileInFolder(`${this.orgPath}/orderers/${ordererName}/tls/signcerts`)}`,
this.newestFileInFolder(`${this.orgPath}/orderers/${ordererName}/tls/signcerts`),
`${this.orgPath}/orderers/${ordererName}/tls/server.crt`,
)
fs.copyFileSync(
`${this.orgPath}/orderers/${ordererName}/tls/keystore/${this.newestFileInFolder(`${this.orgPath}/orderers/${ordererName}/tls/keystore`)}`,
this.newestFileInFolder(`${this.orgPath}/orderers/${ordererName}/tls/keystore`),
`${this.orgPath}/orderers/${ordererName}/tls/server.key`,
)
fs.copyFileSync(
`${this.orgPath}/orderers/${ordererName}/tls/keystore/${this.newestFileInFolder(`${this.orgPath}/orderers/${ordererName}/tls/keystore`)}`,
this.newestFileInFolder(`${this.orgPath}/orderers/${ordererName}/tls/keystore`),
`${this.orgPath}/orderers/${ordererName}/tls/keystore/priv_sk`,
)

Expand Down Expand Up @@ -340,11 +344,11 @@ export default class BdkFile {
// TODO GitHub Actions buffer overflow temporary solution
try {
fs.copyFileSync(
`${this.orgPath}/peers/${peerName}/msp/cacerts/${this.newestFileInFolder(`${this.orgPath}/peers/${peerName}/msp/cacerts`)}`,
this.newestFileInFolder(`${this.orgPath}/peers/${peerName}/msp/cacerts`),
`${this.orgPath}/peers/${peerName}/msp/tlscacerts/tlsca.${hostname}-cert.pem`)
} catch {
fs.copyFileSync(
`${this.orgPath}/peers/${peerName}/msp/cacerts/${this.newestFileInFolder(`${this.orgPath}/peers/${peerName}/msp/cacerts`)}`,
this.newestFileInFolder(`${this.orgPath}/peers/${peerName}/msp/cacerts`),
`${this.orgPath}/peers/${peerName}/msp/tlscacerts/tlsca.${hostname}-cert.pem`)
}
fs.copySync(
Expand All @@ -353,19 +357,19 @@ export default class BdkFile {
)
// TODO 實驗能否直接做成 cachain ,加上 rca cert ../tlscacerts/*.pem
fs.copyFileSync(
`${this.orgPath}/peers/${peerName}/tls/tlsintermediatecerts/${this.newestFileInFolder(`${this.orgPath}/peers/${peerName}/tls/tlsintermediatecerts`)}`,
this.newestFileInFolder(`${this.orgPath}/peers/${peerName}/tls/tlsintermediatecerts`),
`${this.orgPath}/peers/${peerName}/tls/ca.crt`,
)
fs.copyFileSync(
`${this.orgPath}/peers/${peerName}/tls/signcerts/${this.newestFileInFolder(`${this.orgPath}/peers/${peerName}/tls/signcerts`)}`,
this.newestFileInFolder(`${this.orgPath}/peers/${peerName}/tls/signcerts`),
`${this.orgPath}/peers/${peerName}/tls/server.crt`,
)
fs.copyFileSync(
`${this.orgPath}/peers/${peerName}/tls/keystore/${this.newestFileInFolder(`${this.orgPath}/peers/${peerName}/tls/keystore`)}`,
this.newestFileInFolder(`${this.orgPath}/peers/${peerName}/tls/keystore`),
`${this.orgPath}/peers/${peerName}/tls/server.key`,
)
fs.copyFileSync(
`${this.orgPath}/peers/${peerName}/tls/keystore/${this.newestFileInFolder(`${this.orgPath}/peers/${peerName}/tls/keystore`)}`,
this.newestFileInFolder(`${this.orgPath}/peers/${peerName}/tls/keystore`),
`${this.orgPath}/peers/${peerName}/tls/keystore/priv_sk`,
)

Expand Down Expand Up @@ -418,7 +422,7 @@ export default class BdkFile {
newest.created = stats.ctime
}
})
return newest.fileName
return `${folderName}/${newest.fileName}`
}

private createPackageIdFolder () {
Expand Down
7 changes: 0 additions & 7 deletions src/service/peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,6 @@ export default class Peer extends AbstractService {
)
}

connectionConfigYaml.addCertificateAuthorities(
peerOrg.name,
`ca.${peerOrg.domain}`,
`ca-${peerOrg.name}`,
[this.bdkFile.getPeerOrgCaCertString(peerOrg.domain)],
)

this.bdkFile.createConnectionFile(peerOrg.name, peerOrg.domain, connectionConfigYaml)
})
}
Expand Down