Skip to content

Commit de70a58

Browse files
committed
Do CA checks to verify authentication by default
This is a follow-up to b665b28. An attacker that is able to login into a token could bypass authentication by using its own certificate with any valid signature. This change makes the default "ca, signature" with the only way to disable CA check by using "no_ca". This, however, also makes the "none" option disabling CRL and OCSP checks only. Resolves #80
1 parent b8dbe63 commit de70a58

File tree

5 files changed

+40
-28
lines changed

5 files changed

+40
-28
lines changed

doc/pam_pkcs11.xml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -613,18 +613,24 @@ is <filename class='directory'>/etc/pam_pkcs11/crls/</filename>.
613613
</varlistentry>
614614

615615
<varlistentry>
616-
<term><token>cert_policy={none, ca, signature, crl_online, crl_offline, crl_auto}</token></term>
616+
<term><token>cert_policy={none, ca, no_ca, signature, no_signature, crl_online, crl_offline, crl_auto}</token></term>
617617
<listitem>
618618
<para>
619619
Sets the Certificate verification policy:
620620
<itemizedlist>
621-
<listitem><token>none</token>: Performs no verification at all
621+
<listitem><token>none</token>: Performs only CA and signature checks, does not do CRL checks.
622622
</listitem>
623623

624-
<listitem><token>ca</token>: Checks that Certificate has a recognized CA from ca_dir
624+
<listitem><token>ca</token>: Checks that Certificate has a recognized CA from ca_dir.
625625
</listitem>
626626

627-
<listitem><token>signature></token>: Does a signature check to ensure that private and public key matches
627+
<listitem><token>no_ca</token>: Does not check that Certificate is signed by a recognized CA. Only this value disables the CA check.
628+
</listitem>
629+
630+
<listitem><token>signature></token>: Does a signature check to ensure that private and public key matches.
631+
</listitem>
632+
633+
<listitem><token>no_signature></token>: Does not check the signature to ensure that private and public key matches. Only this value disables the signature check.
628634
</listitem>
629635

630636
<listitem><token>crl_online</token>: Downloads the CRL from the location

