a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * This program is free software; you can redistribute it and/or
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * modify it under the terms of the GNU General Public License as
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * published by the Free Software Foundation; either version 2 of the
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * License, or any later version.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * This program is distributed in the hope that it will be useful, but
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * WITHOUT ANY WARRANTY; without even the implied warranty of
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * General Public License for more details.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * You should have received a copy of the GNU General Public License
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * along with this program; if not, write to the Free Software
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * Image trust management
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * Verify image using downloaded signature
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * @v image Image to verify
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * @v signature Image containing signature
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * @v name Required common name, or NULL to allow any name
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * @ret rc Return status code
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncint imgverify ( struct image *image, struct image *signature,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync const char *name ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Mark image as untrusted */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Copy signature to internal memory */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Parse signature */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if ( ( rc = cms_signature ( data, len, &sig ) ) != 0 )
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Free internal copy of signature */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Use signature to verify image */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if ( ( rc = cms_verify ( sig, image->data, image->len,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Drop reference to signature */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Mark image as trusted */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync syslog ( LOG_NOTICE, "Image \"%s\" signature OK\n", image->name );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync syslog ( LOG_ERR, "Image \"%s\" signature bad: %s\n",