/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <pkglocs.h>
#include <locale.h>
#include <libintl.h>
#include <signal.h>
#include <fcntl.h>
#include <libintl.h>
#include <dirent.h>
#include <pkglib.h>
#include <p12lib.h>
#include <install.h>
#include <libadm.h>
#include <libinst.h>
#include "pkgadm.h"
#include "pkgadm_msgs.h"
/*
* Function: load_cert_and_key
* Description: Loads a public key certificate and associated private key
* from a stream.
* Parameters: err - Where to write errors to for underlying library calls
* incert - File to read certs and keys from
* format - The format of the file
* passarg - How to collect password if needed to decrypt file
* key - Location to store resulting key if found
* cert - Location to store resulting cert if found.
*
* Returns: f one or more certificates are found in the file,
* and one or more keys are found, then the first
* certificate is used, and the keys are searched for a
* match. If no key matches the cert, then only the cert
* is returned. If no certs are found, but one or more
* keys are found, then the first key is returned.
*/
int
{
int i, ret = 0;
unsigned long crypto_err;
switch (format) {
case KEYSTORE_FORMAT_DER:
/* first try to load a DER cert, which cannot contain a key */
ret = 1;
}
break;
case KEYSTORE_FORMAT_PEM:
default:
/* print out openssl-generated PEM errors */
while ((crypto_err = ERR_get_error()) != 0) {
}
ret = 1;
goto cleanup;
}
/* take the first cert in the file, if any */
ret = 1;
goto cleanup;
} else {
}
}
/*
* if we found a cert and some keys,
* only return the key that
* matches the cert
*/
for (i = 0; i < sk_EVP_PKEY_num(keys); i++) {
sk_EVP_PKEY_value(keys, i))) {
tmpkey =
sk_EVP_PKEY_value(keys, i);
break;
}
}
} else {
if (sk_EVP_PKEY_num(keys) > 0) {
}
}
}
break;
}
/* set results */
}
}
}
}
return (ret);
}
/*
* Function: load_all_certs
* Description: Loads alll certificates from a stream.
* Parameters: err - Where to write errors to for underlying library calls
* incert - File to read certs and keys from
* format - The format of the file
* passarg - How to collect password if needed to decrypt file
* certs - Location to store resulting cert if found.
*
* Returns: 0 - success, all certs placed in ''certs'
* non-zero failure, errors in 'err'
*/
int
{
int ret = 0;
unsigned long crypto_err;
switch (format) {
case KEYSTORE_FORMAT_DER:
/* first try to load a DER cert, which cannot contain a key */
ret = 1;
goto cleanup;
}
ret = 1;
goto cleanup;
}
break;
case KEYSTORE_FORMAT_PEM:
default:
/* print out openssl-generated PEM errors */
while ((crypto_err = ERR_get_error()) != 0) {
}
}
break;
}
/* set results */
}
}
return (ret);
}