Path: blob/main/crypto/krb5/src/tests/gssapi/t_bindings.c
34907 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/*2* Copyright (C) 2020 by Red Hat, Inc.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* * Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11*12* * Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in14* the documentation and/or other materials provided with the15* distribution.16*17* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS20* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE21* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,22* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR24* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)25* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,26* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)27* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED28* OF THE POSSIBILITY OF SUCH DAMAGE.29*/3031#include <stdio.h>32#include <string.h>33#include <assert.h>3435#include "common.h"3637/*38* Establish contexts (without and with GSS_C_DCE_STYLE) with the default39* initiator name, a specified principal name as target name, initiator40* bindings, and acceptor bindings. If any call is unsuccessful, display an41* error message. Output "yes" or "no" to indicate whether the contexts were42* reported as channel-bound on the acceptor. Exit with status 0 if all43* operations are successful, or 1 if not.44*45* Usage: ./t_bindings [-s] [-b] targetname icb acb46*47* An icb or abc value of "-" will not specify channel bindings. The -s flag48* uses the SPNEGO mechanism instead of the krb5 mecanism. The -b flag49* includes GSS_C_CHANNEL_BOUND in req_flags, which requests strict enforcement50* of channel bindings by the acceptor.51*/5253int54main(int argc, char *argv[])55{56OM_uint32 client_flags = 0;57OM_uint32 minor, flags1, flags2;58gss_name_t target_name;59gss_ctx_id_t ictx, actx;60struct gss_channel_bindings_struct icb_data = {0}, acb_data = {0};61gss_channel_bindings_t icb = GSS_C_NO_CHANNEL_BINDINGS;62gss_channel_bindings_t acb = GSS_C_NO_CHANNEL_BINDINGS;63gss_OID_desc *mech = GSS_C_NO_OID;6465argv++;66argc--;6768if (*argv != NULL && strcmp(*argv, "-s") == 0) {69mech = &mech_spnego;70argv++;71argc--;72}7374if (*argv != NULL && strcmp(*argv, "-b") == 0) {75client_flags |= GSS_C_CHANNEL_BOUND_FLAG;76argv++;77argc--;78}7980if (mech == GSS_C_NO_OID)81mech = &mech_krb5;8283if (argc != 3) {84fprintf(stderr, "Usage: t_bindings [-s] [-b] targetname icb acb\n");85return 1;86}8788target_name = import_name(argv[0]);8990if (strcmp(argv[1], "-") != 0) {91icb_data.application_data.length = strlen(argv[1]);92icb_data.application_data.value = argv[1];93icb = &icb_data;94}9596if (strcmp(argv[2], "-") != 0) {97acb_data.application_data.length = strlen(argv[2]);98acb_data.application_data.value = argv[2];99acb = &acb_data;100}101102establish_contexts_ex(mech, GSS_C_NO_CREDENTIAL, GSS_C_NO_CREDENTIAL,103target_name, client_flags, &ictx, &actx, icb, acb,104&flags1, NULL, NULL, NULL);105106/* Try again with GSS_C_DCE_STYLE */107(void)gss_delete_sec_context(&minor, &ictx, NULL);108(void)gss_delete_sec_context(&minor, &actx, NULL);109110client_flags |= GSS_C_DCE_STYLE;111establish_contexts_ex(mech, GSS_C_NO_CREDENTIAL, GSS_C_NO_CREDENTIAL,112target_name, client_flags, &ictx, &actx, icb, acb,113&flags2, NULL, NULL, NULL);114assert((flags1 & GSS_C_CHANNEL_BOUND_FLAG) ==115(flags2 & GSS_C_CHANNEL_BOUND_FLAG));116printf("%s\n", (flags1 & GSS_C_CHANNEL_BOUND_FLAG) ? "yes" : "no");117118(void)gss_delete_sec_context(&minor, &ictx, NULL);119(void)gss_delete_sec_context(&minor, &actx, NULL);120(void)gss_release_name(&minor, &target_name);121122return 0;123}124125126