diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-17 15:20:42 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:52 +0100 |
commit | 9a27cdc27c900feaae5f6db4315c4ccdfc0c4493 (patch) | |
tree | f91fcfa0fa1a2e45aae1c5333ef2f7ec60e56ef0 /server/helpers | |
parent | 975e6e0e44e2f2b25f804cd48a62e2a8d9e8117a (diff) | |
download | PeerTube-9a27cdc27c900feaae5f6db4315c4ccdfc0c4493.tar.gz PeerTube-9a27cdc27c900feaae5f6db4315c4ccdfc0c4493.tar.zst PeerTube-9a27cdc27c900feaae5f6db4315c4ccdfc0c4493.zip |
Optimize signature verification
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/activitypub.ts | 6 | ||||
-rw-r--r-- | server/helpers/custom-jsonld-signature.ts | 20 | ||||
-rw-r--r-- | server/helpers/custom-validators/activitypub/misc.ts | 4 | ||||
-rw-r--r-- | server/helpers/peertube-crypto.ts | 5 |
4 files changed, 28 insertions, 7 deletions
diff --git a/server/helpers/activitypub.ts b/server/helpers/activitypub.ts index 6f216e106..aff58515a 100644 --- a/server/helpers/activitypub.ts +++ b/server/helpers/activitypub.ts | |||
@@ -8,7 +8,7 @@ import { ActivityPubActor } from '../../shared/models/activitypub/activitypub-ac | |||
8 | import { VideoChannelObject } from '../../shared/models/activitypub/objects/video-channel-object' | 8 | import { VideoChannelObject } from '../../shared/models/activitypub/objects/video-channel-object' |
9 | import { ResultList } from '../../shared/models/result-list.model' | 9 | import { ResultList } from '../../shared/models/result-list.model' |
10 | import { database as db, REMOTE_SCHEME } from '../initializers' | 10 | import { database as db, REMOTE_SCHEME } from '../initializers' |
11 | import { ACTIVITY_PUB_ACCEPT_HEADER, CONFIG, STATIC_PATHS } from '../initializers/constants' | 11 | import { ACTIVITY_PUB, CONFIG, STATIC_PATHS } from '../initializers/constants' |
12 | import { videoChannelActivityObjectToDBAttributes } from '../lib/activitypub/misc' | 12 | import { videoChannelActivityObjectToDBAttributes } from '../lib/activitypub/misc' |
13 | import { sendVideoAnnounce } from '../lib/activitypub/send-request' | 13 | import { sendVideoAnnounce } from '../lib/activitypub/send-request' |
14 | import { sendVideoChannelAnnounce } from '../lib/index' | 14 | import { sendVideoChannelAnnounce } from '../lib/index' |
@@ -99,7 +99,7 @@ async function fetchRemoteAccountAndCreateServer (accountUrl: string) { | |||
99 | uri: accountUrl, | 99 | uri: accountUrl, |
100 | method: 'GET', | 100 | method: 'GET', |
101 | headers: { | 101 | headers: { |
102 | 'Accept': ACTIVITY_PUB_ACCEPT_HEADER | 102 | 'Accept': ACTIVITY_PUB.ACCEPT_HEADER |
103 | } | 103 | } |
104 | } | 104 | } |
105 | 105 | ||
@@ -157,7 +157,7 @@ async function fetchRemoteVideoChannel (ownerAccount: AccountInstance, videoChan | |||
157 | uri: videoChannelUrl, | 157 | uri: videoChannelUrl, |
158 | method: 'GET', | 158 | method: 'GET', |
159 | headers: { | 159 | headers: { |
160 | 'Accept': ACTIVITY_PUB_ACCEPT_HEADER | 160 | 'Accept': ACTIVITY_PUB.ACCEPT_HEADER |
161 | } | 161 | } |
162 | } | 162 | } |
163 | 163 | ||
diff --git a/server/helpers/custom-jsonld-signature.ts b/server/helpers/custom-jsonld-signature.ts new file mode 100644 index 000000000..afb960618 --- /dev/null +++ b/server/helpers/custom-jsonld-signature.ts | |||
@@ -0,0 +1,20 @@ | |||
1 | import * as AsyncLRU from 'async-lru' | ||
2 | import * as jsonld from 'jsonld' | ||
3 | import * as jsig from 'jsonld-signatures' | ||
4 | |||
5 | jsig.use('jsonld', jsonld) | ||
6 | |||
7 | const nodeDocumentLoader = jsonld.documentLoaders.node() | ||
8 | |||
9 | const lru = new AsyncLRU({ | ||
10 | max: 10, | ||
11 | load: (key, cb) => { | ||
12 | nodeDocumentLoader(key, cb) | ||
13 | } | ||
14 | }) | ||
15 | |||
16 | jsonld.documentLoader = (url, cb) => { | ||
17 | lru.get(url, cb) | ||
18 | } | ||
19 | |||
20 | export { jsig } | ||
diff --git a/server/helpers/custom-validators/activitypub/misc.ts b/server/helpers/custom-validators/activitypub/misc.ts index f09a764b6..1bbfd0fc4 100644 --- a/server/helpers/custom-validators/activitypub/misc.ts +++ b/server/helpers/custom-validators/activitypub/misc.ts | |||
@@ -28,6 +28,10 @@ function isBaseActivityValid (activity: any, type: string) { | |||
28 | ( | 28 | ( |
29 | activity.to === undefined || | 29 | activity.to === undefined || |
30 | (Array.isArray(activity.to) && activity.to.every(t => isActivityPubUrlValid(t))) | 30 | (Array.isArray(activity.to) && activity.to.every(t => isActivityPubUrlValid(t))) |
31 | ) && | ||
32 | ( | ||
33 | activity.cc === undefined || | ||
34 | (Array.isArray(activity.cc) && activity.cc.every(t => isActivityPubUrlValid(t))) | ||
31 | ) | 35 | ) |
32 | } | 36 | } |
33 | 37 | ||
diff --git a/server/helpers/peertube-crypto.ts b/server/helpers/peertube-crypto.ts index 04a8d5681..c61abfa8e 100644 --- a/server/helpers/peertube-crypto.ts +++ b/server/helpers/peertube-crypto.ts | |||
@@ -1,7 +1,3 @@ | |||
1 | import * as jsonld from 'jsonld' | ||
2 | import * as jsig from 'jsonld-signatures' | ||
3 | jsig.use('jsonld', jsonld) | ||
4 | |||
5 | import { | 1 | import { |
6 | PRIVATE_RSA_KEY_SIZE, | 2 | PRIVATE_RSA_KEY_SIZE, |
7 | BCRYPT_SALT_SIZE | 3 | BCRYPT_SALT_SIZE |
@@ -15,6 +11,7 @@ import { | |||
15 | } from './core-utils' | 11 | } from './core-utils' |
16 | import { logger } from './logger' | 12 | import { logger } from './logger' |
17 | import { AccountInstance } from '../models/account/account-interface' | 13 | import { AccountInstance } from '../models/account/account-interface' |
14 | import { jsig } from './custom-jsonld-signature' | ||
18 | 15 | ||
19 | async function createPrivateAndPublicKeys () { | 16 | async function createPrivateAndPublicKeys () { |
20 | logger.info('Generating a RSA key...') | 17 | logger.info('Generating a RSA key...') |