summaryrefslogtreecommitdiff
path: root/src/gmcerts.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gmcerts.c')
-rw-r--r--src/gmcerts.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/gmcerts.c b/src/gmcerts.c
index 35d784f6..8577cf2b 100644
--- a/src/gmcerts.c
+++ b/src/gmcerts.c
@@ -105,7 +105,7 @@ void deserialize_GmIdentity(iGmIdentity *d, iStream *ins) {
105 iString url; 105 iString url;
106 init_String(&url); 106 init_String(&url);
107 deserialize_String(&url, ins); 107 deserialize_String(&url, ins);
108 insert_StringSet(d->useUrls, &url); 108 setUse_GmIdentity(d, &url, iTrue);
109 deinit_String(&url); 109 deinit_String(&url);
110 } 110 }
111} 111}
@@ -161,11 +161,30 @@ iBool isUsedOn_GmIdentity(const iGmIdentity *d, const iString *url) {
161 return iFalse; 161 return iFalse;
162} 162}
163 163
164iBool isUsedOnDomain_GmIdentity(const iGmIdentity *d, const iRangecc domain) {
165 iConstForEach(StringSet, i, d->useUrls) {
166 const iRangecc host = urlHost_String(i.value);
167 if (equalRangeCase_Rangecc(host, domain)) {
168 return iTrue;
169 }
170 }
171 return iFalse;
172}
173
164void setUse_GmIdentity(iGmIdentity *d, const iString *url, iBool use) { 174void setUse_GmIdentity(iGmIdentity *d, const iString *url, iBool use) {
165 if (use && isUsedOn_GmIdentity(d, url)) { 175 if (use && isUsedOn_GmIdentity(d, url)) {
166 return; /* Redudant. */ 176 return; /* Redudant. */
167 } 177 }
168 if (use) { 178 if (use) {
179 /* Remove all use-URLs that become redundant by this newly added URL. */
180 /* TODO: StringSet could have a non-const iterator. */
181 iForEach(Array, i, &d->useUrls->strings.values) {
182 iString *used = i.value;
183 if (startsWithCase_String(used, cstr_String(url))) {
184 deinit_String(used);
185 remove_ArrayIterator(&i);
186 }
187 }
169#if !defined (NDEBUG) 188#if !defined (NDEBUG)
170 const iBool wasInserted = 189 const iBool wasInserted =
171#endif 190#endif
@@ -182,7 +201,11 @@ void clearUse_GmIdentity(iGmIdentity *d) {
182} 201}
183 202
184const iString *name_GmIdentity(const iGmIdentity *d) { 203const iString *name_GmIdentity(const iGmIdentity *d) {
185 return collect_String(subject_TlsCertificate(d->cert)); 204 iString *name = collect_String(subject_TlsCertificate(d->cert));
205 if (startsWith_String(name, "CN = ")) {
206 remove_Block(&name->chars, 0, 5);
207 }
208 return name;
186} 209}
187 210
188iDefineTypeConstruction(GmIdentity) 211iDefineTypeConstruction(GmIdentity)