| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | use VOMS::Lite::PEMHelper qw(writeCertKey); | ||
| 4 | use VOMS::Lite::MyProxy; | ||
| 5 | require Term::ReadKey; | ||
| 6 | |||
| 7 | my $name=$0; | ||
| 8 | my $lname=length($name); | ||
| 9 | $name =~ s#.*/##g; | ||
| 10 | my $usage = "Usage: $name username@myproxy.server[:port]\n". | ||
| 11 | " " x ($lname+8). "[ -out /path/to/save/proxy ]\n". | ||
| 12 | " " x ($lname+8). "[ -lifetime N (hours, default 12 hours) ]\n". | ||
| 13 | |||
| 14 | my %Input; | ||
| 15 | my $outfile="/tmp/x509up_u$<"; | ||
| 16 | if ( defined $ENV{"X509_USER_PROXY"} && $ENV{"X509_USER_PROXY"} =~ /(.*)/ ) { $outfile=$1; }; | ||
| 17 | my ($lifetime); | ||
| 18 | |||
| 19 | while ($_=shift @ARGV) { | ||
| 20 | if ( /^--?lifetime$/ ) { | ||
| 21 | $lifetime=shift @ARGV; | ||
| 22 | die "$& requires an argument" if ( ! defined $lifetime ); | ||
| 23 | die "$& requires a positive numeric integer argument." if ( $lifetime =~ /^[0-9]+$/ ); | ||
| 24 | $lifetime*=3600; | ||
| 25 | $Input{"Lifetime"}=$lifetime; | ||
| 26 | } | ||
| 27 | elsif ( /^([\/a-zA-Z0-9_ =.-]+)@([a-zA-Z0-9_][a-zA-Z0-9_.-]+[a-zA-Z0-9_])(?::([0-9]{1,5}))?$/ ) { | ||
| 28 | $Input{"Username"}=$1; | ||
| 29 | $Input{"Server"}=$2; | ||
| 30 | $Input{"Port"}=$3; | ||
| 31 | } | ||
| 32 | else { die "Unrecognised option \"$_\"\n$usage"; } | ||
| 33 | } | ||
| 34 | |||
| 35 | # Prompt for password | ||
| 36 | if ( ! defined $Input{"Password"} ) { | ||
| 37 | print "Passphrase to protect the credential on the MyProxy Server: "; | ||
| 38 | my $dummy=Term::ReadKey::ReadMode('noecho'); | ||
| 39 | my $passwd = Term::ReadKey::ReadLine(), | ||
| 40 | $dummy=Term::ReadKey::ReadMode('normal'); | ||
| 41 | chomp $passwd; | ||
| 42 | $Input{"Password"}=$passwd; | ||
| 43 | print "\n"; | ||
| 44 | } | ||
| 45 | |||
| 46 | my %Output = %{ VOMS::Lite::MyProxy::Get(\%Input) }; | ||
| 47 | |||
| 48 | my $cert= shift @{ $Output{CertChain} }; | ||
| 49 | |||
| 50 | if ( ! defined $Output{CertChain} || ! defined $Output{Key} ) { | ||
| 51 | foreach ( @{ $Output{Errors} } ) { print "Error: $_\n"; } | ||
| 52 | die "Failed to get a proxy"; | ||
| 53 | } | ||
| 54 | |||
| 55 | foreach ( @{ $Output{Warnings} } ) { print "Warning: $_\n"; } | ||
| 56 | |||
| 57 | print "Retrieved\n"; | ||
| 58 | |||
| 59 | writeCertKey($outfile, $cert, $Output{'Key'}, @{ $Output{CertChain} } ); | ||
| 60 | |||
| 61 | __END__ |