Skip to content

Commit

Permalink
fix: Remove unused dmPublicKey to prevent UI delay during joining (#2392
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Lucas Leblow authored Apr 10, 2024
1 parent 595d896 commit c089c68
Show file tree
Hide file tree
Showing 30 changed files with 23 additions and 126 deletions.
1 change: 0 additions & 1 deletion packages/backend/src/nest/common/client-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export const createUsersCerts = async (
nickname: 'dev99damian1',
commonName: onion,
peerId: 'Qmf3ySkYqLET9xtAtDzvAr5Pp3egK1H3C5iJAZm1SpLert',
dmPublicKey: 'dmPublicKey1',
signAlg: configCrypto.signAlg,
hashAlg: configCrypto.hashAlg,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ describe('RegistrationService', () => {
nickname: 'userName',
commonName: 'nqnw4kc4c77fb47lk52m5l57h4tcxceo7ymxekfn7yh5m66t4jv2olad.onion',
peerId: 'Qmf3ySkYqLET9xtAtDzvAr5Pp3egK1H3C5iJAZm1SpLEp6',
dmPublicKey: 'testdmPublicKey',
signAlg: configCrypto.signAlg,
hashAlg: configCrypto.hashAlg,
})
Expand Down Expand Up @@ -88,7 +87,6 @@ describe('RegistrationService', () => {
nickname: 'alice',
commonName: 'nqnw4kc4c77fb47lk52m5l57h4tcxceo7ymxekfn7yh5m66t4jv2olad.onion',
peerId: 'Qmf3ySkYqLET9xtAtDzvAr5Pp3egK1H3C5iJAZm1SpLEp6',
dmPublicKey: 'testdmPublicKey',
signAlg: configCrypto.signAlg,
hashAlg: configCrypto.hashAlg,
})
Expand Down Expand Up @@ -122,7 +120,6 @@ describe('RegistrationService', () => {
nickname: 'userName2',
commonName: 'nqnw4kc4c77fb47lk52m5l57h4tcxceo7ymxekfn7yh5m66t4jv2olad.onion',
peerId: 'Qmf3ySkYqLET9xtAtDzvAr5Pp3egK1H3C5iJAZm1SpLEp6',
dmPublicKey: 'testdmPublicKey',
signAlg: configCrypto.signAlg,
hashAlg: configCrypto.hashAlg,
})
Expand All @@ -136,15 +133,13 @@ describe('RegistrationService', () => {
nickname: 'karol',
commonName: 'nqnw4kc4c77fb47lk52m5l57h4tcxceo7ymxekfn7yh5m66t4jv2olad.onion',
peerId: 'Qmf3ySkYqLET9xtAtDzvAr5Pp3egK1H3C5iJAZm1SpLEp6',
dmPublicKey: 'testdmPublicKey',
signAlg: configCrypto.signAlg,
hashAlg: configCrypto.hashAlg,
})
const userCsr2 = await createUserCsr({
nickname: 'karol',
commonName: 'nnnnnnc4c77fb47lk52m5l57h4tcxceo7ymxekfn7yh5m66t4jv2olad.onion',
peerId: 'QmffffffqLET9xtAtDzvAr5Pp3egK1H3C5iJAZm1SpLEp6',
dmPublicKey: 'testdmPublicKey',
signAlg: configCrypto.signAlg,
hashAlg: configCrypto.hashAlg,
})
Expand Down Expand Up @@ -187,7 +182,6 @@ describe('RegistrationService', () => {
nickname: 'alice',
commonName: 'nqnw4kc4c77fb47lk52m5l57h4tcxceo7ymxekfn7yh5m66t4jv2olad.onion',
peerId: 'Qmf3ySkYqLET9xtAtDzvAr5Pp3egK1H3C5iJAZm1SpLEp6',
dmPublicKey: 'testdmPublicKey',
signAlg: configCrypto.signAlg,
hashAlg: configCrypto.hashAlg,
})
Expand All @@ -196,7 +190,6 @@ describe('RegistrationService', () => {
nickname: 'alice',
commonName: 'nnnnnnc4c77fb47lk52m5l57h4tcxceo7ymxekfn7yh5m66t4jv2olad.onion',
peerId: 'QmffffffqLET9xtAtDzvAr5Pp3egK1H3C5iJAZm1SpLEp6',
dmPublicKey: 'testdmPublicKey',
signAlg: configCrypto.signAlg,
hashAlg: configCrypto.hashAlg,
})
Expand Down
4 changes: 0 additions & 4 deletions packages/backend/src/nest/storage/storage.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,15 +525,11 @@ describe('StorageService', () => {
{
onionAddress: '6vu2bxki777it3cpayv6fq6vpl4ke3kzj7gxicfygm55dhhtphyfdvyd.onion',
peerId: 'QmXRY4rhAx8Muq8dMGkr9qknJdE6UHZDdGaDRTQEbwFN5b',
dmPublicKey:
'299abdb3a1c456245fa65560624ba583a5d5e35d5945ee14d548df5d37f5a516b281f71e9c66d3e9145a80fb59ce3baae611dd621a838d1cd98676e7f1901261380133ba9cb1e52ae54a52d69134f032368de3caa9ab69dcfce6e9afcc192ce21129d1131efce0994a7f028c8c9977dd403c9509bd9e149e0081f2071ddce0b7fc217756da7deb9e16d57e3a41300c7087a96df9ee5a82d197cbeabfc4011251e2cf7d481161672d94b82df0ea7e593a4bc81919b1516806f26b32dd9774cd11237d98cd346be7a19715ae15c90998e715f095048f8227403fb8cf915ca035ca1e5ef033d990a4dc84750a7de65fc9cc928e773250cd68c625754400d2e836f3f4bb0654a56aad820c3e0e977b304eaec2e0a193c4aac8dfaaee614671ecd11a40317957b56fa8f099d1f6684c826e4984d0ebb8',
username: 'o',
},
{
onionAddress: 'y7yczmugl2tekami7sbdz5pfaemvx7bahwthrdvcbzw5vex2crsr26qd.onion',
peerId: 'QmT18UvnUBkseMc3SqnfPxpHwN8nzLrJeNSLZtc8rAFXhz',
dmPublicKey:
'050bf2be48a25c47ff3cb2a7b11d416bd02162c54ef28e7a6e77ed527a15cc19516605332c9bce4aba0f93f1266d5cfea2484cadc60d802587bf1ac0a87555ab42513fa6e2f7c06d094a2dc7a38f147a792b94022fad21a1dd6e02784aa1cc891bdb6ca0cf5a4be92b9ff93e83844206388f676e5c0bb406fd436beb0c8843c7a5061a3830a9bc88ea7b112852b19395d5feb1ae75d8082ff3c9473ce4612ec9c2f35489a0010bcf0136dd333638cd21a734b1f192f494371691f4b9c459ffa2d637aa70e8973af99dc94e417b766a8462afbc183fe6fc8b4220887de6a98d97a69cba851d0062b609439b6c6728be87cccc9f6680073d5ed8716611e2ca54f49bbc43c6aa49e02bcb1eecc79e5e491e063b95104e8e43ad09fac6d930399ff2b6c3a49c5b6117c8dc03db9300c0ca0364f29425',
username: 'o',
},
])
Expand Down
5 changes: 2 additions & 3 deletions packages/backend/src/nest/storage/storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,9 +738,8 @@ export class StorageService extends EventEmitter {
const onionAddress = getReqFieldValue(parsedCert, CertFieldsTypes.commonName)
const peerId = getReqFieldValue(parsedCert, CertFieldsTypes.peerId)
const username = getReqFieldValue(parsedCert, CertFieldsTypes.nickName)
const dmPublicKey = getReqFieldValue(parsedCert, CertFieldsTypes.dmPublicKey)
if (!onionAddress || !peerId || !username || !dmPublicKey) continue
allUsers.push({ onionAddress, peerId, username, dmPublicKey })
if (!onionAddress || !peerId || !username) continue
allUsers.push({ onionAddress, peerId, username })
}
return allUsers
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ const Template: ComponentStory<typeof ChannelComponent> = () => {
privKey: 'privKey',
pubKey: 'pubKey',
},
dmKeys: {
publicKey: 'publicKey',
privateKey: 'privateKey',
},
userCsr: {
userCsr: 'userCsr',
userKey: 'userKey',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ const args: Partial<ChannelComponentProps & UploadFilesPreviewsProps> = {
privKey: 'privKey',
pubKey: 'pubKey',
},
dmKeys: {
publicKey: 'publicKey',
privateKey: 'privateKey',
},
userCsr: {
userCsr: 'userCsr',
userKey: 'userKey',
Expand Down
22 changes: 5 additions & 17 deletions packages/identity/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export enum CertFieldsTypes {
subjectAltName = '2.5.29.17',
nickName = '1.3.6.1.4.1.50715.2.1',
peerId = '1.3.6.1.2.1.15.3.1.1',
// DEPRECATED
dmPublicKey = '1.2.840.113549.1.9.12',
}

Expand Down Expand Up @@ -100,17 +101,9 @@ export const getCertFieldValue = (cert: Certificate, fieldType: CertFieldsTypes
} else {
const ext = cert.extensions?.find(tav => tav.extnID === fieldType)
if (ext) {
if (fieldType === CertFieldsTypes.dmPublicKey) {
const extObj = ext?.extnValue.valueBlock.value[0]
// @ts-ignore
const arrayBuffer = extObj.valueBlock.valueHex

return arrayBufferToHexString(arrayBuffer)
} else {
const extObj = ext?.extnValue.valueBlock.value[0]
// @ts-ignore
return extObj.valueBlock.value
}
const extObj = ext?.extnValue.valueBlock.value[0]
// @ts-ignore
return extObj.valueBlock.value
} else {
return null
}
Expand All @@ -131,12 +124,7 @@ export const getReqFieldValue = (
} else {
const ext = csr.attributes?.find(tav => tav.type === fieldType)
if (ext) {
if (fieldType === CertFieldsTypes.dmPublicKey) {
const extObj = ext.values[0].valueBlock.valueHex
return arrayBufferToHexString(extObj)
} else {
return ext.values[0].valueBlock.value
}
return ext.values[0].valueBlock.value
} else {
return null
}
Expand Down
13 changes: 6 additions & 7 deletions packages/identity/src/createUserCert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,17 @@ async function generateUserCertificate({
],
})
const attr: Attribute[] | undefined = pkcs10.attributes
let dmPubKey = null
let nickname = null
let peerId = null
let onionAddress = null
let altNames

try {
dmPubKey = attr?.[1].values[0].valueBlock.valueHex
// publicKey = attr[0]

// DEPRECATED
// dmPublicKey = attr[1]

nickname = attr?.[2].values[0].valueBlock.value
peerId = attr?.[3].values[0].valueBlock.value
onionAddress = attr?.[4].values[0].valueBlock.value
Expand All @@ -89,6 +92,7 @@ async function generateUserCertificate({
],
})
} catch (err) {
console.error(err)
throw new Error('Cannot get certificate request extension')
}

Expand All @@ -114,11 +118,6 @@ async function generateUserCertificate({
extnValue: extKeyUsage.toSchema().toBER(false),
parsedValue: extKeyUsage, // Parsed value for well-known extensions
}),
new Extension({
extnID: CertFieldsTypes.dmPublicKey,
critical: false,
extnValue: new OctetString({ valueHex: dmPubKey }).toBER(false),
}),
new Extension({
extnID: CertFieldsTypes.nickName,
critical: false,
Expand Down
16 changes: 8 additions & 8 deletions packages/identity/src/createUserCsr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ export const createUserCsr = async ({
nickname,
commonName,
peerId,
dmPublicKey,
existingKeyPair,
}: {
nickname: string
commonName: string
peerId: string
dmPublicKey: string
signAlg: string
hashAlg: string
existingKeyPair?: CryptoKeyPair
Expand All @@ -35,7 +33,6 @@ export const createUserCsr = async ({
nickname,
commonName,
peerId,
dmPublicKey,
signAlg: config.signAlg,
hashAlg: config.hashAlg,
existingKeyPair,
Expand All @@ -59,23 +56,19 @@ async function requestCertificate({
nickname,
commonName,
peerId,
dmPublicKey,
signAlg = config.signAlg,
hashAlg = config.hashAlg,
existingKeyPair,
}: {
nickname: string
commonName: string
peerId: string
dmPublicKey: string
signAlg: string
hashAlg: string
existingKeyPair?: CryptoKeyPair
}): Promise<CertData> {
const keyPair: CryptoKeyPair = existingKeyPair ? existingKeyPair : await generateKeyPair({ signAlg })

const arrayBufferDmPubKey = hexStringToArrayBuffer(dmPublicKey)

const pkcs10 = new CertificationRequest({
version: 0,
attributes: [],
Expand Down Expand Up @@ -110,10 +103,17 @@ async function requestCertificate({
}).toSchema(),
],
}),

// DEPRECATED
//
// We can only remove this attribute when all owners upgrade to
// the version that contains this commit. Otherwise, there could
// be Quiet instances that still reference this attribute.
new Attribute({
type: CertFieldsTypes.dmPublicKey,
values: [new OctetString({ valueHex: arrayBufferDmPubKey })],
values: [new OctetString({ valueHex: hexStringToArrayBuffer('') })],
}),

new Attribute({
type: CertFieldsTypes.nickName,
values: [new PrintableString({ value: nickname })],
Expand Down
3 changes: 0 additions & 3 deletions packages/identity/src/test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export const userData = {
nickname: 'userName',
commonName: 'nqnw4kc4c77fb47lk52m5l57h4tcxceo7ymxekfn7yh5m66t4jv2olad.onion',
peerId: 'Qmf3ySkYqLET9xtAtDzvAr5Pp3egK1H3C5iJAZm1SpLEp6',
dmPublicKey: '0bfb475810c0e26c9fab590d47c3d60ec533bb3c451596acc3cd4f21602e9ad9',
signAlg: config.signAlg,
hashAlg: config.hashAlg,
}
Expand Down Expand Up @@ -62,7 +61,6 @@ export const createUserCertificateTestHelper = async (
nickname: string
commonName: string
peerId: string
dmPublicKey: string
},
rootCA?: Pick<RootCA, 'rootCertString' | 'rootKeyString'> | null
): Promise<{
Expand All @@ -73,7 +71,6 @@ export const createUserCertificateTestHelper = async (
nickname: user.nickname,
commonName: user.commonName,
peerId: user.peerId,
dmPublicKey: user.dmPublicKey,
signAlg: config.signAlg,
hashAlg: config.hashAlg,
})
Expand Down
3 changes: 0 additions & 3 deletions packages/identity/src/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ describe('Certificate', () => {
[CertFieldsTypes.commonName]: userData.commonName,
[CertFieldsTypes.nickName]: userData.nickname,
[CertFieldsTypes.peerId]: userData.peerId,
[CertFieldsTypes.dmPublicKey]: userData.dmPublicKey,
}
type CertFieldsTypesKeys = keyof typeof certTypeData

Expand All @@ -107,7 +106,6 @@ describe('Certificate', () => {
[CertFieldsTypes.commonName]: userData.commonName,
[CertFieldsTypes.nickName]: userData.nickname,
[CertFieldsTypes.peerId]: userData.peerId,
[CertFieldsTypes.dmPublicKey]: userData.dmPublicKey,
}
type CertFieldsTypesKeys = keyof typeof certTypeData

Expand All @@ -126,7 +124,6 @@ describe('Certificate', () => {
'MIIB7TCCAZMCBgF641h5xzAKBggqhkjOPQQDAjASMRAwDgYDVQQDEwdaYmF5IENBMB4XDTIxMDcyNjE1MDQyNFoXDTMwMDIwMTAwMDAwMFowgc4xgcswHAYKKwYBBAGDjBsCARMOZGV2OTlkZXY5OXlvZGEwPwYDVQQDEzgzNWNzNmZramJoZmJiMnppYnIzNm5rdXY0cWlld2x2NXBmcGprbHh2N2xtcGphM2hydTN3NDdpZDA7BgkrBgECAQ8DAQETLlFtVmIxbUZ2Z1hKZXRKS0o1NmRtR1Q2Rkd1TnJtM0VhVFZ6V3VHaGtxcjZodjUwLQYJKoZIhvcNAQkMBCCf3wijnripB3ZADnDgT1ZIr1zUGjHVZI2K4kt6Yb7CazBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABDKw/zcoE2Vahw3q9CdRQsCXikFU8PhEIN/y65hrB6yAxWH4Ut9QBKMMAnaG8JlzvEeaScQiu5Jyyx0O0xAadQ+jHTAbMAwGA1UdEwQFMAMCAQMwCwYDVR0PBAQDAgAGMAoGCCqGSM49BAMCA0gAMEUCIQCRz+6W3K3SI7Q7uYDVVIJXnWud/DGvpqHCuLJ+gnJLMgIgBmS1D8s1xnGOQpARx40vus4b/f49LQeG2YxPCSHVQOM='
)

expect(getCertFieldValue(parsedCert, CertFieldsTypes.dmPublicKey)).toEqual(null)
expect(getCertFieldValue(parsedCert, CertFieldsTypes.subjectAltName)).toEqual(null)
expect(getCertFieldValue(parsedCert, CertFieldsTypes.peerId)).toEqual(null)
expect(getCertFieldValue(parsedCert, CertFieldsTypes.nickName)).toEqual(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export const UsernameRegistration: FC<UsernameRegistrationProps> = ({
hint={
isNewUser
? 'Your username cannot have any spaces or special characters, must be lowercase letters and numbers only.'
: 'Your username will be public, but you can choose any name you like. No spaces or special characters. Lowercase letters and numbers only. '
: 'Your username will be public, but you can choose any name you like. No spaces or special characters. Lowercase letters and numbers only.'
}
disabled={loading}
validation={inputError}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,11 @@ describe('UsernameRegistration', () => {
currentUsername={'john'}
registeredUsers={{
'BCidRGCBqBPNGNrZ1oml99/qtHjZ6ZtliVzJPpReZk9YC6+aQ1zeooOlpyzv7rNG6nMX2R5ffaVkZZFgEMdNEBg=': {
dmPublicKey:
'1c63a0152f0b0221f96c80aab6777e2569d27a14e991dccd086e34cda1c55d9d6e898efdb9cb5a16d2f90b4155e34abf3261c84e76936ba0105929922feda1fb0615f3254cc56c056cb6144076d0cbdba67cf0fb6687a97d9bb6621bb6b38dcf08aa509f1164212118111f045edc5dab8d315d6e1241cdd10c40883ea420d10d560e48329e086154645035af0668e372a381fbd8aa0912f3581de34b50361cc31adf7a8e811504b6970c9093c058f0fb41ae27df64b09bcb13df84bd23d47a0024463cbb92ee917af3b77b168deb93f6da2d0d13a361969447e16bf249edd872b4797125fa86aad1ce35b1d6ee449359f31c9224a70997d0f0ca38c1f796cede660dd0bb3b1fc9ec251f896bc0aec1603ee8e1278c76d9d1e52adcfa0a06658d631486016efb3b5f44e0c3fb1ce4299834cdf05e',
onionAddress: 'zpu47hphczcuyt3auu5pr2knvimf3adm76gt3g7zbspungjbm3tsy3ad.onion',
peerId: 'QmPrgB2jSFvr7yP3vbLKMLW4JS9hoA9kj2fhN8VjE2NWvJ',
username: 'owner',
},
'BJ50trLih9tvIznBAi69dLNpBV5YiQHCU610UfH3Qm9t3cki9QHWAAhvrfOX+763BH1fwqkOU3JsoBAEF1+USvM=': {
dmPublicKey:
'01161f217d3b372ddefe390b6aed6ada3f21c7ca0d2aacd125840d0c420030b5caec93fbcc1825bb19f38448c1573be814c827b3bce99f6d37b427044687b63799ce0cd7133a654eb2c5644405380399ed0b9140cf0f6d2937008929be8c8ad97cba64e08f7608bb54e0148c8bb30fd2c6df2b8d237cdbfe7ae3d300d896c0ce9e3c5006b687f2e573bedb68152db1954869c21243ef1557eb6d442138ad98e47285f5dd9475fac3a06d2972ae775bdc50d5ab59676d27367c15954b64b0b1a29083ac78934f3f1d0088b73389e29d84f61c60c321770550ecdffa9a24cf0c7fdd279974b5703ce105f22d683530c2f62b36945b3d97f88256f31e1146c3861993a989f5cd99bda647d8744068c3bb44eea407f33109c9c1a0f790f745a6ff2bfd45f5be741fc351549b11d54a4980c4d6d7afb4',
onionAddress: 'lr5d3d64p4hx4mw3uue3ufews23jhl6bfqnsimt7j52igjqdv2zrmsyd.onion',
peerId: 'QmWwMev68izPUKB1PGxkG3UHHXiappQQAnkvUwPSTzrUyy',
username: 'johnny',
Expand Down Expand Up @@ -577,7 +573,7 @@ describe('UsernameRegistration', () => {
}
verticalTextAlign="center"
>
Your username will be public, but you can choose any name you like. No spaces or special characters. Lowercase letters and numbers only.
Your username will be public, but you can choose any name you like. No spaces or special characters. Lowercase letters and numbers only.
</Text>
</View>
<View
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ describe('connectionReducer', () => {
username: alice.nickname,
onionAddress: alice.hiddenService.onionAddress,
peerId: alice.peerId.id,
dmPublicKey: alice.dmKeys.publicKey,
isDuplicated: false,
isRegistered: true,
pubKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { communitiesActions } from '../communities.slice'
import { identityActions } from '../../identity/identity.slice'
import { createRootCA } from '@quiet/identity'
import { type Community, CommunityOwnership, type Identity, SocketActionTypes } from '@quiet/types'
import { generateDmKeyPair } from '../../../utils/cryptography/cryptography'
import { Socket, applyEmitParams } from '../../../types'

export function* createNetworkSaga(
Expand Down Expand Up @@ -55,15 +54,12 @@ export function* createNetworkSaga(
yield* put(communitiesActions.setInvitationCodes(invitationPeers))
}

const dmKeys = yield* call(generateDmKeyPair)

// Identities are tied to communities for now
const identity: Identity = {
id: community.id,
nickname: '',
hiddenService: network.hiddenService,
peerId: network.peerId,
dmKeys,
userCsr: null,
userCertificate: null,
joinTimestamp: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ describe('checkLocalCsr', () => {
nickname: 'alice',
commonName: identity.hiddenService.onionAddress,
peerId: identity.peerId.id,
dmPublicKey: identity.dmKeys.publicKey,
signAlg: 'ECDSA',
hashAlg: 'sha-256',
existingKeyPair,
Expand Down
Loading

0 comments on commit c089c68

Please sign in to comment.