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      private Set<String> keyAgreementAlgorithms = Collections.emptySet();
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 addKeyAgreementMethodAlgorithm(String keyAgreementAlgorithm) {
120         if (keyAgreementAlgorithms.isEmpty()) {
121             keyAgreementAlgorithms = new HashSet<>();
122         }
123         keyAgreementAlgorithms.add(keyAgreementAlgorithm);
124     }
125 
126     public Set<String> getKeyAgreementMethodAlgorithms() {
127         return keyAgreementAlgorithms;
128     }
129 
130     public void addDerivedKeyAlgorithm(String derivedKeyAlgorithm) {
131         if (derivedKeyAlgorithms.isEmpty()) {
132             derivedKeyAlgorithms = new HashSet<>();
133         }
134         derivedKeyAlgorithms.add(derivedKeyAlgorithm);
135     }
136 
137     public Set<String> getDerivedKeyAlgorithms() {
138         return derivedKeyAlgorithms;
139     }
140 
141     public int getMaximumSymmetricKeyLength() {
142         return maximumSymmetricKeyLength;
143     }
144 
145     public void setMaximumSymmetricKeyLength(int maximumSymmetricKeyLength) {
146         this.maximumSymmetricKeyLength = maximumSymmetricKeyLength;
147     }
148 
149     public int getMinimumAsymmetricKeyLength() {
150         return minimumAsymmetricKeyLength;
151     }
152 
153     public void setMinimumAsymmetricKeyLength(int minimumAsymmetricKeyLength) {
154         this.minimumAsymmetricKeyLength = minimumAsymmetricKeyLength;
155     }
156 
157     public int getMaximumAsymmetricKeyLength() {
158         return maximumAsymmetricKeyLength;
159     }
160 
161     public void setMaximumAsymmetricKeyLength(int maximumAsymmetricKeyLength) {
162         this.maximumAsymmetricKeyLength = maximumAsymmetricKeyLength;
163     }
164 
165     public int getEncryptionDerivedKeyLength() {
166         return encryptionDerivedKeyLength;
167     }
168 
169     public void setEncryptionDerivedKeyLength(int encryptionDerivedKeyLength) {
170         this.encryptionDerivedKeyLength = encryptionDerivedKeyLength;
171     }
172 
173     public int getSignatureDerivedKeyLength() {
174         return signatureDerivedKeyLength;
175     }
176 
177     public void setSignatureDerivedKeyLength(int signatureDerivedKeyLength) {
178         this.signatureDerivedKeyLength = signatureDerivedKeyLength;
179     }
180 
181     public int getMinimumSymmetricKeyLength() {
182         return minimumSymmetricKeyLength;
183     }
184 
185     public void setMinimumSymmetricKeyLength(int minimumSymmetricKeyLength) {
186         this.minimumSymmetricKeyLength = minimumSymmetricKeyLength;
187     }
188 
189     public int getMaximumEllipticCurveKeyLength() {
190         return maximumEllipticCurveKeyLength;
191     }
192 
193     public void setMaximumEllipticCurveKeyLength(int maximumEllipticCurveKeyLength) {
194         this.maximumEllipticCurveKeyLength = maximumEllipticCurveKeyLength;
195     }
196 
197     public int getMinimumEllipticCurveKeyLength() {
198         return minimumEllipticCurveKeyLength;
199     }
200 
201     public void setMinimumEllipticCurveKeyLength(int minimumEllipticCurveKeyLength) {
202         this.minimumEllipticCurveKeyLength = minimumEllipticCurveKeyLength;
203     }
204 
205 }