}
/* list optional pathLenConstraint */
- pathlen = x509->get_pathLenConstraint(x509);
+ pathlen = x509->get_constraint(x509, X509_PATH_LEN);
if (pathlen != X509_NO_CONSTRAINT)
{
fprintf(out, " pathlen: %d\n", pathlen);
typedef struct x509_policy_mapping_t x509_policy_mapping_t;
typedef struct x509_cdp_t x509_cdp_t;
typedef enum x509_flag_t x509_flag_t;
+typedef enum x509_constraint_t x509_constraint_t;
/**
* X.509 certificate flags.
};
/**
+ * Different numerical X.509 constraints.
+ */
+enum x509_constraint_t {
+ /** pathLenConstraint basicConstraints */
+ X509_PATH_LEN,
+ /** inhibitPolicyMapping policyConstraint */
+ X509_INHIBIT_POLICY_MAPPING,
+ /** requireExplicitPolicy policyConstraint */
+ X509_REQUIRE_EXPLICIT_POLICY,
+};
+
+/**
* X.509 certPolicy extension.
*/
struct x509_cert_policy_t {
chunk_t (*get_authKeyIdentifier)(x509_t *this);
/**
- * Get an optional path length constraint.
- *
- * @return pathLenConstraint, X509_NO_CONSTRAINT if none found
- */
- int (*get_pathLenConstraint)(x509_t *this);
-
- /**
- * Get a policyConstraint, inhibitPolicyMapping or requireExplicitPolicy.
+ * Get a numerical X.509 constraint.
*
- * @param inhibit TRUE to get inhibitPolicyMapping
+ * @param type type of constraint to get
* @return constraint, X509_NO_CONSTRAINT if none found
*/
- int (*get_policyConstraint)(x509_t *this, bool inhibit);
+ int (*get_constraint)(x509_t *this, x509_constraint_t type);
/**
* Create an enumerator over all subjectAltNames.
{
int pathlen_constraint;
- pathlen_constraint = issuer->get_pathLenConstraint(issuer);
+ pathlen_constraint = issuer->get_constraint(issuer, X509_PATH_LEN);
if (pathlen_constraint != X509_NO_CONSTRAINT &&
pathlen > pathlen_constraint)
{
enumerator = chain->create_enumerator(chain);
while (enumerator->enumerate(enumerator, &x509))
{
- expl = x509->get_policyConstraint(x509, FALSE);
+ expl = x509->get_constraint(x509, X509_REQUIRE_EXPLICIT_POLICY);
if (expl != X509_NO_CONSTRAINT)
{
if (!has_policy_chain(chain, (x509_t*)subject, len - expl))
enumerator = chain->create_enumerator(chain);
while (enumerator->enumerate(enumerator, &x509))
{
- expl = x509->get_policyConstraint(x509, TRUE);
+ expl = x509->get_constraint(x509, X509_INHIBIT_POLICY_MAPPING);
if (expl != X509_NO_CONSTRAINT)
{
if (!has_policy_mapping(chain, len - expl))
return chunk_empty;
}
-METHOD(x509_t, get_pathLenConstraint, int,
- private_openssl_x509_t *this)
-{
- return this->pathlen;
-}
-
-METHOD(x509_t, get_policyConstraint, int,
- private_openssl_x509_t *this, bool inhibit)
+METHOD(x509_t, get_constraint, int,
+ private_openssl_x509_t *this, x509_constraint_t type)
{
- return X509_NO_CONSTRAINT;
+ switch (type)
+ {
+ case X509_PATH_LEN:
+ return this->pathlen;
+ default:
+ return X509_NO_CONSTRAINT;
+ }
}
METHOD(x509_t, create_subjectAltName_enumerator, enumerator_t*,
.get_serial = _get_serial,
.get_subjectKeyIdentifier = _get_subjectKeyIdentifier,
.get_authKeyIdentifier = _get_authKeyIdentifier,
- .get_pathLenConstraint = _get_pathLenConstraint,
- .get_policyConstraint = _get_policyConstraint,
+ .get_constraint = _get_constraint,
.create_subjectAltName_enumerator = _create_subjectAltName_enumerator,
.create_crl_uri_enumerator = _create_crl_uri_enumerator,
.create_ocsp_uri_enumerator = _create_ocsp_uri_enumerator,
return this->authKeyIdentifier;
}
-METHOD(x509_t, get_pathLenConstraint, int,
- private_x509_cert_t *this)
-{
- return this->pathLenConstraint;
-}
-
-METHOD(x509_t, get_policyConstraint, int,
- private_x509_cert_t *this, bool inhibit)
+METHOD(x509_t, get_constraint, int,
+ private_x509_cert_t *this, x509_constraint_t type)
{
- if (inhibit)
- {
- return this->inhibit_policy_constraint;
+ switch (type)
+ {
+ case X509_PATH_LEN:
+ return this->pathLenConstraint;
+ case X509_REQUIRE_EXPLICIT_POLICY:
+ return this->explicit_policy_constraint;
+ case X509_INHIBIT_POLICY_MAPPING:
+ return this->inhibit_policy_constraint;
+ default:
+ return X509_NO_CONSTRAINT;
}
- return this->explicit_policy_constraint;
}
METHOD(x509_t, create_subjectAltName_enumerator, enumerator_t*,
.get_serial = _get_serial,
.get_subjectKeyIdentifier = _get_subjectKeyIdentifier,
.get_authKeyIdentifier = _get_authKeyIdentifier,
- .get_pathLenConstraint = _get_pathLenConstraint,
- .get_policyConstraint = _get_policyConstraint,
+ .get_constraint = _get_constraint,
.create_subjectAltName_enumerator = _create_subjectAltName_enumerator,
.create_crl_uri_enumerator = _create_crl_uri_enumerator,
.create_ocsp_uri_enumerator = _create_ocsp_uri_enumerator,
chunk_t chunk;
bool first;
char *uri;
- int len;
+ int len, explicit, inhibit;
x509_flag_t flags;
x509_cdp_t *cdp;
x509_cert_policy_t *policy;
}
enumerator->destroy(enumerator);
- len = x509->get_pathLenConstraint(x509);
+ len = x509->get_constraint(x509, X509_PATH_LEN);
if (len != X509_NO_CONSTRAINT)
{
printf("pathlen: %d\n", len);
}
enumerator->destroy(enumerator);
- if (x509->get_policyConstraint(x509, FALSE) != X509_NO_CONSTRAINT ||
- x509->get_policyConstraint(x509, TRUE) != X509_NO_CONSTRAINT)
+ explicit = x509->get_constraint(x509, X509_REQUIRE_EXPLICIT_POLICY);
+ inhibit = x509->get_constraint(x509, X509_INHIBIT_POLICY_MAPPING);
+
+ if (explicit != X509_NO_CONSTRAINT || inhibit != X509_NO_CONSTRAINT)
{
printf("PolicyConstraints:\n");
- if (x509->get_policyConstraint(x509, FALSE) != X509_NO_CONSTRAINT)
+ if (explicit != X509_NO_CONSTRAINT)
{
- printf(" requireExplicitPolicy: %d\n",
- x509->get_policyConstraint(x509, FALSE));
+ printf(" requireExplicitPolicy: %d\n", explicit);
}
- if (x509->get_policyConstraint(x509, TRUE) != X509_NO_CONSTRAINT)
+ if (inhibit != X509_NO_CONSTRAINT)
{
- printf(" inhibitPolicyMapping: %d\n",
- x509->get_policyConstraint(x509, TRUE));
+ printf(" inhibitPolicyMapping: %d\n", inhibit);
}
}
)
/* check path length constraint */
- pathlen_constraint = x509->get_pathLenConstraint(x509);
+ pathlen_constraint = x509->get_constraint(x509, X509_PATH_LEN);
if (pathlen_constraint != X509_NO_CONSTRAINT &&
pathlen > pathlen_constraint)
{
unlock_authcert_list("verify_x509cert");
/* check path length constraint */
- pathlen_constraint = x509->get_pathLenConstraint(x509);
+ pathlen_constraint = x509->get_constraint(x509, X509_PATH_LEN);
if (pathlen_constraint != X509_NO_CONSTRAINT &&
pathlen > pathlen_constraint)
{
}
/* list optional pathLenConstraint */
- pathlen = x509->get_pathLenConstraint(x509);
+ pathlen = x509->get_constraint(x509, X509_PATH_LEN);
if (pathlen != X509_NO_CONSTRAINT)
{
whack_log(RC_COMMENT, " pathlen: %d", pathlen);