Mercurial > 510Connectbot
comparison src/ch/ethz/ssh2/auth/AuthenticationManager.java @ 282:c3019725b123 ganymed
start conversion from trilead to ganymed
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 18 Jul 2014 17:19:41 -0700 |
parents | 51d5f434ef6b |
children | 3855f58ffd2b |
comparison
equal
deleted
inserted
replaced
281:b4ca341c318d | 282:c3019725b123 |
---|---|
198 return false; | 198 return false; |
199 } | 199 } |
200 throw new PacketTypeException(type); | 200 throw new PacketTypeException(type); |
201 } | 201 } |
202 | 202 |
203 public boolean authenticatePublicKey(String user, char[] PEMPrivateKey, String password, SecureRandom rnd) | 203 public boolean authenticatePublicKey(String user, KeyPair pair, String password, SecureRandom rnd) |
204 throws IOException { | 204 throws IOException { |
205 PrivateKey key = pair.getPrivate(); | |
205 try { | 206 try { |
206 initialize(user); | 207 initialize(user); |
207 | 208 |
208 if(!remainingMethods.contains("publickey")) { | 209 if(!remainingMethods.contains("publickey")) { |
209 throw new IOException("Authentication method publickey not supported by the server at this stage."); | 210 throw new IOException("Authentication method publickey not supported by the server at this stage."); |
210 } | 211 } |
211 | 212 |
212 Object key = PEMDecoder.decode(PEMPrivateKey, password); | 213 if (key instanceof DSAPrivateKey) { |
213 | |
214 if(key instanceof DSAPrivateKey) { | |
215 DSAPrivateKey pk = (DSAPrivateKey) key; | 214 DSAPrivateKey pk = (DSAPrivateKey) key; |
216 | 215 |
217 byte[] pk_enc = DSASHA1Verify.encodeSSHDSAPublicKey(pk.getPublicKey()); | 216 byte[] pk_enc = DSASHA1Verify.encodeSSHDSAPublicKey((DSAPublicKey) pair.getPublic()); |
218 | 217 |
219 TypesWriter tw = new TypesWriter(); | 218 TypesWriter tw = new TypesWriter(); |
220 | 219 |
221 byte[] H = tm.getSessionIdentifier(); | 220 byte[] H = tm.getSessionIdentifier(); |
222 | 221 |
240 tm.sendMessage(ua.getPayload()); | 239 tm.sendMessage(ua.getPayload()); |
241 } | 240 } |
242 else if(key instanceof RSAPrivateKey) { | 241 else if(key instanceof RSAPrivateKey) { |
243 RSAPrivateKey pk = (RSAPrivateKey) key; | 242 RSAPrivateKey pk = (RSAPrivateKey) key; |
244 | 243 |
245 byte[] pk_enc = RSASHA1Verify.encodeSSHRSAPublicKey(pk.getPublicKey()); | 244 byte[] pk_enc = RSASHA1Verify.encodeSSHRSAPublicKey((RSAPublicKey) pair.getPublic()); |
246 | 245 |
247 TypesWriter tw = new TypesWriter(); | 246 TypesWriter tw = new TypesWriter(); |
248 { | 247 { |
249 byte[] H = tm.getSessionIdentifier(); | 248 byte[] H = tm.getSessionIdentifier(); |
250 | 249 |
264 | 263 |
265 byte[] rsa_sig_enc = RSASHA1Verify.encodeSSHRSASignature(ds); | 264 byte[] rsa_sig_enc = RSASHA1Verify.encodeSSHRSASignature(ds); |
266 | 265 |
267 PacketUserauthRequestPublicKey ua = new PacketUserauthRequestPublicKey("ssh-connection", user, | 266 PacketUserauthRequestPublicKey ua = new PacketUserauthRequestPublicKey("ssh-connection", user, |
268 "ssh-rsa", pk_enc, rsa_sig_enc); | 267 "ssh-rsa", pk_enc, rsa_sig_enc); |
268 tm.sendMessage(ua.getPayload()); | |
269 } | |
270 else if (key instanceof ECPrivateKey) { | |
271 ECPrivateKey pk = (ECPrivateKey) key; | |
272 final String algo = ECDSASHA2Verify.ECDSA_SHA2_PREFIX | |
273 + ECDSASHA2Verify.getCurveName(pk.getParams()); | |
274 byte[] pk_enc = ECDSASHA2Verify.encodeSSHECDSAPublicKey((ECPublicKey) pair.getPublic()); | |
275 TypesWriter tw = new TypesWriter(); | |
276 { | |
277 byte[] H = tm.getSessionIdentifier(); | |
278 tw.writeString(H, 0, H.length); | |
279 tw.writeByte(Packets.SSH_MSG_USERAUTH_REQUEST); | |
280 tw.writeString(user); | |
281 tw.writeString("ssh-connection"); | |
282 tw.writeString("publickey"); | |
283 tw.writeBoolean(true); | |
284 tw.writeString(algo); | |
285 tw.writeString(pk_enc, 0, pk_enc.length); | |
286 } | |
287 byte[] msg = tw.getBytes(); | |
288 byte[] ds = ECDSASHA2Verify.generateSignature(msg, pk); | |
289 byte[] ec_sig_enc = ECDSASHA2Verify.encodeSSHECDSASignature(ds, pk.getParams()); | |
290 PacketUserauthRequestPublicKey ua = new PacketUserauthRequestPublicKey("ssh-connection", user, | |
291 algo, pk_enc, ec_sig_enc); | |
269 tm.sendMessage(ua.getPayload()); | 292 tm.sendMessage(ua.getPayload()); |
270 } | 293 } |
271 else { | 294 else { |
272 throw new IOException("Unknown private key type returned by the PEM decoder."); | 295 throw new IOException("Unknown private key type returned by the PEM decoder."); |
273 } | 296 } |