/**
* Fetches the CRL bytes from an URL.
* If no url is passed as parameter, the url will be obtained from the certificate.
* If you want to load a CRL from a local file, subclass this method and pass an
* URL with the path to the local file to this method. An other option is to use
* the CrlClientOffline class.
* @see com.itextpdf.text.pdf.security.CrlClient#getEncoded(java.security.cert.X509Certificate, java.lang.String)
*/
public ICollection <byte[]> GetEncoded(X509Certificate checkCert, String url)
{
if (checkCert == null)
{
return(null);
}
if (urls.Count == 0)
{
LOGGER.Info("Looking for CRL for certificate " + checkCert.SubjectDN.ToString());
try {
if (url == null)
{
url = CertificateUtil.GetCRLURL(checkCert);
}
if (url == null)
{
throw new ArgumentNullException();
}
urls.Add(url);
LOGGER.Info("Found CRL url: " + url);
}
catch (Exception e) {
LOGGER.Info("Skipped CRL url: " + e.Message);
}
}
List <byte[]> ar = new List <byte[]>();
foreach (string urlt in urls)
{
try {
LOGGER.Info("Checking CRL: " + urlt);
HttpWebRequest con = (HttpWebRequest)WebRequest.Create(urlt);
HttpWebResponse response = (HttpWebResponse)con.GetResponse();
if (response.StatusCode != HttpStatusCode.OK)
{
throw new IOException(MessageLocalization.GetComposedMessage("invalid.http.response.1", (int)response.StatusCode));
}
//Get Response
Stream inp = response.GetResponseStream();
byte[] buf = new byte[1024];
MemoryStream bout = new MemoryStream();
while (true)
{
int n = inp.Read(buf, 0, buf.Length);
if (n <= 0)
{
break;
}
bout.Write(buf, 0, n);
}
inp.Close();
ar.Add(bout.ToArray());
LOGGER.Info("Added CRL found at: " + urlt);
}
catch (Exception e) {
LOGGER.Info("Skipped CRL: " + e.Message + " for " + urlt);
}
}
return(ar);
}