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