#include <iostream>

#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include "globus_gss_assist.h"
#include "tokens.h"

int main()
{
  assert(globus_module_activate(GLOBUS_GSI_GSSAPI_MODULE) == GLOBUS_SUCCESS);

  int sck = socket(AF_INET, SOCK_STREAM, 0);
  assert(sck != -1);

  struct sockaddr_in him;
  him.sin_family = AF_INET;

  struct hostent * hp;
  assert(hp = gethostbyname("datatag6.cnaf.infn.it"));
  him.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr))->s_addr;

  him.sin_port = htons(10001);

  assert(connect(sck, (struct sockaddr*)&him, sizeof(struct sockaddr_in)) != -1);

  OM_uint32 major = 0, minor = 0;

  gss_cred_id_t credential = GSS_C_NO_CREDENTIAL;

  major = globus_gss_assist_acquire_cred(&minor,
                                         GSS_C_BOTH,
                                         &credential);

  if(GSS_ERROR(major))
  {
    char * str = NULL;
    globus_gss_assist_display_status_str(&str,
                                         "Failed to acquire credentials : ",
                                         major, minor, 0);
    std::cout << str;
    exit(1);
  }

  gss_ctx_id_t context = GSS_C_NO_CONTEXT;
  char * service = "/C=IT/O=INFN/OU=Personal Certificate/L=CNAF/CN=Valerio Venturi/emailAddress=valerio.venturi@cnaf.infn.it";
  OM_uint32 req_flags = 0;
  OM_uint32 ret_flags = 0;
  int token_status = 0;
  gss_cred_id_t delegated_cred = GSS_C_NO_CREDENTIAL;

  major = globus_gss_assist_init_sec_context(&minor,
                                             credential,
                                             &context,
                                             service,
                                             req_flags,
                                             &ret_flags,
                                             &token_status,
                                             get_token,
                                             (void *) &sck,
                                             send_token,
                                             (void *) &sck);

  if(GSS_ERROR(major))
  {
    std::cout << "Major : " << minor << std::endl;
    std::cout << "Minor : " << major << std::endl;

    char * str = NULL;
    globus_gss_assist_display_status_str(&str,
                                         "Failed to establish security context : ",
                                         major, minor, 0);
    std::cout << str;
    exit(1);
  }

  if(service)
    std::cout << service << std::endl;


  gss_delete_sec_context(&minor,
                         &context,
                         GSS_C_NO_BUFFER);

  gss_release_cred(&minor,
                   &credential);

  assert(globus_module_deactivate(GLOBUS_GSI_GSSAPI_MODULE) == GLOBUS_SUCCESS);

}
Topic revision: r1 - 2006-07-13 - ValerioVenturi
 
TWIKI.NET
This site is powered by the TWiki collaboration platformCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback