1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package net.sf.michaelo.tomcat.pac;
17  
18  import java.nio.charset.StandardCharsets;
19  import java.util.Objects;
20  
21  import net.sf.michaelo.tomcat.realm.Sid;
22  
23  
24  
25  
26  
27  
28  public class UpnDnsInfo {
29  
30  	public final static long UPN_CONSTRUCTED_FLAG = 0x00000001L;
31  	public final static long SAM_NAME_AND_SID_FLAG = 0x00000002L;
32  
33  	private final String upn;
34  	private final String dnsDomainName;
35  
36  	private final long flags;
37  
38  	private String samName;
39  	private Sid sid;
40  
41  	
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  	public UpnDnsInfo(byte[] infoBytes) {
52  		Objects.requireNonNull(infoBytes, "infoBytes cannot be null");
53  		if (infoBytes.length == 0)
54  			throw new IllegalArgumentException("infoBytes cannot be empty");
55  
56  		PacDataBuffer buf = new PacDataBuffer(infoBytes);
57  
58  		
59  		int upnLength = buf.getUnsignedShort();
60  		
61  		int upnOffset = buf.getUnsignedShort();
62  		
63  		int dnsDomainNameLength = buf.getUnsignedShort();
64  		
65  		int dnsDomainNameOffset = buf.getUnsignedShort();
66  		
67  		
68  
69  
70  
71  
72  
73  
74  		this.flags = buf.getUnsignedInt();
75  
76  		int pos = buf.position();
77  		buf.position(upnOffset);
78  		this.upn = getUnicodeString(buf, upnLength);
79  		buf.position(dnsDomainNameOffset);
80  		this.dnsDomainName = getUnicodeString(buf, dnsDomainNameLength);
81  		buf.position(pos);
82  
83  		if ((flags & SAM_NAME_AND_SID_FLAG) != 0L) {
84  			
85  			int samNameLength = buf.getUnsignedShort();
86  			
87  			int samNameOffset = buf.getUnsignedShort();
88  			
89  			int sidLength = buf.getUnsignedShort();
90  			
91  			int sidOffset = buf.getUnsignedShort();
92  
93  			pos = buf.position();
94  			buf.position(samNameOffset);
95  			this.samName = getUnicodeString(buf, samNameLength);
96  			byte[] dst = new byte[sidLength];
97  			buf.position(sidOffset);
98  			buf.get(dst);
99  			this.sid = new Sid(dst);
100 		}
101 	}
102 
103 	public String getUpn() {
104 		return upn;
105 	}
106 
107 	public String getDnsDomainName() {
108 		return dnsDomainName;
109 	}
110 
111 	public long getFlags() {
112 		return flags;
113 	}
114 
115 	public String getSamName() {
116 		return samName;
117 	}
118 
119 	public Sid getSid() {
120 		return sid;
121 	}
122 
123 	private String getUnicodeString(PacDataBuffer buf, int length) {
124 		byte[] dst = new byte[length];
125 		buf.get(dst);
126 		return new String(dst, StandardCharsets.UTF_16LE);
127 	}
128 
129 }