|
20 | 20 | * SOFTWARE. |
21 | 21 | */ |
22 | 22 |
|
23 | | -/* |
24 | | - * Copyright 2017 The Netty Project |
25 | | - * Copyright 2020 The Web eID project |
26 | | - * |
27 | | - * The Netty Project and The Web eID Project license this file to you under the |
28 | | - * Apache License, version 2.0 (the "License"); you may not use this file except |
29 | | - * in compliance with the License. You may obtain a copy of the License at: |
30 | | - * |
31 | | - * http://www.apache.org/licenses/LICENSE-2.0 |
32 | | - * |
33 | | - * Unless required by applicable law or agreed to in writing, software |
34 | | - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
35 | | - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
36 | | - * License for the specific language governing permissions and limitations under |
37 | | - * the License. |
38 | | - */ |
39 | | - |
40 | 23 | package eu.webeid.security.validator.ocsp; |
41 | 24 |
|
42 | | -import org.bouncycastle.asn1.ASN1ObjectIdentifier; |
| 25 | +import org.bouncycastle.asn1.nist.NISTObjectIdentifiers; |
43 | 26 | import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers; |
44 | 27 | import org.bouncycastle.asn1.x509.AlgorithmIdentifier; |
45 | 28 | import org.bouncycastle.crypto.Digest; |
|
52 | 35 |
|
53 | 36 | /** |
54 | 37 | * BouncyCastle's OCSPReqBuilder needs a DigestCalculator but BC doesn't |
55 | | - * provide any public implementations of that interface. That's why we need to |
56 | | - * write our own. There's a default SHA-1 implementation and one for SHA-256. |
57 | | - * Which one to use will depend on the Certificate Authority (CA). |
| 38 | + * provide any public implementations of it, hence this implementation. |
58 | 39 | */ |
59 | | -public final class Digester implements DigestCalculator { |
| 40 | +public final class DigestCalculatorImpl implements DigestCalculator { |
| 41 | + |
| 42 | + private static final AlgorithmIdentifier SHA1 = new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1); |
| 43 | + private static final AlgorithmIdentifier SHA256 = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha256); |
60 | 44 |
|
61 | 45 | private final DigestOutputStream dos; |
62 | 46 | private final AlgorithmIdentifier algId; |
63 | 47 |
|
64 | | - public static DigestCalculator sha1() { |
65 | | - final Digest digest = new SHA1Digest(); |
66 | | - final AlgorithmIdentifier algId = new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1); |
67 | 48 |
|
68 | | - return new Digester(digest, algId); |
| 49 | + public static DigestCalculator sha1() { |
| 50 | + return new DigestCalculatorImpl(new SHA1Digest(), SHA1); |
69 | 51 | } |
70 | 52 |
|
71 | 53 | public static DigestCalculator sha256() { |
72 | | - Digest digest = new SHA256Digest(); |
73 | | - |
74 | | - // The OID for SHA-256: http://www.oid-info.com/get/2.16.840.1.101.3.4.2.1 |
75 | | - final ASN1ObjectIdentifier oid = new ASN1ObjectIdentifier("2.16.840.1.101.3.4.2.1").intern(); |
76 | | - final AlgorithmIdentifier algId = new AlgorithmIdentifier(oid); |
77 | | - |
78 | | - return new Digester(digest, algId); |
| 54 | + return new DigestCalculatorImpl(new SHA256Digest(), SHA256); |
79 | 55 | } |
80 | 56 |
|
81 | | - private Digester(Digest digest, AlgorithmIdentifier algId) { |
| 57 | + private DigestCalculatorImpl(Digest digest, AlgorithmIdentifier algId) { |
82 | 58 | this.dos = new DigestOutputStream(digest); |
83 | 59 | this.algId = algId; |
84 | 60 | } |
|
0 commit comments