comparison src/ch/ethz/ssh2/auth/ServerAuthenticationManager.java @ 307:071eccdff8ea ganymed

fix java formatting
author Carl Byington <carl@five-ten-sg.com>
date Wed, 30 Jul 2014 14:16:58 -0700
parents d2b303406d63
children
comparison
equal deleted inserted replaced
305:d2b303406d63 307:071eccdff8ea
27 this.state = state; 27 this.state = state;
28 state.tm.registerMessageHandler(this, 0, 255); 28 state.tm.registerMessageHandler(this, 0, 255);
29 } 29 }
30 30
31 private void sendresult(AuthenticationResult result) throws IOException { 31 private void sendresult(AuthenticationResult result) throws IOException {
32 if(AuthenticationResult.SUCCESS == result) { 32 if (AuthenticationResult.SUCCESS == result) {
33 PacketUserauthSuccess pus = new PacketUserauthSuccess(); 33 PacketUserauthSuccess pus = new PacketUserauthSuccess();
34 state.tm.sendAsynchronousMessage(pus.getPayload()); 34 state.tm.sendAsynchronousMessage(pus.getPayload());
35
36 state.tm.removeMessageHandler(this); 35 state.tm.removeMessageHandler(this);
37 state.tm.registerMessageHandler(this, 50, 79); 36 state.tm.registerMessageHandler(this, 50, 79);
38
39 state.cm = new ChannelManager(state); 37 state.cm = new ChannelManager(state);
40
41 state.flag_auth_completed = true; 38 state.flag_auth_completed = true;
42
43 } 39 }
44 else { 40 else {
45 Set<String> remaining_methods = new HashSet<String>(); 41 Set<String> remaining_methods = new HashSet<String>();
46 42
47 if(state.cb_auth != null) { 43 if (state.cb_auth != null) {
48 remaining_methods.addAll(Arrays.asList( 44 remaining_methods.addAll(Arrays.asList(
49 state.cb_auth.getRemainingAuthMethods(state.conn))); 45 state.cb_auth.getRemainingAuthMethods(state.conn)));
50 } 46 }
47
51 PacketUserauthFailure puf = new PacketUserauthFailure(remaining_methods, 48 PacketUserauthFailure puf = new PacketUserauthFailure(remaining_methods,
52 AuthenticationResult.PARTIAL_SUCCESS == result); 49 AuthenticationResult.PARTIAL_SUCCESS == result);
53 state.tm.sendAsynchronousMessage(puf.getPayload()); 50 state.tm.sendAsynchronousMessage(puf.getPayload());
54 } 51 }
55 } 52 }
58 // 55 //
59 } 56 }
60 57
61 public void handleMessage(byte[] msg) throws IOException { 58 public void handleMessage(byte[] msg) throws IOException {
62 /* Ignore all authentication messages after successful auth */ 59 /* Ignore all authentication messages after successful auth */
63 60 if (state.flag_auth_completed) {
64 if(state.flag_auth_completed) {
65 return; 61 return;
66 } 62 }
67 63
68 if(!state.flag_auth_serviceRequested) { 64 if (!state.flag_auth_serviceRequested) {
69 /* Must be PacketServiceRequest */ 65 /* Must be PacketServiceRequest */
70
71 PacketServiceRequest psr = new PacketServiceRequest(msg); 66 PacketServiceRequest psr = new PacketServiceRequest(msg);
72 67
73 if(!"ssh-userauth".equals(psr.getServiceName())) { 68 if (!"ssh-userauth".equals(psr.getServiceName())) {
74 throw new IOException("SSH protocol error, expected ssh-userauth service request"); 69 throw new IOException("SSH protocol error, expected ssh-userauth service request");
75 } 70 }
76 71
77 PacketServiceAccept psa = new PacketServiceAccept("ssh-userauth"); 72 PacketServiceAccept psa = new PacketServiceAccept("ssh-userauth");
78 state.tm.sendAsynchronousMessage(psa.getPayload()); 73 state.tm.sendAsynchronousMessage(psa.getPayload());
79
80 String banner = state.cb_auth.initAuthentication(state.conn); 74 String banner = state.cb_auth.initAuthentication(state.conn);
81 75
82 if(banner != null) { 76 if (banner != null) {
83 PacketUserauthBanner pub = new PacketUserauthBanner(banner); 77 PacketUserauthBanner pub = new PacketUserauthBanner(banner);
84 state.tm.sendAsynchronousMessage(pub.getPayload()); 78 state.tm.sendAsynchronousMessage(pub.getPayload());
85 } 79 }
86 80
87 state.flag_auth_serviceRequested = true; 81 state.flag_auth_serviceRequested = true;
88
89 return; 82 return;
90 } 83 }
91 84
92 ServerAuthenticationCallback cb = state.cb_auth; 85 ServerAuthenticationCallback cb = state.cb_auth;
93
94 TypesReader tr = new TypesReader(msg); 86 TypesReader tr = new TypesReader(msg);
95 int packet_type = tr.readByte(); 87 int packet_type = tr.readByte();
96 88
97 if(packet_type == Packets.SSH_MSG_USERAUTH_REQUEST) { 89 if (packet_type == Packets.SSH_MSG_USERAUTH_REQUEST) {
98 String username = tr.readString("UTF-8"); 90 String username = tr.readString("UTF-8");
99 String service = tr.readString(); 91 String service = tr.readString();
100 String method = tr.readString(); 92 String method = tr.readString();
101 93
102 if(!"ssh-connection".equals(service)) { 94 if (!"ssh-connection".equals(service)) {
103 sendresult(AuthenticationResult.FAILURE); 95 sendresult(AuthenticationResult.FAILURE);
104 return; 96 return;
105 } 97 }
106 98
107 if("none".equals(method)) { 99 if ("none".equals(method)) {
108 if(cb != null) { 100 if (cb != null) {
109 sendresult(cb.authenticateWithNone(state.conn, username)); 101 sendresult(cb.authenticateWithNone(state.conn, username));
110 return; 102 return;
111 } 103 }
112 } 104 }
113 105
114 if("password".equals(method)) { 106 if ("password".equals(method)) {
115 boolean flag_change_pass = tr.readBoolean(); 107 boolean flag_change_pass = tr.readBoolean();
116 108
117 if(flag_change_pass) { 109 if (flag_change_pass) {
118 sendresult(AuthenticationResult.FAILURE); 110 sendresult(AuthenticationResult.FAILURE);
119 return; 111 return;
120 } 112 }
121 113
122 String password = tr.readString("UTF-8"); 114 String password = tr.readString("UTF-8");
123 115
124 if(cb != null) { 116 if (cb != null) {
125 sendresult(cb.authenticateWithPassword(state.conn, username, password)); 117 sendresult(cb.authenticateWithPassword(state.conn, username, password));
126 return; 118 return;
127 } 119 }
128 } 120 }
129 121
130 sendresult(AuthenticationResult.FAILURE); 122 sendresult(AuthenticationResult.FAILURE);
131 return; 123 return;
132 } 124 }
125
133 throw new PacketTypeException(packet_type); 126 throw new PacketTypeException(packet_type);
134 } 127 }
135 } 128 }