-
Notifications
You must be signed in to change notification settings - Fork 2
SSH agent forwarding #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: denis-coric/ssh-flow
Are you sure you want to change the base?
Changes from all commits
51a4a35
f6fb9eb
61b3595
3e0e5c0
4a2b273
0f3d3b8
39be87e
dbef641
9545ac2
24d499c
df603ef
7e5d6d9
59aef6e
ebfff2d
0570c4c
e5da79c
ab0bdbe
b72d222
55d06ab
f6281d6
5e3e13e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,4 +31,5 @@ export const { | |
| updateUser, | ||
| addPublicKey, | ||
| removePublicKey, | ||
| getPublicKeys, | ||
| } = users; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import { AuthorisedRepo } from '../config/generated/config'; | ||
| import { PushQuery, Repo, RepoQuery, Sink, User, UserQuery } from './types'; | ||
| import { PushQuery, Repo, RepoQuery, Sink, User, UserQuery, PublicKeyRecord } from './types'; | ||
| import * as bcrypt from 'bcryptjs'; | ||
| import * as config from '../config'; | ||
| import * as mongo from './mongo'; | ||
|
|
@@ -171,9 +171,11 @@ export const findUserBySSHKey = (sshKey: string): Promise<User | null> => | |
| sink.findUserBySSHKey(sshKey); | ||
| export const getUsers = (query?: Partial<UserQuery>): Promise<User[]> => sink.getUsers(query); | ||
| export const deleteUser = (username: string): Promise<void> => sink.deleteUser(username); | ||
| export const updateUser = (user: Partial<User>): Promise<void> => sink.updateUser(user); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the We could alternatively fix the usages, but it makes the most sense for a DB |
||
| export const addPublicKey = (username: string, publicKey: string): Promise<void> => | ||
| export const updateUser = (user: User): Promise<void> => sink.updateUser(user); | ||
| export const addPublicKey = (username: string, publicKey: PublicKeyRecord): Promise<void> => | ||
| sink.addPublicKey(username, publicKey); | ||
| export const removePublicKey = (username: string, publicKey: string): Promise<void> => | ||
| sink.removePublicKey(username, publicKey); | ||
| export type { PushQuery, Repo, Sink, User } from './types'; | ||
| export const removePublicKey = (username: string, fingerprint: string): Promise<void> => | ||
| sink.removePublicKey(username, fingerprint); | ||
| export const getPublicKeys = (username: string): Promise<PublicKeyRecord[]> => | ||
| sink.getPublicKeys(username); | ||
| export type { PushQuery, Repo, Sink, User, PublicKeyRecord } from './types'; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,4 +31,5 @@ export const { | |
| updateUser, | ||
| addPublicKey, | ||
| removePublicKey, | ||
| getPublicKeys, | ||
| } = users; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might want to rename this to
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively, we could rename this to This might make the |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { PACKET_SIZE } from './constants'; | ||
|
|
||
| /** | ||
| * Parses the packet lines from a buffer into an array of strings. | ||
| * Also returns the offset immediately following the parsed lines (including the flush packet). | ||
| * @param {Buffer} buffer - The buffer containing the packet data. | ||
| * @return {[string[], number]} An array containing the parsed lines and the offset after the last parsed line/flush packet. | ||
| */ | ||
| export const parsePacketLines = (buffer: Buffer): [string[], number] => { | ||
| const lines: string[] = []; | ||
| let offset = 0; | ||
|
|
||
| while (offset + PACKET_SIZE <= buffer.length) { | ||
| const lengthHex = buffer.toString('utf8', offset, offset + PACKET_SIZE); | ||
| const length = Number(`0x${lengthHex}`); | ||
|
|
||
| // Prevent non-hex characters from causing issues | ||
| if (isNaN(length) || length < 0) { | ||
| throw new Error(`Invalid packet line length ${lengthHex} at offset ${offset}`); | ||
| } | ||
|
|
||
| // length of 0 indicates flush packet (0000) | ||
| if (length === 0) { | ||
| offset += PACKET_SIZE; // Include length of the flush packet | ||
| break; | ||
| } | ||
|
|
||
| // Make sure we don't read past the end of the buffer | ||
| if (offset + length > buffer.length) { | ||
| throw new Error(`Invalid packet line length ${lengthHex} at offset ${offset}`); | ||
| } | ||
|
|
||
| const line = buffer.toString('utf8', offset + PACKET_SIZE, offset + length); | ||
| lines.push(line); | ||
| offset += length; // Move offset to the start of the next line's length prefix | ||
| } | ||
| return [lines, offset]; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to keep the CLI and server independent? Since the CLI is already importing a few things from the parent package.
Perhaps we could extract this function to
src/service/routes/utils.tsfor better testing and dealing with potential bugs. 🤔