Skip to content

Commit dfa50ef

Browse files
committed
【feat】新增瓦片解密库; review by luox
1 parent e255151 commit dfa50ef

File tree

8 files changed

+25
-82
lines changed

8 files changed

+25
-82
lines changed

build/webpack.config.base.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,7 @@ module.exports = {
5858

5959
//其它解决方案配置
6060
resolve: {
61-
extensions: ['.js', '.json', '.css'],
62-
fallback: {
63-
crypto: false,
64-
stream: false,
65-
vm: false
66-
}
61+
extensions: ['.js', '.json', '.css']
6762
},
6863

6964
externals: {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
"@mapbox/vector-tile": "1.3.1",
134134
"@sinonjs/text-encoding": "^0.7.2",
135135
"@supermap/iclient-common": "file:src/common",
136+
"@supermap/tile-decryptor": "^0.0.1",
136137
"@tensorflow/tfjs": "^3.9.0",
137138
"@turf/turf": "6.5.0",
138139
"canvg": "3.0.10",

src/common/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"license": "Apache-2.0",
1616
"dependencies": {
1717
"@antv/g6": "^4.8.14",
18+
"@supermap/tile-decryptor": "^0.0.1",
1819
"echarts": "5.4.3",
1920
"fetch-ie8": "1.5.0",
2021
"fetch-jsonp": "1.1.3",

src/common/util/EncryptRequest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {
99
import URI from 'urijs';
1010

1111
/**
12-
* @private
1312
* @name EncryptRequest
13+
* @version 11.2.0
1414
* @namespace
1515
* @category BaseTypes Util
1616
* @classdesc 加密请求地址
@@ -173,7 +173,7 @@ export async function getServiceKey(serviceUrl) {
173173
method: 'get',
174174
url: svckeyUrl
175175
});
176-
return await svcReponse.json();
176+
return svcReponse.json();
177177
} catch (error) {
178178
console.error(error);
179179
}

src/common/util/RequestcryptUtil.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import pki from 'node-forge/lib/pki';
2-
import md from 'node-forge/lib/md';
3-
import cipher from 'node-forge/lib/cipher';
4-
import util from 'node-forge/lib/util';
1+
// import pki from 'node-forge/lib/pki';
2+
// import md from 'node-forge/lib/md';
3+
// import cipher from 'node-forge/lib/cipher';
4+
// import util from 'node-forge/lib/util';
5+
import { pki, md, cipher, util } from 'node-forge/dist/forge.min';
56

67
/**
78
* @private

src/openlayers/overlay/VectorTileSuperMapRest.js

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { Util } from '../core/Util';
55
import { SecurityManager } from '@supermap/iclient-common/security/SecurityManager';
66
import { FetchRequest } from '@supermap/iclient-common/util/FetchRequest';
7-
import { EncryptRequest } from '@supermap/iclient-common/util/EncryptRequest';
7+
import { getServiceKey } from '@supermap/iclient-common/util/EncryptRequest';
88
import { Unit } from '@supermap/iclient-common/REST';
99
import { Util as CommonUtil } from '@supermap/iclient-common/commontypes/Util';
1010
import { Bounds } from '@supermap/iclient-common/commontypes/Bounds';
@@ -17,7 +17,7 @@ import GeoJSON from 'ol/format/GeoJSON';
1717
import * as olSize from 'ol/size';
1818
import Projection from 'ol/proj/Projection';
1919
import TileGrid from 'ol/tilegrid/TileGrid';
20-
import decodeUtil from './bundle.esm';
20+
import decryptTileUtil from '@supermap/tile-decryptor';
2121

2222
/**
2323
* @class VectorTileSuperMapRest
@@ -271,10 +271,7 @@ export class VectorTileSuperMapRest extends VectorTile {
271271
source = xhr.response;
272272
}
273273
if (source) {
274-
// console.time('瓦片解密完成');
275274
source = me._decryptMvt(source);
276-
// console.timeEnd('瓦片解密完成');
277-
// console.log('瓦片解密字节大小: ', source.byteLength);
278275
if (['4', '5'].indexOf(Util.getOlVersion()) > -1) {
279276
success.call(
280277
this,
@@ -395,32 +392,15 @@ export class VectorTileSuperMapRest extends VectorTile {
395392
const firstSource = Object.keys(options.style.sources)[0];
396393
serviceUrl = options.style.sources[firstSource].tiles[0];
397394
}
398-
const workspaceServerUrl = (serviceUrl && serviceUrl.match(/.+(?=(\/restjsr\/v1\/vectortile\/|\/rest\/maps\/))/) || [])[0];
399-
if (!workspaceServerUrl) {
400-
return;
401-
}
402-
const servicesResponse = await FetchRequest.get(workspaceServerUrl);
403-
const servicesResult = await servicesResponse.json();
404-
const matchRestData = (servicesResult || []).find(item => serviceUrl.includes(item.name) && item.serviceEncryptInfo);
405-
if (!matchRestData) {
406-
return;
407-
}
408-
const iserverHost = workspaceServerUrl.split('/services/')[0];
409-
const encryptRequest = new EncryptRequest(iserverHost);
410-
const svckeyUrl = matchRestData && `${iserverHost}/services/security/svckeys/${matchRestData.serviceEncryptInfo.encrptKeyID}.json`
411-
const svcReponse = await encryptRequest.request({
412-
method: 'get',
413-
url: svckeyUrl
414-
})
415-
this.serviceKey = await svcReponse.json();
395+
this.serviceKey = await getServiceKey(serviceUrl);
416396
} catch (error) {
417397
console.error(error);
418398
}
419399
}
420400

421401
_decryptMvt(mvtData) {
422402
if (this.serviceKey) {
423-
return decodeUtil(mvtData, this.serviceKey);
403+
return decryptTileUtil(mvtData, this.serviceKey);
424404
}
425405
return mvtData;
426406
}

test/common/util/EncryptFetchRequestUtilSpec.js renamed to test/common/util/EncryptRequestSpec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ describe('EncryptRequest', () => {
5353
const encryptRequest = new EncryptRequest(serverUrl);
5454
encryptRequest.encryptAESKey = 'SLbsaRbf4Rou8Bju';
5555
encryptRequest.encryptAESIV = 'rzLM7Z4RJGFd';
56-
encryptRequest.request(options).then((result) => {
56+
encryptRequest.request(options).then(res => res.json()).then((result) => {
5757
expect(result).toBe('l3nQtAUM4li87qMfO68exInHVFQ5gS3a6pb8ySIbib8=');
5858
expect(spyGet.calls.count()).toBe(1);
5959
expect(spyPost.calls.count()).toBe(1);
6060
expect(spyCommit.calls.count()).toBe(1);
6161
expect(encryptRequest.tunnelUrl).not.toBeUndefined();
62-
encryptRequest.request(options).then(result => {
62+
encryptRequest.request(options).then(res => res.json()).then(result => {
6363
expect(result).toBe('l3nQtAUM4li87qMfO68exInHVFQ5gS3a6pb8ySIbib8=');
6464
expect(FetchRequest.get.calls.count()).toBe(1);
6565
expect(FetchRequest.post.calls.count()).toBe(1);

test/openlayers/overlay/VectorTileSuperMapRestSpec.js

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { VectorTileSuperMapRest } from '../../../src/openlayers/overlay/VectorTileSuperMapRest';
22
import { FetchRequest } from '@supermap/iclient-common/util/FetchRequest';
3-
import * as RequestcryptUtil from '@supermap/iclient-common/util/RequestcryptUtil';
3+
import { EncryptRequest } from '@supermap/iclient-common/util/EncryptRequest';
44
import { MapService } from '../../../src/openlayers/services/MapService';
55
import Map from 'ol/Map';
66
import View from 'ol/View';
@@ -59,7 +59,7 @@ const mapObject = {
5959
};
6060
describe('openlayers_VectorTileSuperMapRest', () => {
6161
var testDiv, map, vectorTileOptions, vectorTileSource, originalTimeout, vectorLayer, spyGet, spyPost, spyCommit;
62-
const mockCallback = (testUrl, method) => {
62+
const mockCallback = (testUrl) => {
6363
if ((url.match(/.+(?=(\/restjsr\/v1\/vectortile\/|\/rest\/maps\/))/) || [])[0] === testUrl) {
6464
return Promise.resolve(
6565
new Response(
@@ -80,33 +80,6 @@ describe('openlayers_VectorTileSuperMapRest', () => {
8080
])
8181
)
8282
);
83-
} else if (testUrl.includes('/security/tunnel/v1/publickey')) {
84-
return Promise.resolve(
85-
new Response(
86-
JSON.stringify({
87-
keyLength: 2048,
88-
publicKey:
89-
'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2BQweGm/+YpzPn/QaRvkOYQQOwO0LI52NSdtJDehARLvFLfKfpaXs2Qks2VISYX8bl1aBRtS5m5/Z8mdo41k2XM9sRUKldF5M0gTUqKWUnDkS6INnNfsW4VsHNizIiZY7YvQA2cwl/4eYm4YF5Qy3KugPGrxt5KxZvh8O7b6si9JwLwIx53Y5oRbFttCHdjWR4mqFTzTR/yD4K1xYo/fizdvqUmWLhfpirHQsWv3WLaUOdEj36nDGBxuqahQ5JbH3VeASdbJQRTp+0QQcfpZ1x0GxXJWstemCrCUETQIQczYtj98qxSqknC8HZQhDz8F31NFV4341vrGKgOzrsq5HQIDAQAB',
90-
keyScheme: 'PKCS#8'
91-
})
92-
)
93-
);
94-
} else if (testUrl.includes('/services/security/tunnel/v1/tunnels/')) {
95-
const response =
96-
'HAsHE/ok/jROEySWBxWSr2FTLXcnIkeFAYzig+V7NGalR0f/VnBorkAOyOnbCSq9nM3YWrhEUFaWwAouSDeEVqe+BLuIA+7KmCBfD7hh+qyM0lC5cvZ8vOIjsI3eqhHhiPOi+IQLGHQsRbFl8hSkE0XU1GIojqjppSEAxW5jhFC2bH5hdCt/+PKuHPhATElgJqOI6FJHpVpbLWiqoP7WMYVYvZm7wubYCQIG77LUSivbUQ61gjW0mevsKRdoiRl8fafV8Zq5D+QBbCy+Mn4rWXDC+gjwvyyYxEdOixALJgfnjWL48RRHxvITPapzbEsEkcnZiu+INSULcT60BeuduKzxp+hUg6Q8sn2Bu//CNk0NlGMeT5hqTON72iI4GBgfEOnGrcBHjsT/N2jX0NnVz1bgR6B9O6TpQQr3zkjVPidw8ElSO+lM8P5AuRqtNH9ajYt2uDwWBhbG+OfyR4hKIJ9V5aDhAwkIzkUerRP78Colsg==';
97-
return Promise.resolve({ text: () => Promise.resolve(response) });
98-
} else if (testUrl.includes('/services/security/tunnel/v1/tunnels')) {
99-
const response = {
100-
blockedUrlRegex: {
101-
DELETE: [],
102-
POST: [],
103-
GET: ['.*/services/security/svckeys/[a-zA-Z]+\\.json'],
104-
PUT: []
105-
},
106-
tunnelUrl:
107-
'http://fake.iserver.com/iserver/services/security/tunnel/v1/tunnels/UUV6U25KNkVSNHhnQTYzcFVOTnZlNm9KVEVWZE4yeXVPNHlEVHAzeEZ2UnQ3WmtxS29qZURXQi9HcDBDYjNtM1FaOHFabGQwclduNGNzNjFjck1PbmFyakdOcGxQR25id2dQZ2ljY1NWdU5lMWg3dzV4UUtDQktyQ3doc3MzWnhmTkdNNWU3V01FZ21XNWJsR3pVdEtJenRpQXRTQ2RYQVBkN1oxRGNhNTh1a2pGSG1rUUZBeStjYVZPMXJ3NXFJcUdxN05ack1SNEEzNWRwNEZVNWV6ME96anYwN0tQempHZVl2U2VHa3YxRlc1R3ZXUW9KNmgwb290MjE1cEVZT2xNdzAwdXBidWpNOTQ2ck1iR1FFajFVUEtpeSt0OU9xdzdON0ZpZnhkTjEvRlF2cFpHN3ZBalVPV0ovVkNDdU9nN3RyU081SlhRMlZVQXhsbDlkMHZnPT0=.json'
108-
};
109-
return Promise.resolve(new Response(JSON.stringify(response)));
11083
}
11184
return Promise.resolve(new Response(JSON.stringify(mapObject)));
11285
};
@@ -121,8 +94,8 @@ describe('openlayers_VectorTileSuperMapRest', () => {
12194
window.document.body.appendChild(testDiv);
12295
});
12396
beforeEach(() => {
124-
// originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
125-
// jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
97+
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
98+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
12699

127100
spyGet = spyOn(FetchRequest, 'get').and.callFake((url) => mockCallback(url, 'GET'));
128101
spyPost = spyOn(FetchRequest, 'post').and.callFake((url) => mockCallback(url, 'POST'));
@@ -132,7 +105,7 @@ describe('openlayers_VectorTileSuperMapRest', () => {
132105
if (vectorLayer) {
133106
map.removeLayer(vectorLayer);
134107
}
135-
// jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
108+
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
136109
spyGet.calls.reset();
137110
spyPost.calls.reset();
138111
spyCommit.calls.reset();
@@ -141,7 +114,7 @@ describe('openlayers_VectorTileSuperMapRest', () => {
141114
window.document.body.removeChild(testDiv);
142115
});
143116

144-
xit('initialize', (done) => {
117+
it('initialize', (done) => {
145118
new MapService(url).getMapInfo((serviceResult) => {
146119
map = new Map({
147120
target: 'map',
@@ -169,7 +142,7 @@ describe('openlayers_VectorTileSuperMapRest', () => {
169142
map.addLayer(vectorLayer);
170143
});
171144
});
172-
xit('custom_tileLoadFunction', (done) => {
145+
it('custom_tileLoadFunction', (done) => {
173146
var spy = jasmine.createSpy('test');
174147
var tileLoadFunction = (tile) => {
175148
tile.setLoader(() => {
@@ -202,16 +175,7 @@ describe('openlayers_VectorTileSuperMapRest', () => {
202175

203176
it('mvt_decrypt ', (done) => {
204177
const spy = jasmine.createSpy('test');
205-
// function EncryptRequestTest() {}
206-
// EncryptRequestTest.prototype.request = function (options) {
207-
// console.log(111111111111111111111111111, optios.url);
208-
// spy();
209-
// return Promise.resolve({ json: () => Promise.resolve('l3nQtAUM4li87qMfO68exInHVFQ5gS3a6pb8ySIbib8=') });
210-
// };
211-
// const spyEncrypt = spyOn(EncryptRequestHelper, 'EncryptRequest').and.returnValue(EncryptRequestTest);
212-
// RequestcryptUtil.generateAESRandomKey = () => 'SLbsaRbf4Rou8Bju';
213-
// RequestcryptUtil.generateAESRandomIV = () => 'rzLM7Z4RJGFd';
214-
const spyEncrypt = spyOn(RequestcryptUtil, 'AESGCMDecrypt').and.returnValue(true);
178+
const spyEncrypt = spyOn(EncryptRequest.prototype, 'request').and.callFake(() => ({ json: () => Promise.resolve('l3nQtAUM4li87qMfO68exInHVFQ5gS3a6pb8ySIbib8=')}));
215179
new MapService(url).getMapInfo((serviceResult) => {
216180
map = new Map({
217181
target: 'map',
@@ -239,6 +203,7 @@ describe('openlayers_VectorTileSuperMapRest', () => {
239203
vectorLayer.getSource().once('tileloadend', () => {
240204
expect(vectorTileOptions).not.toBeNull();
241205
expect(spy.calls.count()).toBe(1);
206+
expect(spyEncrypt).toHaveBeenCalled();
242207
expect(vectorTileSource.serviceKey).not.toBeUndefined();
243208
spy.calls.reset();
244209
spyEncrypt.calls.reset();

0 commit comments

Comments
 (0)