security.c revision 5c51f1241dbbdf2656d0e10011981411ed0c9673
/*
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Module: security.c
* Description:
* Module for handling certificates and various
* utilities to access their data.
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <limits.h>
#include <pkgstrct.h>
#include <pkginfo.h>
#include <locale.h>
#include <libintl.h>
#include <unistd.h>
#include <stdlib.h>
#include "pkgerr.h"
#include "pkglib.h"
#include "pkglibmsgs.h"
#include "pkglocale.h"
#include "p12lib.h"
/* length of allowable passwords */
#define MAX_PASSLEN 128
/*
* Name: init_security
* Description: Initializes structures, libraries, for security operations
* Arguments: none
* Returns: 0 if we couldn't initialize, non-zero otherwise
*/
void
sec_init(void)
{
(void) SSL_library_init();
}
/*
* get_cert_chain - Builds a chain of certificates, from a given
* user certificate to a trusted certificate.
*
* Arguments:
* err - Error object to add errors to
* cert - User cert to start with
* cas - Trusted certs to use as trust anchors
* chain - The resulting chain of certs (in the form of an
* ordered set) is placed here.
*
* Returns:
* 0 - Success - chain is stored in 'chain'.
* non-zero - Failure, errors recorded in err
*/
int
{
int i;
int ret = 0;
ret = 1;
goto cleanup;
}
/* add all ca certs into the store */
for (i = 0; i < sk_X509_num(cas); i++) {
/* LINTED pointer cast may result in improper alignment */
ret = 1;
goto cleanup;
}
}
/* initialize context object used during the chain resolution */
ret = 1;
goto cleanup;
}
/* attempt to verify the cert, which builds the cert chain */
if (X509_verify_cert(store_ctx) <= 0) {
ret = 1;
goto cleanup;
}
(void) X509_STORE_free(ca_store);
(void) X509_STORE_CTX_cleanup(store_ctx);
(void) X509_STORE_CTX_free(store_ctx);
}
return (ret);
}
/*
* Name: get_subject_name
* Description: Retrieves a name used for identifying a certificate's subject.
*
* Arguments: cert - The certificate to get the name from
*
* Returns : A static buffer containing the common name (CN) of the
* subject of the cert.
*
* if the CN is not available, returns a string with the entire
* X509 distinguished name.
*/
char
{
ATTR_MAX) <= 0) {
}
return (sname);
}
/*
* Name: get_display_name
* Description: Retrieves a name used for identifying a certificate's issuer.
*
* Arguments: cert - The certificate to get the name from
*
* Returns : A static buffer containing the common name (CN)
* of the issuer of the cert.
*
* if the CN is not available, returns a string with the entire
* X509 distinguished name.
*/
char
{
ATTR_MAX) <= 0) {
}
return (sname);
}
/*
* Name: get_serial_num
* Description: Retrieves the serial number of an X509 cert
*
* Arguments: cert - The certificate to get the data from
*
* Returns : A static buffer containing the serial number
* of the cert
*
* if the SN is not available, returns NULL
*/
char
{
return (NULL);
} else {
}
return (sn_str);
}
/*
* Name: get_fingerprint
* Description: Generates a fingerprint string given
* a digest algorithm with which to calculate
* the fingerprint
*
* Arguments: cert - The certificate to get the data from
* Arguments: alg - The algorithm to use to calculate the fingerprint
*
* Returns : A static buffer containing the digest
* NULL if cert is NULL, or digest cannot be calculated
*/
char
{
unsigned int n;
unsigned char md[EVP_MAX_MD_SIZE];
int i;
return (NULL);
}
/* start with empty string */
fp_str[0] = '\0';
for (i = 0; i < (int)n; i++) {
/* form a byte of the fingerprint */
/* cat it onto the end of the result */
}
/* nuke trailing ':' */
return (fp_str);
}