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