1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -05:00
This commit is contained in:
Darien Raymond 2018-10-18 09:25:58 +02:00
parent be56feead3
commit 4fcb39ded9
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
8 changed files with 31 additions and 16 deletions

View File

@ -9,16 +9,21 @@ option java_multiple_files = true;
import "v2ray.com/core/common/net/address.proto";
import "v2ray.com/core/common/protocol/server_spec.proto";
// Account represents a Socks account.
message Account {
string username = 1;
string password = 2;
}
// AuthType is the authentication type of Socks proxy.
enum AuthType {
// NO_AUTH is for anounymous authentication.
NO_AUTH = 0;
// PASSWORD is for username/password authentication.
PASSWORD = 1;
}
// ServerConfig is the protobuf config for Socks server.
message ServerConfig {
AuthType auth_type = 1;
map<string, string> accounts = 2;
@ -28,6 +33,8 @@ message ServerConfig {
uint32 user_level = 6;
}
// ClientConfig is the protobuf config for Socks client.
message ClientConfig {
// Sever is a list of Socks server addresses.
repeated v2ray.core.common.protocol.ServerEndpoint server = 1;
}

View File

@ -24,22 +24,23 @@ import (
// Server is a SOCKS 5 proxy server
type Server struct {
config *ServerConfig
v *core.Instance
config *ServerConfig
policyManager policy.Manager
}
// NewServer creates a new Server object.
func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) {
v := core.MustFromContext(ctx)
s := &Server{
config: config,
v: core.MustFromContext(ctx),
config: config,
policyManager: v.PolicyManager(),
}
return s, nil
}
func (s *Server) policy() policy.Session {
config := s.config
p := s.v.PolicyManager().ForLevel(config.UserLevel)
p := s.policyManager.ForLevel(config.UserLevel)
if config.Timeout > 0 {
features.PrintDeprecatedFeatureWarning("Socks timeout")
}

View File

@ -6,21 +6,27 @@ import (
"v2ray.com/core/common/uuid"
)
type InternalAccount struct {
ID *protocol.ID
// MemoryAccount is an in-memory from of VMess account.
type MemoryAccount struct {
// ID is the main ID of the account.
ID *protocol.ID
// AlterIDs are the alternative IDs of the account.
AlterIDs []*protocol.ID
// Security type of the account. Used for client connections.
Security protocol.SecurityType
}
func (a *InternalAccount) AnyValidID() *protocol.ID {
// AnyValidID returns an ID that is either the main ID or one of the alternative IDs if any.
func (a *MemoryAccount) AnyValidID() *protocol.ID {
if len(a.AlterIDs) == 0 {
return a.ID
}
return a.AlterIDs[dice.Roll(len(a.AlterIDs))]
}
func (a *InternalAccount) Equals(account protocol.Account) bool {
vmessAccount, ok := account.(*InternalAccount)
// Equals implements protocol.Account.
func (a *MemoryAccount) Equals(account protocol.Account) bool {
vmessAccount, ok := account.(*MemoryAccount)
if !ok {
return false
}
@ -28,13 +34,14 @@ func (a *InternalAccount) Equals(account protocol.Account) bool {
return a.ID.Equals(vmessAccount.ID)
}
// AsAccount implements protocol.Account.
func (a *Account) AsAccount() (protocol.Account, error) {
id, err := uuid.ParseString(a.Id)
if err != nil {
return nil, newError("failed to parse ID").Base(err).AtError()
}
protoID := protocol.NewID(id)
return &InternalAccount{
return &MemoryAccount{
ID: protoID,
AlterIDs: protocol.NewAlterIDs(protoID, uint16(a.AlterId)),
Security: a.SecuritySettings.GetSecurityType(),

View File

@ -56,7 +56,7 @@ func NewClientSession(idHash protocol.IDHash) *ClientSession {
func (c *ClientSession) EncodeRequestHeader(header *protocol.RequestHeader, writer io.Writer) error {
timestamp := protocol.NewTimestampGenerator(protocol.NowTime(), 30)()
account := header.User.Account.(*vmess.InternalAccount)
account := header.User.Account.(*vmess.MemoryAccount)
idHash := c.idHash(account.AnyValidID().Bytes())
common.Must2(idHash.Write(timestamp.Bytes(nil)))
common.Must2(writer.Write(idHash.Sum(nil)))

View File

@ -135,7 +135,7 @@ func (s *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
}
iv := md5.Sum(hashTimestamp(timestamp))
vmessAccount := user.Account.(*vmess.InternalAccount)
vmessAccount := user.Account.(*vmess.MemoryAccount)
aesStream := crypto.NewAesDecryptionStream(vmessAccount.ID.CmdKey(), iv[:])
decryptor := crypto.NewCryptionReader(aesStream, reader)

View File

@ -333,7 +333,7 @@ func (h *Handler) generateCommand(ctx context.Context, request *protocol.Request
if user == nil {
return nil
}
account := user.Account.(*vmess.InternalAccount)
account := user.Account.(*vmess.MemoryAccount)
return &protocol.CommandSwitchAccount{
Port: port,
ID: account.ID.UUID(),

View File

@ -94,7 +94,7 @@ func (v *Handler) Process(ctx context.Context, link *vio.Link, dialer proxy.Dial
Option: protocol.RequestOptionChunkStream,
}
account := request.User.Account.(*vmess.InternalAccount)
account := request.User.Account.(*vmess.MemoryAccount)
request.Security = account.Security
if request.Security == protocol.SecurityType_AES128_GCM || request.Security == protocol.SecurityType_NONE || request.Security == protocol.SecurityType_CHACHA20_POLY1305 {

View File

@ -79,7 +79,7 @@ func (v *TimedUserValidator) generateNewHashes(nowSec protocol.Timestamp, user *
}
}
account := user.user.Account.(*InternalAccount)
account := user.user.Account.(*MemoryAccount)
genHashForID(account.ID)
for _, id := range account.AlterIDs {