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.crypto;
21  
22  import java.util.HashSet;
23  import java.util.Collections;
24  import java.util.Set;
25  
26  /**
27   * This class holds the permitted values for encryption/signature/etc. algorithms on the
28   * inbound side. If the corresponding value is not null then the received algorithm must
29   * match the appropriate algorithm stored in this class.
30   */
31  public class AlgorithmSuite {
32  
33      private Set<String> signatureMethods = Collections.emptySet();
34      private Set<String> c14nAlgorithms = Collections.emptySet();
35      private Set<String> digestAlgorithms = Collections.emptySet();
36      private Set<String> transformAlgorithms = Collections.emptySet();
37  
38      private Set<String> encryptionMethods = Collections.emptySet();
39      private Set<String> keyWrapAlgorithms = Collections.emptySet();
40  
41      private Set<String> derivedKeyAlgorithms = Collections.emptySet();
42  
43      private int maximumSymmetricKeyLength = 256;
44      private int minimumSymmetricKeyLength = 128;
45      private int maximumAsymmetricKeyLength = 4096;
46      private int minimumAsymmetricKeyLength = 1024;
47      private int maximumEllipticCurveKeyLength = 512;
48      private int minimumEllipticCurveKeyLength = 160;
49  
50      private int signatureDerivedKeyLength;
51      private int encryptionDerivedKeyLength;
52  
53      public void addSignatureMethod(String signatureMethod) {
54          if (signatureMethods.isEmpty()) {
55              signatureMethods = new HashSet<>();
56          }
57          signatureMethods.add(signatureMethod);
58      }
59  
60      public Set<String> getSignatureMethods() {
61          return signatureMethods;
62      }
63  
64      public void addC14nAlgorithm(String c14nAlgorithm) {
65          if (c14nAlgorithms.isEmpty()) {
66              c14nAlgorithms = new HashSet<>();
67          }
68          c14nAlgorithms.add(c14nAlgorithm);
69      }
70  
71      public Set<String> getC14nAlgorithms() {
72          return c14nAlgorithms;
73      }
74  
75      public void addDigestAlgorithm(String digestAlgorithm) {
76          if (digestAlgorithms.isEmpty()) {
77              digestAlgorithms = new HashSet<>();
78          }
79          digestAlgorithms.add(digestAlgorithm);
80      }
81  
82      public Set<String> getDigestAlgorithms() {
83          return digestAlgorithms;
84      }
85  
86      public void addTransformAlgorithm(String transformAlgorithm) {
87          if (transformAlgorithms.isEmpty()) {
88              transformAlgorithms = new HashSet<>();
89          }
90          transformAlgorithms.add(transformAlgorithm);
91      }
92  
93      public Set<String> getTransformAlgorithms() {
94          return transformAlgorithms;
95      }
96  
97      public void addEncryptionMethod(String encryptionMethod) {
98          if (encryptionMethods.isEmpty()) {
99              encryptionMethods = new HashSet<>();
100         }
101         encryptionMethods.add(encryptionMethod);
102     }
103 
104     public Set<String> getEncryptionMethods() {
105         return encryptionMethods;
106     }
107 
108     public void addKeyWrapAlgorithm(String keyWrapAlgorithm) {
109         if (keyWrapAlgorithms.isEmpty()) {
110             keyWrapAlgorithms = new HashSet<>();
111         }
112         keyWrapAlgorithms.add(keyWrapAlgorithm);
113     }
114 
115     public Set<String> getKeyWrapAlgorithms() {
116         return keyWrapAlgorithms;
117     }
118 
119     public void addDerivedKeyAlgorithm(String derivedKeyAlgorithm) {
120         if (derivedKeyAlgorithms.isEmpty()) {
121             derivedKeyAlgorithms = new HashSet<>();
122         }
123         derivedKeyAlgorithms.add(derivedKeyAlgorithm);
124     }
125 
126     public Set<String> getDerivedKeyAlgorithms() {
127         return derivedKeyAlgorithms;
128     }
129 
130     public int getMaximumSymmetricKeyLength() {
131         return maximumSymmetricKeyLength;
132     }
133 
134     public void setMaximumSymmetricKeyLength(int maximumSymmetricKeyLength) {
135         this.maximumSymmetricKeyLength = maximumSymmetricKeyLength;
136     }
137 
138     public int getMinimumAsymmetricKeyLength() {
139         return minimumAsymmetricKeyLength;
140     }
141 
142     public void setMinimumAsymmetricKeyLength(int minimumAsymmetricKeyLength) {
143         this.minimumAsymmetricKeyLength = minimumAsymmetricKeyLength;
144     }
145 
146     public int getMaximumAsymmetricKeyLength() {
147         return maximumAsymmetricKeyLength;
148     }
149 
150     public void setMaximumAsymmetricKeyLength(int maximumAsymmetricKeyLength) {
151         this.maximumAsymmetricKeyLength = maximumAsymmetricKeyLength;
152     }
153 
154     public int getEncryptionDerivedKeyLength() {
155         return encryptionDerivedKeyLength;
156     }
157 
158     public void setEncryptionDerivedKeyLength(int encryptionDerivedKeyLength) {
159         this.encryptionDerivedKeyLength = encryptionDerivedKeyLength;
160     }
161 
162     public int getSignatureDerivedKeyLength() {
163         return signatureDerivedKeyLength;
164     }
165 
166     public void setSignatureDerivedKeyLength(int signatureDerivedKeyLength) {
167         this.signatureDerivedKeyLength = signatureDerivedKeyLength;
168     }
169 
170     public int getMinimumSymmetricKeyLength() {
171         return minimumSymmetricKeyLength;
172     }
173 
174     public void setMinimumSymmetricKeyLength(int minimumSymmetricKeyLength) {
175         this.minimumSymmetricKeyLength = minimumSymmetricKeyLength;
176     }
177 
178     public int getMaximumEllipticCurveKeyLength() {
179         return maximumEllipticCurveKeyLength;
180     }
181 
182     public void setMaximumEllipticCurveKeyLength(int maximumEllipticCurveKeyLength) {
183         this.maximumEllipticCurveKeyLength = maximumEllipticCurveKeyLength;
184     }
185 
186     public int getMinimumEllipticCurveKeyLength() {
187         return minimumEllipticCurveKeyLength;
188     }
189 
190     public void setMinimumEllipticCurveKeyLength(int minimumEllipticCurveKeyLength) {
191         this.minimumEllipticCurveKeyLength = minimumEllipticCurveKeyLength;
192     }
193 
194 }