Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
2cbc1b0
super basic picker with logging
Jul 5, 2022
bc51777
Adds SharedDirectoryAnnounce
Jul 6, 2022
bc6586b
Removes recording icon
Jul 6, 2022
fa09ec3
reverting config to its rightful checkin state
Jul 6, 2022
becfad3
updates storybook and storybook test snapshot
Jul 7, 2022
17408f8
Adds types for File System Access API
Jul 7, 2022
edfe30d
prettier
Jul 7, 2022
b9f0690
Adds SharedDirectoryAcknowledge, SharedDirectoryErrCode, updates some…
Jul 7, 2022
b3bf95c
Adds debug to logger
Jul 7, 2022
d69f16d
Adds SharedDirectoryInfoRequest
Jul 7, 2022
3474fed
Updates test with some ts-fu to get the maximum value of a numerical …
Jul 7, 2022
a0c6e9d
Updates babel targets to the latest 2 versions of primary browsers
Jul 13, 2022
1cd8131
Updates Adding Packages section with better instructions
Jul 14, 2022
589bc1e
Merge branch 'master' into isaiah/update-babel-build-targets
Jul 14, 2022
f2970db
super basic picker with logging
Jul 5, 2022
8150acc
Adds SharedDirectoryAnnounce
Jul 6, 2022
d3f9cac
Removes recording icon
Jul 6, 2022
9b5f4c6
updates storybook and storybook test snapshot
Jul 7, 2022
15d8343
Adds types for File System Access API
Jul 7, 2022
ca59266
prettier
Jul 7, 2022
20c14ff
Adds SharedDirectoryAcknowledge, SharedDirectoryErrCode, updates some…
Jul 7, 2022
43f921f
Adds debug to logger
Jul 7, 2022
e779785
Adds SharedDirectoryInfoRequest
Jul 7, 2022
265564f
Updates test with some ts-fu to get the maximum value of a numerical …
Jul 7, 2022
14a6166
swaps out wicg-native-file-system for apparently more up to date wicg…
Jul 12, 2022
317d0d8
adds SharedDirectoryInfoResponse and FileSystemObject to the codec
Jul 12, 2022
6c258ad
Retains existing functionality, substituting in a new sharedDirectory…
Jul 12, 2022
ece73c7
Adds untested walkPath
Jul 18, 2022
a187232
Merge branch 'master' into isaiah/sd-acknowledge
Jul 18, 2022
fe6ea5b
uses consts in decodeSharedDirectoryAcknowledge
Jul 18, 2022
7170e15
Merge branch 'isaiah/sd-acknowledge' into isaiah/sd-info-request
Jul 18, 2022
e54f251
uses consts in decodeSharedDirectoryInfoRequest
Jul 18, 2022
1c2ec0e
uses consts in decodeSharedDirectoryInfoRequest
Jul 18, 2022
d86c2ee
uses consts in decodePngFrame
Jul 18, 2022
85f87e5
uses consts in decodeStringMessage
Jul 18, 2022
f09ec07
uses consts in decodeMfaJson
Jul 18, 2022
a53d2ca
Merge branch 'master' into isaiah/sd-info-request
Jul 18, 2022
868f9d0
Adds __LAST to MessageType enum
Jul 18, 2022
6285d0e
Merge branch 'isaiah/sd-info-request' into isaiah/sd-info-response
Jul 19, 2022
634ad6a
reverting webapps.e change
Jul 19, 2022
e51e4e5
fixes broken merge
Jul 19, 2022
aea3043
creates getInfo for more efficient traversal
Jul 19, 2022
9b1e905
manually tested, cleaning up
Jul 19, 2022
ca89319
Merge branch 'master' into isaiah/sd-info-response
Jul 19, 2022
9a732a5
removing duplicate function definition
Jul 19, 2022
c318873
Adds plumbing for SharedDirectoryListRequest
Jul 19, 2022
ef35ede
adds a FileOrDirInfo type in sharedDirectoryManager and a toFso() in …
Jul 19, 2022
e7551ce
functionality is there with a Promise.all version of listContents, ho…
Jul 20, 2022
69d4b8c
non-promise.all version with better performance
Jul 20, 2022
3654f54
SharedDirectoryReadRequest
Jul 20, 2022
6719855
SharedDirectoryReadResponse
Jul 21, 2022
92757b8
SharedDirectoryWriteRequest
Jul 21, 2022
11eb8ed
SharedDirectoryWriteResponse
Jul 21, 2022
a4ef72b
wrapping in try-catch
Jul 27, 2022
5049763
Merge branch 'master' into isaiah/sd-write-response
Jul 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions packages/teleport/src/lib/tdp/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import Codec, {
SharedDirectoryInfoResponse,
SharedDirectoryListResponse,
SharedDirectoryReadResponse,
SharedDirectoryWriteResponse,
FileSystemObject,
} from './codec';
import {
Expand Down Expand Up @@ -276,12 +277,23 @@ export default class Client extends EventEmitterWebAuthnSender {
}
}

