-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**概要** `Network`クラス内でオブジェクト化している`SkyWayConnection`クラスの実装を 現在の"src\app\class\core\system\network\skyway\skyway-connection.ts"から 新規実装した"src\app\class\core\system\network\skyway2023\skyway-connection.ts"に 切り替えることで新しいSkyWayを使用した通信処理が可能になる. **制約** - 新しいSkyWayのChannelの概念の都合からユドナリウムのプライベート接続をオミットしている. - 現状のコードはバックエンドのモック実装を含んでおりセキュリティ的に問題があるため本番環境で使用してはならない.(詳細は下記) **シークレットキーの取り扱いについて** 新しいSkyWayはJWTによる権限管理を行っており、JWTの署名に使用するシークレットキーはクライアントに秘匿される必要がある. しかし、現状のコードではバックエンド処理(`SkyWayBackend`)がモックとなっておりシークレットキーが秘匿されないため危険である. 安全に運用するためにはJWTを発行するWeb APIなどの準備が別途必要.
- Loading branch information
Showing
8 changed files
with
1,736 additions
and
11 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/app/class/core/system/network/skyway2023/skyway-backend.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { ChannelScope, nowInSec, SkyWayAuthToken, uuidV4 } from '@skyway-sdk/core'; | ||
|
||
export namespace SkyWayBackend { | ||
export async function createSkyWayAuthToken(appId: string, channelName: string, peerId: string): Promise<string> { | ||
return createSkyWayAuthTokenMock(appId, channelName, peerId); | ||
} | ||
} | ||
|
||
/** | ||
* SkyWayAuthTokenを生成するモック実装. | ||
* | ||
* **シークレットキーはフロントエンドでは秘匿されている必要があります. この実装を本番環境で運用しないでください.** | ||
* | ||
* サーバを構築せずにフロントエンドでSkyWayAuthTokenを生成した場合、 | ||
* シークレットキーをエンドユーザが取得できるため、誰でも任意のChannelやRoomを生成して参加できる等のセキュリティ上の問題が発生します. | ||
* | ||
* @param appId アプリケーションID | ||
* @param channelName 接続するチャンネルの名称 | ||
* @param peerId PeerId | ||
* @returns JWT | ||
*/ | ||
async function createSkyWayAuthTokenMock(appId: string, channelName: string, peerId: string): Promise<string> { | ||
// モック実装のため、アプリケーションIDとシークレットキーは固定値 | ||
// 本番環境ではシークレットキーをサーバなどに置いて秘匿する | ||
const _appId = '<SkyWay2023 Application ID>'; | ||
const _secret = '<SkyWay2023 Secret key>'; | ||
|
||
const _lobbySize = 4; | ||
|
||
let lobbyChannels: ChannelScope[] = []; | ||
for (let index = 0; index < _lobbySize; index++) { | ||
lobbyChannels.push({ | ||
name: `udonarium-lobby-${index}`, | ||
actions: ['read', 'create'], | ||
members: [ | ||
{ | ||
name: peerId, | ||
actions: ['write'], | ||
publication: { | ||
actions: [], | ||
}, | ||
subscription: { | ||
actions: [], | ||
}, | ||
}, | ||
], | ||
}); | ||
} | ||
|
||
let roomChannels: ChannelScope[] = []; | ||
roomChannels.push({ | ||
name: channelName, | ||
actions: ['read', 'create'], | ||
members: [ | ||
{ | ||
name: peerId, | ||
actions: ['write'], | ||
publication: { | ||
actions: ['write'], | ||
}, | ||
subscription: { | ||
actions: ['write'], | ||
}, | ||
}, | ||
{ | ||
name: '*', | ||
actions: ['signal'], | ||
publication: { | ||
actions: [], | ||
}, | ||
subscription: { | ||
actions: [], | ||
}, | ||
}, | ||
], | ||
}); | ||
|
||
let token = new SkyWayAuthToken({ | ||
jti: uuidV4(), | ||
iat: nowInSec(), | ||
exp: nowInSec() + 60 * 60 * 24, | ||
scope: { | ||
app: { | ||
id: _appId, | ||
turn: false, | ||
actions: ['read'], | ||
channels: lobbyChannels.concat(roomChannels), | ||
}, | ||
}, | ||
}).encode(_secret); | ||
|
||
return token; | ||
} |
Oops, something went wrong.