verify_cert(struct tls_session *session, x509_cert_t *cert, int cert_depth)
{
char *subject = NULL;
- char envname[64];
char common_name[TLS_USERNAME_LEN] = {0};
const struct tls_options *opt;
session->verified = false;
/* get the X509 name */
- if (verify_get_subject(&subject, cert))
+ subject = verify_get_subject(cert);
+ if (!subject)
{
msg (D_TLS_ERRORS, "VERIFY ERROR: depth=%d, could not extract X509 "
"subject string from certificate", cert_depth);
}
}
+ /* enforce character class restrictions in common name */
string_mod_sslname (common_name, COMMON_NAME_CHAR_CLASS, opt->ssl_flags);
-#if 0 /* print some debugging info */
- {
- struct gc_arena gc = gc_new ();
- msg (M_INFO, "LOCAL OPT[%d]: %s", cert_depth, opt->local_options);
- msg (M_INFO, "X509[%d]: %s", cert_depth, subject);
- msg (M_INFO, "SHA1[%d]: %s", cert_depth, format_hex(cert->sha1_hash, SHA_DIGEST_LENGTH, 0, &gc));
- gc_free (&gc);
- }
-#endif
-
/* warn if cert chain is too deep */
if (cert_depth >= MAX_CERT_DEPTH)
{
session->verified = true;
done:
- OPENSSL_free (subject);
+ verify_free_subject (subject);
return (session->verified == true) ? 1 : 0;
err:
- ERR_clear_error ();
+ tls_clear_error();
session->verified = false;
goto done;
}
/*
* Retrieve certificate's subject name, and place it in **subject.
*
- * Memory for subject is allocated in the process, and must be freed.
+ * The returned string must be freed with \c verify_free_subject()
*
- * @param subject Pointer to memory to be allocated for the subject
* @param cert Certificate to retrieve the subject from.
*
- * @return \c 1 on failure, \c 0 on success
+ * @return a string containing the subject
+ */
+char *verify_get_subject (X509 *cert);
+
+/*
+ * Free a subjectnumber string as returned by \c verify_get_subject()
+ *
+ * @param subject The subject to be freed.
*/
-bool verify_get_subject (char **subject, x509_cert_t *cert);
+void verify_free_subject (char *subject);
/*
* Retrieve the certificate's username from the specified field.
* Return the certificate's serial number.
*
* The serial number is returned as a string, since it might be a bignum.
- * The returened string must be freed with \c verify_free_serial()
+ * The returned string must be freed with \c verify_free_serial()
*
* @param cert Certificate to retrieve the serial number from.
*
return verify_cert(session, ctx->current_cert, ctx->error_depth);
}
-int
-verify_get_subject (char **subject, X509 *cert)
-{
- *subject = X509_NAME_oneline (X509_get_subject_name (cert), NULL, 0);
- if (!*subject)
- return 1;
-
- return 0;
-}
-
#ifdef ENABLE_X509ALTUSERNAME
static
bool extract_x509_extension(X509 *cert, char *fieldname, char *out, int size)
OPENSSL_free(serial);
}
+char *
+verify_get_subject (X509 *cert)
+{
+ return X509_NAME_oneline (X509_get_subject_name (cert), NULL, 0);
+}
+
+void
+verify_free_subject (char *subject)
+{
+ if (subject)
+ OPENSSL_free(subject);
+}
+
+
#ifdef ENABLE_X509_TRACK
/*
* setenv_x509_track function -- save X509 fields to environment,