@@ -321,12 +321,13 @@ public String toString() {
321321 * @return the hexdump of the byte array
322322 */
323323 private static String dumpHexBytes (byte [] data ) {
324- return dumpHexBytes (data , 16 , "\n " , " " );
324+ return dumpHexBytes (data , data . length , 16 , "\n " , " " );
325325 }
326326
327327 /**
328328 *
329- * @param data the array of bytes to dump to stdout.
329+ * @param data the array of bytes to dump to stdout
330+ * @param dataLen the length of the data to be displayed
330331 * @param itemsPerLine the number of bytes to display per line
331332 * if the {@code lineDelim} character is blank then all bytes will be
332333 * printed on a single line.
@@ -335,11 +336,11 @@ private static String dumpHexBytes(byte[] data) {
335336 *
336337 * @return The hexdump of the byte array
337338 */
338- private static String dumpHexBytes (byte [] data , int itemsPerLine ,
339- String lineDelim , String itemDelim ) {
339+ private static String dumpHexBytes (byte [] data , int dataLen ,
340+ int itemsPerLine , String lineDelim , String itemDelim ) {
340341 StringBuilder sb = new StringBuilder ();
341342 if (data != null ) {
342- for (int i = 0 ; i < data . length ; i ++) {
343+ for (int i = 0 ; i < dataLen ; i ++) {
343344 if (i % itemsPerLine == 0 && i != 0 ) {
344345 sb .append (lineDelim );
345346 }
@@ -489,6 +490,7 @@ public void setSignatureAlgorithm(String algName)
489490 throws NoSuchAlgorithmException {
490491 if (!started ) {
491492 sigAlgId = AlgorithmId .get (algName );
493+ log ("Signature algorithm set to " + sigAlgId .getName ());
492494 }
493495 }
494496
@@ -552,6 +554,8 @@ public void setDelay(long delayMillis) {
552554 public void setDisableContentLength (boolean isDisabled ) {
553555 if (!started ) {
554556 omitContentLength = isDisabled ;
557+ log ("Response Content-Length field " +
558+ (isDisabled ? "disabled" : "enabled" ));
555559 }
556560 }
557561
@@ -726,6 +730,10 @@ public void run() {
726730 OutputStream out = ocspSocket .getOutputStream ()) {
727731 peerSockAddr =
728732 (InetSocketAddress )ocspSocket .getRemoteSocketAddress ();
733+
734+ // Read in the first line which will be the request line.
735+ // This will be tokenized so we know if we are dealing with
736+ // a GET or POST.
729737 String [] headerTokens = readLine (in ).split (" " );
730738 LocalOcspRequest ocspReq = null ;
731739 LocalOcspResponse ocspResp = null ;
@@ -734,12 +742,12 @@ public void run() {
734742 if (headerTokens [0 ] != null ) {
735743 log ("Received incoming HTTP " + headerTokens [0 ] +
736744 " from " + peerSockAddr );
737- switch (headerTokens [0 ]) {
745+ switch (headerTokens [0 ]. toUpperCase () ) {
738746 case "POST" :
739747 ocspReq = parseHttpOcspPost (in );
740748 break ;
741749 case "GET" :
742- ocspReq = parseHttpOcspGet (headerTokens );
750+ ocspReq = parseHttpOcspGet (headerTokens , in );
743751 break ;
744752 default :
745753 respStat = ResponseStatus .MALFORMED_REQUEST ;
@@ -773,6 +781,9 @@ public void run() {
773781 ocspResp = new LocalOcspResponse (respStat );
774782 }
775783 sendResponse (out , ocspResp );
784+ out .flush ();
785+
786+ log ("Closing " + ocspSocket );
776787 } catch (IOException | CertificateException exc ) {
777788 err (exc );
778789 }
@@ -870,6 +881,8 @@ private LocalOcspRequest parseHttpOcspPost(InputStream inStream)
870881 *
871882 * @param headerTokens the individual String tokens from the first
872883 * line of the HTTP GET.
884+ * @param inStream the input stream from the socket bound to this
885+ * {@code OcspHandler}.
873886 *
874887 * @return the OCSP Request as a {@code LocalOcspRequest}
875888 *
@@ -878,8 +891,26 @@ private LocalOcspRequest parseHttpOcspPost(InputStream inStream)
878891 * @throws CertificateException if one or more of the certificates in
879892 * the OCSP request cannot be read/parsed.
880893 */
881- private LocalOcspRequest parseHttpOcspGet (String [] headerTokens )
882- throws IOException , CertificateException {
894+ private LocalOcspRequest parseHttpOcspGet (String [] headerTokens ,
895+ InputStream inStream ) throws IOException , CertificateException {
896+ // Before we process the remainder of the GET URL, we should drain
897+ // the InputStream of any other header data. We (for now) won't
898+ // use it, but will display the contents if logging is enabled.
899+ boolean endOfHeader = false ;
900+ while (!endOfHeader ) {
901+ String [] lineTokens = readLine (inStream ).split (":" , 2 );
902+ // We expect to see a type and value pair delimited by a colon.
903+ if (lineTokens [0 ].isEmpty ()) {
904+ endOfHeader = true ;
905+ } else if (lineTokens .length == 2 ) {
906+ log (String .format ("ReqHdr: %s: %s" , lineTokens [0 ].trim (),
907+ lineTokens [1 ].trim ()));
908+ } else {
909+ // A colon wasn't found and token 0 should be the whole line
910+ log ("ReqHdr: " + lineTokens [0 ].trim ());
911+ }
912+ }
913+
883914 // We have already established headerTokens[0] to be "GET".
884915 // We should have the URL-encoded base64 representation of the
885916 // OCSP request in headerTokens[1]. We need to strip any leading
@@ -1200,10 +1231,14 @@ public String toString() {
12001231 sb .append ("CertId, Algorithm = " );
12011232 sb .append (cid .getHashAlgorithm ()).append ("\n " );
12021233 sb .append ("\t Issuer Name Hash: " );
1203- sb .append (dumpHexBytes (cid .getIssuerNameHash (), 256 , "" , "" ));
1234+ byte [] cidHashBuf = cid .getIssuerNameHash ();
1235+ sb .append (dumpHexBytes (cidHashBuf , cidHashBuf .length ,
1236+ 256 , "" , "" ));
12041237 sb .append ("\n " );
12051238 sb .append ("\t Issuer Key Hash: " );
1206- sb .append (dumpHexBytes (cid .getIssuerKeyHash (), 256 , "" , "" ));
1239+ cidHashBuf = cid .getIssuerKeyHash ();
1240+ sb .append (dumpHexBytes (cidHashBuf , cidHashBuf .length ,
1241+ 256 , "" , "" ));
12071242 sb .append ("\n " );
12081243 sb .append ("\t Serial Number: " ).append (cid .getSerialNumber ());
12091244 if (!extensions .isEmpty ()) {
@@ -1543,10 +1578,14 @@ public String toString() {
15431578 sb .append ("CertId, Algorithm = " );
15441579 sb .append (certId .getHashAlgorithm ()).append ("\n " );
15451580 sb .append ("\t Issuer Name Hash: " );
1546- sb .append (dumpHexBytes (certId .getIssuerNameHash (), 256 , "" , "" ));
1581+ byte [] cidHashBuf = certId .getIssuerNameHash ();
1582+ sb .append (dumpHexBytes (cidHashBuf , cidHashBuf .length ,
1583+ 256 , "" , "" ));
15471584 sb .append ("\n " );
15481585 sb .append ("\t Issuer Key Hash: " );
1549- sb .append (dumpHexBytes (certId .getIssuerKeyHash (), 256 , "" , "" ));
1586+ cidHashBuf = certId .getIssuerKeyHash ();
1587+ sb .append (dumpHexBytes (cidHashBuf , cidHashBuf .length ,
1588+ 256 , "" , "" ));
15501589 sb .append ("\n " );
15511590 sb .append ("\t Serial Number: " ).append (certId .getSerialNumber ());
15521591 sb .append ("\n " );
0 commit comments