001: /*
002: * SSHTools - Java SSH2 API
003: *
004: * Copyright (C) 2002-2003 Lee David Painter and Contributors.
005: *
006: * Contributions made by:
007: *
008: * Brett Smith
009: * Richard Pernavas
010: * Erwin Bolwidt
011: *
012: * This program is free software; you can redistribute it and/or
013: * modify it under the terms of the GNU General Public License
014: * as published by the Free Software Foundation; either version 2
015: * of the License, or (at your option) any later version.
016: *
017: * This program is distributed in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020: * GNU General Public License for more details.
021: *
022: * You should have received a copy of the GNU General Public License
023: * along with this program; if not, write to the Free Software
024: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
025: */
026: package com.sshtools.j2ssh.agent;
027:
028: import com.sshtools.j2ssh.io.ByteArrayReader;
029: import com.sshtools.j2ssh.io.ByteArrayWriter;
030: import com.sshtools.j2ssh.subsystem.SubsystemMessage;
031: import com.sshtools.j2ssh.transport.InvalidMessageException;
032: import com.sshtools.j2ssh.transport.publickey.SshKeyPairFactory;
033: import com.sshtools.j2ssh.transport.publickey.SshPublicKey;
034:
035: import java.io.IOException;
036:
037: class SshAgentPrivateKeyOp extends SubsystemMessage {
038: /** */
039: public static final int SSH_AGENT_PRIVATE_KEY_OP = 205;
040: SshPublicKey pubkey;
041: String operation;
042: byte[] data;
043:
044: /**
045: * Creates a new SshAgentPrivateKeyOp object.
046: */
047: public SshAgentPrivateKeyOp() {
048: super (SSH_AGENT_PRIVATE_KEY_OP);
049: }
050:
051: /**
052: * Creates a new SshAgentPrivateKeyOp object.
053: *
054: * @param pubkey
055: * @param operation
056: * @param data
057: */
058: public SshAgentPrivateKeyOp(SshPublicKey pubkey, String operation,
059: byte[] data) {
060: super (SSH_AGENT_PRIVATE_KEY_OP);
061: this .pubkey = pubkey;
062: this .operation = operation;
063: this .data = data;
064: }
065:
066: /**
067: *
068: *
069: * @return
070: */
071: public SshPublicKey getPublicKey() {
072: return pubkey;
073: }
074:
075: /**
076: *
077: *
078: * @return
079: */
080: public String getOperation() {
081: return operation;
082: }
083:
084: /**
085: *
086: *
087: * @return
088: */
089: public byte[] getOperationData() {
090: return data;
091: }
092:
093: /**
094: *
095: *
096: * @return
097: */
098: public String getMessageName() {
099: return "SSH_AGENT_PRIVATE_KEY_OP";
100: }
101:
102: /**
103: *
104: *
105: * @param baw
106: *
107: * @throws java.io.IOException
108: * @throws com.sshtools.j2ssh.transport.InvalidMessageException DOCUMENT
109: * ME!
110: * @throws InvalidMessageException
111: */
112: public void constructByteArray(ByteArrayWriter baw)
113: throws java.io.IOException,
114: com.sshtools.j2ssh.transport.InvalidMessageException {
115: try {
116: baw.writeString(operation);
117: baw.writeBinaryString(pubkey.getEncoded());
118: baw.write(data);
119: } catch (IOException ex) {
120: throw new InvalidMessageException(ex.getMessage());
121: }
122: }
123:
124: /**
125: *
126: *
127: * @param bar
128: *
129: * @throws java.io.IOException
130: * @throws com.sshtools.j2ssh.transport.InvalidMessageException DOCUMENT
131: * ME!
132: * @throws InvalidMessageException
133: */
134: public void constructMessage(ByteArrayReader bar)
135: throws java.io.IOException,
136: com.sshtools.j2ssh.transport.InvalidMessageException {
137: try {
138: operation = bar.readString();
139: pubkey = SshKeyPairFactory.decodePublicKey(bar
140: .readBinaryString());
141: data = new byte[bar.available()];
142: bar.read(data);
143: } catch (IOException ex) {
144: throw new InvalidMessageException(ex.getMessage());
145: }
146: }
147: }
|