handleSharedDirectoryWriteRequest(buffer: ArrayBuffer) {
async handleSharedDirectoryWriteRequest(buffer: ArrayBuffer) {
const req = this.codec.decodeSharedDirectoryWriteRequest(buffer);
// TODO(isaiah): delete debug logs
this.logger.debug('Received SharedDirectoryWriteRequest:');
this.logger.debug(req);
// TODO(isaiah): here's where we'll respond with a SharedDirectoryWriteResponse
try {
const bytesWritten = await this.sdManager.writeFile(
req.path,
req.offset,
req.writeData
);

this.sendSharedDirectoryWriteResponse({
completionId: req.completionId,
errCode: SharedDirectoryErrCode.Nil,
bytesWritten,
});
} catch (e) {
this.handleError(e);
}
}

async handleSharedDirectoryListRequest(buffer: ArrayBuffer) {
Expand Down Expand Up @@ -394,6 +406,10 @@ export default class Client extends EventEmitterWebAuthnSender {
this.send(this.codec.encodeSharedDirectoryReadResponse(response));
}

sendSharedDirectoryWriteResponse(response: SharedDirectoryWriteResponse) {
this.send(this.codec.encodeSharedDirectoryWriteResponse(response));
}

resize(spec: ClientScreenSpec) {
this.send(this.codec.encodeClientScreenSpec(spec));
}
Expand Down
28 changes: 28 additions & 0 deletions packages/teleport/src/lib/tdp/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export enum MessageType {
SHARED_DIRECTORY_READ_REQUEST = 19,
SHARED_DIRECTORY_READ_RESPONSE = 20,
SHARED_DIRECTORY_WRITE_REQUEST = 21,
SHARED_DIRECTORY_WRITE_RESPONSE = 22,
SHARED_DIRECTORY_LIST_REQUEST = 25,
SHARED_DIRECTORY_LIST_RESPONSE = 26,
__LAST, // utility value
Expand Down Expand Up @@ -149,6 +150,13 @@ export type SharedDirectoryWriteRequest = {
writeData: Uint8Array;
};

// | message type (22) | completion_id uint32 | err_code uint32 | bytes_written uint32 |
export type SharedDirectoryWriteResponse = {
completionId: number;
errCode: number;
bytesWritten: number;
};

// | message type (25) | completion_id uint32 | directory_id uint32 | path_length uint32 | path []byte |
export type SharedDirectoryListRequest = {
completionId: number;
Expand Down Expand Up @@ -570,6 +578,26 @@ export default class Codec {
return buffer;
}

encodeSharedDirectoryWriteResponse(
res: SharedDirectoryWriteResponse
): Message {
const bufLen = byteLength + 3 * uint32Length;
const buffer = new ArrayBuffer(bufLen);
const view = new DataView(buffer);
let offset = 0;

view.setUint8(offset, MessageType.SHARED_DIRECTORY_WRITE_RESPONSE);
offset += byteLength;
view.setUint32(offset, res.completionId);
offset += uint32Length;
view.setUint32(offset, res.errCode);
offset += uint32Length;
view.setUint32(offset, res.bytesWritten);
offset += uint32Length;

return buffer;
}

// | message type (26) | completion_id uint32 | err_code uint32 | fso_list_length uint32 | fso_list fso[] |
encodeSharedDirectoryListResponse(res: SharedDirectoryListResponse): Message {
const bufLenSansFsoList = byteLength + 3 * uint32Length;
Expand Down
23 changes: 23 additions & 0 deletions packages/teleport/src/lib/tdp/sharedDirectoryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,29 @@ export class SharedDirectoryManager {
);
}

// Writes the bytes in writeData to the file at path starting at offset.
async writeFile(
path: string,
offset: bigint,
writeData: Uint8Array
): Promise<number> {
this.checkReady();

const fileHandle = await this.walkPath(path);
if (fileHandle.kind !== 'file') {
throw new Error('cannot read the bytes of a directory');
}

const file = await fileHandle.createWritable();
if (offset > 0) {
file.seek(Number(offset));
}
file.write(writeData);
file.close(); // Needed to actually write data to disk.

return writeData.length;
}

// walkPath walks a pathstr (assumed to be in the qualified Unix format specified
// in the TDP spec), returning the FileSystemDirectoryHandle | FileSystemFileHandle
// it finds at its end. If the pathstr isn't a valid path in the shared directory,
Expand Down
64 changes: 0 additions & 64 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10412,70 +10412,6 @@ node-gyp@8.4.1:
tar "^6.1.2"
which "^2.0.2"

node-gyp@8.4.1:
version "8.4.1"
resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-8.4.1.tgz#3d49308fc31f768180957d6b5746845fbd429937"
integrity sha512-olTJRgUtAb/hOXG0E93wZDs5YiJlgbXxTwQAFHyNlRsXQnYzUaF2aGgujZbw+hR8aF4ZG/rST57bWMWD16jr9w==
dependencies:
env-paths "^2.2.0"
glob "^7.1.4"
graceful-fs "^4.2.6"
make-fetch-happen "^9.1.0"
nopt "^5.0.0"
npmlog "^6.0.0"
rimraf "^3.0.2"
semver "^7.3.5"
tar "^6.1.2"
which "^2.0.2"

node-gyp@8.4.1:
version "8.4.1"
resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-8.4.1.tgz#3d49308fc31f768180957d6b5746845fbd429937"
integrity sha512-olTJRgUtAb/hOXG0E93wZDs5YiJlgbXxTwQAFHyNlRsXQnYzUaF2aGgujZbw+hR8aF4ZG/rST57bWMWD16jr9w==
dependencies:
env-paths "^2.2.0"
glob "^7.1.4"
graceful-fs "^4.2.6"
make-fetch-happen "^9.1.0"
nopt "^5.0.0"
npmlog "^6.0.0"
rimraf "^3.0.2"
semver "^7.3.5"
tar "^6.1.2"
which "^2.0.2"

node-gyp@8.4.1:
version "8.4.1"
resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-8.4.1.tgz#3d49308fc31f768180957d6b5746845fbd429937"
integrity sha512-olTJRgUtAb/hOXG0E93wZDs5YiJlgbXxTwQAFHyNlRsXQnYzUaF2aGgujZbw+hR8aF4ZG/rST57bWMWD16jr9w==
dependencies:
env-paths "^2.2.0"
glob "^7.1.4"
graceful-fs "^4.2.6"
make-fetch-happen "^9.1.0"
nopt "^5.0.0"
npmlog "^6.0.0"
rimraf "^3.0.2"
semver "^7.3.5"
tar "^6.1.2"
which "^2.0.2"

node-gyp@8.4.1:
version "8.4.1"
resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-8.4.1.tgz#3d49308fc31f768180957d6b5746845fbd429937"
integrity sha512-olTJRgUtAb/hOXG0E93wZDs5YiJlgbXxTwQAFHyNlRsXQnYzUaF2aGgujZbw+hR8aF4ZG/rST57bWMWD16jr9w==
dependencies:
env-paths "^2.2.0"
glob "^7.1.4"
graceful-fs "^4.2.6"
make-fetch-happen "^9.1.0"
nopt "^5.0.0"
npmlog "^6.0.0"
rimraf "^3.0.2"
semver "^7.3.5"
tar "^6.1.2"
which "^2.0.2"

node-int64@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b"
Expand Down