src/java.security.jgss/share/classes/sun/security/krb5/internal/NetClient.java
author mbalao
Wed, 05 Jun 2019 01:42:11 -0300
changeset 55258 d65d3c37232c
parent 47216 71c04702a3d5
permissions -rw-r--r--
8215032: Support Kerberos cross-realm referrals (RFC 6806) Reviewed-by: weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 20804
diff changeset
     2
 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *  (C) Copyright IBM Corp. 1999 All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *  Copyright 1997 The Open Group Research Institute.  All rights reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
package sun.security.krb5.internal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.net.*;
32933
83d50f1247bb 8138978: Examine usages of sun.misc.IOUtils
chegar
parents: 31538
diff changeset
    36
import sun.security.util.IOUtils;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
12842
f6f9cb8f6b97 7162687: enhance KDC server availability detection
weijun
parents: 9268
diff changeset
    38
public abstract class NetClient implements AutoCloseable {
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
    39
    public static NetClient getInstance(String protocol, String hostname, int port,
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
    40
            int timeout) throws IOException {
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
    41
        if (protocol.equals("TCP")) {
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
    42
            return new TCPClient(hostname, port, timeout);
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
    43
        } else {
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
    44
            return new UDPClient(hostname, port, timeout);
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
    45
        }
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
    46
    }
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
    47
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
    48
    abstract public void send(byte[] data) throws IOException;
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
    49
    abstract public byte[] receive() throws IOException;
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
    50
    abstract public void close() throws IOException;
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
    51
}
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
    52
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
    53
class TCPClient extends NetClient {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private Socket tcpSocket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private BufferedOutputStream out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private BufferedInputStream in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
    59
    TCPClient(String hostname, int port, int timeout)
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
    60
            throws IOException {
9268
0fee35a7b071 7036157: TCP connection does not use kdc_timeout
weijun
parents: 7175
diff changeset
    61
        tcpSocket = new Socket();
0fee35a7b071 7036157: TCP connection does not use kdc_timeout
weijun
parents: 7175
diff changeset
    62
        tcpSocket.connect(new InetSocketAddress(hostname, port), timeout);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        out = new BufferedOutputStream(tcpSocket.getOutputStream());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        in = new BufferedInputStream(tcpSocket.getInputStream());
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
    65
        tcpSocket.setSoTimeout(timeout);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
    68
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public void send(byte[] data) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        byte[] lenField = new byte[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        intToNetworkByteOrder(data.length, lenField, 0, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        out.write(lenField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        out.write(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
    78
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public byte[] receive() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        byte[] lenField = new byte[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        int count = readFully(lenField, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        if (count != 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            if (Krb5.DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                System.out.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                    ">>>DEBUG: TCPClient could not read length field");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        int len = networkByteOrderToInt(lenField, 0, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        if (Krb5.DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            System.out.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                ">>>DEBUG: TCPClient reading " + len + " bytes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        if (len <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            if (Krb5.DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                System.out.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                    ">>>DEBUG: TCPClient zero or negative length field: "+len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
20804
18285d130365 8014341: Better service from Kerberos servers
weijun
parents: 14342
diff changeset
   104
        try {
18285d130365 8014341: Better service from Kerberos servers
weijun
parents: 14342
diff changeset
   105
            return IOUtils.readFully(in, len, true);
18285d130365 8014341: Better service from Kerberos servers
weijun
parents: 14342
diff changeset
   106
        } catch (IOException ioe) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            if (Krb5.DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                System.out.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                    ">>>DEBUG: TCPClient could not read complete packet (" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                    len + "/" + count + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   116
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public void close() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        tcpSocket.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Read requested number of bytes before returning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @return The number of bytes actually read; -1 if none read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    private int readFully(byte[] inBuf, int total) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        int count, pos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        while (total > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            count = in.read(inBuf, pos, total);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            if (count == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                return (pos == 0? -1 : pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            pos += count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            total -= count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Returns the integer represented by 4 bytes in network byte order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   143
    private static int networkByteOrderToInt(byte[] buf, int start,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        int count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        if (count > 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                "Cannot handle more than 4 bytes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        int answer = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        for (int i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            answer <<= 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            answer |= ((int)buf[start+i] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        return answer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * Encodes an integer into 4 bytes in network byte order in the buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * supplied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     */
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   163
    private static void intToNetworkByteOrder(int num, byte[] buf,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        int start, int count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        if (count > 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                "Cannot handle more than 4 bytes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        for (int i = count-1; i >= 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            buf[start+i] = (byte)(num & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            num >>>= 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
}
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   176
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   177
class UDPClient extends NetClient {
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   178
    InetAddress iaddr;
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   179
    int iport;
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   180
    int bufSize = 65507;
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   181
    DatagramSocket dgSocket;
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   182
    DatagramPacket dgPacketIn;
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   183
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   184
    UDPClient(String hostname, int port, int timeout)
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   185
        throws UnknownHostException, SocketException {
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   186
        iaddr = InetAddress.getByName(hostname);
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   187
        iport = port;
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   188
        dgSocket = new DatagramSocket();
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   189
        dgSocket.setSoTimeout(timeout);
12842
f6f9cb8f6b97 7162687: enhance KDC server availability detection
weijun
parents: 9268
diff changeset
   190
        dgSocket.connect(iaddr, iport);
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   191
    }
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   192
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   193
    @Override
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   194
    public void send(byte[] data) throws IOException {
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   195
        DatagramPacket dgPacketOut = new DatagramPacket(data, data.length,
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   196
                                                        iaddr, iport);
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   197
        dgSocket.send(dgPacketOut);
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   198
    }
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   199
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   200
    @Override
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   201
    public byte[] receive() throws IOException {
31538
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 25859
diff changeset
   202
        byte[] ibuf = new byte[bufSize];
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   203
        dgPacketIn = new DatagramPacket(ibuf, ibuf.length);
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   204
        try {
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   205
            dgSocket.receive(dgPacketIn);
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   206
        }
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   207
        catch (SocketException e) {
12842
f6f9cb8f6b97 7162687: enhance KDC server availability detection
weijun
parents: 9268
diff changeset
   208
            if (e instanceof PortUnreachableException) {
f6f9cb8f6b97 7162687: enhance KDC server availability detection
weijun
parents: 9268
diff changeset
   209
                throw e;
f6f9cb8f6b97 7162687: enhance KDC server availability detection
weijun
parents: 9268
diff changeset
   210
            }
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   211
            dgSocket.receive(dgPacketIn);
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   212
        }
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   213
        byte[] data = new byte[dgPacketIn.getLength()];
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   214
        System.arraycopy(dgPacketIn.getData(), 0, data, 0,
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   215
                         dgPacketIn.getLength());
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   216
        return data;
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   217
    }
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   218
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   219
    @Override
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   220
    public void close() {
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   221
        dgSocket.close();
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   222
    }
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   223
}