private void SendSign(SSH2DataReader r) { byte[] blob = r.ReadString(); byte[] data = r.ReadString(); //Debug.WriteLine(String.Format("SignRequest blobsize={0} datasize={1}", blob.Length, data.Length)); SSH2UserAuthKey[] keys = _client.GetAvailableSSH2UserAuthKeys(); SSH2UserAuthKey key = FindKey(keys, blob); if (key == null) { TransmitWriter(OpenWriter(AgentForwadPacketType.SSH_AGENT_FAILURE)); _client.NotifyPublicKeyDidNotMatch(); } else { SSH2DataWriter signpack = new SSH2DataWriter(); signpack.WriteString(SSH2Util.PublicKeyAlgorithmName(key.Algorithm)); signpack.WriteAsString(key.Sign(data)); SSH2DataWriter wr = OpenWriter(AgentForwadPacketType.SSH2_AGENT_SIGN_RESPONSE); wr.WriteAsString(signpack.ToByteArray()); TransmitWriter(wr); } }
/// <summary> /// SSH2 private key signature /// </summary> private void SSH2Sign(byte[] blob, byte[] data, uint flags) { if ((flags & SSH_AGENT_OLD_SIGNATURE) != 0) { SendFailure(); return; } SSH2UserAuthKey key = SSH2FindKey(blob); if (key == null) { SendFailure(); return; } SSH2PayloadImageBuilder image = new SSH2PayloadImageBuilder(); image.WriteString(SSH2Util.PublicKeyAlgorithmName(key.Algorithm)); image.WriteAsString(key.Sign(data)); byte[] signatureBlob = image.GetBytes(); Send( new OpenSSHAgentForwardingMessage(OpenSSHAgentForwardingMessageType.SSH2_AGENT_SIGN_RESPONSE) .WriteAsString(signatureBlob) ); }