novastone-media / MQTT-Client-Framework

iOS, macOS, tvOS native ObjectiveC MQTT Client Framework
Other
1.84k stars 465 forks source link

Error Domain=MQTT Code=-9807 "Unable to apply security policy, the SSL connection is insecure!" #592

Open ml1732457 opened 3 years ago

ml1732457 commented 3 years ago

//证书1 NSString ca = [[NSBundle mainBundle] pathForResource:@"AmazonRootCA1" ofType:@"pem"]; NSString ca1 = [[NSBundle mainBundle] pathForResource:@"certificate" ofType:@"der"]; NSString *ca2 = [[NSBundle mainBundle] pathForResource:@"client" ofType:@"key"];

//证书2
NSString *client = [[NSBundle mainBundle] pathForResource:@"certificate" ofType:@"p12"];//注意不可以用client命名,否则无法获取到文件路径

NSArray *myCerts = [MQTTCFSocketTransport clientCertsFromP12:client passphrase:@"123"];

if (myCerts) {
    NSLog(@"myCerts ok");
}else{
    NSLog(@"myCerts error");
}

_sslTransport.certificates = [MQTTSSLSecurityPolicyTransport clientCertsFromP12:client passphrase:@"123"];

_securityPolicy = [MQTTSSLSecurityPolicy policyWithPinningMode:MQTTSSLPinningModeCertificate];

_securityPolicy.allowInvalidCertificates = YES;
_securityPolicy.validatesDomainName = NO;
_securityPolicy.validatesCertificateChain = NO;

NSLog(@"----------%@",@[[NSData dataWithContentsOfFile:ca],[NSData dataWithContentsOfFile:ca1],[NSData dataWithContentsOfFile:ca2]]);

_securityPolicy.pinnedCertificates = @[[NSData dataWithContentsOfFile:ca],[NSData dataWithContentsOfFile:ca1],[NSData dataWithContentsOfFile:ca2]];

Short description

The certificate is set but keeps reporting errors, but I used Mac tools to debug MQTT just fine!

Environment

Link to logs

Create a GIST which is a paste of your logs, and link them here. Please do NOT paste your full logs here, it will make issue very long and hard to read!

Steps to reproduce

Expected behaviour

Actual behaviour

Other information