273
|
1 /*
|
|
2 * Copyright (c) 2006-2013 Christian Plattner. All rights reserved.
|
|
3 * Please refer to the LICENSE.txt for licensing details.
|
|
4 */
|
|
5 package ch.ethz.ssh2.packets;
|
|
6
|
|
7 import java.io.IOException;
|
|
8 import java.util.Arrays;
|
|
9 import java.util.HashSet;
|
|
10 import java.util.Set;
|
|
11
|
|
12 import ch.ethz.ssh2.PacketFormatException;
|
|
13 import ch.ethz.ssh2.PacketTypeException;
|
|
14
|
|
15 /**
|
|
16 * @author Christian Plattner
|
|
17 * @version $Id: PacketUserauthFailure.java 160 2014-05-01 14:30:26Z dkocher@sudo.ch $
|
|
18 */
|
|
19 public final class PacketUserauthFailure {
|
|
20
|
|
21 private final byte[] payload;
|
|
22
|
|
23 private Set<String> authThatCanContinue;
|
|
24
|
|
25 private boolean partialSuccess;
|
|
26
|
|
27 public PacketUserauthFailure(Set<String> authThatCanContinue, boolean partialSuccess) {
|
|
28 this.authThatCanContinue = authThatCanContinue;
|
|
29 this.partialSuccess = partialSuccess;
|
|
30 TypesWriter tw = new TypesWriter();
|
|
31 tw.writeByte(Packets.SSH_MSG_USERAUTH_FAILURE);
|
|
32 tw.writeNameList(authThatCanContinue.toArray(new String[authThatCanContinue.size()]));
|
|
33 tw.writeBoolean(partialSuccess);
|
|
34 payload = tw.getBytes();
|
|
35 }
|
|
36
|
|
37 public PacketUserauthFailure(byte payload[]) throws IOException {
|
|
38 this.payload = payload;
|
|
39 TypesReader tr = new TypesReader(payload);
|
|
40 int packet_type = tr.readByte();
|
|
41
|
307
|
42 if (packet_type != Packets.SSH_MSG_USERAUTH_FAILURE) {
|
273
|
43 throw new PacketTypeException(packet_type);
|
|
44 }
|
307
|
45
|
273
|
46 authThatCanContinue = new HashSet<String>(Arrays.asList(tr.readNameList()));
|
|
47 partialSuccess = tr.readBoolean();
|
|
48
|
307
|
49 if (tr.remain() != 0) {
|
273
|
50 throw new PacketFormatException(String.format("Padding in %s", Packets.getMessageName(packet_type)));
|
|
51 }
|
|
52 }
|
|
53
|
|
54 public byte[] getPayload() {
|
|
55 return payload;
|
|
56 }
|
|
57
|
|
58 public Set<String> getAuthThatCanContinue() {
|
|
59 return authThatCanContinue;
|
|
60 }
|
|
61
|
|
62 public boolean isPartialSuccess() {
|
|
63 return partialSuccess;
|
|
64 }
|
|
65 }
|