-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathmyproxy-test
executable file
·2390 lines (2243 loc) · 70.3 KB
/
myproxy-test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl -w
# myproxy test script
# written by Jim Basney <jbasney@ncsa.uiuc.edu>
# Assumes myproxy-server running as root on the local machine if
# MYPROXY_SERVER not set.
# Requires a valid proxy credential with lifetime of at least 3 hours
# unless the -generatecerts option is used
# Assumes myproxy-server.config has default policy.
#
# Some tests only run if -startserver is given.
use File::Temp qw(tempdir);
use File::Copy;
use IPC::Open3;
use Socket;
$tmpdir = tempdir(CLEANUP => 1);
my $openssl = $ENV{OPENSSL} || "openssl";
$PROXYBITS = "-bits 2048";
#
# handle cmdline options
#
$usage = "usage: myproxy-test [-help] [-verbose] [-startserver]\n" .
" [-performance iterations clients]\n" .
" [-dbperformance] [-valgrind]\n" .
" [-generatecerts]\n" ;
$startserver = 0;
$performance = 0;
$dbperformance = 0;
$perfiters = 0;
$perfclients = 0;
$verbose = 0;
$generatecerts = 0;
while (($arg = shift @ARGV)) {
if ($arg eq "-h" || $arg eq "-help") {
print STDERR $usage;
exit 1;
} elsif ($arg eq "-v" || $arg eq "-verbose") {
$verbose = 1;
} elsif ($arg eq "-startserver") {
$startserver = 1;
} elsif ($arg eq "-performance") {
$performance = 1;
$perfiters = shift @ARGV;
$perfclients = shift @ARGV;
} elsif ($arg eq "-dbperformance") {
$dbperformance = 1;
} elsif ($arg eq "-valgrind") {
chomp($valgrind = `which valgrind 2>/dev/null`);
die "valgrind not in PATH, stopped" if (!(-x $valgrind));
&write_valgrind_supp();
$valgrind .= " --leak-check=full";
$valgrind .= " --suppressions=$tmpdir/valgrind.supp";
$valgrind .= " --undef-value-errors=no";
$valgrind .= " --gen-suppressions=all";
$valgrind .= " --num-callers=50 -q ";
} elsif ($arg eq "-generatecerts" ) {
$generatecerts = 1;
} else {
print STDERR $usage;
exit 1;
}
}
#
# If generatecerts option is specified then create
# a private CA and proxy locally and use them.
if ( $generatecerts) {
die("-generatecerts option requires -startserver option") unless ($startserver);
my $privcerts = "$tmpdir/privcerts.$$" ;
print STDERR "creating a CA in ", $privcerts, "\n" if ($verbose);
mkdir("$privcerts") ||
die("failed to create $privcerts directory, stopped") ;
open(SSLCNF, ">$privcerts/openssl.cnf") ||
die("failed to create $privcerts/openssl.cnf: $!");
print SSLCNF <<EOF;
[ ca ]
default_ca = CA_default # The default ca section
[ CA_default ]
dir = $privcerts # top dir
database = $privcerts/index.txt # index file.
new_certs_dir = $privcerts/ # new certs dir
certificate = $privcerts/cacert.pem # The CA cert
serial = $privcerts/serial # serial no file
private_key = $privcerts/cakey.pem # CA private key
RANDFILE = $privcerts/.rand # random number file
default_md = default
[ req ]
default_bits = 2048
default_md = sha256
distinguished_name = req_distinguished_name
[ req_distinguished_name ]
commonName = Common Name (hostname, IP, or your name)
commonName_max = 64
[ v3_ca ]
basicConstraints = CA:TRUE
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer:always
[ policy_anything ]
commonName = supplied
EOF
close(SSLCNF);
open(CAINDEX,">$privcerts/index.txt") ||
die("failed to create $privcerts/index.txt");
close(CAINDEX);
open(SERIAL,">$privcerts/serial") ||
die("failed to create $privcerts/serial");
print SERIAL "01\n";
close(SERIAL);
&runcmd("$openssl req -batch -subj '/CN=MyProxy Test CA' -config $privcerts/openssl.cnf -new -x509 -extensions v3_ca -nodes -keyout $privcerts/cakey.pem -out $privcerts/cacert.pem -days 30");
chomp($hash = `$openssl x509 -in $privcerts/cacert.pem -hash -noout`) ;
mkdir("$privcerts/grid-security") ||
die("failed to create $privcerts/grid-security");
copy("$privcerts/cacert.pem","$privcerts/grid-security/$hash.0") ||
die("failed to copy $privcerts/cacert.pem","$privcerts/grid-security/$hash.0");
open(POLICY,">$privcerts/grid-security/$hash.signing_policy") ||
die("failed to create $privcerts/grid-security/$hash.signing_policy");
print POLICY "access_id_CA X509 '/CN=MyProxy Test CA'\n";
print POLICY "pos_rights globus CA:sign\n";
print POLICY "cond_subjects globus '\"/*\"'\n";
close(POLICY);
print STDERR "creating a user certificate request ", $privcerts, "\n" if ($verbose);
&runcmd("$openssl req -batch -subj '/CN=MyProxy Test User' -config $privcerts/openssl.cnf -new -nodes -keyout $privcerts/userkey.pem -out $privcerts/usercert.csr -days 7") ;
print STDERR "signing user certificate with by CA in ", $privcerts, "\n" if ($verbose);
&runcmd("$openssl ca -batch -days 7 -config $privcerts/openssl.cnf -policy policy_anything -out $privcerts/usercert.pem -infiles $privcerts/usercert.csr");
chmod(oct("0600"),"$privcerts/userkey.pem","$privcerts/usercert.pem") ||
die("failed to chmod $privcerts/userkey.pem or $privcerts/usercert.pem");
$ENV{'X509_USER_CERT'} = "$privcerts/usercert.pem" ;
$ENV{'X509_USER_KEY'} = "$privcerts/userkey.pem" ;
$ENV{'X509_CERT_DIR'} = "$privcerts/grid-security" ;
print STDERR "generating a user proxy\n" if ($verbose);
chomp($grid_proxy_init = `which grid-proxy-init 2>/dev/null`);
die "grid-proxy-init not found, stopped" if (!(-x $grid_proxy_init));
&runcmd("$grid_proxy_init -debug $PROXYBITS");
} #end of generatecerts.
#
# make sure I have a valid proxy
#
chomp($grid_proxy_init = `which grid-proxy-init 2>/dev/null`);
die "grid-proxy-init not found, stopped" if (!(-x $grid_proxy_init));
chomp($grid_proxy_info = `which grid-proxy-info 2>/dev/null`);
die "grid-proxy-info not found, stopped" if (!(-x $grid_proxy_info));
chomp($grid_cert_info = `which grid-cert-info 2>/dev/null`);
die "grid-cert-info not found, stopped" if (!(-x $grid_cert_info));
$timeleft = `$grid_proxy_info -timeleft 2>/dev/null`;
if (!defined($timeleft) || $timeleft eq "" || ($timeleft < 60*60*3)) {
&debug("Problem with proxy. Will try to create a new one.");
`$grid_proxy_init $PROXYBITS -pwstdin </dev/null >/dev/null 2>&1`;
$timeleft = `$grid_proxy_info -timeleft 2>/dev/null`;
}
if (!defined($timeleft) || $timeleft eq "") {
print STDERR "grid-proxy-info failed:\n";
system("$grid_proxy_info -timeleft"); # show the error
die "stopped";
}
die "proxy expired, stopped" if ($timeleft < 60);
die "proxy lifetime too short, stopped" if ($timeleft < 60*60*6);
die "proxy is limited, stopped" if (`$grid_proxy_info -type` =~ /limited/);
chomp($cert_subject = `$grid_proxy_info -identity`);
die "grid-proxy-info -identity failed, stopped"
if (!defined($cert_subject) || $cert_subject eq "");
chomp($proxy_path = `$grid_proxy_info -path 2>/dev/null`);
die "grid-proxy-info -path failed, stopped" if (!(-e $proxy_path));
($exitstatus, $output) = &verifyproxy($proxy_path);
if ($exitstatus) {
print STDERR $output;
die if ($exitstatus);
}
#
# check for the commands I want to run
#
chomp($myproxy_store = `which myproxy-store 2>/dev/null`);
die "myproxy-store not in PATH, stopped" if (!(-x $myproxy_store));
chomp($myproxy_init = `which myproxy-init 2>/dev/null`);
die "myproxy-init not in PATH, stopped" if (!(-x $myproxy_init));
chomp($myproxy_retrieve = `which myproxy-retrieve 2>/dev/null`);
die "myproxy-retrieve not in PATH, stopped" if (!(-x $myproxy_retrieve));
chomp($myproxy_info = `which myproxy-info 2>/dev/null`);
die "myproxy-info not in PATH, stopped" if (!(-x $myproxy_info));
chomp($myproxy_destroy = `which myproxy-destroy 2>/dev/null`);
die "myproxy-destroy not in PATH, stopped" if (!(-x $myproxy_destroy));
chomp($myproxy_get = `which myproxy-logon 2>/dev/null`);
die "myproxy-logon not in PATH, stopped" if (!(-x $myproxy_get));
chomp($myproxy_passwd = `which myproxy-change-pass-phrase 2>/dev/null`);
die "myproxy-change-pass-phrase not in PATH, stopped"
if (!(-x $myproxy_passwd));
chomp($bintrue = `which true 2>/dev/null`);
#
# setup environment variables
#
if (!defined($ENV{'MYPROXY_SERVER'})) {
chomp($hostname = `hostname 2>/dev/null`);
$ENV{'MYPROXY_SERVER'} = $hostname;
}
if (!defined($ENV{'X509_USER_PROXY'})) {
$ENV{'X509_USER_PROXY'} = "/tmp/x509up_u$<";
}
# make proxy from existing proxy, so we don't need to deal with long-term cred
$ENV{'X509_USER_CERT'} = $ENV{'X509_USER_PROXY'};
$ENV{'X509_USER_KEY'} = $ENV{'X509_USER_PROXY'};
$ENV{'LOGNAME'} = $ENV{'USER'} if (!defined($ENV{'LOGNAME'}));
$ENV{'LOGNAME'} = $ENV{'LOGNAME'} . ".myproxy-test";
#
# make an independent proxy for a separate identity
#
$iproxyloc = "$tmpdir/iproxy.pem";
&runcmd("$grid_proxy_init $PROXYBITS -out $iproxyloc -independent -hours 0");
chomp($iproxysubject = `$grid_proxy_info -file $iproxyloc -identity`);
die "grid-proxy-info -file $iproxyloc -identity failed, stopped"
if (!defined($iproxysubject) || $iproxysubject eq "");
srand(time||$$);
$passphrase = sprintf "%010d", int(rand(0x7fffffff));
$trustrootdir = "$tmpdir/.globus/certificates.test.$$";
$origtrustrootdir = $ENV{'X509_CERT_DIR'} if defined($ENV{'X509_CERT_DIR'});
&opensslsanitycheck();
# all temporary files accessible only by running user
umask(0077);
#
# start server if requested
#
if ($startserver) {
$ENV{'MYPROXY_SERVER'} = "localhost";
$ENV{'MYPROXY_SERVER_DN'} = $cert_subject;
chomp($myproxy_server = `which myproxy-server 2>/dev/null`);
die "myproxy-server not in PATH, stopped" if (!(-x $myproxy_server));
$serverdir = "$tmpdir/myproxy-test.serverdir.$$";
mkdir($serverdir, 0700) ||
die "failed to create $serverdir, stopped";
$serverconf = "$tmpdir/myproxy-test.serverconf.$$";
open(CONF, ">$serverconf") ||
die "failed to open $serverconf, stopped";
print CONF "accepted_credentials \"*\"\n";
print CONF "authorized_retrievers \"*\"\n";
print CONF "default_retrievers \"*\"\n";
print CONF "authorized_renewers \"*\"\n";
print CONF "default_renewers \"none\"\n";
print CONF "authorized_key_retrievers \"*\"\n";
print CONF "default_key_retrievers \"none\"\n";
print CONF "trusted_retrievers \"*\"\n";
print CONF "default_trusted_retrievers \"none\"\n";
print CONF "passphrase_policy_program $bintrue\n" if (-x $bintrue);
print CONF "accepted_credentials_mapapp $bintrue\n" if (-x $bintrue);
print CONF "allow_self_authorization true\n"; # for renewal testing
print CONF "check_multiple_credentials true\n";
close(CONF);
$SERVERPIDFILE = "$tmpdir/myproxy-test.serverpid.$$";
$SERVERPORTFILE = "$tmpdir/myproxy-test.serverport.$$";
$servercmd = "$myproxy_server -s $serverdir -c $serverconf";
$servercmd .= " -l $ENV{'MYPROXY_SERVER'} -p 0";
$servercmd .= " -P $SERVERPIDFILE -z $SERVERPORTFILE";
if (defined($valgrind)) {
$valgrindlog = File::Temp::tempnam($tmpdir, "valgrind.log.");
$valgrindlogopt = " --log-file=$valgrindlog ";
$servercmd = $valgrind . $valgrindlogopt . $servercmd;
}
&debug("running '$servercmd'");
system($servercmd);
sleep(2); # give server a chance to startup
sleep(4) if (defined($valgrind)); # valgrind slows things down
if (open SERVERPIDFILE) {
chomp($serverpid = <SERVERPIDFILE>);
close SERVERPIDFILE;
}
if (!defined($serverpid) || $serverpid eq "") {
print STDERR "failed to start myproxy-server:\n";
system("$servercmd -d"); # send errors to STDERR
if (defined($valgrindlog) && -e $valgrindlog) {
print STDERR "valgrind log follows:\n";
system("cat $valgrindlog");
}
&docleanup();
exit 1;
}
if (open SERVERPORTFILE) {
chomp($serverport = <SERVERPORTFILE>);
close SERVERPORTFILE;
}
if (!defined($serverport) || $serverport eq "") {
print STDERR "myproxy-server didn't write portfile!\n";
&docleanup();
exit 1;
} else {
$ENV{'MYPROXY_SERVER_PORT'} = $serverport;
print STDERR "server listening on port ", $serverport, "\n" if ($verbose);
}
}
#
# run performance tests if requested
#
if ($performance) {
&doperftests();
exit 0;
}
#
# BEGIN TESTS
#
$SUCCESSES = $FAILURES = 0;
# commands to test: myproxy-init, myproxy-info, myproxy-destroy,
# myproxy-logon, and myproxy-change-pass-phrase
($exitstatus, $output) =
&runtest("myproxy-init -v -a -c 1 -t 1 -S",
$passphrase . "\n");
print "MyProxy Test 1 (store credential with default name): ";
if ($exitstatus == 0) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
print "Skipping remaining tests.\n";
goto end_of_all_tests;
}
($exitstatus, $output) = &runtest("myproxy-info -v", undef);
print "MyProxy Test 2 (get info for stored credential): ";
if ($exitstatus == 0 && $output =~ /username/) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
($exitstatus, $output) =
&runtest("myproxy-logon -t 1 -o $tmpdir/myproxy-test.$$ -v -S",
$passphrase . "\n");
print "MyProxy Test 3 (retrieve stored credential): ";
if ($exitstatus == 0) {
($exitstatus, $output) =
&verifyproxy("$tmpdir/myproxy-test.$$");
}
if ($exitstatus == 0) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
($exitstatus, $output) =
&runtest("myproxy-logon -t 1 -o - -v -S > $tmpdir/myproxy-test.$$",
$passphrase . "\n");
print "MyProxy Test 3- (retrieve stored credential to stdout): ";
if ($exitstatus == 0) {
($exitstatus, $output) =
&verifyproxy("$tmpdir/myproxy-test.$$");
}
if ($exitstatus == 0) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
($exitstatus, $output) =
&runtest("myproxy-logon -t 1 -N -v -S",
$passphrase . "\n");
print "MyProxy Test 3N (authenticate w/o retrieving credential): ";
if ($exitstatus == 0) {
($exitstatus, $output) =
&verifyproxy("$tmpdir/myproxy-test.$$");
}
if ($exitstatus == 0) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
$ENV{'X509_CERT_DIR'} = $trustrootdir;
($exitstatus, $output) =
&runtest("myproxy-logon -T -t 1 -o $tmpdir/myproxy-test.$$ -v -S",
$passphrase . "\n");
print "MyProxy Test 3T (retrieve stored credential w/ trustroots): ";
if ($exitstatus == 0) {
($exitstatus, $output) =
&verifyproxy("$tmpdir/myproxy-test.$$");
}
if ($exitstatus == 0) {
($exitstatus, $output) =
&verifytrustroots();
}
if ($exitstatus == 0) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
if (defined($origtrustrootdir)) {
$ENV{'X509_CERT_DIR'} = $origtrustrootdir;
} else {
delete $ENV{'X509_CERT_DIR'};
}
if (defined($serverconf)) {
system("touch $serverconf") && die "failed to touch $serverconf, stopped";
($exitstatus, $output) =
&runtest("myproxy-logon -t 1 -o $tmpdir/myproxy-test.$$ -v -S",
$passphrase . "\n");
print "MyProxy Test 3R1 (retrieve stored credential after server reconfig): ";
if ($exitstatus == 0) {
($exitstatus, $output) =
&verifyproxy("$tmpdir/myproxy-test.$$");
}
if ($exitstatus == 0) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
system("touch $serverconf") && die "failed to touch $serverconf, stopped";
($exitstatus, $output) =
&runtest("myproxy-logon -t 1 -o $tmpdir/myproxy-test.$$ -v -S",
$passphrase . "\n");
print "MyProxy Test 3R2 (retrieve stored credential after server reconfig): ";
if ($exitstatus == 0) {
($exitstatus, $output) =
&verifyproxy("$tmpdir/myproxy-test.$$");
}
if ($exitstatus == 0) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
system("touch $serverconf") && die "failed to touch $serverconf, stopped";
($exitstatus, $output) =
&runtest("myproxy-logon -t 1 -o $tmpdir/myproxy-test.$$ -v -S",
$passphrase . "\n");
print "MyProxy Test 3R3 (retrieve stored credential after server reconfig): ";
if ($exitstatus == 0) {
($exitstatus, $output) =
&verifyproxy("$tmpdir/myproxy-test.$$");
}
if ($exitstatus == 0) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
}
($exitstatus, $output) =
&runtest("myproxy-logon -t 1 -o $tmpdir/myproxy-test.$$ -v -S",
"badpassphrase\n");
print "MyProxy Test 4 (verify passphrase checking on retrieve): ";
if ($exitstatus != 0 && $output =~ /invalid credential passphrase/) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
($exitstatus, $output) =
&runtest("myproxy-logon -t 1 -N -v -S",
"badpassphrase\n");
print "MyProxy Test 4N (verify passphrase checking on authenticate): ";
if ($exitstatus != 0 && $output =~ /invalid credential passphrase/) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
$old_passphrase = $passphrase;
$passphrase = sprintf "%010d", int(rand(0x7fffffff));
($exitstatus, $output) =
&runtest("myproxy-change-pass-phrase -v -S",
"$old_passphrase\n$passphrase\n");
print "MyProxy Test 5 (change passphrase for credential): ";
if ($exitstatus == 0 && $output =~ /Pass phrase changed/) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
($exitstatus, $output) =
&runtest("myproxy-logon -t 1 -N -v -S",
$passphrase . "\n");
print "MyProxy Test 6 (verify new passphrase): ";
if ($exitstatus == 0) {
($exitstatus, $output) =
&verifyproxy("$tmpdir/myproxy-test.$$");
}
if ($exitstatus == 0) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
($exitstatus, $output) =
&runtest("myproxy-logon -t 1 -o $tmpdir/myproxy-test.$$ -v -S",
$old_passphrase . "\n");
print "MyProxy Test 7 (verify old passphrase fails): ";
if ($exitstatus != 0 && $output =~ /invalid credential passphrase/) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
($exitstatus, $output) =
&runtest("myproxy-logon -a \$X509_USER_PROXY -t 1 -o $tmpdir/myproxy-test.$$ -v", undef);
print "MyProxy Test 8 (verify default renewal policy): ";
if ($exitstatus != 0) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
($exitstatus, $output) =
&runtest("myproxy-destroy -v", undef);
print "MyProxy Test 9 (remove credential from repository): ";
if ($exitstatus == 0 && $output =~ /was successfully removed/) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
($exitstatus, $output) =
&runtest("myproxy-info -v", undef);
print "MyProxy Test 10 (verify credentials are removed): ";
if (!($output =~ /default credential/)) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
#
# Test 10.a
#
if ($startserver && defined($serverpid)) { # only case we have direct access to server
# ($exitstatus, $output) = kill('HUP', $serverpid);
($exitstatus, $output) = &runtest("/bin/kill -HUP $serverpid");
print "MyProxy Test 10.a (kill -HUP $serverpid): ";
if ($exitstatus != 0) {
print "FAILED with $exitstatus\n"; $FAILURES++;
print STDERR $output;
} else {
print "SUCCEEDED\n"; $SUCCESSES++;
}
} else {
print "MyProxy Test 10.a (kill -HUP <myproxy-server>): SKIPPED\n";
}
($exitstatus, $output) =
&runtest("myproxy-init -v -r 'nobody' -k 'nobody' -c 1 -t 1 -S",
$passphrase . "\n");
print "MyProxy Test 11 (store credentials with retrieval policies): ";
if ($exitstatus == 0) {
($exitstatus, $output) =
&runtest("myproxy-init -v -x -r '$cert_subject' -k 'mine' -c 1 -t 1 -S",
$passphrase . "\n");
}
if ($exitstatus == 0) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
($exitstatus, $output) =
&runtest("myproxy-logon -k 'mine' -t 1 -o $tmpdir/myproxy-test.$$ -v -S",
$passphrase . "\n");
print "MyProxy Test 12 (verify retrieval policies): ";
if ($exitstatus == 0) {
($exitstatus, $output) =
&verifyproxy("$tmpdir/myproxy-test.$$");
}
if ($exitstatus == 0) {
($exitstatus, $output) =
&runtest("myproxy-logon -k 'nobody' -t 1 -o $tmpdir/myproxy-test.$$ -v -S",
$passphrase . "\n");
if ($exitstatus != 0) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++;
print STDERR "Shouldn't have allowed retrieval.\n";
print STDERR $output;
}
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
&runtest("myproxy-destroy -v -k 'mine'", undef);
&runtest("myproxy-destroy -v -k 'nobody'", undef);
($exitstatus, $output) =
&runtest("myproxy-init -v -R 'nobody' -k 'nobody' -c 1 -t 1 -d -S",
$passphrase . "\n");
print "MyProxy Test 13 (store credentials with renewal policies): ";
if ($exitstatus == 0) {
($exitstatus, $output) =
&runtest("myproxy-init -v -x -R '$cert_subject' -k 'mine' -c 1 -t 1 -d -S",
$passphrase . "\n");
}
if ($exitstatus == 0) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
($exitstatus, $output) = &runtest("myproxy-info -v -d", undef);
print "MyProxy Test 14 (get info for stored renewal credentials): ";
if ($exitstatus == 0 && $output =~ /username/) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
($exitstatus, $output) =
&runtest("myproxy-logon -k 'mine' -a $ENV{'X509_USER_PROXY'} -t 1 -o $tmpdir/myproxy-test.$$ -v -d",
undef);
print "MyProxy Test 15 (verify renewal policies): ";
if ($exitstatus == 0) {
($exitstatus, $output) =
&verifyproxy("$tmpdir/myproxy-test.$$");
} elsif ($output =~ /self-authz not allowed/) {
$exitstatus = 0; # default policy will give this response
}
if ($exitstatus == 0) {
($exitstatus, $output) =
&runtest("myproxy-logon -k 'nobody' -a $ENV{'X509_USER_PROXY'} -t 1 -o $tmpdir/myproxy-test.$$ -v -d",
undef);
if ($exitstatus != 0) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++;
print STDERR "Shouldn't have allowed retrieval.\n";
print STDERR $output;
}
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
&runtest("myproxy-destroy -v -k 'mine' -d", undef);
&runtest("myproxy-destroy -v -k 'nobody' -d", undef);
($exitstatus, $output) =
&runtest("myproxy-init -v -a -c 3 -t 2 -S",
$passphrase . "\n");
print "MyProxy Test 16 (verify lifetime of retrieved credentials): ";
if ($exitstatus == 0) {
($exitstatus, $output) =
&runtest("myproxy-logon -o $tmpdir/myproxy-test.$$ -v -S",
$passphrase . "\n");
$timeleft = `$grid_proxy_info -file $tmpdir/myproxy-test.$$ -timeleft`;
if (defined($timeleft) &&
$timeleft > 60*60*2+300 || $timeleft < 60*60*2-300) {
$output = "Credential lifetime ($timeleft) incorrect." .
"It should be " . (60*60*2) . ".\n";
$exitstatus = 1;
}
}
if ($exitstatus == 0) {
($exitstatus, $output) =
&verifyproxy("$tmpdir/myproxy-test.$$");
}
if ($exitstatus == 0) {
($exitstatus, $output) =
&runtest("myproxy-logon -t 1 -o $tmpdir/myproxy-test.$$ -v -S",
$passphrase . "\n");
$timeleft = `$grid_proxy_info -file $tmpdir/myproxy-test.$$ -timeleft`;
if ($timeleft > 60*61 || $timeleft < 60*59) {
$output = "Credential lifetime ($timeleft) incorrect." .
"It should be " . (60*60) . ".\n";
$exitstatus = 1;
}
}
if ($exitstatus == 0) {
($exitstatus, $output) =
&verifyproxy("$tmpdir/myproxy-test.$$");
}
if ($exitstatus == 0) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
&runtest("myproxy-destroy -v", undef);
#
# Start of myproxy-store and myproxy-retrieve tests
#
# commands to test: myproxy-store, myproxy-info, myproxy-destroy,
# myproxy-logon, myproxy-retrieve, and
# myproxy-change-pass-phrase
# For myproxy-store, we need an encrypted key to store.
# So, let's encrypt our proxy key.
$passphrase = sprintf "%010d", int(rand(0x7fffffff));
$testkey = "$tmpdir/myproxy-test.$$.key";
&runcmd("$openssl rsa -des3 -passout stdin -in \$X509_USER_KEY -out $testkey",
$passphrase . "\n");
chmod(0600, $testkey);
#
# Test 17
#
($exitstatus, $output) =
&runtest("myproxy-store -x -E '$cert_subject' -v -t 1 -y $testkey", undef);
print "MyProxy Test 17 (store credential with default name): ";
if ($exitstatus == 0) {
print "SUCCEEDED\n"; $SUCCESSES++;
} elsif (($output =~ /Error checking authorization/) ||
($output =~ /unknown command/)) {
print "UNSUPPORTED\n"; $FAILURES++;
print "Server does not support myproxy-store. Skipping futher myproxy-store tests.\n";
goto end_of_store_tests;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
print "Skipping futher myproxy-store tests.\n";
goto end_of_store_tests;
}
#
# Test 18
#
($exitstatus, $output) = &runtest("myproxy-info -v", undef);
print "MyProxy Test 18 (get info for stored credential): ";
if ($exitstatus == 0 && $output =~ /username/) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
#
# Test 19
#
($exitstatus, $output) =
&runtest("myproxy-logon -t 1 -o $tmpdir/myproxy-test.$$ -v -S",
$passphrase . "\n");
print "MyProxy Test 19 (create proxy from stored credential): ";
if ($exitstatus == 0) {
($exitstatus, $output) =
&verifyproxy("$tmpdir/myproxy-test.$$");
}
if ($exitstatus == 0) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
#
# Test 20
#
($exitstatus, $output) =
&runtest("myproxy-retrieve -c $tmpdir/myproxy-test.cert.$$.pem -y $tmpdir/myproxy-test.key.$$.pem -v -S",
$passphrase . "\n");
print "MyProxy Test 20 (retrieve stored credential): ";
if ($exitstatus == 0) {
($exitstatus, $output) =
&verifycert("$tmpdir/myproxy-test.cert.$$.pem", "$tmpdir/myproxy-test.key.$$.pem");
}
if ($exitstatus == 0) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
unlink( "$tmpdir/myproxy-test.cert.$$.pem" );
unlink( "$tmpdir/myproxy-test.key.$$.pem" );
$ENV{'X509_CERT_DIR'} = $trustrootdir;
($exitstatus, $output) =
&runtest("myproxy-retrieve -T -c $tmpdir/myproxy-test.cert.$$.pem -y $tmpdir/myproxy-test.key.$$.pem -v -S",
$passphrase . "\n");
print "MyProxy Test 20T (retrieve stored credential w/ trustroots): ";
if ($exitstatus == 0) {
($exitstatus, $output) =
&verifycert("$tmpdir/myproxy-test.cert.$$.pem", "$tmpdir/myproxy-test.key.$$.pem");
}
if ($exitstatus == 0) {
($exitstatus, $output) =
&verifytrustroots();
}
if ($exitstatus == 0) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
unlink( "$tmpdir/myproxy-test.cert.$$.pem" );
unlink( "$tmpdir/myproxy-test.key.$$.pem" );
if (defined($origtrustrootdir)) {
$ENV{'X509_CERT_DIR'} = $origtrustrootdir;
} else {
delete $ENV{'X509_CERT_DIR'};
}
#
# Test 20.a
#
if ($startserver && defined($serverpid)) { # only case we have direct access to server
# ($exitstatus, $output) = kill('HUP', $serverpid);
($exitstatus, $output) = &runtest("/bin/kill -HUP $serverpid");
print "MyProxy Test 20.a (kill -HUP $serverpid): ";
if ($exitstatus != 0) {
print "FAILED with $exitstatus\n"; $FAILURES++;
print STDERR $output;
} else {
print "SUCCEEDED\n"; $SUCCESSES++;
}
} else {
print "MyProxy Test 20.a (kill -HUP <myproxy-server>): SKIPPED\n";
}
#
# Test 21
#
($exitstatus, $output) =
&runtest("myproxy-logon -t 1 -o $tmpdir/myproxy-test.$$ -v -S",
"badpassphrase\n");
print "MyProxy Test 21 (verify passphrase checking on myproxy-logon): ";
if ($exitstatus != 0 && $output =~ /invalid credential passphrase/) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
#
# Test 22
#
($exitstatus, $output) =
&runtest("myproxy-retrieve -c $tmpdir/myproxy-test-cert.$$.pem -y $tmpdir/myproxy-test-key.$$.pem -v -S",
"badpassphrase\n");
print "MyProxy Test 22 (verify passphrase checking on myproxy-retrieve): ";
if ($exitstatus != 0 && $output =~ /invalid credential passphrase/) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
unlink( "$tmpdir/myproxy-test.cert.$$.pem" );
unlink( "$tmpdir/myproxy-test.key.$$.pem" );
#
# Test 23
#
($exitstatus, $output) =
&runtest("myproxy-logon -a \$X509_USER_PROXY -t 1 -o $tmpdir/myproxy-test.$$ -v", undef);
print "MyProxy Test 23 (verify myproxy-logon default renewal policy): ";
if ($exitstatus != 0) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
#
# Test 24
#
($exitstatus, $output) =
&runtest("myproxy-retrieve -a \$X509_USER_PROXY -c $tmpdir/myproxy-test-cert.$$.pem -y $tmpdir/myproxy-test-key.$$.pem -v", undef);
print "MyProxy Test 24 (verify myproxy-retrieve default renewal policy): ";
if ($exitstatus != 0) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
unlink( "$tmpdir/myproxy-test-cert.$$.pem" );
unlink( "$tmpdir/myproxy-test-key.$$.pem" );
#
# Test 25
#
($exitstatus, $output) =
&runtest("myproxy-destroy -v", undef);
print "MyProxy Test 25 (remove credential from repository): ";
if ($exitstatus == 0 && $output =~ /was successfully removed/) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
#
# Test 26
#
($exitstatus, $output) =
&runtest("myproxy-info -v", undef);
print "MyProxy Test 26 (verify credentials are removed): ";
if (!($output =~ /default credential/)) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
#
# Test 27
#
($exitstatus, $output) =
&runtest("myproxy-store -v -r 'nobody' -k 'nobody' -t 1 -y $testkey",
undef);
print "MyProxy Test 27 (store credentials with retrieval policies): ";
if ($exitstatus == 0) {
($exitstatus, $output) =
&runtest("myproxy-store -x -E '$cert_subject' -v -r '$cert_subject' -k 'mine' -t 1 -y $testkey", undef);
}
if ($exitstatus == 0) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
#
# Test 28
#
($exitstatus, $output) =
&runtest("myproxy-logon -k 'mine' -t 1 -o $tmpdir/myproxy-test.$$ -v -S",
$passphrase . "\n");
print "MyProxy Test 28 (verify myproxy-logon retrieval policies): ";
if ($exitstatus == 0) {
($exitstatus, $output) =
&verifyproxy("$tmpdir/myproxy-test.$$");
}
if ($exitstatus == 0) {
($exitstatus, $output) =
&runtest("myproxy-logon -k 'nobody' -t 1 -o $tmpdir/myproxy-test.$$ -v -S",
$passphrase . "\n");
if ($exitstatus != 0) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++;
print STDERR "Shouldn't have allowed retrieval.\n";
print STDERR $output;
}
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
#
# Test 29
#
($exitstatus, $output) =
&runtest("myproxy-retrieve -k 'mine' -c $tmpdir/myproxy-test.cert.12.1.$$.pem -y $tmpdir/myproxy-test.key.12.1.$$.pem -v -S",
$passphrase . "\n");
print "MyProxy Test 29 (verify myproxy-retrieve retrieval policies): ";
if ($exitstatus == 0) {
($exitstatus, $output) =
&verifycert("$tmpdir/myproxy-test.cert.12.1.$$.pem", "$tmpdir/myproxy-test.key.12.1.$$.pem");
}
if ($exitstatus == 0) {
($exitstatus, $output) =
&runtest("myproxy-retrieve -k 'nobody' -c $tmpdir/myproxy-test.cert.12.2.$$.pem -y $tmpdir/myproxy-test.key.12.2.$$.pem -v -S",
$passphrase . "\n");
if ($exitstatus != 0) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++;
print STDERR "Shouldn't have allowed retrieval.\n";
print STDERR $output;
}
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
&runtest("myproxy-destroy -v -k 'mine'", undef);
&runtest("myproxy-destroy -v -k 'nobody'", undef);
`rm -f $tmpdir/myproxy-test.*.12.*.$$.pem`;
#
# Test 30
#
($exitstatus, $output) =
&runtest("myproxy-store -v -R 'nobody' -k 'nobody' -t 1 -d -y \$X509_USER_PROXY -c \$X509_USER_PROXY",
undef);
print "MyProxy Test 30 (store credentials with renewal policies): ";
if ($exitstatus == 0) {
($exitstatus, $output) =
&runtest("myproxy-store -v -x -R '$cert_subject' -k 'mine' -t 1 -d -y \$X509_USER_PROXY -c \$X509_USER_PROXY", undef);
}
if ($exitstatus == 0) {
($exitstatus, $output) =
&runtest("myproxy-store -v -c $iproxyloc -y $iproxyloc -x -R '$cert_subject' -k 'independent' -t 1", undef);
}
if ($exitstatus == 0) {
print "SUCCEEDED\n"; $SUCCESSES++;
} else {
print "FAILED\n"; $FAILURES++; print STDERR $output;
}
#
# Test 30.a
#
if ($startserver && defined($serverpid)) { # only case we have direct access to server
# ($exitstatus, $output) = kill('HUP', $serverpid);
($exitstatus, $output) = &runtest("/bin/kill -HUP $serverpid");
print "MyProxy Test 30.a (kill -HUP $serverpid): ";
if ($exitstatus != 0) {
print "FAILED with $exitstatus\n"; $FAILURES++;
print STDERR $output;