download.c revision 99ebb4ca412cb0a19d77a3899a87c055b9c30fa8
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys * CDDL HEADER START
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys * The contents of this file are subject to the terms of the
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys * Common Development and Distribution License (the "License").
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys * You may not use this file except in compliance with the License.
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys * See the License for the specific language governing permissions
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys * and limitations under the License.
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys * When distributing Covered Code, include this CDDL HEADER in each
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys * If applicable, add the following below this CDDL HEADER, with the
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys * fields enclosed by brackets "[]" replaced with your own identifying
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys * information: Portions Copyright [yyyy] [name of copyright owner]
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys * CDDL HEADER END
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys * Use is subject to license terms.
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys#pragma ident "%Z%%M% %I% %E% SMI"
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys extern char *optarg_av;
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys "t:(objtype)u:(url)h:(http_proxy)o:(outfile)d:(dir)")) != EOF) {
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys "unrecognized download option '%s'\n"),
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys /* No additional args allowed. */
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys /* Check the dir and outfile options */
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys /* If outfile is not specified, use the basename of URI */
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys cryptoerror(LOG_STDERR, gettext("Incorrect dir or outfile "
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys "option value \n"));
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys /* Check if the file exists and might be overwritten. */
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys gettext("Respond with yes or no.\n"), B_FALSE) == B_FALSE) {
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys return (0);
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys /* URI MUST be specified */
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys cryptoerror(LOG_STDERR, gettext("A URL must be specified\n"));
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys * Get the http proxy from the command "http_proxy" option or the
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys * environment variable. The command option has a higher priority.
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys /* If objtype is not specified, default to CRL */
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys if (oclass == 0) {
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys if ((rv = KMF_Initialize(&kmfhandle, NULL, NULL)) != KMF_OK) {
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys cryptoerror(LOG_STDERR, gettext("Error initializing KMF\n"));
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys /* Now we are ready to download */
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys rv = KMF_DownloadCRL(kmfhandle, url, proxy, proxy_port, 30,
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys rv = KMF_DownloadCert(kmfhandle, url, proxy, proxy_port, 30,
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys switch (rv) {
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys cryptoerror(LOG_STDERR, gettext("Not a CRL file\n"));
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys * If the file is successfully downloaded, we also check the date.
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys * If the downloaded file is outdated, give a warning.
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys } else { /* certificate */
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys ch_rv = KMF_ReadInputFile(kmfhandle, fullpath, &cert);
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys gettext("Warning: the downloaded file is expired.\n"));
99ebb4ca412cb0a19d77a3899a87c055b9c30fa8wyllys gettext("Warning: failed to check the validity.\n"));