source: TI12-security/trunk/MyProxyWebService/myproxy/server/test/myproxy-ws-get-trustroots.sh @ 6943

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/MyProxyWebService/myproxy/server/test/myproxy-ws-get-trustroots.sh@6943
Revision 6943, 2.1 KB checked in by pjkersha, 9 years ago (diff)

Incomplete - task 5: MyProxy? Logon HTTPS Interface

  • Working myproxy-ws-get-trustroots.sh http client shell script.
  • Property svn:executable set to *
Line 
1#!/bin/bash
2#
3# Client script for web service interface to MyProxy get-trustroots based on
4# openssl and curl.  Get trust roots retrieves the CA certificate issuer(s) of
5# the MyProxy server's SSL certificate
6#
7# @author P J Kershaw 07/06/2010
8#
9# @copyright: (C) 2010 STFC
10#
11# @license: BSD - See top-level LICENCE file for licence details
12#
13# $Id$
14cmdname=$(basename $0)
15cmdline_opt=`getopt -o hU:b --long help,uri:,bootstrap: -n "$cmdname" -- "$@"`
16
17usage="Usage: $cmdname [-U MyProxy Web Service URI][-b]\n
18\n
19   Options\n
20       -h | --help\t\t\t\tDisplays usage\n
21       -U | --uri\t\t<uri>\t\tMyProxy web service URI\n
22       -b | --bootstrap\t\tbootstrap trust in the MyProxy Server\n
23"
24
25if [ $? != 0 ] ; then
26    echo -e $usage >&2 ;
27    exit 1 ;
28fi
29
30eval set -- "$cmdline_opt"
31
32while true ; do
33    case "$1" in
34        -h|--help) echo -e $usage ; exit 0 ;;
35        -U|--uri) uri=$2 ; shift 2 ;;
36        -b|--bootstrap) bootstrap=1 ; shift 1 ;;
37         --) shift ; break ;;
38        *) echo "Error parsing command line" ; exit 1 ;;
39    esac
40done
41
42if [ -z $uri ]; then
43    echo -e Give the URI for the MyProxy web service get trust roots request;
44    echo -e $usage >&2 ;
45    exit 1;
46fi
47
48# Set-up destination trust root directory
49if [ ${X509_CERT_DIR} ]; then
50    cadir=${X509_CERT_DIR}
51elif [ "$username" = "root" ]; then
52    cadir=/etc/grid-security/certificates
53else
54    cadir=${HOME}/.globus/certificates
55fi
56
57# Set peer authentication based on bootstrap command line setting
58if [ -z $bootstrap ]; then
59    ca_arg="--capath $cadir"
60else
61    ca_arg="--insecure"
62fi
63
64# Post request to MyProxy web service
65echo curl $uri $ca_arg -w " %{http_code}" -s -S
66response=$(curl $uri $ca_arg -w " %{http_code}" -s -S)
67responsemsg=$(echo "$response"|sed '$s/ *\([^ ]* *\)$//')
68responsecode=$(echo $response|awk '{print $NF}')
69if [ "$responsecode" != "200" ]; then
70    echo "$responsemsg" >&2
71    exit 1
72fi
73
74# Process response
75entries=$(echo $responsemsg|awk '{print $0}')
76for i in $entries; do
77    filename=${i%%=*}
78    filecontent="$(echo ${i#*=}|base64 -d)"
79    echo "$filecontent" > $cadir/$filename
80done
Note: See TracBrowser for help on using the repository browser.