|
|
4dbf30 |
From acf8c4a91a76bf8049f6bfbd95b04e2e36bae4ea Mon Sep 17 00:00:00 2001
|
|
|
4dbf30 |
From: Daiki Ueno <dueno@redhat.com>
|
|
|
4dbf30 |
Date: Thu, 18 May 2017 10:45:26 +0200
|
|
|
4dbf30 |
Subject: [PATCH 1/2] Revert "trust: Honor "modifiable" setting in persist
|
|
|
4dbf30 |
file"
|
|
|
4dbf30 |
|
|
|
4dbf30 |
This reverts commit 8eed1e60b0921d05872e2f43eee9088cef038d7e, which
|
|
|
4dbf30 |
broke "trust anchor --remove".
|
|
|
4dbf30 |
---
|
|
|
4dbf30 |
trust/input/verisign-v1.p11-kit | 1 -
|
|
|
4dbf30 |
trust/parser.c | 10 +---------
|
|
|
4dbf30 |
trust/test-parser.c | 1 -
|
|
|
4dbf30 |
3 files changed, 1 insertion(+), 11 deletions(-)
|
|
|
4dbf30 |
|
|
|
4dbf30 |
diff --git a/trust/input/verisign-v1.p11-kit b/trust/input/verisign-v1.p11-kit
|
|
|
4dbf30 |
index aea49ea..eaa080d 100644
|
|
|
4dbf30 |
--- a/trust/input/verisign-v1.p11-kit
|
|
|
4dbf30 |
+++ b/trust/input/verisign-v1.p11-kit
|
|
|
4dbf30 |
@@ -1,6 +1,5 @@
|
|
|
4dbf30 |
[p11-kit-object-v1]
|
|
|
4dbf30 |
trusted: true
|
|
|
4dbf30 |
-modifiable: false
|
|
|
4dbf30 |
|
|
|
4dbf30 |
-----BEGIN CERTIFICATE-----
|
|
|
4dbf30 |
MIICPDCCAaUCED9pHoGc8JpK83P/uUii5N0wDQYJKoZIhvcNAQEFBQAwXzELMAkG
|
|
|
4dbf30 |
diff --git a/trust/parser.c b/trust/parser.c
|
|
|
4dbf30 |
index 52d1128..41513d4 100644
|
|
|
4dbf30 |
--- a/trust/parser.c
|
|
|
4dbf30 |
+++ b/trust/parser.c
|
|
|
4dbf30 |
@@ -610,7 +610,6 @@ p11_parser_format_persist (p11_parser *parser,
|
|
|
4dbf30 |
{
|
|
|
4dbf30 |
CK_BBOOL modifiablev = CK_TRUE;
|
|
|
4dbf30 |
CK_ATTRIBUTE *attrs;
|
|
|
4dbf30 |
- CK_ATTRIBUTE *attr;
|
|
|
4dbf30 |
p11_array *objects;
|
|
|
4dbf30 |
bool ret;
|
|
|
4dbf30 |
int i;
|
|
|
4dbf30 |
@@ -631,14 +630,7 @@ p11_parser_format_persist (p11_parser *parser,
|
|
|
4dbf30 |
ret = p11_persist_read (parser->persist, parser->basename, data, length, objects);
|
|
|
4dbf30 |
if (ret) {
|
|
|
4dbf30 |
for (i = 0; i < objects->num; i++) {
|
|
|
4dbf30 |
- /* By default, we mark objects read from a persist
|
|
|
4dbf30 |
- * file as modifiable, as the persist format is
|
|
|
4dbf30 |
- * writable. However, if CKA_MODIFIABLE is explictly
|
|
|
4dbf30 |
- * set in the file, respect the setting. */
|
|
|
4dbf30 |
- attrs = objects->elem[i];
|
|
|
4dbf30 |
- attr = p11_attrs_find_valid (objects->elem[i], CKA_MODIFIABLE);
|
|
|
4dbf30 |
- if (!attr)
|
|
|
4dbf30 |
- attrs = p11_attrs_build (attrs, &modifiable, NULL);
|
|
|
4dbf30 |
+ attrs = p11_attrs_build (objects->elem[i], &modifiable, NULL);
|
|
|
4dbf30 |
sink_object (parser, attrs);
|
|
|
4dbf30 |
}
|
|
|
4dbf30 |
}
|
|
|
4dbf30 |
diff --git a/trust/test-parser.c b/trust/test-parser.c
|
|
|
4dbf30 |
index 088cff9..b5c2525 100644
|
|
|
4dbf30 |
--- a/trust/test-parser.c
|
|
|
4dbf30 |
+++ b/trust/test-parser.c
|
|
|
4dbf30 |
@@ -168,7 +168,6 @@ test_parse_p11_kit_persist (void)
|
|
|
4dbf30 |
{ CKA_CLASS, &certificate, sizeof (certificate) },
|
|
|
4dbf30 |
{ CKA_VALUE, (void *)verisign_v1_ca, sizeof (verisign_v1_ca) },
|
|
|
4dbf30 |
{ CKA_TRUSTED, &truev, sizeof (truev) },
|
|
|
4dbf30 |
- { CKA_MODIFIABLE, &falsev, sizeof (falsev) },
|
|
|
4dbf30 |
{ CKA_X_DISTRUSTED, &falsev, sizeof (falsev) },
|
|
|
4dbf30 |
{ CKA_INVALID },
|
|
|
4dbf30 |
};
|
|
|
4dbf30 |
--
|
|
|
4dbf30 |
2.9.4
|
|
|
4dbf30 |
|
|
|
4dbf30 |
|
|
|
4dbf30 |
From 66c6a7e912d39d66cd4cc91375ac7be418bf7176 Mon Sep 17 00:00:00 2001
|
|
|
4dbf30 |
From: Daiki Ueno <dueno@redhat.com>
|
|
|
4dbf30 |
Date: Thu, 18 May 2017 11:11:45 +0200
|
|
|
4dbf30 |
Subject: [PATCH 2/2] trust: Check magic comment in persist file for
|
|
|
4dbf30 |
modifiablity
|
|
|
4dbf30 |
|
|
|
4dbf30 |
A persistent file written by the trust module starts with the line "#
|
|
|
4dbf30 |
This file has been auto-generated and written by p11-kit". This can
|
|
|
4dbf30 |
be used as a magic word to determine whether the objects read from a
|
|
|
4dbf30 |
.p11-kit file are read-only.
|
|
|
4dbf30 |
---
|
|
|
4dbf30 |
trust/parser.c | 6 +++++-
|
|
|
4dbf30 |
trust/persist.c | 9 ++++++++-
|
|
|
4dbf30 |
trust/test-token.c | 1 +
|
|
|
4dbf30 |
3 files changed, 14 insertions(+), 2 deletions(-)
|
|
|
4dbf30 |
|
|
|
4dbf30 |
diff --git a/trust/parser.c b/trust/parser.c
|
|
|
4dbf30 |
index 41513d4..abe86fc 100644
|
|
|
4dbf30 |
--- a/trust/parser.c
|
|
|
4dbf30 |
+++ b/trust/parser.c
|
|
|
4dbf30 |
@@ -49,6 +49,7 @@
|
|
|
4dbf30 |
#include "pem.h"
|
|
|
4dbf30 |
#include "pkcs11x.h"
|
|
|
4dbf30 |
#include "persist.h"
|
|
|
4dbf30 |
+#include "types.h"
|
|
|
4dbf30 |
#include "x509.h"
|
|
|
4dbf30 |
|
|
|
4dbf30 |
#include <libtasn1.h>
|
|
|
4dbf30 |
@@ -630,7 +631,10 @@ p11_parser_format_persist (p11_parser *parser,
|
|
|
4dbf30 |
ret = p11_persist_read (parser->persist, parser->basename, data, length, objects);
|
|
|
4dbf30 |
if (ret) {
|
|
|
4dbf30 |
for (i = 0; i < objects->num; i++) {
|
|
|
4dbf30 |
- attrs = p11_attrs_build (objects->elem[i], &modifiable, NULL);
|
|
|
4dbf30 |
+ CK_BBOOL generatedv;
|
|
|
4dbf30 |
+ attrs = objects->elem[i];
|
|
|
4dbf30 |
+ if (p11_attrs_find_bool (attrs, CKA_X_GENERATED, &generatedv) && generatedv)
|
|
|
4dbf30 |
+ attrs = p11_attrs_build (attrs, &modifiable, NULL);
|
|
|
4dbf30 |
sink_object (parser, attrs);
|
|
|
4dbf30 |
}
|
|
|
4dbf30 |
}
|
|
|
4dbf30 |
diff --git a/trust/persist.c b/trust/persist.c
|
|
|
4dbf30 |
index 63a531e..928260e 100644
|
|
|
4dbf30 |
--- a/trust/persist.c
|
|
|
4dbf30 |
+++ b/trust/persist.c
|
|
|
4dbf30 |
@@ -631,6 +631,9 @@ p11_persist_read (p11_persist *persist,
|
|
|
4dbf30 |
CK_ATTRIBUTE *attrs;
|
|
|
4dbf30 |
bool failed;
|
|
|
4dbf30 |
bool skip;
|
|
|
4dbf30 |
+ CK_BBOOL generatedv = CK_FALSE;
|
|
|
4dbf30 |
+ CK_ATTRIBUTE generated = { CKA_X_GENERATED, &generatedv, sizeof (generatedv) };
|
|
|
4dbf30 |
+ static const char comment[] = "# This file has been auto-generated and written by p11-kit.";
|
|
|
4dbf30 |
|
|
|
4dbf30 |
return_val_if_fail (persist != NULL, false);
|
|
|
4dbf30 |
return_val_if_fail (objects != NULL, false);
|
|
|
4dbf30 |
@@ -639,6 +642,10 @@ p11_persist_read (p11_persist *persist,
|
|
|
4dbf30 |
attrs = NULL;
|
|
|
4dbf30 |
failed = false;
|
|
|
4dbf30 |
|
|
|
4dbf30 |
+ if (length >= sizeof (comment) - 1 &&
|
|
|
4dbf30 |
+ memcmp ((const char *)data, comment, sizeof (comment) - 1) == 0)
|
|
|
4dbf30 |
+ generatedv = CK_TRUE;
|
|
|
4dbf30 |
+
|
|
|
4dbf30 |
p11_lexer_init (&lexer, filename, (const char *)data, length);
|
|
|
4dbf30 |
while (p11_lexer_next (&lexer, &failed)) {
|
|
|
4dbf30 |
switch (lexer.tok_type) {
|
|
|
4dbf30 |
@@ -650,7 +657,7 @@ p11_persist_read (p11_persist *persist,
|
|
|
4dbf30 |
p11_lexer_msg (&lexer, "unrecognized or invalid section header");
|
|
|
4dbf30 |
skip = true;
|
|
|
4dbf30 |
} else {
|
|
|
4dbf30 |
- attrs = p11_attrs_build (NULL, NULL);
|
|
|
4dbf30 |
+ attrs = p11_attrs_build (NULL, &generated, NULL);
|
|
|
4dbf30 |
return_val_if_fail (attrs != NULL, false);
|
|
|
4dbf30 |
skip = false;
|
|
|
4dbf30 |
}
|
|
|
4dbf30 |
diff --git a/trust/test-token.c b/trust/test-token.c
|
|
|
4dbf30 |
index ad22fcb..3e7d735 100644
|
|
|
4dbf30 |
--- a/trust/test-token.c
|
|
|
4dbf30 |
+++ b/trust/test-token.c
|
|
|
4dbf30 |
@@ -610,6 +610,7 @@ static void
|
|
|
4dbf30 |
test_modify_multiple (void)
|
|
|
4dbf30 |
{
|
|
|
4dbf30 |
const char *test_data =
|
|
|
4dbf30 |
+ "# This file has been auto-generated and written by p11-kit.\n"
|
|
|
4dbf30 |
"[p11-kit-object-v1]\n"
|
|
|
4dbf30 |
"class: data\n"
|
|
|
4dbf30 |
"label: \"first\"\n"
|
|
|
4dbf30 |
--
|
|
|
4dbf30 |
2.9.4
|
|
|
4dbf30 |
|
|
|
4dbf30 |
From d661194319f2375c1764125b449bf924c0cbc8a1 Mon Sep 17 00:00:00 2001
|
|
|
4dbf30 |
From: Daiki Ueno <dueno@redhat.com>
|
|
|
4dbf30 |
Date: Thu, 18 May 2017 14:27:36 +0200
|
|
|
4dbf30 |
Subject: [PATCH] trust: Simplify the check for the magic
|
|
|
4dbf30 |
|
|
|
4dbf30 |
Instead of reusing the CKA_X_GENERATED attribute, check the file
|
|
|
4dbf30 |
contents directly in the caller side.
|
|
|
4dbf30 |
---
|
|
|
4dbf30 |
trust/parser.c | 7 +++----
|
|
|
4dbf30 |
trust/persist.c | 19 +++++++++++--------
|
|
|
4dbf30 |
trust/persist.h | 3 +++
|
|
|
4dbf30 |
3 files changed, 17 insertions(+), 12 deletions(-)
|
|
|
4dbf30 |
|
|
|
4dbf30 |
diff --git a/trust/parser.c b/trust/parser.c
|
|
|
4dbf30 |
index abe86fc..f92cdc9 100644
|
|
|
4dbf30 |
--- a/trust/parser.c
|
|
|
4dbf30 |
+++ b/trust/parser.c
|
|
|
4dbf30 |
@@ -630,11 +630,10 @@ p11_parser_format_persist (p11_parser *parser,
|
|
|
4dbf30 |
|
|
|
4dbf30 |
ret = p11_persist_read (parser->persist, parser->basename, data, length, objects);
|
|
|
4dbf30 |
if (ret) {
|
|
|
4dbf30 |
+ if (!p11_persist_is_generated (data, length))
|
|
|
4dbf30 |
+ modifiablev = CK_FALSE;
|
|
|
4dbf30 |
for (i = 0; i < objects->num; i++) {
|
|
|
4dbf30 |
- CK_BBOOL generatedv;
|
|
|
4dbf30 |
- attrs = objects->elem[i];
|
|
|
4dbf30 |
- if (p11_attrs_find_bool (attrs, CKA_X_GENERATED, &generatedv) && generatedv)
|
|
|
4dbf30 |
- attrs = p11_attrs_build (attrs, &modifiable, NULL);
|
|
|
4dbf30 |
+ attrs = p11_attrs_build (objects->elem[i], &modifiable, NULL);
|
|
|
4dbf30 |
sink_object (parser, attrs);
|
|
|
4dbf30 |
}
|
|
|
4dbf30 |
}
|
|
|
4dbf30 |
diff --git a/trust/persist.c b/trust/persist.c
|
|
|
4dbf30 |
index 928260e..887b316 100644
|
|
|
4dbf30 |
--- a/trust/persist.c
|
|
|
4dbf30 |
+++ b/trust/persist.c
|
|
|
4dbf30 |
@@ -70,6 +70,16 @@ p11_persist_magic (const unsigned char *data,
|
|
|
4dbf30 |
return (strnstr ((char *)data, "[" PERSIST_HEADER "]", length) != NULL);
|
|
|
4dbf30 |
}
|
|
|
4dbf30 |
|
|
|
4dbf30 |
+bool
|
|
|
4dbf30 |
+p11_persist_is_generated (const unsigned char *data,
|
|
|
4dbf30 |
+ size_t length)
|
|
|
4dbf30 |
+{
|
|
|
4dbf30 |
+ static const char comment[] =
|
|
|
4dbf30 |
+ "# This file has been auto-generated and written by p11-kit.";
|
|
|
4dbf30 |
+ return length >= sizeof (comment) - 1 &&
|
|
|
4dbf30 |
+ memcmp ((const char *)data, comment, sizeof (comment) - 1) == 0;
|
|
|
4dbf30 |
+}
|
|
|
4dbf30 |
+
|
|
|
4dbf30 |
p11_persist *
|
|
|
4dbf30 |
p11_persist_new (void)
|
|
|
4dbf30 |
{
|
|
|
4dbf30 |
@@ -631,9 +641,6 @@ p11_persist_read (p11_persist *persist,
|
|
|
4dbf30 |
CK_ATTRIBUTE *attrs;
|
|
|
4dbf30 |
bool failed;
|
|
|
4dbf30 |
bool skip;
|
|
|
4dbf30 |
- CK_BBOOL generatedv = CK_FALSE;
|
|
|
4dbf30 |
- CK_ATTRIBUTE generated = { CKA_X_GENERATED, &generatedv, sizeof (generatedv) };
|
|
|
4dbf30 |
- static const char comment[] = "# This file has been auto-generated and written by p11-kit.";
|
|
|
4dbf30 |
|
|
|
4dbf30 |
return_val_if_fail (persist != NULL, false);
|
|
|
4dbf30 |
return_val_if_fail (objects != NULL, false);
|
|
|
4dbf30 |
@@ -642,10 +649,6 @@ p11_persist_read (p11_persist *persist,
|
|
|
4dbf30 |
attrs = NULL;
|
|
|
4dbf30 |
failed = false;
|
|
|
4dbf30 |
|
|
|
4dbf30 |
- if (length >= sizeof (comment) - 1 &&
|
|
|
4dbf30 |
- memcmp ((const char *)data, comment, sizeof (comment) - 1) == 0)
|
|
|
4dbf30 |
- generatedv = CK_TRUE;
|
|
|
4dbf30 |
-
|
|
|
4dbf30 |
p11_lexer_init (&lexer, filename, (const char *)data, length);
|
|
|
4dbf30 |
while (p11_lexer_next (&lexer, &failed)) {
|
|
|
4dbf30 |
switch (lexer.tok_type) {
|
|
|
4dbf30 |
@@ -657,7 +660,7 @@ p11_persist_read (p11_persist *persist,
|
|
|
4dbf30 |
p11_lexer_msg (&lexer, "unrecognized or invalid section header");
|
|
|
4dbf30 |
skip = true;
|
|
|
4dbf30 |
} else {
|
|
|
4dbf30 |
- attrs = p11_attrs_build (NULL, &generated, NULL);
|
|
|
4dbf30 |
+ attrs = p11_attrs_build (NULL, NULL);
|
|
|
4dbf30 |
return_val_if_fail (attrs != NULL, false);
|
|
|
4dbf30 |
skip = false;
|
|
|
4dbf30 |
}
|
|
|
4dbf30 |
diff --git a/trust/persist.h b/trust/persist.h
|
|
|
4dbf30 |
index 0ef142c..6344e4e 100644
|
|
|
4dbf30 |
--- a/trust/persist.h
|
|
|
4dbf30 |
+++ b/trust/persist.h
|
|
|
4dbf30 |
@@ -60,4 +60,7 @@ bool p11_persist_write (p11_persist *persist,
|
|
|
4dbf30 |
|
|
|
4dbf30 |
void p11_persist_free (p11_persist *persist);
|
|
|
4dbf30 |
|
|
|
4dbf30 |
+bool p11_persist_is_generated (const unsigned char *data,
|
|
|
4dbf30 |
+ size_t length);
|
|
|
4dbf30 |
+
|
|
|
4dbf30 |
#endif /* P11_PERSIST_H_ */
|
|
|
4dbf30 |
--
|
|
|
4dbf30 |
2.9.4
|
|
|
4dbf30 |
|