etc/pam_pkcs11.conf.example.in

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,22 @@ pam_pkcs11 {
9292
support_threads = false;
9393

9494
# Sets the Certificate verification policy.
95-
# "none" Performs no verification, except (!) the signature
96-
# "ca" Does CA check
97-
# "crl_online" Downloads the CRL form the location given by the
98-
# CRL distribution point extension of the certificate
99-
# "crl_offline" Uses the locally stored CRLs
100-
# "crl_auto" Is a combination of online and offline; it first
101-
# tries to download the CRL from a possibly given CRL
102-
# distribution point and if this fails, uses the local
103-
# CRLs
104-
# "signature" Does a signature check to ensure that private
105-
# and public key matches
106-
# "no_signature" The only value that disables signature check.
95+
# "none" Performs only (!) CA and signature checks
96+
# "ca" Does CA check
97+
# "no_ca" The only value that disables CA check
98+
# "crl_online" Downloads the CRL form the location given by the
99+
# CRL distribution point extension of the certificate
100+
# "crl_offline" Uses the locally stored CRLs
101+
# "crl_auto" Is a combination of online and offline; it first
102+
# tries to download the CRL from a possibly given CRL
103+
# distribution point and if this fails, uses the local
104+
# CRLs
105+
# "signature" Does a signature check to ensure that private
106+
# and public key matches
107+
# "no_signature" The only value that disables signature check
107108
#
108109
# You can use a combination of ca,crl, and signature flags, or just
109-
# use "none".
110+
# use "none". Use "none,no_ca,no_signature" to disable all checks.
110111
cert_policy = ca,signature;
111112

112113
# What kind of token?
@@ -140,7 +141,7 @@ pam_pkcs11 {
140141
support_threads = false;
141142
ca_dir = /etc/pam_pkcs11/cacerts;
142143
crl_dir = /etc/pam_pkcs11/crls;
143-
cert_policy = signature;
144+
cert_policy = ca,signature;
144145
}
145146

146147
# Which mappers ( Cert to login ) to use?

src/common/cert_vfy.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ static X509_STORE * setup_store(cert_policy *policy) {
408408
}
409409
}
410410
/* add needed hash dir pathname entries */
411-
if ( (policy->ca_policy) && (is_dir(policy->ca_dir)>0) ) {
411+
if ( (!policy->no_ca_policy==0) && (is_dir(policy->ca_dir)>0) ) {
412412
const char *pt=policy->ca_dir;
413413
if ( strstr(pt,"file:///")) pt+=8; /* strip url if needed */
414414
DBG1("Adding hash dir '%s' to CACERT checks",policy->ca_dir);
@@ -434,7 +434,7 @@ static X509_STORE * setup_store(cert_policy *policy) {
434434
}
435435
}
436436
/* and add file entries to lookup */
437-
if ( (policy->ca_policy) && (is_file(policy->ca_dir)>0) ) {
437+
if ( (policy->no_ca_policy==0) && (is_file(policy->ca_dir)>0) ) {
438438
const char *pt=policy->ca_dir;
439439
if ( strstr(pt,"file:///")) pt+=8; /* strip url if needed */
440440
DBG1("Adding file '%s' to CACERT checks",policy->ca_dir);
@@ -467,7 +467,7 @@ int verify_certificate(X509 * x509, cert_policy *policy)
467467
X509_STORE_CTX *ctx = NULL;
468468

469469
/* if neither ca nor crl check are requested skip */
470-
if ( (policy->ca_policy==0) && (policy->crl_policy==CRLP_NONE) ) {
470+
if ( (policy->no_ca_policy==1) && (policy->crl_policy==CRLP_NONE) ) {
471471
DBG("Neither CA nor CRL check requested. CertVrfy() skipped");
472472
return 1;
473473
}
@@ -489,7 +489,7 @@ int verify_certificate(X509 * x509, cert_policy *policy)
489489
#if 0
490490
X509_STORE_CTX_set_purpose(ctx, purpose);
491491
#endif
492-
if (policy->ca_policy) {
492+
if (!policy->no_ca_policy) {
493493
rv = X509_verify_cert(ctx);
494494
if (rv != 1) {
495495
X509_STORE_CTX_free(ctx);

src/common/cert_vfy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ typedef enum {
4646
} ocsp_policy_t;
4747

4848
struct cert_policy_st {
49-
int ca_policy;
49+
int no_ca_policy;
5050
int crl_policy;
5151
int no_signature_policy;
5252
const char *ca_dir;

src/pam_pkcs11/pam_config.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static void display_config (void) {
8585
DBG1("crl_dir %s",configuration.policy.crl_dir);
8686
DBG1("nss_dir %s",configuration.policy.nss_dir);
8787
DBG1("support_threads %d",configuration.support_threads);
88-
DBG1("ca_policy %d",configuration.policy.ca_policy);
88+
DBG1("no_ca_policy %d",configuration.policy.no_ca_policy);
8989
DBG1("crl_policy %d",configuration.policy.crl_policy);
9090
DBG1("no_signature_policy %d",configuration.policy.no_signature_policy);
9191
DBG1("ocsp_policy %d",configuration.policy.ocsp_policy);
@@ -179,7 +179,7 @@ static void parse_config_file(void) {
179179
if ( !strcmp(policy_list->data,"none") ) {
180180
configuration.policy.crl_policy=CRLP_NONE;
181181
configuration.policy.ocsp_policy=OCSP_NONE;
182-
configuration.policy.ca_policy=0;
182+
configuration.policy.no_ca_policy=0;
183183
configuration.policy.no_signature_policy=0;
184184
break;
185185
} else if ( !strcmp(policy_list->data,"crl_auto") ) {
@@ -191,7 +191,9 @@ static void parse_config_file(void) {
191191
} else if ( !strcmp(policy_list->data,"ocsp_on") ) {
192192
configuration.policy.ocsp_policy=OCSP_ON;
193193
} else if ( !strcmp(policy_list->data,"ca") ) {
194-
configuration.policy.ca_policy=1;
194+
// ignore this setting for legacy reasons
195+
} else if ( !strcmp(policy_list->data,"no_ca") ) {
196+
configuration.policy.no_ca_policy=1;
195197
} else if ( !strcmp(policy_list->data,"signature") ) {
196198
// ignore this setting for legacy reasons
197199
} else if ( !strcmp(policy_list->data,"no_signature") ) {
@@ -322,7 +324,7 @@ struct configuration_st *pk_configure( int argc, const char **argv ) {
322324
if (strstr(argv[i],"cert_policy=") ) {
323325
if (strstr(argv[i],"none")) {
324326
configuration.policy.crl_policy=CRLP_NONE;
325-
configuration.policy.ca_policy=0;
327+
configuration.policy.no_ca_policy=0;
326328
configuration.policy.no_signature_policy=0;
327329
configuration.policy.ocsp_policy=OCSP_NONE;
328330
}
@@ -339,7 +341,10 @@ struct configuration_st *pk_configure( int argc, const char **argv ) {
339341
configuration.policy.ocsp_policy=OCSP_ON;
340342
}
341343
if (strstr(argv[i],"ca")) {
342-
configuration.policy.ca_policy=1;
344+
// ignore this setting for legacy reasons
345+
}
346+
if (strstr(argv[i],"no_ca")) {
347+
configuration.policy.no_ca_policy=1;
343348
}
344349
if (strstr(argv[i],"signature")) {
345350
// ignore this setting for legacy reasons

0 commit comments

Comments
 (0)