-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathnassh_agent_backend.js
110 lines (98 loc) · 3.62 KB
/
nassh_agent_backend.js
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2017 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
/**
* @fileoverview A dummy backend for the SSH agent from which all other backends
* derive.
*/
nassh.agent.backends = {};
/**
* Base class for SSH agent backends compatible with nassh.agent.Agent.
*
* @param {!nassh.agent.Agent.UserIO} userIO Used for user-facing terminal IO.
* @constructor
*/
nassh.agent.Backend = function(userIO) {
/**
* Reference to object with terminal IO functions.
*
* @private {!nassh.agent.Agent.UserIO}
* @const
*/
this.userIO_ = userIO;
};
/**
* The unique ID of the backend. This is used to reference the backend in the
* relay options and must not match the regexp /^[a-z]{32}$/.
*
* @type {string}
*/
nassh.agent.Backend.prototype.BACKEND_ID = 'stub';
/**
* Generic response for request types that are not implemented.
*
* @const {!Error}
*/
nassh.agent.Backend.ERR_NOT_IMPLEMENTED = new Error('not implemented');
// Register the backend for use by nassh.agent.Agent.
nassh.agent.registerBackend(nassh.agent.Backend);
/**
* Called once when the client connects to the agent.
* The backend should check whether it is fully operational and run
* initializations that can fail.
*
* @return {!Promise<void>} A resolving promise if the
* backend initialized successfully; a rejecting promise otherwise.
*/
nassh.agent.Backend.prototype.ping = function() {
return Promise.resolve();
};
/**
* Called when the client sends an AGENTC_REQUEST_IDENTITIES request.
*
* @see https://tools.ietf.org/id/draft-miller-ssh-agent-00.html#rfc.section.4.4
* @return {!Promise<!Array<!nassh.agent.messages.Identity>>} A promise
* resolving to an array of SSH identities; a rejecting promise with an
* error message if the request could not be handled.
*/
nassh.agent.Backend.prototype.requestIdentities = function() {
return Promise.reject(nassh.agent.Backend.ERR_NOT_IMPLEMENTED);
};
/**
* Called when the client sends an AGENTC_SIGN_REQUEST request.
*
* @see https://tools.ietf.org/id/draft-miller-ssh-agent-00.html#rfc.section.4.5
* @param {!Uint8Array} keyBlob The key blob of the key requested to perform
* the signature.
* @param {!Uint8Array} data The challenge data to be signed.
* @param {number} flags A uint32 treated as a bitfield of signature flags.
* @return {!Promise<!Uint8Array>|!Promise<!Error>} A promise resolving to
* the computed signature; a rejecting promise with an error message if the
* request could not be handled.
*/
nassh.agent.Backend.prototype.signRequest = function(keyBlob, data, flags) {
return Promise.reject(nassh.agent.Backend.ERR_NOT_IMPLEMENTED);
};
/**
* Show a message in the terminal window.
*
* @param {string} message The message to be shown. Note: The message should
* consist of a localized string obtained via nassh.msg.
*/
nassh.agent.Backend.prototype.showMessage = function(message) {
this.userIO_.showMessage(this.BACKEND_ID, message);
};
/**
* Show a message in the terminal window and prompt the user for a string.
*
* @param {string} promptMessage The message that should precede the prompt.
* Note: The message should consist of a localized string obtained via
* nassh.msg.
* @return {!Promise<string>|!Promise<void>} A promise resolving to the input
* if the user confirms it by pressing enter; a rejecting promise if the
* user cancels the prompt by pressing ESC.
*/
nassh.agent.Backend.prototype.promptUser = async function(promptMessage) {
return this.userIO_.promptUser(this.BACKEND_ID, promptMessage);
};