Path: blob/main/crypto/heimdal/appl/test/tcp_client.c
34879 views
/*1* Copyright (c) 1997 - 1999 Kungliga Tekniska Högskolan2* (Royal Institute of Technology, Stockholm, Sweden).3* All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8*9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11*12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* 3. Neither the name of the Institute nor the names of its contributors17* may be used to endorse or promote products derived from this software18* without specific prior written permission.19*20* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND21* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE22* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE23* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE24* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL25* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS26* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)27* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT28* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY29* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF30* SUCH DAMAGE.31*/3233#include "test_locl.h"34RCSID("$Id$");3536krb5_context context;3738static int39proto (int sock, const char *hostname, const char *service)40{41krb5_auth_context auth_context;42krb5_error_code status;43krb5_principal server;44krb5_data data;45krb5_data packet;46uint32_t len, net_len;4748status = krb5_auth_con_init (context, &auth_context);49if (status)50krb5_err (context, 1, status, "krb5_auth_con_init");5152status = krb5_auth_con_setaddrs_from_fd (context,53auth_context,54&sock);55if (status)56krb5_err (context, 1, status, "krb5_auth_con_setaddrs_from_fd");5758status = krb5_sname_to_principal (context,59hostname,60service,61KRB5_NT_SRV_HST,62&server);63if (status)64krb5_err (context, 1, status, "krb5_sname_to_principal");6566status = krb5_sendauth (context,67&auth_context,68&sock,69VERSION,70NULL,71server,72AP_OPTS_MUTUAL_REQUIRED,73NULL,74NULL,75NULL,76NULL,77NULL,78NULL);79if (status)80krb5_err (context, 1, status, "krb5_sendauth");8182data.data = "hej";83data.length = 3;8485krb5_data_zero (&packet);8687status = krb5_mk_safe (context,88auth_context,89&data,90&packet,91NULL);92if (status)93krb5_err (context, 1, status, "krb5_mk_safe");9495len = packet.length;96net_len = htonl(len);9798if (krb5_net_write (context, &sock, &net_len, 4) != 4)99err (1, "krb5_net_write");100if (krb5_net_write (context, &sock, packet.data, len) != len)101err (1, "krb5_net_write");102103data.data = "hemligt";104data.length = 7;105106krb5_data_free (&packet);107108status = krb5_mk_priv (context,109auth_context,110&data,111&packet,112NULL);113if (status)114krb5_err (context, 1, status, "krb5_mk_priv");115116len = packet.length;117net_len = htonl(len);118119if (krb5_net_write (context, &sock, &net_len, 4) != 4)120err (1, "krb5_net_write");121if (krb5_net_write (context, &sock, packet.data, len) != len)122err (1, "krb5_net_write");123return 0;124}125126int127main(int argc, char **argv)128{129int port = client_setup(&context, &argc, argv);130return client_doit (argv[argc], port, service, proto);131}132133134