Browse Source

[image] Use image_asn1() to extract data from CMS signature images

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 7 years ago
parent
commit
829fedafcb
2 changed files with 11 additions and 12 deletions
  1. 1
    0
      src/hci/commands/image_trust_cmd.c
  2. 10
    12
      src/usr/imgtrust.c

+ 1
- 0
src/hci/commands/image_trust_cmd.c View File

@@ -181,3 +181,4 @@ REQUIRE_OBJECT ( rsa );
181 181
 REQUIRE_OBJECT ( md5 );
182 182
 REQUIRE_OBJECT ( sha1 );
183 183
 REQUIRE_OBJECT ( sha256 );
184
+REQUIRE_OBJECT ( der );

+ 10
- 12
src/usr/imgtrust.c View File

@@ -50,30 +50,28 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
50 50
  */
51 51
 int imgverify ( struct image *image, struct image *signature,
52 52
 		const char *name ) {
53
-	size_t len;
54
-	void *data;
53
+	struct asn1_cursor *data;
55 54
 	struct cms_signature *sig;
56 55
 	struct cms_signer_info *info;
57 56
 	time_t now;
57
+	int next;
58 58
 	int rc;
59 59
 
60 60
 	/* Mark image as untrusted */
61 61
 	image_untrust ( image );
62 62
 
63
-	/* Copy signature to internal memory */
64
-	len = signature->len;
65
-	data = malloc ( len );
66
-	if ( ! data ) {
67
-		rc = -ENOMEM;
68
-		goto err_alloc;
63
+	/* Get raw signature data */
64
+	next = image_asn1 ( signature, 0, &data );
65
+	if ( next < 0 ) {
66
+		rc = next;
67
+		goto err_asn1;
69 68
 	}
70
-	copy_from_user ( data, signature->data, 0, len );
71 69
 
72 70
 	/* Parse signature */
73
-	if ( ( rc = cms_signature ( data, len, &sig ) ) != 0 )
71
+	if ( ( rc = cms_signature ( data->data, data->len, &sig ) ) != 0 )
74 72
 		goto err_parse;
75 73
 
76
-	/* Free internal copy of signature */
74
+	/* Free raw signature data */
77 75
 	free ( data );
78 76
 	data = NULL;
79 77
 
@@ -107,7 +105,7 @@ int imgverify ( struct image *image, struct image *signature,
107 105
 	cms_put ( sig );
108 106
  err_parse:
109 107
 	free ( data );
110
- err_alloc:
108
+ err_asn1:
111 109
 	syslog ( LOG_ERR, "Image \"%s\" signature bad: %s\n",
112 110
 		 image->name, strerror ( rc ) );
113 111
 	return rc;

Loading…
Cancel
Save