summaryrefslogtreecommitdiffstats
path: root/comm/mail/extensions/openpgp/content/modules/trust.jsm
blob: 37e0014b59012ed11e6371818fe46dc0b0da3e21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 */

"use strict";

var EXPORTED_SYMBOLS = ["EnigmailTrust"];

var l10n;

// trust flags according to GPG documentation:
// - https://www.gnupg.org/documentation/manuals/gnupg.pdf
// - sources: doc/DETAILS
// In the order of trustworthy:
//  ---------------------------------------------------------
//  i = The key is invalid (e.g. due to a missing self-signature)
//  n = The key is not valid / Never trust this key
//  d/D = The key has been disabled
//  r = The key has been revoked
//  e = The key has expired
//  g = group (???)
//  ---------------------------------------------------------
//  ? = INTERNAL VALUE to separate invalid from unknown keys
//  ---------------------------------------------------------
//  o = Unknown (this key is new to the system)
//  - = Unknown validity (i.e. no value assigned)
//  q = Undefined validity (Not enough information for calculation)
//      '-' and 'q' may safely be treated as the same value for most purposes
//  ---------------------------------------------------------
//  m = Marginally trusted
//  ---------------------------------------------------------
//  f = Fully trusted / valid key
//  u = Ultimately trusted
//  ---------------------------------------------------------
const TRUSTLEVELS_SORTED = "indDreg?o-qmfu";
const TRUSTLEVELS_SORTED_IDX_UNKNOWN = 7; // index of '?'

var EnigmailTrust = {
  /**
   * @returns - |string| containing the order of trust/validity values
   */
  trustLevelsSorted() {
    return TRUSTLEVELS_SORTED;
  },

  /**
   * @returns - |boolean| whether the flag is invalid (neither unknown nor valid)
   */
  isInvalid(flag) {
    return TRUSTLEVELS_SORTED.indexOf(flag) < TRUSTLEVELS_SORTED_IDX_UNKNOWN;
  },

  getTrustCode(keyObj) {
    return keyObj.keyTrust;
  },

  getTrustLabel(trustCode) {
    if (!l10n) {
      l10n = new Localization(["messenger/openpgp/openpgp.ftl"], true);
    }
    let keyTrust;
    switch (trustCode) {
      case "q":
        return l10n.formatValueSync("key-valid-unknown");
      case "i":
        return l10n.formatValueSync("key-valid-invalid");
      case "d":
      case "D":
        return l10n.formatValueSync("key-valid-disabled");
      case "r":
        return l10n.formatValueSync("key-valid-revoked");
      case "e":
        return l10n.formatValueSync("key-valid-expired");
      case "n":
        return l10n.formatValueSync("key-trust-untrusted");
      case "m":
        return l10n.formatValueSync("key-trust-marginal");
      case "f":
        return l10n.formatValueSync("key-trust-full");
      case "u":
        return l10n.formatValueSync("key-trust-ultimate");
      case "g":
        return l10n.formatValueSync("key-trust-group");
      case "-":
        keyTrust = "-";
        break;
      default:
        keyTrust = "";
    }
    return keyTrust;
  },
};