Skip to content

Commit

Permalink
Show RSA key length
Browse files Browse the repository at this point in the history
  • Loading branch information
lieser committed Jul 28, 2024
1 parent 7c2e3ce commit 7839331
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
48 changes: 43 additions & 5 deletions content/displayAction.mjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,52 @@ class DkimResult extends HTMLElement {
DkimResult.#addOptionalTextValue(this.#content, "AUID", this.result?.auid);
DkimResult.#addOptionalTimeValue(this.#content, "Sign date", this.result?.timestamp);
DkimResult.#addOptionalTimeValue(this.#content, "Expiration date", this.result?.expiration);
let algorithm;
if (this.result?.algorithmSignature && this.result?.algorithmHash) {
algorithm = `${this.result?.algorithmSignature}-${this.result?.algorithmHash}`;
}
DkimResult.#addOptionalTextValue(this.#content, "Algorithm", algorithm);
DkimResult.#addOptionalTextValue(this.#content, "Algorithm", this.#algorithm());
DkimResult.#addOptionalTextValue(this.#content, "Signed headers", this.result?.signedHeaders?.join(", "));
}

/**
* Get a string description of the used algorithm.
*
* @returns {string|undefined}
*/
#algorithm() {
if (!this.result?.algorithmSignature || !this.result?.algorithmHash) {
return undefined;
}
const signature = (() => {
switch (this.result?.algorithmSignature) {
case "rsa": {
const name = "RSA";
if (this.result.keyLength) {
return `${name} (${this.result.keyLength} bits)`;
}
return name;
}
case "ed25519": {
return "Ed25519";
}
default: {
return this.result?.algorithmSignature;
}
}
})();
const hash = (() => {
switch (this.result?.algorithmHash) {
case "sha1": {
return "SHA-1";
}
case "sha256": {
return "SHA-256";
}
default: {
return this.result?.algorithmHash;
}
}
})();
return `${signature} / ${hash}`;
}

/**
* Add a text value to an element under the specified key.
*
Expand Down
8 changes: 8 additions & 0 deletions modules/dkim/verifier.mjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import RfcParser from "../rfcParser.mjs.js";
* @property {number|null} [expiration]
* @property {string} [algorithmSignature]
* @property {string} [algorithmHash]
* @property {number|undefined} [keyLength]
* @property {string[]} [signedHeaders]
*/

Expand Down Expand Up @@ -928,6 +929,11 @@ class DkimSignature {
* @readonly
*/
this._header = header;
/**
* @private
* @type {number|undefined}
*/
this._keyLength = undefined;
}

/**
Expand Down Expand Up @@ -1382,6 +1388,7 @@ class DkimSignature {
}

if (this._header.a_sig === "rsa") {
this._keyLength = keyLength;
// Check strength of RSA keys.
if (keyLength < 1024) {
// error if key is too short
Expand Down Expand Up @@ -1436,6 +1443,7 @@ class DkimSignature {
...this._header.toBaseResult("SUCCESS"),
warnings,
keySecure: keyQueryResult.secure,
keyLength: this._keyLength,
};
return verification_result;
}
Expand Down

0 comments on commit 7839331

Please sign in to comment.