(keyringId, armored, rotation)
| 76 | } |
| 77 | |
| 78 | async importKey(keyringId, armored, rotation) { |
| 79 | try { |
| 80 | this.keyringId = keyringId; |
| 81 | // check keyringId |
| 82 | this.keyring = await getKeyringById(keyringId); |
| 83 | this.armored = armored; |
| 84 | this.rotation = rotation; |
| 85 | this.key = await readKey({armoredKey: this.armored}); |
| 86 | this.key = await sanitizeKey(this.key); |
| 87 | if (!this.key || await verifyPrimaryKey(this.key) === KEY_STATUS.invalid) { |
| 88 | throw new Error('Key is invalid.'); |
| 89 | } |
| 90 | this.armored = this.key.armor(); |
| 91 | // collect key details |
| 92 | [this.keyDetails] = await mapKeys([this.key]); |
| 93 | if (this.keyDetails.type === 'private') { |
| 94 | throw new Error('Import of private keys not allowed.'); |
| 95 | } |
| 96 | const users = []; |
| 97 | for (const [index, user] of this.key.users.entries()) { |
| 98 | if (!user.userID) { |
| 99 | // filter out user attribute packages |
| 100 | continue; |
| 101 | } |
| 102 | const userStatus = await verifyUser(user); |
| 103 | const uiUser = {id: index, userId: user.userID.userID, name: user.userID.name, email: user.userID.email, status: userStatus}; |
| 104 | parseUserId(uiUser); |
| 105 | users.push(uiUser); |
| 106 | } |
| 107 | this.keyDetails.users = users; |
| 108 | // check if key already in keyring |
| 109 | const fingerprint = this.key.getFingerprint(); |
| 110 | let stockKey = this.keyring.keystore.getKeysForId(fingerprint); |
| 111 | if (stockKey) { |
| 112 | stockKey = stockKey[0]; |
| 113 | return this.updateKey(fingerprint, stockKey, this.key); |
| 114 | } else { |
| 115 | return this.openPopup(); |
| 116 | } |
| 117 | } catch (err) { |
| 118 | throw new MvError(err.message, 'IMPORT_ERROR'); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | async updateKey(fingerprint, stockKey, newKey) { |
| 123 | const statusBefore = await verifyPrimaryKey(stockKey); |
no test coverage detected