Skip to content

Commit

Permalink
[crypto] Enable both DER and PEM formats by default
Browse files Browse the repository at this point in the history
Enable both IMAGE_DER and IMAGE_PEM by default, and drag in the
relevant objects only when image_asn1() is present in the binary.

This allows "imgverify" to transparently use either DER or PEM
signature files.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed Jul 29, 2016
1 parent b7e43b0 commit 942b798
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 43 deletions.
6 changes: 0 additions & 6 deletions src/config/config.c
Expand Up @@ -188,12 +188,6 @@ REQUIRE_OBJECT ( pnm );
#ifdef IMAGE_PNG
REQUIRE_OBJECT ( png );
#endif
#ifdef IMAGE_DER
REQUIRE_OBJECT ( der );
#endif
#ifdef IMAGE_PEM
REQUIRE_OBJECT ( pem );
#endif

/*
* Drag in all requested commands
Expand Down
39 changes: 39 additions & 0 deletions src/config/config_asn1.c
@@ -0,0 +1,39 @@
/*
* 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 2 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*
* You can also choose to distribute this program under the terms of
* the Unmodified Binary Distribution Licence (as given in the file
* COPYING.UBDL), provided that you have satisfied its requirements.
*/

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );

#include <config/general.h>

/** @file
*
* ASN.1 file format configuration
*
*/

PROVIDE_REQUIRING_SYMBOL();

#ifdef IMAGE_DER
REQUIRE_OBJECT ( der );
#endif
#ifdef IMAGE_PEM
REQUIRE_OBJECT ( pem );
#endif
4 changes: 2 additions & 2 deletions src/config/general.h
Expand Up @@ -112,8 +112,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
//#define IMAGE_SDI /* SDI image support */
//#define IMAGE_PNM /* PNM image support */
//#define IMAGE_PNG /* PNG image support */
//#define IMAGE_DER /* DER image support */
//#define IMAGE_PEM /* PEM image support */
#define IMAGE_DER /* DER image support */
#define IMAGE_PEM /* PEM image support */

/*
* Command-line commands to include
Expand Down
35 changes: 0 additions & 35 deletions src/core/image.c
Expand Up @@ -505,38 +505,3 @@ int image_pixbuf ( struct image *image, struct pixel_buffer **pixbuf ) {

return 0;
}

/**
* Extract ASN.1 object from image
*
* @v image Image
* @v offset Offset within image
* @v cursor ASN.1 cursor to fill in
* @ret next Offset to next image, or negative error
*
* The caller is responsible for eventually calling free() on the
* allocated ASN.1 cursor.
*/
int image_asn1 ( struct image *image, size_t offset,
struct asn1_cursor **cursor ) {
int next;
int rc;

/* Sanity check */
assert ( offset <= image->len );

/* Check that this image can be used to extract an ASN.1 object */
if ( ! ( image->type && image->type->asn1 ) )
return -ENOTSUP;

/* Try creating ASN.1 cursor */
next = image->type->asn1 ( image, offset, cursor );
if ( next < 0 ) {
rc = next;
DBGC ( image, "IMAGE %s could not extract ASN.1 object: %s\n",
image->name, strerror ( rc ) );
return rc;
}

return next;
}
42 changes: 42 additions & 0 deletions src/crypto/asn1.c
Expand Up @@ -31,6 +31,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <errno.h>
#include <time.h>
#include <ipxe/tables.h>
#include <ipxe/image.h>
#include <ipxe/asn1.h>

/** @file
Expand Down Expand Up @@ -838,3 +839,44 @@ int asn1_wrap ( struct asn1_builder *builder, unsigned int type ) {

return 0;
}

/**
* Extract ASN.1 object from image
*
* @v image Image
* @v offset Offset within image
* @v cursor ASN.1 cursor to fill in
* @ret next Offset to next image, or negative error
*
* The caller is responsible for eventually calling free() on the
* allocated ASN.1 cursor.
*/
int image_asn1 ( struct image *image, size_t offset,
struct asn1_cursor **cursor ) {
int next;
int rc;

/* Sanity check */
assert ( offset <= image->len );

/* Check that this image can be used to extract an ASN.1 object */
if ( ! ( image->type && image->type->asn1 ) )
return -ENOTSUP;

/* Try creating ASN.1 cursor */
next = image->type->asn1 ( image, offset, cursor );
if ( next < 0 ) {
rc = next;
DBGC ( image, "IMAGE %s could not extract ASN.1 object: %s\n",
image->name, strerror ( rc ) );
return rc;
}

return next;
}

/* Drag in objects via image_asn1() */
REQUIRING_SYMBOL ( image_asn1 );

/* Drag in ASN.1 image formats */
REQUIRE_OBJECT ( config_asn1 );

0 comments on commit 942b798

Please sign in to comment.