OcspUtils Class — netty Architecture
Architecture documentation for the OcspUtils class in OcspUtils.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 08ffedd7_4191_0abc_ea5f_a0e3ce4ff56b["OcspUtils"] d42f2788_1a61_5db4_2186_97123511c211["OcspUtils.java"] 08ffedd7_4191_0abc_ea5f_a0e3ce4ff56b -->|defined in| d42f2788_1a61_5db4_2186_97123511c211 1fa30da5_7db1_7059_bc32_dbe98673febe["OcspUtils()"] 08ffedd7_4191_0abc_ea5f_a0e3ce4ff56b -->|method| 1fa30da5_7db1_7059_bc32_dbe98673febe cfe00cbf_c65a_202f_ab58_0578a3b22402["URI()"] 08ffedd7_4191_0abc_ea5f_a0e3ce4ff56b -->|method| cfe00cbf_c65a_202f_ab58_0578a3b22402 1e1eef3c_1de2_1f16_c238_756ece8cb056["T()"] 08ffedd7_4191_0abc_ea5f_a0e3ce4ff56b -->|method| 1e1eef3c_1de2_1f16_c238_756ece8cb056 d3c5c4ee_1073_0c54_cefb_39c0c8493c5d["OCSPResp()"] 08ffedd7_4191_0abc_ea5f_a0e3ce4ff56b -->|method| d3c5c4ee_1073_0c54_cefb_39c0c8493c5d
Relationship Graph
Source Code
example/src/main/java/io/netty/example/ocsp/OcspUtils.java lines 44–172
public final class OcspUtils {
/**
* The OID for OCSP responder URLs.
*
* https://www.alvestrand.no/objectid/1.3.6.1.5.5.7.48.1.html
*/
private static final ASN1ObjectIdentifier OCSP_RESPONDER_OID
= new ASN1ObjectIdentifier("1.3.6.1.5.5.7.48.1").intern();
private static final String OCSP_REQUEST_TYPE = "application/ocsp-request";
private static final String OCSP_RESPONSE_TYPE = "application/ocsp-response";
private OcspUtils() {
}
/**
* Returns the OCSP responder {@link URI} or {@code null} if it doesn't have one.
*/
public static URI ocspUri(X509Certificate certificate) throws IOException {
byte[] value = certificate.getExtensionValue(Extension.authorityInfoAccess.getId());
if (value == null) {
return null;
}
ASN1Primitive authorityInfoAccess = X509ExtensionUtil.fromExtensionValue(value);
if (!(authorityInfoAccess instanceof DLSequence)) {
return null;
}
DLSequence aiaSequence = (DLSequence) authorityInfoAccess;
DLTaggedObject taggedObject = findObject(aiaSequence, OCSP_RESPONDER_OID, DLTaggedObject.class);
if (taggedObject == null) {
return null;
}
if (taggedObject.getTagNo() != BERTags.OBJECT_IDENTIFIER) {
return null;
}
byte[] encoded = taggedObject.getEncoded();
int length = encoded[1] & 0xFF;
String uri = new String(encoded, 2, length, CharsetUtil.UTF_8);
return URI.create(uri);
}
private static <T> T findObject(DLSequence sequence, ASN1ObjectIdentifier oid, Class<T> type) {
for (ASN1Encodable element : sequence) {
if (!(element instanceof DLSequence)) {
continue;
}
DLSequence subSequence = (DLSequence) element;
if (subSequence.size() != 2) {
continue;
}
ASN1Encodable key = subSequence.getObjectAt(0);
ASN1Encodable value = subSequence.getObjectAt(1);
if (key.equals(oid) && type.isInstance(value)) {
return type.cast(value);
}
}
return null;
}
/**
* TODO: This is a very crude and non-scalable HTTP client to fetch the OCSP response from the
* CA's OCSP responder server. It's meant to demonstrate the basic building blocks on how to
* interact with the responder server and you should consider using Netty's HTTP client instead.
*/
public static OCSPResp request(URI uri, OCSPReq request, long timeout, TimeUnit unit) throws IOException {
byte[] encoded = request.getEncoded();
URL url = uri.toURL();
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
try {
connection.setConnectTimeout((int) unit.toMillis(timeout));
connection.setReadTimeout((int) unit.toMillis(timeout));
Source
Frequently Asked Questions
What is the OcspUtils class?
OcspUtils is a class in the netty codebase, defined in example/src/main/java/io/netty/example/ocsp/OcspUtils.java.
Where is OcspUtils defined?
OcspUtils is defined in example/src/main/java/io/netty/example/ocsp/OcspUtils.java at line 44.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free