Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commit HF - Addition of WebProxy #38

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/core/iTextSharp/text/pdf/security/ITSAClient.cs
Expand Up @@ -76,5 +76,11 @@ public interface ITSAClient {
* @throws Exception - TSA request failed
*/
byte[] GetTimeStampToken(byte[] imprint);

/**
* Sets the webproxy needed when working behing proxy.
* @param proxy WebProxy
*/
void SetProxy(System.Net.WebProxy proxy);
}
}
59 changes: 55 additions & 4 deletions src/core/iTextSharp/text/pdf/security/TSAClientBouncyCastle.cs
Expand Up @@ -95,15 +95,25 @@ public class TSAClientBouncyCastle : ITSAClient {

/** TSA request policy */
private string tsaReqPolicy = null;


/** Implements webproxy needed when behind a proxy */
private WebProxy webProxy = null;
/**
* Creates an instance of a TSAClient that will use BouncyCastle.
* @param url String - Time Stamp Authority URL (i.e. "http://tsatest1.digistamp.com/TSA")
*/
public TSAClientBouncyCastle(String url)
: this(url, null, null, DEFAULTTOKENSIZE, DEFAULTHASHALGORITHM) {
}
}

/**
* Creates an instance of a TSAClient that will use BouncyCastle.
* @param url String - Time Stamp Authority URL (i.e. "http://tsatest1.digistamp.com/TSA")
* @param webproxy WebProxy - WebProxy
*/
public TSAClientBouncyCastle(String url, WebProxy webproxy)
: this(url, null, null, DEFAULTTOKENSIZE, DEFAULTHASHALGORITHM, webproxy) { }

/**
* Creates an instance of a TSAClient that will use BouncyCastle.
* @param url String - Time Stamp Authority URL (i.e. "http://tsatest1.digistamp.com/TSA")
Expand All @@ -112,8 +122,19 @@ public TSAClientBouncyCastle(String url)
*/
public TSAClientBouncyCastle(String url, String username, String password)
: this(url, username, password, DEFAULTTOKENSIZE, DEFAULTHASHALGORITHM) {
}

}

/**
* Creates an instance of a TSAClient that will use BouncyCastle.
* @param url String - Time Stamp Authority URL (i.e. "http://tsatest1.digistamp.com/TSA")
* @param username String - user(account) name
* @param password String - password
* @param webproxy WebProxy - WebProxy
*/
public TSAClientBouncyCastle(String url, String username, String password, WebProxy webproxy)
: this(url, username, password, DEFAULTTOKENSIZE, DEFAULTHASHALGORITHM, webproxy) {
}

/**
* Constructor.
* Note the token size estimate is updated by each call, as the token
Expand All @@ -132,6 +153,33 @@ public TSAClientBouncyCastle(String url, String username, String password)
this.digestAlgorithm = digestAlgorithm;
}

/**
* Constructor.
* Note the token size estimate is updated by each call, as the token
* size is not likely to change (as long as we call the same TSA using
* the same imprint length).
* @param url String - Time Stamp Authority URL (i.e. "http://tsatest1.digistamp.com/TSA")
* @param username String - user(account) name
* @param password String - password
* @param tokSzEstimate int - estimated size of received time stamp token (DER encoded)
* @param webproxy WebProxy - WebProxy
*/
public TSAClientBouncyCastle(String url, String username, String password, int tokSzEstimate, String digestAlgorithm, WebProxy webproxy)
{
this.tsaURL = url;
this.tsaUsername = username;
this.tsaPassword = password;
this.tokenSizeEstimate = tokSzEstimate;
this.digestAlgorithm = digestAlgorithm;
this.webProxy = webproxy;
}

/**
* Sets the webproxy needed when working behing proxy.
* @param proxy WebProxy
*/
public void SetProxy(WebProxy proxy) => this.webProxy = proxy;

/**
* @param tsaInfo the tsaInfo to set
*/
Expand Down Expand Up @@ -226,6 +274,9 @@ public TSAClientBouncyCastle(String url, String username, String password)
con.ContentLength = requestBytes.Length;
con.ContentType = "application/timestamp-query";
con.Method = "POST";
//Added support for webproxy
if (this.webProxy != null) con.Proxy = this.webProxy;

if ((tsaUsername != null) && !tsaUsername.Equals("") ) {
string authInfo = tsaUsername + ":" + tsaPassword;
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo), Base64FormattingOptions.None);
Expand Down