| | | 1 | | using System; |
| | | 2 | | using Renci.SshNet.Common; |
| | | 3 | | |
| | | 4 | | namespace Renci.SshNet |
| | | 5 | | { |
| | | 6 | | /// <summary> |
| | | 7 | | /// Provides connection information when keyboard interactive authentication method is used. |
| | | 8 | | /// </summary> |
| | | 9 | | /// <example> |
| | | 10 | | /// <code source="..\..\src\Renci.SshNet.Tests\Classes\KeyboardInteractiveConnectionInfoTest.cs" region="Example |
| | | 11 | | /// </example> |
| | | 12 | | public class KeyboardInteractiveConnectionInfo : ConnectionInfo, IDisposable |
| | | 13 | | { |
| | | 14 | | private bool _isDisposed; |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// Occurs when server prompts for more authentication information. |
| | | 18 | | /// </summary> |
| | | 19 | | /// <example> |
| | | 20 | | /// <code source="..\..\src\Renci.SshNet.Tests\Classes\KeyboardInteractiveConnectionInfoTest.cs" region="Exa |
| | | 21 | | /// </example> |
| | | 22 | | public event EventHandler<AuthenticationPromptEventArgs> AuthenticationPrompt; |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// Initializes a new instance of the <see cref="KeyboardInteractiveConnectionInfo"/> class. |
| | | 26 | | /// </summary> |
| | | 27 | | /// <param name="host">The host.</param> |
| | | 28 | | /// <param name="username">The username.</param> |
| | | 29 | | public KeyboardInteractiveConnectionInfo(string host, string username) |
| | 0 | 30 | | : this(host, DefaultPort, username, ProxyTypes.None, string.Empty, 0, string.Empty, string.Empty) |
| | 0 | 31 | | { |
| | 0 | 32 | | } |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Initializes a new instance of the <see cref="KeyboardInteractiveConnectionInfo"/> class. |
| | | 36 | | /// </summary> |
| | | 37 | | /// <param name="host">The host.</param> |
| | | 38 | | /// <param name="port">The port.</param> |
| | | 39 | | /// <param name="username">The username.</param> |
| | | 40 | | public KeyboardInteractiveConnectionInfo(string host, int port, string username) |
| | 1 | 41 | | : this(host, port, username, ProxyTypes.None, string.Empty, 0, string.Empty, string.Empty) |
| | 1 | 42 | | { |
| | 1 | 43 | | } |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// Initializes a new instance of the <see cref="KeyboardInteractiveConnectionInfo"/> class. |
| | | 47 | | /// </summary> |
| | | 48 | | /// <param name="host">Connection host.</param> |
| | | 49 | | /// <param name="port">Connection port.</param> |
| | | 50 | | /// <param name="username">Connection username.</param> |
| | | 51 | | /// <param name="proxyType">Type of the proxy.</param> |
| | | 52 | | /// <param name="proxyHost">The proxy host.</param> |
| | | 53 | | /// <param name="proxyPort">The proxy port.</param> |
| | | 54 | | public KeyboardInteractiveConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string pr |
| | 0 | 55 | | : this(host, port, username, proxyType, proxyHost, proxyPort, string.Empty, string.Empty) |
| | 0 | 56 | | { |
| | 0 | 57 | | } |
| | | 58 | | |
| | | 59 | | /// <summary> |
| | | 60 | | /// Initializes a new instance of the <see cref="KeyboardInteractiveConnectionInfo"/> class. |
| | | 61 | | /// </summary> |
| | | 62 | | /// <param name="host">Connection host.</param> |
| | | 63 | | /// <param name="port">Connection port.</param> |
| | | 64 | | /// <param name="username">Connection username.</param> |
| | | 65 | | /// <param name="proxyType">Type of the proxy.</param> |
| | | 66 | | /// <param name="proxyHost">The proxy host.</param> |
| | | 67 | | /// <param name="proxyPort">The proxy port.</param> |
| | | 68 | | /// <param name="proxyUsername">The proxy username.</param> |
| | | 69 | | public KeyboardInteractiveConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string pr |
| | 0 | 70 | | : this(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, string.Empty) |
| | 0 | 71 | | { |
| | 0 | 72 | | } |
| | | 73 | | |
| | | 74 | | /// <summary> |
| | | 75 | | /// Initializes a new instance of the <see cref="KeyboardInteractiveConnectionInfo"/> class. |
| | | 76 | | /// </summary> |
| | | 77 | | /// <param name="host">Connection host.</param> |
| | | 78 | | /// <param name="username">Connection username.</param> |
| | | 79 | | /// <param name="proxyType">Type of the proxy.</param> |
| | | 80 | | /// <param name="proxyHost">The proxy host.</param> |
| | | 81 | | /// <param name="proxyPort">The proxy port.</param> |
| | | 82 | | public KeyboardInteractiveConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, i |
| | 0 | 83 | | : this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, string.Empty, string.Empty) |
| | 0 | 84 | | { |
| | 0 | 85 | | } |
| | | 86 | | |
| | | 87 | | /// <summary> |
| | | 88 | | /// Initializes a new instance of the <see cref="KeyboardInteractiveConnectionInfo"/> class. |
| | | 89 | | /// </summary> |
| | | 90 | | /// <param name="host">Connection host.</param> |
| | | 91 | | /// <param name="username">Connection username.</param> |
| | | 92 | | /// <param name="proxyType">Type of the proxy.</param> |
| | | 93 | | /// <param name="proxyHost">The proxy host.</param> |
| | | 94 | | /// <param name="proxyPort">The proxy port.</param> |
| | | 95 | | /// <param name="proxyUsername">The proxy username.</param> |
| | | 96 | | public KeyboardInteractiveConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, i |
| | 0 | 97 | | : this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, proxyUsername, string.Empty) |
| | 0 | 98 | | { |
| | 0 | 99 | | } |
| | | 100 | | |
| | | 101 | | /// <summary> |
| | | 102 | | /// Initializes a new instance of the <see cref="KeyboardInteractiveConnectionInfo"/> class. |
| | | 103 | | /// </summary> |
| | | 104 | | /// <param name="host">Connection host.</param> |
| | | 105 | | /// <param name="username">Connection username.</param> |
| | | 106 | | /// <param name="proxyType">Type of the proxy.</param> |
| | | 107 | | /// <param name="proxyHost">The proxy host.</param> |
| | | 108 | | /// <param name="proxyPort">The proxy port.</param> |
| | | 109 | | /// <param name="proxyUsername">The proxy username.</param> |
| | | 110 | | /// <param name="proxyPassword">The proxy password.</param> |
| | | 111 | | public KeyboardInteractiveConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, i |
| | 0 | 112 | | : this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword) |
| | 0 | 113 | | { |
| | 0 | 114 | | } |
| | | 115 | | |
| | | 116 | | /// <summary> |
| | | 117 | | /// Initializes a new instance of the <see cref="KeyboardInteractiveConnectionInfo"/> class. |
| | | 118 | | /// </summary> |
| | | 119 | | /// <param name="host">Connection host.</param> |
| | | 120 | | /// <param name="port">Connection port.</param> |
| | | 121 | | /// <param name="username">Connection username.</param> |
| | | 122 | | /// <param name="proxyType">Type of the proxy.</param> |
| | | 123 | | /// <param name="proxyHost">The proxy host.</param> |
| | | 124 | | /// <param name="proxyPort">The proxy port.</param> |
| | | 125 | | /// <param name="proxyUsername">The proxy username.</param> |
| | | 126 | | /// <param name="proxyPassword">The proxy password.</param> |
| | | 127 | | public KeyboardInteractiveConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string pr |
| | 1 | 128 | | : base(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, new KeyboardInte |
| | 1 | 129 | | { |
| | 5 | 130 | | foreach (var authenticationMethod in AuthenticationMethods) |
| | 1 | 131 | | { |
| | 1 | 132 | | if (authenticationMethod is KeyboardInteractiveAuthenticationMethod kbdInteractive) |
| | 1 | 133 | | { |
| | 1 | 134 | | kbdInteractive.AuthenticationPrompt += AuthenticationMethod_AuthenticationPrompt; |
| | 1 | 135 | | } |
| | 1 | 136 | | } |
| | 1 | 137 | | } |
| | | 138 | | |
| | | 139 | | private void AuthenticationMethod_AuthenticationPrompt(object sender, AuthenticationPromptEventArgs e) |
| | 2 | 140 | | { |
| | | 141 | | #pragma warning disable MA0091 // Sender should be 'this' for instance events |
| | 2 | 142 | | AuthenticationPrompt?.Invoke(sender, e); |
| | | 143 | | #pragma warning restore MA0091 // Sender should be 'this' for instance events |
| | 2 | 144 | | } |
| | | 145 | | |
| | | 146 | | /// <summary> |
| | | 147 | | /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. |
| | | 148 | | /// </summary> |
| | | 149 | | public void Dispose() |
| | 0 | 150 | | { |
| | 0 | 151 | | Dispose(disposing: true); |
| | 0 | 152 | | GC.SuppressFinalize(this); |
| | 0 | 153 | | } |
| | | 154 | | |
| | | 155 | | /// <summary> |
| | | 156 | | /// Releases unmanaged and - optionally - managed resources. |
| | | 157 | | /// </summary> |
| | | 158 | | /// <param name="disposing"><see langword="true"/> to release both managed and unmanaged resources; <see langwor |
| | | 159 | | protected virtual void Dispose(bool disposing) |
| | 1 | 160 | | { |
| | 1 | 161 | | if (_isDisposed) |
| | 0 | 162 | | { |
| | 0 | 163 | | return; |
| | | 164 | | } |
| | | 165 | | |
| | 1 | 166 | | if (disposing) |
| | 0 | 167 | | { |
| | 0 | 168 | | if (AuthenticationMethods != null) |
| | 0 | 169 | | { |
| | 0 | 170 | | foreach (var authenticationMethods in AuthenticationMethods) |
| | 0 | 171 | | { |
| | 0 | 172 | | if (authenticationMethods is IDisposable disposable) |
| | 0 | 173 | | { |
| | 0 | 174 | | disposable.Dispose(); |
| | 0 | 175 | | } |
| | 0 | 176 | | } |
| | 0 | 177 | | } |
| | | 178 | | |
| | 0 | 179 | | _isDisposed = true; |
| | 0 | 180 | | } |
| | 1 | 181 | | } |
| | | 182 | | |
| | | 183 | | /// <summary> |
| | | 184 | | /// Finalizes an instance of the <see cref="KeyboardInteractiveConnectionInfo"/> class. |
| | | 185 | | /// </summary> |
| | | 186 | | ~KeyboardInteractiveConnectionInfo() |
| | 2 | 187 | | { |
| | 1 | 188 | | Dispose(disposing: false); |
| | 2 | 189 | | } |
| | | 190 | | } |
| | | 191 | | } |