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.transport.kex;
027:
028: import java.math.*;
029:
030: /**
031: *
032: *
033: * @author $author$
034: * @version $Revision: 1.16 $
035: */
036: public class KeyExchangeState {
037: /** */
038: public final static int IN_PROGRESS = 0;
039:
040: /** */
041: public final static int COMPLETE = 1;
042:
043: /** */
044: public final static int FAILED = 2;
045: private BigInteger secret;
046: private String reason;
047: private byte[] exchangeHash;
048: private byte[] hostKey;
049: private byte[] signature;
050: private int state = IN_PROGRESS;
051:
052: /**
053: * Creates a new KeyExchangeState object.
054: */
055: public KeyExchangeState() {
056: }
057:
058: /**
059: *
060: *
061: * @param exchangeHash
062: * @param hostKey
063: * @param signature
064: * @param secret
065: */
066: public final synchronized void setComplete(byte[] exchangeHash,
067: byte[] hostKey, byte[] signature, BigInteger secret) {
068: this .exchangeHash = exchangeHash;
069: this .hostKey = hostKey;
070: this .signature = signature;
071: this .secret = secret;
072: state = COMPLETE;
073: notifyAll();
074: }
075:
076: /**
077: *
078: *
079: * @return
080: */
081: public byte[] getExchangeHash() {
082: return exchangeHash;
083: }
084:
085: /**
086: *
087: *
088: * @param reason
089: */
090: public final synchronized void setFailed(String reason) {
091: this .reason = reason;
092: state = FAILED;
093: notifyAll();
094: }
095:
096: /**
097: *
098: *
099: * @return
100: */
101: public byte[] getHostKey() {
102: return hostKey;
103: }
104:
105: /**
106: *
107: *
108: * @return
109: */
110: public BigInteger getSecret() {
111: return secret;
112: }
113:
114: /**
115: *
116: *
117: * @return
118: */
119: public byte[] getSignature() {
120: return signature;
121: }
122:
123: /**
124: *
125: *
126: * @return
127: */
128: public synchronized int getState() {
129: return state;
130: }
131:
132: /**
133: *
134: */
135: public final synchronized void waitForCompletion() {
136: while (state == IN_PROGRESS) {
137: try {
138: wait();
139: } catch (InterruptedException e) {
140: }
141: }
142: }
143:
144: /**
145: *
146: *
147: * @return
148: */
149: public synchronized String getFailureReason() {
150: return reason;
151: }
152: }
|