Je suis très nouveau dans ce domaine ... Je veux vérifier le CN dans un certificat de serveur SSL ... comment puis-je y parvenir? J'utilise les méthodes de délégué NSURLConnection canAuthenticateAgainstProtectionSpace et didReceiveAuthenticationChallenge.Connaître le nom commun d'un certificat SSL
1
A
Répondre
5
Utilisez les deux méthodes de délégation ci-dessous et incluez le Security.amework, et remplacez KNOWN-COMMON-NAME par le nom commun de votre cert.
-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]){
SecTrustRef trustRef = [[challenge protectionSpace] serverTrust];
SecTrustEvaluate(trustRef, NULL);
CFIndex count = SecTrustGetCertificateCount(trustRef);
BOOL trust = NO;
if(count > 0){
SecCertificateRef certRef = SecTrustGetCertificateAtIndex(trustRef, 0);
CFStringRef certSummary = SecCertificateCopySubjectSummary(certRef);
NSString* certSummaryNs = (NSString*)certSummary;
if([certSummaryNs isEqualToString:@"KNOWN-COMMON-NAME"]){ // split host n
trust = YES;
}else{
NSLog(@"Certificate name does not have required common name");
}
CFRelease(certSummary);
}
if(trust){
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
}else{
[challenge.sender cancelAuthenticationChallenge:challenge];
}
}
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
0
Depuis iOS 10.3 il a été function disponible dans le cadre de la sécurité:
CFStringRef commonNameRef = NULL;
// Check if function is available (iOS 10.3 and above)
if (SecCertificateCopyCommonName) {
SecCertificateCopyCommonName(certificateRef, &commonNameRef);
}
NSString *commonName = CFBridgingRelease(commonNameRef);
Questions connexes
- 1. Vérification du nom commun du certificat SSL en Java
- 2. NGINX faux certificat SSL de configuration - Le nom de domaine ne correspond pas au nom commun de certificat ou SAN
- 3. extrait le nom commun d'un fichier pfx
- 4. Certificat SSL
- 5. Certificat SSL domaine
- 6. Ignorer le certificat SSL invalide
- 7. Type de certificat non pris en charge. Nom commun (CN)
- 8. Comment puis-je générer un certificat SSL pour avoir un nom commun afin de remplacer le CN AM par défaut
- 9. Self SSL - Certificat invalide
- 10. Génération de certificat SSL
- 11. Choisir un certificat SSL
- 12. certificat SSL installation
- 13. Certificat SSL DNS dynamique
- 14. Remplacement de certificat SSL
- 15. Android certificat SSL
- 16. Certificat SSL Android
- 17. Avertissement de certificat SSL
- 18. android Certificat SSL
- 19. Certificat SSL Edition
- 20. SSL Certificat Erreur: certificate_unknown
- 21. certificat ssl basé ip
- 22. erreur de certificat SSL
- 23. Exportation du certificat SSL
- 24. Certificat SSL - 3ème partie
- 25. Paypal Accès - certificat SSL: impossible d'obtenir le certificat d'émetteur locale
- 26. Comment puis-je rediriger d'un domaine SSL vers celui avec le nom commun correct?
- 27. Test du certificat SSL pour le test SSL MQ
- 28. Quel nom commun dois-je définir lors de l'achat d'un certificat SSL pour naviguer via HTTPS avec mon application?
- 29. Certificat SSL pour l'environnement LAN
- 30. Certificat SSL et Google Checkout
Pourquoi SecCertificateCopySubjectSummary au lieu de SecCertificateCopyCommonName? –
coz SecCertificateCopyCommonName n'est pas disponible sous iOS (uniquement sous OSX) –