mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2026-04-06 00:00:03 +08:00
Merge branch 'develop' into feature/documentation
* develop: Update method signatures that have error objects
This commit is contained in:
@@ -47,7 +47,7 @@
|
|||||||
|
|
||||||
#pragma mark - OpenVPNClient Lifecycle
|
#pragma mark - OpenVPNClient Lifecycle
|
||||||
|
|
||||||
- (OpenVPNProperties *)applyConfiguration:(OpenVPNConfiguration *)configuration error:(NSError * _Nullable __autoreleasing *)error {
|
- (OpenVPNProperties *)applyConfiguration:(OpenVPNConfiguration *)configuration error:(NSError * __autoreleasing *)error {
|
||||||
ClientAPI::EvalConfig eval = self.vpnClient->eval_config(configuration.config);
|
ClientAPI::EvalConfig eval = self.vpnClient->eval_config(configuration.config);
|
||||||
|
|
||||||
if (eval.error) {
|
if (eval.error) {
|
||||||
@@ -65,7 +65,7 @@
|
|||||||
return [[OpenVPNProperties alloc] initWithEvalConfig:eval];
|
return [[OpenVPNProperties alloc] initWithEvalConfig:eval];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)provideCredentials:(OpenVPNCredentials *)credentials error:(NSError * _Nullable __autoreleasing *)error {
|
- (BOOL)provideCredentials:(OpenVPNCredentials *)credentials error:(NSError * __autoreleasing *)error {
|
||||||
ClientAPI::Status status = self.vpnClient->provide_creds(credentials.credentials);
|
ClientAPI::Status status = self.vpnClient->provide_creds(credentials.credentials);
|
||||||
|
|
||||||
if (status.error) {
|
if (status.error) {
|
||||||
|
|||||||
@@ -8,17 +8,18 @@
|
|||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@interface OpenVPNCertificate : NSObject
|
@interface OpenVPNCertificate : NSObject
|
||||||
|
|
||||||
+ (nullable OpenVPNCertificate *)certificateWithPEM:(nonnull NSData *)pemData
|
+ (nullable OpenVPNCertificate *)certificateWithPEM:(NSData *)pemData error:(NSError **)error;
|
||||||
error:(out NSError * _Nullable * _Nullable)error;
|
+ (nullable OpenVPNCertificate *)certificateWithDER:(NSData *)derData error:(NSError **)error;
|
||||||
|
|
||||||
+ (nullable OpenVPNCertificate *)certificateWithDER:(nonnull NSData *)derData
|
- (instancetype) init NS_UNAVAILABLE;
|
||||||
error:(out NSError * _Nullable * _Nullable)error;
|
|
||||||
|
|
||||||
- (nonnull instancetype) init NS_UNAVAILABLE;
|
- (nullable NSData *)pemData:(NSError **)error;
|
||||||
|
- (nullable NSData *)derData:(NSError **)error;
|
||||||
- (nullable NSData *)pemData:(out NSError * _Nullable * _Nullable)error;
|
|
||||||
- (nullable NSData *)derData:(out NSError * _Nullable * _Nullable)error;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
@implementation OpenVPNCertificate
|
@implementation OpenVPNCertificate
|
||||||
|
|
||||||
+ (OpenVPNCertificate *)certificateWithPEM:(NSData *)pemData error:(out NSError **)error {
|
+ (OpenVPNCertificate *)certificateWithPEM:(NSData *)pemData error:(NSError * __autoreleasing *)error {
|
||||||
OpenVPNCertificate *certificate = [OpenVPNCertificate new];
|
OpenVPNCertificate *certificate = [OpenVPNCertificate new];
|
||||||
|
|
||||||
NSString *pemString = [[NSString alloc] initWithData:pemData encoding:NSUTF8StringEncoding];
|
NSString *pemString = [[NSString alloc] initWithData:pemData encoding:NSUTF8StringEncoding];
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
return certificate;
|
return certificate;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (OpenVPNCertificate *)certificateWithDER:(NSData *)derData error:(out NSError **)error {
|
+ (OpenVPNCertificate *)certificateWithDER:(NSData *)derData error:(NSError * __autoreleasing *)error {
|
||||||
OpenVPNCertificate *certificate = [OpenVPNCertificate new];
|
OpenVPNCertificate *certificate = [OpenVPNCertificate new];
|
||||||
|
|
||||||
int result = mbedtls_x509_crt_parse_der(certificate.crt, derData.bytes, derData.length);
|
int result = mbedtls_x509_crt_parse_der(certificate.crt, derData.bytes, derData.length);
|
||||||
@@ -61,7 +61,7 @@
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSData *)pemData:(out NSError **)error {
|
- (NSData *)pemData:(NSError * __autoreleasing *)error {
|
||||||
NSString *header = @"-----BEGIN CERTIFICATE-----\n";
|
NSString *header = @"-----BEGIN CERTIFICATE-----\n";
|
||||||
NSString *footer = @"-----END CERTIFICATE-----\n";
|
NSString *footer = @"-----END CERTIFICATE-----\n";
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@
|
|||||||
return pemData;
|
return pemData;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSData *)derData:(out NSError **)error {
|
- (NSData *)derData:(NSError * __autoreleasing *)error {
|
||||||
if (self.crt->raw.p == NULL || self.crt->raw.len == 0) {
|
if (self.crt->raw.p == NULL || self.crt->raw.len == 0) {
|
||||||
if (error) {
|
if (error) {
|
||||||
*error = [NSError ovpn_errorObjectForMbedTLSError:MBEDTLS_ERR_X509_BAD_INPUT_DATA
|
*error = [NSError ovpn_errorObjectForMbedTLSError:MBEDTLS_ERR_X509_BAD_INPUT_DATA
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ static void SocketCallback(CFSocketRef socket, CFSocketCallBackType type, CFData
|
|||||||
[bridge writePackets:@[packet] toPacketFlow:bridge.packetFlow];
|
[bridge writePackets:@[packet] toPacketFlow:bridge.packetFlow];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)configureSocketsWithError:(NSError **)error {
|
- (BOOL)configureSocketsWithError:(NSError * __autoreleasing *)error {
|
||||||
int sockets[2];
|
int sockets[2];
|
||||||
if (socketpair(PF_LOCAL, SOCK_DGRAM, IPPROTO_IP, sockets) == -1) {
|
if (socketpair(PF_LOCAL, SOCK_DGRAM, IPPROTO_IP, sockets) == -1) {
|
||||||
if (error) {
|
if (error) {
|
||||||
@@ -90,7 +90,7 @@ static void SocketCallback(CFSocketRef socket, CFSocketCallBackType type, CFData
|
|||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)configureOptionsForSocket:(CFSocketRef)socket error:(NSError **)error {
|
- (BOOL)configureOptionsForSocket:(CFSocketRef)socket error:(NSError * __autoreleasing *)error {
|
||||||
CFSocketNativeHandle socketHandle = CFSocketGetNative(socket);
|
CFSocketNativeHandle socketHandle = CFSocketGetNative(socket);
|
||||||
|
|
||||||
int buf_value = 65536;
|
int buf_value = 65536;
|
||||||
|
|||||||
@@ -10,22 +10,26 @@
|
|||||||
|
|
||||||
typedef NS_ENUM(NSInteger, OpenVPNKeyType);
|
typedef NS_ENUM(NSInteger, OpenVPNKeyType);
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@interface OpenVPNPrivateKey : NSObject
|
@interface OpenVPNPrivateKey : NSObject
|
||||||
|
|
||||||
+ (nullable OpenVPNPrivateKey *)keyWithPEM:(nonnull NSData *)pemData
|
+ (nullable OpenVPNPrivateKey *)keyWithPEM:(NSData *)pemData
|
||||||
password:(nullable NSString *)password
|
password:(nullable NSString *)password
|
||||||
error:(out NSError * _Nullable * _Nullable)error;
|
error:(NSError **)error;
|
||||||
|
|
||||||
+ (nullable OpenVPNPrivateKey *)keyWithDER:(nonnull NSData *)derData
|
+ (nullable OpenVPNPrivateKey *)keyWithDER:(NSData *)derData
|
||||||
password:(nullable NSString *)password
|
password:(nullable NSString *)password
|
||||||
error:(out NSError * _Nullable * _Nullable)error;
|
error:(NSError **)error;
|
||||||
|
|
||||||
- (nonnull instancetype) init NS_UNAVAILABLE;
|
- (instancetype) init NS_UNAVAILABLE;
|
||||||
|
|
||||||
@property (nonatomic, readonly) NSInteger size;
|
@property (nonatomic, readonly) NSInteger size;
|
||||||
@property (nonatomic, readonly) OpenVPNKeyType type;
|
@property (nonatomic, readonly) OpenVPNKeyType type;
|
||||||
|
|
||||||
- (nullable NSData *)pemData:(out NSError * _Nullable * _Nullable)error;
|
- (nullable NSData *)pemData:(NSError **)error;
|
||||||
- (nullable NSData *)derData:(out NSError * _Nullable * _Nullable)error;
|
- (nullable NSData *)derData:(NSError **)error;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
@implementation OpenVPNPrivateKey
|
@implementation OpenVPNPrivateKey
|
||||||
|
|
||||||
+ (nullable OpenVPNPrivateKey *)keyWithPEM:(NSData *)pemData password:(NSString *)password error:(out NSError **)error {
|
+ (OpenVPNPrivateKey *)keyWithPEM:(NSData *)pemData password:(NSString *)password error:(NSError * __autoreleasing *)error {
|
||||||
OpenVPNPrivateKey *key = [OpenVPNPrivateKey new];
|
OpenVPNPrivateKey *key = [OpenVPNPrivateKey new];
|
||||||
|
|
||||||
NSString *pemString = [[NSString alloc] initWithData:pemData encoding:NSUTF8StringEncoding];
|
NSString *pemString = [[NSString alloc] initWithData:pemData encoding:NSUTF8StringEncoding];
|
||||||
@@ -43,7 +43,7 @@
|
|||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (nullable OpenVPNPrivateKey *)keyWithDER:(NSData *)derData password:(NSString *)password error:(out NSError **)error {
|
+ (OpenVPNPrivateKey *)keyWithDER:(NSData *)derData password:(NSString *)password error:(NSError * __autoreleasing *)error {
|
||||||
OpenVPNPrivateKey *key = [OpenVPNPrivateKey new];
|
OpenVPNPrivateKey *key = [OpenVPNPrivateKey new];
|
||||||
|
|
||||||
size_t password_length = password != nil ? strlen(password.UTF8String) : 0;
|
size_t password_length = password != nil ? strlen(password.UTF8String) : 0;
|
||||||
@@ -78,7 +78,7 @@
|
|||||||
return (OpenVPNKeyType)mbedtls_pk_get_type(self.ctx);
|
return (OpenVPNKeyType)mbedtls_pk_get_type(self.ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSData *)pemData:(out NSError **)error {
|
- (NSData *)pemData:(NSError * __autoreleasing *)error {
|
||||||
size_t buffer_length = mbedtls_pk_get_len(self.ctx) * 10;
|
size_t buffer_length = mbedtls_pk_get_len(self.ctx) * 10;
|
||||||
unsigned char *pem_buffer = malloc(buffer_length);
|
unsigned char *pem_buffer = malloc(buffer_length);
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@
|
|||||||
return pemData;
|
return pemData;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSData *)derData:(out NSError **)error {
|
- (NSData *)derData:(NSError * __autoreleasing *)error {
|
||||||
size_t buffer_length = mbedtls_pk_get_len(self.ctx) * 10;
|
size_t buffer_length = mbedtls_pk_get_len(self.ctx) * 10;
|
||||||
unsigned char *der_buffer = malloc(buffer_length);
|
unsigned char *der_buffer = malloc(buffer_length);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user