< prev index next >

src/java.base/share/classes/sun/security/rsa/PSSParameters.java

Print this page

  1 /*
  2  * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any

 86         String mdName = DEFAULT.getDigestAlgorithm();
 87         MGF1ParameterSpec mgfSpec = (MGF1ParameterSpec) DEFAULT.getMGFParameters();
 88         int saltLength = DEFAULT.getSaltLength();
 89         int trailerField = DEFAULT.getTrailerField();
 90 
 91         DerInputStream der = new DerInputStream(encoded);
 92         DerValue[] datum = der.getSequence(4);
 93 
 94         for (DerValue d : datum) {
 95             if (d.isContextSpecific((byte) 0x00)) {
 96                 // hash algid
 97                 mdName = AlgorithmId.parse
 98                     (d.data.getDerValue()).getName();
 99             } else if (d.isContextSpecific((byte) 0x01)) {
100                 // mgf algid
101                 AlgorithmId val = AlgorithmId.parse(d.data.getDerValue());
102                 if (!val.getOID().equals(AlgorithmId.MGF1_oid)) {
103                     throw new IOException("Only MGF1 mgf is supported");
104                 }
105                 AlgorithmId params = AlgorithmId.parse(
106                     new DerValue(val.getEncodedParams()));
107                 String mgfDigestName = params.getName();
108                 switch (mgfDigestName) {
109                 case "SHA-1":
110                     mgfSpec = MGF1ParameterSpec.SHA1;
111                     break;
112                 case "SHA-224":
113                     mgfSpec = MGF1ParameterSpec.SHA224;
114                     break;
115                 case "SHA-256":
116                     mgfSpec = MGF1ParameterSpec.SHA256;
117                     break;
118                 case "SHA-384":
119                     mgfSpec = MGF1ParameterSpec.SHA384;
120                     break;
121                 case "SHA-512":
122                     mgfSpec = MGF1ParameterSpec.SHA512;
123                     break;
124                 case "SHA-512/224":
125                     mgfSpec = MGF1ParameterSpec.SHA512_224;
126                     break;
127                 case "SHA-512/256":
128                     mgfSpec = MGF1ParameterSpec.SHA512_256;
129                     break;












130                 default:
131                     throw new IOException
132                         ("Unrecognized message digest algorithm " +
133                         mgfDigestName);
134                 }
135             } else if (d.isContextSpecific((byte) 0x02)) {
136                 // salt length
137                 saltLength = d.data.getDerValue().getInteger();
138                 if (saltLength < 0) {
139                     throw new IOException("Negative value for saltLength");
140                 }
141             } else if (d.isContextSpecific((byte) 0x03)) {
142                 // trailer field
143                 trailerField = d.data.getDerValue().getInteger();
144                 if (trailerField != 1) {
145                     throw new IOException("Unsupported trailerField value " +
146                     trailerField);
147                 }
148             } else {
149                 throw new IOException("Invalid encoded PSSParameters");

  1 /*
  2  * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any

 86         String mdName = DEFAULT.getDigestAlgorithm();
 87         MGF1ParameterSpec mgfSpec = (MGF1ParameterSpec) DEFAULT.getMGFParameters();
 88         int saltLength = DEFAULT.getSaltLength();
 89         int trailerField = DEFAULT.getTrailerField();
 90 
 91         DerInputStream der = new DerInputStream(encoded);
 92         DerValue[] datum = der.getSequence(4);
 93 
 94         for (DerValue d : datum) {
 95             if (d.isContextSpecific((byte) 0x00)) {
 96                 // hash algid
 97                 mdName = AlgorithmId.parse
 98                     (d.data.getDerValue()).getName();
 99             } else if (d.isContextSpecific((byte) 0x01)) {
100                 // mgf algid
101                 AlgorithmId val = AlgorithmId.parse(d.data.getDerValue());
102                 if (!val.getOID().equals(AlgorithmId.MGF1_oid)) {
103                     throw new IOException("Only MGF1 mgf is supported");
104                 }
105                 AlgorithmId params = AlgorithmId.parse(
106                         new DerValue(val.getEncodedParams()));
107                 String mgfDigestName = params.getName();
108                 switch (mgfDigestName) {
109                 case "SHA-1":
110                     mgfSpec = MGF1ParameterSpec.SHA1;
111                     break;
112                 case "SHA-224":
113                     mgfSpec = MGF1ParameterSpec.SHA224;
114                     break;
115                 case "SHA-256":
116                     mgfSpec = MGF1ParameterSpec.SHA256;
117                     break;
118                 case "SHA-384":
119                     mgfSpec = MGF1ParameterSpec.SHA384;
120                     break;
121                 case "SHA-512":
122                     mgfSpec = MGF1ParameterSpec.SHA512;
123                     break;
124                 case "SHA-512/224":
125                     mgfSpec = MGF1ParameterSpec.SHA512_224;
126                     break;
127                 case "SHA-512/256":
128                     mgfSpec = MGF1ParameterSpec.SHA512_256;
129                     break;
130                 case "SHA3-224":
131                     mgfSpec = MGF1ParameterSpec.SHA3_224;
132                     break;
133                 case "SHA3-256":
134                     mgfSpec = MGF1ParameterSpec.SHA3_256;
135                     break;
136                 case "SHA3-384":
137                     mgfSpec = MGF1ParameterSpec.SHA3_384;
138                     break;
139                 case "SHA3-512":
140                     mgfSpec = MGF1ParameterSpec.SHA3_512;
141                     break;
142                 default:
143                     throw new IOException
144                         ("Unrecognized message digest algorithm " +
145                         mgfDigestName);
146                 }
147             } else if (d.isContextSpecific((byte) 0x02)) {
148                 // salt length
149                 saltLength = d.data.getDerValue().getInteger();
150                 if (saltLength < 0) {
151                     throw new IOException("Negative value for saltLength");
152                 }
153             } else if (d.isContextSpecific((byte) 0x03)) {
154                 // trailer field
155                 trailerField = d.data.getDerValue().getInteger();
156                 if (trailerField != 1) {
157                     throw new IOException("Unsupported trailerField value " +
158                     trailerField);
159                 }
160             } else {
161                 throw new IOException("Invalid encoded PSSParameters");
< prev index next >