View Javadoc
1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied. See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.wss4j.common.derivedKey;
21  
22  import javax.xml.namespace.QName;
23  
24  import org.apache.wss4j.common.ext.WSSecurityException;
25  
26  /**
27   * Class ConversationConstants
28   */
29  public final class ConversationConstants {
30  
31      public static final int VERSION_05_02 = 1;
32  
33      public static final int VERSION_05_12 = 2;
34  
35      public static final int DEFAULT_VERSION = VERSION_05_12;
36  
37      /**
38       * WS-SecConv Feb 2005 version
39       */
40      public static final String WSC_NS_05_02 = "http://schemas.xmlsoap.org/ws/2005/02/sc";
41  
42      /**
43       * WS-Sx version
44       */
45      public static final String WSC_NS_05_12 =
46          "http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512";
47  
48      /**
49       * Token type of DerivedKeyToken
50       */
51      public static final String TOKEN_TYPE_DERIVED_KEY_TOKEN = "/dk";
52  
53      /**
54       * Token type of SecurityContextToken
55       */
56      public static final String TOKEN_TYPE_SECURITY_CONTEXT_TOKEN = "/sct";
57  
58      /**
59       * Field WSC_PREFIX
60       */
61      public static final String WSC_PREFIX = "wsc";
62  
63      /**
64       * Field SECURITY_CONTEXT_TOKEN_LN
65       */
66      public static final String SECURITY_CONTEXT_TOKEN_LN =
67              "SecurityContextToken";
68  
69      /**
70       * Field IDENTIFIER_LN
71       */
72      public static final String IDENTIFIER_LN = "Identifier";
73  
74      /**
75       * Field INSTANCE_LN
76       */
77      public static final String INSTANCE_LN = "Instance";
78  
79      /**
80       * Field EXPIRES_LN
81       */
82      public static final String EXPIRES_LN = "Expires";
83  
84      /**
85       * Field KEYS_LN
86       */
87      public static final String KEYS_LN = "Keys";
88  
89      /**
90       * Field SECURITY_TOKEN_REFERENCE_LN
91       */
92      public static final String SECURITY_TOKEN_REFERENCE_LN =
93              "SecurityTokenReference";
94  
95      /**
96       * Field DERIVED_KEY_TOKEN_LN
97       */
98      public static final String DERIVED_KEY_TOKEN_LN = "DerivedKeyToken";
99  
100     /**
101      * Field PROPERTIES_LN
102      */
103     public static final String PROPERTIES_LN = "Properties";
104 
105     /**
106      * Field LENGTH_LN
107      */
108     public static final String LENGTH_LN = "Length";
109 
110     /**
111      * Field GENERATION_LN
112      */
113     public static final String GENERATION_LN = "Generation";
114 
115     /**
116      * Field OFFSET_LN
117      */
118     public static final String OFFSET_LN = "Offset";
119 
120     /**
121      * Field LABEL_LN
122      */
123     public static final String LABEL_LN = "Label";
124 
125     /**
126      * Field NONCE_LN
127      */
128     public static final String NONCE_LN = "Nonce";
129 
130     public static final int DIRECT_GENERATED = 1;
131     public static final int STS_GENERATED = 2;
132     public static final int STSREQUEST_TOKEN = 3;
133     public static final int INTEROP_SCENE1 = 4;
134 
135     public static final String IDENTIFIER = "SCT_Identifier";
136 
137     public static final int DK_SIGN = 1;
138     public static final int DK_ENCRYPT = 2;
139 
140     public static final String DEFAULT_LABEL = "WS-SecureConversation";
141 
142     public static final QName SECURITY_CTX_TOKEN_QNAME_05_02 =
143         new QName(
144             ConversationConstants.WSC_NS_05_02,
145             ConversationConstants.SECURITY_CONTEXT_TOKEN_LN
146         );
147 
148     public static final QName SECURITY_CTX_TOKEN_QNAME_05_12 =
149         new QName(
150             ConversationConstants.WSC_NS_05_12,
151             ConversationConstants.SECURITY_CONTEXT_TOKEN_LN
152         );
153 
154     public static final QName DERIVED_KEY_TOKEN_QNAME_05_02 =
155         new QName(
156             ConversationConstants.WSC_NS_05_02,
157             ConversationConstants.DERIVED_KEY_TOKEN_LN
158         );
159 
160     public static final QName DERIVED_KEY_TOKEN_QNAME_05_12 =
161         new QName(
162             ConversationConstants.WSC_NS_05_12,
163             ConversationConstants.DERIVED_KEY_TOKEN_LN
164         );
165 
166     /**
167      * Key to hold the map of security context identifiers against the
168      * service epr addresses (service scope) or wsa:Action values (operation
169      * scope).
170      */
171     public static final String KEY_CONTEXT_MAP = "contextMap";
172 
173     private ConversationConstants() {
174         // Complete
175     }
176 
177     public interface DerivationAlgorithm {
178         String P_SHA_1 =
179             "http://schemas.xmlsoap.org/ws/2005/02/sc/dk/p_sha1";
180 
181         String P_SHA_1_2005_12 =
182             "http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512/dk/p_sha1";
183 
184         byte[] createKey(byte[] secret, byte[] seed, int offset, long length)
185             throws WSSecurityException;
186     }
187 
188     public static String getWSCNs(int version) {
189         if (VERSION_05_02 == version) {
190             return WSC_NS_05_02;
191         } else {
192             return WSC_NS_05_12;
193         }
194     }
195 
196     public static int getWSTVersion(String ns) {
197         if (WSC_NS_05_02.equals(ns)) {
198             return VERSION_05_02;
199         } else {
200             return VERSION_05_12;
201         }
202     }
203 }