From: Sascha Silbe <sascha-pgp@silbe.org>
Subject: [PATCH] check syntax of private key (#1568)
Check that header and footer of the private key are present in order to detect
corrupted key files.
Signed-off-by: Sascha Silbe <sascha-pgp@silbe.org>
---
src/sugar/profile.py | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/src/sugar/profile.py b/src/sugar/profile.py
index 3ea1e67..3f93bba 100644
a
|
b
|
class Profile(object): |
105 | 105 | return None |
106 | 106 | |
107 | 107 | key = "" |
| 108 | begin_found = False |
| 109 | end_found = False |
108 | 110 | for l in lines: |
109 | 111 | l = l.strip() |
110 | 112 | if l.startswith("-----BEGIN DSA PRIVATE KEY-----"): |
| 113 | begin_found = True |
111 | 114 | continue |
112 | 115 | if l.startswith("-----END DSA PRIVATE KEY-----"): |
| 116 | end_found = True |
113 | 117 | continue |
114 | 118 | key += l |
115 | | if not len(key): |
| 119 | if not (len(key) and begin_found and end_found): |
116 | 120 | logging.error("Error parsing public key.") |
117 | 121 | return None |
118 | 122 | |