1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 24 */ 25 26 /** 27 * \file KMSAgentPKIimpl.h 28 */ 29 30 #ifndef K_KMSAgentPKIimpl_h 31 #define K_KMSAgentPKIimpl_h 32 33 /** 34 * initializes the implementation environment for an X509 35 * certificate implementation and returns an opague handle to any 36 * resources that should be freed when use of the X.509 37 * implementation is complete. This handle is used on all 38 * subsequent calls that may need to access this resource. 39 */ 40 void * InitializeCertImpl(); 41 42 /** 43 * Save the X.509 Certificate in PEM format to the specified filename 44 */ 45 bool SaveX509CertTofile( 46 void* const i_pImplResource, 47 const char * const i_pcFileName ); 48 49 /** 50 * Save the X.509Certificate in PEM format to the specified buffer 51 * and set the length of the certificate in the location referenced 52 * by o_pActualLength 53 */ 54 bool SaveX509CertToBuffer( 55 void* const i_pImplResource, 56 unsigned char * const i_pcBuffer, 57 int i_iBufferLength, 58 int * const o_pActualLength ); 59 60 /** 61 * loads the X.509 certificate from i_pcFileName and keeps a reference to it 62 * via i_pImplResource 63 */ 64 bool LoadX509CertFromFile( 65 void* const i_pImplResource, 66 const char * const i_pcFileName ); 67 68 /** 69 * load the X.509 certificate from i_pX509Buffer and keeps a reference to it 70 * via i_pImplResource 71 */ 72 bool LoadX509CertFromBuffer( 73 void* const i_pImplResource, 74 void* const i_pX509Cert, 75 int i_iLength); 76 77 /** 78 * frees any resources allocated by <code>InitializeCertImpl</code> 79 */ 80 void FinalizeCertImpl( 81 void* i_pImplResource); 82 83 /** 84 * print the X.509 certificate to stdout 85 */ 86 bool PrintX509Cert( void* const i_pImplResource ); 87 88 /** 89 * initializes the implementation environment for a public or private key 90 * and returns an opague handle to any resources that should be freed 91 * when use of the key is complete. This handle is used 92 * on all subsequent calls that may need to access this resource. 93 */ 94 void * InitializePKeyImpl(); 95 96 /** 97 * frees any resources allocated by <code>InitializePKeyImpl</code> 98 */ 99 void FinalizePKeyImpl( void * i_pPKeyImpl ); 100 101 #ifdef KMSUSERPKCS12 102 void *GetPKey( void *i_pImplResource); 103 void SetPKey( void *i_pImplResource, void *i_pPKey); 104 void *GetCert( void *i_pImplResource); 105 void SetCert( void *i_pImplResource, void *cert); 106 #endif 107 108 /** 109 * Stores the private key in a memory buffer referenced by 110 * i_pcBuffer with the length of the key being stored in the area 111 * referenced by o_pActualLength. 112 * 113 */ 114 bool SavePrivateKeyToBuffer( 115 void * const i_pPKeyImpl, 116 unsigned char * const i_pcBuffer, 117 int i_iBufferLength, 118 int * const o_pActualLength, 119 const char * const i_pPassphrase, 120 int i_iFormat); 121 122 /** 123 * load the private key into this object from the specified buffer 124 */ 125 bool LoadPrivateKeyFromBuffer( 126 void * const i_pPKeyImpl, 127 unsigned char * i_pcBuffer, 128 int i_iLength, 129 const char * const i_pPassphrase, 130 int i_iFormat); 131 132 /** 133 * Stores the pubic key in a memory buffer referenced by 134 * i_pcBuffer with the length of the key being stored in the area 135 * referenced by o_pActualLength. 136 * 137 */ 138 bool SavePublicKeyToBuffer( 139 void * const i_pPKeyImpl, 140 unsigned char * const i_pcBuffer, 141 int i_iBufferLength, 142 int * const o_pActualLength, 143 int i_iFormat); 144 145 /** 146 * load a public key into this object from the specified buffer 147 */ 148 bool LoadPublicKeyFromBuffer( 149 void * const i_pPKeyImpl, 150 unsigned char * i_pcBuffer, 151 int i_iLength, 152 int i_iFormat); 153 154 /** 155 * encrypt the plaintext using RSA encryption with the RSA public 156 * key provided and return resulting cyphertext 157 */ 158 bool PublicKeyEncrypt (int i_iLength, 159 const unsigned char * const i_pcPlainText, 160 unsigned char * const o_pcCypherText, 161 int * const o_pActualLength, 162 void * i_pRSAPublicKey); 163 164 #endif // K_KMSAgentPKIimpl_h 165 166