wkd-checker 2.3.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +17 -16
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -186,26 +186,24 @@ const checkKeyUrl = (url, policy, options, email) => __awaiter(void 0, void 0, v
186
186
  result.keyTypeValid = keyType === KeyType.BinaryKey;
187
187
  if (key) {
188
188
  const identities = yield key.getUserIDs();
189
- // Spec Section 5: "The mail provider MUST make sure to publish a key in a way that only the mail address belonging to the requested user is part of the User ID packets included in the returned key."
190
- // "Other User ID packets and their associated binding signatures MUST be removed before publication."
191
- result.emailInKey = identities.length > 0;
192
- for (const id of identities) {
193
- const match = id.match(/<(.+)>/);
194
- const emailInId = match ? match[1] : id;
195
- if (emailInId.trim() !== email) {
196
- result.emailInKey = false;
197
- break;
198
- }
199
- }
189
+ // Helper to extract email address from User ID string ("Name <email@domain>" or "email@domain")
190
+ const extractEmail = (id) => {
191
+ const match = id.match(/<([^>]+)>/);
192
+ return (match ? match[1] : id).trim().toLowerCase();
193
+ };
194
+ const targetEmail = email.trim().toLowerCase();
195
+ const emailsInKey = identities.map(extractEmail);
196
+ // Spec Section 3.1 & Section 5: The key needs to carry a User ID packet with that mail address.
197
+ // Client MUST check that the received key has the requested User-Id and MUST drop all other User-Ids.
198
+ result.emailInKey = emailsInKey.includes(targetEmail);
200
199
  // Check policy compliance
201
200
  if (((_c = result.policy) === null || _c === void 0 ? void 0 : _c.mailboxOnly) && identities.length > 0) {
202
201
  for (const id of identities) {
203
- // If mailbox-only, the ID MUST
204
- const match = id.match(/<(.+)>/);
205
- const emailInId = match ? match[1] : id;
206
- const expected = [`<${emailInId.trim()}>`, emailInId.trim()];
207
- if (!expected.includes(id.trim())) {
202
+ const emailInId = extractEmail(id);
203
+ const expected = [`<${emailInId}>`, emailInId];
204
+ if (!expected.includes(id.trim().toLowerCase())) {
208
205
  result.policyCompliant = false;
206
+ break;
209
207
  }
210
208
  }
211
209
  }
@@ -320,6 +318,9 @@ exports.getKey = getKey;
320
318
  * @returns {Promise<{ advanced: KeyCheckResult, direct: KeyCheckResult }>} Results for both lookup methods.
321
319
  */
322
320
  const checkKey = (email) => __awaiter(void 0, void 0, void 0, function* () {
321
+ if (!(0, exports.validateEmail)(email)) {
322
+ throw new WKDError('Invalid e-mail address.');
323
+ }
323
324
  const { advancedUrl, directUrl, advancedPolicyUrl, directPolicyUrl } = yield generateWkdUrls(email);
324
325
  const options = {
325
326
  headers: { "User-Agent": USER_AGENT }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wkd-checker",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "description": "Web Key Directory library for Node.js. Retreive OpenPGP keys from WKD servers and validate them.",
5
5
  "repository": {
6
6
  "type": "git",