Skip to content

Commit

Permalink
fix PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vinkabuki committed Oct 4, 2023
1 parent 5617d5e commit d60f9da
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 23 deletions.
15 changes: 4 additions & 11 deletions packages/backend/src/nest/registration/registration.functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,17 @@ export const extractPendingCsrs = async (payload: { csrs: string[]; certificates
}
})

const parsedCsrs: { [key: string]: CertificationRequest } = {}
const pendingCsrs: string[] = []

for (const csr of payload.csrs) {
const parsedCsr = await loadCSR(csr)
parsedCsrs[csr] = parsedCsr
}

const pendingCsrs = payload.csrs.filter(csr => {
const username = getReqFieldValue(parsedCsrs[csr], CertFieldsTypes.nickName)
const username = getReqFieldValue(parsedCsr, CertFieldsTypes.nickName)

if (username && !certNames.has(username) && !pendingNames.has(username)) {
pendingNames.add(username)
return true
} else {
return false
pendingCsrs.push(csr)
}
})

}
return pendingCsrs
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class RegistrationService extends EventEmitter implements OnModuleInit {
this.on(
RegistrationEvents.REGISTER_USER_CERTIFICATE,
async (payload: { csrs: string[]; certificates: string[] }) => {
// Lack of permsData means that we are not the owner of the community
// Lack of permsData means that we are not the owner of the community in the official model of the app, however anyone can modify the source code, put malicious permsData here, issue false certificates and try to trick other users.
await this.issueCertificates(payload)
}
)
Expand All @@ -41,13 +41,13 @@ export class RegistrationService extends EventEmitter implements OnModuleInit {
}

public async registerOwnerCertificate(payload: RegisterOwnerCertificatePayload): Promise<void> {
// It should not be here.
// FIXME: We should resolve problems with events order and we should set permsData only on LAUNCH_REGISTRART socket event in connectionsManager.
this._permsData = payload.permsData
const result = await issueCertificate(payload.userCsr.userCsr, this._permsData)
if (result?.cert) {
this.emit(SocketActionTypes.SAVED_OWNER_CERTIFICATE, {
communityId: payload.communityId,
network: { certificate: result.cert, peers: [] },
network: { certificate: result.cert },
})
} else {
this.emit(SocketActionTypes.ERROR, {
Expand Down
1 change: 0 additions & 1 deletion packages/desktop/src/rtl-tests/community.create.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ describe('User', () => {
communityId: payload.communityId,
network: {
certificate: payload.permsData.certificate,
peers: [],
},
})
}
Expand Down
2 changes: 1 addition & 1 deletion packages/identity/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export const pubKeyMatch = (cert: string, parsedCsr: CertificationRequest): bool
return false
}

// generalize to certificateByField
// TODO: generalize to certificateByField
export const certificateByUsername = (username: string, certificates: string[]): string | null => {
/**
* Check if given username is already in use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,6 @@ export function subscribe(socket: Socket) {
ownerCertificate: payload.network.certificate,
})
)
emit(
communitiesActions.storePeerList({
communityId: payload.communityId,
peerList: payload.network.peers,
})
)
emit(
identityActions.storeUserCertificate({
userCertificate: payload.network.certificate,
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export interface SaveOwnerCertificatePayload {

export interface SavedOwnerCertificatePayload {
communityId: string
network: { certificate: string; peers: string[] }
network: { certificate: string }
}

export interface SuccessfullRegistrarionResponse {
Expand Down

0 comments on commit d60f9da

Please sign in to comment.