xref: /onnv-gate/usr/src/lib/libkmsagent/common/KMSAgentStorage.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    KMSAgentStorage.h
28*12720SWyllys.Ingersoll@Sun.COM  *
29*12720SWyllys.Ingersoll@Sun.COM  *  This header provides an interface for the agent library to persist profile information, including
30*12720SWyllys.Ingersoll@Sun.COM  *  <ul>
31*12720SWyllys.Ingersoll@Sun.COM  *  <li>Profile Configuration properties
32*12720SWyllys.Ingersoll@Sun.COM  *  <li>Profile KMS Cluster information
33*12720SWyllys.Ingersoll@Sun.COM  *  <li>PKI Certificates and Agent Private Key
34*12720SWyllys.Ingersoll@Sun.COM  *  </ul>
35*12720SWyllys.Ingersoll@Sun.COM  *  With the storage management of PKI elements is an interface for initialization of the gSoap SSL
36*12720SWyllys.Ingersoll@Sun.COM  *  client context.
37*12720SWyllys.Ingersoll@Sun.COM  *  <p>
38*12720SWyllys.Ingersoll@Sun.COM  *  The reference implementation of this interface maps these storage elements into files.
39*12720SWyllys.Ingersoll@Sun.COM  *  Other implmentations may need to persist these elements into other types of non-volatile
40*12720SWyllys.Ingersoll@Sun.COM  *  storage.
41*12720SWyllys.Ingersoll@Sun.COM  */
42*12720SWyllys.Ingersoll@Sun.COM 
43*12720SWyllys.Ingersoll@Sun.COM #ifndef KMSAGENT_STORAGE_H
44*12720SWyllys.Ingersoll@Sun.COM #define KMSAGENT_STORAGE_H
45*12720SWyllys.Ingersoll@Sun.COM 
46*12720SWyllys.Ingersoll@Sun.COM /**
47*12720SWyllys.Ingersoll@Sun.COM  *  checks if a profile exists in the working directory with the name specified in the io_pProfile struct
48*12720SWyllys.Ingersoll@Sun.COM  */
49*12720SWyllys.Ingersoll@Sun.COM extern "C" bool ProfileExists(
50*12720SWyllys.Ingersoll@Sun.COM                 const char* const i_pWorkingDirectory,
51*12720SWyllys.Ingersoll@Sun.COM                 const char* const i_pProfileName);
52*12720SWyllys.Ingersoll@Sun.COM 
53*12720SWyllys.Ingersoll@Sun.COM /**
54*12720SWyllys.Ingersoll@Sun.COM  *   creates a Storage object in the working directory with the specified name.
55*12720SWyllys.Ingersoll@Sun.COM  *   The storage object's contents are empty.
56*12720SWyllys.Ingersoll@Sun.COM  */
57*12720SWyllys.Ingersoll@Sun.COM bool CreateProfile(
58*12720SWyllys.Ingersoll@Sun.COM    KMSClientProfile* const io_pProfile,
59*12720SWyllys.Ingersoll@Sun.COM    const char* const i_pWorkingDirectory,
60*12720SWyllys.Ingersoll@Sun.COM    const char* const i_pProfileName);
61*12720SWyllys.Ingersoll@Sun.COM 
62*12720SWyllys.Ingersoll@Sun.COM /**
63*12720SWyllys.Ingersoll@Sun.COM  *  saves the Config portion of the profile into persistent storage
64*12720SWyllys.Ingersoll@Sun.COM  */
65*12720SWyllys.Ingersoll@Sun.COM bool StoreConfig(
66*12720SWyllys.Ingersoll@Sun.COM             KMSClientProfile* const i_pProfile );
67*12720SWyllys.Ingersoll@Sun.COM 
68*12720SWyllys.Ingersoll@Sun.COM /**
69*12720SWyllys.Ingersoll@Sun.COM  *  saves the Cluster information from the profile into persistent storage
70*12720SWyllys.Ingersoll@Sun.COM  */
71*12720SWyllys.Ingersoll@Sun.COM bool StoreCluster(
72*12720SWyllys.Ingersoll@Sun.COM             KMSClientProfile* const i_pProfile );
73*12720SWyllys.Ingersoll@Sun.COM 
74*12720SWyllys.Ingersoll@Sun.COM /**
75*12720SWyllys.Ingersoll@Sun.COM  *  retrieve the Config information from persistent storage into the profile
76*12720SWyllys.Ingersoll@Sun.COM  */
77*12720SWyllys.Ingersoll@Sun.COM bool GetConfig(
78*12720SWyllys.Ingersoll@Sun.COM         KMSClientProfile* const io_pProfile );
79*12720SWyllys.Ingersoll@Sun.COM 
80*12720SWyllys.Ingersoll@Sun.COM 
81*12720SWyllys.Ingersoll@Sun.COM /**
82*12720SWyllys.Ingersoll@Sun.COM  *  populate cluster array with names from storage.  If the profile does
83*12720SWyllys.Ingersoll@Sun.COM  *  does not contain cluster information then sets o_bClusterInformationFound
84*12720SWyllys.Ingersoll@Sun.COM  *  to true.
85*12720SWyllys.Ingersoll@Sun.COM  */
86*12720SWyllys.Ingersoll@Sun.COM bool GetCluster(
87*12720SWyllys.Ingersoll@Sun.COM    KMSClientProfile* const io_pProfile,
88*12720SWyllys.Ingersoll@Sun.COM    int&                   o_bClusterInformationFound );
89*12720SWyllys.Ingersoll@Sun.COM 
90*12720SWyllys.Ingersoll@Sun.COM /**
91*12720SWyllys.Ingersoll@Sun.COM  *   delete the cluster information from persistent storage
92*12720SWyllys.Ingersoll@Sun.COM  */
93*12720SWyllys.Ingersoll@Sun.COM bool DeleteCluster( KMSClientProfile* const io_pProfile );
94*12720SWyllys.Ingersoll@Sun.COM 
95*12720SWyllys.Ingersoll@Sun.COM /**
96*12720SWyllys.Ingersoll@Sun.COM  *  saves the CA certificate into persistent storage
97*12720SWyllys.Ingersoll@Sun.COM  */
98*12720SWyllys.Ingersoll@Sun.COM bool StoreCACertificate(
99*12720SWyllys.Ingersoll@Sun.COM    KMSClientProfile* const     i_pProfile,
100*12720SWyllys.Ingersoll@Sun.COM    CCertificate* const         i_pCACertificate );
101*12720SWyllys.Ingersoll@Sun.COM 
102*12720SWyllys.Ingersoll@Sun.COM 
103*12720SWyllys.Ingersoll@Sun.COM /**
104*12720SWyllys.Ingersoll@Sun.COM  *  save the CA certificate, agent certificate and agent
105*12720SWyllys.Ingersoll@Sun.COM  *  private key material to persistent storage
106*12720SWyllys.Ingersoll@Sun.COM  *  @param i_sHexHashedPassphrase this is an optional passphrase
107*12720SWyllys.Ingersoll@Sun.COM  *  that is required when the caller wishes the private key to be
108*12720SWyllys.Ingersoll@Sun.COM  *  encrypted.  The private key will then be encrypted using this
109*12720SWyllys.Ingersoll@Sun.COM  *  pass phrase.
110*12720SWyllys.Ingersoll@Sun.COM  */
111*12720SWyllys.Ingersoll@Sun.COM bool StorePKIcerts(
112*12720SWyllys.Ingersoll@Sun.COM         KMSClientProfile* const     io_pProfile,
113*12720SWyllys.Ingersoll@Sun.COM         CCertificate* const         i_pCACertificate,
114*12720SWyllys.Ingersoll@Sun.COM         CCertificate* const         i_pAgentCertificate,
115*12720SWyllys.Ingersoll@Sun.COM         CPrivateKey* const          i_pAgentPrivateKey,
116*12720SWyllys.Ingersoll@Sun.COM         const char* const           i_sHexHashedPassphrase );
117*12720SWyllys.Ingersoll@Sun.COM 
118*12720SWyllys.Ingersoll@Sun.COM /**
119*12720SWyllys.Ingersoll@Sun.COM  *  retrieve the CA certificate, agent certificate and agent
120*12720SWyllys.Ingersoll@Sun.COM  *  private key material from persistent storage and reference
121*12720SWyllys.Ingersoll@Sun.COM  *  from the profile
122*12720SWyllys.Ingersoll@Sun.COM  */
123*12720SWyllys.Ingersoll@Sun.COM bool GetPKIcerts(
124*12720SWyllys.Ingersoll@Sun.COM         KMSClientProfile* const     io_pProfile );
125*12720SWyllys.Ingersoll@Sun.COM 
126*12720SWyllys.Ingersoll@Sun.COM #ifdef KMSUSERPKCS12
127*12720SWyllys.Ingersoll@Sun.COM bool StoreAgentPKI(
128*12720SWyllys.Ingersoll@Sun.COM 	KMSClientProfile* const i_pProfile,
129*12720SWyllys.Ingersoll@Sun.COM 	CCertificate* const     i_pAgentCertificate,
130*12720SWyllys.Ingersoll@Sun.COM 	CPrivateKey* const      i_pAgentPrivateKey,
131*12720SWyllys.Ingersoll@Sun.COM 	const char* const       i_sHexHashedPassphrase);
132*12720SWyllys.Ingersoll@Sun.COM 
133*12720SWyllys.Ingersoll@Sun.COM bool GetPKCS12CertAndKey(
134*12720SWyllys.Ingersoll@Sun.COM 	KMSClientProfile* const io_pProfile,
135*12720SWyllys.Ingersoll@Sun.COM 	utf8char        *i_pPassphrase,
136*12720SWyllys.Ingersoll@Sun.COM 	CCertificate    *i_pEntityCert,
137*12720SWyllys.Ingersoll@Sun.COM 	CPrivateKey     *i_pEntityPrivateKey);
138*12720SWyllys.Ingersoll@Sun.COM 
139*12720SWyllys.Ingersoll@Sun.COM bool StoreTempAgentPKI(
140*12720SWyllys.Ingersoll@Sun.COM 	KMSClientProfile* const io_pProfile,
141*12720SWyllys.Ingersoll@Sun.COM 	CCertificate    *i_pEntityCert,
142*12720SWyllys.Ingersoll@Sun.COM 	CPrivateKey     *i_pEntityPrivateKey);
143*12720SWyllys.Ingersoll@Sun.COM 
144*12720SWyllys.Ingersoll@Sun.COM bool ClientKeyP12Exists(char *profileName);
145*12720SWyllys.Ingersoll@Sun.COM 
146*12720SWyllys.Ingersoll@Sun.COM void CleanupPrivateKeyFile(KMSClientProfile* const io_pProfile);
147*12720SWyllys.Ingersoll@Sun.COM #endif
148*12720SWyllys.Ingersoll@Sun.COM 
149*12720SWyllys.Ingersoll@Sun.COM /**
150*12720SWyllys.Ingersoll@Sun.COM  *  Provides a wrapper to gSoap's soap_ssl_client_context()
151*12720SWyllys.Ingersoll@Sun.COM  *  that hides how Certificates and Private key material are presented to the underlying SSL
152*12720SWyllys.Ingersoll@Sun.COM  *  layer.
153*12720SWyllys.Ingersoll@Sun.COM  *  @param  i_pProfile The profile must contain a reference to the CA certificate and for
154*12720SWyllys.Ingersoll@Sun.COM  *                  SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION the Agent's certificate and private key material.
155*12720SWyllys.Ingersoll@Sun.COM  *  @param  io_pSoap  gSoap runtime
156*12720SWyllys.Ingersoll@Sun.COM  *  @param  i_iFlags  These are the gSoap authentication flags, either
157*12720SWyllys.Ingersoll@Sun.COM  *                  SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION or SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION.
158*12720SWyllys.Ingersoll@Sun.COM  *                  The private key password argument is only applicable
159*12720SWyllys.Ingersoll@Sun.COM  *                  for SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION.
160*12720SWyllys.Ingersoll@Sun.COM  *
161*12720SWyllys.Ingersoll@Sun.COM  *  @return value from gSoap's soap_ssl_client_context()
162*12720SWyllys.Ingersoll@Sun.COM  */
163*12720SWyllys.Ingersoll@Sun.COM int K_soap_ssl_client_context(
164*12720SWyllys.Ingersoll@Sun.COM         KMSClientProfile* const   i_pProfile,
165*12720SWyllys.Ingersoll@Sun.COM         struct soap *             io_pSoap,
166*12720SWyllys.Ingersoll@Sun.COM         unsigned short            i_iFlags );
167*12720SWyllys.Ingersoll@Sun.COM 
168*12720SWyllys.Ingersoll@Sun.COM /**
169*12720SWyllys.Ingersoll@Sun.COM  *  deletes the persistent storage object specified by name and its contents
170*12720SWyllys.Ingersoll@Sun.COM  */
171*12720SWyllys.Ingersoll@Sun.COM bool DeleteStorageProfile(
172*12720SWyllys.Ingersoll@Sun.COM                 const char* const i_pName);
173*12720SWyllys.Ingersoll@Sun.COM 
174*12720SWyllys.Ingersoll@Sun.COM #endif // KMSAGENT_STORAGE_H
175*12720SWyllys.Ingersoll@Sun.COM 
176