Skip to content

Commit

Permalink
Merge pull request #66 from CyberSource/custom-password-fix
Browse files Browse the repository at this point in the history
Added fix to account for custom password for the p12 file
  • Loading branch information
gnongsie authored Apr 4, 2024
2 parents 6fc8499 + 34d1b63 commit af287b0
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CyberSource.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>CyberSource</id>
<version>1.4.0</version>
<version>1.4.5</version>
<title>CyberSource Corporation</title>
<authors>CyberSource Corporation</authors>
<owners>CyberSource Corporation</owners>
Expand Down
4 changes: 2 additions & 2 deletions CyberSource/Base/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.4.4")]
[assembly: AssemblyFileVersion("1.4.4")]
[assembly: AssemblyVersion("1.4.5")]
[assembly: AssemblyFileVersion("1.4.5")]
15 changes: 12 additions & 3 deletions CyberSource/Client/CustomTextMessageEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,16 @@ public override Message ReadMessage(Stream stream, int maxSizeOfHeaders, string
{
var sr = new StreamReader(stream);
var wireResponse = sr.ReadToEnd();
sr.Close();

// Fix for Xml external entity injection violation in fortify report
XmlReaderSettings settings = new XmlReaderSettings();
settings.DtdProcessing = DtdProcessing.Prohibit;
settings.XmlResolver = null;

XmlDocument doc = new XmlDocument();
XmlReader reader = XmlReader.Create(new StringReader(wireResponse), settings);
StringReader stringReader = new StringReader(wireResponse);
XmlReader reader = XmlReader.Create(stringReader, settings);
doc.Load(reader);
//We need to get rid of the security header because it is not signed by the web service.
//The whole reason for the custom Encoder is to do this. the client rejected the unsigned header.
Expand All @@ -79,8 +81,15 @@ public override Message ReadMessage(Stream stream, int maxSizeOfHeaders, string
{
n.DeleteSelf();
}
reader = XmlReader.Create(new StringReader(doc.InnerXml), settings);
return Message.CreateMessage(reader, maxSizeOfHeaders, MessageVersion.Soap11);
StringReader stringReaderInnerXml = new StringReader(doc.InnerXml);
reader = XmlReader.Create(stringReaderInnerXml, settings);
Message returnMessage = Message.CreateMessage(reader, maxSizeOfHeaders, MessageVersion.Soap11);

stringReader.Close();
stringReaderInnerXml.Close();
reader.Close();

return returnMessage;
}

public override ArraySegment<byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)
Expand Down
4 changes: 3 additions & 1 deletion CyberSource/Client/NVPClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static Hashtable RunTransaction(

//Setup endpoint Address with dns identity
AddressHeaderCollection headers = new AddressHeaderCollection();
EndpointAddress endpointAddress = new EndpointAddress(new Uri(config.EffectiveServerURL), EndpointIdentity.CreateDnsIdentity(config.EffectivePassword), headers);
EndpointAddress endpointAddress = new EndpointAddress(new Uri(config.EffectiveServerURL), EndpointIdentity.CreateDnsIdentity(config.MerchantID), headers);

//Get instance of service
using (proc = new NVPTransactionProcessorClient(currentBinding, endpointAddress))
Expand Down Expand Up @@ -272,6 +272,8 @@ private static Hashtable String2Hash(string src)
}
}

reader.Close();

return (dest);
}

Expand Down
4 changes: 2 additions & 2 deletions CyberSource/Client/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.4.4")]
[assembly: AssemblyFileVersion("1.4.4")]
[assembly: AssemblyVersion("1.4.5")]
[assembly: AssemblyFileVersion("1.4.5")]
2 changes: 1 addition & 1 deletion CyberSource/Client/SoapClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static ReplyMessage RunTransaction(

//Setup endpoint Address with dns identity
AddressHeaderCollection headers = new AddressHeaderCollection();
EndpointAddress endpointAddress = new EndpointAddress(new Uri(config.EffectiveServerURL), EndpointIdentity.CreateDnsIdentity(config.EffectivePassword), headers);
EndpointAddress endpointAddress = new EndpointAddress(new Uri(config.EffectiveServerURL), EndpointIdentity.CreateDnsIdentity(config.MerchantID), headers);

//Get instance of service
using (proc = new TransactionProcessorClient(currentBinding, endpointAddress))
Expand Down
18 changes: 14 additions & 4 deletions CyberSource/Client/XmlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ static XmlClient()
XmlReaderSettings settings = new XmlReaderSettings();
settings.DtdProcessing = DtdProcessing.Prohibit;
settings.XmlResolver = null;
XmlReader reader = XmlReader.Create(new StringReader(SOAP_ENVELOPE), settings);
StringReader stringReader = new StringReader(SOAP_ENVELOPE);
XmlReader reader = XmlReader.Create(stringReader, settings);

mSoapEnvelope.Load(reader);

stringReader.Close();
reader.Close();
}

private XmlClient() { }
Expand Down Expand Up @@ -332,7 +336,8 @@ private static void SignDocument(X509Certificate2 cert, XmlDocument doc)
XmlReaderSettings settings = new XmlReaderSettings();
settings.DtdProcessing = DtdProcessing.Prohibit;
settings.XmlResolver = null;
XmlReader reader = XmlReader.Create(new StringReader(keyInfoTags), settings);
StringReader stringReader = new StringReader(keyInfoTags);
XmlReader reader = XmlReader.Create(stringReader, settings);

