Skip to content

Commit

Permalink
feat: Import and share links support reality related fields
Browse files Browse the repository at this point in the history
  • Loading branch information
tzmax committed Apr 22, 2023
1 parent 1ed5a22 commit 6bb7d46
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion V2RayX/ConfigImporter.m
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ + (ServerProfile*)importFromVmessOfV2RayN:(NSString*)vmessStr {
return newProfile;
}

// 目前为初步提案, 详情请见 VMessAEAD / VLESS 分享链接标准提案 https://github.com/XTLS/Xray-core/issues/91
// 目前为初步提案, 详情请见 VMessAEAD / VLESS 分享链接标准提案 https://github.com/XTLS/Xray-core/discussions/716
+ (ServerProfile*)importFromVLESSOfXray:(NSString*)vlessStr {
// decode base64String
NSString *base64String = [self decodeBase64String:vlessStr];
Expand Down Expand Up @@ -543,6 +543,7 @@ + (ServerProfile*)importFromVLESSOfXray:(NSString*)vlessStr {
}
break;
case grpc:
streamSettings[@"grpcSettings"][@"headerType"] = nilCoalescing([sharedServer objectForKey:@"headerType"], @"");
streamSettings[@"grpcSettings"][@"serviceName"] = nilCoalescing([sharedServer objectForKey:@"serviceName"], @"");
if ([[sharedServer objectForKey:@"mode"] containsString:@"multi"]) {
streamSettings[@"grpcSettings"][@"multiMode"] = @YES;
Expand Down Expand Up @@ -570,12 +571,26 @@ + (ServerProfile*)importFromVLESSOfXray:(NSString*)vlessStr {
settingsName = @"tlsSettings";
}

// temporarily compatible with xtls configuration, will be obsolete soon
if ([sharedServer[@"security"] isEqualToString:@"xtls"] && [sharedServer objectForKey:@"flow"]) {
newProfile.flow = searchInArray(nilCoalescing(sharedServer[@"flow"], @""), VLESS_FLOW_LIST);
settingsName = @"xtlsSettings";
}

if ([sharedServer[@"security"] isEqualToString:@"reality"]) {
newProfile.flow = searchInArray(nilCoalescing(sharedServer[@"flow"], @""), VLESS_FLOW_LIST);
settingsName = @"realitySettings";
streamSettings[settingsName][@"fingerprint"] = nilCoalescing(sharedServer[@"fp"], @"chrome");
streamSettings[settingsName][@"shortId"] = nilCoalescing(sharedServer[@"sid"], @"");
streamSettings[settingsName][@"spiderX"] = [nilCoalescing(sharedServer[@"spx"], @"") stringByRemovingPercentEncoding];
if ([sharedServer objectForKey:@"pbk"]) {
streamSettings[settingsName][@"publicKey"] = nilCoalescing(sharedServer[@"pbk"], @"");
}
}

if ([settingsName isNotEqualTo:@""]) {
streamSettings[settingsName][@"allowInsecure"] = nilCoalescing(sharedServer[@"allowInsecure"], @NO);
streamSettings[settingsName][@"allowInsecureCiphers"] = nilCoalescing(sharedServer[@"allowInsecureCiphers"], @NO);
streamSettings[settingsName][@"serverName"] = nilCoalescing(sharedServer[@"sni"], newProfile.address);
if ([sharedServer objectForKey:@"alpn"]) {
streamSettings[settingsName][@"alpn"] = [sharedServer[@"alpn"] stringByRemovingPercentEncoding];
Expand Down
2 changes: 1 addition & 1 deletion V2RayX/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#define VMESS_SECURITY_LIST (@[@"none", @"auto", @"aes-128-gcm", @"chacha20-poly1305"])
#define NETWORK_LIST (@[@"tcp", @"kcp", @"ws", @"http", @"quic", @"grpc"])
#define QUIC_SECURITY_LIST (@[@"none", @"aes-128-gcm", @"chacha20-poly1305"])
#define TLS_SECURITY_LIST (@[@"none", @"tls", @"xtls"])
#define TLS_SECURITY_LIST (@[@"none", @"tls", @"xtls", @"reality"])
#define nilCoalescing(a,b) ( (a != nil) ? (a) : (b) ) // equivalent to ?? operator in Swift

#define TCP_NONE_HEADER_OBJECT (@"{\"type\": \"none\"}")
Expand Down

0 comments on commit 6bb7d46

Please sign in to comment.