0

Here I have RCTHTTPRequestHandler+ignoreSSL.m that can ignoreSSL based on value from plist.info. It works nicely when I set the value of ignoreSSL from plist.info.


#import "React/RCTBridgeModule.h"
#import "React/RCTHTTPRequestHandler.h"

@implementation RCTHTTPRequestHandler (ignoreSSL)

- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler
{
    // Get the main bundle
    NSBundle *mainBundle = [NSBundle mainBundle];
    
    // Get the value of "IgnoreSSL" from the Info.plist
    NSNumber *ignoreSSLValue = [mainBundle objectForInfoDictionaryKey:@"IgnoreSSL"];
    
    NSLog(@"Ignore SSL: %@", ignoreSSLValue);

    
    // Check if the value is a boolean and if it's set to true (1)
    if ([ignoreSSLValue isKindOfClass:[NSNumber class]] && [ignoreSSLValue boolValue]) {
        NSLog(@"SSL Ignored: %@", ignoreSSLValue);

        // Handle SSL challenge here if IgnoreSSL is true
        completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
    } else {
        // Do not IgnoreSSL is false
        NSLog(@"SSL Not Ignored: %@", ignoreSSLValue);
        completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
    }
}

@end

I expect to set IgnoreSSL when something happens in my code like shown below:


@implementation JitsiMeetView {
    /**
     * The unique identifier of this `JitsiMeetView` within the process for the
     * purposes of `ExternalAPI`. The name scope was inspired by postis which we
     * use on Web for the similar purposes of the iframe-based external API.
     */
    NSString *externalAPIScope;

    /**
     * React Native view where the entire content will be rendered.
     */
    RNRootView *rootView;
}

- (void)join:(JitsiMeetConferenceOptions *)options {
    [self setProps:options == nil ? @{} : [options asProps]];
    
    
    // Access the boolean value from options._starvConferenceInfo._ignoreSSL
    NSString *ignoreSSL = options.starvConferenceInfo.ignoreSSL;
   
    NSLog(@"Ivan SSL Ignored: %@",ignoreSSL);

   // Or use it in a conditional statement:
    if ([ignoreSSL  isEqual: @"true"]) {
       // Do something when ignoreSSL is true
        NSLog(@" SSL Ignored");
   } else {
       // Do something when ignoreSSL is false
       NSLog(@" SSL not ignored");
   }
}

Could we do something like this? I am sorry, I am a beginner in Objective-C

HangarRash
  • 7,314
  • 5
  • 5
  • 32

1 Answers1

0

I found the answer, we need to create ignoreSSL globally that could be accessed by both class.

Here we could create SSLManager.h:

#import <Foundation/Foundation.h>

@interface SSLManager : NSObject

@property (nonatomic, assign) BOOL ignoreSSL;

+ (instancetype)sharedManager;

@end

Here we could create SSLManager.m:

#import "SSLManager.h"

@implementation SSLManager

+ (instancetype)sharedManager {
    static SSLManager *sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedInstance = [[self alloc] init];
    });
    return sharedInstance;
}
@end

Then, you can set to shared instance like this:

- (void)join:(JitsiMeetConferenceOptions *)options {
    
    
    // Access the boolean value from options._starvConferenceInfo._ignoreSSL
    NSString *ignoreSSL = options.starvConferenceInfo.ignoreSSL;
   
    NSLog(@"Ivan SSL Ignored: %@", ignoreSSL);

    // Convert the ignoreSSL value to a BOOL and set it in the SSLManager
    [SSLManager sharedManager].ignoreSSL = [ignoreSSL isEqualToString:@"true"];

    
    [self setProps:options == nil ? @{} : [options asProps]];
}

In RCTHTTPRequestHandler+ignoreSSL.m, you can access sharedManager like this:

#import "React/RCTBridgeModule.h"
#import "React/RCTHTTPRequestHandler.h"
#import "SSLManager.h"

@implementation RCTHTTPRequestHandler (ignoreSSL)

- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler
{
    // Get the value of "ignoreSSL" from the SSLManager singleton
     BOOL ignoreSSLValue = [SSLManager sharedManager].ignoreSSL;
     
    NSLog(@"Ignore SSL: %@", @(ignoreSSLValue));
    // Check if the value is set to true
    if (ignoreSSLValue) {
        NSLog(@"SSL Ignored: %@", @(ignoreSSLValue));
        // Handle SSL challenge here if ignoreSSL is true
        completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
    } else {
        // Do not ignore SSL if false
        NSLog(@"SSL Not Ignored: %@", @(ignoreSSLValue));
        completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
    }
}

@end

Finally, you can set ignoreSSL from another class and share the value from this sharedManager.