-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: Client authentication and connect method completed
- Loading branch information
Showing
13 changed files
with
375 additions
and
71 deletions.
There are no files selected for viewing
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
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
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
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
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 |
---|---|---|
@@ -1,20 +1,59 @@ | ||
import { AUTHMODES } from '../../../helper/constants' | ||
import { AUTHMODES, SOCKSVERSIONS } from '../../../helper/constants' | ||
import { AuthMethod } from '../../../helper/authMethod' | ||
import Connection from '../../../helper/connection' | ||
import Writable from '../../../helper/writable' | ||
import { State } from '../../../helper/state' | ||
import { RequestState } from '../../state/socks5' | ||
|
||
/** | ||
* Extract user/pass from user authentication request and, | ||
* execute the handler function | ||
* @param handler - Check the authorization of user/pass | ||
* Get the username and password from the user and, | ||
* Handle the authentication procedure | ||
* @param user - Username | ||
* @param pass - Password | ||
* @returns AuthMethod | ||
*/ | ||
export const userPass = ( | ||
handler: (user: string, pass: string) => boolean | ||
): AuthMethod => { | ||
export const userPass = (user: string, pass: string): AuthMethod => { | ||
return { | ||
method: AUTHMODES.userPass, | ||
authenticate: (connection: Connection) => { | ||
console.log('hey userPass') | ||
const writeable = new Writable() | ||
writeable.push( | ||
0x01, | ||
user.length, | ||
Buffer.from(user), | ||
pass.length, | ||
Buffer.from(pass) | ||
) | ||
connection.write(writeable) | ||
connection.transitionTo(new UserPassReqState(connection)) | ||
}, | ||
} | ||
} | ||
|
||
class UserPassReqState extends State { | ||
/** | ||
* Authentication result | ||
*/ | ||
private status?: number | ||
|
||
/** | ||
* Parse authentication result | ||
*/ | ||
parse(): void { | ||
this.context.read(1) | ||
this.status = this.context.read(1).readInt8() | ||
} | ||
|
||
/** | ||
* Proceed to sending (connect | bind | associate) request | ||
*/ | ||
reply(): void { | ||
if (this.status !== 0x00) { | ||
this.context.close() | ||
} else { | ||
this.context.transitionTo(new RequestState(this.context)) | ||
this.context.parse() | ||
this.context.reply() | ||
} | ||
} | ||
} |
Oops, something went wrong.