-
Notifications
You must be signed in to change notification settings - Fork 4
/
blacklist.c
102 lines (83 loc) · 2.8 KB
/
blacklist.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <stdio.h>
#include <syslog.h>
#include <CoreFoundation/CoreFoundation.h>
#include "comodo.h"
#include "diginotar.h"
#define SecCertificateRefP void* //moo
CFDataRef SecCertificateGetNormalizedIssuerContent(SecCertificateRefP);
CFDataRef SecCertificateCopySerialNumber(SecCertificateRefP);
CFDataRef SecCertificateCopyPublicKeySHA1Digest(SecCertificateRefP certificate);
/**
* Add check for blacklisted Comodo certificates for iOS < 4.3.2
* http://support.apple.com/kb/HT4606
* http://www.comodo.com/Comodo-Fraud-Incident-2011-03-23.html
* https://bugzilla.mozilla.org/show_bug.cgi?id=643056
* http://hg.mozilla.org/mozilla-central/rev/f6215eef2276
* iOS 4.3.2 introducted a new kSecPolicyCheckBlackListedLeaf policy
* that checks the issuer name and serial number against hardcoded values
**/
int check_comodo_blacklist(SecCertificateRefP cert)
{
int i;
//check if issuer is UTNB
CFDataRef issuer = SecCertificateGetNormalizedIssuerContent(cert);
//CFDataGetLength() == 0x97
if (issuer == NULL || CFDataGetLength(issuer) != sizeof(comodo_utnb_issuer))
return 0;
if(memcmp(CFDataGetBytePtr(issuer), comodo_utnb_issuer, sizeof(comodo_utnb_issuer)))
return 0;
CFDataRef serial = SecCertificateCopySerialNumber(cert);
if (serial == NULL) //should not happen but whatever
return 0;
int sl = CFDataGetLength(serial);
const UInt8* p = CFDataGetBytePtr(serial);
if( p == NULL)
return 0;
//skip leading null bytes
while(sl > 0 && *p == 0)
{
p++;
sl--;
}
if (sl == SERIALSIZE)
{
for(i=0; i < N_COMODO_SERIALS; i++)
{
//XXX apple only memcmp 4 bytes ? false positives ?
if(!memcmp(p, comodo_serials[i], SERIALSIZE))
{
syslog(LOG_WARNING, "iSSLFix: blocking blacklisted Comodo certificate");
CFRelease(serial);
return 1;
}
}
}
CFRelease(serial);
return 0;
}
/**
* Blacklist DigiNotar roots
* http://codereview.chromium.org/7791032/
* https://bugzilla.mozilla.org/show_bug.cgi?id=682956
**/
int check_diginotar_blacklist(SecCertificateRefP cert)
{
int i;
CFDataRef pkh_data = SecCertificateCopyPublicKeySHA1Digest(cert);
if( pkh_data == NULL)
return 0;
const UInt8* pkh = CFDataGetBytePtr(pkh_data);
if( pkh == NULL)
return 0;
for(i=0; i < NUM_DIGINOTAR_PKHS; i++)
{
if(!memcmp(pkh, diginotar_pkhs[i], PKH_SIZE))
{
syslog(LOG_WARNING, "iSSLFix: blocking DigiNotar certificate");
CFRelease(pkh_data);
return 1;
}
}
CFRelease(pkh_data);
return 0;
}