Source Code Cross Referenced for ChannelAgentForwarding.java in  » Net » JSch » com » jcraft » jsch » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » JSch » com.jcraft.jsch 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
002:        /*
003:         Copyright (c) 2006-2008 ymnk, JCraft,Inc. All rights reserved.
004:
005:         Redistribution and use in source and binary forms, with or without
006:         modification, are permitted provided that the following conditions are met:
007:
008:         1. Redistributions of source code must retain the above copyright notice,
009:         this list of conditions and the following disclaimer.
010:
011:         2. Redistributions in binary form must reproduce the above copyright 
012:         notice, this list of conditions and the following disclaimer in 
013:         the documentation and/or other materials provided with the distribution.
014:
015:         3. The names of the authors may not be used to endorse or promote products
016:         derived from this software without specific prior written permission.
017:
018:         THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
019:         INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
020:         FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
021:         INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
022:         INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
023:         LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
024:         OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
025:         LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
026:         NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
027:         EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028:         */
029:
030:        package com.jcraft.jsch;
031:
032:        import java.net.*;
033:        import java.util.Vector;
034:
035:        class ChannelAgentForwarding extends Channel {
036:
037:            static private final int LOCAL_WINDOW_SIZE_MAX = 0x20000;
038:            static private final int LOCAL_MAXIMUM_PACKET_SIZE = 0x4000;
039:
040:            private final int SSH2_AGENTC_REQUEST_IDENTITIES = 11;
041:            private final int SSH2_AGENT_IDENTITIES_ANSWER = 12;
042:            private final int SSH2_AGENTC_SIGN_REQUEST = 13;
043:            private final int SSH2_AGENT_SIGN_RESPONSE = 14;
044:            private final int SSH2_AGENTC_ADD_IDENTITY = 17;
045:            private final int SSH2_AGENTC_REMOVE_IDENTITY = 18;
046:            private final int SSH2_AGENTC_REMOVE_ALL_IDENTITIES = 19;
047:            private final int SSH2_AGENT_FAILURE = 30;
048:
049:            boolean init = true;
050:
051:            private Buffer rbuf = null;
052:            private Buffer wbuf = null;
053:            private Packet packet = null;
054:            private Buffer mbuf = null;
055:
056:            ChannelAgentForwarding() {
057:                super ();
058:
059:                setLocalWindowSizeMax(LOCAL_WINDOW_SIZE_MAX);
060:                setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX);
061:                setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE);
062:
063:                type = "auth-agent@openssh.com".getBytes();
064:                rbuf = new Buffer();
065:                rbuf.reset();
066:                //wbuf=new Buffer(rmpsize);
067:                //packet=new Packet(wbuf);
068:                mbuf = new Buffer();
069:                connected = true;
070:            }
071:
072:            public void run() {
073:                try {
074:                    sendOpenConfirmation();
075:                } catch (Exception e) {
076:                    close = true;
077:                    disconnect();
078:                }
079:            }
080:
081:            void write(byte[] foo, int s, int l) throws java.io.IOException {
082:
083:                if (packet == null) {
084:                    wbuf = new Buffer(rmpsize);
085:                    packet = new Packet(wbuf);
086:                }
087:
088:                rbuf.shift();
089:                if (rbuf.buffer.length < rbuf.index + l) {
090:                    byte[] newbuf = new byte[rbuf.s + l];
091:                    System.arraycopy(rbuf.buffer, 0, newbuf, 0,
092:                            rbuf.buffer.length);
093:                    rbuf.buffer = newbuf;
094:                }
095:
096:                rbuf.putByte(foo, s, l);
097:
098:                int mlen = rbuf.getInt();
099:                if (mlen > rbuf.getLength()) {
100:                    rbuf.s -= 4;
101:                    return;
102:                }
103:
104:                int typ = rbuf.getByte();
105:
106:                Vector identities = getSession().jsch.identities;
107:                UserInfo userinfo = getSession().getUserInfo();
108:
109:                if (typ == SSH2_AGENTC_REQUEST_IDENTITIES) {
110:                    mbuf.reset();
111:                    mbuf.putByte((byte) SSH2_AGENT_IDENTITIES_ANSWER);
112:                    synchronized (identities) {
113:                        int count = 0;
114:                        for (int i = 0; i < identities.size(); i++) {
115:                            Identity identity = (Identity) (identities
116:                                    .elementAt(i));
117:                            if (identity.getPublicKeyBlob() != null)
118:                                count++;
119:                        }
120:                        mbuf.putInt(count);
121:                        for (int i = 0; i < identities.size(); i++) {
122:                            Identity identity = (Identity) (identities
123:                                    .elementAt(i));
124:                            byte[] pubkeyblob = identity.getPublicKeyBlob();
125:                            if (pubkeyblob == null)
126:                                continue;
127:                            mbuf.putString(pubkeyblob);
128:                            mbuf.putString("".getBytes());
129:                        }
130:                    }
131:                    byte[] bar = new byte[mbuf.getLength()];
132:                    mbuf.getByte(bar);
133:
134:                    send(bar);
135:                } else if (typ == SSH2_AGENTC_SIGN_REQUEST) {
136:                    byte[] blob = rbuf.getString();
137:                    byte[] data = rbuf.getString();
138:                    int flags = rbuf.getInt();
139:
140:                    //      if((flags & 1)!=0){ //SSH_AGENT_OLD_SIGNATURE // old OpenSSH 2.0, 2.1
141:                    //        datafellows = SSH_BUG_SIGBLOB;
142:                    //      }
143:
144:                    Identity identity = null;
145:                    synchronized (identities) {
146:                        for (int i = 0; i < identities.size(); i++) {
147:                            Identity _identity = (Identity) (identities
148:                                    .elementAt(i));
149:                            if (_identity.getPublicKeyBlob() == null)
150:                                continue;
151:                            if (!Util.array_equals(blob, _identity
152:                                    .getPublicKeyBlob())) {
153:                                continue;
154:                            }
155:                            if (_identity.isEncrypted()) {
156:                                if (userinfo == null)
157:                                    continue;
158:                                while (_identity.isEncrypted()) {
159:                                    if (!userinfo
160:                                            .promptPassphrase("Passphrase for "
161:                                                    + _identity.getName())) {
162:                                        break;
163:                                    }
164:
165:                                    String _passphrase = userinfo
166:                                            .getPassphrase();
167:                                    if (_passphrase == null) {
168:                                        break;
169:                                    }
170:
171:                                    byte[] passphrase = Util
172:                                            .str2byte(_passphrase);
173:                                    try {
174:                                        if (_identity.setPassphrase(passphrase)) {
175:                                            break;
176:                                        }
177:                                    } catch (JSchException e) {
178:                                        break;
179:                                    }
180:                                }
181:                            }
182:
183:                            if (!_identity.isEncrypted()) {
184:                                identity = _identity;
185:                                break;
186:                            }
187:                        }
188:                    }
189:
190:                    byte[] signature = null;
191:
192:                    if (identity != null) {
193:                        signature = identity.getSignature(data);
194:                    }
195:
196:                    mbuf.reset();
197:                    if (signature == null) {
198:                        mbuf.putByte((byte) SSH2_AGENT_FAILURE);
199:                    } else {
200:                        mbuf.putByte((byte) SSH2_AGENT_SIGN_RESPONSE);
201:                        mbuf.putString(signature);
202:                    }
203:
204:                    byte[] bar = new byte[mbuf.getLength()];
205:                    mbuf.getByte(bar);
206:
207:                    send(bar);
208:                }
209:            }
210:
211:            private void send(byte[] message) {
212:                packet.reset();
213:                wbuf.putByte((byte) Session.SSH_MSG_CHANNEL_DATA);
214:                wbuf.putInt(recipient);
215:                wbuf.putInt(4 + message.length);
216:                wbuf.putString(message);
217:
218:                try {
219:                    session.write(packet, this , 4 + message.length);
220:                } catch (Exception e) {
221:                }
222:            }
223:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.