~ubuntu-branches/ubuntu/maverick/eucalyptus/maverick

« back to all changes in this revision

Viewing changes to util/euca_auth.c

  • Committer: Bazaar Package Importer
  • Author(s): Dave Walker (Daviey)
  • Date: 2010-07-21 17:27:10 UTC
  • mfrom: (1.1.38 upstream)
  • Revision ID: james.westby@ubuntu.com-20100721172710-7xv07dmdqgivc3t9
Tags: 2.0~bzr1211-0ubuntu1
* New major upstream version merge, 2.0 (r1211).
* debian/patches/:
  - 01-wsdl-stubs.patch, debian/wsdl.md5sums: wsdl stubs updated.
  - 02-Makefile.patch: Updated to reflect new code layout.
  - 07-local_support_euca_conf-in.patch: Updated to reflect new code layout.
  - 08-ubuntu-default-networking.patch: Refreshed.
  - 09-small-128-192MB.patch: Updated to point to new location.
  - 10-disable-iscsi.patch: Refreshed.
  - 11-state-cleanup-memleakfix.patch: Removed, fixed upstream.
  - 15-fix-default-ramdisk.patch: Updated to point to new location.
  - 16-kvm_libvirt_xml_default_use_kvm.patch: Updated to reflect changes.
  - 17-fix_walrus_OOM_errors.patch: Removed, fixed upstream.
  - 18-priv_security.patch: Updated to reflect upstream changes.
  - 20-brute-force-webui.patch: Updated to reflect upstream changes. 
  - 21-eucalyptus-1.7-with-gwt-1.6.4.patch: New patch, allows 
    eucalyptus-1.7 to be built against gwt 1.6.4. Based on patch courtesy 
    of Dmitrii Zagorodnov, upstream. (LP: #597330)
* debian/eucalyptus-java-common.links: 
  - Changed symlink for groovy, point to groovy.all.jar, making compatiable 
    with groovy versions >1.7. (LP: #595421)
  - Added ant.jar & jetty-rewrite-handler.jar as they are now required.
* debian/control
  - & debian/build-jars: Added libjavassist-java and libjetty-extra-java as 
    build dependencies.
  - Added libjetty-extra-java as a dependency of eucalyptus-java-common
* The binary resulting jar's have been renamed from eucalyptus-*-1.6.2.jar
  to eucalyptus-*-main.jar:    
  - debian/eucalyptus-cc.upstart
  - debian/eucalyptus-cloud.install
  - debian/eucalyptus-common.eucalyptus.upstart
  - debian/eucalyptus-java-common.install
  - debian/eucalyptus-network.upstart
  - debian/eucalyptus-sc.install
  - debian/eucalyptus-walrus.install
* debian/eucalyptus-java-common.install: New upstream jars that have been
  installed:
  - eucalyptus-db-hsqldb-ext-main.jar
  - eucalyptus-component-main.jar
* debian/control:
  - Updated Standards Version to 3.8.4 (no change)
  - Updated the upstream Homepage to: http://open.eucalyptus.com/
  - Changed Vcs-Bzr to reflect new location of Ubuntu hosted development branch.
  - Made the Build Dependency of groovy and the binary eucalyptus-java-common
    package depend on version >=1.7.

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
  WITHDRAWAL OF THE CODE CAPABILITY TO THE EXTENT NEEDED TO COMPLY WITH
58
58
  ANY SUCH LICENSES OR RIGHTS.
59
59
*/
60
 
/* BRIEF EXAMPLE MSG:
61
 
<soapenv:Envelope>.
62
 
  <soapenv:Header>
63
 
    [..snip..]
64
 
    <wsse:Security>
65
 
      [..snip..]
66
 
      <wsse:BinarySecurityToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
67
 
                              EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"
68
 
                              ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"
69
 
                              wsu:Id="CertId-469">[..snip..]</wsse:BinarySecurityToken>
70
 
      [..snip..]
71
 
      <ds:Signature>
72
 
        <ds:KeyInfo Id="KeyId-374652">
73
 
          <wsse:SecurityTokenReference xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="STRId-22112351">
74
 
            <!-- this thing points to the wsse:BinarySecurityToken above -->
75
 
            <wsse:Reference URI="#CertId-469" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
76
 
          </wsse:SecurityTokenReference>
77
 
        </ds:KeyInfo>
78
 
      </ds:Signature>
79
 
    </wsse:Security>
80
 
  </soapenv:Header>
81
 
  <soapenv:Body>...</soapenv:Body>
82
 
</soapenv:Envelope>.
83
 
*/
84
60
 
85
61
#include <sys/types.h>
 
62
#define _FILE_OFFSET_BITS 64
86
63
#include <sys/stat.h>
87
64
#include <unistd.h>
88
65
#include <assert.h>
95
72
#include <openssl/pem.h>
96
73
#include <openssl/bio.h>
97
74
#include <openssl/evp.h>
 
75
 
98
76
#include "euca_auth.h"
99
77
#include "misc.h" /* get_string_stats, logprintf */
100
78
 
101
 
#ifndef NO_AXIS /* for compiling on systems without Axis */
102
 
#include "oxs_axiom.h"
103
 
#include "oxs_x509_cert.h"
104
 
#include "oxs_key_mgr.h"
105
 
#include "rampart_handler_util.h"
106
 
#include "rampart_sec_processed_result.h"
107
 
#include "rampart_error.h"
108
 
#include "axis2_op_ctx.h"
109
 
#include "rampart_context.h"
110
 
 
111
 
#define NO_U_FAIL(x) do{ \
112
 
AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[rampart][eucalyptus-verify] " #x );\
113
 
AXIS2_ERROR_SET(env->error, RAMPART_ERROR_FAILED_AUTHENTICATION, AXIS2_FAILURE);\
114
 
return AXIS2_FAILURE; \
115
 
}while(0)
116
 
 
117
 
axis2_status_t __euca_authenticate(const axutil_env_t *env,axis2_msg_ctx_t *out_msg_ctx, axis2_op_ctx_t *op_ctx)
118
 
{
119
 
  //***** First get the message context before doing anything dumb w/ a NULL pointer *****/
120
 
  axis2_msg_ctx_t *msg_ctx = NULL; //<--- incoming msg context, it is NULL, see?
121
 
  msg_ctx = axis2_op_ctx_get_msg_ctx(op_ctx, env, AXIS2_WSDL_MESSAGE_LABEL_IN);  
122
 
 
123
 
  //***** Print everything from the security results, just for testing now *****//
124
 
  rampart_context_t *rampart_context = NULL;
125
 
  axutil_property_t *property = NULL;
126
 
 
127
 
  property = axis2_msg_ctx_get_property(msg_ctx, env, RAMPART_CONTEXT);
128
 
  if(property)
129
 
  {
130
 
     rampart_context = (rampart_context_t *)axutil_property_get_value(property, env);
131
 
     //     AXIS2_LOG_CRITICAL(env->log,AXIS2_LOG_SI," ======== PRINTING PROCESSED WSSEC TOKENS ======== ");
132
 
     rampart_print_security_processed_results_set(env,msg_ctx);
133
 
  }
134
 
 
135
 
  //***** Extract Security Node from header from enveloper from msg_ctx *****//
136
 
  axiom_soap_envelope_t *soap_envelope = NULL;
137
 
  axiom_soap_header_t *soap_header = NULL;
138
 
  axiom_node_t *sec_node = NULL;
139
 
 
140
 
 
141
 
  soap_envelope = axis2_msg_ctx_get_soap_envelope(msg_ctx, env);
142
 
  if(!soap_envelope) NO_U_FAIL("SOAP envelope cannot be found."); 
143
 
  soap_header = axiom_soap_envelope_get_header(soap_envelope, env);
144
 
  if (!soap_header) NO_U_FAIL("SOAP header cannot be found.");
145
 
  sec_node = rampart_get_security_header(env, msg_ctx, soap_header); // <---- here it is!
146
 
  if(!sec_node)NO_U_FAIL("No node wsse:Security -- required: ws-security");
147
 
 
148
 
  //***** Find the wsse:Reference to the BinarySecurityToken *****//
149
 
  //** Path is: Security/
150
 
  //** *sec_node must be non-NULL, kkthx **//
151
 
  axiom_node_t *sig_node = NULL;
152
 
  axiom_node_t *key_info_node = NULL;
153
 
  axiom_node_t *sec_token_ref_node = NULL;
154
 
  /** the ds:Signature node **/
155
 
  sig_node = oxs_axiom_get_first_child_node_by_name(env,sec_node, OXS_NODE_SIGNATURE, OXS_DSIG_NS, OXS_DS );
156
 
  if(!sig_node)NO_U_FAIL("No node ds:Signature -- required: signature");
157
 
  /** the ds:KeyInfo **/
158
 
  key_info_node = oxs_axiom_get_first_child_node_by_name(env, sig_node, OXS_NODE_KEY_INFO, OXS_DSIG_NS, NULL );
159
 
  if(!key_info_node)NO_U_FAIL("No node ds:KeyInfo -- required: signature key");
160
 
  /** the wsse:SecurityTokenReference **/ 
161
 
  sec_token_ref_node = oxs_axiom_get_first_child_node_by_name(env, key_info_node,OXS_NODE_SECURITY_TOKEN_REFRENCE, OXS_WSSE_XMLNS, NULL);
162
 
  if(!sec_token_ref_node)NO_U_FAIL("No node wsse:SecurityTokenReference -- required: signing token");
163
 
  //** in theory this is the branching point for supporting all kinds of tokens -- we only do BST Direct Reference **/
164
 
 
165
 
  //***** Find the wsse:Reference to the BinarySecurityToken *****//
166
 
  //** *sec_token_ref_node must be non-NULL **/
167
 
  axis2_char_t *ref = NULL;
168
 
  axis2_char_t *ref_id = NULL;
169
 
  axiom_node_t *token_ref_node = NULL;
170
 
  axiom_node_t *bst_node = NULL;
171
 
  /** the wsse:Reference node **/
172
 
  token_ref_node = oxs_axiom_get_first_child_node_by_name(env, sec_token_ref_node,OXS_NODE_REFERENCE, OXS_WSSE_XMLNS, NULL);
173
 
  /** pull out the name of the BST node **/
174
 
  ref = oxs_token_get_reference(env, token_ref_node);
175
 
  ref_id = axutil_string_substring_starting_at(axutil_strdup(env, ref), 1);
176
 
  /** get the wsse:BinarySecurityToken used to sign the message **/
177
 
  bst_node = oxs_axiom_get_node_by_id(env, sec_node, "Id", ref_id, OXS_WSU_XMLNS);
178
 
  if(!bst_node){oxs_error(env, OXS_ERROR_LOCATION, OXS_ERROR_ELEMENT_FAILED, "Error retrieving elementwith ID=%s", ref_id);NO_U_FAIL("Cant find the required node");}
179
 
 
180
 
 
181
 
  //***** Find the wsse:Reference to the BinarySecurityToken *****//
182
 
  //** *bst_node must be non-NULL **/
183
 
  axis2_char_t *data = NULL;
184
 
  oxs_x509_cert_t *_cert = NULL;
185
 
  oxs_x509_cert_t *recv_cert = NULL;
186
 
  axis2_char_t *file_name = NULL;
187
 
  axis2_char_t *recv_x509_buf = NULL;
188
 
  axis2_char_t *msg_x509_buf = NULL;
189
 
 
190
 
  /** pull out the data from the BST **/
191
 
  data = oxs_axiom_get_node_content(env, bst_node);
192
 
  /** create an oxs_X509_cert **/
193
 
  _cert = oxs_key_mgr_load_x509_cert_from_string(env, data);
194
 
  if(_cert)
195
 
  {
196
 
    //***** FINALLY -- we have the certificate used to sign the message.  authenticate it HERE *****//
197
 
    msg_x509_buf = oxs_x509_cert_get_data(_cert,env);
198
 
    if(!msg_x509_buf)NO_U_FAIL("OMG WHAT NOW?!");
199
 
    /*
200
 
    recv_x509_buf = (axis2_char_t *)rampart_context_get_receiver_certificate(rampart_context, env);
201
 
    if(recv_x509_buf)
202
 
        recv_cert = oxs_key_mgr_load_x509_cert_from_string(env, recv_x509_buf);
203
 
    else
204
 
    {
205
 
        file_name = rampart_context_get_receiver_certificate_file(rampart_context, env);
206
 
        if(!file_name) NO_U_FAIL("Policy for the service is incorrect -- ReceiverCertificate is not set!!");
207
 
        if (check_file(file_name)) NO_U_FAIL("No cert file ($EUCALYPTUS/var/lib/eucalyptus/keys/cloud-cert.pem) found, failing");
208
 
        recv_cert = oxs_key_mgr_load_x509_cert_from_pem_file(env, file_name);
209
 
    }
210
 
    */
211
 
 
212
 
    file_name = rampart_context_get_receiver_certificate_file(rampart_context, env);
213
 
    if(!file_name) NO_U_FAIL("Policy for the service is incorrect -- ReceiverCertificate is not set!!");
214
 
    if (check_file(file_name)) NO_U_FAIL("No cert file ($EUCALYPTUS/var/lib/eucalyptus/keys/cloud-cert.pem) found, failing");
215
 
    recv_cert = oxs_key_mgr_load_x509_cert_from_pem_file(env, file_name);
216
 
 
217
 
    if (recv_cert) {
218
 
      recv_x509_buf = oxs_x509_cert_get_data(recv_cert,env);
219
 
    } else {
220
 
      NO_U_FAIL("could not populate receiver cert");
221
 
    }
222
 
 
223
 
    if( axutil_strcmp(recv_x509_buf,msg_x509_buf)!=0){
224
 
      AXIS2_LOG_CRITICAL(env->log,AXIS2_LOG_SI," --------- Received x509 certificate value ---------" );
225
 
      AXIS2_LOG_CRITICAL(env->log,AXIS2_LOG_SI, msg_x509_buf );
226
 
      AXIS2_LOG_CRITICAL(env->log,AXIS2_LOG_SI," --------- Local x509 certificate value! ---------" );
227
 
      AXIS2_LOG_CRITICAL(env->log,AXIS2_LOG_SI, recv_x509_buf );
228
 
      AXIS2_LOG_CRITICAL(env->log,AXIS2_LOG_SI," ---------------------------------------------------" );
229
 
      NO_U_FAIL("The certificate specified is invalid!");
230
 
    }
231
 
  }
232
 
  else 
233
 
  {
234
 
    oxs_error(env, OXS_ERROR_LOCATION, OXS_ERROR_DEFAULT, "Cannot load certificate from string =%s", data); 
235
 
    NO_U_FAIL("Failed to build certificate from BinarySecurityToken");
236
 
  }
237
 
  oxs_x509_cert_free(_cert, env);
238
 
  oxs_x509_cert_free(recv_cert, env);
239
 
  return AXIS2_SUCCESS;
240
 
 
241
 
}
242
 
#endif /* NO_AXIS */
243
 
 
244
79
static int initialized = 0;
245
80
 
246
81
#define FILENAME 512