src/java.security.jgss/share/classes/org/ietf/jgss/MessageProp.java
author weijun
Thu, 04 Jul 2019 07:25:47 +0800
changeset 55599 e6c430d4d217
parent 47216 71c04702a3d5
permissions -rw-r--r--
8226963: More clarification on possible sequencing error in GSSContext::unwrap Reviewed-by: mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
29820
7a3f0268f55b 8076223: Rest of tidy warning in javax.security / java.security
avstepan
parents: 25859
diff changeset
     2
 * Copyright (c) 2000, 2015, 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
package org.ietf.jgss;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * This is a utility class used within the per-message GSSContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * methods to convey per-message properties.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * When used with the GSSContext interface's wrap and getMIC methods, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * instance of this class is used to indicate the desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Quality-of-Protection (QOP) and to request if confidentiality services
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * are to be applied to caller supplied data (wrap only).  To request
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * default QOP, the value of 0 should be used for QOP.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * When used with the unwrap and verifyMIC methods of the GSSContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * interface, an instance of this class will be used to indicate the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * applied QOP and confidentiality services over the supplied message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * In the case of verifyMIC, the confidentiality state will always be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <code>false</code>.  Upon return from these methods, this object will also
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * contain any supplementary status values applicable to the processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * token.  The supplementary status values can indicate old tokens, out
29820
7a3f0268f55b 8076223: Rest of tidy warning in javax.security / java.security
avstepan
parents: 25859
diff changeset
    45
 * of sequence tokens, gap tokens or duplicate tokens.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * @see GSSContext#wrap
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @see GSSContext#unwrap
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @see GSSContext#getMIC
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @see GSSContext#verifyMIC
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @author Mayank Upadhyay
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
public class MessageProp {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private boolean privacyState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private int qop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private boolean dupToken;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private boolean oldToken;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private boolean unseqToken;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private boolean gapToken;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private int minorStatus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private String minorString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    * Constructor which sets the desired privacy state. The QOP value used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    * is 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    * @param privState the privacy (i.e. confidentiality) state
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public MessageProp(boolean privState) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        this(0, privState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * Constructor which sets the values for the qop and privacy state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @param qop the QOP value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @param privState the privacy (i.e. confidentiality) state
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public MessageProp(int qop, boolean privState) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        this.qop = qop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        this.privacyState = privState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        resetStatusValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * Retrieves the QOP value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @return an int representing the QOP value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @see #setQOP
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public int getQOP() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        return qop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * Retrieves the privacy state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @return true if the privacy (i.e., confidentiality) state is true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @see #setPrivacy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public boolean getPrivacy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        return (privacyState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Sets the QOP value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @param qop the int value to set the QOP to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @see #getQOP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public void setQOP(int qop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        this.qop = qop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
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
     * Sets the privacy state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @param privState true is the privacy (i.e., confidentiality) state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * is true, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @see #getPrivacy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public void setPrivacy(boolean privState) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        this.privacyState = privState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Tests if this is a duplicate of an earlier token.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @return true if this is a duplicate, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public boolean isDuplicateToken() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        return dupToken;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * Tests if this token's validity period has expired, i.e., the token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * is too old to be checked for duplication.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @return true if the token's validity period has expired, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public boolean isOldToken() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        return oldToken;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * Tests if a later token had already been processed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @return true if a later token had already been processed, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public boolean isUnseqToken() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        return unseqToken;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * Tests if an expected token was not received, i.e., one or more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * predecessor tokens have not yet been successfully processed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @return true if an expected per-message token was not received,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public boolean isGapToken() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        return gapToken;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Retrieves the minor status code that the underlying mechanism might
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * have set for this per-message operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @return the int minor status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public int getMinorStatus(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return minorStatus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Retrieves a string explaining the minor status code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @return a String corresponding to the minor status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * code. <code>null</code> will be returned when no minor status code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * has been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public String getMinorString(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return minorString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * This method sets the state for the supplementary information flags
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * and the minor status in MessageProp.  It is not used by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * application but by the GSS implementation to return this information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * to the caller of a per-message context method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @param duplicate true if the token was a duplicate of an earlier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * token, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @param old true if the token's validity period has expired, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @param unseq true if a later token has already been processed, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @param gap true if one or more predecessor tokens have not yet been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * successfully processed, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @param minorStatus the int minor status code for the per-message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @param  minorString the textual representation of the minorStatus value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
   public void setSupplementaryStates(boolean duplicate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                  boolean old, boolean unseq, boolean gap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                  int minorStatus, String minorString) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
       this.dupToken = duplicate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
       this.oldToken = old;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
       this.unseqToken = unseq;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
       this.gapToken = gap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
       this.minorStatus = minorStatus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
       this.minorString = minorString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Resets the supplementary status values to false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    private void resetStatusValues() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        dupToken = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        oldToken = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        unseqToken = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        gapToken = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        minorStatus = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        minorString = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
}