KMSAgentPKIKeyOpenSSL.cpp revision 4f14b0f29aa144cc03efdde5508ae126ae197acf
/*
* 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
*/
/*
*/
/**
* \file KMSAgentPKIKeyOpenSSL.cpp
*/
#include <stdio.h>
#include "SYSCommon.h"
#include "KMSAgentPKIimpl.h"
typedef struct PKeyControl
{
} PKeyControl;
void * InitializePKeyImpl()
{
if ( pPKeyControl != NULL )
{
}
return pPKeyControl;
}
void FinalizePKeyImpl( void * i_pPKeyImpl )
{
if ( i_pPKeyImpl != NULL )
{
}
}
#ifdef KMSUSERPKCS12
void *GetPKey(void *i_pPKeyImpl) {
return ((void *)pPKeyControl->pPKey);
}
return;
}
#endif
/**
* export the private key to a memory BIO, if error, return NULL
*/
const char * const i_pPassphrase)
{
int iReturn;
// set cipher, if passphrase is not empty
if(i_pPassphrase != NULL)
{
}
// create memory BIO
{
//fixme: log -- no memory
return NULL;
}
(pMemBio,
if(!iReturn) // return 0: means error occurs
{
//fixme: log -- could not export private key
return NULL;
}
return pMemBio;
}
bool SavePrivateKeyToBuffer(
void * const i_pPKeyImpl,
unsigned char * const i_pcBuffer,
int i_iBufferLength,
int * const o_pActualLength,
const char * const i_pPassphrase,
int i_iFormat)
{
i_pcBuffer &&
i_iBufferLength > 0 &&
int iLength;
// create memory BIO
{
//fixme: log -- no memory
return false;
}
// If the output buffer is a string, it needs to be NULL terminated
// So always append a NULL to the output
{
//fixme: log -- buffer too small
return false;
}
// copy the data to given buffer
// NULL terminate the string
// free memory
return true;
}
/**
* import the private key from a BIO, if error, return NULL
*/
char *i_pPassphrase )
{
if (io_pPKeyControl == NULL)
{
return false;
}
{
return false;
}
{
return false; // do not allow overwrite
}
{
// fixme: log: invalid private key format or passphrase
return false;
}
return true;
}
bool LoadPrivateKeyFromBuffer(
void * const i_pPKeyImpl,
unsigned char * i_pcBuffer,
int i_iLength,
const char * const i_pPassphrase,
int i_iFormat)
{
bool bReturn;
// create a mem bio from the given buffer
// Note that BIO_new_mem_buf() creates a BIO which never
// destroy the memory attached to it.
{
//fixme: log -- no memory
return false;
}
pMemBio, (char *)i_pPassphrase );
return bReturn;
}
/**
* export the public key to a memory BIO, if error, return NULL
*/
{
int iReturn;
// create memory BIO
{
//fixme: log -- no memory
return NULL;
}
if(!iReturn) // return 0: means error occurs
{
//fixme: log -- could not export private key
return NULL;
}
return pMemBio;
}
bool SavePublicKeyToBuffer(
void * const i_pPKeyImpl,
unsigned char * const i_pcBuffer,
int i_iBufferLength,
int * const o_pActualLength,
int i_iFormat)
{
i_pcBuffer &&
i_iBufferLength > 0 &&
int iLength;
// create memory BIO
{
return false;
}
// If the output buffer is a string, it needs to be NULL terminated
// So always append a NULL to the output
{
return false;
}
// copy the data to given buffer
// NULL terminate the string
// free memory
return true;
}
/**
* import the public key from a BIO, if error, return NULL
*/
{
if(io_pPublicKeyControl == NULL)
{
return false;
}
{
return false;
}
{
return false; // do not allow overwrite
}
{
// fixme: log: invalid public key format or passphrase
return false;
}
return true;
}
bool LoadPublicKeyFromBuffer(
void * const i_pPublicKeyImpl,
unsigned char * i_pcBuffer,
int i_iLength,
int i_iFormat)
{
bool bReturn;
// create a mem bio from the given buffer
// Note that BIO_new_mem_buf() creates a BIO which never
// destroy the memory attached to it.
{
//fixme: log -- no memory
return false;
}
pMemBio );
return bReturn;
}
bool PublicKeyEncrypt (int i_iLength,
const unsigned char * const i_pcPlainText,
unsigned char * const o_pcCypherText,
int * const o_pActualLength,
void * pPKeyControl )
{
//#if defined(DEBUG)
// RSA_print_fp(stdout, pRSAPublicKey, 0);
// printf("PublicKeyEncrypt(): RSA_size()=%d, cyphertextLen=%d\n",
// RSA_size(pRSAPublicKey),
// i_iLength);
//#endif
if ( *o_pActualLength < 0 )
{
return false;
}
else
{
return true;
}
}