//keyInfo.LoadXml("<root xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\" xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" ><ds:KeyInfo><SecurityTokenReference xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\"><wsse:Reference URI=\"#X509Token\" ValueType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3\"/></SecurityTokenReference></ds:KeyInfo></root>");
keyInfo.Load(reader);
Expand All @@ -341,7 +346,8 @@ private static void SignDocument(X509Certificate2 cert, XmlDocument doc)
//Add The Base64 representation of the X509 cert to BinarySecurityToken Node
//X509SecurityToken token = new X509SecurityToken(cert);
doc.DocumentElement.FirstChild.LastChild.InnerText = Convert.ToBase64String(cert.Export(X509ContentType.Cert), Base64FormattingOptions.None);

stringReader.Close();
reader.Close();
}

private static void encryptDocument(X509Certificate2 cert, XmlDocument doc)
Expand All @@ -359,7 +365,8 @@ private static void encryptDocument(X509Certificate2 cert, XmlDocument doc)
XmlReaderSettings settings = new XmlReaderSettings();
settings.DtdProcessing = DtdProcessing.Prohibit;
settings.XmlResolver = null;
XmlReader reader = XmlReader.Create(new StringReader(encData), settings);
StringReader stringReader = new StringReader(encData);
XmlReader reader = XmlReader.Create(stringReader, settings);

encryptedDataTags.Load(reader);
doc.DocumentElement.FirstChild.FirstChild.PrependChild(doc.ImportNode(encryptedDataTags.FirstChild.FirstChild, true));
Expand Down Expand Up @@ -392,6 +399,8 @@ private static void encryptDocument(X509Certificate2 cert, XmlDocument doc)
// Put encypted body inside ciphervalue tag
doc.GetElementsByTagName("SOAP-ENV:Body")[0].InnerXml = encryptedSoapBody;
doc.GetElementsByTagName("xenc:CipherValue")[1].InnerText = encryptedPayload;
stringReader.Close();
reader.Close();
}

/// <summary>
Expand Down Expand Up @@ -492,6 +501,7 @@ private static XmlDocument ReadXml(WebResponse webResponse)
settings.XmlResolver = null;
XmlReader reader = XmlReader.Create(stream, settings);
xmlDoc.Load(reader);
reader.Close();
return (xmlDoc);
}
finally
Expand Down
2 changes: 1 addition & 1 deletion CyberSourceSamples/src/nvp/NVPSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static void Main(string[] args)
request.Add( "billTo_ipAddress", "10.7.111.111" );
request.Add( "card_accountNumber", "4111111111111111" );
request.Add( "card_expirationMonth", "12" );
request.Add( "card_expirationYear", "2020" );
request.Add( "card_expirationYear", "2030" );
request.Add( "purchaseTotals_currency", "USD" );

// there are two items in this sample
Expand Down
12 changes: 6 additions & 6 deletions CyberSourceSamples/src/soap/SoapSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ public RequestMessage authRequest()
Card card = new Card();
card.accountNumber = "4111111111111111";
card.expirationMonth = "12";
card.expirationYear = "2020";
card.expirationYear = "2030";
request.card = card;

PurchaseTotals purchaseTotals = new PurchaseTotals();
Expand Down Expand Up @@ -491,7 +491,7 @@ public RequestMessage emvAuthRequest()
Card card = new Card();
card.accountNumber = "4111111111111111";
card.expirationMonth = "12";
card.expirationYear = "2020";
card.expirationYear = "2030";
request.card = card;

PurchaseTotals purchaseTotals = new PurchaseTotals();
Expand Down Expand Up @@ -663,7 +663,7 @@ public RequestMessage refundRequest()
Card card = new Card();
card.accountNumber = "4111111111111111";
card.expirationMonth = "12";
card.expirationYear = "2020";
card.expirationYear = "2030";
request.card = card;


Expand Down Expand Up @@ -739,7 +739,7 @@ public RequestMessage androidPayAuthRequest()
Card card = new Card();
card.accountNumber = "4111111111111111";
card.expirationMonth = "12";
card.expirationYear = "2020";
card.expirationYear = "2030";
request.card = card;

PurchaseTotals purchaseTotals = new PurchaseTotals();
Expand Down Expand Up @@ -807,7 +807,7 @@ public RequestMessage applePayAuthRequest()
Card card = new Card();
card.accountNumber = "4111111111111111";
card.expirationMonth = "12";
card.expirationYear = "2020";
card.expirationYear = "2030";
request.card = card;

PurchaseTotals purchaseTotals = new PurchaseTotals();
Expand Down Expand Up @@ -874,7 +874,7 @@ public RequestMessage saleRequest()
Card card = new Card();
card.accountNumber = "4111111111111111";
card.expirationMonth = "12";
card.expirationYear = "2020";
card.expirationYear = "2030";
request.card = card;

PurchaseTotals purchaseTotals = new PurchaseTotals();
Expand Down
2 changes: 1 addition & 1 deletion sample.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<card>
<accountNumber>4111111111111111</accountNumber>
<expirationMonth>12</expirationMonth>
<expirationYear>2020</expirationYear>
<expirationYear>2030</expirationYear>
</card>
<ccAuthService run="true">
</ccAuthService>
Expand Down

0 comments on commit af287b0

Please sign in to comment.