-
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.
- Loading branch information
Showing
40 changed files
with
1,125 additions
and
261 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
*.config.ts | ||
*.test.js | ||
*.test.ts | ||
coverage | ||
dist |
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 was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import Connection from '../../helper/connection' | ||
import { Handlers } from '../../helper/handlers' | ||
import Writable from '../../helper/writable' | ||
import { none } from './methods' | ||
import { SOCKSVERSIONS } from '../../helper/constants' | ||
import { MethodSelectionState } from '../state/socks5' | ||
|
||
/** | ||
* The Authenticator Class is responsible for resolving the authentication process | ||
*/ | ||
class Authenticator { | ||
/** | ||
* Client preferred methods | ||
*/ | ||
private readonly availableMethods: Handlers['auth'] | ||
|
||
/** | ||
* Corresponding connection | ||
*/ | ||
private readonly connection: Connection | ||
|
||
constructor(connection: Connection) { | ||
this.connection = connection | ||
if (connection.handlers.auth.length <= 0) { | ||
connection.handlers.auth.push(none()) | ||
} | ||
this.availableMethods = connection.handlers.auth | ||
} | ||
|
||
/** | ||
* Negotiates for authentication method with the server and handle corresponding | ||
* Authentication method | ||
* @returns void | ||
*/ | ||
public authenticate(): void { | ||
const writable = new Writable() | ||
writable.push(SOCKSVERSIONS.socks5, this.availableMethods.length) | ||
for (const method of this.availableMethods) { | ||
writable.push(method.method) | ||
} | ||
this.connection.transitionTo(new MethodSelectionState(this.connection)) | ||
this.connection.write(writable) | ||
} | ||
} | ||
|
||
export default Authenticator |
File renamed without changes.
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,18 @@ | ||
import { AUTHMODES } from '../../../helper/constants' | ||
import { AuthMethod } from '../../../helper/authMethod' | ||
import { RequestState } from '../../state/socks5' | ||
|
||
/** | ||
* No authentication method | ||
* @returns AuthMethod | ||
*/ | ||
export const none = (): AuthMethod => { | ||
return { | ||
method: AUTHMODES.none, | ||
authenticate: (connection) => { | ||
connection.transitionTo(new RequestState(connection)) | ||
connection.parse() | ||
connection.reply() | ||
}, | ||
} | ||
} |
Oops, something went wrong.