| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 | 
							- #!/bin/bash -e
 
- # vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
 
- #
 
- # Copyright (c) 2017 Red Hat, Inc.
 
- # Author: Nathaniel McCallum <npmccallum@redhat.com>
 
- #
 
- # This program is free software: you can redistribute it and/or modify
 
- # it under the terms of the GNU General Public License as published by
 
- # the Free Software Foundation, either version 3 of the License, or
 
- # (at your option) any later version.
 
- #
 
- # This program is distributed in the hope that it will be useful,
 
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
 
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
- # GNU General Public License for more details.
 
- #
 
- # You should have received a copy of the GNU General Public License
 
- # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
- #
 
- [ $# -eq 1 -a "$1" == "--summary" ] && exit 1
 
- if [ -t 0 ]; then
 
-     echo >&2
 
-     echo "Usage: clevis decrypt http < JWE > PLAINTEXT" >&2
 
-     echo >&2
 
-     exit 1
 
- fi
 
- read -d . hdr
 
- if [ "`jose fmt -q "$hdr" -SyOg clevis -g pin -u-`" != "http" ]; then
 
-     echo "JWE pin mismatch!" >&2
 
-     exit 1
 
- fi
 
- if ! url=`jose fmt -q "$hdr" -SyOg clevis -g http -g url -u-`; then
 
-     echo "JWE missing 'clevis.http.url' header parameter!" >&2
 
-     exit 1
 
- fi
 
- if ! typ=`jose fmt -q "$hdr" -SyOg clevis -g http -g type -u-`; then
 
-     echo "JWE missing 'clevis.http.url' header parameter!" >&2
 
-     exit 1
 
- fi
 
- if ! rep=`curl -sfg -H "Accept: $typ" "$url"`; then
 
-     echo "Key transfer failed!" >&2
 
-     exit 1
 
- fi
 
- case $typ in
 
- application/jwk+json)
 
-     if ! rep=`curl -sfg -H "Accept: $typ" "$url" \
 
-             | jose fmt -j- -Og kty -q oct -EUUo-`; then
 
-         echo "Key transfer failed!" >&2
 
-         exit 1
 
-     fi
 
-     ;;
 
- application/octet-stream)
 
-     if ! key=`curl -sfg -H "Accept: $typ" "$url" | jose b64 enc -I-`; then
 
-         echo "Key transfer failed!" >&2
 
-         exit 1
 
-     fi
 
-     jwk="{\"kty\":\"oct\",\"k\":\"$key\"}"
 
-     ;;
 
- esac
 
- exec jose jwe dec -k- -i- < <(echo -n "$jwk$hdr."; cat)
 
 
  |