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) 2007, 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 KMSAgent.cpp
28*12720SWyllys.Ingersoll@Sun.COM */
29*12720SWyllys.Ingersoll@Sun.COM
30*12720SWyllys.Ingersoll@Sun.COM #ifdef WIN32
31*12720SWyllys.Ingersoll@Sun.COM #define _WIN32_WINNT 0x0400
32*12720SWyllys.Ingersoll@Sun.COM #include <windows.h>
33*12720SWyllys.Ingersoll@Sun.COM #include <process.h>
34*12720SWyllys.Ingersoll@Sun.COM #endif
35*12720SWyllys.Ingersoll@Sun.COM
36*12720SWyllys.Ingersoll@Sun.COM #include <stdlib.h>
37*12720SWyllys.Ingersoll@Sun.COM
38*12720SWyllys.Ingersoll@Sun.COM #include "KMSClientProfile.h"
39*12720SWyllys.Ingersoll@Sun.COM
40*12720SWyllys.Ingersoll@Sun.COM #include "KMS_AgentStub.h"
41*12720SWyllys.Ingersoll@Sun.COM #include "KMS_DiscoveryStub.h"
42*12720SWyllys.Ingersoll@Sun.COM
43*12720SWyllys.Ingersoll@Sun.COM #include "KMSClientProfileImpl.h"
44*12720SWyllys.Ingersoll@Sun.COM #include "KMSAgent.h"
45*12720SWyllys.Ingersoll@Sun.COM #include "KMSAuditLogger.h"
46*12720SWyllys.Ingersoll@Sun.COM #include "KMSAgentSoapUtilities.h"
47*12720SWyllys.Ingersoll@Sun.COM #include "KMSAgentStringUtilities.h"
48*12720SWyllys.Ingersoll@Sun.COM #include "KMSAgentPKICommon.h"
49*12720SWyllys.Ingersoll@Sun.COM #include "KMSAgentLoadBalancer.h"
50*12720SWyllys.Ingersoll@Sun.COM
51*12720SWyllys.Ingersoll@Sun.COM #include "KMSAgentWebServiceNamespaces.h"
52*12720SWyllys.Ingersoll@Sun.COM #include "k_setupssl.h"
53*12720SWyllys.Ingersoll@Sun.COM
54*12720SWyllys.Ingersoll@Sun.COM #include "ApplianceParameters.h"
55*12720SWyllys.Ingersoll@Sun.COM
56*12720SWyllys.Ingersoll@Sun.COM #include "AutoMutex.h"
57*12720SWyllys.Ingersoll@Sun.COM #include "KMSAgentKeyCallout.h"
58*12720SWyllys.Ingersoll@Sun.COM
59*12720SWyllys.Ingersoll@Sun.COM #include "KMSAgentLoadBalancer.h"
60*12720SWyllys.Ingersoll@Sun.COM #include "KMSAgentDataUnitCache.h"
61*12720SWyllys.Ingersoll@Sun.COM
62*12720SWyllys.Ingersoll@Sun.COM #ifdef K_SOLARIS_PLATFORM
63*12720SWyllys.Ingersoll@Sun.COM #include "KMSAgentStorage.h"
64*12720SWyllys.Ingersoll@Sun.COM #endif
65*12720SWyllys.Ingersoll@Sun.COM
66*12720SWyllys.Ingersoll@Sun.COM #include "ClientSoapFaultCodes.h"
67*12720SWyllys.Ingersoll@Sun.COM
68*12720SWyllys.Ingersoll@Sun.COM #ifdef METAWARE
69*12720SWyllys.Ingersoll@Sun.COM #include "debug.h"
70*12720SWyllys.Ingersoll@Sun.COM #include "sizet.h"
71*12720SWyllys.Ingersoll@Sun.COM typedef unsigned char uint8_t;
72*12720SWyllys.Ingersoll@Sun.COM typedef unsigned short uint16_t;
73*12720SWyllys.Ingersoll@Sun.COM typedef unsigned int uint32_t;
74*12720SWyllys.Ingersoll@Sun.COM typedef unsigned long long uint64_t;
75*12720SWyllys.Ingersoll@Sun.COM #endif
76*12720SWyllys.Ingersoll@Sun.COM
77*12720SWyllys.Ingersoll@Sun.COM #include "KMSAgentAESKeyWrap.h"
78*12720SWyllys.Ingersoll@Sun.COM #include "KMSAgentKnownAnswerTests.h"
79*12720SWyllys.Ingersoll@Sun.COM
80*12720SWyllys.Ingersoll@Sun.COM #if defined(METAWARE) && defined(DEBUG_RETURNS)
81*12720SWyllys.Ingersoll@Sun.COM extern "C" void ecpt_trace_msg (ECPT_TRACE_ENTRY*, char*, ...);
82*12720SWyllys.Ingersoll@Sun.COM
83*12720SWyllys.Ingersoll@Sun.COM #define RETURN(a) { ecpt_trace_msg( trace,"(returned=%x)",(a)); return(a); }
84*12720SWyllys.Ingersoll@Sun.COM
85*12720SWyllys.Ingersoll@Sun.COM #else
86*12720SWyllys.Ingersoll@Sun.COM #define RETURN(a) return(a)
87*12720SWyllys.Ingersoll@Sun.COM #endif
88*12720SWyllys.Ingersoll@Sun.COM
89*12720SWyllys.Ingersoll@Sun.COM /* KMS_AGENT_VERSION_STRING gets passed in via compilation flags */
90*12720SWyllys.Ingersoll@Sun.COM extern "C" const char KMSAgent_Version[KMS_MAX_VERSION_LENGTH + 1] = KMS_AGENT_VERSION_STRING;
91*12720SWyllys.Ingersoll@Sun.COM
92*12720SWyllys.Ingersoll@Sun.COM
93*12720SWyllys.Ingersoll@Sun.COM /* The following enum and structs are used for QueryParameters in
94*12720SWyllys.Ingersoll@Sun.COM * ListKeyGroup. Since they are only used in implementation code,
95*12720SWyllys.Ingersoll@Sun.COM * so they are not in the header file in order to hide these details
96*12720SWyllys.Ingersoll@Sun.COM */
97*12720SWyllys.Ingersoll@Sun.COM
98*12720SWyllys.Ingersoll@Sun.COM
99*12720SWyllys.Ingersoll@Sun.COM /*---------------------------Start Query Parameters Declartion -------- */
100*12720SWyllys.Ingersoll@Sun.COM
101*12720SWyllys.Ingersoll@Sun.COM #define KMS_MAX_AGENT_FILTER_PARAMETERS 10
102*12720SWyllys.Ingersoll@Sun.COM
103*12720SWyllys.Ingersoll@Sun.COM enum KMSAgent_SortOrder
104*12720SWyllys.Ingersoll@Sun.COM {
105*12720SWyllys.Ingersoll@Sun.COM SORT_ORDER_ASCENDING = 0,
106*12720SWyllys.Ingersoll@Sun.COM SORT_ORDER_DESCENDING
107*12720SWyllys.Ingersoll@Sun.COM };
108*12720SWyllys.Ingersoll@Sun.COM
109*12720SWyllys.Ingersoll@Sun.COM enum KMSAgent_FilterOperator
110*12720SWyllys.Ingersoll@Sun.COM {
111*12720SWyllys.Ingersoll@Sun.COM FILTER_OPERATOR_EQUAL = 0,
112*12720SWyllys.Ingersoll@Sun.COM FILTER_OPERATOR_NOT_EQUAL,
113*12720SWyllys.Ingersoll@Sun.COM FILTER_OPERATOR_GREATER_THAN,
114*12720SWyllys.Ingersoll@Sun.COM FILTER_OPERATOR_LESS_THAN,
115*12720SWyllys.Ingersoll@Sun.COM FILTER_OPERATOR_GREATER_THAN_OR_EQUAL,
116*12720SWyllys.Ingersoll@Sun.COM FILTER_OPERATOR_LESS_THAN_OR_EQUAL,
117*12720SWyllys.Ingersoll@Sun.COM FILTER_OPERATOR_STARTS_WITH
118*12720SWyllys.Ingersoll@Sun.COM };
119*12720SWyllys.Ingersoll@Sun.COM
120*12720SWyllys.Ingersoll@Sun.COM struct KMSAgent_FilterParameters
121*12720SWyllys.Ingersoll@Sun.COM {
122*12720SWyllys.Ingersoll@Sun.COM utf8char m_wsFieldName[KMS_MAX_FIELD_NAME + 1];
123*12720SWyllys.Ingersoll@Sun.COM enum KMSAgent_FilterOperator m_eFilterOperator;
124*12720SWyllys.Ingersoll@Sun.COM utf8char m_wsFieldValue[KMS_MAX_FIELD_VALUE + 1];
125*12720SWyllys.Ingersoll@Sun.COM };
126*12720SWyllys.Ingersoll@Sun.COM
127*12720SWyllys.Ingersoll@Sun.COM struct KMSAgent_QueryParameters
128*12720SWyllys.Ingersoll@Sun.COM {
129*12720SWyllys.Ingersoll@Sun.COM utf8char m_wsSortFieldName[KMS_MAX_FIELD_NAME + 1];
130*12720SWyllys.Ingersoll@Sun.COM enum KMSAgent_SortOrder m_eSortOrder;
131*12720SWyllys.Ingersoll@Sun.COM
132*12720SWyllys.Ingersoll@Sun.COM struct KMSAgent_FilterParameters m_aFilterParameters[KMS_MAX_AGENT_FILTER_PARAMETERS];
133*12720SWyllys.Ingersoll@Sun.COM int m_iSizeFilterParameters;
134*12720SWyllys.Ingersoll@Sun.COM
135*12720SWyllys.Ingersoll@Sun.COM utf8char m_wsPreviousPageLastIDValue[KMS_MAX_ID + 1];
136*12720SWyllys.Ingersoll@Sun.COM utf8char m_wsPreviousPageLastSortFieldValue[KMS_MAX_FIELD_VALUE + 1];
137*12720SWyllys.Ingersoll@Sun.COM };
138*12720SWyllys.Ingersoll@Sun.COM
139*12720SWyllys.Ingersoll@Sun.COM /*---------------------------End Of Query Parameters Declaration -------- */
140*12720SWyllys.Ingersoll@Sun.COM
141*12720SWyllys.Ingersoll@Sun.COM #ifdef METAWARE
142*12720SWyllys.Ingersoll@Sun.COM int CAgentLoadBalancer::FailOver (int i_iFailedApplianceIndex,
143*12720SWyllys.Ingersoll@Sun.COM struct soap *i_pstSoap);
144*12720SWyllys.Ingersoll@Sun.COM #endif
145*12720SWyllys.Ingersoll@Sun.COM
KMSAgent_GetVersion()146*12720SWyllys.Ingersoll@Sun.COM extern const char * KMSAgent_GetVersion ()
147*12720SWyllys.Ingersoll@Sun.COM {
148*12720SWyllys.Ingersoll@Sun.COM return (KMSAgent_Version);
149*12720SWyllys.Ingersoll@Sun.COM }
150*12720SWyllys.Ingersoll@Sun.COM
CopyQueryParametersFromRequest(struct soap * i_pstSoap,int i_iPageSize,struct KMS_Agent::KMS_Agent__QueryParameters * i_pQueryParameters,struct KMSAgent_QueryParameters * i_pSourceQueryParameters)151*12720SWyllys.Ingersoll@Sun.COM static bool CopyQueryParametersFromRequest
152*12720SWyllys.Ingersoll@Sun.COM (
153*12720SWyllys.Ingersoll@Sun.COM struct soap *i_pstSoap,
154*12720SWyllys.Ingersoll@Sun.COM int i_iPageSize,
155*12720SWyllys.Ingersoll@Sun.COM struct KMS_Agent::KMS_Agent__QueryParameters *i_pQueryParameters,
156*12720SWyllys.Ingersoll@Sun.COM struct KMSAgent_QueryParameters *i_pSourceQueryParameters
157*12720SWyllys.Ingersoll@Sun.COM )
158*12720SWyllys.Ingersoll@Sun.COM {
159*12720SWyllys.Ingersoll@Sun.COM
160*12720SWyllys.Ingersoll@Sun.COM // set page size
161*12720SWyllys.Ingersoll@Sun.COM i_pQueryParameters->NextPageSize = i_iPageSize;
162*12720SWyllys.Ingersoll@Sun.COM
163*12720SWyllys.Ingersoll@Sun.COM // copy sort field name
164*12720SWyllys.Ingersoll@Sun.COM i_pQueryParameters->SortFieldName = (char *)
165*12720SWyllys.Ingersoll@Sun.COM soap_malloc(i_pstSoap,
166*12720SWyllys.Ingersoll@Sun.COM sizeof (i_pSourceQueryParameters->m_wsSortFieldName));
167*12720SWyllys.Ingersoll@Sun.COM if (i_pQueryParameters->SortFieldName == NULL)
168*12720SWyllys.Ingersoll@Sun.COM {
169*12720SWyllys.Ingersoll@Sun.COM return (false);
170*12720SWyllys.Ingersoll@Sun.COM }
171*12720SWyllys.Ingersoll@Sun.COM strncpy(i_pQueryParameters->SortFieldName,
172*12720SWyllys.Ingersoll@Sun.COM i_pSourceQueryParameters->m_wsSortFieldName,
173*12720SWyllys.Ingersoll@Sun.COM sizeof (i_pSourceQueryParameters->m_wsSortFieldName));
174*12720SWyllys.Ingersoll@Sun.COM i_pQueryParameters->SortFieldName[sizeof (i_pSourceQueryParameters->m_wsSortFieldName)-1] = 0;
175*12720SWyllys.Ingersoll@Sun.COM
176*12720SWyllys.Ingersoll@Sun.COM // sort order
177*12720SWyllys.Ingersoll@Sun.COM i_pQueryParameters->SortOrder =
178*12720SWyllys.Ingersoll@Sun.COM (enum KMS_Agent::KMS_Agent__SortOrder)i_pSourceQueryParameters->m_eSortOrder;
179*12720SWyllys.Ingersoll@Sun.COM
180*12720SWyllys.Ingersoll@Sun.COM // copy filter parameters
181*12720SWyllys.Ingersoll@Sun.COM i_pQueryParameters->FilterParameters.__size =
182*12720SWyllys.Ingersoll@Sun.COM i_pSourceQueryParameters->m_iSizeFilterParameters;
183*12720SWyllys.Ingersoll@Sun.COM
184*12720SWyllys.Ingersoll@Sun.COM if (i_pQueryParameters->FilterParameters.__size > 0)
185*12720SWyllys.Ingersoll@Sun.COM {
186*12720SWyllys.Ingersoll@Sun.COM i_pQueryParameters->
187*12720SWyllys.Ingersoll@Sun.COM FilterParameters.__ptr =
188*12720SWyllys.Ingersoll@Sun.COM (struct KMS_Agent::KMS_Agent__FilterParameters *)soap_malloc
189*12720SWyllys.Ingersoll@Sun.COM (i_pstSoap,
190*12720SWyllys.Ingersoll@Sun.COM sizeof (KMS_Agent::KMS_Agent__FilterParameters) *
191*12720SWyllys.Ingersoll@Sun.COM i_pQueryParameters->FilterParameters.__size);
192*12720SWyllys.Ingersoll@Sun.COM
193*12720SWyllys.Ingersoll@Sun.COM if (i_pQueryParameters->FilterParameters.__ptr == NULL)
194*12720SWyllys.Ingersoll@Sun.COM {
195*12720SWyllys.Ingersoll@Sun.COM return (false);
196*12720SWyllys.Ingersoll@Sun.COM }
197*12720SWyllys.Ingersoll@Sun.COM }
198*12720SWyllys.Ingersoll@Sun.COM else
199*12720SWyllys.Ingersoll@Sun.COM {
200*12720SWyllys.Ingersoll@Sun.COM i_pQueryParameters->FilterParameters.__ptr = NULL;
201*12720SWyllys.Ingersoll@Sun.COM }
202*12720SWyllys.Ingersoll@Sun.COM
203*12720SWyllys.Ingersoll@Sun.COM for (int i = 0; i < i_pSourceQueryParameters->m_iSizeFilterParameters; i++)
204*12720SWyllys.Ingersoll@Sun.COM {
205*12720SWyllys.Ingersoll@Sun.COM struct KMS_Agent::KMS_Agent__FilterParameters *pParameters;
206*12720SWyllys.Ingersoll@Sun.COM
207*12720SWyllys.Ingersoll@Sun.COM pParameters = &(i_pQueryParameters->FilterParameters.__ptr[i]);
208*12720SWyllys.Ingersoll@Sun.COM
209*12720SWyllys.Ingersoll@Sun.COM // copy field name
210*12720SWyllys.Ingersoll@Sun.COM pParameters->FieldName = (
211*12720SWyllys.Ingersoll@Sun.COM utf8cstr) soap_malloc(i_pstSoap,
212*12720SWyllys.Ingersoll@Sun.COM sizeof (i_pSourceQueryParameters->
213*12720SWyllys.Ingersoll@Sun.COM m_aFilterParameters[i].m_wsFieldName));
214*12720SWyllys.Ingersoll@Sun.COM if (pParameters->FieldName == NULL)
215*12720SWyllys.Ingersoll@Sun.COM {
216*12720SWyllys.Ingersoll@Sun.COM return (false);
217*12720SWyllys.Ingersoll@Sun.COM }
218*12720SWyllys.Ingersoll@Sun.COM
219*12720SWyllys.Ingersoll@Sun.COM strncpy(pParameters->FieldName,
220*12720SWyllys.Ingersoll@Sun.COM i_pSourceQueryParameters->m_aFilterParameters[i].m_wsFieldName,
221*12720SWyllys.Ingersoll@Sun.COM sizeof (i_pSourceQueryParameters->
222*12720SWyllys.Ingersoll@Sun.COM m_aFilterParameters[i].m_wsFieldName));
223*12720SWyllys.Ingersoll@Sun.COM pParameters->FieldName[sizeof (i_pSourceQueryParameters->
224*12720SWyllys.Ingersoll@Sun.COM m_aFilterParameters[i].m_wsFieldName)-1] = '\0';
225*12720SWyllys.Ingersoll@Sun.COM
226*12720SWyllys.Ingersoll@Sun.COM // copy field value
227*12720SWyllys.Ingersoll@Sun.COM pParameters->FieldValue =
228*12720SWyllys.Ingersoll@Sun.COM (utf8cstr) soap_malloc
229*12720SWyllys.Ingersoll@Sun.COM (i_pstSoap,
230*12720SWyllys.Ingersoll@Sun.COM sizeof (i_pSourceQueryParameters->m_aFilterParameters[i].m_wsFieldValue));
231*12720SWyllys.Ingersoll@Sun.COM if (pParameters->FieldValue == NULL)
232*12720SWyllys.Ingersoll@Sun.COM {
233*12720SWyllys.Ingersoll@Sun.COM return (false);
234*12720SWyllys.Ingersoll@Sun.COM }
235*12720SWyllys.Ingersoll@Sun.COM
236*12720SWyllys.Ingersoll@Sun.COM strncpy(pParameters->FieldValue,
237*12720SWyllys.Ingersoll@Sun.COM i_pSourceQueryParameters->m_aFilterParameters[i].m_wsFieldValue,
238*12720SWyllys.Ingersoll@Sun.COM sizeof (i_pSourceQueryParameters->m_aFilterParameters[i].m_wsFieldValue));
239*12720SWyllys.Ingersoll@Sun.COM pParameters->FieldValue[sizeof (i_pSourceQueryParameters->m_aFilterParameters[i].m_wsFieldValue)-1] = '\0';
240*12720SWyllys.Ingersoll@Sun.COM
241*12720SWyllys.Ingersoll@Sun.COM // copy FilterOperator
242*12720SWyllys.Ingersoll@Sun.COM pParameters->FilterOperator =
243*12720SWyllys.Ingersoll@Sun.COM (KMS_Agent::KMS_Agent__FilterOperator)
244*12720SWyllys.Ingersoll@Sun.COM i_pSourceQueryParameters->m_aFilterParameters[i].m_eFilterOperator;
245*12720SWyllys.Ingersoll@Sun.COM }
246*12720SWyllys.Ingersoll@Sun.COM
247*12720SWyllys.Ingersoll@Sun.COM // copy PreviousPageLastIDValue
248*12720SWyllys.Ingersoll@Sun.COM i_pQueryParameters->PreviousPageLastIDValue =
249*12720SWyllys.Ingersoll@Sun.COM (utf8cstr) soap_malloc(i_pstSoap,
250*12720SWyllys.Ingersoll@Sun.COM sizeof (i_pSourceQueryParameters->m_wsPreviousPageLastIDValue));
251*12720SWyllys.Ingersoll@Sun.COM if (i_pQueryParameters->PreviousPageLastIDValue == NULL)
252*12720SWyllys.Ingersoll@Sun.COM {
253*12720SWyllys.Ingersoll@Sun.COM return (false);
254*12720SWyllys.Ingersoll@Sun.COM }
255*12720SWyllys.Ingersoll@Sun.COM strncpy(i_pQueryParameters->PreviousPageLastIDValue,
256*12720SWyllys.Ingersoll@Sun.COM i_pSourceQueryParameters->m_wsPreviousPageLastIDValue,
257*12720SWyllys.Ingersoll@Sun.COM sizeof (i_pSourceQueryParameters->m_wsPreviousPageLastIDValue));
258*12720SWyllys.Ingersoll@Sun.COM i_pQueryParameters->PreviousPageLastIDValue[sizeof (i_pSourceQueryParameters->m_wsPreviousPageLastIDValue)-1] = '\0';
259*12720SWyllys.Ingersoll@Sun.COM
260*12720SWyllys.Ingersoll@Sun.COM // copy PreviousPageLastIDValue
261*12720SWyllys.Ingersoll@Sun.COM i_pQueryParameters->PreviousPageLastSortFieldValue =
262*12720SWyllys.Ingersoll@Sun.COM (utf8cstr) soap_malloc(i_pstSoap,
263*12720SWyllys.Ingersoll@Sun.COM sizeof (i_pSourceQueryParameters->
264*12720SWyllys.Ingersoll@Sun.COM m_wsPreviousPageLastSortFieldValue));
265*12720SWyllys.Ingersoll@Sun.COM if (i_pQueryParameters->PreviousPageLastSortFieldValue == NULL)
266*12720SWyllys.Ingersoll@Sun.COM {
267*12720SWyllys.Ingersoll@Sun.COM return (false);
268*12720SWyllys.Ingersoll@Sun.COM }
269*12720SWyllys.Ingersoll@Sun.COM strncpy(i_pQueryParameters->PreviousPageLastSortFieldValue,
270*12720SWyllys.Ingersoll@Sun.COM i_pSourceQueryParameters->m_wsPreviousPageLastSortFieldValue,
271*12720SWyllys.Ingersoll@Sun.COM sizeof (i_pSourceQueryParameters->
272*12720SWyllys.Ingersoll@Sun.COM m_wsPreviousPageLastSortFieldValue));
273*12720SWyllys.Ingersoll@Sun.COM i_pQueryParameters->PreviousPageLastSortFieldValue[sizeof (i_pSourceQueryParameters->
274*12720SWyllys.Ingersoll@Sun.COM m_wsPreviousPageLastSortFieldValue)-1] = 0;
275*12720SWyllys.Ingersoll@Sun.COM
276*12720SWyllys.Ingersoll@Sun.COM return (true);
277*12720SWyllys.Ingersoll@Sun.COM }
278*12720SWyllys.Ingersoll@Sun.COM
CopyQueryParametersFromResponse(struct KMSAgent_QueryParameters * i_pQueryParameters,struct KMS_Agent::KMS_Agent__QueryParameters * i_pSourceQueryParameters)279*12720SWyllys.Ingersoll@Sun.COM static void CopyQueryParametersFromResponse (
280*12720SWyllys.Ingersoll@Sun.COM struct KMSAgent_QueryParameters *i_pQueryParameters,
281*12720SWyllys.Ingersoll@Sun.COM struct KMS_Agent::KMS_Agent__QueryParameters *i_pSourceQueryParameters)
282*12720SWyllys.Ingersoll@Sun.COM {
283*12720SWyllys.Ingersoll@Sun.COM
284*12720SWyllys.Ingersoll@Sun.COM // copy sort field name
285*12720SWyllys.Ingersoll@Sun.COM if (i_pSourceQueryParameters->SortFieldName)
286*12720SWyllys.Ingersoll@Sun.COM {
287*12720SWyllys.Ingersoll@Sun.COM strncpy(i_pQueryParameters->m_wsSortFieldName,
288*12720SWyllys.Ingersoll@Sun.COM i_pSourceQueryParameters->SortFieldName,
289*12720SWyllys.Ingersoll@Sun.COM sizeof(i_pQueryParameters->m_wsSortFieldName));
290*12720SWyllys.Ingersoll@Sun.COM i_pQueryParameters->m_wsSortFieldName[sizeof(i_pQueryParameters->m_wsSortFieldName)-1] = '\0';
291*12720SWyllys.Ingersoll@Sun.COM }
292*12720SWyllys.Ingersoll@Sun.COM
293*12720SWyllys.Ingersoll@Sun.COM // copy order
294*12720SWyllys.Ingersoll@Sun.COM i_pQueryParameters->m_eSortOrder =
295*12720SWyllys.Ingersoll@Sun.COM (KMSAgent_SortOrder) i_pSourceQueryParameters->SortOrder;
296*12720SWyllys.Ingersoll@Sun.COM
297*12720SWyllys.Ingersoll@Sun.COM // copy filter parameters
298*12720SWyllys.Ingersoll@Sun.COM i_pQueryParameters->m_iSizeFilterParameters =
299*12720SWyllys.Ingersoll@Sun.COM i_pSourceQueryParameters->FilterParameters.__size;
300*12720SWyllys.Ingersoll@Sun.COM
301*12720SWyllys.Ingersoll@Sun.COM // we only accept this amount of parameters
302*12720SWyllys.Ingersoll@Sun.COM if (i_pQueryParameters->m_iSizeFilterParameters >= KMS_MAX_AGENT_FILTER_PARAMETERS)
303*12720SWyllys.Ingersoll@Sun.COM {
304*12720SWyllys.Ingersoll@Sun.COM // this should not happen, but just for defending the code
305*12720SWyllys.Ingersoll@Sun.COM i_pQueryParameters->m_iSizeFilterParameters = KMS_MAX_AGENT_FILTER_PARAMETERS;
306*12720SWyllys.Ingersoll@Sun.COM }
307*12720SWyllys.Ingersoll@Sun.COM
308*12720SWyllys.Ingersoll@Sun.COM for (int i = 0; i < i_pQueryParameters->m_iSizeFilterParameters; i++)
309*12720SWyllys.Ingersoll@Sun.COM {
310*12720SWyllys.Ingersoll@Sun.COM struct KMS_Agent::KMS_Agent__FilterParameters *pParameters;
311*12720SWyllys.Ingersoll@Sun.COM
312*12720SWyllys.Ingersoll@Sun.COM pParameters = i_pSourceQueryParameters->FilterParameters.__ptr + i;
313*12720SWyllys.Ingersoll@Sun.COM
314*12720SWyllys.Ingersoll@Sun.COM i_pQueryParameters->m_aFilterParameters[i].m_eFilterOperator
315*12720SWyllys.Ingersoll@Sun.COM = (KMSAgent_FilterOperator) pParameters->FilterOperator;
316*12720SWyllys.Ingersoll@Sun.COM
317*12720SWyllys.Ingersoll@Sun.COM if (pParameters->FieldName)
318*12720SWyllys.Ingersoll@Sun.COM {
319*12720SWyllys.Ingersoll@Sun.COM strncpy(i_pQueryParameters->m_aFilterParameters[i].m_wsFieldName,
320*12720SWyllys.Ingersoll@Sun.COM pParameters->FieldName,
321*12720SWyllys.Ingersoll@Sun.COM sizeof (i_pQueryParameters->m_aFilterParameters[i].m_wsFieldName));
322*12720SWyllys.Ingersoll@Sun.COM i_pQueryParameters->
323*12720SWyllys.Ingersoll@Sun.COM m_aFilterParameters[i].m_wsFieldName[sizeof (i_pQueryParameters->m_aFilterParameters[i].m_wsFieldName) - 1] = '\0';
324*12720SWyllys.Ingersoll@Sun.COM }
325*12720SWyllys.Ingersoll@Sun.COM
326*12720SWyllys.Ingersoll@Sun.COM if (pParameters->FieldValue)
327*12720SWyllys.Ingersoll@Sun.COM {
328*12720SWyllys.Ingersoll@Sun.COM strncpy(i_pQueryParameters->m_aFilterParameters[i].m_wsFieldValue,
329*12720SWyllys.Ingersoll@Sun.COM pParameters->FieldValue,
330*12720SWyllys.Ingersoll@Sun.COM sizeof(i_pQueryParameters->m_aFilterParameters[i].m_wsFieldValue));
331*12720SWyllys.Ingersoll@Sun.COM i_pQueryParameters->
332*12720SWyllys.Ingersoll@Sun.COM m_aFilterParameters[i].m_wsFieldValue[sizeof(i_pQueryParameters->m_aFilterParameters[i].m_wsFieldValue)-1] = '\0';
333*12720SWyllys.Ingersoll@Sun.COM }
334*12720SWyllys.Ingersoll@Sun.COM }
335*12720SWyllys.Ingersoll@Sun.COM // copy PreviousPageLastIDValue
336*12720SWyllys.Ingersoll@Sun.COM if (i_pSourceQueryParameters->PreviousPageLastIDValue)
337*12720SWyllys.Ingersoll@Sun.COM {
338*12720SWyllys.Ingersoll@Sun.COM strncpy(i_pQueryParameters->m_wsPreviousPageLastIDValue,
339*12720SWyllys.Ingersoll@Sun.COM i_pSourceQueryParameters->PreviousPageLastIDValue,
340*12720SWyllys.Ingersoll@Sun.COM sizeof(i_pQueryParameters->m_wsPreviousPageLastIDValue));
341*12720SWyllys.Ingersoll@Sun.COM i_pQueryParameters->m_wsPreviousPageLastIDValue[sizeof(i_pQueryParameters->m_wsPreviousPageLastIDValue)-1] = '\0';
342*12720SWyllys.Ingersoll@Sun.COM }
343*12720SWyllys.Ingersoll@Sun.COM
344*12720SWyllys.Ingersoll@Sun.COM // copy PreviousPageLastSortFieldValue
345*12720SWyllys.Ingersoll@Sun.COM if (i_pSourceQueryParameters->PreviousPageLastSortFieldValue)
346*12720SWyllys.Ingersoll@Sun.COM {
347*12720SWyllys.Ingersoll@Sun.COM strncpy(i_pQueryParameters->m_wsPreviousPageLastSortFieldValue,
348*12720SWyllys.Ingersoll@Sun.COM i_pSourceQueryParameters->PreviousPageLastSortFieldValue,
349*12720SWyllys.Ingersoll@Sun.COM sizeof(i_pQueryParameters->m_wsPreviousPageLastSortFieldValue));
350*12720SWyllys.Ingersoll@Sun.COM i_pQueryParameters->m_wsPreviousPageLastSortFieldValue[sizeof(i_pQueryParameters->m_wsPreviousPageLastSortFieldValue)-1] = '\0';
351*12720SWyllys.Ingersoll@Sun.COM }
352*12720SWyllys.Ingersoll@Sun.COM
353*12720SWyllys.Ingersoll@Sun.COM }
354*12720SWyllys.Ingersoll@Sun.COM
355*12720SWyllys.Ingersoll@Sun.COM /**
356*12720SWyllys.Ingersoll@Sun.COM * copies data unit to the soap data unit structure, placing the xsd_string types on the
357*12720SWyllys.Ingersoll@Sun.COM * gsoap heap.
358*12720SWyllys.Ingersoll@Sun.COM * @return(false if soap_malloc fails
359*12720SWyllys.Ingersoll@Sun.COM */
CopyDataUnitFromRequest(struct soap * i_pstSoap,struct KMS_Agent::KMS_Agent__DataUnit * i_pDataUnit,const KMSAgent_DataUnit * const i_pSourceDataUnit)360*12720SWyllys.Ingersoll@Sun.COM static bool CopyDataUnitFromRequest (struct soap *i_pstSoap,
361*12720SWyllys.Ingersoll@Sun.COM struct KMS_Agent::KMS_Agent__DataUnit *i_pDataUnit,
362*12720SWyllys.Ingersoll@Sun.COM const KMSAgent_DataUnit * const i_pSourceDataUnit)
363*12720SWyllys.Ingersoll@Sun.COM {
364*12720SWyllys.Ingersoll@Sun.COM
365*12720SWyllys.Ingersoll@Sun.COM if (i_pSourceDataUnit)
366*12720SWyllys.Ingersoll@Sun.COM {
367*12720SWyllys.Ingersoll@Sun.COM // copy field name
368*12720SWyllys.Ingersoll@Sun.COM i_pDataUnit->DataUnitID =
369*12720SWyllys.Ingersoll@Sun.COM (utf8cstr) soap_malloc(i_pstSoap,
370*12720SWyllys.Ingersoll@Sun.COM 2 * sizeof (i_pSourceDataUnit->m_acDataUnitID) + 1);
371*12720SWyllys.Ingersoll@Sun.COM if (i_pDataUnit->DataUnitID == NULL)
372*12720SWyllys.Ingersoll@Sun.COM {
373*12720SWyllys.Ingersoll@Sun.COM return (false);
374*12720SWyllys.Ingersoll@Sun.COM }
375*12720SWyllys.Ingersoll@Sun.COM
376*12720SWyllys.Ingersoll@Sun.COM ConvertBinaryToUTF8HexString(i_pDataUnit->DataUnitID,
377*12720SWyllys.Ingersoll@Sun.COM i_pSourceDataUnit->m_acDataUnitID,
378*12720SWyllys.Ingersoll@Sun.COM KMS_DATA_UNIT_ID_SIZE);
379*12720SWyllys.Ingersoll@Sun.COM }
380*12720SWyllys.Ingersoll@Sun.COM else
381*12720SWyllys.Ingersoll@Sun.COM {
382*12720SWyllys.Ingersoll@Sun.COM strcpy(i_pDataUnit->DataUnitID, "");
383*12720SWyllys.Ingersoll@Sun.COM }
384*12720SWyllys.Ingersoll@Sun.COM
385*12720SWyllys.Ingersoll@Sun.COM i_pDataUnit->ExternalUniqueID = (utf8cstr) soap_malloc(i_pstSoap,
386*12720SWyllys.Ingersoll@Sun.COM 2 * sizeof (i_pSourceDataUnit->m_acExternalUniqueID) + 1);
387*12720SWyllys.Ingersoll@Sun.COM if (i_pDataUnit->ExternalUniqueID == NULL)
388*12720SWyllys.Ingersoll@Sun.COM {
389*12720SWyllys.Ingersoll@Sun.COM return (false);
390*12720SWyllys.Ingersoll@Sun.COM }
391*12720SWyllys.Ingersoll@Sun.COM
392*12720SWyllys.Ingersoll@Sun.COM if (i_pSourceDataUnit->m_iExternalUniqueIDLength > 0 &&
393*12720SWyllys.Ingersoll@Sun.COM i_pSourceDataUnit->m_iExternalUniqueIDLength <= KMS_MAX_EXTERNAL_UNIQUE_ID_SIZE)
394*12720SWyllys.Ingersoll@Sun.COM {
395*12720SWyllys.Ingersoll@Sun.COM ConvertBinaryToUTF8HexString(i_pDataUnit->ExternalUniqueID,
396*12720SWyllys.Ingersoll@Sun.COM i_pSourceDataUnit->m_acExternalUniqueID,
397*12720SWyllys.Ingersoll@Sun.COM i_pSourceDataUnit->m_iExternalUniqueIDLength);
398*12720SWyllys.Ingersoll@Sun.COM }
399*12720SWyllys.Ingersoll@Sun.COM else
400*12720SWyllys.Ingersoll@Sun.COM {
401*12720SWyllys.Ingersoll@Sun.COM strcpy(i_pDataUnit->ExternalUniqueID, "");
402*12720SWyllys.Ingersoll@Sun.COM }
403*12720SWyllys.Ingersoll@Sun.COM
404*12720SWyllys.Ingersoll@Sun.COM i_pDataUnit->ExternalTag = (utf8cstr) soap_malloc(i_pstSoap, sizeof (i_pSourceDataUnit->m_acExternalTag));
405*12720SWyllys.Ingersoll@Sun.COM if (i_pDataUnit->ExternalTag == NULL)
406*12720SWyllys.Ingersoll@Sun.COM {
407*12720SWyllys.Ingersoll@Sun.COM return (false);
408*12720SWyllys.Ingersoll@Sun.COM }
409*12720SWyllys.Ingersoll@Sun.COM
410*12720SWyllys.Ingersoll@Sun.COM if (strlen(i_pSourceDataUnit->m_acExternalTag) <= sizeof (i_pSourceDataUnit->m_acExternalTag))
411*12720SWyllys.Ingersoll@Sun.COM {
412*12720SWyllys.Ingersoll@Sun.COM strncpy(i_pDataUnit->ExternalTag,
413*12720SWyllys.Ingersoll@Sun.COM i_pSourceDataUnit->m_acExternalTag,
414*12720SWyllys.Ingersoll@Sun.COM sizeof (i_pSourceDataUnit->m_acExternalTag));
415*12720SWyllys.Ingersoll@Sun.COM i_pDataUnit->ExternalTag[sizeof (i_pSourceDataUnit->m_acExternalTag)-1] = '\0';
416*12720SWyllys.Ingersoll@Sun.COM }
417*12720SWyllys.Ingersoll@Sun.COM else
418*12720SWyllys.Ingersoll@Sun.COM {
419*12720SWyllys.Ingersoll@Sun.COM strcpy(i_pDataUnit->ExternalTag, "");
420*12720SWyllys.Ingersoll@Sun.COM }
421*12720SWyllys.Ingersoll@Sun.COM
422*12720SWyllys.Ingersoll@Sun.COM i_pDataUnit->Description = (utf8cstr) soap_malloc(i_pstSoap, sizeof (i_pSourceDataUnit->m_acDescription));
423*12720SWyllys.Ingersoll@Sun.COM if (i_pDataUnit->Description == NULL)
424*12720SWyllys.Ingersoll@Sun.COM {
425*12720SWyllys.Ingersoll@Sun.COM return (false);
426*12720SWyllys.Ingersoll@Sun.COM }
427*12720SWyllys.Ingersoll@Sun.COM if (strlen(i_pSourceDataUnit->m_acDescription) <= sizeof (i_pSourceDataUnit->m_acDescription))
428*12720SWyllys.Ingersoll@Sun.COM {
429*12720SWyllys.Ingersoll@Sun.COM strncpy(i_pDataUnit->Description,
430*12720SWyllys.Ingersoll@Sun.COM i_pSourceDataUnit->m_acDescription,
431*12720SWyllys.Ingersoll@Sun.COM sizeof (i_pSourceDataUnit->m_acDescription));
432*12720SWyllys.Ingersoll@Sun.COM i_pDataUnit->Description[sizeof (i_pSourceDataUnit->m_acDescription)-1] = '\0';
433*12720SWyllys.Ingersoll@Sun.COM }
434*12720SWyllys.Ingersoll@Sun.COM else
435*12720SWyllys.Ingersoll@Sun.COM {
436*12720SWyllys.Ingersoll@Sun.COM strcpy(i_pDataUnit->Description, "");
437*12720SWyllys.Ingersoll@Sun.COM }
438*12720SWyllys.Ingersoll@Sun.COM
439*12720SWyllys.Ingersoll@Sun.COM i_pDataUnit->DataUnitState = (KMS_Agent::KMS_Agent__DataUnitState) i_pSourceDataUnit->m_iDataUnitState;
440*12720SWyllys.Ingersoll@Sun.COM
441*12720SWyllys.Ingersoll@Sun.COM return (true);
442*12720SWyllys.Ingersoll@Sun.COM }
443*12720SWyllys.Ingersoll@Sun.COM
444*12720SWyllys.Ingersoll@Sun.COM /**
445*12720SWyllys.Ingersoll@Sun.COM * Converts an ExternalUniqueID value to UTF8Hexstring value from gSoap managed heap storage
446*12720SWyllys.Ingersoll@Sun.COM * @param i_pstSoap pointer to gSoap runtime
447*12720SWyllys.Ingersoll@Sun.COM * @param i_pExternalUniqueID non-NULL pointer to an external unique id to be converted
448*12720SWyllys.Ingersoll@Sun.COM * @return(NULL if memory cannot be allocated
449*12720SWyllys.Ingersoll@Sun.COM */
ConvertBinaryDataFromRequest(struct soap * i_pstSoap,const unsigned char * i_pBinaryData,int i_iBinaryDataLen)450*12720SWyllys.Ingersoll@Sun.COM static char * ConvertBinaryDataFromRequest (struct soap *i_pstSoap,
451*12720SWyllys.Ingersoll@Sun.COM const unsigned char * i_pBinaryData,
452*12720SWyllys.Ingersoll@Sun.COM int i_iBinaryDataLen)
453*12720SWyllys.Ingersoll@Sun.COM {
454*12720SWyllys.Ingersoll@Sun.COM char * pBinaryData = (char *) soap_malloc(i_pstSoap, 2 * i_iBinaryDataLen + 1);
455*12720SWyllys.Ingersoll@Sun.COM if (pBinaryData != NULL)
456*12720SWyllys.Ingersoll@Sun.COM {
457*12720SWyllys.Ingersoll@Sun.COM ConvertBinaryToUTF8HexString(pBinaryData,
458*12720SWyllys.Ingersoll@Sun.COM i_pBinaryData,
459*12720SWyllys.Ingersoll@Sun.COM i_iBinaryDataLen);
460*12720SWyllys.Ingersoll@Sun.COM }
461*12720SWyllys.Ingersoll@Sun.COM return (pBinaryData);
462*12720SWyllys.Ingersoll@Sun.COM }
463*12720SWyllys.Ingersoll@Sun.COM
464*12720SWyllys.Ingersoll@Sun.COM /**
465*12720SWyllys.Ingersoll@Sun.COM * Converts a UTF8 char string value to a fixed length array from
466*12720SWyllys.Ingersoll@Sun.COM * gSoap managed heap storage
467*12720SWyllys.Ingersoll@Sun.COM * @param pointer to gSoap runtime
468*12720SWyllys.Ingersoll@Sun.COM * @param i_pUTF8string non-NULL pointer to a null terminated UTF8 string
469*12720SWyllys.Ingersoll@Sun.COM * @param i_iLen size of arrray to be allocated
470*12720SWyllys.Ingersoll@Sun.COM * @return(NULL if gSoap allocated storage could not be obtained
471*12720SWyllys.Ingersoll@Sun.COM */
ConvertUTF8StringFromRequest(struct soap * i_pstSoap,const char * const i_pUTF8string,size_t i_iLen)472*12720SWyllys.Ingersoll@Sun.COM static char * ConvertUTF8StringFromRequest (struct soap *i_pstSoap,
473*12720SWyllys.Ingersoll@Sun.COM const char * const i_pUTF8string,
474*12720SWyllys.Ingersoll@Sun.COM size_t i_iLen)
475*12720SWyllys.Ingersoll@Sun.COM {
476*12720SWyllys.Ingersoll@Sun.COM char * pUTF8string = NULL;
477*12720SWyllys.Ingersoll@Sun.COM pUTF8string = (char *) soap_malloc(i_pstSoap, i_iLen);
478*12720SWyllys.Ingersoll@Sun.COM if (pUTF8string != NULL)
479*12720SWyllys.Ingersoll@Sun.COM {
480*12720SWyllys.Ingersoll@Sun.COM strncpy(pUTF8string, i_pUTF8string, i_iLen);
481*12720SWyllys.Ingersoll@Sun.COM pUTF8string[i_iLen-1] = '\0';
482*12720SWyllys.Ingersoll@Sun.COM }
483*12720SWyllys.Ingersoll@Sun.COM return (pUTF8string);
484*12720SWyllys.Ingersoll@Sun.COM }
485*12720SWyllys.Ingersoll@Sun.COM
CopyKeyGroupsResponse(struct KMS_Agent::KMS_Agent__ArrayOfKeyGroups * i_pKeyGroupsResponse)486*12720SWyllys.Ingersoll@Sun.COM static KMSAgent_ArrayOfKeyGroups * CopyKeyGroupsResponse
487*12720SWyllys.Ingersoll@Sun.COM (
488*12720SWyllys.Ingersoll@Sun.COM struct KMS_Agent::KMS_Agent__ArrayOfKeyGroups *i_pKeyGroupsResponse
489*12720SWyllys.Ingersoll@Sun.COM )
490*12720SWyllys.Ingersoll@Sun.COM {
491*12720SWyllys.Ingersoll@Sun.COM // alloc memory for result
492*12720SWyllys.Ingersoll@Sun.COM KMSAgent_ArrayOfKeyGroups *pResult =
493*12720SWyllys.Ingersoll@Sun.COM (KMSAgent_ArrayOfKeyGroups *) calloc(1, sizeof (KMSAgent_ArrayOfKeyGroups));
494*12720SWyllys.Ingersoll@Sun.COM
495*12720SWyllys.Ingersoll@Sun.COM // no memory, return
496*12720SWyllys.Ingersoll@Sun.COM if (pResult == NULL)
497*12720SWyllys.Ingersoll@Sun.COM {
498*12720SWyllys.Ingersoll@Sun.COM return (NULL);
499*12720SWyllys.Ingersoll@Sun.COM }
500*12720SWyllys.Ingersoll@Sun.COM
501*12720SWyllys.Ingersoll@Sun.COM // copy size
502*12720SWyllys.Ingersoll@Sun.COM pResult->m_iSize = i_pKeyGroupsResponse->__size;
503*12720SWyllys.Ingersoll@Sun.COM
504*12720SWyllys.Ingersoll@Sun.COM // if the size is 0, return(an empty result
505*12720SWyllys.Ingersoll@Sun.COM if (pResult->m_iSize == 0)
506*12720SWyllys.Ingersoll@Sun.COM {
507*12720SWyllys.Ingersoll@Sun.COM return (pResult);
508*12720SWyllys.Ingersoll@Sun.COM }
509*12720SWyllys.Ingersoll@Sun.COM
510*12720SWyllys.Ingersoll@Sun.COM // alloc memory for all key groups
511*12720SWyllys.Ingersoll@Sun.COM pResult->m_pKeyGroups = (KMSAgent_KeyGroup*)
512*12720SWyllys.Ingersoll@Sun.COM calloc(1, sizeof (KMSAgent_KeyGroup) * pResult->m_iSize);
513*12720SWyllys.Ingersoll@Sun.COM
514*12720SWyllys.Ingersoll@Sun.COM if (pResult->m_pKeyGroups == NULL)
515*12720SWyllys.Ingersoll@Sun.COM {
516*12720SWyllys.Ingersoll@Sun.COM free(pResult);
517*12720SWyllys.Ingersoll@Sun.COM return (NULL);
518*12720SWyllys.Ingersoll@Sun.COM }
519*12720SWyllys.Ingersoll@Sun.COM
520*12720SWyllys.Ingersoll@Sun.COM for (int i = 0; i < pResult->m_iSize; i++)
521*12720SWyllys.Ingersoll@Sun.COM {
522*12720SWyllys.Ingersoll@Sun.COM KMSAgent_KeyGroup *pKeyGroup;
523*12720SWyllys.Ingersoll@Sun.COM
524*12720SWyllys.Ingersoll@Sun.COM pKeyGroup = &(pResult->m_pKeyGroups[i]);
525*12720SWyllys.Ingersoll@Sun.COM
526*12720SWyllys.Ingersoll@Sun.COM strncpy(pKeyGroup->m_acKeyGroupID,
527*12720SWyllys.Ingersoll@Sun.COM i_pKeyGroupsResponse->__ptr[i].KeyGroupID,
528*12720SWyllys.Ingersoll@Sun.COM sizeof(pKeyGroup->m_acKeyGroupID));
529*12720SWyllys.Ingersoll@Sun.COM pKeyGroup->m_acKeyGroupID[sizeof(pKeyGroup->m_acKeyGroupID)-1] = '\0';
530*12720SWyllys.Ingersoll@Sun.COM
531*12720SWyllys.Ingersoll@Sun.COM strncpy(pKeyGroup->m_acDescription,
532*12720SWyllys.Ingersoll@Sun.COM i_pKeyGroupsResponse->__ptr[i].Description,
533*12720SWyllys.Ingersoll@Sun.COM sizeof(pKeyGroup->m_acDescription));
534*12720SWyllys.Ingersoll@Sun.COM pKeyGroup->m_acDescription[sizeof(pKeyGroup->m_acDescription)-1] = '\0';
535*12720SWyllys.Ingersoll@Sun.COM }
536*12720SWyllys.Ingersoll@Sun.COM
537*12720SWyllys.Ingersoll@Sun.COM return (pResult);
538*12720SWyllys.Ingersoll@Sun.COM }
539*12720SWyllys.Ingersoll@Sun.COM /**
540*12720SWyllys.Ingersoll@Sun.COM * allocate storage for the KMSAgent_ArrayOfKeys struct and the array of keys returned in the
541*12720SWyllys.Ingersoll@Sun.COM * soap response.
542*12720SWyllys.Ingersoll@Sun.COM * @param i_pProfile pointer to profile
543*12720SWyllys.Ingersoll@Sun.COM * @param io_pClusterIndex pointer to the cluster index value which is used
544*12720SWyllys.Ingersoll@Sun.COM * by AES Key Unwrap to access the KWK for the KMA corresponding to the
545*12720SWyllys.Ingersoll@Sun.COM * cluster index.
546*12720SWyllys.Ingersoll@Sun.COM * @param i_pKeysResponse pointer to the soap response' array of keys struct
547*12720SWyllys.Ingersoll@Sun.COM * @return(pointer to allocated KMSAgent_ArrayOfKeys and the corresponding keys, returns NULL
548*12720SWyllys.Ingersoll@Sun.COM * on any error and frees any allocated storage before returning. For response data validation errors a
549*12720SWyllys.Ingersoll@Sun.COM * message will be logged.
550*12720SWyllys.Ingersoll@Sun.COM */
CopyDataUnitKeysResponse(KMSClientProfile * i_pProfile,int * const io_pClusterIndex,struct KMS_Agent::KMS_Agent__ArrayOfKeys * i_pKeysResponse)551*12720SWyllys.Ingersoll@Sun.COM static KMSAgent_ArrayOfKeys * CopyDataUnitKeysResponse (
552*12720SWyllys.Ingersoll@Sun.COM KMSClientProfile *i_pProfile,
553*12720SWyllys.Ingersoll@Sun.COM int * const io_pClusterIndex,
554*12720SWyllys.Ingersoll@Sun.COM struct KMS_Agent::KMS_Agent__ArrayOfKeys *i_pKeysResponse)
555*12720SWyllys.Ingersoll@Sun.COM {
556*12720SWyllys.Ingersoll@Sun.COM KMSAgent_ArrayOfKeys * pResult =
557*12720SWyllys.Ingersoll@Sun.COM (KMSAgent_ArrayOfKeys *) calloc(1, sizeof (KMSAgent_ArrayOfKeys));
558*12720SWyllys.Ingersoll@Sun.COM
559*12720SWyllys.Ingersoll@Sun.COM if (pResult == NULL)
560*12720SWyllys.Ingersoll@Sun.COM {
561*12720SWyllys.Ingersoll@Sun.COM return (NULL);
562*12720SWyllys.Ingersoll@Sun.COM }
563*12720SWyllys.Ingersoll@Sun.COM
564*12720SWyllys.Ingersoll@Sun.COM // if the size is 0, return(an empty result
565*12720SWyllys.Ingersoll@Sun.COM if (i_pKeysResponse->__size == 0)
566*12720SWyllys.Ingersoll@Sun.COM {
567*12720SWyllys.Ingersoll@Sun.COM return (pResult);
568*12720SWyllys.Ingersoll@Sun.COM }
569*12720SWyllys.Ingersoll@Sun.COM
570*12720SWyllys.Ingersoll@Sun.COM if (i_pKeysResponse->__size > KMS_MAX_PAGE_SIZE)
571*12720SWyllys.Ingersoll@Sun.COM {
572*12720SWyllys.Ingersoll@Sun.COM free(pResult);
573*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
574*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_KEYS_INVALID_KEY_ARRAY_SIZE_RESPONSE,
575*12720SWyllys.Ingersoll@Sun.COM NULL,
576*12720SWyllys.Ingersoll@Sun.COM NULL,
577*12720SWyllys.Ingersoll@Sun.COM NULL);
578*12720SWyllys.Ingersoll@Sun.COM return (NULL);
579*12720SWyllys.Ingersoll@Sun.COM }
580*12720SWyllys.Ingersoll@Sun.COM
581*12720SWyllys.Ingersoll@Sun.COM pResult->m_iSize = i_pKeysResponse->__size;
582*12720SWyllys.Ingersoll@Sun.COM
583*12720SWyllys.Ingersoll@Sun.COM // alloc memory for all keys returned
584*12720SWyllys.Ingersoll@Sun.COM pResult->m_pKeys = (KMSAgent_Key*)
585*12720SWyllys.Ingersoll@Sun.COM calloc(1, sizeof (KMSAgent_Key) * i_pKeysResponse->__size);
586*12720SWyllys.Ingersoll@Sun.COM
587*12720SWyllys.Ingersoll@Sun.COM if (pResult->m_pKeys == NULL)
588*12720SWyllys.Ingersoll@Sun.COM {
589*12720SWyllys.Ingersoll@Sun.COM free(pResult);
590*12720SWyllys.Ingersoll@Sun.COM return (NULL);
591*12720SWyllys.Ingersoll@Sun.COM // no memory, don't log
592*12720SWyllys.Ingersoll@Sun.COM }
593*12720SWyllys.Ingersoll@Sun.COM
594*12720SWyllys.Ingersoll@Sun.COM // copy keys from response
595*12720SWyllys.Ingersoll@Sun.COM for (int i = 0; i < i_pKeysResponse->__size; i++)
596*12720SWyllys.Ingersoll@Sun.COM {
597*12720SWyllys.Ingersoll@Sun.COM if (KMS_KEY_ID_SIZE != ConvertUTF8HexStringToBinary(
598*12720SWyllys.Ingersoll@Sun.COM i_pKeysResponse->__ptr[i].KeyID, NULL))
599*12720SWyllys.Ingersoll@Sun.COM {
600*12720SWyllys.Ingersoll@Sun.COM free(pResult->m_pKeys);
601*12720SWyllys.Ingersoll@Sun.COM free(pResult);
602*12720SWyllys.Ingersoll@Sun.COM
603*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
604*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_KEYS_INVALID_KEY_RESPONSE,
605*12720SWyllys.Ingersoll@Sun.COM NULL,
606*12720SWyllys.Ingersoll@Sun.COM NULL,
607*12720SWyllys.Ingersoll@Sun.COM NULL);
608*12720SWyllys.Ingersoll@Sun.COM return (NULL);
609*12720SWyllys.Ingersoll@Sun.COM }
610*12720SWyllys.Ingersoll@Sun.COM
611*12720SWyllys.Ingersoll@Sun.COM ConvertUTF8HexStringToBinary(
612*12720SWyllys.Ingersoll@Sun.COM i_pKeysResponse->__ptr[i].KeyID, pResult->m_pKeys[i].m_acKeyID);
613*12720SWyllys.Ingersoll@Sun.COM
614*12720SWyllys.Ingersoll@Sun.COM if ((KMS_AGENT_KEY_STATE) i_pKeysResponse->__ptr[i].KeyState < KMS_KEY_STATE_ACTIVE_PROTECT_AND_PROCESS ||
615*12720SWyllys.Ingersoll@Sun.COM (KMS_AGENT_KEY_STATE) i_pKeysResponse->__ptr[i].KeyState > KMS_KEY_STATE_COMPROMISED)
616*12720SWyllys.Ingersoll@Sun.COM {
617*12720SWyllys.Ingersoll@Sun.COM free(pResult->m_pKeys);
618*12720SWyllys.Ingersoll@Sun.COM free(pResult);
619*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
620*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_KEYS_INVALID_KEY_STATE_RESPONSE,
621*12720SWyllys.Ingersoll@Sun.COM NULL,
622*12720SWyllys.Ingersoll@Sun.COM NULL,
623*12720SWyllys.Ingersoll@Sun.COM NULL);
624*12720SWyllys.Ingersoll@Sun.COM return (NULL);
625*12720SWyllys.Ingersoll@Sun.COM }
626*12720SWyllys.Ingersoll@Sun.COM pResult->m_pKeys[i].m_iKeyState = (KMS_AGENT_KEY_STATE) i_pKeysResponse->__ptr[i].KeyState;
627*12720SWyllys.Ingersoll@Sun.COM
628*12720SWyllys.Ingersoll@Sun.COM if ((KMS_KEY_TYPE) i_pKeysResponse->__ptr[i].KeyType != (KMS_KEY_TYPE)KMS_KEY_TYPE_AES_256)
629*12720SWyllys.Ingersoll@Sun.COM {
630*12720SWyllys.Ingersoll@Sun.COM free(pResult->m_pKeys);
631*12720SWyllys.Ingersoll@Sun.COM free(pResult);
632*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
633*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_KEYS_INVALID_KEY_TYPE_RESPONSE,
634*12720SWyllys.Ingersoll@Sun.COM NULL,
635*12720SWyllys.Ingersoll@Sun.COM NULL,
636*12720SWyllys.Ingersoll@Sun.COM NULL);
637*12720SWyllys.Ingersoll@Sun.COM return (NULL);
638*12720SWyllys.Ingersoll@Sun.COM }
639*12720SWyllys.Ingersoll@Sun.COM pResult->m_pKeys[i].m_iKeyType = (KMS_KEY_TYPE) i_pKeysResponse->__ptr[i].KeyType;
640*12720SWyllys.Ingersoll@Sun.COM
641*12720SWyllys.Ingersoll@Sun.COM strncpy(pResult->m_pKeys[i].m_acKeyGroupID,
642*12720SWyllys.Ingersoll@Sun.COM i_pKeysResponse->__ptr[i].KeyGroupID,
643*12720SWyllys.Ingersoll@Sun.COM sizeof(pResult->m_pKeys[i].m_acKeyGroupID));
644*12720SWyllys.Ingersoll@Sun.COM pResult->m_pKeys[i].m_acKeyGroupID[sizeof(pResult->m_pKeys[i].m_acKeyGroupID)-1] = '\0';
645*12720SWyllys.Ingersoll@Sun.COM
646*12720SWyllys.Ingersoll@Sun.COM CAgentLoadBalancer *pAgentLoadBalancer = reinterpret_cast
647*12720SWyllys.Ingersoll@Sun.COM <CAgentLoadBalancer *> (i_pProfile->m_pAgentLoadBalancer);
648*12720SWyllys.Ingersoll@Sun.COM
649*12720SWyllys.Ingersoll@Sun.COM if (pAgentLoadBalancer->AESKeyWrapSupported(*io_pClusterIndex))
650*12720SWyllys.Ingersoll@Sun.COM {
651*12720SWyllys.Ingersoll@Sun.COM if (i_pKeysResponse->__ptr[i].Key.__size != KMS_MAX_WRAPPED_KEY_SIZE)
652*12720SWyllys.Ingersoll@Sun.COM {
653*12720SWyllys.Ingersoll@Sun.COM free(pResult->m_pKeys);
654*12720SWyllys.Ingersoll@Sun.COM free(pResult);
655*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
656*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_KEYS_INVALID_WRAPPED_KEY_LENGTH_RESPONSE,
657*12720SWyllys.Ingersoll@Sun.COM NULL,
658*12720SWyllys.Ingersoll@Sun.COM NULL,
659*12720SWyllys.Ingersoll@Sun.COM NULL);
660*12720SWyllys.Ingersoll@Sun.COM return (NULL);
661*12720SWyllys.Ingersoll@Sun.COM }
662*12720SWyllys.Ingersoll@Sun.COM else
663*12720SWyllys.Ingersoll@Sun.COM {
664*12720SWyllys.Ingersoll@Sun.COM if (pAgentLoadBalancer->AESKeyUnwrap(io_pClusterIndex,
665*12720SWyllys.Ingersoll@Sun.COM i_pKeysResponse->__ptr[i].Key.__ptr,
666*12720SWyllys.Ingersoll@Sun.COM pResult->m_pKeys[i].m_acKey) == false)
667*12720SWyllys.Ingersoll@Sun.COM {
668*12720SWyllys.Ingersoll@Sun.COM free(pResult->m_pKeys);
669*12720SWyllys.Ingersoll@Sun.COM free(pResult);
670*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
671*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_KEYS_AESKEYUNWRAP_ERROR,
672*12720SWyllys.Ingersoll@Sun.COM NULL,
673*12720SWyllys.Ingersoll@Sun.COM NULL,
674*12720SWyllys.Ingersoll@Sun.COM NULL);
675*12720SWyllys.Ingersoll@Sun.COM
676*12720SWyllys.Ingersoll@Sun.COM return (NULL);
677*12720SWyllys.Ingersoll@Sun.COM }
678*12720SWyllys.Ingersoll@Sun.COM }
679*12720SWyllys.Ingersoll@Sun.COM }
680*12720SWyllys.Ingersoll@Sun.COM else // non-AES Key Wrap
681*12720SWyllys.Ingersoll@Sun.COM {
682*12720SWyllys.Ingersoll@Sun.COM if (i_pKeysResponse->__ptr[i].Key.__size != KMS_MAX_KEY_SIZE)
683*12720SWyllys.Ingersoll@Sun.COM {
684*12720SWyllys.Ingersoll@Sun.COM free(pResult->m_pKeys);
685*12720SWyllys.Ingersoll@Sun.COM free(pResult);
686*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
687*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_KEYS_INVALID_KEY_LENGTH_RESPONSE,
688*12720SWyllys.Ingersoll@Sun.COM NULL,
689*12720SWyllys.Ingersoll@Sun.COM NULL,
690*12720SWyllys.Ingersoll@Sun.COM NULL);
691*12720SWyllys.Ingersoll@Sun.COM return (NULL);
692*12720SWyllys.Ingersoll@Sun.COM }
693*12720SWyllys.Ingersoll@Sun.COM
694*12720SWyllys.Ingersoll@Sun.COM memcpy(pResult->m_pKeys[i].m_acKey,
695*12720SWyllys.Ingersoll@Sun.COM i_pKeysResponse->__ptr[i].Key.__ptr,
696*12720SWyllys.Ingersoll@Sun.COM KMS_MAX_KEY_SIZE);
697*12720SWyllys.Ingersoll@Sun.COM }
698*12720SWyllys.Ingersoll@Sun.COM
699*12720SWyllys.Ingersoll@Sun.COM pResult->m_pKeys[i].m_iKeyLength = KMS_MAX_KEY_SIZE;
700*12720SWyllys.Ingersoll@Sun.COM
701*12720SWyllys.Ingersoll@Sun.COM if (KMSAgentKeyCallout(pResult->m_pKeys[i].m_acKey) != 0)
702*12720SWyllys.Ingersoll@Sun.COM {
703*12720SWyllys.Ingersoll@Sun.COM free(pResult->m_pKeys);
704*12720SWyllys.Ingersoll@Sun.COM free(pResult);
705*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
706*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_KEYS_KEY_CALLOUT_ERROR,
707*12720SWyllys.Ingersoll@Sun.COM NULL,
708*12720SWyllys.Ingersoll@Sun.COM NULL,
709*12720SWyllys.Ingersoll@Sun.COM NULL);
710*12720SWyllys.Ingersoll@Sun.COM return (NULL);
711*12720SWyllys.Ingersoll@Sun.COM }
712*12720SWyllys.Ingersoll@Sun.COM }
713*12720SWyllys.Ingersoll@Sun.COM
714*12720SWyllys.Ingersoll@Sun.COM return (pResult);
715*12720SWyllys.Ingersoll@Sun.COM }
716*12720SWyllys.Ingersoll@Sun.COM
717*12720SWyllys.Ingersoll@Sun.COM /**
718*12720SWyllys.Ingersoll@Sun.COM * This function returns the API status code based upon the error string in the profile and
719*12720SWyllys.Ingersoll@Sun.COM * availability of KMAs. KMA availability determination is based upon the i_iKMAFailoverReturnCode
720*12720SWyllys.Ingersoll@Sun.COM * parameter and the size of the cluster. A cluster size of 0 is an indicator that there are
721*12720SWyllys.Ingersoll@Sun.COM * no KMAs available, unless cluster discovery is disabled by the profile's cluster discovery
722*12720SWyllys.Ingersoll@Sun.COM * frequency.
723*12720SWyllys.Ingersoll@Sun.COM *
724*12720SWyllys.Ingersoll@Sun.COM * @param i_pProfile pointer to the profile
725*12720SWyllys.Ingersoll@Sun.COM * @param i_iKMAFailoverReturnCode the return(code from CAgentLoadBalancer::Failover() or 0
726*12720SWyllys.Ingersoll@Sun.COM * if it was not called. This is used to for determining if KMS_AGENT_STATUS_KMS_UNAVAILABLE
727*12720SWyllys.Ingersoll@Sun.COM * needs to be returned.
728*12720SWyllys.Ingersoll@Sun.COM * @returns KMS_AGENT_STATUS_GENERIC_ERROR
729*12720SWyllys.Ingersoll@Sun.COM * unless the profile's last error message field contains a message substring matching one of the
730*12720SWyllys.Ingersoll@Sun.COM * KMSAgent service soap fault strings.
731*12720SWyllys.Ingersoll@Sun.COM *
732*12720SWyllys.Ingersoll@Sun.COM */
KMSAgent_GetLastStatusCode(KMSClientProfile * i_pProfile,int i_iKMAFailoverReturnCode)733*12720SWyllys.Ingersoll@Sun.COM static KMS_AGENT_STATUS KMSAgent_GetLastStatusCode (KMSClientProfile *i_pProfile,
734*12720SWyllys.Ingersoll@Sun.COM int i_iKMAFailoverReturnCode)
735*12720SWyllys.Ingersoll@Sun.COM {
736*12720SWyllys.Ingersoll@Sun.COM bool bServerError = false;
737*12720SWyllys.Ingersoll@Sun.COM
738*12720SWyllys.Ingersoll@Sun.COM FATAL_ASSERT(i_pProfile);
739*12720SWyllys.Ingersoll@Sun.COM
740*12720SWyllys.Ingersoll@Sun.COM // see KMSAgentLoadBalancer.h for return codes from Failover
741*12720SWyllys.Ingersoll@Sun.COM
742*12720SWyllys.Ingersoll@Sun.COM if (i_iKMAFailoverReturnCode == CAgentLoadBalancer::NO_FIPS_KMA_AVAILABLE)
743*12720SWyllys.Ingersoll@Sun.COM {
744*12720SWyllys.Ingersoll@Sun.COM return (KMS_AGENT_STATUS_NO_FIPS_KMAS_AVAILABLE);
745*12720SWyllys.Ingersoll@Sun.COM }
746*12720SWyllys.Ingersoll@Sun.COM
747*12720SWyllys.Ingersoll@Sun.COM // parse for server errors -
748*12720SWyllys.Ingersoll@Sun.COM // when KMAs have no ready keys we want to inform the client, vs reporting that the KMS is unavailable
749*12720SWyllys.Ingersoll@Sun.COM bServerError = ServerError(i_pProfile->m_wsErrorString, 0);
750*12720SWyllys.Ingersoll@Sun.COM
751*12720SWyllys.Ingersoll@Sun.COM // parse for Soap errors
752*12720SWyllys.Ingersoll@Sun.COM const char* sFaultstringStart = strstr(i_pProfile->m_wsErrorString, "SoapFaultString=");
753*12720SWyllys.Ingersoll@Sun.COM
754*12720SWyllys.Ingersoll@Sun.COM int iErrorCode = INVALID_CLIENT_ERROR; // initially
755*12720SWyllys.Ingersoll@Sun.COM
756*12720SWyllys.Ingersoll@Sun.COM
757*12720SWyllys.Ingersoll@Sun.COM // if there is a Soap error
758*12720SWyllys.Ingersoll@Sun.COM if (sFaultstringStart)
759*12720SWyllys.Ingersoll@Sun.COM {
760*12720SWyllys.Ingersoll@Sun.COM if (SSL_InvalidCertificate(sFaultstringStart))
761*12720SWyllys.Ingersoll@Sun.COM {
762*12720SWyllys.Ingersoll@Sun.COM // this can be caused by the KMS invalidating the agent's cert
763*12720SWyllys.Ingersoll@Sun.COM return (KMS_AGENT_STATUS_ACCESS_DENIED);
764*12720SWyllys.Ingersoll@Sun.COM }
765*12720SWyllys.Ingersoll@Sun.COM iErrorCode = GET_FAULT_CODE(sFaultstringStart + strlen("SoapFaultString="));
766*12720SWyllys.Ingersoll@Sun.COM }
767*12720SWyllys.Ingersoll@Sun.COM
768*12720SWyllys.Ingersoll@Sun.COM
769*12720SWyllys.Ingersoll@Sun.COM #ifdef METAWARE
770*12720SWyllys.Ingersoll@Sun.COM // log the failure code/cause to the event log
771*12720SWyllys.Ingersoll@Sun.COM LogToFile(i_iKMAFailoverReturnCode, i_pProfile->m_wsErrorString);
772*12720SWyllys.Ingersoll@Sun.COM LogToFile(iErrorCode, "error code");
773*12720SWyllys.Ingersoll@Sun.COM #endif
774*12720SWyllys.Ingersoll@Sun.COM
775*12720SWyllys.Ingersoll@Sun.COM
776*12720SWyllys.Ingersoll@Sun.COM // parse return code passed in from last call to FailOver, Balance or BalanceByDataUnitKeyID
777*12720SWyllys.Ingersoll@Sun.COM // if failover reported no kma and there is a valid server error and client couldn't get keys
778*12720SWyllys.Ingersoll@Sun.COM if (i_iKMAFailoverReturnCode == CAgentLoadBalancer::NO_KMA_AVAILABLE &&
779*12720SWyllys.Ingersoll@Sun.COM bServerError &&
780*12720SWyllys.Ingersoll@Sun.COM iErrorCode == CLIENT_ERROR_AGENT_NO_READY_KEYS)
781*12720SWyllys.Ingersoll@Sun.COM {
782*12720SWyllys.Ingersoll@Sun.COM return (KMS_AGENT_STATUS_KMS_UNAVAILABLE);
783*12720SWyllys.Ingersoll@Sun.COM }
784*12720SWyllys.Ingersoll@Sun.COM
785*12720SWyllys.Ingersoll@Sun.COM // if there is a server error and we are doing discovery
786*12720SWyllys.Ingersoll@Sun.COM if (bServerError &&
787*12720SWyllys.Ingersoll@Sun.COM ((i_pProfile->m_iClusterDiscoveryFrequency > 0 &&
788*12720SWyllys.Ingersoll@Sun.COM i_pProfile->m_iClusterNum == 0)
789*12720SWyllys.Ingersoll@Sun.COM || iErrorCode == CLIENT_ERROR_AGENT_APPLIANCE_LOCKED))
790*12720SWyllys.Ingersoll@Sun.COM {
791*12720SWyllys.Ingersoll@Sun.COM return (KMS_AGENT_STATUS_KMS_UNAVAILABLE);
792*12720SWyllys.Ingersoll@Sun.COM }
793*12720SWyllys.Ingersoll@Sun.COM
794*12720SWyllys.Ingersoll@Sun.COM if (bServerError && i_iKMAFailoverReturnCode == CAgentLoadBalancer::NO_KMA_AVAILABLE)
795*12720SWyllys.Ingersoll@Sun.COM {
796*12720SWyllys.Ingersoll@Sun.COM return (KMS_AGENT_STATUS_KMS_UNAVAILABLE);
797*12720SWyllys.Ingersoll@Sun.COM }
798*12720SWyllys.Ingersoll@Sun.COM
799*12720SWyllys.Ingersoll@Sun.COM if ( i_iKMAFailoverReturnCode == CAgentLoadBalancer::AES_KEY_UNWRAP_ERROR )
800*12720SWyllys.Ingersoll@Sun.COM return (KMS_AGENT_AES_KEY_UNWRAP_ERROR);
801*12720SWyllys.Ingersoll@Sun.COM if ( i_iKMAFailoverReturnCode == CAgentLoadBalancer::AES_KEY_WRAP_SETUP_ERROR )
802*12720SWyllys.Ingersoll@Sun.COM return (KMS_AGENT_AES_KEY_WRAP_SETUP_ERROR);
803*12720SWyllys.Ingersoll@Sun.COM
804*12720SWyllys.Ingersoll@Sun.COM if (iErrorCode == CLIENT_ERROR_ACCESS_DENIED)
805*12720SWyllys.Ingersoll@Sun.COM return (KMS_AGENT_STATUS_ACCESS_DENIED);
806*12720SWyllys.Ingersoll@Sun.COM if (iErrorCode == CLIENT_ERROR_SERVER_BUSY)
807*12720SWyllys.Ingersoll@Sun.COM return (KMS_AGENT_STATUS_SERVER_BUSY);
808*12720SWyllys.Ingersoll@Sun.COM if (iErrorCode == CLIENT_ERROR_AGENT_INVALID_PARAMETERS)
809*12720SWyllys.Ingersoll@Sun.COM return (KMS_AGENT_STATUS_INVALID_PARAMETER);
810*12720SWyllys.Ingersoll@Sun.COM if (iErrorCode == CLIENT_ERROR_AGENT_KEY_DOES_NOT_EXIST)
811*12720SWyllys.Ingersoll@Sun.COM return (KMS_AGENT_STATUS_KEY_DOES_NOT_EXIST);
812*12720SWyllys.Ingersoll@Sun.COM if (iErrorCode == CLIENT_ERROR_AGENT_KEY_DESTROYED)
813*12720SWyllys.Ingersoll@Sun.COM return (KMS_AGENT_STATUS_KEY_DESTROYED);
814*12720SWyllys.Ingersoll@Sun.COM if (iErrorCode == CLIENT_ERROR_AGENT_DATA_UNIT_ID_NOT_FOUND_EXTERNAL_ID_EXISTS)
815*12720SWyllys.Ingersoll@Sun.COM return (KMS_AGENT_STATUS_DATA_UNIT_ID_NOT_FOUND_EXTERNAL_ID_EXISTS);
816*12720SWyllys.Ingersoll@Sun.COM if (iErrorCode == CLIENT_ERROR_AGENT_DUPLICATE_EXTERNAL_ID)
817*12720SWyllys.Ingersoll@Sun.COM return (KMS_AGENT_STATUS_EXTERNAL_UNIQUE_ID_EXISTS);
818*12720SWyllys.Ingersoll@Sun.COM if (iErrorCode == CLIENT_ERROR_AGENT_NO_READY_KEYS)
819*12720SWyllys.Ingersoll@Sun.COM return (KMS_AGENT_STATUS_KMS_NO_READY_KEYS);
820*12720SWyllys.Ingersoll@Sun.COM
821*12720SWyllys.Ingersoll@Sun.COM // this check is made last to allow other specific errors that may have occurred to take precedence,
822*12720SWyllys.Ingersoll@Sun.COM // e.g. return access denied before reporting No FIPS KMAs
823*12720SWyllys.Ingersoll@Sun.COM if (i_pProfile->m_eKMSmode == FIPS_MODE &&
824*12720SWyllys.Ingersoll@Sun.COM KMSClient_NoFIPSCompatibleKMAs(i_pProfile))
825*12720SWyllys.Ingersoll@Sun.COM {
826*12720SWyllys.Ingersoll@Sun.COM return (KMS_AGENT_STATUS_NO_FIPS_KMAS_AVAILABLE);
827*12720SWyllys.Ingersoll@Sun.COM }
828*12720SWyllys.Ingersoll@Sun.COM
829*12720SWyllys.Ingersoll@Sun.COM return (KMS_AGENT_STATUS_GENERIC_ERROR);
830*12720SWyllys.Ingersoll@Sun.COM }
831*12720SWyllys.Ingersoll@Sun.COM
832*12720SWyllys.Ingersoll@Sun.COM /*---------------------------------------------------------------------------
833*12720SWyllys.Ingersoll@Sun.COM * Function: KMSAgent_InitializeLibrary
834*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/
835*12720SWyllys.Ingersoll@Sun.COM #include "KMSAuditLogger.h"
836*12720SWyllys.Ingersoll@Sun.COM
837*12720SWyllys.Ingersoll@Sun.COM extern "C"
KMSAgent_InitializeLibrary(utf8cstr const i_pWorkingDirectory,int i_bUseFileLog)838*12720SWyllys.Ingersoll@Sun.COM KMS_AGENT_STATUS KMSAgent_InitializeLibrary (utf8cstr const i_pWorkingDirectory,
839*12720SWyllys.Ingersoll@Sun.COM int i_bUseFileLog)
840*12720SWyllys.Ingersoll@Sun.COM
841*12720SWyllys.Ingersoll@Sun.COM {
842*12720SWyllys.Ingersoll@Sun.COM bool bSuccess;
843*12720SWyllys.Ingersoll@Sun.COM
844*12720SWyllys.Ingersoll@Sun.COM #if defined(METAWARE)
845*12720SWyllys.Ingersoll@Sun.COM #warn "debug timing is on"
846*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
847*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE(trace, KMSAgent_InitializeLibrary);
848*12720SWyllys.Ingersoll@Sun.COM #endif
849*12720SWyllys.Ingersoll@Sun.COM
850*12720SWyllys.Ingersoll@Sun.COM #if defined(DEBUG) && defined(METAWARE)
851*12720SWyllys.Ingersoll@Sun.COM log_printf("KMSAgent_InitializeLibrary : Entered");
852*12720SWyllys.Ingersoll@Sun.COM #endif
853*12720SWyllys.Ingersoll@Sun.COM
854*12720SWyllys.Ingersoll@Sun.COM bSuccess = KMSClient_InitializeLibrary(
855*12720SWyllys.Ingersoll@Sun.COM i_pWorkingDirectory,
856*12720SWyllys.Ingersoll@Sun.COM i_bUseFileLog);
857*12720SWyllys.Ingersoll@Sun.COM
858*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
859*12720SWyllys.Ingersoll@Sun.COM {
860*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_OK);
861*12720SWyllys.Ingersoll@Sun.COM }
862*12720SWyllys.Ingersoll@Sun.COM
863*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_GENERIC_ERROR);
864*12720SWyllys.Ingersoll@Sun.COM }
865*12720SWyllys.Ingersoll@Sun.COM
866*12720SWyllys.Ingersoll@Sun.COM /*---------------------------------------------------------------------------
867*12720SWyllys.Ingersoll@Sun.COM * Function: KMSAgent_KnownAnswerTests
868*12720SWyllys.Ingersoll@Sun.COM *
869*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/
KMSAgent_KnownAnswerTests()870*12720SWyllys.Ingersoll@Sun.COM KMS_AGENT_STATUS KMSAgent_KnownAnswerTests()
871*12720SWyllys.Ingersoll@Sun.COM {
872*12720SWyllys.Ingersoll@Sun.COM #if defined(METAWARE)
873*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
874*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE(trace, KMSAgent_KnownAnswerTests);
875*12720SWyllys.Ingersoll@Sun.COM #endif
876*12720SWyllys.Ingersoll@Sun.COM
877*12720SWyllys.Ingersoll@Sun.COM // Known Answer Test on AES Key Wrap code
878*12720SWyllys.Ingersoll@Sun.COM if ( KnownAnswerTestAESKeyWrap() != 0 )
879*12720SWyllys.Ingersoll@Sun.COM {
880*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_FIPS_KAT_AES_KEYWRAP_ERROR);
881*12720SWyllys.Ingersoll@Sun.COM }
882*12720SWyllys.Ingersoll@Sun.COM
883*12720SWyllys.Ingersoll@Sun.COM if ( KnownAnswerTestAESECB() != 0 )
884*12720SWyllys.Ingersoll@Sun.COM {
885*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_FIPS_KAT_AES_ECB_ERROR);
886*12720SWyllys.Ingersoll@Sun.COM }
887*12720SWyllys.Ingersoll@Sun.COM
888*12720SWyllys.Ingersoll@Sun.COM if ( KnownAnswerTestHMACSHA1() != 0 )
889*12720SWyllys.Ingersoll@Sun.COM {
890*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_FIPS_KAT_HMAC_SHA1_ERROR);
891*12720SWyllys.Ingersoll@Sun.COM }
892*12720SWyllys.Ingersoll@Sun.COM
893*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_OK);
894*12720SWyllys.Ingersoll@Sun.COM
895*12720SWyllys.Ingersoll@Sun.COM }
896*12720SWyllys.Ingersoll@Sun.COM
897*12720SWyllys.Ingersoll@Sun.COM /*---------------------------------------------------------------------------
898*12720SWyllys.Ingersoll@Sun.COM * Function: KMSAgent_FinalizeLibrary
899*12720SWyllys.Ingersoll@Sun.COM *
900*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/
901*12720SWyllys.Ingersoll@Sun.COM
902*12720SWyllys.Ingersoll@Sun.COM extern "C"
KMSAgent_FinalizeLibrary()903*12720SWyllys.Ingersoll@Sun.COM KMS_AGENT_STATUS KMSAgent_FinalizeLibrary ()
904*12720SWyllys.Ingersoll@Sun.COM {
905*12720SWyllys.Ingersoll@Sun.COM bool bSuccess;
906*12720SWyllys.Ingersoll@Sun.COM
907*12720SWyllys.Ingersoll@Sun.COM #if defined(METAWARE)
908*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
909*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE(trace, KMSAgent_FinalizeLibrary);
910*12720SWyllys.Ingersoll@Sun.COM #endif
911*12720SWyllys.Ingersoll@Sun.COM
912*12720SWyllys.Ingersoll@Sun.COM bSuccess = KMSClient_FinalizeLibrary();
913*12720SWyllys.Ingersoll@Sun.COM
914*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
915*12720SWyllys.Ingersoll@Sun.COM {
916*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_OK);
917*12720SWyllys.Ingersoll@Sun.COM }
918*12720SWyllys.Ingersoll@Sun.COM
919*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_GENERIC_ERROR);
920*12720SWyllys.Ingersoll@Sun.COM }
921*12720SWyllys.Ingersoll@Sun.COM
922*12720SWyllys.Ingersoll@Sun.COM /*---------------------------------------------------------------------------
923*12720SWyllys.Ingersoll@Sun.COM * Function: KMSAgent_GetLastErrorMessage
924*12720SWyllys.Ingersoll@Sun.COM *
925*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/
926*12720SWyllys.Ingersoll@Sun.COM
927*12720SWyllys.Ingersoll@Sun.COM extern "C"
KMSAgent_GetLastErrorMessage(KMSClientProfile * i_pProfile)928*12720SWyllys.Ingersoll@Sun.COM utf8cstr KMSAgent_GetLastErrorMessage (KMSClientProfile* i_pProfile)
929*12720SWyllys.Ingersoll@Sun.COM {
930*12720SWyllys.Ingersoll@Sun.COM #if defined(METAWARE)
931*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
932*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE(trace, KMSAgent_GetLastErrorMessage);
933*12720SWyllys.Ingersoll@Sun.COM #endif
934*12720SWyllys.Ingersoll@Sun.COM
935*12720SWyllys.Ingersoll@Sun.COM if (i_pProfile == NULL)
936*12720SWyllys.Ingersoll@Sun.COM {
937*12720SWyllys.Ingersoll@Sun.COM RETURN(NULL);
938*12720SWyllys.Ingersoll@Sun.COM }
939*12720SWyllys.Ingersoll@Sun.COM
940*12720SWyllys.Ingersoll@Sun.COM RETURN(KMSClient_GetLastErrorMessage(i_pProfile));
941*12720SWyllys.Ingersoll@Sun.COM }
942*12720SWyllys.Ingersoll@Sun.COM
943*12720SWyllys.Ingersoll@Sun.COM /*---------------------------------------------------------------------------
944*12720SWyllys.Ingersoll@Sun.COM * Function: KMSAgent_GetClusterInformation
945*12720SWyllys.Ingersoll@Sun.COM *
946*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/
947*12720SWyllys.Ingersoll@Sun.COM extern "C"
KMSAgent_GetClusterInformation(KMSClientProfile * const i_pProfile,int i_iEntitySiteIDSize,int i_iClusterEntryArraySize,utf8cstr const o_pEntitySiteID,int * const o_pApplianceNum,KMSClusterEntry * const o_pClusterEntryArray)948*12720SWyllys.Ingersoll@Sun.COM KMS_AGENT_STATUS KMSAgent_GetClusterInformation (
949*12720SWyllys.Ingersoll@Sun.COM KMSClientProfile * const i_pProfile,
950*12720SWyllys.Ingersoll@Sun.COM int i_iEntitySiteIDSize,
951*12720SWyllys.Ingersoll@Sun.COM int i_iClusterEntryArraySize,
952*12720SWyllys.Ingersoll@Sun.COM utf8cstr const o_pEntitySiteID,
953*12720SWyllys.Ingersoll@Sun.COM int * const o_pApplianceNum,
954*12720SWyllys.Ingersoll@Sun.COM KMSClusterEntry * const o_pClusterEntryArray)
955*12720SWyllys.Ingersoll@Sun.COM {
956*12720SWyllys.Ingersoll@Sun.COM bool bSuccess;
957*12720SWyllys.Ingersoll@Sun.COM #if defined(METAWARE)
958*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
959*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE(trace, KMSAgent_GetClusterInformation);
960*12720SWyllys.Ingersoll@Sun.COM #endif
961*12720SWyllys.Ingersoll@Sun.COM
962*12720SWyllys.Ingersoll@Sun.COM if (!i_pProfile)
963*12720SWyllys.Ingersoll@Sun.COM {
964*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_GET_CLUSTER_INFORMATION_INVALID_PARAMETERS,
965*12720SWyllys.Ingersoll@Sun.COM NULL,
966*12720SWyllys.Ingersoll@Sun.COM NULL,
967*12720SWyllys.Ingersoll@Sun.COM "Profile arg");
968*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
969*12720SWyllys.Ingersoll@Sun.COM }
970*12720SWyllys.Ingersoll@Sun.COM
971*12720SWyllys.Ingersoll@Sun.COM if (!o_pEntitySiteID || (i_iEntitySiteIDSize <= (KMS_MAX_ENTITY_SITE_ID)))
972*12720SWyllys.Ingersoll@Sun.COM {
973*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_GET_CLUSTER_INFORMATION_INVALID_PARAMETERS,
974*12720SWyllys.Ingersoll@Sun.COM NULL,
975*12720SWyllys.Ingersoll@Sun.COM NULL,
976*12720SWyllys.Ingersoll@Sun.COM "EntitySiteIDSize arg");
977*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
978*12720SWyllys.Ingersoll@Sun.COM }
979*12720SWyllys.Ingersoll@Sun.COM
980*12720SWyllys.Ingersoll@Sun.COM if (i_iClusterEntryArraySize > KMS_MAX_CLUSTER_NUM)
981*12720SWyllys.Ingersoll@Sun.COM {
982*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_GET_CLUSTER_INFORMATION_INVALID_PARAMETERS,
983*12720SWyllys.Ingersoll@Sun.COM NULL,
984*12720SWyllys.Ingersoll@Sun.COM NULL,
985*12720SWyllys.Ingersoll@Sun.COM "i_iClusterEntryArraySize exceeds KMS_MAX_CLUSTER_NUM");
986*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
987*12720SWyllys.Ingersoll@Sun.COM }
988*12720SWyllys.Ingersoll@Sun.COM
989*12720SWyllys.Ingersoll@Sun.COM if (!o_pApplianceNum)
990*12720SWyllys.Ingersoll@Sun.COM {
991*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_GET_CLUSTER_INFORMATION_INVALID_PARAMETERS,
992*12720SWyllys.Ingersoll@Sun.COM NULL,
993*12720SWyllys.Ingersoll@Sun.COM NULL,
994*12720SWyllys.Ingersoll@Sun.COM "ApplianceNum arg");
995*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
996*12720SWyllys.Ingersoll@Sun.COM }
997*12720SWyllys.Ingersoll@Sun.COM
998*12720SWyllys.Ingersoll@Sun.COM if (!o_pClusterEntryArray ||
999*12720SWyllys.Ingersoll@Sun.COM (i_iClusterEntryArraySize <= 0))
1000*12720SWyllys.Ingersoll@Sun.COM {
1001*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_GET_CLUSTER_INFORMATION_INVALID_PARAMETERS,
1002*12720SWyllys.Ingersoll@Sun.COM NULL,
1003*12720SWyllys.Ingersoll@Sun.COM NULL,
1004*12720SWyllys.Ingersoll@Sun.COM "ClusterEntry or Size arg");
1005*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
1006*12720SWyllys.Ingersoll@Sun.COM }
1007*12720SWyllys.Ingersoll@Sun.COM
1008*12720SWyllys.Ingersoll@Sun.COM if (!KMSClient_ProfileLoaded(i_pProfile))
1009*12720SWyllys.Ingersoll@Sun.COM {
1010*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_PROFILE_NOT_LOADED);
1011*12720SWyllys.Ingersoll@Sun.COM }
1012*12720SWyllys.Ingersoll@Sun.COM
1013*12720SWyllys.Ingersoll@Sun.COM CAutoMutex oAutoMutex((K_MUTEX_HANDLE) i_pProfile->m_pLock);
1014*12720SWyllys.Ingersoll@Sun.COM
1015*12720SWyllys.Ingersoll@Sun.COM bSuccess = KMSClient_GetClusterInformation(
1016*12720SWyllys.Ingersoll@Sun.COM i_pProfile,
1017*12720SWyllys.Ingersoll@Sun.COM o_pEntitySiteID,
1018*12720SWyllys.Ingersoll@Sun.COM i_iEntitySiteIDSize,
1019*12720SWyllys.Ingersoll@Sun.COM o_pApplianceNum,
1020*12720SWyllys.Ingersoll@Sun.COM o_pClusterEntryArray,
1021*12720SWyllys.Ingersoll@Sun.COM i_iClusterEntryArraySize);
1022*12720SWyllys.Ingersoll@Sun.COM
1023*12720SWyllys.Ingersoll@Sun.COM // KMSClient_GetClusterInformation logs if there was an error
1024*12720SWyllys.Ingersoll@Sun.COM
1025*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
1026*12720SWyllys.Ingersoll@Sun.COM {
1027*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_OK);
1028*12720SWyllys.Ingersoll@Sun.COM }
1029*12720SWyllys.Ingersoll@Sun.COM
1030*12720SWyllys.Ingersoll@Sun.COM RETURN(KMSAgent_GetLastStatusCode(i_pProfile, 0));
1031*12720SWyllys.Ingersoll@Sun.COM }
1032*12720SWyllys.Ingersoll@Sun.COM
1033*12720SWyllys.Ingersoll@Sun.COM extern "C"
KMSAgent_SelectAppliance(KMSClientProfile * const i_pProfile,utf8cstr const i_pApplianceAddress)1034*12720SWyllys.Ingersoll@Sun.COM KMS_AGENT_STATUS KMSAgent_SelectAppliance (
1035*12720SWyllys.Ingersoll@Sun.COM KMSClientProfile * const i_pProfile,
1036*12720SWyllys.Ingersoll@Sun.COM utf8cstr const i_pApplianceAddress)
1037*12720SWyllys.Ingersoll@Sun.COM {
1038*12720SWyllys.Ingersoll@Sun.COM bool bSuccess;
1039*12720SWyllys.Ingersoll@Sun.COM #if defined(METAWARE)
1040*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
1041*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE(trace, KMSAgent_SelectAppliance);
1042*12720SWyllys.Ingersoll@Sun.COM #endif
1043*12720SWyllys.Ingersoll@Sun.COM
1044*12720SWyllys.Ingersoll@Sun.COM if (!i_pProfile)
1045*12720SWyllys.Ingersoll@Sun.COM {
1046*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_SELECT_APPLIANCE_INVALID_PARAMETERS,
1047*12720SWyllys.Ingersoll@Sun.COM NULL,
1048*12720SWyllys.Ingersoll@Sun.COM NULL,
1049*12720SWyllys.Ingersoll@Sun.COM "Profile arg");
1050*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
1051*12720SWyllys.Ingersoll@Sun.COM }
1052*12720SWyllys.Ingersoll@Sun.COM if (!i_pApplianceAddress)
1053*12720SWyllys.Ingersoll@Sun.COM {
1054*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_GET_CLUSTER_INFORMATION_INVALID_PARAMETERS,
1055*12720SWyllys.Ingersoll@Sun.COM NULL,
1056*12720SWyllys.Ingersoll@Sun.COM NULL,
1057*12720SWyllys.Ingersoll@Sun.COM "ApplianceAddress arg");
1058*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
1059*12720SWyllys.Ingersoll@Sun.COM }
1060*12720SWyllys.Ingersoll@Sun.COM
1061*12720SWyllys.Ingersoll@Sun.COM if (!KMSClient_ProfileLoaded(i_pProfile))
1062*12720SWyllys.Ingersoll@Sun.COM {
1063*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_PROFILE_NOT_LOADED);
1064*12720SWyllys.Ingersoll@Sun.COM }
1065*12720SWyllys.Ingersoll@Sun.COM
1066*12720SWyllys.Ingersoll@Sun.COM // All modes are supported by this function.
1067*12720SWyllys.Ingersoll@Sun.COM
1068*12720SWyllys.Ingersoll@Sun.COM bSuccess = KMSClient_SelectAppliance(i_pProfile, i_pApplianceAddress);
1069*12720SWyllys.Ingersoll@Sun.COM
1070*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
1071*12720SWyllys.Ingersoll@Sun.COM {
1072*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_OK);
1073*12720SWyllys.Ingersoll@Sun.COM }
1074*12720SWyllys.Ingersoll@Sun.COM
1075*12720SWyllys.Ingersoll@Sun.COM RETURN(KMSAgent_GetLastStatusCode(i_pProfile, 0));
1076*12720SWyllys.Ingersoll@Sun.COM }
1077*12720SWyllys.Ingersoll@Sun.COM
1078*12720SWyllys.Ingersoll@Sun.COM /*---------------------------------------------------------------------------
1079*12720SWyllys.Ingersoll@Sun.COM * Function: KMSAgent_LoadProfile
1080*12720SWyllys.Ingersoll@Sun.COM *
1081*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/
1082*12720SWyllys.Ingersoll@Sun.COM extern "C"
KMSAgent_LoadProfile(KMSClientProfile * const io_pProfile,utf8cstr const i_pProfileName,utf8cstr const i_pAgentID,utf8cstr const i_pPassphrase,utf8cstr const i_pInitialApplianceAddress,int i_iTransactionTimeout,int i_iFailOverLimit,int i_iClusterDiscoveryFrequency,int i_eKMSmode)1083*12720SWyllys.Ingersoll@Sun.COM KMS_AGENT_STATUS KMSAgent_LoadProfile (
1084*12720SWyllys.Ingersoll@Sun.COM KMSClientProfile * const io_pProfile,
1085*12720SWyllys.Ingersoll@Sun.COM utf8cstr const i_pProfileName,
1086*12720SWyllys.Ingersoll@Sun.COM utf8cstr const i_pAgentID,
1087*12720SWyllys.Ingersoll@Sun.COM utf8cstr const i_pPassphrase,
1088*12720SWyllys.Ingersoll@Sun.COM utf8cstr const i_pInitialApplianceAddress,
1089*12720SWyllys.Ingersoll@Sun.COM int i_iTransactionTimeout,
1090*12720SWyllys.Ingersoll@Sun.COM int i_iFailOverLimit,
1091*12720SWyllys.Ingersoll@Sun.COM int i_iClusterDiscoveryFrequency,
1092*12720SWyllys.Ingersoll@Sun.COM int i_eKMSmode)
1093*12720SWyllys.Ingersoll@Sun.COM {
1094*12720SWyllys.Ingersoll@Sun.COM bool bSuccess;
1095*12720SWyllys.Ingersoll@Sun.COM #if defined(METAWARE)
1096*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
1097*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE(trace, KMSAgent_LoadProfile);
1098*12720SWyllys.Ingersoll@Sun.COM #endif
1099*12720SWyllys.Ingersoll@Sun.COM
1100*12720SWyllys.Ingersoll@Sun.COM #if defined(DEBUG) && defined(METAWARE)
1101*12720SWyllys.Ingersoll@Sun.COM log_printf("KMSAgent_LoadProfile : Entered");
1102*12720SWyllys.Ingersoll@Sun.COM #endif
1103*12720SWyllys.Ingersoll@Sun.COM if (!io_pProfile ||
1104*12720SWyllys.Ingersoll@Sun.COM !i_pProfileName || (strlen(i_pProfileName) <= 0))
1105*12720SWyllys.Ingersoll@Sun.COM {
1106*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_LOAD_PROFILE_INVALID_PARAMETERS,
1107*12720SWyllys.Ingersoll@Sun.COM NULL,
1108*12720SWyllys.Ingersoll@Sun.COM NULL,
1109*12720SWyllys.Ingersoll@Sun.COM "Profile or Name arg");
1110*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
1111*12720SWyllys.Ingersoll@Sun.COM }
1112*12720SWyllys.Ingersoll@Sun.COM if (!i_pInitialApplianceAddress || (strlen(i_pInitialApplianceAddress) <= 0))
1113*12720SWyllys.Ingersoll@Sun.COM {
1114*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_LOAD_PROFILE_INVALID_PARAMETERS,
1115*12720SWyllys.Ingersoll@Sun.COM NULL,
1116*12720SWyllys.Ingersoll@Sun.COM NULL,
1117*12720SWyllys.Ingersoll@Sun.COM "InitialApplianceAddress arg");
1118*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
1119*12720SWyllys.Ingersoll@Sun.COM }
1120*12720SWyllys.Ingersoll@Sun.COM
1121*12720SWyllys.Ingersoll@Sun.COM if (i_iTransactionTimeout <= 0)
1122*12720SWyllys.Ingersoll@Sun.COM {
1123*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_LOAD_PROFILE_INVALID_PARAMETERS,
1124*12720SWyllys.Ingersoll@Sun.COM NULL,
1125*12720SWyllys.Ingersoll@Sun.COM NULL,
1126*12720SWyllys.Ingersoll@Sun.COM "TransactionTimeout arg");
1127*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
1128*12720SWyllys.Ingersoll@Sun.COM }
1129*12720SWyllys.Ingersoll@Sun.COM if (i_iClusterDiscoveryFrequency < 0)
1130*12720SWyllys.Ingersoll@Sun.COM {
1131*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_LOAD_PROFILE_INVALID_PARAMETERS,
1132*12720SWyllys.Ingersoll@Sun.COM NULL,
1133*12720SWyllys.Ingersoll@Sun.COM NULL,
1134*12720SWyllys.Ingersoll@Sun.COM "ClusterDiscoveryFrequency arg");
1135*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
1136*12720SWyllys.Ingersoll@Sun.COM }
1137*12720SWyllys.Ingersoll@Sun.COM
1138*12720SWyllys.Ingersoll@Sun.COM // for enrollment both arguments are required
1139*12720SWyllys.Ingersoll@Sun.COM if ((i_pAgentID && !i_pPassphrase) || (i_pPassphrase && !i_pAgentID))
1140*12720SWyllys.Ingersoll@Sun.COM {
1141*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_LOAD_PROFILE_INVALID_PARAMETERS,
1142*12720SWyllys.Ingersoll@Sun.COM NULL,
1143*12720SWyllys.Ingersoll@Sun.COM NULL,
1144*12720SWyllys.Ingersoll@Sun.COM "Enrollment requires AgentID & Passphrase");
1145*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
1146*12720SWyllys.Ingersoll@Sun.COM }
1147*12720SWyllys.Ingersoll@Sun.COM
1148*12720SWyllys.Ingersoll@Sun.COM if (i_pAgentID && (strlen(i_pAgentID) <= 0))
1149*12720SWyllys.Ingersoll@Sun.COM {
1150*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_LOAD_PROFILE_INVALID_PARAMETERS,
1151*12720SWyllys.Ingersoll@Sun.COM NULL,
1152*12720SWyllys.Ingersoll@Sun.COM NULL,
1153*12720SWyllys.Ingersoll@Sun.COM "AgentID arg");
1154*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
1155*12720SWyllys.Ingersoll@Sun.COM }
1156*12720SWyllys.Ingersoll@Sun.COM
1157*12720SWyllys.Ingersoll@Sun.COM if (i_pPassphrase && (strlen(i_pPassphrase) <= 0))
1158*12720SWyllys.Ingersoll@Sun.COM {
1159*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_LOAD_PROFILE_INVALID_PARAMETERS,
1160*12720SWyllys.Ingersoll@Sun.COM NULL,
1161*12720SWyllys.Ingersoll@Sun.COM NULL,
1162*12720SWyllys.Ingersoll@Sun.COM "Passphrase arg");
1163*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
1164*12720SWyllys.Ingersoll@Sun.COM }
1165*12720SWyllys.Ingersoll@Sun.COM
1166*12720SWyllys.Ingersoll@Sun.COM if ( i_eKMSmode != DEFAULT_MODE && i_eKMSmode != FIPS_MODE )
1167*12720SWyllys.Ingersoll@Sun.COM {
1168*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_LOAD_PROFILE_INVALID_PARAMETERS,
1169*12720SWyllys.Ingersoll@Sun.COM NULL,
1170*12720SWyllys.Ingersoll@Sun.COM NULL,
1171*12720SWyllys.Ingersoll@Sun.COM "KMS security mode arg");
1172*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
1173*12720SWyllys.Ingersoll@Sun.COM }
1174*12720SWyllys.Ingersoll@Sun.COM
1175*12720SWyllys.Ingersoll@Sun.COM if (KMSClient_ProfileLoaded(io_pProfile))
1176*12720SWyllys.Ingersoll@Sun.COM {
1177*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_LOAD_PROFILE_PROFILE_ALREADY_LOADED,
1178*12720SWyllys.Ingersoll@Sun.COM NULL,
1179*12720SWyllys.Ingersoll@Sun.COM NULL,
1180*12720SWyllys.Ingersoll@Sun.COM "profile is already loaded and should be unloaded first");
1181*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_PROFILE_ALREADY_LOADED);
1182*12720SWyllys.Ingersoll@Sun.COM }
1183*12720SWyllys.Ingersoll@Sun.COM
1184*12720SWyllys.Ingersoll@Sun.COM memset(io_pProfile, 0, sizeof (KMSClientProfile));
1185*12720SWyllys.Ingersoll@Sun.COM char sInitialApplianceAddress[KMS_MAX_NETWORK_ADDRESS+1];
1186*12720SWyllys.Ingersoll@Sun.COM strncpy(sInitialApplianceAddress, i_pInitialApplianceAddress, sizeof(sInitialApplianceAddress));
1187*12720SWyllys.Ingersoll@Sun.COM sInitialApplianceAddress[sizeof(sInitialApplianceAddress)-1] = '\0';
1188*12720SWyllys.Ingersoll@Sun.COM
1189*12720SWyllys.Ingersoll@Sun.COM // Convert to lower case
1190*12720SWyllys.Ingersoll@Sun.COM
1191*12720SWyllys.Ingersoll@Sun.COM for ( size_t i = 0; i < strlen( sInitialApplianceAddress ); i++ )
1192*12720SWyllys.Ingersoll@Sun.COM {
1193*12720SWyllys.Ingersoll@Sun.COM if ( isupper( sInitialApplianceAddress[i] ) )
1194*12720SWyllys.Ingersoll@Sun.COM {
1195*12720SWyllys.Ingersoll@Sun.COM sInitialApplianceAddress[i] = tolower( sInitialApplianceAddress[i] );
1196*12720SWyllys.Ingersoll@Sun.COM }
1197*12720SWyllys.Ingersoll@Sun.COM }
1198*12720SWyllys.Ingersoll@Sun.COM
1199*12720SWyllys.Ingersoll@Sun.COM bSuccess = KMSClient_LoadProfile(
1200*12720SWyllys.Ingersoll@Sun.COM io_pProfile,
1201*12720SWyllys.Ingersoll@Sun.COM i_pProfileName,
1202*12720SWyllys.Ingersoll@Sun.COM i_pAgentID,
1203*12720SWyllys.Ingersoll@Sun.COM i_pPassphrase,
1204*12720SWyllys.Ingersoll@Sun.COM sInitialApplianceAddress,
1205*12720SWyllys.Ingersoll@Sun.COM i_iTransactionTimeout,
1206*12720SWyllys.Ingersoll@Sun.COM i_iFailOverLimit,
1207*12720SWyllys.Ingersoll@Sun.COM i_iClusterDiscoveryFrequency,
1208*12720SWyllys.Ingersoll@Sun.COM i_eKMSmode);
1209*12720SWyllys.Ingersoll@Sun.COM
1210*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
1211*12720SWyllys.Ingersoll@Sun.COM {
1212*12720SWyllys.Ingersoll@Sun.COM #if defined(DEBUG) && defined(METAWARE)
1213*12720SWyllys.Ingersoll@Sun.COM log_printf("KMSAgent_LoadProfile : Returned ok");
1214*12720SWyllys.Ingersoll@Sun.COM #endif
1215*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_OK);
1216*12720SWyllys.Ingersoll@Sun.COM }
1217*12720SWyllys.Ingersoll@Sun.COM
1218*12720SWyllys.Ingersoll@Sun.COM // when not enrolling & cluster discovery is disabled there are no
1219*12720SWyllys.Ingersoll@Sun.COM // soap transactions so failover would not have occurred
1220*12720SWyllys.Ingersoll@Sun.COM bool bEnrolling = i_pAgentID && i_pPassphrase;
1221*12720SWyllys.Ingersoll@Sun.COM
1222*12720SWyllys.Ingersoll@Sun.COM if (!bEnrolling &&
1223*12720SWyllys.Ingersoll@Sun.COM i_iClusterDiscoveryFrequency == 0)
1224*12720SWyllys.Ingersoll@Sun.COM {
1225*12720SWyllys.Ingersoll@Sun.COM RETURN(KMSAgent_GetLastStatusCode(io_pProfile, 0));
1226*12720SWyllys.Ingersoll@Sun.COM }
1227*12720SWyllys.Ingersoll@Sun.COM else
1228*12720SWyllys.Ingersoll@Sun.COM {
1229*12720SWyllys.Ingersoll@Sun.COM // if (i_eKMSmode == FIPS_MODE &&
1230*12720SWyllys.Ingersoll@Sun.COM // KMSClient_NoFIPSCompatibleKMAs(io_pProfile))
1231*12720SWyllys.Ingersoll@Sun.COM // {
1232*12720SWyllys.Ingersoll@Sun.COM // RETURN(KMSAgent_GetLastStatusCode(io_pProfile,
1233*12720SWyllys.Ingersoll@Sun.COM // CAgentLoadBalancer::NO_FIPS_KMA_AVAILABLE));
1234*12720SWyllys.Ingersoll@Sun.COM // }
1235*12720SWyllys.Ingersoll@Sun.COM
1236*12720SWyllys.Ingersoll@Sun.COM RETURN(KMSAgent_GetLastStatusCode(io_pProfile,
1237*12720SWyllys.Ingersoll@Sun.COM CAgentLoadBalancer::NO_KMA_AVAILABLE));
1238*12720SWyllys.Ingersoll@Sun.COM }
1239*12720SWyllys.Ingersoll@Sun.COM }
1240*12720SWyllys.Ingersoll@Sun.COM
1241*12720SWyllys.Ingersoll@Sun.COM /*---------------------------------------------------------------------------
1242*12720SWyllys.Ingersoll@Sun.COM * Function: KMSAgent_UnloadProfile
1243*12720SWyllys.Ingersoll@Sun.COM *
1244*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/
1245*12720SWyllys.Ingersoll@Sun.COM extern "C"
KMSAgent_UnloadProfile(KMSClientProfile * const i_pProfile)1246*12720SWyllys.Ingersoll@Sun.COM KMS_AGENT_STATUS KMSAgent_UnloadProfile (KMSClientProfile * const i_pProfile)
1247*12720SWyllys.Ingersoll@Sun.COM {
1248*12720SWyllys.Ingersoll@Sun.COM bool bSuccess;
1249*12720SWyllys.Ingersoll@Sun.COM #if defined(METAWARE)
1250*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
1251*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE(trace, KMSAgent_UnloadProfile);
1252*12720SWyllys.Ingersoll@Sun.COM #endif
1253*12720SWyllys.Ingersoll@Sun.COM
1254*12720SWyllys.Ingersoll@Sun.COM if (!i_pProfile)
1255*12720SWyllys.Ingersoll@Sun.COM {
1256*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_UNLOAD_PROFILE_INVALID_PARAMETERS,
1257*12720SWyllys.Ingersoll@Sun.COM NULL,
1258*12720SWyllys.Ingersoll@Sun.COM NULL,
1259*12720SWyllys.Ingersoll@Sun.COM "Profile arg");
1260*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
1261*12720SWyllys.Ingersoll@Sun.COM }
1262*12720SWyllys.Ingersoll@Sun.COM
1263*12720SWyllys.Ingersoll@Sun.COM if (!KMSClient_ProfileLoaded(i_pProfile))
1264*12720SWyllys.Ingersoll@Sun.COM {
1265*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_PROFILE_NOT_LOADED);
1266*12720SWyllys.Ingersoll@Sun.COM }
1267*12720SWyllys.Ingersoll@Sun.COM
1268*12720SWyllys.Ingersoll@Sun.COM bSuccess = KMSClient_UnloadProfile(i_pProfile);
1269*12720SWyllys.Ingersoll@Sun.COM
1270*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
1271*12720SWyllys.Ingersoll@Sun.COM {
1272*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_OK);
1273*12720SWyllys.Ingersoll@Sun.COM }
1274*12720SWyllys.Ingersoll@Sun.COM
1275*12720SWyllys.Ingersoll@Sun.COM RETURN(KMSAgent_GetLastStatusCode(i_pProfile, 0));
1276*12720SWyllys.Ingersoll@Sun.COM }
1277*12720SWyllys.Ingersoll@Sun.COM
1278*12720SWyllys.Ingersoll@Sun.COM /*---------------------------------------------------------------------------
1279*12720SWyllys.Ingersoll@Sun.COM * Function: KMSAgent_DeleteProfile
1280*12720SWyllys.Ingersoll@Sun.COM *
1281*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/
1282*12720SWyllys.Ingersoll@Sun.COM extern "C"
KMSAgent_DeleteProfile(utf8cstr i_pProfileName)1283*12720SWyllys.Ingersoll@Sun.COM KMS_AGENT_STATUS KMSAgent_DeleteProfile (utf8cstr i_pProfileName)
1284*12720SWyllys.Ingersoll@Sun.COM {
1285*12720SWyllys.Ingersoll@Sun.COM bool bSuccess;
1286*12720SWyllys.Ingersoll@Sun.COM #if defined(METAWARE)
1287*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
1288*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE(trace, KMSAgent_DeleteProfile);
1289*12720SWyllys.Ingersoll@Sun.COM #endif
1290*12720SWyllys.Ingersoll@Sun.COM
1291*12720SWyllys.Ingersoll@Sun.COM if (!i_pProfileName || (strlen(i_pProfileName) <= 0))
1292*12720SWyllys.Ingersoll@Sun.COM {
1293*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
1294*12720SWyllys.Ingersoll@Sun.COM }
1295*12720SWyllys.Ingersoll@Sun.COM
1296*12720SWyllys.Ingersoll@Sun.COM bSuccess = KMSClient_DeleteProfile(i_pProfileName);
1297*12720SWyllys.Ingersoll@Sun.COM
1298*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
1299*12720SWyllys.Ingersoll@Sun.COM {
1300*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_OK);
1301*12720SWyllys.Ingersoll@Sun.COM }
1302*12720SWyllys.Ingersoll@Sun.COM
1303*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_GENERIC_ERROR);
1304*12720SWyllys.Ingersoll@Sun.COM }
1305*12720SWyllys.Ingersoll@Sun.COM
1306*12720SWyllys.Ingersoll@Sun.COM /*---------------------------------------------------------------------------
1307*12720SWyllys.Ingersoll@Sun.COM * Function: KMSAgent_ListKeyGroups
1308*12720SWyllys.Ingersoll@Sun.COM *
1309*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/
1310*12720SWyllys.Ingersoll@Sun.COM
1311*12720SWyllys.Ingersoll@Sun.COM extern "C"
KMSAgent_ListKeyGroups(KMSClientProfile * const i_pProfile,KMSAgent_ArrayOfKeyGroups ** const o_ppKeyGroups)1312*12720SWyllys.Ingersoll@Sun.COM KMS_AGENT_STATUS KMSAgent_ListKeyGroups (
1313*12720SWyllys.Ingersoll@Sun.COM KMSClientProfile * const i_pProfile,
1314*12720SWyllys.Ingersoll@Sun.COM KMSAgent_ArrayOfKeyGroups* * const o_ppKeyGroups)
1315*12720SWyllys.Ingersoll@Sun.COM {
1316*12720SWyllys.Ingersoll@Sun.COM bool bSuccess;
1317*12720SWyllys.Ingersoll@Sun.COM #if defined(METAWARE)
1318*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
1319*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE(trace, KMSAgent_ListKeyGroups);
1320*12720SWyllys.Ingersoll@Sun.COM #endif
1321*12720SWyllys.Ingersoll@Sun.COM
1322*12720SWyllys.Ingersoll@Sun.COM int bIsLastPage;
1323*12720SWyllys.Ingersoll@Sun.COM struct KMSAgent_QueryParameters stQueryParameters;
1324*12720SWyllys.Ingersoll@Sun.COM
1325*12720SWyllys.Ingersoll@Sun.COM if (!i_pProfile)
1326*12720SWyllys.Ingersoll@Sun.COM {
1327*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_LIST_KEY_GROUPS_INVALID_PARAMETERS,
1328*12720SWyllys.Ingersoll@Sun.COM NULL,
1329*12720SWyllys.Ingersoll@Sun.COM NULL,
1330*12720SWyllys.Ingersoll@Sun.COM "Profile arg");
1331*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
1332*12720SWyllys.Ingersoll@Sun.COM }
1333*12720SWyllys.Ingersoll@Sun.COM if (!o_ppKeyGroups)
1334*12720SWyllys.Ingersoll@Sun.COM {
1335*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_LIST_KEY_GROUPS_INVALID_PARAMETERS,
1336*12720SWyllys.Ingersoll@Sun.COM NULL,
1337*12720SWyllys.Ingersoll@Sun.COM NULL,
1338*12720SWyllys.Ingersoll@Sun.COM "KeyGroups arg");
1339*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
1340*12720SWyllys.Ingersoll@Sun.COM }
1341*12720SWyllys.Ingersoll@Sun.COM
1342*12720SWyllys.Ingersoll@Sun.COM if (!KMSClient_ProfileLoaded(i_pProfile))
1343*12720SWyllys.Ingersoll@Sun.COM {
1344*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_PROFILE_NOT_LOADED);
1345*12720SWyllys.Ingersoll@Sun.COM }
1346*12720SWyllys.Ingersoll@Sun.COM
1347*12720SWyllys.Ingersoll@Sun.COM CAutoMutex oAutoMutex((K_MUTEX_HANDLE) i_pProfile->m_pLock);
1348*12720SWyllys.Ingersoll@Sun.COM
1349*12720SWyllys.Ingersoll@Sun.COM struct soap *pstSoap = (struct soap *) i_pProfile->m_pvSoap;
1350*12720SWyllys.Ingersoll@Sun.COM
1351*12720SWyllys.Ingersoll@Sun.COM // Get Key Groups
1352*12720SWyllys.Ingersoll@Sun.COM memset(&stQueryParameters, 0, sizeof (stQueryParameters));
1353*12720SWyllys.Ingersoll@Sun.COM
1354*12720SWyllys.Ingersoll@Sun.COM struct KMS_Agent::KMS_Agent__QueryParameters oQueryParameters;
1355*12720SWyllys.Ingersoll@Sun.COM struct KMS_Agent::KMS_Agent__ListKeyGroupsResponse oResponse;
1356*12720SWyllys.Ingersoll@Sun.COM
1357*12720SWyllys.Ingersoll@Sun.COM memset(&oQueryParameters, 0, sizeof (oQueryParameters));
1358*12720SWyllys.Ingersoll@Sun.COM
1359*12720SWyllys.Ingersoll@Sun.COM bSuccess = CopyQueryParametersFromRequest(pstSoap,
1360*12720SWyllys.Ingersoll@Sun.COM KMS_MAX_LIST_KEY_GROUPS,
1361*12720SWyllys.Ingersoll@Sun.COM &oQueryParameters,
1362*12720SWyllys.Ingersoll@Sun.COM &stQueryParameters);
1363*12720SWyllys.Ingersoll@Sun.COM if (!bSuccess)
1364*12720SWyllys.Ingersoll@Sun.COM {
1365*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
1366*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
1367*12720SWyllys.Ingersoll@Sun.COM // no memory, don't log
1368*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_NO_MEMORY);
1369*12720SWyllys.Ingersoll@Sun.COM }
1370*12720SWyllys.Ingersoll@Sun.COM
1371*12720SWyllys.Ingersoll@Sun.COM CAgentLoadBalancer *pLoadBalancer =
1372*12720SWyllys.Ingersoll@Sun.COM (CAgentLoadBalancer *) i_pProfile->m_pAgentLoadBalancer;
1373*12720SWyllys.Ingersoll@Sun.COM
1374*12720SWyllys.Ingersoll@Sun.COM int iIndex = pLoadBalancer->Balance();
1375*12720SWyllys.Ingersoll@Sun.COM
1376*12720SWyllys.Ingersoll@Sun.COM if ( iIndex >= 0 )
1377*12720SWyllys.Ingersoll@Sun.COM {
1378*12720SWyllys.Ingersoll@Sun.COM do
1379*12720SWyllys.Ingersoll@Sun.COM {
1380*12720SWyllys.Ingersoll@Sun.COM const char* sURL =
1381*12720SWyllys.Ingersoll@Sun.COM pLoadBalancer->GetHTTPSURL(iIndex, i_pProfile->m_iPortForAgentService);
1382*12720SWyllys.Ingersoll@Sun.COM strncpy(i_pProfile->m_sURL, sURL, sizeof(i_pProfile->m_sURL));
1383*12720SWyllys.Ingersoll@Sun.COM i_pProfile->m_sURL[sizeof(i_pProfile->m_sURL)-1] = '\0';
1384*12720SWyllys.Ingersoll@Sun.COM
1385*12720SWyllys.Ingersoll@Sun.COM bSuccess = KMS_Agent::soap_call_KMS_Agent__ListKeyGroups(
1386*12720SWyllys.Ingersoll@Sun.COM pstSoap,
1387*12720SWyllys.Ingersoll@Sun.COM sURL,
1388*12720SWyllys.Ingersoll@Sun.COM NULL,
1389*12720SWyllys.Ingersoll@Sun.COM oQueryParameters,
1390*12720SWyllys.Ingersoll@Sun.COM oResponse) == SOAP_OK;
1391*12720SWyllys.Ingersoll@Sun.COM
1392*12720SWyllys.Ingersoll@Sun.COM if (!bSuccess)
1393*12720SWyllys.Ingersoll@Sun.COM {
1394*12720SWyllys.Ingersoll@Sun.COM iIndex = pLoadBalancer->FailOver(iIndex, pstSoap);
1395*12720SWyllys.Ingersoll@Sun.COM
1396*12720SWyllys.Ingersoll@Sun.COM char sKmaAddress[g_iMAX_PEER_NETWORK_ADDRESS_LENGTH];
1397*12720SWyllys.Ingersoll@Sun.COM char sSoapFaultMsg[g_iMAX_SOAP_FAULT_MESSAGE_LENGTH];
1398*12720SWyllys.Ingersoll@Sun.COM
1399*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
1400*12720SWyllys.Ingersoll@Sun.COM GetSoapFault(sSoapFaultMsg, pstSoap);
1401*12720SWyllys.Ingersoll@Sun.COM
1402*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile, AUDIT_CLIENT_AGENT_LIST_KEY_GROUPS_SOAP_ERROR,
1403*12720SWyllys.Ingersoll@Sun.COM NULL,
1404*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
1405*12720SWyllys.Ingersoll@Sun.COM sSoapFaultMsg);
1406*12720SWyllys.Ingersoll@Sun.COM }
1407*12720SWyllys.Ingersoll@Sun.COM else
1408*12720SWyllys.Ingersoll@Sun.COM {
1409*12720SWyllys.Ingersoll@Sun.COM pLoadBalancer->UpdateResponseStatus(iIndex);
1410*12720SWyllys.Ingersoll@Sun.COM }
1411*12720SWyllys.Ingersoll@Sun.COM }
1412*12720SWyllys.Ingersoll@Sun.COM while (iIndex >= 0 && (!bSuccess));
1413*12720SWyllys.Ingersoll@Sun.COM }
1414*12720SWyllys.Ingersoll@Sun.COM else
1415*12720SWyllys.Ingersoll@Sun.COM {
1416*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
1417*12720SWyllys.Ingersoll@Sun.COM }
1418*12720SWyllys.Ingersoll@Sun.COM
1419*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
1420*12720SWyllys.Ingersoll@Sun.COM {
1421*12720SWyllys.Ingersoll@Sun.COM bIsLastPage = oResponse.LastPage;
1422*12720SWyllys.Ingersoll@Sun.COM
1423*12720SWyllys.Ingersoll@Sun.COM *o_ppKeyGroups = CopyKeyGroupsResponse(&oResponse.KeyGroups);
1424*12720SWyllys.Ingersoll@Sun.COM if (*o_ppKeyGroups == NULL)
1425*12720SWyllys.Ingersoll@Sun.COM {
1426*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
1427*12720SWyllys.Ingersoll@Sun.COM // no memory, don't log
1428*12720SWyllys.Ingersoll@Sun.COM }
1429*12720SWyllys.Ingersoll@Sun.COM
1430*12720SWyllys.Ingersoll@Sun.COM CopyQueryParametersFromResponse(&stQueryParameters,
1431*12720SWyllys.Ingersoll@Sun.COM &oResponse.NextPageQueryParameters);
1432*12720SWyllys.Ingersoll@Sun.COM }
1433*12720SWyllys.Ingersoll@Sun.COM
1434*12720SWyllys.Ingersoll@Sun.COM // free allocated memory for output if error condition
1435*12720SWyllys.Ingersoll@Sun.COM // Clean up SOAP
1436*12720SWyllys.Ingersoll@Sun.COM
1437*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
1438*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
1439*12720SWyllys.Ingersoll@Sun.COM
1440*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
1441*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_OK);
1442*12720SWyllys.Ingersoll@Sun.COM
1443*12720SWyllys.Ingersoll@Sun.COM RETURN(KMSAgent_GetLastStatusCode(i_pProfile, iIndex));
1444*12720SWyllys.Ingersoll@Sun.COM }
1445*12720SWyllys.Ingersoll@Sun.COM
1446*12720SWyllys.Ingersoll@Sun.COM /*---------------------------------------------------------------------------
1447*12720SWyllys.Ingersoll@Sun.COM * Function: KMSAgent_FreeArrayOfKeyGroups
1448*12720SWyllys.Ingersoll@Sun.COM *
1449*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/
1450*12720SWyllys.Ingersoll@Sun.COM
1451*12720SWyllys.Ingersoll@Sun.COM extern "C"
KMSAgent_FreeArrayOfKeyGroups(struct KMSAgent_ArrayOfKeyGroups * i_pArrayOfKeyGroups)1452*12720SWyllys.Ingersoll@Sun.COM void KMSAgent_FreeArrayOfKeyGroups (
1453*12720SWyllys.Ingersoll@Sun.COM struct KMSAgent_ArrayOfKeyGroups *i_pArrayOfKeyGroups)
1454*12720SWyllys.Ingersoll@Sun.COM {
1455*12720SWyllys.Ingersoll@Sun.COM #if defined(METAWARE)
1456*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
1457*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE(trace, KMSAgent_FreeArrayOfKeyGroups);
1458*12720SWyllys.Ingersoll@Sun.COM #endif
1459*12720SWyllys.Ingersoll@Sun.COM if (!i_pArrayOfKeyGroups)
1460*12720SWyllys.Ingersoll@Sun.COM {
1461*12720SWyllys.Ingersoll@Sun.COM return;
1462*12720SWyllys.Ingersoll@Sun.COM }
1463*12720SWyllys.Ingersoll@Sun.COM
1464*12720SWyllys.Ingersoll@Sun.COM // free memory for all information groups
1465*12720SWyllys.Ingersoll@Sun.COM if (i_pArrayOfKeyGroups->m_pKeyGroups)
1466*12720SWyllys.Ingersoll@Sun.COM {
1467*12720SWyllys.Ingersoll@Sun.COM free(i_pArrayOfKeyGroups->m_pKeyGroups);
1468*12720SWyllys.Ingersoll@Sun.COM }
1469*12720SWyllys.Ingersoll@Sun.COM
1470*12720SWyllys.Ingersoll@Sun.COM free(i_pArrayOfKeyGroups);
1471*12720SWyllys.Ingersoll@Sun.COM }
1472*12720SWyllys.Ingersoll@Sun.COM
1473*12720SWyllys.Ingersoll@Sun.COM extern "C"
KMSAgent_CreateKey(KMSClientProfile * const i_pProfile,const KMSAgent_DataUnit * const i_pDataUnit,KEY_GROUP_ID const i_pKeyGroupID,KMSAgent_Key * const o_pKey)1474*12720SWyllys.Ingersoll@Sun.COM KMS_AGENT_STATUS KMSAgent_CreateKey (
1475*12720SWyllys.Ingersoll@Sun.COM KMSClientProfile * const i_pProfile,
1476*12720SWyllys.Ingersoll@Sun.COM const KMSAgent_DataUnit * const i_pDataUnit,
1477*12720SWyllys.Ingersoll@Sun.COM KEY_GROUP_ID const i_pKeyGroupID,
1478*12720SWyllys.Ingersoll@Sun.COM KMSAgent_Key * const o_pKey)
1479*12720SWyllys.Ingersoll@Sun.COM {
1480*12720SWyllys.Ingersoll@Sun.COM bool bSuccess;
1481*12720SWyllys.Ingersoll@Sun.COM #if defined(METAWARE)
1482*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
1483*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE(trace, KMSAgent_CreateKey);
1484*12720SWyllys.Ingersoll@Sun.COM #endif
1485*12720SWyllys.Ingersoll@Sun.COM
1486*12720SWyllys.Ingersoll@Sun.COM if (!i_pProfile)
1487*12720SWyllys.Ingersoll@Sun.COM {
1488*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_CREATE_KEY_INVALID_PARAMETERS,
1489*12720SWyllys.Ingersoll@Sun.COM NULL,
1490*12720SWyllys.Ingersoll@Sun.COM NULL,
1491*12720SWyllys.Ingersoll@Sun.COM "Profile arg");
1492*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
1493*12720SWyllys.Ingersoll@Sun.COM }
1494*12720SWyllys.Ingersoll@Sun.COM if (!o_pKey)
1495*12720SWyllys.Ingersoll@Sun.COM {
1496*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_CREATE_KEY_INVALID_PARAMETERS,
1497*12720SWyllys.Ingersoll@Sun.COM NULL,
1498*12720SWyllys.Ingersoll@Sun.COM NULL,
1499*12720SWyllys.Ingersoll@Sun.COM "Key arg");
1500*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
1501*12720SWyllys.Ingersoll@Sun.COM }
1502*12720SWyllys.Ingersoll@Sun.COM
1503*12720SWyllys.Ingersoll@Sun.COM if (!KMSClient_ProfileLoaded(i_pProfile))
1504*12720SWyllys.Ingersoll@Sun.COM {
1505*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_PROFILE_NOT_LOADED);
1506*12720SWyllys.Ingersoll@Sun.COM }
1507*12720SWyllys.Ingersoll@Sun.COM
1508*12720SWyllys.Ingersoll@Sun.COM if (i_pKeyGroupID &&
1509*12720SWyllys.Ingersoll@Sun.COM strlen(i_pKeyGroupID) > KMS_MAX_KEY_GROUP_ID_SIZE)
1510*12720SWyllys.Ingersoll@Sun.COM {
1511*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_CREATE_KEY_INVALID_PARAMETERS,
1512*12720SWyllys.Ingersoll@Sun.COM NULL,
1513*12720SWyllys.Ingersoll@Sun.COM NULL,
1514*12720SWyllys.Ingersoll@Sun.COM "GroupID arg");
1515*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
1516*12720SWyllys.Ingersoll@Sun.COM }
1517*12720SWyllys.Ingersoll@Sun.COM
1518*12720SWyllys.Ingersoll@Sun.COM CAutoMutex oAutoMutex((K_MUTEX_HANDLE) i_pProfile->m_pLock);
1519*12720SWyllys.Ingersoll@Sun.COM
1520*12720SWyllys.Ingersoll@Sun.COM struct KMS_Agent::KMS_Agent__DataUnit
1521*12720SWyllys.Ingersoll@Sun.COM stDataUnit = {"", "", "", "",
1522*12720SWyllys.Ingersoll@Sun.COM (KMS_Agent::KMS_Agent__DataUnitState) 0};
1523*12720SWyllys.Ingersoll@Sun.COM
1524*12720SWyllys.Ingersoll@Sun.COM struct soap *pstSoap = (struct soap *) i_pProfile->m_pvSoap;
1525*12720SWyllys.Ingersoll@Sun.COM struct KMS_Agent::KMS_Agent__CreateKeyResponse oResponse;
1526*12720SWyllys.Ingersoll@Sun.COM
1527*12720SWyllys.Ingersoll@Sun.COM if (i_pDataUnit != NULL)
1528*12720SWyllys.Ingersoll@Sun.COM {
1529*12720SWyllys.Ingersoll@Sun.COM if (!CopyDataUnitFromRequest(pstSoap,
1530*12720SWyllys.Ingersoll@Sun.COM &stDataUnit,
1531*12720SWyllys.Ingersoll@Sun.COM i_pDataUnit))
1532*12720SWyllys.Ingersoll@Sun.COM {
1533*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
1534*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
1535*12720SWyllys.Ingersoll@Sun.COM // no memory dont' log
1536*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_NO_MEMORY);
1537*12720SWyllys.Ingersoll@Sun.COM }
1538*12720SWyllys.Ingersoll@Sun.COM }
1539*12720SWyllys.Ingersoll@Sun.COM
1540*12720SWyllys.Ingersoll@Sun.COM char * pKeyGroupID = NULL;
1541*12720SWyllys.Ingersoll@Sun.COM if (i_pKeyGroupID)
1542*12720SWyllys.Ingersoll@Sun.COM {
1543*12720SWyllys.Ingersoll@Sun.COM pKeyGroupID = ConvertUTF8StringFromRequest(pstSoap,
1544*12720SWyllys.Ingersoll@Sun.COM i_pKeyGroupID,
1545*12720SWyllys.Ingersoll@Sun.COM KMS_MAX_KEY_GROUP_ID_SIZE + 1);
1546*12720SWyllys.Ingersoll@Sun.COM if (pKeyGroupID == NULL)
1547*12720SWyllys.Ingersoll@Sun.COM {
1548*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
1549*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
1550*12720SWyllys.Ingersoll@Sun.COM // no memory dont' log
1551*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_NO_MEMORY);
1552*12720SWyllys.Ingersoll@Sun.COM }
1553*12720SWyllys.Ingersoll@Sun.COM }
1554*12720SWyllys.Ingersoll@Sun.COM
1555*12720SWyllys.Ingersoll@Sun.COM CAgentLoadBalancer *pLoadBalancer =
1556*12720SWyllys.Ingersoll@Sun.COM (CAgentLoadBalancer *) i_pProfile->m_pAgentLoadBalancer;
1557*12720SWyllys.Ingersoll@Sun.COM
1558*12720SWyllys.Ingersoll@Sun.COM char sKmaAddress[g_iMAX_PEER_NETWORK_ADDRESS_LENGTH];
1559*12720SWyllys.Ingersoll@Sun.COM char sSoapFaultMsg[g_iMAX_SOAP_FAULT_MESSAGE_LENGTH];
1560*12720SWyllys.Ingersoll@Sun.COM
1561*12720SWyllys.Ingersoll@Sun.COM int iIndex;
1562*12720SWyllys.Ingersoll@Sun.COM UTF8_KEYID acKWKID;
1563*12720SWyllys.Ingersoll@Sun.COM bool bClientAESKeyWrapSetupError = false;
1564*12720SWyllys.Ingersoll@Sun.COM
1565*12720SWyllys.Ingersoll@Sun.COM if (i_pDataUnit)
1566*12720SWyllys.Ingersoll@Sun.COM {
1567*12720SWyllys.Ingersoll@Sun.COM // attempt to maintain affinity with KMA for specified DU ID
1568*12720SWyllys.Ingersoll@Sun.COM iIndex = pLoadBalancer->BalanceByDataUnitID(
1569*12720SWyllys.Ingersoll@Sun.COM i_pDataUnit->m_acDataUnitID,
1570*12720SWyllys.Ingersoll@Sun.COM KMS_DATA_UNIT_ID_SIZE);
1571*12720SWyllys.Ingersoll@Sun.COM }
1572*12720SWyllys.Ingersoll@Sun.COM else
1573*12720SWyllys.Ingersoll@Sun.COM {
1574*12720SWyllys.Ingersoll@Sun.COM iIndex = pLoadBalancer->Balance();
1575*12720SWyllys.Ingersoll@Sun.COM }
1576*12720SWyllys.Ingersoll@Sun.COM
1577*12720SWyllys.Ingersoll@Sun.COM if (iIndex >= 0)
1578*12720SWyllys.Ingersoll@Sun.COM {
1579*12720SWyllys.Ingersoll@Sun.COM do
1580*12720SWyllys.Ingersoll@Sun.COM {
1581*12720SWyllys.Ingersoll@Sun.COM bSuccess = true;
1582*12720SWyllys.Ingersoll@Sun.COM const char* sURL = pLoadBalancer->GetHTTPSURL(
1583*12720SWyllys.Ingersoll@Sun.COM iIndex,
1584*12720SWyllys.Ingersoll@Sun.COM i_pProfile->m_iPortForAgentService);
1585*12720SWyllys.Ingersoll@Sun.COM
1586*12720SWyllys.Ingersoll@Sun.COM strncpy(i_pProfile->m_sURL, sURL, sizeof(i_pProfile->m_sURL));
1587*12720SWyllys.Ingersoll@Sun.COM
1588*12720SWyllys.Ingersoll@Sun.COM i_pProfile->m_sURL[sizeof(i_pProfile->m_sURL)-1] = '\0';
1589*12720SWyllys.Ingersoll@Sun.COM
1590*12720SWyllys.Ingersoll@Sun.COM Long64 lKMAID = pLoadBalancer->GetKMAID(iIndex);
1591*12720SWyllys.Ingersoll@Sun.COM
1592*12720SWyllys.Ingersoll@Sun.COM if (bSuccess && pLoadBalancer->AESKeyWrapSupported(iIndex))
1593*12720SWyllys.Ingersoll@Sun.COM {
1594*12720SWyllys.Ingersoll@Sun.COM // if this fails we want to utilize normal failover logic, GetKWKID
1595*12720SWyllys.Ingersoll@Sun.COM // logs error
1596*12720SWyllys.Ingersoll@Sun.COM bSuccess = pLoadBalancer->GetKWKID(iIndex, lKMAID, pstSoap,
1597*12720SWyllys.Ingersoll@Sun.COM acKWKID, &bClientAESKeyWrapSetupError) ? true : false;
1598*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
1599*12720SWyllys.Ingersoll@Sun.COM {
1600*12720SWyllys.Ingersoll@Sun.COM bSuccess = KMS_Agent::soap_call_KMS_Agent__CreateKey2(
1601*12720SWyllys.Ingersoll@Sun.COM pstSoap,
1602*12720SWyllys.Ingersoll@Sun.COM sURL,
1603*12720SWyllys.Ingersoll@Sun.COM NULL,
1604*12720SWyllys.Ingersoll@Sun.COM stDataUnit,
1605*12720SWyllys.Ingersoll@Sun.COM i_pKeyGroupID ? pKeyGroupID : (char *) "",
1606*12720SWyllys.Ingersoll@Sun.COM acKWKID,
1607*12720SWyllys.Ingersoll@Sun.COM //NOTE: this is ugly but the soap response struct's are the same for both flavors of CreateKey
1608*12720SWyllys.Ingersoll@Sun.COM *(reinterpret_cast<struct KMS_Agent::KMS_Agent__CreateKey2Response *>(&oResponse))) == SOAP_OK;
1609*12720SWyllys.Ingersoll@Sun.COM }
1610*12720SWyllys.Ingersoll@Sun.COM }
1611*12720SWyllys.Ingersoll@Sun.COM else if (bSuccess) // NO AES Key Wrap
1612*12720SWyllys.Ingersoll@Sun.COM {
1613*12720SWyllys.Ingersoll@Sun.COM bSuccess = KMS_Agent::soap_call_KMS_Agent__CreateKey(
1614*12720SWyllys.Ingersoll@Sun.COM pstSoap,
1615*12720SWyllys.Ingersoll@Sun.COM sURL,
1616*12720SWyllys.Ingersoll@Sun.COM NULL,
1617*12720SWyllys.Ingersoll@Sun.COM stDataUnit,
1618*12720SWyllys.Ingersoll@Sun.COM i_pKeyGroupID ? pKeyGroupID : (char *) "",
1619*12720SWyllys.Ingersoll@Sun.COM oResponse) == SOAP_OK;
1620*12720SWyllys.Ingersoll@Sun.COM }
1621*12720SWyllys.Ingersoll@Sun.COM
1622*12720SWyllys.Ingersoll@Sun.COM // don'f failover for Client side AES Key Wrap setup problems
1623*12720SWyllys.Ingersoll@Sun.COM if (!bSuccess && !bClientAESKeyWrapSetupError)
1624*12720SWyllys.Ingersoll@Sun.COM {
1625*12720SWyllys.Ingersoll@Sun.COM iIndex = pLoadBalancer->FailOver(iIndex, pstSoap);
1626*12720SWyllys.Ingersoll@Sun.COM
1627*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
1628*12720SWyllys.Ingersoll@Sun.COM GetSoapFault(sSoapFaultMsg, pstSoap);
1629*12720SWyllys.Ingersoll@Sun.COM
1630*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
1631*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_CREATE_KEY_SOAP_ERROR,
1632*12720SWyllys.Ingersoll@Sun.COM NULL,
1633*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
1634*12720SWyllys.Ingersoll@Sun.COM sSoapFaultMsg);
1635*12720SWyllys.Ingersoll@Sun.COM }
1636*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
1637*12720SWyllys.Ingersoll@Sun.COM {
1638*12720SWyllys.Ingersoll@Sun.COM pLoadBalancer->UpdateResponseStatus(iIndex);
1639*12720SWyllys.Ingersoll@Sun.COM }
1640*12720SWyllys.Ingersoll@Sun.COM }
1641*12720SWyllys.Ingersoll@Sun.COM while (iIndex >= 0 && (!bSuccess) && (!bClientAESKeyWrapSetupError));
1642*12720SWyllys.Ingersoll@Sun.COM }
1643*12720SWyllys.Ingersoll@Sun.COM else
1644*12720SWyllys.Ingersoll@Sun.COM {
1645*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
1646*12720SWyllys.Ingersoll@Sun.COM }
1647*12720SWyllys.Ingersoll@Sun.COM
1648*12720SWyllys.Ingersoll@Sun.COM
1649*12720SWyllys.Ingersoll@Sun.COM #if defined(DEBUG) && defined(METAWARE)
1650*12720SWyllys.Ingersoll@Sun.COM log_printf("CreateKey gets keyID %s (size %x) \n",
1651*12720SWyllys.Ingersoll@Sun.COM oResponse.Key.KeyID,
1652*12720SWyllys.Ingersoll@Sun.COM sizeof (oResponse.Key.KeyID));
1653*12720SWyllys.Ingersoll@Sun.COM #endif
1654*12720SWyllys.Ingersoll@Sun.COM
1655*12720SWyllys.Ingersoll@Sun.COM
1656*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
1657*12720SWyllys.Ingersoll@Sun.COM {
1658*12720SWyllys.Ingersoll@Sun.COM if (KMS_KEY_ID_SIZE != ConvertUTF8HexStringToBinary(
1659*12720SWyllys.Ingersoll@Sun.COM oResponse.Key.KeyID, NULL))
1660*12720SWyllys.Ingersoll@Sun.COM {
1661*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
1662*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
1663*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_CREATE_KEY_INVALID_KEYID_RESPONSE,
1664*12720SWyllys.Ingersoll@Sun.COM NULL,
1665*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
1666*12720SWyllys.Ingersoll@Sun.COM NULL);
1667*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
1668*12720SWyllys.Ingersoll@Sun.COM }
1669*12720SWyllys.Ingersoll@Sun.COM
1670*12720SWyllys.Ingersoll@Sun.COM ConvertUTF8HexStringToBinary(
1671*12720SWyllys.Ingersoll@Sun.COM oResponse.Key.KeyID, // in
1672*12720SWyllys.Ingersoll@Sun.COM o_pKey->m_acKeyID); // out
1673*12720SWyllys.Ingersoll@Sun.COM
1674*12720SWyllys.Ingersoll@Sun.COM #if defined(DEBUG) && defined(METAWARE)
1675*12720SWyllys.Ingersoll@Sun.COM log_printf("CreateKey gets keyState %x (size %x) \n",
1676*12720SWyllys.Ingersoll@Sun.COM oResponse.Key.KeyState,
1677*12720SWyllys.Ingersoll@Sun.COM sizeof (oResponse.Key.KeyState));
1678*12720SWyllys.Ingersoll@Sun.COM #endif
1679*12720SWyllys.Ingersoll@Sun.COM
1680*12720SWyllys.Ingersoll@Sun.COM if ((KMS_AGENT_KEY_STATE) oResponse.Key.KeyState < KMS_KEY_STATE_ACTIVE_PROTECT_AND_PROCESS ||
1681*12720SWyllys.Ingersoll@Sun.COM (KMS_AGENT_KEY_STATE) oResponse.Key.KeyState > KMS_KEY_STATE_COMPROMISED)
1682*12720SWyllys.Ingersoll@Sun.COM {
1683*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
1684*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
1685*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_CREATE_KEY_INVALID_KEY_STATE_RESPONSE,
1686*12720SWyllys.Ingersoll@Sun.COM NULL,
1687*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
1688*12720SWyllys.Ingersoll@Sun.COM NULL);
1689*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
1690*12720SWyllys.Ingersoll@Sun.COM }
1691*12720SWyllys.Ingersoll@Sun.COM
1692*12720SWyllys.Ingersoll@Sun.COM o_pKey->m_iKeyState = (KMS_AGENT_KEY_STATE) oResponse.Key.KeyState;
1693*12720SWyllys.Ingersoll@Sun.COM
1694*12720SWyllys.Ingersoll@Sun.COM #if defined(DEBUG) && defined(METAWARE)
1695*12720SWyllys.Ingersoll@Sun.COM log_printf("CreateKey o_pKey->m_iKeyState %x (size %x) = "
1696*12720SWyllys.Ingersoll@Sun.COM "(KMS_AGENT_KEY_STATE) oResponse.Key.KeyState %x (size %x)\n",
1697*12720SWyllys.Ingersoll@Sun.COM o_pKey->m_iKeyState,
1698*12720SWyllys.Ingersoll@Sun.COM sizeof (o_pKey->m_iKeyState),
1699*12720SWyllys.Ingersoll@Sun.COM oResponse.Key.KeyState,
1700*12720SWyllys.Ingersoll@Sun.COM sizeof (oResponse.Key.KeyState));
1701*12720SWyllys.Ingersoll@Sun.COM #endif
1702*12720SWyllys.Ingersoll@Sun.COM
1703*12720SWyllys.Ingersoll@Sun.COM
1704*12720SWyllys.Ingersoll@Sun.COM if ((KMS_KEY_TYPE) oResponse.Key.KeyType != KMS_KEY_TYPE_AES_256)
1705*12720SWyllys.Ingersoll@Sun.COM {
1706*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
1707*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
1708*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_CREATE_KEY_INVALID_KEY_TYPE_RESPONSE,
1709*12720SWyllys.Ingersoll@Sun.COM NULL,
1710*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
1711*12720SWyllys.Ingersoll@Sun.COM NULL);
1712*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
1713*12720SWyllys.Ingersoll@Sun.COM }
1714*12720SWyllys.Ingersoll@Sun.COM o_pKey->m_iKeyType = (KMS_KEY_TYPE) oResponse.Key.KeyType;
1715*12720SWyllys.Ingersoll@Sun.COM
1716*12720SWyllys.Ingersoll@Sun.COM if (strlen(oResponse.Key.KeyGroupID) > KMS_MAX_KEY_GROUP_ID_SIZE)
1717*12720SWyllys.Ingersoll@Sun.COM {
1718*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
1719*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
1720*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_CREATE_KEY_INVALID_KEY_GROUP_ID_LENGTH_RESPONSE,
1721*12720SWyllys.Ingersoll@Sun.COM NULL,
1722*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
1723*12720SWyllys.Ingersoll@Sun.COM NULL);
1724*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
1725*12720SWyllys.Ingersoll@Sun.COM }
1726*12720SWyllys.Ingersoll@Sun.COM else
1727*12720SWyllys.Ingersoll@Sun.COM {
1728*12720SWyllys.Ingersoll@Sun.COM strncpy(o_pKey->m_acKeyGroupID,
1729*12720SWyllys.Ingersoll@Sun.COM oResponse.Key.KeyGroupID,
1730*12720SWyllys.Ingersoll@Sun.COM sizeof(o_pKey->m_acKeyGroupID));
1731*12720SWyllys.Ingersoll@Sun.COM o_pKey->m_acKeyGroupID[sizeof(o_pKey->m_acKeyGroupID)-1] = '\0';
1732*12720SWyllys.Ingersoll@Sun.COM }
1733*12720SWyllys.Ingersoll@Sun.COM
1734*12720SWyllys.Ingersoll@Sun.COM if ( bSuccess && pLoadBalancer->AESKeyWrapSupported(iIndex))
1735*12720SWyllys.Ingersoll@Sun.COM {
1736*12720SWyllys.Ingersoll@Sun.COM // verify KWK ID matches what was registered
1737*12720SWyllys.Ingersoll@Sun.COM if (oResponse.Key.Key.__size != KMS_MAX_WRAPPED_KEY_SIZE)
1738*12720SWyllys.Ingersoll@Sun.COM {
1739*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
1740*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
1741*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_CREATE_KEY_INVALID_WRAPPED_KEY_LENGTH_RESPONSE,
1742*12720SWyllys.Ingersoll@Sun.COM NULL,
1743*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
1744*12720SWyllys.Ingersoll@Sun.COM NULL);
1745*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
1746*12720SWyllys.Ingersoll@Sun.COM }
1747*12720SWyllys.Ingersoll@Sun.COM else
1748*12720SWyllys.Ingersoll@Sun.COM {
1749*12720SWyllys.Ingersoll@Sun.COM if (pLoadBalancer->AESKeyUnwrap(&iIndex, oResponse.Key.Key.__ptr,
1750*12720SWyllys.Ingersoll@Sun.COM o_pKey->m_acKey) == false)
1751*12720SWyllys.Ingersoll@Sun.COM {
1752*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
1753*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
1754*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_CREATE_KEY_AESKEYUNWRAP_ERROR,
1755*12720SWyllys.Ingersoll@Sun.COM NULL,
1756*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
1757*12720SWyllys.Ingersoll@Sun.COM NULL);
1758*12720SWyllys.Ingersoll@Sun.COM
1759*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
1760*12720SWyllys.Ingersoll@Sun.COM }
1761*12720SWyllys.Ingersoll@Sun.COM }
1762*12720SWyllys.Ingersoll@Sun.COM }
1763*12720SWyllys.Ingersoll@Sun.COM else if (bSuccess) // non-AES key wrap
1764*12720SWyllys.Ingersoll@Sun.COM {
1765*12720SWyllys.Ingersoll@Sun.COM if (oResponse.Key.Key.__size != KMS_MAX_KEY_SIZE)
1766*12720SWyllys.Ingersoll@Sun.COM {
1767*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
1768*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
1769*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_CREATE_KEY_INVALID_KEY_LENGTH_RESPONSE,
1770*12720SWyllys.Ingersoll@Sun.COM NULL,
1771*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
1772*12720SWyllys.Ingersoll@Sun.COM NULL);
1773*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
1774*12720SWyllys.Ingersoll@Sun.COM }
1775*12720SWyllys.Ingersoll@Sun.COM else
1776*12720SWyllys.Ingersoll@Sun.COM {
1777*12720SWyllys.Ingersoll@Sun.COM memcpy(o_pKey->m_acKey,
1778*12720SWyllys.Ingersoll@Sun.COM oResponse.Key.Key.__ptr,
1779*12720SWyllys.Ingersoll@Sun.COM KMS_MAX_KEY_SIZE);
1780*12720SWyllys.Ingersoll@Sun.COM }
1781*12720SWyllys.Ingersoll@Sun.COM }
1782*12720SWyllys.Ingersoll@Sun.COM
1783*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
1784*12720SWyllys.Ingersoll@Sun.COM {
1785*12720SWyllys.Ingersoll@Sun.COM o_pKey->m_iKeyLength = KMS_MAX_KEY_SIZE;
1786*12720SWyllys.Ingersoll@Sun.COM
1787*12720SWyllys.Ingersoll@Sun.COM if (KMSAgentKeyCallout(o_pKey->m_acKey) != 0)
1788*12720SWyllys.Ingersoll@Sun.COM {
1789*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
1790*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_CREATE_KEY_KEY_CALLOUT_ERROR,
1791*12720SWyllys.Ingersoll@Sun.COM NULL,
1792*12720SWyllys.Ingersoll@Sun.COM NULL,
1793*12720SWyllys.Ingersoll@Sun.COM NULL);
1794*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
1795*12720SWyllys.Ingersoll@Sun.COM }
1796*12720SWyllys.Ingersoll@Sun.COM }
1797*12720SWyllys.Ingersoll@Sun.COM }
1798*12720SWyllys.Ingersoll@Sun.COM
1799*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
1800*12720SWyllys.Ingersoll@Sun.COM {
1801*12720SWyllys.Ingersoll@Sun.COM // add Key ID and the creating KMA IP address to the DU cache
1802*12720SWyllys.Ingersoll@Sun.COM CDataUnitCache* pDataUnitCache = (CDataUnitCache*) i_pProfile->m_pDataUnitCache;
1803*12720SWyllys.Ingersoll@Sun.COM
1804*12720SWyllys.Ingersoll@Sun.COM if (i_pProfile->m_iClusterDiscoveryFrequency != 0) // load balancing enabled
1805*12720SWyllys.Ingersoll@Sun.COM {
1806*12720SWyllys.Ingersoll@Sun.COM bSuccess = pDataUnitCache->Insert(
1807*12720SWyllys.Ingersoll@Sun.COM NULL,
1808*12720SWyllys.Ingersoll@Sun.COM 0,
1809*12720SWyllys.Ingersoll@Sun.COM o_pKey->m_acKeyID,
1810*12720SWyllys.Ingersoll@Sun.COM KMS_KEY_ID_SIZE,
1811*12720SWyllys.Ingersoll@Sun.COM pLoadBalancer->GetApplianceNetworkAddress(iIndex));
1812*12720SWyllys.Ingersoll@Sun.COM }
1813*12720SWyllys.Ingersoll@Sun.COM }
1814*12720SWyllys.Ingersoll@Sun.COM // free allocated memory for output if error condition
1815*12720SWyllys.Ingersoll@Sun.COM // Clean up SOAP
1816*12720SWyllys.Ingersoll@Sun.COM
1817*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
1818*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
1819*12720SWyllys.Ingersoll@Sun.COM
1820*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
1821*12720SWyllys.Ingersoll@Sun.COM {
1822*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_OK);
1823*12720SWyllys.Ingersoll@Sun.COM }
1824*12720SWyllys.Ingersoll@Sun.COM
1825*12720SWyllys.Ingersoll@Sun.COM RETURN(KMSAgent_GetLastStatusCode(i_pProfile,
1826*12720SWyllys.Ingersoll@Sun.COM bClientAESKeyWrapSetupError ?
1827*12720SWyllys.Ingersoll@Sun.COM CAgentLoadBalancer::AES_KEY_WRAP_SETUP_ERROR : iIndex));
1828*12720SWyllys.Ingersoll@Sun.COM }
1829*12720SWyllys.Ingersoll@Sun.COM
1830*12720SWyllys.Ingersoll@Sun.COM extern "C"
KMSAgent_CreateDataUnit(KMSClientProfile * const i_pProfile,const unsigned char * i_pExternalUniqueID,int i_iExternalUniqueIDIDLen,utf8cstr const i_pExternalTag,utf8cstr const i_pDescription,KMSAgent_DataUnit * const o_pDataUnit)1831*12720SWyllys.Ingersoll@Sun.COM KMS_AGENT_STATUS KMSAgent_CreateDataUnit (
1832*12720SWyllys.Ingersoll@Sun.COM KMSClientProfile * const i_pProfile,
1833*12720SWyllys.Ingersoll@Sun.COM const unsigned char * i_pExternalUniqueID,
1834*12720SWyllys.Ingersoll@Sun.COM int i_iExternalUniqueIDIDLen,
1835*12720SWyllys.Ingersoll@Sun.COM utf8cstr const i_pExternalTag,
1836*12720SWyllys.Ingersoll@Sun.COM utf8cstr const i_pDescription,
1837*12720SWyllys.Ingersoll@Sun.COM KMSAgent_DataUnit * const o_pDataUnit)
1838*12720SWyllys.Ingersoll@Sun.COM {
1839*12720SWyllys.Ingersoll@Sun.COM bool bSuccess;
1840*12720SWyllys.Ingersoll@Sun.COM #if defined(METAWARE)
1841*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
1842*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE(trace, KMSAgent_CreateDataUnit);
1843*12720SWyllys.Ingersoll@Sun.COM #endif
1844*12720SWyllys.Ingersoll@Sun.COM
1845*12720SWyllys.Ingersoll@Sun.COM #if defined(DEBUG) && defined(METAWARE)
1846*12720SWyllys.Ingersoll@Sun.COM #warn "debug Create Data Unit is on"
1847*12720SWyllys.Ingersoll@Sun.COM log_printf("KMSAgent_CreateDataUnit entered\n");
1848*12720SWyllys.Ingersoll@Sun.COM log_printf("KMSAgent_CreateDataUnit profile=%x\n", i_pProfile);
1849*12720SWyllys.Ingersoll@Sun.COM #endif
1850*12720SWyllys.Ingersoll@Sun.COM
1851*12720SWyllys.Ingersoll@Sun.COM if (!i_pProfile)
1852*12720SWyllys.Ingersoll@Sun.COM {
1853*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_CREATE_DATA_UNIT_INVALID_PARAMETERS,
1854*12720SWyllys.Ingersoll@Sun.COM NULL,
1855*12720SWyllys.Ingersoll@Sun.COM NULL,
1856*12720SWyllys.Ingersoll@Sun.COM "Profile arg");
1857*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
1858*12720SWyllys.Ingersoll@Sun.COM }
1859*12720SWyllys.Ingersoll@Sun.COM if (!o_pDataUnit)
1860*12720SWyllys.Ingersoll@Sun.COM {
1861*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_CREATE_DATA_UNIT_INVALID_PARAMETERS,
1862*12720SWyllys.Ingersoll@Sun.COM NULL,
1863*12720SWyllys.Ingersoll@Sun.COM NULL,
1864*12720SWyllys.Ingersoll@Sun.COM "DataUnit arg");
1865*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
1866*12720SWyllys.Ingersoll@Sun.COM }
1867*12720SWyllys.Ingersoll@Sun.COM
1868*12720SWyllys.Ingersoll@Sun.COM if (!KMSClient_ProfileLoaded(i_pProfile))
1869*12720SWyllys.Ingersoll@Sun.COM {
1870*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_PROFILE_NOT_LOADED);
1871*12720SWyllys.Ingersoll@Sun.COM }
1872*12720SWyllys.Ingersoll@Sun.COM
1873*12720SWyllys.Ingersoll@Sun.COM CAutoMutex oAutoMutex((K_MUTEX_HANDLE) i_pProfile->m_pLock);
1874*12720SWyllys.Ingersoll@Sun.COM
1875*12720SWyllys.Ingersoll@Sun.COM // validate input parms
1876*12720SWyllys.Ingersoll@Sun.COM
1877*12720SWyllys.Ingersoll@Sun.COM if (i_pExternalUniqueID &&
1878*12720SWyllys.Ingersoll@Sun.COM (i_iExternalUniqueIDIDLen <= 0 ||
1879*12720SWyllys.Ingersoll@Sun.COM i_iExternalUniqueIDIDLen > KMS_MAX_EXTERNAL_UNIQUE_ID_SIZE))
1880*12720SWyllys.Ingersoll@Sun.COM {
1881*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_CREATE_DATA_UNIT_INVALID_PARAMETERS,
1882*12720SWyllys.Ingersoll@Sun.COM NULL,
1883*12720SWyllys.Ingersoll@Sun.COM NULL,
1884*12720SWyllys.Ingersoll@Sun.COM "ExternalUniqueID arg");
1885*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
1886*12720SWyllys.Ingersoll@Sun.COM }
1887*12720SWyllys.Ingersoll@Sun.COM
1888*12720SWyllys.Ingersoll@Sun.COM if (i_pExternalTag && strlen(i_pExternalTag) > KMS_MAX_EXTERNAL_TAG)
1889*12720SWyllys.Ingersoll@Sun.COM {
1890*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
1891*12720SWyllys.Ingersoll@Sun.COM }
1892*12720SWyllys.Ingersoll@Sun.COM
1893*12720SWyllys.Ingersoll@Sun.COM if (i_pDescription && strlen(i_pDescription) > KMS_MAX_DESCRIPTION)
1894*12720SWyllys.Ingersoll@Sun.COM {
1895*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
1896*12720SWyllys.Ingersoll@Sun.COM }
1897*12720SWyllys.Ingersoll@Sun.COM
1898*12720SWyllys.Ingersoll@Sun.COM struct soap *pstSoap = (struct soap *) i_pProfile->m_pvSoap;
1899*12720SWyllys.Ingersoll@Sun.COM struct KMS_Agent::KMS_Agent__CreateDataUnitResponse oResponse;
1900*12720SWyllys.Ingersoll@Sun.COM
1901*12720SWyllys.Ingersoll@Sun.COM char * pExternalUniqueID = NULL;
1902*12720SWyllys.Ingersoll@Sun.COM if (i_pExternalUniqueID)
1903*12720SWyllys.Ingersoll@Sun.COM {
1904*12720SWyllys.Ingersoll@Sun.COM pExternalUniqueID = ConvertBinaryDataFromRequest(pstSoap,
1905*12720SWyllys.Ingersoll@Sun.COM i_pExternalUniqueID,
1906*12720SWyllys.Ingersoll@Sun.COM i_iExternalUniqueIDIDLen);
1907*12720SWyllys.Ingersoll@Sun.COM if (pExternalUniqueID == NULL)
1908*12720SWyllys.Ingersoll@Sun.COM {
1909*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
1910*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
1911*12720SWyllys.Ingersoll@Sun.COM // no memory dont' log
1912*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_NO_MEMORY);
1913*12720SWyllys.Ingersoll@Sun.COM }
1914*12720SWyllys.Ingersoll@Sun.COM }
1915*12720SWyllys.Ingersoll@Sun.COM
1916*12720SWyllys.Ingersoll@Sun.COM char * pExternalTag = NULL;
1917*12720SWyllys.Ingersoll@Sun.COM if (i_pExternalTag)
1918*12720SWyllys.Ingersoll@Sun.COM {
1919*12720SWyllys.Ingersoll@Sun.COM pExternalTag = ConvertUTF8StringFromRequest(pstSoap,
1920*12720SWyllys.Ingersoll@Sun.COM i_pExternalTag,
1921*12720SWyllys.Ingersoll@Sun.COM strlen(i_pExternalTag) + 1);
1922*12720SWyllys.Ingersoll@Sun.COM if (pExternalTag == NULL)
1923*12720SWyllys.Ingersoll@Sun.COM {
1924*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
1925*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
1926*12720SWyllys.Ingersoll@Sun.COM // no memory dont' log
1927*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_NO_MEMORY);
1928*12720SWyllys.Ingersoll@Sun.COM }
1929*12720SWyllys.Ingersoll@Sun.COM }
1930*12720SWyllys.Ingersoll@Sun.COM
1931*12720SWyllys.Ingersoll@Sun.COM char * pDescription = NULL;
1932*12720SWyllys.Ingersoll@Sun.COM if (i_pDescription)
1933*12720SWyllys.Ingersoll@Sun.COM {
1934*12720SWyllys.Ingersoll@Sun.COM pDescription = ConvertUTF8StringFromRequest(pstSoap,
1935*12720SWyllys.Ingersoll@Sun.COM i_pDescription,
1936*12720SWyllys.Ingersoll@Sun.COM strlen(i_pDescription) + 1);
1937*12720SWyllys.Ingersoll@Sun.COM if (pDescription == NULL)
1938*12720SWyllys.Ingersoll@Sun.COM {
1939*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
1940*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
1941*12720SWyllys.Ingersoll@Sun.COM // no memory dont' log
1942*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_NO_MEMORY);
1943*12720SWyllys.Ingersoll@Sun.COM }
1944*12720SWyllys.Ingersoll@Sun.COM }
1945*12720SWyllys.Ingersoll@Sun.COM
1946*12720SWyllys.Ingersoll@Sun.COM CAgentLoadBalancer *pLoadBalancer =
1947*12720SWyllys.Ingersoll@Sun.COM (CAgentLoadBalancer *) i_pProfile->m_pAgentLoadBalancer;
1948*12720SWyllys.Ingersoll@Sun.COM int iIndex = pLoadBalancer->Balance();
1949*12720SWyllys.Ingersoll@Sun.COM
1950*12720SWyllys.Ingersoll@Sun.COM if (iIndex >= 0)
1951*12720SWyllys.Ingersoll@Sun.COM {
1952*12720SWyllys.Ingersoll@Sun.COM do
1953*12720SWyllys.Ingersoll@Sun.COM {
1954*12720SWyllys.Ingersoll@Sun.COM const char* sURL = pLoadBalancer->GetHTTPSURL(
1955*12720SWyllys.Ingersoll@Sun.COM iIndex,
1956*12720SWyllys.Ingersoll@Sun.COM i_pProfile->m_iPortForAgentService);
1957*12720SWyllys.Ingersoll@Sun.COM
1958*12720SWyllys.Ingersoll@Sun.COM strncpy(i_pProfile->m_sURL, sURL, sizeof(i_pProfile->m_sURL));
1959*12720SWyllys.Ingersoll@Sun.COM
1960*12720SWyllys.Ingersoll@Sun.COM i_pProfile->m_sURL[sizeof(i_pProfile->m_sURL)-1] = '\0';
1961*12720SWyllys.Ingersoll@Sun.COM
1962*12720SWyllys.Ingersoll@Sun.COM bSuccess = KMS_Agent::soap_call_KMS_Agent__CreateDataUnit(
1963*12720SWyllys.Ingersoll@Sun.COM pstSoap,
1964*12720SWyllys.Ingersoll@Sun.COM sURL,
1965*12720SWyllys.Ingersoll@Sun.COM NULL,
1966*12720SWyllys.Ingersoll@Sun.COM i_pExternalUniqueID ? pExternalUniqueID : (char *) "",
1967*12720SWyllys.Ingersoll@Sun.COM i_pExternalTag ? pExternalTag : (char *) "",
1968*12720SWyllys.Ingersoll@Sun.COM i_pDescription ? pDescription : (char *) "",
1969*12720SWyllys.Ingersoll@Sun.COM oResponse) == SOAP_OK;
1970*12720SWyllys.Ingersoll@Sun.COM
1971*12720SWyllys.Ingersoll@Sun.COM if (!bSuccess)
1972*12720SWyllys.Ingersoll@Sun.COM {
1973*12720SWyllys.Ingersoll@Sun.COM iIndex = pLoadBalancer->FailOver(iIndex, pstSoap);
1974*12720SWyllys.Ingersoll@Sun.COM
1975*12720SWyllys.Ingersoll@Sun.COM char sKmaAddress[g_iMAX_PEER_NETWORK_ADDRESS_LENGTH];
1976*12720SWyllys.Ingersoll@Sun.COM char sSoapFaultMsg[g_iMAX_SOAP_FAULT_MESSAGE_LENGTH];
1977*12720SWyllys.Ingersoll@Sun.COM
1978*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
1979*12720SWyllys.Ingersoll@Sun.COM GetSoapFault(sSoapFaultMsg, pstSoap);
1980*12720SWyllys.Ingersoll@Sun.COM
1981*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
1982*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_CREATE_DATA_UNIT_SOAP_ERROR,
1983*12720SWyllys.Ingersoll@Sun.COM NULL,
1984*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
1985*12720SWyllys.Ingersoll@Sun.COM sSoapFaultMsg);
1986*12720SWyllys.Ingersoll@Sun.COM }
1987*12720SWyllys.Ingersoll@Sun.COM else
1988*12720SWyllys.Ingersoll@Sun.COM {
1989*12720SWyllys.Ingersoll@Sun.COM pLoadBalancer->UpdateResponseStatus(iIndex);
1990*12720SWyllys.Ingersoll@Sun.COM }
1991*12720SWyllys.Ingersoll@Sun.COM
1992*12720SWyllys.Ingersoll@Sun.COM }
1993*12720SWyllys.Ingersoll@Sun.COM while (iIndex >= 0 && (!bSuccess));
1994*12720SWyllys.Ingersoll@Sun.COM }
1995*12720SWyllys.Ingersoll@Sun.COM else
1996*12720SWyllys.Ingersoll@Sun.COM {
1997*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
1998*12720SWyllys.Ingersoll@Sun.COM }
1999*12720SWyllys.Ingersoll@Sun.COM
2000*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
2001*12720SWyllys.Ingersoll@Sun.COM {
2002*12720SWyllys.Ingersoll@Sun.COM int iDataUnitIDLength;
2003*12720SWyllys.Ingersoll@Sun.COM iDataUnitIDLength = ConvertUTF8HexStringToBinary(
2004*12720SWyllys.Ingersoll@Sun.COM oResponse.DataUnit.DataUnitID, o_pDataUnit->m_acDataUnitID);
2005*12720SWyllys.Ingersoll@Sun.COM
2006*12720SWyllys.Ingersoll@Sun.COM if (iDataUnitIDLength != KMS_DATA_UNIT_ID_SIZE)
2007*12720SWyllys.Ingersoll@Sun.COM {
2008*12720SWyllys.Ingersoll@Sun.COM #if defined(DEBUG) && defined(METAWARE)
2009*12720SWyllys.Ingersoll@Sun.COM log_printf("iDataUnitIDLength (%x) != KMS_DATA_UNIT_ID_SIZE (%x)",
2010*12720SWyllys.Ingersoll@Sun.COM iDataUnitIDLength,
2011*12720SWyllys.Ingersoll@Sun.COM KMS_DATA_UNIT_ID_SIZE);
2012*12720SWyllys.Ingersoll@Sun.COM #endif
2013*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
2014*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_CREATE_DATA_UNIT_RESPONSE_INVALID_DU_ID_LENGTH,
2015*12720SWyllys.Ingersoll@Sun.COM NULL,
2016*12720SWyllys.Ingersoll@Sun.COM NULL,
2017*12720SWyllys.Ingersoll@Sun.COM NULL);
2018*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
2019*12720SWyllys.Ingersoll@Sun.COM }
2020*12720SWyllys.Ingersoll@Sun.COM o_pDataUnit->m_iExternalUniqueIDLength = ConvertUTF8HexStringToBinary(
2021*12720SWyllys.Ingersoll@Sun.COM oResponse.DataUnit.ExternalUniqueID, o_pDataUnit->m_acExternalUniqueID);
2022*12720SWyllys.Ingersoll@Sun.COM
2023*12720SWyllys.Ingersoll@Sun.COM if (strlen(oResponse.DataUnit.ExternalTag) > KMS_MAX_EXTERNAL_TAG)
2024*12720SWyllys.Ingersoll@Sun.COM {
2025*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
2026*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_CREATE_DATA_UNIT_RESPONSE_INVALID_EXTERNAL_TAG_LENGTH,
2027*12720SWyllys.Ingersoll@Sun.COM NULL,
2028*12720SWyllys.Ingersoll@Sun.COM NULL,
2029*12720SWyllys.Ingersoll@Sun.COM NULL);
2030*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
2031*12720SWyllys.Ingersoll@Sun.COM }
2032*12720SWyllys.Ingersoll@Sun.COM else
2033*12720SWyllys.Ingersoll@Sun.COM {
2034*12720SWyllys.Ingersoll@Sun.COM strncpy(o_pDataUnit->m_acExternalTag,
2035*12720SWyllys.Ingersoll@Sun.COM oResponse.DataUnit.ExternalTag,
2036*12720SWyllys.Ingersoll@Sun.COM sizeof(o_pDataUnit->m_acExternalTag));
2037*12720SWyllys.Ingersoll@Sun.COM o_pDataUnit->m_acExternalTag[sizeof(o_pDataUnit->m_acExternalTag)-1] = '\0';
2038*12720SWyllys.Ingersoll@Sun.COM }
2039*12720SWyllys.Ingersoll@Sun.COM
2040*12720SWyllys.Ingersoll@Sun.COM if (strlen(oResponse.DataUnit.Description) > KMS_MAX_DESCRIPTION)
2041*12720SWyllys.Ingersoll@Sun.COM {
2042*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
2043*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_CREATE_DATA_UNIT_RESPONSE_INVALID_DESCRIPTION_LENGTH,
2044*12720SWyllys.Ingersoll@Sun.COM NULL,
2045*12720SWyllys.Ingersoll@Sun.COM NULL,
2046*12720SWyllys.Ingersoll@Sun.COM NULL);
2047*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
2048*12720SWyllys.Ingersoll@Sun.COM }
2049*12720SWyllys.Ingersoll@Sun.COM else
2050*12720SWyllys.Ingersoll@Sun.COM {
2051*12720SWyllys.Ingersoll@Sun.COM strcpy(o_pDataUnit->m_acDescription,
2052*12720SWyllys.Ingersoll@Sun.COM oResponse.DataUnit.Description);
2053*12720SWyllys.Ingersoll@Sun.COM }
2054*12720SWyllys.Ingersoll@Sun.COM
2055*12720SWyllys.Ingersoll@Sun.COM o_pDataUnit->m_iDataUnitState =
2056*12720SWyllys.Ingersoll@Sun.COM (KMS_AGENT_DATA_UNIT_STATE) oResponse.DataUnit.DataUnitState;
2057*12720SWyllys.Ingersoll@Sun.COM }
2058*12720SWyllys.Ingersoll@Sun.COM
2059*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
2060*12720SWyllys.Ingersoll@Sun.COM {
2061*12720SWyllys.Ingersoll@Sun.COM // add data unit ID and the creating KMA IP address to the DU cache
2062*12720SWyllys.Ingersoll@Sun.COM CDataUnitCache* pDataUnitCache = (CDataUnitCache*) i_pProfile->m_pDataUnitCache;
2063*12720SWyllys.Ingersoll@Sun.COM
2064*12720SWyllys.Ingersoll@Sun.COM if (i_pProfile->m_iClusterDiscoveryFrequency != 0) // load balancing enabled
2065*12720SWyllys.Ingersoll@Sun.COM {
2066*12720SWyllys.Ingersoll@Sun.COM bSuccess = pDataUnitCache->Insert(
2067*12720SWyllys.Ingersoll@Sun.COM o_pDataUnit->m_acDataUnitID,
2068*12720SWyllys.Ingersoll@Sun.COM KMS_DATA_UNIT_ID_SIZE,
2069*12720SWyllys.Ingersoll@Sun.COM NULL, 0,
2070*12720SWyllys.Ingersoll@Sun.COM pLoadBalancer->GetApplianceNetworkAddress(iIndex));
2071*12720SWyllys.Ingersoll@Sun.COM }
2072*12720SWyllys.Ingersoll@Sun.COM }
2073*12720SWyllys.Ingersoll@Sun.COM
2074*12720SWyllys.Ingersoll@Sun.COM // free allocated memory for output if error condition
2075*12720SWyllys.Ingersoll@Sun.COM // Clean up SOAP
2076*12720SWyllys.Ingersoll@Sun.COM
2077*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
2078*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
2079*12720SWyllys.Ingersoll@Sun.COM
2080*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
2081*12720SWyllys.Ingersoll@Sun.COM {
2082*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_OK);
2083*12720SWyllys.Ingersoll@Sun.COM }
2084*12720SWyllys.Ingersoll@Sun.COM
2085*12720SWyllys.Ingersoll@Sun.COM RETURN(KMSAgent_GetLastStatusCode(i_pProfile, iIndex));
2086*12720SWyllys.Ingersoll@Sun.COM }
2087*12720SWyllys.Ingersoll@Sun.COM
2088*12720SWyllys.Ingersoll@Sun.COM extern "C"
KMSAgent_DisassociateDataUnitKeys(KMSClientProfile * const i_pProfile,const KMSAgent_DataUnit * const i_pDataUnit)2089*12720SWyllys.Ingersoll@Sun.COM KMS_AGENT_STATUS KMSAgent_DisassociateDataUnitKeys (
2090*12720SWyllys.Ingersoll@Sun.COM KMSClientProfile * const i_pProfile,
2091*12720SWyllys.Ingersoll@Sun.COM const KMSAgent_DataUnit * const i_pDataUnit)
2092*12720SWyllys.Ingersoll@Sun.COM {
2093*12720SWyllys.Ingersoll@Sun.COM bool bSuccess;
2094*12720SWyllys.Ingersoll@Sun.COM #if defined(METAWARE)
2095*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
2096*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE(trace, KMSAgent_DisassociateDataUnitKeys);
2097*12720SWyllys.Ingersoll@Sun.COM #endif
2098*12720SWyllys.Ingersoll@Sun.COM
2099*12720SWyllys.Ingersoll@Sun.COM if (!i_pProfile)
2100*12720SWyllys.Ingersoll@Sun.COM {
2101*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_DISASSOCIATE_DATA_UNIT_KEYS_INVALID_PARAMETERS,
2102*12720SWyllys.Ingersoll@Sun.COM NULL,
2103*12720SWyllys.Ingersoll@Sun.COM NULL,
2104*12720SWyllys.Ingersoll@Sun.COM "Profile arg");
2105*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
2106*12720SWyllys.Ingersoll@Sun.COM }
2107*12720SWyllys.Ingersoll@Sun.COM
2108*12720SWyllys.Ingersoll@Sun.COM if (!i_pDataUnit)
2109*12720SWyllys.Ingersoll@Sun.COM {
2110*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_DISASSOCIATE_DATA_UNIT_KEYS_INVALID_PARAMETERS,
2111*12720SWyllys.Ingersoll@Sun.COM NULL,
2112*12720SWyllys.Ingersoll@Sun.COM NULL,
2113*12720SWyllys.Ingersoll@Sun.COM "DataUnit arg");
2114*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
2115*12720SWyllys.Ingersoll@Sun.COM }
2116*12720SWyllys.Ingersoll@Sun.COM if (!KMSClient_ProfileLoaded(i_pProfile))
2117*12720SWyllys.Ingersoll@Sun.COM {
2118*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_PROFILE_NOT_LOADED);
2119*12720SWyllys.Ingersoll@Sun.COM }
2120*12720SWyllys.Ingersoll@Sun.COM
2121*12720SWyllys.Ingersoll@Sun.COM CAutoMutex oAutoMutex((K_MUTEX_HANDLE) i_pProfile->m_pLock);
2122*12720SWyllys.Ingersoll@Sun.COM
2123*12720SWyllys.Ingersoll@Sun.COM struct KMS_Agent::KMS_Agent__DataUnit stDataUnit = {"", "", "", "",
2124*12720SWyllys.Ingersoll@Sun.COM (KMS_Agent::KMS_Agent__DataUnitState) 0};
2125*12720SWyllys.Ingersoll@Sun.COM
2126*12720SWyllys.Ingersoll@Sun.COM struct soap *pstSoap = (struct soap *) i_pProfile->m_pvSoap;
2127*12720SWyllys.Ingersoll@Sun.COM struct KMS_Agent::KMS_Agent__DisassociateDataUnitKeysResponse oResponse;
2128*12720SWyllys.Ingersoll@Sun.COM
2129*12720SWyllys.Ingersoll@Sun.COM if (!CopyDataUnitFromRequest(pstSoap,
2130*12720SWyllys.Ingersoll@Sun.COM &stDataUnit,
2131*12720SWyllys.Ingersoll@Sun.COM i_pDataUnit))
2132*12720SWyllys.Ingersoll@Sun.COM {
2133*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
2134*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
2135*12720SWyllys.Ingersoll@Sun.COM // no memory dont' log
2136*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_NO_MEMORY);
2137*12720SWyllys.Ingersoll@Sun.COM }
2138*12720SWyllys.Ingersoll@Sun.COM
2139*12720SWyllys.Ingersoll@Sun.COM CAgentLoadBalancer *pLoadBalancer =
2140*12720SWyllys.Ingersoll@Sun.COM (CAgentLoadBalancer *) i_pProfile->m_pAgentLoadBalancer;
2141*12720SWyllys.Ingersoll@Sun.COM int iIndex = pLoadBalancer->BalanceByDataUnitID(
2142*12720SWyllys.Ingersoll@Sun.COM i_pDataUnit->m_acDataUnitID,
2143*12720SWyllys.Ingersoll@Sun.COM KMS_DATA_UNIT_ID_SIZE);
2144*12720SWyllys.Ingersoll@Sun.COM
2145*12720SWyllys.Ingersoll@Sun.COM if (iIndex >= 0)
2146*12720SWyllys.Ingersoll@Sun.COM {
2147*12720SWyllys.Ingersoll@Sun.COM do
2148*12720SWyllys.Ingersoll@Sun.COM {
2149*12720SWyllys.Ingersoll@Sun.COM const char* sURL = pLoadBalancer->GetHTTPSURL(
2150*12720SWyllys.Ingersoll@Sun.COM iIndex,
2151*12720SWyllys.Ingersoll@Sun.COM i_pProfile->m_iPortForAgentService);
2152*12720SWyllys.Ingersoll@Sun.COM
2153*12720SWyllys.Ingersoll@Sun.COM strncpy(i_pProfile->m_sURL, sURL, sizeof(i_pProfile->m_sURL));
2154*12720SWyllys.Ingersoll@Sun.COM
2155*12720SWyllys.Ingersoll@Sun.COM i_pProfile->m_sURL[sizeof(i_pProfile->m_sURL)-1] = '\0';
2156*12720SWyllys.Ingersoll@Sun.COM
2157*12720SWyllys.Ingersoll@Sun.COM bSuccess = KMS_Agent::soap_call_KMS_Agent__DisassociateDataUnitKeys(
2158*12720SWyllys.Ingersoll@Sun.COM pstSoap,
2159*12720SWyllys.Ingersoll@Sun.COM sURL,
2160*12720SWyllys.Ingersoll@Sun.COM NULL,
2161*12720SWyllys.Ingersoll@Sun.COM stDataUnit,
2162*12720SWyllys.Ingersoll@Sun.COM oResponse) == SOAP_OK;
2163*12720SWyllys.Ingersoll@Sun.COM
2164*12720SWyllys.Ingersoll@Sun.COM if (!bSuccess)
2165*12720SWyllys.Ingersoll@Sun.COM {
2166*12720SWyllys.Ingersoll@Sun.COM iIndex = pLoadBalancer->FailOver(iIndex, pstSoap);
2167*12720SWyllys.Ingersoll@Sun.COM
2168*12720SWyllys.Ingersoll@Sun.COM char sKmaAddress[g_iMAX_PEER_NETWORK_ADDRESS_LENGTH];
2169*12720SWyllys.Ingersoll@Sun.COM char sSoapFaultMsg[g_iMAX_SOAP_FAULT_MESSAGE_LENGTH];
2170*12720SWyllys.Ingersoll@Sun.COM
2171*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
2172*12720SWyllys.Ingersoll@Sun.COM GetSoapFault(sSoapFaultMsg, pstSoap);
2173*12720SWyllys.Ingersoll@Sun.COM
2174*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
2175*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_DISASSOCIATE_DATA_UNIT_KEYS_SOAP_ERROR,
2176*12720SWyllys.Ingersoll@Sun.COM NULL,
2177*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
2178*12720SWyllys.Ingersoll@Sun.COM sSoapFaultMsg);
2179*12720SWyllys.Ingersoll@Sun.COM }
2180*12720SWyllys.Ingersoll@Sun.COM else
2181*12720SWyllys.Ingersoll@Sun.COM {
2182*12720SWyllys.Ingersoll@Sun.COM pLoadBalancer->UpdateResponseStatus(iIndex);
2183*12720SWyllys.Ingersoll@Sun.COM }
2184*12720SWyllys.Ingersoll@Sun.COM }
2185*12720SWyllys.Ingersoll@Sun.COM while (iIndex >= 0 && (!bSuccess));
2186*12720SWyllys.Ingersoll@Sun.COM }
2187*12720SWyllys.Ingersoll@Sun.COM else
2188*12720SWyllys.Ingersoll@Sun.COM {
2189*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
2190*12720SWyllys.Ingersoll@Sun.COM }
2191*12720SWyllys.Ingersoll@Sun.COM
2192*12720SWyllys.Ingersoll@Sun.COM // no response data for this transaction
2193*12720SWyllys.Ingersoll@Sun.COM
2194*12720SWyllys.Ingersoll@Sun.COM // free allocated memory for output if error condition
2195*12720SWyllys.Ingersoll@Sun.COM // Clean up SOAP
2196*12720SWyllys.Ingersoll@Sun.COM
2197*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
2198*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
2199*12720SWyllys.Ingersoll@Sun.COM
2200*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
2201*12720SWyllys.Ingersoll@Sun.COM {
2202*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_OK);
2203*12720SWyllys.Ingersoll@Sun.COM }
2204*12720SWyllys.Ingersoll@Sun.COM
2205*12720SWyllys.Ingersoll@Sun.COM RETURN(KMSAgent_GetLastStatusCode(i_pProfile, iIndex));
2206*12720SWyllys.Ingersoll@Sun.COM }
2207*12720SWyllys.Ingersoll@Sun.COM
2208*12720SWyllys.Ingersoll@Sun.COM extern "C"
KMSAgent_RetrieveKey(KMSClientProfile * const i_pProfile,const unsigned char * const i_pKeyID,const KMSAgent_DataUnit * const i_pDataUnit,utf8cstr const i_pKeyGroupID,KMSAgent_Key * const o_pKey)2209*12720SWyllys.Ingersoll@Sun.COM KMS_AGENT_STATUS KMSAgent_RetrieveKey (
2210*12720SWyllys.Ingersoll@Sun.COM KMSClientProfile * const i_pProfile,
2211*12720SWyllys.Ingersoll@Sun.COM const unsigned char * const i_pKeyID,
2212*12720SWyllys.Ingersoll@Sun.COM const KMSAgent_DataUnit * const i_pDataUnit,
2213*12720SWyllys.Ingersoll@Sun.COM utf8cstr const i_pKeyGroupID,
2214*12720SWyllys.Ingersoll@Sun.COM KMSAgent_Key * const o_pKey)
2215*12720SWyllys.Ingersoll@Sun.COM {
2216*12720SWyllys.Ingersoll@Sun.COM bool bSuccess;
2217*12720SWyllys.Ingersoll@Sun.COM
2218*12720SWyllys.Ingersoll@Sun.COM #if defined(METAWARE)
2219*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
2220*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE(trace, KMSAgent_RetrieveKey);
2221*12720SWyllys.Ingersoll@Sun.COM #endif
2222*12720SWyllys.Ingersoll@Sun.COM
2223*12720SWyllys.Ingersoll@Sun.COM if (!i_pProfile)
2224*12720SWyllys.Ingersoll@Sun.COM {
2225*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_KEY_INVALID_PARAMETERS,
2226*12720SWyllys.Ingersoll@Sun.COM NULL,
2227*12720SWyllys.Ingersoll@Sun.COM NULL,
2228*12720SWyllys.Ingersoll@Sun.COM "Profile arg");
2229*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
2230*12720SWyllys.Ingersoll@Sun.COM }
2231*12720SWyllys.Ingersoll@Sun.COM if (!i_pKeyID)
2232*12720SWyllys.Ingersoll@Sun.COM {
2233*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_KEY_INVALID_PARAMETERS,
2234*12720SWyllys.Ingersoll@Sun.COM NULL,
2235*12720SWyllys.Ingersoll@Sun.COM NULL,
2236*12720SWyllys.Ingersoll@Sun.COM "KeyID arg");
2237*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
2238*12720SWyllys.Ingersoll@Sun.COM }
2239*12720SWyllys.Ingersoll@Sun.COM if (!o_pKey)
2240*12720SWyllys.Ingersoll@Sun.COM {
2241*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_KEY_INVALID_PARAMETERS,
2242*12720SWyllys.Ingersoll@Sun.COM NULL,
2243*12720SWyllys.Ingersoll@Sun.COM NULL,
2244*12720SWyllys.Ingersoll@Sun.COM "Key arg");
2245*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
2246*12720SWyllys.Ingersoll@Sun.COM }
2247*12720SWyllys.Ingersoll@Sun.COM
2248*12720SWyllys.Ingersoll@Sun.COM if (!KMSClient_ProfileLoaded(i_pProfile))
2249*12720SWyllys.Ingersoll@Sun.COM {
2250*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_PROFILE_NOT_LOADED);
2251*12720SWyllys.Ingersoll@Sun.COM }
2252*12720SWyllys.Ingersoll@Sun.COM
2253*12720SWyllys.Ingersoll@Sun.COM CAutoMutex oAutoMutex((K_MUTEX_HANDLE) i_pProfile->m_pLock);
2254*12720SWyllys.Ingersoll@Sun.COM
2255*12720SWyllys.Ingersoll@Sun.COM if (i_pKeyGroupID &&
2256*12720SWyllys.Ingersoll@Sun.COM strlen(i_pKeyGroupID) > KMS_MAX_KEY_GROUP_ID_SIZE)
2257*12720SWyllys.Ingersoll@Sun.COM {
2258*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_KEY_INVALID_PARAMETERS,
2259*12720SWyllys.Ingersoll@Sun.COM NULL,
2260*12720SWyllys.Ingersoll@Sun.COM NULL,
2261*12720SWyllys.Ingersoll@Sun.COM "GroupID arg");
2262*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
2263*12720SWyllys.Ingersoll@Sun.COM }
2264*12720SWyllys.Ingersoll@Sun.COM
2265*12720SWyllys.Ingersoll@Sun.COM struct KMS_Agent::KMS_Agent__DataUnit stDataUnit = {"", "", "", "",
2266*12720SWyllys.Ingersoll@Sun.COM (KMS_Agent::KMS_Agent__DataUnitState) 0};
2267*12720SWyllys.Ingersoll@Sun.COM
2268*12720SWyllys.Ingersoll@Sun.COM struct soap *pstSoap = (struct soap *) i_pProfile->m_pvSoap;
2269*12720SWyllys.Ingersoll@Sun.COM struct KMS_Agent::KMS_Agent__RetrieveKeyResponse oResponse;
2270*12720SWyllys.Ingersoll@Sun.COM
2271*12720SWyllys.Ingersoll@Sun.COM char * pKeyID = NULL;
2272*12720SWyllys.Ingersoll@Sun.COM pKeyID = ConvertBinaryDataFromRequest(pstSoap,
2273*12720SWyllys.Ingersoll@Sun.COM i_pKeyID,
2274*12720SWyllys.Ingersoll@Sun.COM KMS_KEY_ID_SIZE);
2275*12720SWyllys.Ingersoll@Sun.COM if (pKeyID == NULL)
2276*12720SWyllys.Ingersoll@Sun.COM {
2277*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
2278*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
2279*12720SWyllys.Ingersoll@Sun.COM // no memory dont' log
2280*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_NO_MEMORY);
2281*12720SWyllys.Ingersoll@Sun.COM }
2282*12720SWyllys.Ingersoll@Sun.COM
2283*12720SWyllys.Ingersoll@Sun.COM if (i_pDataUnit != NULL)
2284*12720SWyllys.Ingersoll@Sun.COM {
2285*12720SWyllys.Ingersoll@Sun.COM if (!CopyDataUnitFromRequest(pstSoap,
2286*12720SWyllys.Ingersoll@Sun.COM &stDataUnit,
2287*12720SWyllys.Ingersoll@Sun.COM i_pDataUnit))
2288*12720SWyllys.Ingersoll@Sun.COM {
2289*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
2290*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
2291*12720SWyllys.Ingersoll@Sun.COM // no memory dont' log
2292*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_NO_MEMORY);
2293*12720SWyllys.Ingersoll@Sun.COM }
2294*12720SWyllys.Ingersoll@Sun.COM }
2295*12720SWyllys.Ingersoll@Sun.COM
2296*12720SWyllys.Ingersoll@Sun.COM char * pKeyGroupID = NULL;
2297*12720SWyllys.Ingersoll@Sun.COM if (i_pKeyGroupID)
2298*12720SWyllys.Ingersoll@Sun.COM {
2299*12720SWyllys.Ingersoll@Sun.COM pKeyGroupID = ConvertUTF8StringFromRequest(pstSoap,
2300*12720SWyllys.Ingersoll@Sun.COM i_pKeyGroupID,
2301*12720SWyllys.Ingersoll@Sun.COM KMS_MAX_KEY_GROUP_ID_SIZE + 1);
2302*12720SWyllys.Ingersoll@Sun.COM if (pKeyGroupID == NULL)
2303*12720SWyllys.Ingersoll@Sun.COM {
2304*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
2305*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
2306*12720SWyllys.Ingersoll@Sun.COM // no memory dont' log
2307*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_NO_MEMORY);
2308*12720SWyllys.Ingersoll@Sun.COM }
2309*12720SWyllys.Ingersoll@Sun.COM }
2310*12720SWyllys.Ingersoll@Sun.COM
2311*12720SWyllys.Ingersoll@Sun.COM UTF8_KEYID acKWKID;
2312*12720SWyllys.Ingersoll@Sun.COM
2313*12720SWyllys.Ingersoll@Sun.COM char sKmaAddress[g_iMAX_PEER_NETWORK_ADDRESS_LENGTH];
2314*12720SWyllys.Ingersoll@Sun.COM char sSoapFaultMsg[g_iMAX_SOAP_FAULT_MESSAGE_LENGTH];
2315*12720SWyllys.Ingersoll@Sun.COM bool bClientAESKeyWrapSetupError = false;
2316*12720SWyllys.Ingersoll@Sun.COM
2317*12720SWyllys.Ingersoll@Sun.COM CAgentLoadBalancer *pLoadBalancer =
2318*12720SWyllys.Ingersoll@Sun.COM (CAgentLoadBalancer *) i_pProfile->m_pAgentLoadBalancer;
2319*12720SWyllys.Ingersoll@Sun.COM int iIndex = pLoadBalancer->BalanceByDataUnitKeyID(i_pKeyID, KMS_KEY_ID_SIZE);
2320*12720SWyllys.Ingersoll@Sun.COM
2321*12720SWyllys.Ingersoll@Sun.COM if (iIndex >= 0)
2322*12720SWyllys.Ingersoll@Sun.COM {
2323*12720SWyllys.Ingersoll@Sun.COM do
2324*12720SWyllys.Ingersoll@Sun.COM {
2325*12720SWyllys.Ingersoll@Sun.COM bSuccess = true;
2326*12720SWyllys.Ingersoll@Sun.COM const char* sURL = pLoadBalancer->GetHTTPSURL(
2327*12720SWyllys.Ingersoll@Sun.COM iIndex,
2328*12720SWyllys.Ingersoll@Sun.COM i_pProfile->m_iPortForAgentService);
2329*12720SWyllys.Ingersoll@Sun.COM
2330*12720SWyllys.Ingersoll@Sun.COM strncpy(i_pProfile->m_sURL, sURL, sizeof(i_pProfile->m_sURL));
2331*12720SWyllys.Ingersoll@Sun.COM
2332*12720SWyllys.Ingersoll@Sun.COM i_pProfile->m_sURL[sizeof(i_pProfile->m_sURL)-1] = '\0';
2333*12720SWyllys.Ingersoll@Sun.COM
2334*12720SWyllys.Ingersoll@Sun.COM Long64 lKMAID = pLoadBalancer->GetKMAID(iIndex);
2335*12720SWyllys.Ingersoll@Sun.COM
2336*12720SWyllys.Ingersoll@Sun.COM if (bSuccess && pLoadBalancer->AESKeyWrapSupported(iIndex))
2337*12720SWyllys.Ingersoll@Sun.COM {
2338*12720SWyllys.Ingersoll@Sun.COM // if this fails we want to utilize normal failover logic, GetKWKID
2339*12720SWyllys.Ingersoll@Sun.COM // logs error
2340*12720SWyllys.Ingersoll@Sun.COM bSuccess = pLoadBalancer->GetKWKID(iIndex, lKMAID, pstSoap,
2341*12720SWyllys.Ingersoll@Sun.COM acKWKID, &bClientAESKeyWrapSetupError) ? true : false;
2342*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
2343*12720SWyllys.Ingersoll@Sun.COM {
2344*12720SWyllys.Ingersoll@Sun.COM bSuccess = KMS_Agent::soap_call_KMS_Agent__RetrieveKey2(
2345*12720SWyllys.Ingersoll@Sun.COM pstSoap,
2346*12720SWyllys.Ingersoll@Sun.COM sURL,
2347*12720SWyllys.Ingersoll@Sun.COM NULL,
2348*12720SWyllys.Ingersoll@Sun.COM pKeyID,
2349*12720SWyllys.Ingersoll@Sun.COM stDataUnit,
2350*12720SWyllys.Ingersoll@Sun.COM i_pKeyGroupID ? i_pKeyGroupID : (char *) "",
2351*12720SWyllys.Ingersoll@Sun.COM acKWKID,
2352*12720SWyllys.Ingersoll@Sun.COM //NOTE: this is ugly but the soap response struct's are the same for both flavors of CreateKey
2353*12720SWyllys.Ingersoll@Sun.COM *(reinterpret_cast<struct KMS_Agent::KMS_Agent__RetrieveKey2Response *>(&oResponse))) == SOAP_OK;
2354*12720SWyllys.Ingersoll@Sun.COM }
2355*12720SWyllys.Ingersoll@Sun.COM }
2356*12720SWyllys.Ingersoll@Sun.COM else if (bSuccess) // NO AES Key Wrap
2357*12720SWyllys.Ingersoll@Sun.COM {
2358*12720SWyllys.Ingersoll@Sun.COM bSuccess = KMS_Agent::soap_call_KMS_Agent__RetrieveKey(
2359*12720SWyllys.Ingersoll@Sun.COM pstSoap,
2360*12720SWyllys.Ingersoll@Sun.COM sURL,
2361*12720SWyllys.Ingersoll@Sun.COM NULL,
2362*12720SWyllys.Ingersoll@Sun.COM pKeyID,
2363*12720SWyllys.Ingersoll@Sun.COM stDataUnit,
2364*12720SWyllys.Ingersoll@Sun.COM i_pKeyGroupID ? i_pKeyGroupID : (char *) "",
2365*12720SWyllys.Ingersoll@Sun.COM oResponse) == SOAP_OK;
2366*12720SWyllys.Ingersoll@Sun.COM }
2367*12720SWyllys.Ingersoll@Sun.COM
2368*12720SWyllys.Ingersoll@Sun.COM // don'f failover for Client side AES Key Wrap setup problems
2369*12720SWyllys.Ingersoll@Sun.COM if (!bSuccess && !bClientAESKeyWrapSetupError)
2370*12720SWyllys.Ingersoll@Sun.COM {
2371*12720SWyllys.Ingersoll@Sun.COM iIndex = pLoadBalancer->FailOver(iIndex, pstSoap);
2372*12720SWyllys.Ingersoll@Sun.COM
2373*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
2374*12720SWyllys.Ingersoll@Sun.COM GetSoapFault(sSoapFaultMsg, pstSoap);
2375*12720SWyllys.Ingersoll@Sun.COM
2376*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
2377*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_KEY_SOAP_ERROR,
2378*12720SWyllys.Ingersoll@Sun.COM NULL,
2379*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
2380*12720SWyllys.Ingersoll@Sun.COM sSoapFaultMsg);
2381*12720SWyllys.Ingersoll@Sun.COM }
2382*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
2383*12720SWyllys.Ingersoll@Sun.COM {
2384*12720SWyllys.Ingersoll@Sun.COM pLoadBalancer->UpdateResponseStatus(iIndex);
2385*12720SWyllys.Ingersoll@Sun.COM }
2386*12720SWyllys.Ingersoll@Sun.COM }
2387*12720SWyllys.Ingersoll@Sun.COM while (iIndex >= 0 && (!bSuccess) && (!bClientAESKeyWrapSetupError));
2388*12720SWyllys.Ingersoll@Sun.COM }
2389*12720SWyllys.Ingersoll@Sun.COM else
2390*12720SWyllys.Ingersoll@Sun.COM {
2391*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
2392*12720SWyllys.Ingersoll@Sun.COM }
2393*12720SWyllys.Ingersoll@Sun.COM
2394*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
2395*12720SWyllys.Ingersoll@Sun.COM {
2396*12720SWyllys.Ingersoll@Sun.COM if (KMS_KEY_ID_SIZE != ConvertUTF8HexStringToBinary(
2397*12720SWyllys.Ingersoll@Sun.COM oResponse.Key.KeyID, NULL))
2398*12720SWyllys.Ingersoll@Sun.COM {
2399*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
2400*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
2401*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_KEY_INVALID_KEYID_RESPONSE,
2402*12720SWyllys.Ingersoll@Sun.COM NULL,
2403*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
2404*12720SWyllys.Ingersoll@Sun.COM NULL);
2405*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
2406*12720SWyllys.Ingersoll@Sun.COM }
2407*12720SWyllys.Ingersoll@Sun.COM }
2408*12720SWyllys.Ingersoll@Sun.COM
2409*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
2410*12720SWyllys.Ingersoll@Sun.COM {
2411*12720SWyllys.Ingersoll@Sun.COM ConvertUTF8HexStringToBinary(
2412*12720SWyllys.Ingersoll@Sun.COM oResponse.Key.KeyID, o_pKey->m_acKeyID);
2413*12720SWyllys.Ingersoll@Sun.COM
2414*12720SWyllys.Ingersoll@Sun.COM //if ( oResponse.Key.KeyState < (KMS_Agent__KeyState)KMS_KEY_STATE_ACTIVE_PROTECT_AND_PROCESS ||
2415*12720SWyllys.Ingersoll@Sun.COM // oResponse.Key.KeyState > (KMS_Agent__KeyState)KMS_KEY_STATE_COMPROMISED )
2416*12720SWyllys.Ingersoll@Sun.COM if ((KMS_AGENT_KEY_STATE) oResponse.Key.KeyState < KMS_KEY_STATE_ACTIVE_PROTECT_AND_PROCESS ||
2417*12720SWyllys.Ingersoll@Sun.COM (KMS_AGENT_KEY_STATE) oResponse.Key.KeyState > KMS_KEY_STATE_COMPROMISED)
2418*12720SWyllys.Ingersoll@Sun.COM {
2419*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
2420*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
2421*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_KEY_INVALID_KEY_STATE_RESPONSE,
2422*12720SWyllys.Ingersoll@Sun.COM NULL,
2423*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
2424*12720SWyllys.Ingersoll@Sun.COM NULL);
2425*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
2426*12720SWyllys.Ingersoll@Sun.COM }
2427*12720SWyllys.Ingersoll@Sun.COM
2428*12720SWyllys.Ingersoll@Sun.COM o_pKey->m_iKeyState = (KMS_AGENT_KEY_STATE) oResponse.Key.KeyState;
2429*12720SWyllys.Ingersoll@Sun.COM
2430*12720SWyllys.Ingersoll@Sun.COM if ((KMS_KEY_TYPE) oResponse.Key.KeyType != KMS_KEY_TYPE_AES_256)
2431*12720SWyllys.Ingersoll@Sun.COM {
2432*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
2433*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
2434*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_KEY_INVALID_KEY_TYPE_RESPONSE,
2435*12720SWyllys.Ingersoll@Sun.COM NULL,
2436*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
2437*12720SWyllys.Ingersoll@Sun.COM NULL);
2438*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
2439*12720SWyllys.Ingersoll@Sun.COM }
2440*12720SWyllys.Ingersoll@Sun.COM
2441*12720SWyllys.Ingersoll@Sun.COM o_pKey->m_iKeyType = (KMS_KEY_TYPE) oResponse.Key.KeyType;
2442*12720SWyllys.Ingersoll@Sun.COM
2443*12720SWyllys.Ingersoll@Sun.COM if (strlen(oResponse.Key.KeyGroupID) > KMS_MAX_KEY_GROUP_ID_SIZE)
2444*12720SWyllys.Ingersoll@Sun.COM {
2445*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
2446*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
2447*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_KEY_INVALID_KEY_GROUP_ID_LENGTH_RESPONSE,
2448*12720SWyllys.Ingersoll@Sun.COM NULL,
2449*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
2450*12720SWyllys.Ingersoll@Sun.COM NULL);
2451*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
2452*12720SWyllys.Ingersoll@Sun.COM }
2453*12720SWyllys.Ingersoll@Sun.COM else
2454*12720SWyllys.Ingersoll@Sun.COM {
2455*12720SWyllys.Ingersoll@Sun.COM strncpy(o_pKey->m_acKeyGroupID,
2456*12720SWyllys.Ingersoll@Sun.COM oResponse.Key.KeyGroupID,
2457*12720SWyllys.Ingersoll@Sun.COM sizeof(o_pKey->m_acKeyGroupID));
2458*12720SWyllys.Ingersoll@Sun.COM o_pKey->m_acKeyGroupID[sizeof(o_pKey->m_acKeyGroupID)-1] = '\0';
2459*12720SWyllys.Ingersoll@Sun.COM }
2460*12720SWyllys.Ingersoll@Sun.COM
2461*12720SWyllys.Ingersoll@Sun.COM if ( bSuccess && pLoadBalancer->AESKeyWrapSupported(iIndex))
2462*12720SWyllys.Ingersoll@Sun.COM {
2463*12720SWyllys.Ingersoll@Sun.COM // verify KWK ID matches what was registered
2464*12720SWyllys.Ingersoll@Sun.COM if (oResponse.Key.Key.__size != KMS_MAX_WRAPPED_KEY_SIZE)
2465*12720SWyllys.Ingersoll@Sun.COM {
2466*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
2467*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
2468*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_KEY_INVALID_WRAPPED_KEY_LENGTH_RESPONSE,
2469*12720SWyllys.Ingersoll@Sun.COM NULL,
2470*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
2471*12720SWyllys.Ingersoll@Sun.COM NULL);
2472*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
2473*12720SWyllys.Ingersoll@Sun.COM }
2474*12720SWyllys.Ingersoll@Sun.COM else
2475*12720SWyllys.Ingersoll@Sun.COM {
2476*12720SWyllys.Ingersoll@Sun.COM if (pLoadBalancer->AESKeyUnwrap(&iIndex, oResponse.Key.Key.__ptr,
2477*12720SWyllys.Ingersoll@Sun.COM o_pKey->m_acKey) == false)
2478*12720SWyllys.Ingersoll@Sun.COM {
2479*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
2480*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
2481*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_KEY_AESKEYUNWRAP_ERROR,
2482*12720SWyllys.Ingersoll@Sun.COM NULL,
2483*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
2484*12720SWyllys.Ingersoll@Sun.COM NULL);
2485*12720SWyllys.Ingersoll@Sun.COM
2486*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
2487*12720SWyllys.Ingersoll@Sun.COM }
2488*12720SWyllys.Ingersoll@Sun.COM }
2489*12720SWyllys.Ingersoll@Sun.COM }
2490*12720SWyllys.Ingersoll@Sun.COM else if (bSuccess) // non-AES key wrap
2491*12720SWyllys.Ingersoll@Sun.COM {
2492*12720SWyllys.Ingersoll@Sun.COM if (oResponse.Key.Key.__size != KMS_MAX_KEY_SIZE)
2493*12720SWyllys.Ingersoll@Sun.COM {
2494*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
2495*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
2496*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_KEY_INVALID_KEY_LENGTH_RESPONSE,
2497*12720SWyllys.Ingersoll@Sun.COM NULL,
2498*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
2499*12720SWyllys.Ingersoll@Sun.COM NULL);
2500*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
2501*12720SWyllys.Ingersoll@Sun.COM }
2502*12720SWyllys.Ingersoll@Sun.COM else
2503*12720SWyllys.Ingersoll@Sun.COM {
2504*12720SWyllys.Ingersoll@Sun.COM memcpy(o_pKey->m_acKey,
2505*12720SWyllys.Ingersoll@Sun.COM oResponse.Key.Key.__ptr,
2506*12720SWyllys.Ingersoll@Sun.COM KMS_MAX_KEY_SIZE);
2507*12720SWyllys.Ingersoll@Sun.COM }
2508*12720SWyllys.Ingersoll@Sun.COM }
2509*12720SWyllys.Ingersoll@Sun.COM
2510*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
2511*12720SWyllys.Ingersoll@Sun.COM {
2512*12720SWyllys.Ingersoll@Sun.COM o_pKey->m_iKeyLength = KMS_MAX_KEY_SIZE;
2513*12720SWyllys.Ingersoll@Sun.COM
2514*12720SWyllys.Ingersoll@Sun.COM if (KMSAgentKeyCallout(o_pKey->m_acKey) != 0)
2515*12720SWyllys.Ingersoll@Sun.COM {
2516*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
2517*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_KEY_KEY_CALLOUT_ERROR,
2518*12720SWyllys.Ingersoll@Sun.COM NULL,
2519*12720SWyllys.Ingersoll@Sun.COM NULL,
2520*12720SWyllys.Ingersoll@Sun.COM NULL);
2521*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
2522*12720SWyllys.Ingersoll@Sun.COM }
2523*12720SWyllys.Ingersoll@Sun.COM }
2524*12720SWyllys.Ingersoll@Sun.COM }
2525*12720SWyllys.Ingersoll@Sun.COM
2526*12720SWyllys.Ingersoll@Sun.COM // free allocated memory for output if error condition
2527*12720SWyllys.Ingersoll@Sun.COM // Clean up SOAP
2528*12720SWyllys.Ingersoll@Sun.COM
2529*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
2530*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
2531*12720SWyllys.Ingersoll@Sun.COM
2532*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
2533*12720SWyllys.Ingersoll@Sun.COM {
2534*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_OK);
2535*12720SWyllys.Ingersoll@Sun.COM }
2536*12720SWyllys.Ingersoll@Sun.COM
2537*12720SWyllys.Ingersoll@Sun.COM RETURN(KMSAgent_GetLastStatusCode(i_pProfile,
2538*12720SWyllys.Ingersoll@Sun.COM bClientAESKeyWrapSetupError ?
2539*12720SWyllys.Ingersoll@Sun.COM CAgentLoadBalancer::AES_KEY_WRAP_SETUP_ERROR : iIndex));
2540*12720SWyllys.Ingersoll@Sun.COM }
2541*12720SWyllys.Ingersoll@Sun.COM
2542*12720SWyllys.Ingersoll@Sun.COM extern "C"
KMSAgent_RetrieveDataUnit(KMSClientProfile * const i_pProfile,const unsigned char * const i_pDataUnitID,const unsigned char * const i_pExternalUniqueID,int i_iExternalUniqueIDLen,utf8cstr const i_pExternalTag,utf8cstr const i_pDescription,KMSAgent_DataUnit * const o_pDataUnit)2543*12720SWyllys.Ingersoll@Sun.COM KMS_AGENT_STATUS KMSAgent_RetrieveDataUnit (
2544*12720SWyllys.Ingersoll@Sun.COM KMSClientProfile * const i_pProfile,
2545*12720SWyllys.Ingersoll@Sun.COM const unsigned char * const i_pDataUnitID,
2546*12720SWyllys.Ingersoll@Sun.COM const unsigned char * const i_pExternalUniqueID,
2547*12720SWyllys.Ingersoll@Sun.COM int i_iExternalUniqueIDLen,
2548*12720SWyllys.Ingersoll@Sun.COM utf8cstr const i_pExternalTag,
2549*12720SWyllys.Ingersoll@Sun.COM utf8cstr const i_pDescription,
2550*12720SWyllys.Ingersoll@Sun.COM KMSAgent_DataUnit * const o_pDataUnit)
2551*12720SWyllys.Ingersoll@Sun.COM {
2552*12720SWyllys.Ingersoll@Sun.COM bool bSuccess;
2553*12720SWyllys.Ingersoll@Sun.COM #if defined(METAWARE)
2554*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
2555*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE(trace, KMSAgent_RetrieveDataUnit);
2556*12720SWyllys.Ingersoll@Sun.COM #endif
2557*12720SWyllys.Ingersoll@Sun.COM
2558*12720SWyllys.Ingersoll@Sun.COM #if defined(DEBUG) && defined(METAWARE)
2559*12720SWyllys.Ingersoll@Sun.COM log_printf("KMSAgent_RetrieveDataUnit entered\n");
2560*12720SWyllys.Ingersoll@Sun.COM #endif
2561*12720SWyllys.Ingersoll@Sun.COM
2562*12720SWyllys.Ingersoll@Sun.COM // required parms
2563*12720SWyllys.Ingersoll@Sun.COM if (!i_pProfile)
2564*12720SWyllys.Ingersoll@Sun.COM {
2565*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_INVALID_PARAMETERS,
2566*12720SWyllys.Ingersoll@Sun.COM NULL,
2567*12720SWyllys.Ingersoll@Sun.COM NULL,
2568*12720SWyllys.Ingersoll@Sun.COM "Profile arg");
2569*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
2570*12720SWyllys.Ingersoll@Sun.COM }
2571*12720SWyllys.Ingersoll@Sun.COM if (!i_pDataUnitID)
2572*12720SWyllys.Ingersoll@Sun.COM {
2573*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_INVALID_PARAMETERS,
2574*12720SWyllys.Ingersoll@Sun.COM NULL,
2575*12720SWyllys.Ingersoll@Sun.COM NULL,
2576*12720SWyllys.Ingersoll@Sun.COM "DataUnitID arg");
2577*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
2578*12720SWyllys.Ingersoll@Sun.COM }
2579*12720SWyllys.Ingersoll@Sun.COM if (!o_pDataUnit)
2580*12720SWyllys.Ingersoll@Sun.COM {
2581*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_INVALID_PARAMETERS,
2582*12720SWyllys.Ingersoll@Sun.COM NULL,
2583*12720SWyllys.Ingersoll@Sun.COM NULL,
2584*12720SWyllys.Ingersoll@Sun.COM "DataUnit arg");
2585*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
2586*12720SWyllys.Ingersoll@Sun.COM }
2587*12720SWyllys.Ingersoll@Sun.COM
2588*12720SWyllys.Ingersoll@Sun.COM
2589*12720SWyllys.Ingersoll@Sun.COM
2590*12720SWyllys.Ingersoll@Sun.COM if (!KMSClient_ProfileLoaded(i_pProfile))
2591*12720SWyllys.Ingersoll@Sun.COM {
2592*12720SWyllys.Ingersoll@Sun.COM #if defined(DEBUG) && defined(METAWARE)
2593*12720SWyllys.Ingersoll@Sun.COM log_printf("KMSAgent_RetrieveDataUnit profile not loaded\n");
2594*12720SWyllys.Ingersoll@Sun.COM #endif
2595*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_PROFILE_NOT_LOADED);
2596*12720SWyllys.Ingersoll@Sun.COM }
2597*12720SWyllys.Ingersoll@Sun.COM
2598*12720SWyllys.Ingersoll@Sun.COM CAutoMutex oAutoMutex((K_MUTEX_HANDLE) i_pProfile->m_pLock);
2599*12720SWyllys.Ingersoll@Sun.COM
2600*12720SWyllys.Ingersoll@Sun.COM // validate input parms
2601*12720SWyllys.Ingersoll@Sun.COM
2602*12720SWyllys.Ingersoll@Sun.COM if (i_pExternalUniqueID &&
2603*12720SWyllys.Ingersoll@Sun.COM (i_iExternalUniqueIDLen <= 0 ||
2604*12720SWyllys.Ingersoll@Sun.COM i_iExternalUniqueIDLen > KMS_MAX_EXTERNAL_UNIQUE_ID_SIZE))
2605*12720SWyllys.Ingersoll@Sun.COM {
2606*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_INVALID_PARAMETERS,
2607*12720SWyllys.Ingersoll@Sun.COM NULL,
2608*12720SWyllys.Ingersoll@Sun.COM NULL,
2609*12720SWyllys.Ingersoll@Sun.COM "ExternalUniqueID arg");
2610*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
2611*12720SWyllys.Ingersoll@Sun.COM }
2612*12720SWyllys.Ingersoll@Sun.COM
2613*12720SWyllys.Ingersoll@Sun.COM if (i_pExternalTag && strlen(i_pExternalTag) > KMS_MAX_EXTERNAL_TAG)
2614*12720SWyllys.Ingersoll@Sun.COM {
2615*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_INVALID_PARAMETERS,
2616*12720SWyllys.Ingersoll@Sun.COM NULL,
2617*12720SWyllys.Ingersoll@Sun.COM NULL,
2618*12720SWyllys.Ingersoll@Sun.COM "ExternalTag arg");
2619*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
2620*12720SWyllys.Ingersoll@Sun.COM }
2621*12720SWyllys.Ingersoll@Sun.COM
2622*12720SWyllys.Ingersoll@Sun.COM if (i_pDescription &&
2623*12720SWyllys.Ingersoll@Sun.COM strlen(i_pDescription) > KMS_MAX_DESCRIPTION)
2624*12720SWyllys.Ingersoll@Sun.COM {
2625*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_INVALID_PARAMETERS,
2626*12720SWyllys.Ingersoll@Sun.COM NULL,
2627*12720SWyllys.Ingersoll@Sun.COM NULL,
2628*12720SWyllys.Ingersoll@Sun.COM "Description arg");
2629*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
2630*12720SWyllys.Ingersoll@Sun.COM }
2631*12720SWyllys.Ingersoll@Sun.COM
2632*12720SWyllys.Ingersoll@Sun.COM // prepare args to soap transaction
2633*12720SWyllys.Ingersoll@Sun.COM
2634*12720SWyllys.Ingersoll@Sun.COM struct soap *pstSoap = (struct soap *) i_pProfile->m_pvSoap;
2635*12720SWyllys.Ingersoll@Sun.COM struct KMS_Agent::KMS_Agent__RetrieveDataUnitResponse oResponse;
2636*12720SWyllys.Ingersoll@Sun.COM
2637*12720SWyllys.Ingersoll@Sun.COM char * pDataUnitID = NULL;
2638*12720SWyllys.Ingersoll@Sun.COM pDataUnitID = ConvertBinaryDataFromRequest(pstSoap,
2639*12720SWyllys.Ingersoll@Sun.COM i_pDataUnitID,
2640*12720SWyllys.Ingersoll@Sun.COM KMS_DATA_UNIT_ID_SIZE);
2641*12720SWyllys.Ingersoll@Sun.COM //sizeof(DATA_UNIT_ID) );
2642*12720SWyllys.Ingersoll@Sun.COM if (pDataUnitID == NULL)
2643*12720SWyllys.Ingersoll@Sun.COM {
2644*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
2645*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
2646*12720SWyllys.Ingersoll@Sun.COM // no memory dont' log
2647*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_NO_MEMORY);
2648*12720SWyllys.Ingersoll@Sun.COM }
2649*12720SWyllys.Ingersoll@Sun.COM
2650*12720SWyllys.Ingersoll@Sun.COM char * pExternalUniqueID = NULL;
2651*12720SWyllys.Ingersoll@Sun.COM if (i_pExternalUniqueID)
2652*12720SWyllys.Ingersoll@Sun.COM {
2653*12720SWyllys.Ingersoll@Sun.COM pExternalUniqueID = ConvertBinaryDataFromRequest(pstSoap,
2654*12720SWyllys.Ingersoll@Sun.COM i_pExternalUniqueID,
2655*12720SWyllys.Ingersoll@Sun.COM i_iExternalUniqueIDLen);
2656*12720SWyllys.Ingersoll@Sun.COM if (pExternalUniqueID == NULL)
2657*12720SWyllys.Ingersoll@Sun.COM {
2658*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
2659*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
2660*12720SWyllys.Ingersoll@Sun.COM // no memory dont' log
2661*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_NO_MEMORY);
2662*12720SWyllys.Ingersoll@Sun.COM }
2663*12720SWyllys.Ingersoll@Sun.COM }
2664*12720SWyllys.Ingersoll@Sun.COM
2665*12720SWyllys.Ingersoll@Sun.COM char * pExternalTag = NULL;
2666*12720SWyllys.Ingersoll@Sun.COM if (i_pExternalTag)
2667*12720SWyllys.Ingersoll@Sun.COM {
2668*12720SWyllys.Ingersoll@Sun.COM pExternalTag = ConvertUTF8StringFromRequest(pstSoap,
2669*12720SWyllys.Ingersoll@Sun.COM i_pExternalTag,
2670*12720SWyllys.Ingersoll@Sun.COM KMS_MAX_EXTERNAL_TAG + 1);
2671*12720SWyllys.Ingersoll@Sun.COM if (pExternalTag == NULL)
2672*12720SWyllys.Ingersoll@Sun.COM {
2673*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
2674*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
2675*12720SWyllys.Ingersoll@Sun.COM // no memory dont' log
2676*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_NO_MEMORY);
2677*12720SWyllys.Ingersoll@Sun.COM }
2678*12720SWyllys.Ingersoll@Sun.COM }
2679*12720SWyllys.Ingersoll@Sun.COM
2680*12720SWyllys.Ingersoll@Sun.COM char * pDescription = NULL;
2681*12720SWyllys.Ingersoll@Sun.COM if (i_pDescription)
2682*12720SWyllys.Ingersoll@Sun.COM {
2683*12720SWyllys.Ingersoll@Sun.COM pDescription = ConvertUTF8StringFromRequest(pstSoap,
2684*12720SWyllys.Ingersoll@Sun.COM i_pDescription,
2685*12720SWyllys.Ingersoll@Sun.COM KMS_MAX_DESCRIPTION + 1);
2686*12720SWyllys.Ingersoll@Sun.COM if (pDescription == NULL)
2687*12720SWyllys.Ingersoll@Sun.COM {
2688*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
2689*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
2690*12720SWyllys.Ingersoll@Sun.COM // no memory dont' log
2691*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_NO_MEMORY);
2692*12720SWyllys.Ingersoll@Sun.COM }
2693*12720SWyllys.Ingersoll@Sun.COM }
2694*12720SWyllys.Ingersoll@Sun.COM
2695*12720SWyllys.Ingersoll@Sun.COM CAgentLoadBalancer *pLoadBalancer =
2696*12720SWyllys.Ingersoll@Sun.COM (CAgentLoadBalancer *) i_pProfile->m_pAgentLoadBalancer;
2697*12720SWyllys.Ingersoll@Sun.COM int iIndex = pLoadBalancer->BalanceByDataUnitID(i_pDataUnitID,
2698*12720SWyllys.Ingersoll@Sun.COM KMS_DATA_UNIT_ID_SIZE);
2699*12720SWyllys.Ingersoll@Sun.COM
2700*12720SWyllys.Ingersoll@Sun.COM if ( iIndex >= 0 )
2701*12720SWyllys.Ingersoll@Sun.COM {
2702*12720SWyllys.Ingersoll@Sun.COM do
2703*12720SWyllys.Ingersoll@Sun.COM {
2704*12720SWyllys.Ingersoll@Sun.COM const char* sURL = pLoadBalancer->GetHTTPSURL(
2705*12720SWyllys.Ingersoll@Sun.COM iIndex,
2706*12720SWyllys.Ingersoll@Sun.COM i_pProfile->m_iPortForAgentService);
2707*12720SWyllys.Ingersoll@Sun.COM
2708*12720SWyllys.Ingersoll@Sun.COM strncpy(i_pProfile->m_sURL, sURL, sizeof(i_pProfile->m_sURL));
2709*12720SWyllys.Ingersoll@Sun.COM
2710*12720SWyllys.Ingersoll@Sun.COM i_pProfile->m_sURL[sizeof(i_pProfile->m_sURL)-1] = '\0';
2711*12720SWyllys.Ingersoll@Sun.COM
2712*12720SWyllys.Ingersoll@Sun.COM bSuccess = KMS_Agent::soap_call_KMS_Agent__RetrieveDataUnit(
2713*12720SWyllys.Ingersoll@Sun.COM pstSoap,
2714*12720SWyllys.Ingersoll@Sun.COM sURL,
2715*12720SWyllys.Ingersoll@Sun.COM NULL,
2716*12720SWyllys.Ingersoll@Sun.COM pDataUnitID,
2717*12720SWyllys.Ingersoll@Sun.COM i_pExternalUniqueID ? pExternalUniqueID : (char *) "",
2718*12720SWyllys.Ingersoll@Sun.COM i_pExternalTag ? pExternalTag : (char *) "",
2719*12720SWyllys.Ingersoll@Sun.COM i_pDescription ? pDescription : (char *) "",
2720*12720SWyllys.Ingersoll@Sun.COM oResponse) == SOAP_OK;
2721*12720SWyllys.Ingersoll@Sun.COM
2722*12720SWyllys.Ingersoll@Sun.COM if (!bSuccess)
2723*12720SWyllys.Ingersoll@Sun.COM {
2724*12720SWyllys.Ingersoll@Sun.COM iIndex = pLoadBalancer->FailOver(iIndex, pstSoap);
2725*12720SWyllys.Ingersoll@Sun.COM
2726*12720SWyllys.Ingersoll@Sun.COM char sKmaAddress[g_iMAX_PEER_NETWORK_ADDRESS_LENGTH];
2727*12720SWyllys.Ingersoll@Sun.COM char sSoapFaultMsg[g_iMAX_SOAP_FAULT_MESSAGE_LENGTH];
2728*12720SWyllys.Ingersoll@Sun.COM
2729*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
2730*12720SWyllys.Ingersoll@Sun.COM GetSoapFault(sSoapFaultMsg, pstSoap);
2731*12720SWyllys.Ingersoll@Sun.COM
2732*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
2733*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_SOAP_ERROR,
2734*12720SWyllys.Ingersoll@Sun.COM NULL,
2735*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
2736*12720SWyllys.Ingersoll@Sun.COM sSoapFaultMsg);
2737*12720SWyllys.Ingersoll@Sun.COM }
2738*12720SWyllys.Ingersoll@Sun.COM else
2739*12720SWyllys.Ingersoll@Sun.COM {
2740*12720SWyllys.Ingersoll@Sun.COM pLoadBalancer->UpdateResponseStatus(iIndex);
2741*12720SWyllys.Ingersoll@Sun.COM }
2742*12720SWyllys.Ingersoll@Sun.COM }
2743*12720SWyllys.Ingersoll@Sun.COM while (iIndex >= 0 && (!bSuccess));
2744*12720SWyllys.Ingersoll@Sun.COM }
2745*12720SWyllys.Ingersoll@Sun.COM else
2746*12720SWyllys.Ingersoll@Sun.COM {
2747*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
2748*12720SWyllys.Ingersoll@Sun.COM }
2749*12720SWyllys.Ingersoll@Sun.COM
2750*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
2751*12720SWyllys.Ingersoll@Sun.COM {
2752*12720SWyllys.Ingersoll@Sun.COM ConvertUTF8HexStringToBinary(
2753*12720SWyllys.Ingersoll@Sun.COM oResponse.DataUnit.DataUnitID, o_pDataUnit->m_acDataUnitID);
2754*12720SWyllys.Ingersoll@Sun.COM
2755*12720SWyllys.Ingersoll@Sun.COM o_pDataUnit->m_iExternalUniqueIDLength = ConvertUTF8HexStringToBinary(
2756*12720SWyllys.Ingersoll@Sun.COM oResponse.DataUnit.ExternalUniqueID, o_pDataUnit->m_acExternalUniqueID);
2757*12720SWyllys.Ingersoll@Sun.COM
2758*12720SWyllys.Ingersoll@Sun.COM if (strlen(oResponse.DataUnit.ExternalTag) > KMS_MAX_EXTERNAL_TAG)
2759*12720SWyllys.Ingersoll@Sun.COM {
2760*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
2761*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_RESPONSE_INVALID_EXTERNAL_TAG_LENGTH,
2762*12720SWyllys.Ingersoll@Sun.COM NULL,
2763*12720SWyllys.Ingersoll@Sun.COM NULL,
2764*12720SWyllys.Ingersoll@Sun.COM NULL);
2765*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
2766*12720SWyllys.Ingersoll@Sun.COM }
2767*12720SWyllys.Ingersoll@Sun.COM else
2768*12720SWyllys.Ingersoll@Sun.COM {
2769*12720SWyllys.Ingersoll@Sun.COM strncpy(o_pDataUnit->m_acExternalTag,
2770*12720SWyllys.Ingersoll@Sun.COM oResponse.DataUnit.ExternalTag,
2771*12720SWyllys.Ingersoll@Sun.COM sizeof(o_pDataUnit->m_acExternalTag));
2772*12720SWyllys.Ingersoll@Sun.COM o_pDataUnit->m_acExternalTag[sizeof(o_pDataUnit->m_acExternalTag)-1] = '\0';
2773*12720SWyllys.Ingersoll@Sun.COM }
2774*12720SWyllys.Ingersoll@Sun.COM
2775*12720SWyllys.Ingersoll@Sun.COM if (strlen(oResponse.DataUnit.Description) > KMS_MAX_DESCRIPTION)
2776*12720SWyllys.Ingersoll@Sun.COM {
2777*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
2778*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_RESPONSE_INVALID_DESCRIPTION_LENGTH,
2779*12720SWyllys.Ingersoll@Sun.COM NULL,
2780*12720SWyllys.Ingersoll@Sun.COM NULL,
2781*12720SWyllys.Ingersoll@Sun.COM NULL);
2782*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
2783*12720SWyllys.Ingersoll@Sun.COM }
2784*12720SWyllys.Ingersoll@Sun.COM else
2785*12720SWyllys.Ingersoll@Sun.COM {
2786*12720SWyllys.Ingersoll@Sun.COM strcpy(o_pDataUnit->m_acDescription,
2787*12720SWyllys.Ingersoll@Sun.COM oResponse.DataUnit.Description);
2788*12720SWyllys.Ingersoll@Sun.COM }
2789*12720SWyllys.Ingersoll@Sun.COM
2790*12720SWyllys.Ingersoll@Sun.COM o_pDataUnit->m_iDataUnitState =
2791*12720SWyllys.Ingersoll@Sun.COM (KMS_AGENT_DATA_UNIT_STATE) oResponse.DataUnit.DataUnitState;
2792*12720SWyllys.Ingersoll@Sun.COM }
2793*12720SWyllys.Ingersoll@Sun.COM
2794*12720SWyllys.Ingersoll@Sun.COM // free allocated memory for output if error condition
2795*12720SWyllys.Ingersoll@Sun.COM // Clean up SOAP
2796*12720SWyllys.Ingersoll@Sun.COM
2797*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
2798*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
2799*12720SWyllys.Ingersoll@Sun.COM
2800*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
2801*12720SWyllys.Ingersoll@Sun.COM {
2802*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_OK);
2803*12720SWyllys.Ingersoll@Sun.COM }
2804*12720SWyllys.Ingersoll@Sun.COM
2805*12720SWyllys.Ingersoll@Sun.COM RETURN(KMSAgent_GetLastStatusCode(i_pProfile, iIndex));
2806*12720SWyllys.Ingersoll@Sun.COM }
2807*12720SWyllys.Ingersoll@Sun.COM
2808*12720SWyllys.Ingersoll@Sun.COM extern "C"
KMSAgent_RetrieveDataUnitByExternalUniqueID(KMSClientProfile * const i_pProfile,const unsigned char * const i_pExternalUniqueID,int i_iExternalUniqueIDLen,utf8cstr const i_pExternalTag,utf8cstr const i_pDescription,KMSAgent_DataUnit * const o_pDataUnit)2809*12720SWyllys.Ingersoll@Sun.COM KMS_AGENT_STATUS KMSAgent_RetrieveDataUnitByExternalUniqueID (
2810*12720SWyllys.Ingersoll@Sun.COM KMSClientProfile * const i_pProfile,
2811*12720SWyllys.Ingersoll@Sun.COM const unsigned char* const i_pExternalUniqueID,
2812*12720SWyllys.Ingersoll@Sun.COM int i_iExternalUniqueIDLen,
2813*12720SWyllys.Ingersoll@Sun.COM utf8cstr const i_pExternalTag,
2814*12720SWyllys.Ingersoll@Sun.COM utf8cstr const i_pDescription,
2815*12720SWyllys.Ingersoll@Sun.COM KMSAgent_DataUnit * const o_pDataUnit)
2816*12720SWyllys.Ingersoll@Sun.COM {
2817*12720SWyllys.Ingersoll@Sun.COM bool bSuccess;
2818*12720SWyllys.Ingersoll@Sun.COM #if defined(METAWARE)
2819*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
2820*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE(trace, KMSAgent_RetrieveDataUnitByExternalUniqueID);
2821*12720SWyllys.Ingersoll@Sun.COM #endif
2822*12720SWyllys.Ingersoll@Sun.COM
2823*12720SWyllys.Ingersoll@Sun.COM // required parms
2824*12720SWyllys.Ingersoll@Sun.COM if (!i_pProfile)
2825*12720SWyllys.Ingersoll@Sun.COM {
2826*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_BY_EXTERNAL_UNIQUE_ID_INVALID_PARAMETERS,
2827*12720SWyllys.Ingersoll@Sun.COM NULL,
2828*12720SWyllys.Ingersoll@Sun.COM NULL,
2829*12720SWyllys.Ingersoll@Sun.COM "Profile arg");
2830*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
2831*12720SWyllys.Ingersoll@Sun.COM }
2832*12720SWyllys.Ingersoll@Sun.COM if (!i_pExternalUniqueID)
2833*12720SWyllys.Ingersoll@Sun.COM {
2834*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_BY_EXTERNAL_UNIQUE_ID_INVALID_PARAMETERS,
2835*12720SWyllys.Ingersoll@Sun.COM NULL,
2836*12720SWyllys.Ingersoll@Sun.COM NULL,
2837*12720SWyllys.Ingersoll@Sun.COM "ExternalUniqueID arg");
2838*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
2839*12720SWyllys.Ingersoll@Sun.COM }
2840*12720SWyllys.Ingersoll@Sun.COM if (!o_pDataUnit)
2841*12720SWyllys.Ingersoll@Sun.COM {
2842*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_BY_EXTERNAL_UNIQUE_ID_INVALID_PARAMETERS,
2843*12720SWyllys.Ingersoll@Sun.COM NULL,
2844*12720SWyllys.Ingersoll@Sun.COM NULL,
2845*12720SWyllys.Ingersoll@Sun.COM "DataUnit arg");
2846*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
2847*12720SWyllys.Ingersoll@Sun.COM }
2848*12720SWyllys.Ingersoll@Sun.COM
2849*12720SWyllys.Ingersoll@Sun.COM if (!KMSClient_ProfileLoaded(i_pProfile))
2850*12720SWyllys.Ingersoll@Sun.COM {
2851*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_PROFILE_NOT_LOADED);
2852*12720SWyllys.Ingersoll@Sun.COM }
2853*12720SWyllys.Ingersoll@Sun.COM
2854*12720SWyllys.Ingersoll@Sun.COM CAutoMutex oAutoMutex((K_MUTEX_HANDLE) i_pProfile->m_pLock);
2855*12720SWyllys.Ingersoll@Sun.COM
2856*12720SWyllys.Ingersoll@Sun.COM // validate input parms
2857*12720SWyllys.Ingersoll@Sun.COM
2858*12720SWyllys.Ingersoll@Sun.COM if (i_iExternalUniqueIDLen <= 0 ||
2859*12720SWyllys.Ingersoll@Sun.COM i_iExternalUniqueIDLen > KMS_MAX_EXTERNAL_UNIQUE_ID_SIZE)
2860*12720SWyllys.Ingersoll@Sun.COM {
2861*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_BY_EXTERNAL_UNIQUE_ID_INVALID_PARAMETERS,
2862*12720SWyllys.Ingersoll@Sun.COM NULL,
2863*12720SWyllys.Ingersoll@Sun.COM NULL,
2864*12720SWyllys.Ingersoll@Sun.COM "ExternalUniqueIDLen arg");
2865*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
2866*12720SWyllys.Ingersoll@Sun.COM }
2867*12720SWyllys.Ingersoll@Sun.COM
2868*12720SWyllys.Ingersoll@Sun.COM if (i_pExternalTag && strlen(i_pExternalTag) > KMS_MAX_EXTERNAL_TAG)
2869*12720SWyllys.Ingersoll@Sun.COM {
2870*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_BY_EXTERNAL_UNIQUE_ID_INVALID_PARAMETERS,
2871*12720SWyllys.Ingersoll@Sun.COM NULL,
2872*12720SWyllys.Ingersoll@Sun.COM NULL,
2873*12720SWyllys.Ingersoll@Sun.COM "ExternalTag arg");
2874*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
2875*12720SWyllys.Ingersoll@Sun.COM }
2876*12720SWyllys.Ingersoll@Sun.COM
2877*12720SWyllys.Ingersoll@Sun.COM if (i_pDescription &&
2878*12720SWyllys.Ingersoll@Sun.COM strlen(i_pDescription) > KMS_MAX_DESCRIPTION)
2879*12720SWyllys.Ingersoll@Sun.COM {
2880*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_BY_EXTERNAL_UNIQUE_ID_INVALID_PARAMETERS,
2881*12720SWyllys.Ingersoll@Sun.COM NULL,
2882*12720SWyllys.Ingersoll@Sun.COM NULL,
2883*12720SWyllys.Ingersoll@Sun.COM "Description arg");
2884*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
2885*12720SWyllys.Ingersoll@Sun.COM }
2886*12720SWyllys.Ingersoll@Sun.COM
2887*12720SWyllys.Ingersoll@Sun.COM // prepare args to soap transaction
2888*12720SWyllys.Ingersoll@Sun.COM
2889*12720SWyllys.Ingersoll@Sun.COM struct soap *pstSoap = (struct soap *) i_pProfile->m_pvSoap;
2890*12720SWyllys.Ingersoll@Sun.COM struct KMS_Agent::KMS_Agent__RetrieveDataUnitByExternalUniqueIDResponse oResponse;
2891*12720SWyllys.Ingersoll@Sun.COM
2892*12720SWyllys.Ingersoll@Sun.COM char * pExternalUniqueID = NULL;
2893*12720SWyllys.Ingersoll@Sun.COM pExternalUniqueID = ConvertBinaryDataFromRequest(pstSoap,
2894*12720SWyllys.Ingersoll@Sun.COM i_pExternalUniqueID,
2895*12720SWyllys.Ingersoll@Sun.COM i_iExternalUniqueIDLen);
2896*12720SWyllys.Ingersoll@Sun.COM if (pExternalUniqueID == NULL)
2897*12720SWyllys.Ingersoll@Sun.COM {
2898*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
2899*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
2900*12720SWyllys.Ingersoll@Sun.COM // no memory dont' log
2901*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_NO_MEMORY);
2902*12720SWyllys.Ingersoll@Sun.COM }
2903*12720SWyllys.Ingersoll@Sun.COM
2904*12720SWyllys.Ingersoll@Sun.COM char * pExternalTag = NULL;
2905*12720SWyllys.Ingersoll@Sun.COM if (i_pExternalTag)
2906*12720SWyllys.Ingersoll@Sun.COM {
2907*12720SWyllys.Ingersoll@Sun.COM pExternalTag = ConvertUTF8StringFromRequest(pstSoap,
2908*12720SWyllys.Ingersoll@Sun.COM i_pExternalTag,
2909*12720SWyllys.Ingersoll@Sun.COM KMS_MAX_EXTERNAL_TAG + 1);
2910*12720SWyllys.Ingersoll@Sun.COM if (pExternalTag == NULL)
2911*12720SWyllys.Ingersoll@Sun.COM {
2912*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
2913*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
2914*12720SWyllys.Ingersoll@Sun.COM // no memory dont' log
2915*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_NO_MEMORY);
2916*12720SWyllys.Ingersoll@Sun.COM }
2917*12720SWyllys.Ingersoll@Sun.COM }
2918*12720SWyllys.Ingersoll@Sun.COM
2919*12720SWyllys.Ingersoll@Sun.COM char * pDescription = NULL;
2920*12720SWyllys.Ingersoll@Sun.COM if (i_pDescription)
2921*12720SWyllys.Ingersoll@Sun.COM {
2922*12720SWyllys.Ingersoll@Sun.COM pDescription = ConvertUTF8StringFromRequest(pstSoap,
2923*12720SWyllys.Ingersoll@Sun.COM i_pDescription,
2924*12720SWyllys.Ingersoll@Sun.COM KMS_MAX_DESCRIPTION + 1);
2925*12720SWyllys.Ingersoll@Sun.COM if (pDescription == NULL)
2926*12720SWyllys.Ingersoll@Sun.COM {
2927*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
2928*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
2929*12720SWyllys.Ingersoll@Sun.COM // no memory dont' log
2930*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_NO_MEMORY);
2931*12720SWyllys.Ingersoll@Sun.COM }
2932*12720SWyllys.Ingersoll@Sun.COM }
2933*12720SWyllys.Ingersoll@Sun.COM
2934*12720SWyllys.Ingersoll@Sun.COM CAgentLoadBalancer *pLoadBalancer =
2935*12720SWyllys.Ingersoll@Sun.COM (CAgentLoadBalancer *) i_pProfile->m_pAgentLoadBalancer;
2936*12720SWyllys.Ingersoll@Sun.COM int iIndex = pLoadBalancer->Balance();
2937*12720SWyllys.Ingersoll@Sun.COM
2938*12720SWyllys.Ingersoll@Sun.COM if ( iIndex >= 0 )
2939*12720SWyllys.Ingersoll@Sun.COM {
2940*12720SWyllys.Ingersoll@Sun.COM do
2941*12720SWyllys.Ingersoll@Sun.COM {
2942*12720SWyllys.Ingersoll@Sun.COM const char* sURL = pLoadBalancer->GetHTTPSURL(
2943*12720SWyllys.Ingersoll@Sun.COM iIndex,
2944*12720SWyllys.Ingersoll@Sun.COM i_pProfile->m_iPortForAgentService);
2945*12720SWyllys.Ingersoll@Sun.COM
2946*12720SWyllys.Ingersoll@Sun.COM strncpy(i_pProfile->m_sURL, sURL, sizeof(i_pProfile->m_sURL));
2947*12720SWyllys.Ingersoll@Sun.COM
2948*12720SWyllys.Ingersoll@Sun.COM i_pProfile->m_sURL[sizeof(i_pProfile->m_sURL)-1] = '\0';
2949*12720SWyllys.Ingersoll@Sun.COM
2950*12720SWyllys.Ingersoll@Sun.COM bSuccess = KMS_Agent::
2951*12720SWyllys.Ingersoll@Sun.COM soap_call_KMS_Agent__RetrieveDataUnitByExternalUniqueID(
2952*12720SWyllys.Ingersoll@Sun.COM pstSoap,
2953*12720SWyllys.Ingersoll@Sun.COM sURL,
2954*12720SWyllys.Ingersoll@Sun.COM NULL,
2955*12720SWyllys.Ingersoll@Sun.COM pExternalUniqueID,
2956*12720SWyllys.Ingersoll@Sun.COM i_pExternalTag ? pExternalTag : (char *) "",
2957*12720SWyllys.Ingersoll@Sun.COM i_pDescription ? pDescription : (char *) "",
2958*12720SWyllys.Ingersoll@Sun.COM oResponse) == SOAP_OK;
2959*12720SWyllys.Ingersoll@Sun.COM
2960*12720SWyllys.Ingersoll@Sun.COM if (!bSuccess)
2961*12720SWyllys.Ingersoll@Sun.COM {
2962*12720SWyllys.Ingersoll@Sun.COM iIndex = pLoadBalancer->FailOver(iIndex, pstSoap);
2963*12720SWyllys.Ingersoll@Sun.COM
2964*12720SWyllys.Ingersoll@Sun.COM char sKmaAddress[g_iMAX_PEER_NETWORK_ADDRESS_LENGTH];
2965*12720SWyllys.Ingersoll@Sun.COM char sSoapFaultMsg[g_iMAX_SOAP_FAULT_MESSAGE_LENGTH];
2966*12720SWyllys.Ingersoll@Sun.COM
2967*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
2968*12720SWyllys.Ingersoll@Sun.COM GetSoapFault(sSoapFaultMsg, pstSoap);
2969*12720SWyllys.Ingersoll@Sun.COM
2970*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
2971*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_BY_EXTERNAL_UNIQUE_ID_SOAP_ERROR,
2972*12720SWyllys.Ingersoll@Sun.COM NULL,
2973*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
2974*12720SWyllys.Ingersoll@Sun.COM sSoapFaultMsg);
2975*12720SWyllys.Ingersoll@Sun.COM }
2976*12720SWyllys.Ingersoll@Sun.COM else
2977*12720SWyllys.Ingersoll@Sun.COM {
2978*12720SWyllys.Ingersoll@Sun.COM pLoadBalancer->UpdateResponseStatus(iIndex);
2979*12720SWyllys.Ingersoll@Sun.COM }
2980*12720SWyllys.Ingersoll@Sun.COM }
2981*12720SWyllys.Ingersoll@Sun.COM while (iIndex >= 0 && (!bSuccess));
2982*12720SWyllys.Ingersoll@Sun.COM }
2983*12720SWyllys.Ingersoll@Sun.COM else
2984*12720SWyllys.Ingersoll@Sun.COM {
2985*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
2986*12720SWyllys.Ingersoll@Sun.COM }
2987*12720SWyllys.Ingersoll@Sun.COM
2988*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
2989*12720SWyllys.Ingersoll@Sun.COM {
2990*12720SWyllys.Ingersoll@Sun.COM ConvertUTF8HexStringToBinary(
2991*12720SWyllys.Ingersoll@Sun.COM oResponse.DataUnit.DataUnitID, o_pDataUnit->m_acDataUnitID);
2992*12720SWyllys.Ingersoll@Sun.COM
2993*12720SWyllys.Ingersoll@Sun.COM o_pDataUnit->m_iExternalUniqueIDLength = ConvertUTF8HexStringToBinary(
2994*12720SWyllys.Ingersoll@Sun.COM oResponse.DataUnit.ExternalUniqueID,
2995*12720SWyllys.Ingersoll@Sun.COM o_pDataUnit->m_acExternalUniqueID);
2996*12720SWyllys.Ingersoll@Sun.COM
2997*12720SWyllys.Ingersoll@Sun.COM if (strlen(oResponse.DataUnit.ExternalTag) > KMS_MAX_EXTERNAL_TAG)
2998*12720SWyllys.Ingersoll@Sun.COM {
2999*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
3000*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_BY_EXTERNAL_UNIQUE_ID_RESPONSE_INVALID_EXTERNAL_TAG_LENGTH,
3001*12720SWyllys.Ingersoll@Sun.COM NULL,
3002*12720SWyllys.Ingersoll@Sun.COM NULL,
3003*12720SWyllys.Ingersoll@Sun.COM NULL);
3004*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
3005*12720SWyllys.Ingersoll@Sun.COM }
3006*12720SWyllys.Ingersoll@Sun.COM else
3007*12720SWyllys.Ingersoll@Sun.COM {
3008*12720SWyllys.Ingersoll@Sun.COM strncpy(o_pDataUnit->m_acExternalTag,
3009*12720SWyllys.Ingersoll@Sun.COM oResponse.DataUnit.ExternalTag,
3010*12720SWyllys.Ingersoll@Sun.COM sizeof(o_pDataUnit->m_acExternalTag));
3011*12720SWyllys.Ingersoll@Sun.COM o_pDataUnit->m_acExternalTag[sizeof(o_pDataUnit->m_acExternalTag)-1] = '\0';
3012*12720SWyllys.Ingersoll@Sun.COM }
3013*12720SWyllys.Ingersoll@Sun.COM
3014*12720SWyllys.Ingersoll@Sun.COM if (strlen(oResponse.DataUnit.Description) > KMS_MAX_DESCRIPTION)
3015*12720SWyllys.Ingersoll@Sun.COM {
3016*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
3017*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_BY_EXTERNAL_UNIQUE_ID_RESPONSE_INVALID_DESCRIPTION_LENGTH,
3018*12720SWyllys.Ingersoll@Sun.COM NULL,
3019*12720SWyllys.Ingersoll@Sun.COM NULL,
3020*12720SWyllys.Ingersoll@Sun.COM NULL);
3021*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
3022*12720SWyllys.Ingersoll@Sun.COM }
3023*12720SWyllys.Ingersoll@Sun.COM else
3024*12720SWyllys.Ingersoll@Sun.COM {
3025*12720SWyllys.Ingersoll@Sun.COM strcpy(o_pDataUnit->m_acDescription,
3026*12720SWyllys.Ingersoll@Sun.COM oResponse.DataUnit.Description);
3027*12720SWyllys.Ingersoll@Sun.COM }
3028*12720SWyllys.Ingersoll@Sun.COM
3029*12720SWyllys.Ingersoll@Sun.COM o_pDataUnit->m_iDataUnitState =
3030*12720SWyllys.Ingersoll@Sun.COM (KMS_AGENT_DATA_UNIT_STATE) oResponse.DataUnit.DataUnitState;
3031*12720SWyllys.Ingersoll@Sun.COM
3032*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
3033*12720SWyllys.Ingersoll@Sun.COM {
3034*12720SWyllys.Ingersoll@Sun.COM // RetrieveDataUnitByExternalUniqueID may create a DU so add data unit ID
3035*12720SWyllys.Ingersoll@Sun.COM // and the KMA IP address to the DU cache
3036*12720SWyllys.Ingersoll@Sun.COM CDataUnitCache* pDataUnitCache = (CDataUnitCache*) i_pProfile->m_pDataUnitCache;
3037*12720SWyllys.Ingersoll@Sun.COM
3038*12720SWyllys.Ingersoll@Sun.COM if (i_pProfile->m_iClusterDiscoveryFrequency != 0) // load balancing enabled
3039*12720SWyllys.Ingersoll@Sun.COM {
3040*12720SWyllys.Ingersoll@Sun.COM bSuccess = pDataUnitCache->Insert(
3041*12720SWyllys.Ingersoll@Sun.COM o_pDataUnit->m_acDataUnitID,
3042*12720SWyllys.Ingersoll@Sun.COM KMS_DATA_UNIT_ID_SIZE,
3043*12720SWyllys.Ingersoll@Sun.COM NULL, 0,
3044*12720SWyllys.Ingersoll@Sun.COM pLoadBalancer->GetApplianceNetworkAddress(iIndex));
3045*12720SWyllys.Ingersoll@Sun.COM }
3046*12720SWyllys.Ingersoll@Sun.COM }
3047*12720SWyllys.Ingersoll@Sun.COM }
3048*12720SWyllys.Ingersoll@Sun.COM
3049*12720SWyllys.Ingersoll@Sun.COM // free allocated memory for output if error condition
3050*12720SWyllys.Ingersoll@Sun.COM // Clean up SOAP
3051*12720SWyllys.Ingersoll@Sun.COM
3052*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
3053*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
3054*12720SWyllys.Ingersoll@Sun.COM
3055*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
3056*12720SWyllys.Ingersoll@Sun.COM {
3057*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_OK);
3058*12720SWyllys.Ingersoll@Sun.COM }
3059*12720SWyllys.Ingersoll@Sun.COM
3060*12720SWyllys.Ingersoll@Sun.COM RETURN(KMSAgent_GetLastStatusCode(i_pProfile, iIndex));
3061*12720SWyllys.Ingersoll@Sun.COM }
3062*12720SWyllys.Ingersoll@Sun.COM
3063*12720SWyllys.Ingersoll@Sun.COM extern "C"
KMSAgent_RetrieveDataUnitKeys(KMSClientProfile * const i_pProfile,const KMSAgent_DataUnit * const i_pDataUnit,int i_iPageSize,int i_iPageOffset,int * const o_piKeysRemaining,const unsigned char * const i_pKeyID,KMSAgent_ArrayOfKeys ** const o_ppKeys)3064*12720SWyllys.Ingersoll@Sun.COM KMS_AGENT_STATUS KMSAgent_RetrieveDataUnitKeys (
3065*12720SWyllys.Ingersoll@Sun.COM KMSClientProfile * const i_pProfile,
3066*12720SWyllys.Ingersoll@Sun.COM const KMSAgent_DataUnit * const i_pDataUnit,
3067*12720SWyllys.Ingersoll@Sun.COM int i_iPageSize,
3068*12720SWyllys.Ingersoll@Sun.COM int i_iPageOffset,
3069*12720SWyllys.Ingersoll@Sun.COM int* const o_piKeysRemaining,
3070*12720SWyllys.Ingersoll@Sun.COM const unsigned char * const i_pKeyID,
3071*12720SWyllys.Ingersoll@Sun.COM KMSAgent_ArrayOfKeys* * const o_ppKeys)
3072*12720SWyllys.Ingersoll@Sun.COM {
3073*12720SWyllys.Ingersoll@Sun.COM bool bSuccess;
3074*12720SWyllys.Ingersoll@Sun.COM #if defined(METAWARE)
3075*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
3076*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE(trace, KMSAgent_RetrieveDataUnitKeys);
3077*12720SWyllys.Ingersoll@Sun.COM #endif
3078*12720SWyllys.Ingersoll@Sun.COM
3079*12720SWyllys.Ingersoll@Sun.COM if (!i_pProfile)
3080*12720SWyllys.Ingersoll@Sun.COM {
3081*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_KEYS_INVALID_PARAMETERS,
3082*12720SWyllys.Ingersoll@Sun.COM NULL,
3083*12720SWyllys.Ingersoll@Sun.COM NULL,
3084*12720SWyllys.Ingersoll@Sun.COM "Profile arg");
3085*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
3086*12720SWyllys.Ingersoll@Sun.COM }
3087*12720SWyllys.Ingersoll@Sun.COM if (!i_pDataUnit)
3088*12720SWyllys.Ingersoll@Sun.COM {
3089*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_KEYS_INVALID_PARAMETERS,
3090*12720SWyllys.Ingersoll@Sun.COM NULL,
3091*12720SWyllys.Ingersoll@Sun.COM NULL,
3092*12720SWyllys.Ingersoll@Sun.COM "DataUnit arg");
3093*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
3094*12720SWyllys.Ingersoll@Sun.COM }
3095*12720SWyllys.Ingersoll@Sun.COM if (!o_piKeysRemaining)
3096*12720SWyllys.Ingersoll@Sun.COM {
3097*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_KEYS_INVALID_PARAMETERS,
3098*12720SWyllys.Ingersoll@Sun.COM NULL,
3099*12720SWyllys.Ingersoll@Sun.COM NULL,
3100*12720SWyllys.Ingersoll@Sun.COM "KeysRemaining arg");
3101*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
3102*12720SWyllys.Ingersoll@Sun.COM }
3103*12720SWyllys.Ingersoll@Sun.COM if (!o_ppKeys)
3104*12720SWyllys.Ingersoll@Sun.COM {
3105*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_KEYS_INVALID_PARAMETERS,
3106*12720SWyllys.Ingersoll@Sun.COM NULL,
3107*12720SWyllys.Ingersoll@Sun.COM NULL,
3108*12720SWyllys.Ingersoll@Sun.COM "Keys arg");
3109*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
3110*12720SWyllys.Ingersoll@Sun.COM }
3111*12720SWyllys.Ingersoll@Sun.COM if (i_pKeyID && i_iPageOffset != 0)
3112*12720SWyllys.Ingersoll@Sun.COM {
3113*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_KEYS_INVALID_PARAMETERS,
3114*12720SWyllys.Ingersoll@Sun.COM NULL,
3115*12720SWyllys.Ingersoll@Sun.COM NULL,
3116*12720SWyllys.Ingersoll@Sun.COM "KeyID and PageOffset are mutually exclusive");
3117*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
3118*12720SWyllys.Ingersoll@Sun.COM }
3119*12720SWyllys.Ingersoll@Sun.COM
3120*12720SWyllys.Ingersoll@Sun.COM if (!KMSClient_ProfileLoaded(i_pProfile))
3121*12720SWyllys.Ingersoll@Sun.COM {
3122*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_PROFILE_NOT_LOADED);
3123*12720SWyllys.Ingersoll@Sun.COM }
3124*12720SWyllys.Ingersoll@Sun.COM
3125*12720SWyllys.Ingersoll@Sun.COM CAutoMutex oAutoMutex((K_MUTEX_HANDLE) i_pProfile->m_pLock);
3126*12720SWyllys.Ingersoll@Sun.COM
3127*12720SWyllys.Ingersoll@Sun.COM // validate input parms
3128*12720SWyllys.Ingersoll@Sun.COM
3129*12720SWyllys.Ingersoll@Sun.COM if (i_iPageSize <= 0 || i_iPageSize > KMS_MAX_PAGE_SIZE)
3130*12720SWyllys.Ingersoll@Sun.COM {
3131*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_KEYS_INVALID_PARAMETERS,
3132*12720SWyllys.Ingersoll@Sun.COM NULL,
3133*12720SWyllys.Ingersoll@Sun.COM NULL,
3134*12720SWyllys.Ingersoll@Sun.COM "PageSize arg");
3135*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
3136*12720SWyllys.Ingersoll@Sun.COM }
3137*12720SWyllys.Ingersoll@Sun.COM
3138*12720SWyllys.Ingersoll@Sun.COM if (i_iPageOffset < 0)
3139*12720SWyllys.Ingersoll@Sun.COM {
3140*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_KEYS_INVALID_PARAMETERS,
3141*12720SWyllys.Ingersoll@Sun.COM NULL,
3142*12720SWyllys.Ingersoll@Sun.COM NULL,
3143*12720SWyllys.Ingersoll@Sun.COM "PageOffset arg");
3144*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
3145*12720SWyllys.Ingersoll@Sun.COM }
3146*12720SWyllys.Ingersoll@Sun.COM
3147*12720SWyllys.Ingersoll@Sun.COM // prepare args to soap transaction
3148*12720SWyllys.Ingersoll@Sun.COM
3149*12720SWyllys.Ingersoll@Sun.COM struct KMS_Agent::KMS_Agent__DataUnit stDataUnit = {"", "", "", "",
3150*12720SWyllys.Ingersoll@Sun.COM (KMS_Agent::KMS_Agent__DataUnitState) 0};
3151*12720SWyllys.Ingersoll@Sun.COM
3152*12720SWyllys.Ingersoll@Sun.COM struct soap *pstSoap = (struct soap *) i_pProfile->m_pvSoap;
3153*12720SWyllys.Ingersoll@Sun.COM struct KMS_Agent::KMS_Agent__RetrieveDataUnitKeysResponse oResponse;
3154*12720SWyllys.Ingersoll@Sun.COM
3155*12720SWyllys.Ingersoll@Sun.COM if (!CopyDataUnitFromRequest(pstSoap,
3156*12720SWyllys.Ingersoll@Sun.COM &stDataUnit,
3157*12720SWyllys.Ingersoll@Sun.COM i_pDataUnit))
3158*12720SWyllys.Ingersoll@Sun.COM {
3159*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
3160*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
3161*12720SWyllys.Ingersoll@Sun.COM // no memory dont' log
3162*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_NO_MEMORY);
3163*12720SWyllys.Ingersoll@Sun.COM }
3164*12720SWyllys.Ingersoll@Sun.COM
3165*12720SWyllys.Ingersoll@Sun.COM char * pKeyID = NULL;
3166*12720SWyllys.Ingersoll@Sun.COM if (i_pKeyID)
3167*12720SWyllys.Ingersoll@Sun.COM {
3168*12720SWyllys.Ingersoll@Sun.COM pKeyID = ConvertBinaryDataFromRequest(pstSoap,
3169*12720SWyllys.Ingersoll@Sun.COM i_pKeyID,
3170*12720SWyllys.Ingersoll@Sun.COM KMS_KEY_ID_SIZE);
3171*12720SWyllys.Ingersoll@Sun.COM if (pKeyID == NULL)
3172*12720SWyllys.Ingersoll@Sun.COM {
3173*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
3174*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
3175*12720SWyllys.Ingersoll@Sun.COM // no memory dont' log
3176*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_NO_MEMORY);
3177*12720SWyllys.Ingersoll@Sun.COM }
3178*12720SWyllys.Ingersoll@Sun.COM }
3179*12720SWyllys.Ingersoll@Sun.COM
3180*12720SWyllys.Ingersoll@Sun.COM UTF8_KEYID acKWKID;
3181*12720SWyllys.Ingersoll@Sun.COM char sKmaAddress[g_iMAX_PEER_NETWORK_ADDRESS_LENGTH];
3182*12720SWyllys.Ingersoll@Sun.COM char sSoapFaultMsg[g_iMAX_SOAP_FAULT_MESSAGE_LENGTH];
3183*12720SWyllys.Ingersoll@Sun.COM bool bClientAESKeyWrapSetupError = false;
3184*12720SWyllys.Ingersoll@Sun.COM
3185*12720SWyllys.Ingersoll@Sun.COM CAgentLoadBalancer *pLoadBalancer =
3186*12720SWyllys.Ingersoll@Sun.COM (CAgentLoadBalancer *) i_pProfile->m_pAgentLoadBalancer;
3187*12720SWyllys.Ingersoll@Sun.COM
3188*12720SWyllys.Ingersoll@Sun.COM int iIndex = pLoadBalancer->BalanceByDataUnitID(i_pDataUnit->m_acDataUnitID,
3189*12720SWyllys.Ingersoll@Sun.COM KMS_DATA_UNIT_ID_SIZE);
3190*12720SWyllys.Ingersoll@Sun.COM
3191*12720SWyllys.Ingersoll@Sun.COM if (iIndex >= 0)
3192*12720SWyllys.Ingersoll@Sun.COM {
3193*12720SWyllys.Ingersoll@Sun.COM do
3194*12720SWyllys.Ingersoll@Sun.COM {
3195*12720SWyllys.Ingersoll@Sun.COM bSuccess = true;
3196*12720SWyllys.Ingersoll@Sun.COM
3197*12720SWyllys.Ingersoll@Sun.COM const char* sURL = pLoadBalancer->GetHTTPSURL(
3198*12720SWyllys.Ingersoll@Sun.COM iIndex,
3199*12720SWyllys.Ingersoll@Sun.COM i_pProfile->m_iPortForAgentService);
3200*12720SWyllys.Ingersoll@Sun.COM
3201*12720SWyllys.Ingersoll@Sun.COM strncpy(i_pProfile->m_sURL, sURL, sizeof(i_pProfile->m_sURL));
3202*12720SWyllys.Ingersoll@Sun.COM
3203*12720SWyllys.Ingersoll@Sun.COM i_pProfile->m_sURL[sizeof(i_pProfile->m_sURL)-1] = 0;
3204*12720SWyllys.Ingersoll@Sun.COM
3205*12720SWyllys.Ingersoll@Sun.COM Long64 lKMAID = pLoadBalancer->GetKMAID(iIndex);
3206*12720SWyllys.Ingersoll@Sun.COM
3207*12720SWyllys.Ingersoll@Sun.COM if (bSuccess && pLoadBalancer->AESKeyWrapSupported(iIndex))
3208*12720SWyllys.Ingersoll@Sun.COM {
3209*12720SWyllys.Ingersoll@Sun.COM // if this fails we want to utilize normal failover logic, GetKWKID
3210*12720SWyllys.Ingersoll@Sun.COM // logs error
3211*12720SWyllys.Ingersoll@Sun.COM bSuccess = pLoadBalancer->GetKWKID(iIndex, lKMAID, pstSoap,
3212*12720SWyllys.Ingersoll@Sun.COM acKWKID, &bClientAESKeyWrapSetupError) ? true : false;
3213*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
3214*12720SWyllys.Ingersoll@Sun.COM {
3215*12720SWyllys.Ingersoll@Sun.COM bSuccess = KMS_Agent::soap_call_KMS_Agent__RetrieveDataUnitKeys2(
3216*12720SWyllys.Ingersoll@Sun.COM pstSoap,
3217*12720SWyllys.Ingersoll@Sun.COM sURL,
3218*12720SWyllys.Ingersoll@Sun.COM NULL,
3219*12720SWyllys.Ingersoll@Sun.COM stDataUnit,
3220*12720SWyllys.Ingersoll@Sun.COM i_iPageSize,
3221*12720SWyllys.Ingersoll@Sun.COM i_iPageOffset,
3222*12720SWyllys.Ingersoll@Sun.COM pKeyID,
3223*12720SWyllys.Ingersoll@Sun.COM acKWKID,
3224*12720SWyllys.Ingersoll@Sun.COM *(reinterpret_cast<struct KMS_Agent::KMS_Agent__RetrieveDataUnitKeys2Response *>(&oResponse))) == SOAP_OK;
3225*12720SWyllys.Ingersoll@Sun.COM }
3226*12720SWyllys.Ingersoll@Sun.COM }
3227*12720SWyllys.Ingersoll@Sun.COM else if (bSuccess) // No AES Key Wrap
3228*12720SWyllys.Ingersoll@Sun.COM {
3229*12720SWyllys.Ingersoll@Sun.COM bSuccess = KMS_Agent::soap_call_KMS_Agent__RetrieveDataUnitKeys(
3230*12720SWyllys.Ingersoll@Sun.COM pstSoap,
3231*12720SWyllys.Ingersoll@Sun.COM sURL,
3232*12720SWyllys.Ingersoll@Sun.COM NULL,
3233*12720SWyllys.Ingersoll@Sun.COM stDataUnit,
3234*12720SWyllys.Ingersoll@Sun.COM i_iPageSize,
3235*12720SWyllys.Ingersoll@Sun.COM i_iPageOffset,
3236*12720SWyllys.Ingersoll@Sun.COM pKeyID,
3237*12720SWyllys.Ingersoll@Sun.COM oResponse) == SOAP_OK;
3238*12720SWyllys.Ingersoll@Sun.COM }
3239*12720SWyllys.Ingersoll@Sun.COM
3240*12720SWyllys.Ingersoll@Sun.COM // don'f failover for Client side AES Key Wrap setup problems
3241*12720SWyllys.Ingersoll@Sun.COM if (!bSuccess && !bClientAESKeyWrapSetupError)
3242*12720SWyllys.Ingersoll@Sun.COM {
3243*12720SWyllys.Ingersoll@Sun.COM iIndex = pLoadBalancer->FailOver(iIndex, pstSoap);
3244*12720SWyllys.Ingersoll@Sun.COM
3245*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
3246*12720SWyllys.Ingersoll@Sun.COM GetSoapFault(sSoapFaultMsg, pstSoap);
3247*12720SWyllys.Ingersoll@Sun.COM
3248*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
3249*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_KEYS_SOAP_ERROR,
3250*12720SWyllys.Ingersoll@Sun.COM NULL,
3251*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
3252*12720SWyllys.Ingersoll@Sun.COM sSoapFaultMsg);
3253*12720SWyllys.Ingersoll@Sun.COM }
3254*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
3255*12720SWyllys.Ingersoll@Sun.COM {
3256*12720SWyllys.Ingersoll@Sun.COM pLoadBalancer->UpdateResponseStatus(iIndex);
3257*12720SWyllys.Ingersoll@Sun.COM }
3258*12720SWyllys.Ingersoll@Sun.COM }
3259*12720SWyllys.Ingersoll@Sun.COM while (iIndex >= 0 && (!bSuccess) && (!bClientAESKeyWrapSetupError));
3260*12720SWyllys.Ingersoll@Sun.COM }
3261*12720SWyllys.Ingersoll@Sun.COM else
3262*12720SWyllys.Ingersoll@Sun.COM {
3263*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
3264*12720SWyllys.Ingersoll@Sun.COM }
3265*12720SWyllys.Ingersoll@Sun.COM
3266*12720SWyllys.Ingersoll@Sun.COM // validate response
3267*12720SWyllys.Ingersoll@Sun.COM
3268*12720SWyllys.Ingersoll@Sun.COM if (bSuccess && oResponse.KeysRemaining < 0)
3269*12720SWyllys.Ingersoll@Sun.COM {
3270*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
3271*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_KEYS_INVALID_KEYS_REMAINING_RESPONSE,
3272*12720SWyllys.Ingersoll@Sun.COM NULL,
3273*12720SWyllys.Ingersoll@Sun.COM NULL,
3274*12720SWyllys.Ingersoll@Sun.COM NULL);
3275*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
3276*12720SWyllys.Ingersoll@Sun.COM }
3277*12720SWyllys.Ingersoll@Sun.COM
3278*12720SWyllys.Ingersoll@Sun.COM if (bSuccess &&
3279*12720SWyllys.Ingersoll@Sun.COM (oResponse.Keys.__size < 0 ||
3280*12720SWyllys.Ingersoll@Sun.COM oResponse.Keys.__size > i_iPageSize))
3281*12720SWyllys.Ingersoll@Sun.COM {
3282*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
3283*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_DATA_UNIT_KEYS_INVALID_KEYS_SIZE_RESPONSE,
3284*12720SWyllys.Ingersoll@Sun.COM NULL,
3285*12720SWyllys.Ingersoll@Sun.COM NULL,
3286*12720SWyllys.Ingersoll@Sun.COM NULL);
3287*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
3288*12720SWyllys.Ingersoll@Sun.COM }
3289*12720SWyllys.Ingersoll@Sun.COM
3290*12720SWyllys.Ingersoll@Sun.COM if ( bSuccess && pLoadBalancer->AESKeyWrapSupported(iIndex))
3291*12720SWyllys.Ingersoll@Sun.COM {
3292*12720SWyllys.Ingersoll@Sun.COM // verify KWK ID matches what was registered
3293*12720SWyllys.Ingersoll@Sun.COM }
3294*12720SWyllys.Ingersoll@Sun.COM
3295*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
3296*12720SWyllys.Ingersoll@Sun.COM {
3297*12720SWyllys.Ingersoll@Sun.COM *o_ppKeys = CopyDataUnitKeysResponse(i_pProfile, &iIndex, &oResponse.Keys);
3298*12720SWyllys.Ingersoll@Sun.COM
3299*12720SWyllys.Ingersoll@Sun.COM if (*o_ppKeys == NULL)
3300*12720SWyllys.Ingersoll@Sun.COM {
3301*12720SWyllys.Ingersoll@Sun.COM // CopyDataUnitKeysResponse logs errors
3302*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
3303*12720SWyllys.Ingersoll@Sun.COM }
3304*12720SWyllys.Ingersoll@Sun.COM *o_piKeysRemaining = (int) oResponse.KeysRemaining;
3305*12720SWyllys.Ingersoll@Sun.COM }
3306*12720SWyllys.Ingersoll@Sun.COM
3307*12720SWyllys.Ingersoll@Sun.COM // free allocated memory for output if error condition
3308*12720SWyllys.Ingersoll@Sun.COM // Clean up SOAP
3309*12720SWyllys.Ingersoll@Sun.COM
3310*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
3311*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
3312*12720SWyllys.Ingersoll@Sun.COM
3313*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
3314*12720SWyllys.Ingersoll@Sun.COM {
3315*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_OK);
3316*12720SWyllys.Ingersoll@Sun.COM }
3317*12720SWyllys.Ingersoll@Sun.COM
3318*12720SWyllys.Ingersoll@Sun.COM RETURN(KMSAgent_GetLastStatusCode(i_pProfile,
3319*12720SWyllys.Ingersoll@Sun.COM bClientAESKeyWrapSetupError ?
3320*12720SWyllys.Ingersoll@Sun.COM CAgentLoadBalancer::AES_KEY_WRAP_SETUP_ERROR : iIndex));
3321*12720SWyllys.Ingersoll@Sun.COM }
3322*12720SWyllys.Ingersoll@Sun.COM
3323*12720SWyllys.Ingersoll@Sun.COM extern "C"
KMSAgent_RetrieveProtectAndProcessKey(KMSClientProfile * const i_pProfile,const KMSAgent_DataUnit * const i_pDataUnit,utf8cstr const i_pKeyGroupID,KMSAgent_Key * const o_pKey)3324*12720SWyllys.Ingersoll@Sun.COM KMS_AGENT_STATUS KMSAgent_RetrieveProtectAndProcessKey (
3325*12720SWyllys.Ingersoll@Sun.COM KMSClientProfile * const i_pProfile,
3326*12720SWyllys.Ingersoll@Sun.COM const KMSAgent_DataUnit * const i_pDataUnit,
3327*12720SWyllys.Ingersoll@Sun.COM utf8cstr const i_pKeyGroupID,
3328*12720SWyllys.Ingersoll@Sun.COM KMSAgent_Key * const o_pKey)
3329*12720SWyllys.Ingersoll@Sun.COM {
3330*12720SWyllys.Ingersoll@Sun.COM bool bSuccess;
3331*12720SWyllys.Ingersoll@Sun.COM #if defined(METAWARE)
3332*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
3333*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE(trace, KMSAgent_RetrieveProtectAndProcessKey);
3334*12720SWyllys.Ingersoll@Sun.COM #endif
3335*12720SWyllys.Ingersoll@Sun.COM
3336*12720SWyllys.Ingersoll@Sun.COM if (!i_pProfile || !i_pDataUnit || !o_pKey)
3337*12720SWyllys.Ingersoll@Sun.COM {
3338*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
3339*12720SWyllys.Ingersoll@Sun.COM }
3340*12720SWyllys.Ingersoll@Sun.COM
3341*12720SWyllys.Ingersoll@Sun.COM if (!i_pProfile)
3342*12720SWyllys.Ingersoll@Sun.COM {
3343*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_PROTECT_AND_PROCESS_KEY_INVALID_PARAMETERS,
3344*12720SWyllys.Ingersoll@Sun.COM NULL,
3345*12720SWyllys.Ingersoll@Sun.COM NULL,
3346*12720SWyllys.Ingersoll@Sun.COM "Profile arg");
3347*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
3348*12720SWyllys.Ingersoll@Sun.COM }
3349*12720SWyllys.Ingersoll@Sun.COM if (!i_pDataUnit)
3350*12720SWyllys.Ingersoll@Sun.COM {
3351*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_PROTECT_AND_PROCESS_KEY_INVALID_PARAMETERS,
3352*12720SWyllys.Ingersoll@Sun.COM NULL,
3353*12720SWyllys.Ingersoll@Sun.COM NULL,
3354*12720SWyllys.Ingersoll@Sun.COM "DataUnit arg");
3355*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
3356*12720SWyllys.Ingersoll@Sun.COM }
3357*12720SWyllys.Ingersoll@Sun.COM if (!o_pKey)
3358*12720SWyllys.Ingersoll@Sun.COM {
3359*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_PROTECT_AND_PROCESS_KEY_INVALID_PARAMETERS,
3360*12720SWyllys.Ingersoll@Sun.COM NULL,
3361*12720SWyllys.Ingersoll@Sun.COM NULL,
3362*12720SWyllys.Ingersoll@Sun.COM "Key arg");
3363*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
3364*12720SWyllys.Ingersoll@Sun.COM }
3365*12720SWyllys.Ingersoll@Sun.COM
3366*12720SWyllys.Ingersoll@Sun.COM if (i_pKeyGroupID &&
3367*12720SWyllys.Ingersoll@Sun.COM strlen(i_pKeyGroupID) > KMS_MAX_KEY_GROUP_ID_SIZE)
3368*12720SWyllys.Ingersoll@Sun.COM {
3369*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_RETRIEVE_PROTECT_AND_PROCESS_KEY_INVALID_PARAMETERS,
3370*12720SWyllys.Ingersoll@Sun.COM NULL,
3371*12720SWyllys.Ingersoll@Sun.COM NULL,
3372*12720SWyllys.Ingersoll@Sun.COM "GroupID arg");
3373*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
3374*12720SWyllys.Ingersoll@Sun.COM }
3375*12720SWyllys.Ingersoll@Sun.COM
3376*12720SWyllys.Ingersoll@Sun.COM if (!KMSClient_ProfileLoaded(i_pProfile))
3377*12720SWyllys.Ingersoll@Sun.COM {
3378*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_PROFILE_NOT_LOADED);
3379*12720SWyllys.Ingersoll@Sun.COM }
3380*12720SWyllys.Ingersoll@Sun.COM
3381*12720SWyllys.Ingersoll@Sun.COM CAutoMutex oAutoMutex((K_MUTEX_HANDLE) i_pProfile->m_pLock);
3382*12720SWyllys.Ingersoll@Sun.COM
3383*12720SWyllys.Ingersoll@Sun.COM struct KMS_Agent::KMS_Agent__DataUnit stDataUnit ={"", "", "", "",
3384*12720SWyllys.Ingersoll@Sun.COM (KMS_Agent::KMS_Agent__DataUnitState) 0};
3385*12720SWyllys.Ingersoll@Sun.COM
3386*12720SWyllys.Ingersoll@Sun.COM struct soap *pstSoap = (struct soap *) i_pProfile->m_pvSoap;
3387*12720SWyllys.Ingersoll@Sun.COM struct KMS_Agent::KMS_Agent__RetrieveProtectAndProcessKeyResponse oResponse;
3388*12720SWyllys.Ingersoll@Sun.COM
3389*12720SWyllys.Ingersoll@Sun.COM if (i_pDataUnit != NULL)
3390*12720SWyllys.Ingersoll@Sun.COM {
3391*12720SWyllys.Ingersoll@Sun.COM if (!CopyDataUnitFromRequest(pstSoap,
3392*12720SWyllys.Ingersoll@Sun.COM &stDataUnit,
3393*12720SWyllys.Ingersoll@Sun.COM i_pDataUnit))
3394*12720SWyllys.Ingersoll@Sun.COM {
3395*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
3396*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
3397*12720SWyllys.Ingersoll@Sun.COM // no memory dont' log
3398*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_NO_MEMORY);
3399*12720SWyllys.Ingersoll@Sun.COM }
3400*12720SWyllys.Ingersoll@Sun.COM }
3401*12720SWyllys.Ingersoll@Sun.COM
3402*12720SWyllys.Ingersoll@Sun.COM char * pKeyGroupID = NULL;
3403*12720SWyllys.Ingersoll@Sun.COM if (i_pKeyGroupID)
3404*12720SWyllys.Ingersoll@Sun.COM {
3405*12720SWyllys.Ingersoll@Sun.COM pKeyGroupID = ConvertUTF8StringFromRequest(pstSoap,
3406*12720SWyllys.Ingersoll@Sun.COM i_pKeyGroupID,
3407*12720SWyllys.Ingersoll@Sun.COM KMS_MAX_KEY_GROUP_ID_SIZE + 1);
3408*12720SWyllys.Ingersoll@Sun.COM if (pKeyGroupID == NULL)
3409*12720SWyllys.Ingersoll@Sun.COM {
3410*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
3411*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
3412*12720SWyllys.Ingersoll@Sun.COM // no memory dont' log
3413*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_NO_MEMORY);
3414*12720SWyllys.Ingersoll@Sun.COM }
3415*12720SWyllys.Ingersoll@Sun.COM }
3416*12720SWyllys.Ingersoll@Sun.COM
3417*12720SWyllys.Ingersoll@Sun.COM char sKmaAddress[g_iMAX_PEER_NETWORK_ADDRESS_LENGTH];
3418*12720SWyllys.Ingersoll@Sun.COM char sSoapFaultMsg[g_iMAX_SOAP_FAULT_MESSAGE_LENGTH];
3419*12720SWyllys.Ingersoll@Sun.COM bool bClientAESKeyWrapSetupError = false;
3420*12720SWyllys.Ingersoll@Sun.COM UTF8_KEYID acKWKID;
3421*12720SWyllys.Ingersoll@Sun.COM
3422*12720SWyllys.Ingersoll@Sun.COM CAgentLoadBalancer *pLoadBalancer = (CAgentLoadBalancer *) i_pProfile->m_pAgentLoadBalancer;
3423*12720SWyllys.Ingersoll@Sun.COM int iIndex = pLoadBalancer->BalanceByDataUnitID(i_pDataUnit->m_acDataUnitID,
3424*12720SWyllys.Ingersoll@Sun.COM KMS_DATA_UNIT_ID_SIZE);
3425*12720SWyllys.Ingersoll@Sun.COM
3426*12720SWyllys.Ingersoll@Sun.COM if (iIndex >= 0)
3427*12720SWyllys.Ingersoll@Sun.COM {
3428*12720SWyllys.Ingersoll@Sun.COM do
3429*12720SWyllys.Ingersoll@Sun.COM {
3430*12720SWyllys.Ingersoll@Sun.COM bSuccess = true;
3431*12720SWyllys.Ingersoll@Sun.COM const char* sURL = pLoadBalancer->GetHTTPSURL(
3432*12720SWyllys.Ingersoll@Sun.COM iIndex,
3433*12720SWyllys.Ingersoll@Sun.COM i_pProfile->m_iPortForAgentService);
3434*12720SWyllys.Ingersoll@Sun.COM
3435*12720SWyllys.Ingersoll@Sun.COM strncpy(i_pProfile->m_sURL, sURL, sizeof(i_pProfile->m_sURL));
3436*12720SWyllys.Ingersoll@Sun.COM
3437*12720SWyllys.Ingersoll@Sun.COM i_pProfile->m_sURL[sizeof(i_pProfile->m_sURL)-1] = '\0';
3438*12720SWyllys.Ingersoll@Sun.COM
3439*12720SWyllys.Ingersoll@Sun.COM Long64 lKMAID = pLoadBalancer->GetKMAID(iIndex);
3440*12720SWyllys.Ingersoll@Sun.COM
3441*12720SWyllys.Ingersoll@Sun.COM if (bSuccess && pLoadBalancer->AESKeyWrapSupported(iIndex))
3442*12720SWyllys.Ingersoll@Sun.COM {
3443*12720SWyllys.Ingersoll@Sun.COM // if this fails we want to utilize normal failover logic, GetKWKID
3444*12720SWyllys.Ingersoll@Sun.COM // logs error
3445*12720SWyllys.Ingersoll@Sun.COM bSuccess = pLoadBalancer->GetKWKID(iIndex, lKMAID, pstSoap,
3446*12720SWyllys.Ingersoll@Sun.COM acKWKID, &bClientAESKeyWrapSetupError)
3447*12720SWyllys.Ingersoll@Sun.COM ? true : false;
3448*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
3449*12720SWyllys.Ingersoll@Sun.COM {
3450*12720SWyllys.Ingersoll@Sun.COM bSuccess = KMS_Agent::soap_call_KMS_Agent__RetrieveProtectAndProcessKey2(
3451*12720SWyllys.Ingersoll@Sun.COM pstSoap,
3452*12720SWyllys.Ingersoll@Sun.COM sURL,
3453*12720SWyllys.Ingersoll@Sun.COM NULL,
3454*12720SWyllys.Ingersoll@Sun.COM stDataUnit,
3455*12720SWyllys.Ingersoll@Sun.COM i_pKeyGroupID ? i_pKeyGroupID : (char *) "",
3456*12720SWyllys.Ingersoll@Sun.COM acKWKID,
3457*12720SWyllys.Ingersoll@Sun.COM *(reinterpret_cast<struct KMS_Agent::KMS_Agent__RetrieveProtectAndProcessKey2Response *>(&oResponse))) == SOAP_OK;
3458*12720SWyllys.Ingersoll@Sun.COM }
3459*12720SWyllys.Ingersoll@Sun.COM }
3460*12720SWyllys.Ingersoll@Sun.COM else if (bSuccess) // No AES Key Wrap
3461*12720SWyllys.Ingersoll@Sun.COM {
3462*12720SWyllys.Ingersoll@Sun.COM bSuccess = KMS_Agent::soap_call_KMS_Agent__RetrieveProtectAndProcessKey(
3463*12720SWyllys.Ingersoll@Sun.COM pstSoap,
3464*12720SWyllys.Ingersoll@Sun.COM sURL,
3465*12720SWyllys.Ingersoll@Sun.COM NULL,
3466*12720SWyllys.Ingersoll@Sun.COM stDataUnit,
3467*12720SWyllys.Ingersoll@Sun.COM i_pKeyGroupID ? i_pKeyGroupID : (char *) "",
3468*12720SWyllys.Ingersoll@Sun.COM oResponse) == SOAP_OK;
3469*12720SWyllys.Ingersoll@Sun.COM }
3470*12720SWyllys.Ingersoll@Sun.COM
3471*12720SWyllys.Ingersoll@Sun.COM // don'f failover for Client side AES Key Wrap setup problems
3472*12720SWyllys.Ingersoll@Sun.COM if (!bSuccess && !bClientAESKeyWrapSetupError)
3473*12720SWyllys.Ingersoll@Sun.COM {
3474*12720SWyllys.Ingersoll@Sun.COM iIndex = pLoadBalancer->FailOver(iIndex, pstSoap);
3475*12720SWyllys.Ingersoll@Sun.COM
3476*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
3477*12720SWyllys.Ingersoll@Sun.COM GetSoapFault(sSoapFaultMsg, pstSoap);
3478*12720SWyllys.Ingersoll@Sun.COM
3479*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
3480*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_PROTECT_AND_PROCESS_KEY_SOAP_ERROR,
3481*12720SWyllys.Ingersoll@Sun.COM NULL,
3482*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
3483*12720SWyllys.Ingersoll@Sun.COM sSoapFaultMsg);
3484*12720SWyllys.Ingersoll@Sun.COM }
3485*12720SWyllys.Ingersoll@Sun.COM else
3486*12720SWyllys.Ingersoll@Sun.COM {
3487*12720SWyllys.Ingersoll@Sun.COM pLoadBalancer->UpdateResponseStatus(iIndex);
3488*12720SWyllys.Ingersoll@Sun.COM }
3489*12720SWyllys.Ingersoll@Sun.COM }
3490*12720SWyllys.Ingersoll@Sun.COM while (iIndex >= 0 && (!bSuccess) && (!bClientAESKeyWrapSetupError));
3491*12720SWyllys.Ingersoll@Sun.COM }
3492*12720SWyllys.Ingersoll@Sun.COM else
3493*12720SWyllys.Ingersoll@Sun.COM {
3494*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
3495*12720SWyllys.Ingersoll@Sun.COM }
3496*12720SWyllys.Ingersoll@Sun.COM
3497*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
3498*12720SWyllys.Ingersoll@Sun.COM {
3499*12720SWyllys.Ingersoll@Sun.COM if (KMS_KEY_ID_SIZE != ConvertUTF8HexStringToBinary(
3500*12720SWyllys.Ingersoll@Sun.COM oResponse.Key.KeyID, NULL))
3501*12720SWyllys.Ingersoll@Sun.COM {
3502*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
3503*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
3504*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_PROTECT_AND_PROCESS_KEY_INVALID_KEYID_RESPONSE,
3505*12720SWyllys.Ingersoll@Sun.COM NULL,
3506*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
3507*12720SWyllys.Ingersoll@Sun.COM NULL);
3508*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
3509*12720SWyllys.Ingersoll@Sun.COM }
3510*12720SWyllys.Ingersoll@Sun.COM }
3511*12720SWyllys.Ingersoll@Sun.COM
3512*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
3513*12720SWyllys.Ingersoll@Sun.COM {
3514*12720SWyllys.Ingersoll@Sun.COM ConvertUTF8HexStringToBinary(
3515*12720SWyllys.Ingersoll@Sun.COM oResponse.Key.KeyID, o_pKey->m_acKeyID);
3516*12720SWyllys.Ingersoll@Sun.COM
3517*12720SWyllys.Ingersoll@Sun.COM if ((KMS_AGENT_KEY_STATE) oResponse.Key.KeyState < KMS_KEY_STATE_ACTIVE_PROTECT_AND_PROCESS ||
3518*12720SWyllys.Ingersoll@Sun.COM (KMS_AGENT_KEY_STATE) oResponse.Key.KeyState > KMS_KEY_STATE_COMPROMISED)
3519*12720SWyllys.Ingersoll@Sun.COM {
3520*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
3521*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
3522*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_PROTECT_AND_PROCESS_KEY_INVALID_KEY_STATE_RESPONSE,
3523*12720SWyllys.Ingersoll@Sun.COM NULL,
3524*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
3525*12720SWyllys.Ingersoll@Sun.COM NULL);
3526*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
3527*12720SWyllys.Ingersoll@Sun.COM }
3528*12720SWyllys.Ingersoll@Sun.COM
3529*12720SWyllys.Ingersoll@Sun.COM o_pKey->m_iKeyState = (KMS_AGENT_KEY_STATE) oResponse.Key.KeyState;
3530*12720SWyllys.Ingersoll@Sun.COM
3531*12720SWyllys.Ingersoll@Sun.COM if ((KMS_KEY_TYPE) oResponse.Key.KeyType != KMS_KEY_TYPE_AES_256)
3532*12720SWyllys.Ingersoll@Sun.COM {
3533*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
3534*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
3535*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_PROTECT_AND_PROCESS_KEY_INVALID_KEY_TYPE_RESPONSE,
3536*12720SWyllys.Ingersoll@Sun.COM NULL,
3537*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
3538*12720SWyllys.Ingersoll@Sun.COM NULL);
3539*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
3540*12720SWyllys.Ingersoll@Sun.COM }
3541*12720SWyllys.Ingersoll@Sun.COM
3542*12720SWyllys.Ingersoll@Sun.COM o_pKey->m_iKeyType = (KMS_KEY_TYPE) oResponse.Key.KeyType;
3543*12720SWyllys.Ingersoll@Sun.COM
3544*12720SWyllys.Ingersoll@Sun.COM if (strlen(oResponse.Key.KeyGroupID) > KMS_MAX_KEY_GROUP_ID_SIZE)
3545*12720SWyllys.Ingersoll@Sun.COM {
3546*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
3547*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
3548*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_PROTECT_AND_PROCESS_KEY_INVALID_KEY_GROUP_ID_LENGTH_RESPONSE,
3549*12720SWyllys.Ingersoll@Sun.COM NULL,
3550*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
3551*12720SWyllys.Ingersoll@Sun.COM NULL);
3552*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
3553*12720SWyllys.Ingersoll@Sun.COM }
3554*12720SWyllys.Ingersoll@Sun.COM else
3555*12720SWyllys.Ingersoll@Sun.COM {
3556*12720SWyllys.Ingersoll@Sun.COM strncpy(o_pKey->m_acKeyGroupID,
3557*12720SWyllys.Ingersoll@Sun.COM oResponse.Key.KeyGroupID,
3558*12720SWyllys.Ingersoll@Sun.COM sizeof(o_pKey->m_acKeyGroupID));
3559*12720SWyllys.Ingersoll@Sun.COM o_pKey->m_acKeyGroupID[sizeof(o_pKey->m_acKeyGroupID)-1] = '\0';
3560*12720SWyllys.Ingersoll@Sun.COM }
3561*12720SWyllys.Ingersoll@Sun.COM
3562*12720SWyllys.Ingersoll@Sun.COM if ( bSuccess && pLoadBalancer->AESKeyWrapSupported(iIndex))
3563*12720SWyllys.Ingersoll@Sun.COM {
3564*12720SWyllys.Ingersoll@Sun.COM // verify KWK ID matches what was registered
3565*12720SWyllys.Ingersoll@Sun.COM if (oResponse.Key.Key.__size != KMS_MAX_WRAPPED_KEY_SIZE)
3566*12720SWyllys.Ingersoll@Sun.COM {
3567*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
3568*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
3569*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_PROTECT_AND_PROCESS_KEY_INVALID_WRAPPED_KEY_LENGTH_RESPONSE,
3570*12720SWyllys.Ingersoll@Sun.COM NULL,
3571*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
3572*12720SWyllys.Ingersoll@Sun.COM NULL);
3573*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
3574*12720SWyllys.Ingersoll@Sun.COM }
3575*12720SWyllys.Ingersoll@Sun.COM else
3576*12720SWyllys.Ingersoll@Sun.COM {
3577*12720SWyllys.Ingersoll@Sun.COM if (pLoadBalancer->AESKeyUnwrap(&iIndex, oResponse.Key.Key.__ptr,
3578*12720SWyllys.Ingersoll@Sun.COM o_pKey->m_acKey) == false)
3579*12720SWyllys.Ingersoll@Sun.COM {
3580*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
3581*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
3582*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_PROTECT_AND_PROCESS_KEY_AESKEYUNWRAP_ERROR,
3583*12720SWyllys.Ingersoll@Sun.COM NULL,
3584*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
3585*12720SWyllys.Ingersoll@Sun.COM NULL);
3586*12720SWyllys.Ingersoll@Sun.COM
3587*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
3588*12720SWyllys.Ingersoll@Sun.COM }
3589*12720SWyllys.Ingersoll@Sun.COM }
3590*12720SWyllys.Ingersoll@Sun.COM }
3591*12720SWyllys.Ingersoll@Sun.COM else if (bSuccess) // non-AES key wrap
3592*12720SWyllys.Ingersoll@Sun.COM {
3593*12720SWyllys.Ingersoll@Sun.COM if (oResponse.Key.Key.__size != KMS_MAX_KEY_SIZE)
3594*12720SWyllys.Ingersoll@Sun.COM {
3595*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
3596*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
3597*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_PROTECT_AND_PROCESS_KEY_INVALID_KEY_LENGTH_RESPONSE,
3598*12720SWyllys.Ingersoll@Sun.COM NULL,
3599*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
3600*12720SWyllys.Ingersoll@Sun.COM NULL);
3601*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
3602*12720SWyllys.Ingersoll@Sun.COM }
3603*12720SWyllys.Ingersoll@Sun.COM else
3604*12720SWyllys.Ingersoll@Sun.COM {
3605*12720SWyllys.Ingersoll@Sun.COM memcpy(o_pKey->m_acKey,
3606*12720SWyllys.Ingersoll@Sun.COM oResponse.Key.Key.__ptr,
3607*12720SWyllys.Ingersoll@Sun.COM KMS_MAX_KEY_SIZE);
3608*12720SWyllys.Ingersoll@Sun.COM }
3609*12720SWyllys.Ingersoll@Sun.COM }
3610*12720SWyllys.Ingersoll@Sun.COM
3611*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
3612*12720SWyllys.Ingersoll@Sun.COM {
3613*12720SWyllys.Ingersoll@Sun.COM o_pKey->m_iKeyLength = KMS_MAX_KEY_SIZE;
3614*12720SWyllys.Ingersoll@Sun.COM
3615*12720SWyllys.Ingersoll@Sun.COM if (KMSAgentKeyCallout(o_pKey->m_acKey) != 0)
3616*12720SWyllys.Ingersoll@Sun.COM {
3617*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile,
3618*12720SWyllys.Ingersoll@Sun.COM AUDIT_CLIENT_AGENT_RETRIEVE_PROTECT_AND_PROCESS_KEY_KEY_CALLOUT_ERROR,
3619*12720SWyllys.Ingersoll@Sun.COM NULL,
3620*12720SWyllys.Ingersoll@Sun.COM NULL,
3621*12720SWyllys.Ingersoll@Sun.COM NULL);
3622*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
3623*12720SWyllys.Ingersoll@Sun.COM }
3624*12720SWyllys.Ingersoll@Sun.COM }
3625*12720SWyllys.Ingersoll@Sun.COM }
3626*12720SWyllys.Ingersoll@Sun.COM
3627*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
3628*12720SWyllys.Ingersoll@Sun.COM {
3629*12720SWyllys.Ingersoll@Sun.COM // add Key ID and the creating KMA IP address to the DU cache
3630*12720SWyllys.Ingersoll@Sun.COM CDataUnitCache* pDataUnitCache = (CDataUnitCache*) i_pProfile->m_pDataUnitCache;
3631*12720SWyllys.Ingersoll@Sun.COM
3632*12720SWyllys.Ingersoll@Sun.COM if (i_pProfile->m_iClusterDiscoveryFrequency != 0) // load balancing enabled
3633*12720SWyllys.Ingersoll@Sun.COM {
3634*12720SWyllys.Ingersoll@Sun.COM bSuccess = pDataUnitCache->Insert(
3635*12720SWyllys.Ingersoll@Sun.COM NULL,
3636*12720SWyllys.Ingersoll@Sun.COM 0,
3637*12720SWyllys.Ingersoll@Sun.COM o_pKey->m_acKeyID,
3638*12720SWyllys.Ingersoll@Sun.COM KMS_KEY_ID_SIZE,
3639*12720SWyllys.Ingersoll@Sun.COM pLoadBalancer->GetApplianceNetworkAddress(iIndex));
3640*12720SWyllys.Ingersoll@Sun.COM }
3641*12720SWyllys.Ingersoll@Sun.COM }
3642*12720SWyllys.Ingersoll@Sun.COM
3643*12720SWyllys.Ingersoll@Sun.COM // free allocated memory for output if error condition
3644*12720SWyllys.Ingersoll@Sun.COM // Clean up SOAP
3645*12720SWyllys.Ingersoll@Sun.COM
3646*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
3647*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
3648*12720SWyllys.Ingersoll@Sun.COM
3649*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
3650*12720SWyllys.Ingersoll@Sun.COM {
3651*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_OK);
3652*12720SWyllys.Ingersoll@Sun.COM }
3653*12720SWyllys.Ingersoll@Sun.COM
3654*12720SWyllys.Ingersoll@Sun.COM RETURN(KMSAgent_GetLastStatusCode(i_pProfile,
3655*12720SWyllys.Ingersoll@Sun.COM bClientAESKeyWrapSetupError ?
3656*12720SWyllys.Ingersoll@Sun.COM CAgentLoadBalancer::AES_KEY_WRAP_SETUP_ERROR : iIndex));
3657*12720SWyllys.Ingersoll@Sun.COM }
3658*12720SWyllys.Ingersoll@Sun.COM
3659*12720SWyllys.Ingersoll@Sun.COM extern "C"
KMSAgent_FreeArrayOfKeys(KMSAgent_ArrayOfKeys * i_pArrayOfKeys)3660*12720SWyllys.Ingersoll@Sun.COM void KMSAgent_FreeArrayOfKeys (
3661*12720SWyllys.Ingersoll@Sun.COM KMSAgent_ArrayOfKeys* i_pArrayOfKeys)
3662*12720SWyllys.Ingersoll@Sun.COM {
3663*12720SWyllys.Ingersoll@Sun.COM #if defined(METAWARE)
3664*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
3665*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE(trace, KMSAgent_FreeArrayOfKeys);
3666*12720SWyllys.Ingersoll@Sun.COM #endif
3667*12720SWyllys.Ingersoll@Sun.COM if (!i_pArrayOfKeys)
3668*12720SWyllys.Ingersoll@Sun.COM {
3669*12720SWyllys.Ingersoll@Sun.COM return;
3670*12720SWyllys.Ingersoll@Sun.COM }
3671*12720SWyllys.Ingersoll@Sun.COM
3672*12720SWyllys.Ingersoll@Sun.COM // free memory for all information groups
3673*12720SWyllys.Ingersoll@Sun.COM if (i_pArrayOfKeys->m_pKeys)
3674*12720SWyllys.Ingersoll@Sun.COM {
3675*12720SWyllys.Ingersoll@Sun.COM free(i_pArrayOfKeys->m_pKeys);
3676*12720SWyllys.Ingersoll@Sun.COM }
3677*12720SWyllys.Ingersoll@Sun.COM
3678*12720SWyllys.Ingersoll@Sun.COM free(i_pArrayOfKeys);
3679*12720SWyllys.Ingersoll@Sun.COM }
3680*12720SWyllys.Ingersoll@Sun.COM
3681*12720SWyllys.Ingersoll@Sun.COM /*---------------------------------------------------------------------------
3682*12720SWyllys.Ingersoll@Sun.COM * Function: KMSAgent_CreateAuditLog
3683*12720SWyllys.Ingersoll@Sun.COM *
3684*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/
3685*12720SWyllys.Ingersoll@Sun.COM extern "C"
KMSAgent_CreateAuditLog(KMSClientProfile * i_pProfile,enum KMS_AUDIT_LOG_RETENTION i_iRetention,enum KMS_AUDIT_LOG_CONDITION i_iCondition,int i_bIssueAlert,utf8cstr i_pMessage)3686*12720SWyllys.Ingersoll@Sun.COM KMS_AGENT_STATUS KMSAgent_CreateAuditLog (
3687*12720SWyllys.Ingersoll@Sun.COM KMSClientProfile* i_pProfile,
3688*12720SWyllys.Ingersoll@Sun.COM enum KMS_AUDIT_LOG_RETENTION i_iRetention,
3689*12720SWyllys.Ingersoll@Sun.COM enum KMS_AUDIT_LOG_CONDITION i_iCondition,
3690*12720SWyllys.Ingersoll@Sun.COM int i_bIssueAlert,
3691*12720SWyllys.Ingersoll@Sun.COM utf8cstr i_pMessage)
3692*12720SWyllys.Ingersoll@Sun.COM {
3693*12720SWyllys.Ingersoll@Sun.COM bool bSuccess = true;
3694*12720SWyllys.Ingersoll@Sun.COM #ifdef DEBUG_TIMING
3695*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
3696*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE(trace, KMSAgent_CreateAuditLog);
3697*12720SWyllys.Ingersoll@Sun.COM #endif
3698*12720SWyllys.Ingersoll@Sun.COM
3699*12720SWyllys.Ingersoll@Sun.COM // START_STACK_CHECK;
3700*12720SWyllys.Ingersoll@Sun.COM
3701*12720SWyllys.Ingersoll@Sun.COM if (!i_pProfile)
3702*12720SWyllys.Ingersoll@Sun.COM {
3703*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_CREATED_AUDIT_LOG_INVALID_PARAMETERS,
3704*12720SWyllys.Ingersoll@Sun.COM NULL,
3705*12720SWyllys.Ingersoll@Sun.COM NULL,
3706*12720SWyllys.Ingersoll@Sun.COM "Profile arg");
3707*12720SWyllys.Ingersoll@Sun.COM
3708*12720SWyllys.Ingersoll@Sun.COM // END_STACK_CHECK;
3709*12720SWyllys.Ingersoll@Sun.COM
3710*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
3711*12720SWyllys.Ingersoll@Sun.COM }
3712*12720SWyllys.Ingersoll@Sun.COM
3713*12720SWyllys.Ingersoll@Sun.COM // check arguments
3714*12720SWyllys.Ingersoll@Sun.COM if (i_iRetention > KMS_AUDIT_LOG_SHORT_TERM_RETENTION)
3715*12720SWyllys.Ingersoll@Sun.COM {
3716*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_CREATE_AUDIT_LOG_INVALID_PARAMETERS,
3717*12720SWyllys.Ingersoll@Sun.COM NULL,
3718*12720SWyllys.Ingersoll@Sun.COM NULL,
3719*12720SWyllys.Ingersoll@Sun.COM "Retention arg");
3720*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
3721*12720SWyllys.Ingersoll@Sun.COM }
3722*12720SWyllys.Ingersoll@Sun.COM
3723*12720SWyllys.Ingersoll@Sun.COM if (i_iCondition > KMS_AUDIT_LOG_WARNING_CONDITION)
3724*12720SWyllys.Ingersoll@Sun.COM {
3725*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_CREATE_AUDIT_LOG_INVALID_PARAMETERS,
3726*12720SWyllys.Ingersoll@Sun.COM NULL,
3727*12720SWyllys.Ingersoll@Sun.COM NULL,
3728*12720SWyllys.Ingersoll@Sun.COM "Condition arg");
3729*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
3730*12720SWyllys.Ingersoll@Sun.COM }
3731*12720SWyllys.Ingersoll@Sun.COM
3732*12720SWyllys.Ingersoll@Sun.COM if (!i_pMessage || (strlen(i_pMessage) <= 0))
3733*12720SWyllys.Ingersoll@Sun.COM {
3734*12720SWyllys.Ingersoll@Sun.COM Log(AUDIT_CLIENT_AGENT_CREATE_AUDIT_LOG_INVALID_PARAMETERS,
3735*12720SWyllys.Ingersoll@Sun.COM NULL,
3736*12720SWyllys.Ingersoll@Sun.COM NULL,
3737*12720SWyllys.Ingersoll@Sun.COM "Message arg");
3738*12720SWyllys.Ingersoll@Sun.COM // END_STACK_CHECK;
3739*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_INVALID_PARAMETER);
3740*12720SWyllys.Ingersoll@Sun.COM }
3741*12720SWyllys.Ingersoll@Sun.COM if (!KMSClient_ProfileLoaded(i_pProfile))
3742*12720SWyllys.Ingersoll@Sun.COM {
3743*12720SWyllys.Ingersoll@Sun.COM // END_STACK_CHECK;
3744*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_PROFILE_NOT_LOADED);
3745*12720SWyllys.Ingersoll@Sun.COM }
3746*12720SWyllys.Ingersoll@Sun.COM
3747*12720SWyllys.Ingersoll@Sun.COM CAutoMutex oAutoMutex((K_MUTEX_HANDLE) i_pProfile->m_pLock);
3748*12720SWyllys.Ingersoll@Sun.COM
3749*12720SWyllys.Ingersoll@Sun.COM struct soap* pstSoap = (struct soap*) i_pProfile->m_pvSoap;
3750*12720SWyllys.Ingersoll@Sun.COM
3751*12720SWyllys.Ingersoll@Sun.COM // Create Audit Log
3752*12720SWyllys.Ingersoll@Sun.COM
3753*12720SWyllys.Ingersoll@Sun.COM KMS_Agent::KMS_Agent__CreateAuditLogResponse oResponse;
3754*12720SWyllys.Ingersoll@Sun.COM
3755*12720SWyllys.Ingersoll@Sun.COM CAgentLoadBalancer *pLoadBalancer =
3756*12720SWyllys.Ingersoll@Sun.COM (CAgentLoadBalancer *) i_pProfile->m_pAgentLoadBalancer;
3757*12720SWyllys.Ingersoll@Sun.COM
3758*12720SWyllys.Ingersoll@Sun.COM int iIndex = pLoadBalancer->Balance();
3759*12720SWyllys.Ingersoll@Sun.COM if (iIndex >= 0)
3760*12720SWyllys.Ingersoll@Sun.COM {
3761*12720SWyllys.Ingersoll@Sun.COM do
3762*12720SWyllys.Ingersoll@Sun.COM {
3763*12720SWyllys.Ingersoll@Sun.COM const char* sURL = pLoadBalancer->
3764*12720SWyllys.Ingersoll@Sun.COM GetHTTPSURL(iIndex, i_pProfile->m_iPortForAgentService);
3765*12720SWyllys.Ingersoll@Sun.COM strncpy(i_pProfile->m_sURL, sURL, sizeof(i_pProfile->m_sURL));
3766*12720SWyllys.Ingersoll@Sun.COM i_pProfile->m_sURL[sizeof(i_pProfile->m_sURL)-1] = '\0';
3767*12720SWyllys.Ingersoll@Sun.COM
3768*12720SWyllys.Ingersoll@Sun.COM bSuccess = KMS_Agent::soap_call_KMS_Agent__CreateAuditLog(
3769*12720SWyllys.Ingersoll@Sun.COM pstSoap,
3770*12720SWyllys.Ingersoll@Sun.COM sURL,
3771*12720SWyllys.Ingersoll@Sun.COM NULL,
3772*12720SWyllys.Ingersoll@Sun.COM (enum KMS_Agent::KMS_Agent__AuditLogRetention)i_iRetention,
3773*12720SWyllys.Ingersoll@Sun.COM (enum KMS_Agent::KMS_Agent__AuditLogCondition)i_iCondition,
3774*12720SWyllys.Ingersoll@Sun.COM i_bIssueAlert ? true : false,
3775*12720SWyllys.Ingersoll@Sun.COM i_pMessage,
3776*12720SWyllys.Ingersoll@Sun.COM oResponse) == SOAP_OK;
3777*12720SWyllys.Ingersoll@Sun.COM
3778*12720SWyllys.Ingersoll@Sun.COM
3779*12720SWyllys.Ingersoll@Sun.COM if (!bSuccess)
3780*12720SWyllys.Ingersoll@Sun.COM {
3781*12720SWyllys.Ingersoll@Sun.COM char sSoapFaultMsg[g_iMAX_SOAP_FAULT_MESSAGE_LENGTH];
3782*12720SWyllys.Ingersoll@Sun.COM char sKmaAddress[g_iMAX_PEER_NETWORK_ADDRESS_LENGTH];
3783*12720SWyllys.Ingersoll@Sun.COM
3784*12720SWyllys.Ingersoll@Sun.COM GetSoapFault(sSoapFaultMsg, pstSoap);
3785*12720SWyllys.Ingersoll@Sun.COM GetPeerNetworkAddress(sKmaAddress, pstSoap);
3786*12720SWyllys.Ingersoll@Sun.COM
3787*12720SWyllys.Ingersoll@Sun.COM iIndex = pLoadBalancer->FailOver(iIndex, pstSoap);
3788*12720SWyllys.Ingersoll@Sun.COM
3789*12720SWyllys.Ingersoll@Sun.COM LogError(i_pProfile, AUDIT_CLIENT_AGENT_CREATE_AUDIT_LOG_SOAP_ERROR,
3790*12720SWyllys.Ingersoll@Sun.COM NULL,
3791*12720SWyllys.Ingersoll@Sun.COM sKmaAddress,
3792*12720SWyllys.Ingersoll@Sun.COM sSoapFaultMsg);
3793*12720SWyllys.Ingersoll@Sun.COM }
3794*12720SWyllys.Ingersoll@Sun.COM else
3795*12720SWyllys.Ingersoll@Sun.COM {
3796*12720SWyllys.Ingersoll@Sun.COM pLoadBalancer->UpdateResponseStatus(iIndex);
3797*12720SWyllys.Ingersoll@Sun.COM }
3798*12720SWyllys.Ingersoll@Sun.COM }
3799*12720SWyllys.Ingersoll@Sun.COM while (iIndex >= 0 && (!bSuccess));
3800*12720SWyllys.Ingersoll@Sun.COM }
3801*12720SWyllys.Ingersoll@Sun.COM else
3802*12720SWyllys.Ingersoll@Sun.COM {
3803*12720SWyllys.Ingersoll@Sun.COM bSuccess = false;
3804*12720SWyllys.Ingersoll@Sun.COM }
3805*12720SWyllys.Ingersoll@Sun.COM
3806*12720SWyllys.Ingersoll@Sun.COM // free allocated memory for output if error condition
3807*12720SWyllys.Ingersoll@Sun.COM // Clean up SOAP
3808*12720SWyllys.Ingersoll@Sun.COM
3809*12720SWyllys.Ingersoll@Sun.COM soap_destroy(pstSoap);
3810*12720SWyllys.Ingersoll@Sun.COM soap_end(pstSoap);
3811*12720SWyllys.Ingersoll@Sun.COM
3812*12720SWyllys.Ingersoll@Sun.COM if (bSuccess)
3813*12720SWyllys.Ingersoll@Sun.COM {
3814*12720SWyllys.Ingersoll@Sun.COM // END_STACK_CHECK;
3815*12720SWyllys.Ingersoll@Sun.COM RETURN(KMS_AGENT_STATUS_OK);
3816*12720SWyllys.Ingersoll@Sun.COM }
3817*12720SWyllys.Ingersoll@Sun.COM
3818*12720SWyllys.Ingersoll@Sun.COM // END_STACK_CHECK;
3819*12720SWyllys.Ingersoll@Sun.COM RETURN(KMSAgent_GetLastStatusCode(i_pProfile, iIndex));
3820*12720SWyllys.Ingersoll@Sun.COM }
3821*12720SWyllys.Ingersoll@Sun.COM
3822*12720SWyllys.Ingersoll@Sun.COM #ifdef KMSUSERPKCS12
3823*12720SWyllys.Ingersoll@Sun.COM /*
3824*12720SWyllys.Ingersoll@Sun.COM * This function allows the user to change the PIN on the PKCS12
3825*12720SWyllys.Ingersoll@Sun.COM * file that holds the clients private key and cert.
3826*12720SWyllys.Ingersoll@Sun.COM */
3827*12720SWyllys.Ingersoll@Sun.COM extern "C"
KMSAgent_ChangeLocalPWD(KMSClientProfile * i_pProfile,utf8cstr const i_pOldPassphrase,utf8cstr const i_pNewPassphrase)3828*12720SWyllys.Ingersoll@Sun.COM KMS_AGENT_STATUS KMSAgent_ChangeLocalPWD(
3829*12720SWyllys.Ingersoll@Sun.COM KMSClientProfile* i_pProfile,
3830*12720SWyllys.Ingersoll@Sun.COM utf8cstr const i_pOldPassphrase,
3831*12720SWyllys.Ingersoll@Sun.COM utf8cstr const i_pNewPassphrase)
3832*12720SWyllys.Ingersoll@Sun.COM {
3833*12720SWyllys.Ingersoll@Sun.COM CCertificate *pCert;
3834*12720SWyllys.Ingersoll@Sun.COM CPrivateKey *pKey;
3835*12720SWyllys.Ingersoll@Sun.COM bool bSuccess;
3836*12720SWyllys.Ingersoll@Sun.COM
3837*12720SWyllys.Ingersoll@Sun.COM pCert = new CCertificate;
3838*12720SWyllys.Ingersoll@Sun.COM pKey = new CPrivateKey;
3839*12720SWyllys.Ingersoll@Sun.COM
3840*12720SWyllys.Ingersoll@Sun.COM bSuccess = GetPKCS12CertAndKey(i_pProfile, i_pOldPassphrase,
3841*12720SWyllys.Ingersoll@Sun.COM pCert, pKey);
3842*12720SWyllys.Ingersoll@Sun.COM if (!bSuccess)
3843*12720SWyllys.Ingersoll@Sun.COM return(KMSAgent_GetLastStatusCode(i_pProfile, 0));
3844*12720SWyllys.Ingersoll@Sun.COM
3845*12720SWyllys.Ingersoll@Sun.COM bSuccess = StoreAgentPKI(i_pProfile, pCert, pKey, i_pNewPassphrase);
3846*12720SWyllys.Ingersoll@Sun.COM if (!bSuccess)
3847*12720SWyllys.Ingersoll@Sun.COM return(KMSAgent_GetLastStatusCode(i_pProfile, 0));
3848*12720SWyllys.Ingersoll@Sun.COM
3849*12720SWyllys.Ingersoll@Sun.COM return (KMS_AGENT_STATUS_OK);
3850*12720SWyllys.Ingersoll@Sun.COM }
3851*12720SWyllys.Ingersoll@Sun.COM #endif /* KMSUSERPKCS12 */
3852