Fix AES-256-CBC SSH private key decryption

Restore silverlight compatibility
This commit is contained in:
olegkap_cp
2012-12-20 01:41:43 +00:00
parent d551995eb6
commit 41bb6920d0
5 changed files with 50 additions and 33 deletions
@@ -519,6 +519,9 @@
<Compile Include="..\Renci.SshNet\Security\Cryptography\Ciphers\Paddings\PKCS7Padding.cs">
<Link>Security\Cryptography\Ciphers\Paddings\PKCS7Padding.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet\Security\Cryptography\Ciphers\Paddings\PKCS5Padding.cs">
<Link>Security\Cryptography\Ciphers\Paddings\PKCS5Padding.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet\Security\Cryptography\Ciphers\RsaCipher.cs">
<Link>Security\Cryptography\Ciphers\RsaCipher.cs</Link>
</Compile>
@@ -26,6 +26,11 @@ namespace Renci.SshNet
private bool _isConnected = false;
partial void IsSocketConnected(ref bool isConnected)
{
isConnected = (!this._isDisconnecting && this._socket != null && this._socket.Connected && this._isAuthenticated && this._messageListenerCompleted != null && this._isConnected);
}
partial void SocketConnect(string host, int port)
{
var ep = new DnsEndPoint(host, port);
@@ -94,39 +99,39 @@ namespace Renci.SshNet
do
{
SocketAsyncEventArgs args = new SocketAsyncEventArgs();
args.SetBuffer(buffer, offset + receivedTotal, length - receivedTotal);
args.UserToken = this._socket;
args.RemoteEndPoint = this._socket.RemoteEndPoint;
args.Completed += new EventHandler<SocketAsyncEventArgs>(OnReceive);
this._socket.ReceiveAsync(args);
SocketAsyncEventArgs args = new SocketAsyncEventArgs();
args.SetBuffer(buffer, offset + receivedTotal, length - receivedTotal);
args.UserToken = this._socket;
args.RemoteEndPoint = this._socket.RemoteEndPoint;
args.Completed += new EventHandler<SocketAsyncEventArgs>(OnReceive);
this._socket.ReceiveAsync(args);
this._receiveEvent.WaitOne(this.ConnectionInfo.Timeout);
this._receiveEvent.WaitOne(this.ConnectionInfo.Timeout);
if (args.SocketError == SocketError.WouldBlock ||
args.SocketError == SocketError.IOPending ||
args.SocketError == SocketError.NoBufferSpaceAvailable)
{
// socket buffer is probably empty, wait and try again
Thread.Sleep(30);
continue;
}
else if (args.SocketError != SocketError.Success)
{
throw new SocketException((int)args.SocketError);
}
if (args.SocketError == SocketError.WouldBlock ||
args.SocketError == SocketError.IOPending ||
args.SocketError == SocketError.NoBufferSpaceAvailable)
{
// socket buffer is probably empty, wait and try again
Thread.Sleep(30);
continue;
}
else if (args.SocketError != SocketError.Success)
{
throw new SocketException((int)args.SocketError);
}
var receivedBytes = args.BytesTransferred;
var receivedBytes = args.BytesTransferred;
if (receivedBytes > 0)
{
receivedTotal += receivedBytes;
continue;
}
else
{
throw new SshConnectionException("An established connection was aborted by the software in your host machine.", DisconnectReason.ConnectionLost);
}
if (receivedBytes > 0)
{
receivedTotal += receivedBytes;
continue;
}
else
{
throw new SshConnectionException("An established connection was aborted by the software in your host machine.", DisconnectReason.ConnectionLost);
}
} while (receivedTotal < length);
}
@@ -174,8 +179,8 @@ namespace Renci.SshNet
{
foreach (var item in from m in this._messagesMetadata where m.Name == messageName select m)
{
item.Enabled = true;
item.Activated = true;
item.Enabled = true;
item.Activated = true;
}
}
}
@@ -151,7 +151,7 @@ namespace Renci.SshNet
cipher = new CipherInfo(192, (key, iv) => { return new AesCipher(key, new CbcCipherMode(iv), new PKCS7Padding()); });
break;
case "AES-256-CBC":
cipher = new CipherInfo(256, (key, iv) => { return new AesCipher(key, new CbcCipherMode(iv), new PKCS5Padding()); });
cipher = new CipherInfo(256, (key, iv) => { return new AesCipher(key, new CbcCipherMode(iv), new PKCS7Padding()); });
break;
default:
throw new SshException(string.Format(CultureInfo.CurrentCulture, "Private key cipher \"{0}\" is not supported.", cipherName));
@@ -22,6 +22,11 @@ namespace Renci.SshNet
new TraceSource("SshNet.Logging");
#endif
partial void IsSocketConnected(ref bool isConnected)
{
isConnected = (!this._isDisconnecting && this._socket != null && this._socket.Connected && this._isAuthenticated && this._messageListenerCompleted != null) && !(this._socket.Poll(10, SelectMode.SelectRead));
}
partial void SocketConnect(string host, int port)
{
IPAddress addr;
+5 -1
View File
@@ -183,7 +183,9 @@ namespace Renci.SshNet
{
get
{
return (!this._isDisconnecting && this._socket != null && this._socket.Connected && this._isAuthenticated && this._messageListenerCompleted != null) && !(this._socket.Poll(10, SelectMode.SelectRead));
var isSocketConnected = false;
IsSocketConnected(ref isSocketConnected);
return isSocketConnected;
}
}
@@ -1552,6 +1554,8 @@ namespace Renci.SshNet
partial void ExecuteThread(Action action);
partial void IsSocketConnected(ref bool isConnected);
partial void SocketConnect(string host, int port);
partial void SocketDisconnect();