Apache auth hook appears to work, but filter still not registered properly. Added...
[mod_auth_kerb.cvs/.git] / test / gssweb_client.pl~
1 #!/usr/bin/perl -w
2
3 use strict;
4 use WWW::Mechanize;
5 use GSSAPI;
6 use GSSAPI::OID;
7 use MIME::Base64;
8 use JSON;
9
10 sub parse_token($) {
11     my ($json) = @_;
12     my $ref = decode_json($json);
13     return $ref->{'gssweb'}{'token'};
14                 }
15
16
17 sub token_body($$) {
18     my ($target_server, $itoken) = @_;
19     my $status;
20     my $otoken;
21     my $target;
22   try: {
23      $status = GSSAPI::Name->import( $target,
24                                        $target_server,
25                                      GSSAPI::OID::gss_nt_hostbased_service) or last;
26      our  $ctx = GSSAPI::Context->new() unless $ctx;
27      my $mech;
28      $status = GSSAPI::OID->from_str($mech, '{ 1.3.6.1.5.5.15.1.1.17              }') or last;
29      my $iflags = GSSAPI::GSS_C_MUTUAL_FLAG | GSSAPI::GSS_C_SEQUENCE_FLAG | GSSAPI::GSS_C_REPLAY_FLAG;
30      my $bindings = GSS_C_NO_CHANNEL_BINDINGS;
31      my $creds = GSS_C_NO_CREDENTIAL;
32      my $itime = 0;
33
34              $status = $ctx->init($creds,$target,
35                                   $mech,$iflags,$itime,$bindings,$itoken,
36                                   undef, $otoken,undef,undef);
37     }
38     print "$status\n";
39     return undef unless $otoken;
40
41     my $out =  "token:" . encode_base64($otoken) ."nonce: 42\n";
42     print $out;
43     return $out;
44 }
45
46 my ($url, $gssname) = @ARGV;
47 my $www = WWW::Mechanize->new('autocheck' => 0);
48 my $done = 0;
49 my $response_token = undef;
50 unless ($done) {
51
52     $www->post($url, 'Content' => token_body($gssname, $response_token));
53     my $status = $www->status();
54     if ($status == 200) {
55         $done = 1;
56         print "authenticated: response is ".$www->content()."\n";
57         if (token_body($gssname, parse_token($www->content()))) {
58             print "Expecting gss success but did not get it!\n";
59         }
60     } elsif ($status == 401) {
61         print "Contiuning\n";
62         $response_token = parse_token($www->content());
63     } else {
64         print "Unexpected response status: $status\n";
65         print $www->content();
66     }
67 }