Skip to content

Commit 2e8ff6c

Browse files
committed
Allow PKCS12 file content to be included inline in configuration file,
rendered as base64. git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@6412 e7ae566f-a301-0410-adde-c780ea21d3b5
1 parent 5f866d9 commit 2e8ff6c

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

options.c

+6
Original file line numberDiff line numberDiff line change
@@ -5680,6 +5680,12 @@ add_option (struct options *options,
56805680
{
56815681
VERIFY_PERMISSION (OPT_P_GENERAL);
56825682
options->pkcs12_file = p[1];
5683+
#if ENABLE_INLINE_FILES
5684+
if (streq (p[1], INLINE_FILE_TAG) && p[2])
5685+
{
5686+
options->pkcs12_file_inline = p[2];
5687+
}
5688+
#endif
56835689
}
56845690
else if (streq (p[0], "askpass"))
56855691
{

options.h

+1
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ struct options
473473
const char *cert_file_inline;
474474
char *priv_key_file_inline;
475475
const char *dh_file_inline;
476+
const char *pkcs12_file_inline; /* contains the base64 encoding of pkcs12 file */
476477
#endif
477478

478479
int ns_cert_type; /* set to 0, NS_SSL_SERVER, or NS_SSL_CLIENT */

ssl.c

+32-10
Original file line numberDiff line numberDiff line change
@@ -1514,23 +1514,41 @@ init_ssl (const struct options *options)
15141514

15151515
if (options->pkcs12_file)
15161516
{
1517-
/* Use PKCS #12 file for key, cert and CA certs */
1517+
/* Use PKCS #12 file for key, cert and CA certs */
15181518

15191519
FILE *fp;
15201520
EVP_PKEY *pkey;
15211521
X509 *cert;
15221522
STACK_OF(X509) *ca = NULL;
1523-
PKCS12 *p12;
1523+
PKCS12 *p12=NULL;
15241524
int i;
15251525
char password[256];
15261526

1527-
/* Load the PKCS #12 file */
1528-
if (!(fp = fopen(options->pkcs12_file, "rb")))
1529-
msg (M_SSLERR, "Error opening file %s", options->pkcs12_file);
1530-
p12 = d2i_PKCS12_fp(fp, NULL);
1531-
fclose (fp);
1532-
if (!p12) msg (M_SSLERR, "Error reading PKCS#12 file %s", options->pkcs12_file);
1533-
1527+
#if ENABLE_INLINE_FILES
1528+
if (!strcmp (options->pkcs12_file, INLINE_FILE_TAG) && options->pkcs12_file_inline)
1529+
{
1530+
BIO *b64 = BIO_new (BIO_f_base64());
1531+
BIO *bio = BIO_new_mem_buf ((void *)options->pkcs12_file_inline, (int)strlen(options->pkcs12_file_inline));
1532+
ASSERT(b64 && bio);
1533+
BIO_push (b64, bio);
1534+
p12 = d2i_PKCS12_bio(b64, NULL);
1535+
if (!p12)
1536+
msg (M_SSLERR, "Error reading inline PKCS#12 file");
1537+
BIO_free (b64);
1538+
BIO_free (bio);
1539+
}
1540+
else
1541+
#endif
1542+
{
1543+
/* Load the PKCS #12 file */
1544+
if (!(fp = fopen(options->pkcs12_file, "rb")))
1545+
msg (M_SSLERR, "Error opening file %s", options->pkcs12_file);
1546+
p12 = d2i_PKCS12_fp(fp, NULL);
1547+
fclose (fp);
1548+
if (!p12)
1549+
msg (M_SSLERR, "Error reading PKCS#12 file %s", options->pkcs12_file);
1550+
}
1551+
15341552
/* Parse the PKCS #12 file */
15351553
if (!PKCS12_parse(p12, "", &pkey, &cert, &ca))
15361554
{
@@ -1539,8 +1557,12 @@ init_ssl (const struct options *options)
15391557
ca = NULL;
15401558
if (!PKCS12_parse(p12, password, &pkey, &cert, &ca))
15411559
{
1560+
#ifdef ENABLE_MANAGEMENT
1561+
if (management && (ERR_GET_REASON (ERR_peek_error()) == PKCS12_R_MAC_VERIFY_FAILURE))
1562+
management_auth_failure (management, UP_TYPE_PRIVATE_KEY, NULL);
1563+
#endif
15421564
PKCS12_free(p12);
1543-
msg (M_WARN|M_SSL, "Error parsing PKCS#12 file %s", options->pkcs12_file);
1565+
msg (M_INFO, "OpenSSL ERROR code: %d", (ERR_GET_REASON (ERR_peek_error()))); // fixme
15441566
goto err;
15451567
}
15461568
}

0 commit comments

Comments
 (0)