9a4b7d411e19bdc7b2bc5fbe44aea2c9d09113f3
[teamcity/git-plugin.git] / git-agent / src / org / jetbrains / git4idea / ssh / GitSSHHandler.java
1 /*
2  * Copyright 2000-2018 JetBrains s.r.o.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.jetbrains.git4idea.ssh;
18
19 import org.jetbrains.annotations.NonNls;
20 import org.jetbrains.annotations.Nullable;
21
22 import java.util.Vector;
23
24 /**
25  * An interface for GIT SSH handler
26  */
27 public interface GitSSHHandler {
28   /**
29    * The prefix of the ssh script name
30    */
31   @NonNls String GIT_SSH_PREFIX = "git-ssh-";
32   /**
33    * Name of environment variable for SSH handler number
34    */
35   @NonNls String SSH_HANDLER_ENV = "GIT4IDEA_SSH_HANDLER";
36   /**
37    * Name of environment variable for SSH handler number
38    */
39   @NonNls String SSH_IGNORE_KNOWN_HOSTS_ENV = "GIT4IDEA_SSH_IGNORE_KNOWN_HOSTS";
40   /**
41    * Name of environment variable for SSH handler
42    */
43   @NonNls String SSH_PORT_ENV = "GIT4IDEA_SSH_PORT";
44   /**
45    * Name of environment variable for SSH executable
46    */
47   @NonNls String GIT_SSH_ENV = "GIT_SSH";
48   /**
49    * Name of the handler
50    */
51   @NonNls String HANDLER_NAME = "Git4ideaSSHHandler";
52
53   String TEAMCITY_PRIVATE_KEY_PATH = "TEAMCITY_PRIVATE_KEY";
54   String TEAMCITY_PASSPHRASE = "TEAMCITY_PASSPHRASE";
55   String TEAMCITY_DEBUG_SSH = "TEAMCITY_DEBUG_SSH";
56   String TEAMCITY_SSH_MAC_TYPE = "TEAMCITY_SSH_MAC_TYPE";
57   String TEAMCITY_SSH_PREFERRED_AUTH_METHODS = "TEAMCITY_SSH_PREFERRED_AUTH_METHODS";
58   String TEAMCITY_VERSION = "TEAMCITY_VERSION";
59
60   /**
61    * Verify server host key
62    *
63    * @param handler                  a handler identifier
64    * @param hostName                 a host name
65    * @param port                     a port number
66    * @param serverHostKeyAlgorithm   an algorithm
67    * @param serverHostKeyFingerprint a key fingerprint
68    * @param isNew                    true if the key is a new, false if the key was changed
69    * @return true the host is verified, false otherwise
70    */
71   boolean verifyServerHostKey(int handler,
72                               String hostName,
73                               int port,
74                               String serverHostKeyAlgorithm,
75                               String serverHostKeyFingerprint,
76                               boolean isNew);
77
78   /**
79    * Ask passphrase for the key
80    *
81    * @param handler       a handler identifier
82    * @param userName      a name of user
83    * @param keyPath       a path for the key
84    * @param resetPassword a reset password if one was stored in password database
85    * @param lastError     a last error (or empty string)
86    * @return the passphrase entered by the user
87    */
88   @Nullable
89   String askPassphrase(final int handler, final String userName, final String keyPath, boolean resetPassword, final String lastError);
90
91   /**
92    * Reply to challenge for keyboard-interactive method. Also used for
93    *
94    * @param handlerNo   a handler identifier
95    * @param userName    a user name (includes host and port)
96    * @param name        name of challenge
97    * @param instruction instruction
98    * @param numPrompts  amount of prompts
99    * @param prompt      prompts
100    * @param echo        whether the reply should be echoed (boolean values represented as string due to XML RPC limitation)
101    * @param lastError   the last error from the challenge
102    * @return a list or replies to challenges (the size should be equal to the number of prompts)
103    */
104   @SuppressWarnings({"UseOfObsoleteCollectionType"})
105   @Nullable
106   Vector<String> replyToChallenge(final int handlerNo,
107                                   final String userName,
108                                   final String name,
109                                   final String instruction,
110                                   final int numPrompts,
111                                   final Vector<String> prompt,
112                                   final Vector<Boolean> echo,
113                                   final String lastError);
114
115   /**
116    * Ask password for the specified user name
117    *
118    * @param handlerNo     a handler identifier
119    * @param userName      a name of user to ask password for
120    * @param resetPassword a reset password if one was stored in password database
121    * @param lastError     a last error
122    * @return the password or null if authentication failed.
123    */
124   @Nullable
125   String askPassword(final int handlerNo, final String userName, boolean resetPassword, final String lastError);
126 }