jdk/src/share/classes/sun/security/krb5/KrbPriv.java
author prr
Tue, 15 Jul 2014 11:22:14 -0700
changeset 25522 10d789df41bb
parent 14342 8435a30053c1
permissions -rw-r--r--
8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes Reviewed-by: psandoz, prr Contributed-by: otaviopolianasantana@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 13247
diff changeset
     2
 * Copyright (c) 2000, 2012, 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;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.security.krb5.internal.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.security.krb5.internal.crypto.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/** XXX This class does not appear to be used. **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
class KrbPriv extends KrbAppMessage {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private byte[] obuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private byte[] userData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private KrbPriv(byte[] userData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
                   Credentials creds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
                   EncryptionKey subKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
                   KerberosTime timestamp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
                   SeqNumber seqNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                   HostAddress saddr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                   HostAddress raddr
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
                   )  throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        EncryptionKey reqKey = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        if (subKey != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            reqKey = subKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            reqKey = creds.key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        obuf = mk_priv(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                       userData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                       reqKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                       timestamp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                       seqNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                       saddr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                       raddr
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                       );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private KrbPriv(byte[] msg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                   Credentials creds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                   EncryptionKey subKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                   SeqNumber seqNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                   HostAddress saddr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                   HostAddress raddr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                   boolean timestampRequired,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                   boolean seqNumberRequired
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                   )  throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        KRBPriv krb_priv = new KRBPriv(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        EncryptionKey reqKey = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        if (subKey != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            reqKey = subKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            reqKey = creds.key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        userData = rd_priv(krb_priv,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                           reqKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                           seqNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                           saddr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                           raddr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                           timestampRequired,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                           seqNumberRequired,
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 5975
diff changeset
    92
                           creds.client
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                           );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public byte[] getMessage() throws KrbException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        return obuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public byte[] getData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        return userData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private byte[] mk_priv(byte[] userData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                           EncryptionKey key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                           KerberosTime timestamp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                           SeqNumber seqNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                           HostAddress sAddress,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                           HostAddress rAddress
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                           ) throws Asn1Exception, IOException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                           KdcErrException, KrbCryptoException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                               Integer usec = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                               Integer seqno = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                               if (timestamp != null)
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 14342
diff changeset
   117
                               usec = timestamp.getMicroSeconds();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                               if (seqNumber != null) {
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 14342
diff changeset
   120
                                   seqno = seqNumber.current();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                                   seqNumber.step();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                               EncKrbPrivPart unenc_encKrbPrivPart =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                               new EncKrbPrivPart(userData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                                                  timestamp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                                                  usec,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                                                  seqno,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                                                  sAddress,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                                                  rAddress
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                                                  );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                               byte[] temp = unenc_encKrbPrivPart.asn1Encode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                               EncryptedData encKrbPrivPart =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                               new EncryptedData(key, temp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                                   KeyUsage.KU_ENC_KRB_PRIV_PART);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                               KRBPriv krb_priv = new KRBPriv(encKrbPrivPart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                               temp = krb_priv.asn1Encode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                               return krb_priv.asn1Encode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    private byte[] rd_priv(KRBPriv krb_priv,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                           EncryptionKey key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                           SeqNumber seqNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                           HostAddress sAddress,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                           HostAddress rAddress,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                           boolean timestampRequired,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                           boolean seqNumberRequired,
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 5975
diff changeset
   153
                           PrincipalName cname
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                           ) throws Asn1Exception, KdcErrException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                           KrbApErrException, IOException, KrbCryptoException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                               byte[] bytes = krb_priv.encPart.decrypt(key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                                   KeyUsage.KU_ENC_KRB_PRIV_PART);
5975
076cd013e5e4 6946669: SSL/Krb5 should not call EncryptedData.reset(data, false)
weijun
parents: 5506
diff changeset
   159
                               byte[] temp = krb_priv.encPart.reset(bytes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                               DerValue ref = new DerValue(temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                               EncKrbPrivPart enc_part = new EncKrbPrivPart(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                               check(enc_part.timestamp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                                     enc_part.usec,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                                     enc_part.seqNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                                     enc_part.sAddress,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                                     enc_part.rAddress,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                                     seqNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                                     sAddress,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                                     rAddress,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                                     timestampRequired,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                                     seqNumberRequired,
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 5975
diff changeset
   173
                                     cname
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                                     );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                               return enc_part.userData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
}