Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
import from ssd://
Browse files Browse the repository at this point in the history
  • Loading branch information
Cenmrev committed Dec 26, 2018
1 parent cca7a04 commit ed617f9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions V2RayX/ConfigImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSMutableDictionary*)importFromSubscriptionOfV2RayN:(NSString*)httpLink;
+ (NSMutableDictionary*)importFromStandardConfigFiles:(NSArray*)files;
+ (NSMutableDictionary*)validateRuleSet:(NSMutableDictionary*)set;
+ (NSMutableDictionary* _Nonnull)importFromSubscriptionOfSSD: (NSString* _Nonnull)ssdLink;
@end

NS_ASSUME_NONNULL_END
47 changes: 47 additions & 0 deletions V2RayX/ConfigImporter.m
Original file line number Diff line number Diff line change
Expand Up @@ -376,5 +376,52 @@ + (ServerProfile*)importFromVmessOfV2RayN:(NSString*)vmessStr {
return newProfile;
}

// https://github.com/CGDF-Github/SSD-Windows/wiki/订阅链接协定
+ (NSMutableDictionary* _Nonnull)importFromSubscriptionOfSSD: (NSString* _Nonnull)ssdLink {
NSMutableDictionary* result = EMPTY_IMPORT_RESULT;
@try {
NSString* encodedPart;
if (![[ssdLink substringToIndex:6] isEqualToString:@"ssd://"]) {
return EMPTY_IMPORT_RESULT;
}
encodedPart = [ssdLink substringFromIndex:6];
NSString* decodedJSONStr = [ConfigImporter decodeBase64String:encodedPart];
NSDictionary* decodedObject = [NSJSONSerialization JSONObjectWithData:[decodedJSONStr dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
NSString* airportName = decodedObject[@"airport"];
NSNumber* defaultPort = decodedObject[@"port"];
NSString* defaultEncryption = decodedObject[@"encryption"];
NSString* defaultPassword = decodedObject[@"password"];
NSString* defaultPlutgin = decodedObject[@"plugin"];
NSInteger count = 0;
for (NSDictionary* server in decodedObject[@"servers"]) {
NSString* address = server[@"server"];
NSNumber* port = nilCoalescing(server[@"port"], defaultPort) ;
NSString* method = nilCoalescing(server[@"encryption"], defaultEncryption);
NSString* password = nilCoalescing(server[@"password"], defaultPassword);
NSString* plugIn = nilCoalescing(server[@"plugin"], defaultPlutgin);
if (plugIn && plugIn.length > 0) {
continue; // do not support plug-in yet
}
NSString* defaultServerName = [NSString stringWithFormat:@"%lu", count];
NSString* serverName = nilCoalescing(server[@"remarks"], defaultServerName);
NSString* tag = [NSString stringWithFormat:@"%@-%@", airportName, serverName];
NSMutableDictionary* ssOutbound =
[ConfigImporter ssOutboundFromSSConfig:@{ @"server":address,
@"server_port":port,
@"password":password,
@"method":method,
@"tag": tag
}];
if (ssOutbound) {
[result[@"other"] addObject:ssOutbound];
count += 1;
}
}
NSLog(@"%@", result);
return result;
} @catch (NSException *exception) {
return EMPTY_IMPORT_RESULT;
}
}

@end
3 changes: 3 additions & 0 deletions V2RayX/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@

#define SUPPORTED_SS_SECURITY (@[@"aes-256-cfb",@"aes-128-cfb",@"chacha20",@"chacha20-ietf",@"aes-256-gcm",@"aes-128-gcm",@"chacha20-poly1305", @"chacha20-ietf-poly1305"])

#define EMPTY_DICT ([[NSMutableDictionary alloc] init])
#define EMPTY_IMPORT_RESULT ([@{@"vmess": @[], @"other": @[], @"rules":@[]} mutableDeepCopy])

NSUInteger searchInArray(NSString* str, NSArray* array);


Expand Down

0 comments on commit ed617f9

Please sign in to comment.