admin管理员组

文章数量:1125978

My goal is to implement a wss connection using SSL pinning on an React Native iOS module. For this problem, I chose to use Jetfire. I have the following class:

@interface RCTWebSocketSslPinning : RCTEventEmitter <RCTBridgeModule, JFRWebSocketDelegate>

@property (nonatomic, strong) JFRWebSocket *socket;
@property bool hasListeners;

-(void)sendEventToJavaScript:(NSString *)eventName withParams:(id)params;
@end

And the following fetch method:

RCT_EXPORT_METHOD(fetch:(NSString *)url withOptions:(NSDictionary *)options callback:(RCTResponseSenderBlock)callback)
{
  RCTLogInfo(@"Pretending to fetch %@ with options: %@", url, options.description);
  
  self.socket = [[JFRWebSocket alloc] initWithURL:[NSURL URLWithString: url] protocols:nil];
  self.socket.delegate = self;
  
  NSString *path = [[NSBundle mainBundle] pathForResource:@"rootCA_public" ofType:@"cer"];
  NSData *data = [NSData dataWithContentsOfFile:path];

  if (data) {
      NSLog(@"Certificate loaded successfully!");
  } else {
      NSLog(@"Failed to load certificate. Check the file path.");
      callback(@[ @"Failed to load certificate.", [NSNull null]]);
  }
  
  self.socket.security = [[JFRSecurity alloc] initWithCerts:@[[[JFRSSLCert alloc] initWithData:data]] publicKeys:YES];
  [self.socket connect];
  
  callback(@[[NSNull null], @"WebSocket fetch complete."]);
}

I implemented this method following the Jetfire guide here however when I run the program I get a run-time error within JFRSecurity.m:

- (SecKeyRef)extractPublicKeyFromCert:(SecCertificateRef)cert policy:(SecPolicyRef)policy {
    
    SecTrustRef trust;
    SecTrustCreateWithCertificates(cert,policy,&trust); // ERROR: Thread x: EXC_BAD_ACCESS (code=1, address=0x8)
    SecTrustResultType result = kSecTrustResultInvalid;
    SecTrustEvaluate(trust,&result);
    SecKeyRef key = SecTrustCopyPublicKey(trust);
    CFRelease(trust);
    return key;
}

I analyzed the project and I get this message:

I'm not familiar with Objective-C, and I'm not sure if this is a problem with the library that I'm using or if it's the way I'm attempting to extract the certificate from path.

本文标签: