|
@@ -82,7 +82,7 @@ static SecCertificateRef SecTrustGetLeafCertificate(SecTrustRef trust)
|
|
|
|
|
|
NSFileManager *fileManager = [ NSFileManager defaultManager];
|
|
|
|
|
|
- if([fileManager contentsEqualAtPath:[NSString stringWithFormat:@"%@%@",localCertificatesFolder,@"tmp.der"] andPath:[NSString stringWithFormat:@"%@",currentLocalCertLocation]]) {
|
|
|
+ if([fileManager contentsEqualAtPath:[NSString stringWithFormat:@"%@/%@",localCertificatesFolder,@"tmp.der"] andPath:[NSString stringWithFormat:@"%@",currentLocalCertLocation]]) {
|
|
|
|
|
|
NSLog(@"[LOG] Is the same certificate!!!");
|
|
|
trusted = YES;
|
|
@@ -115,7 +115,7 @@ static SecCertificateRef SecTrustGetLeafCertificate(SecTrustRef trust)
|
|
|
|
|
|
NSString *localCertificatesFolder = [CCUtility getDirectoryCerificates];
|
|
|
|
|
|
- certName = [NSString stringWithFormat:@"%@%@",localCertificatesFolder,certName];
|
|
|
+ certName = [NSString stringWithFormat:@"%@/%@",localCertificatesFolder,certName];
|
|
|
|
|
|
if ([[NSFileManager defaultManager] fileExistsAtPath:certName]) {
|
|
|
NSError *error;
|
|
@@ -168,50 +168,17 @@ static SecCertificateRef SecTrustGetLeafCertificate(SecTrustRef trust)
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-- (void)viewCertificate:(SecTrustRef)trust
|
|
|
-{
|
|
|
- SecCertificateRef currentServerCert = SecTrustGetLeafCertificate(trust);
|
|
|
-
|
|
|
- CFDataRef data = SecCertificateCopyData(currentServerCert);
|
|
|
- X509 *x509cert = NULL;
|
|
|
- if (data) {
|
|
|
- BIO *mem = BIO_new_mem_buf((void *)CFDataGetBytePtr(data), (int)CFDataGetLength(data));
|
|
|
- x509cert = d2i_X509_bio(mem, NULL);
|
|
|
- BIO_free(mem);
|
|
|
- CFRelease(data);
|
|
|
-
|
|
|
- if (!x509cert) {
|
|
|
-
|
|
|
- NSLog(@"[LOG] OpenSSL couldn't parse X509 Certificate");
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- NSString *issuer = CertificateGetIssuerName(x509cert);
|
|
|
- NSDate *expiryDate = CertificateGetExpiryDate(x509cert);
|
|
|
-
|
|
|
- NSLog(@"[LOG] %@ %@", issuer, expiryDate);
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- NSLog(@"[LOG] Failed to retrieve DER data from Certificate Ref");
|
|
|
- }
|
|
|
-
|
|
|
- //Free
|
|
|
- X509_free(x509cert);
|
|
|
-}
|
|
|
-
|
|
|
- (BOOL)acceptCertificate
|
|
|
{
|
|
|
NSString *localCertificatesFolder = [CCUtility getDirectoryCerificates];
|
|
|
NSError *error;
|
|
|
NSFileManager *fm = [[NSFileManager alloc] init];
|
|
|
NSTimeInterval dateCertificate = [[NSDate date] timeIntervalSince1970];
|
|
|
- NSString *currentCertLocation = [NSString stringWithFormat:@"%@%f.der",localCertificatesFolder, dateCertificate];
|
|
|
+ NSString *currentCertLocation = [NSString stringWithFormat:@"%@/%f.der",localCertificatesFolder, dateCertificate];
|
|
|
|
|
|
NSLog(@"[LOG] currentCertLocation: %@", currentCertLocation);
|
|
|
|
|
|
- if(![fm moveItemAtPath:[NSString stringWithFormat:@"%@%@",localCertificatesFolder, @"tmp.der"] toPath:currentCertLocation error:&error]) {
|
|
|
+ if(![fm moveItemAtPath:[NSString stringWithFormat:@"%@/%@",localCertificatesFolder, @"tmp.der"] toPath:currentCertLocation error:&error]) {
|
|
|
|
|
|
NSLog(@"[LOG] Error: %@", [error localizedDescription]);
|
|
|
return NO;
|
|
@@ -224,70 +191,4 @@ static SecCertificateRef SecTrustGetLeafCertificate(SecTrustRef trust)
|
|
|
return YES;
|
|
|
}
|
|
|
|
|
|
-static NSString * CertificateGetIssuerName(X509 *certificateX509)
|
|
|
-{
|
|
|
- NSString *issuer = nil;
|
|
|
- if (certificateX509 != NULL) {
|
|
|
- X509_NAME *issuerX509Name = X509_get_issuer_name(certificateX509);
|
|
|
-
|
|
|
- if (issuerX509Name != NULL) {
|
|
|
- int nid = OBJ_txt2nid("O"); // organization
|
|
|
- int index = X509_NAME_get_index_by_NID(issuerX509Name, nid, -1);
|
|
|
-
|
|
|
- X509_NAME_ENTRY *issuerNameEntry = X509_NAME_get_entry(issuerX509Name, index);
|
|
|
-
|
|
|
- if (issuerNameEntry) {
|
|
|
- ASN1_STRING *issuerNameASN1 = X509_NAME_ENTRY_get_data(issuerNameEntry);
|
|
|
-
|
|
|
- if (issuerNameASN1 != NULL) {
|
|
|
- const unsigned char *issuerName = ASN1_STRING_get0_data(issuerNameASN1);
|
|
|
- issuer = [NSString stringWithUTF8String:(char *)issuerName];
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return issuer;
|
|
|
-}
|
|
|
-
|
|
|
-static NSDate *CertificateGetExpiryDate(X509 *certificateX509)
|
|
|
-{
|
|
|
- NSDate *expiryDate = nil;
|
|
|
-
|
|
|
- if (certificateX509 != NULL) {
|
|
|
- ASN1_TIME *certificateExpiryASN1 = X509_getm_notAfter(certificateX509);
|
|
|
- if (certificateExpiryASN1 != NULL) {
|
|
|
- ASN1_GENERALIZEDTIME *certificateExpiryASN1Generalized = ASN1_TIME_to_generalizedtime(certificateExpiryASN1, NULL);
|
|
|
- if (certificateExpiryASN1Generalized != NULL) {
|
|
|
- const unsigned char *certificateExpiryData = ASN1_STRING_get0_data(certificateExpiryASN1Generalized);
|
|
|
-
|
|
|
- // ASN1 generalized times look like this: "20131114230046Z"
|
|
|
- // format: YYYYMMDDHHMMSS
|
|
|
- // indices: 01234567890123
|
|
|
- // 1111
|
|
|
- // There are other formats (e.g. specifying partial seconds or
|
|
|
- // time zones) but this is good enough for our purposes since
|
|
|
- // we only use the date and not the time.
|
|
|
- //
|
|
|
- // (Source: http://www.obj-sys.com/asn1tutorial/node14.html)
|
|
|
-
|
|
|
- NSString *expiryTimeStr = [NSString stringWithUTF8String:(char *)certificateExpiryData];
|
|
|
- NSDateComponents *expiryDateComponents = [[NSDateComponents alloc] init];
|
|
|
-
|
|
|
- expiryDateComponents.year = [[expiryTimeStr substringWithRange:NSMakeRange(0, 4)] intValue];
|
|
|
- expiryDateComponents.month = [[expiryTimeStr substringWithRange:NSMakeRange(4, 2)] intValue];
|
|
|
- expiryDateComponents.day = [[expiryTimeStr substringWithRange:NSMakeRange(6, 2)] intValue];
|
|
|
- expiryDateComponents.hour = [[expiryTimeStr substringWithRange:NSMakeRange(8, 2)] intValue];
|
|
|
- expiryDateComponents.minute = [[expiryTimeStr substringWithRange:NSMakeRange(10, 2)] intValue];
|
|
|
- expiryDateComponents.second = [[expiryTimeStr substringWithRange:NSMakeRange(12, 2)] intValue];
|
|
|
-
|
|
|
- NSCalendar *calendar = [NSCalendar currentCalendar];
|
|
|
- expiryDate = [calendar dateFromComponents:expiryDateComponents];
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return expiryDate;
|
|
|
-}
|
|
|
-
|
|
|
@end
|