Skip to content

Commit

Permalink
Encode correctly OCSP NONCE extension
Browse files Browse the repository at this point in the history
WE2-819

Signed-off-by: Raul Metsma <raul@metsma.ee>
  • Loading branch information
metsma authored and mrts committed Feb 16, 2024
1 parent 4f7f9cf commit 19818d4
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.bouncycastle.cert.ocsp.OCSPReq;
import org.bouncycastle.cert.ocsp.OCSPReqBuilder;

import java.io.IOException;
import java.security.SecureRandom;
import java.util.Objects;

Expand Down Expand Up @@ -82,19 +83,23 @@ public OCSPReq build() throws OCSPException {
builder.addRequest(Objects.requireNonNull(certificateId, "certificateId"));

if (ocspNonceEnabled) {
addNonce(builder);
try {
addNonce(builder);
} catch (IOException e) {
throw new OCSPException("Failed to generate OCSP NONCE extension", e);
}
}

return builder.build();
}

private void addNonce(OCSPReqBuilder builder) {
private void addNonce(OCSPReqBuilder builder) throws IOException {
final byte[] nonce = new byte[32];
GENERATOR.nextBytes(nonce);

final Extension[] extensions = new Extension[]{
new Extension(OCSPObjectIdentifiers.id_pkix_ocsp_nonce, false,
new DEROctetString(nonce))
new DEROctetString(new DEROctetString(nonce)))
};
builder.setRequestExtensions(new Extensions(extensions));
}
Expand Down

0 comments on commit 19818d4

Please sign in to comment.