Skip to content

Commit

Permalink
Fixed issue #2
Browse files Browse the repository at this point in the history
Added Exchange 2013 CU1 & CU2
  • Loading branch information
Pro committed Jan 18, 2014
1 parent f3d2083 commit 6071a23
Show file tree
Hide file tree
Showing 22 changed files with 383 additions and 277 deletions.
10 changes: 8 additions & 2 deletions DkimSigner.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ Global
Debug Ex2013 CU2|Any CPU = Debug Ex2013 CU2|Any CPU
Debug Ex2013|Any CPU = Debug Ex2013|Any CPU
Release Ex2007 SP3|Any CPU = Release Ex2007 SP3|Any CPU
Release Ex2010|Any CPU = Release Ex2010|Any CPU
Release Ex2010 SP1|Any CPU = Release Ex2010 SP1|Any CPU
Release Ex2010 SP2|Any CPU = Release Ex2010 SP2|Any CPU
Release Ex2010 SP3|Any CPU = Release Ex2010 SP3|Any CPU
Release Ex2010|Any CPU = Release Ex2010|Any CPU
Release Ex2013 CU2|Any CPU = Release Ex2013 CU2|Any CPU
Release Ex2013|Any CPU = Release Ex2013|Any CPU
Release Ex2013 CU1|Any CPU = Release Ex2013 CU1|Any CPU
Release Ex2013 CU2|Any CPU = Release Ex2013 CU2|Any CPU
Release Ex2013 CU3|Any CPU = Release Ex2013 CU3|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3AF0EAB4-6135-4908-A659-5E3C974E4718}.Debug Ex2010 SP3|Any CPU.ActiveCfg = Debug Ex2010 SP3|Any CPU
Expand All @@ -37,6 +39,10 @@ Global
{3AF0EAB4-6135-4908-A659-5E3C974E4718}.Release Ex2013 CU2|Any CPU.Build.0 = Release Ex2013 CU2|Any CPU
{3AF0EAB4-6135-4908-A659-5E3C974E4718}.Release Ex2013|Any CPU.ActiveCfg = Release Ex2013|Any CPU
{3AF0EAB4-6135-4908-A659-5E3C974E4718}.Release Ex2013|Any CPU.Build.0 = Release Ex2013|Any CPU
{3AF0EAB4-6135-4908-A659-5E3C974E4718}.Release Ex2013 CU1|Any CPU.ActiveCfg = Release Ex2013 CU1|Any CPU
{3AF0EAB4-6135-4908-A659-5E3C974E4718}.Release Ex2013 CU1|Any CPU.Build.0 = Release Ex2013 CU1|Any CPU
{3AF0EAB4-6135-4908-A659-5E3C974E4718}.Release Ex2013 CU3|Any CPU.ActiveCfg = Release Ex2013 CU3|Any CPU
{3AF0EAB4-6135-4908-A659-5E3C974E4718}.Release Ex2013 CU3|Any CPU.Build.0 = Release Ex2013 CU3|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 4 additions & 0 deletions Lib/Exchange 2013 CU1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ DKIM Signing Agent for Exchange Server.

This code is mainly based on the work of http://nicholas.piasecki.name/blog/2010/12/dkim-signing-outbound-messages-in-exchange-server-2007/

WARNING: Please read the 'Known Bugs' section before you continue!

If you have a version installed previous to 26.11.2013 read the Section [Update from Version 0.5](#update-from-version-05)

## Supported versions
Expand All @@ -21,8 +19,6 @@ This Receive Agent is fully tested under Exchange 2013

This Receive Agent is fully tested under Exchange 2010 SP3 with Windows Server 2008 R2.

There's are also compiled versions for no Service Pack, SP1 and SP2 installed.

### Exchange 2007

Exchange 2007 SP3 .dll is build and can be found in the release directory. Please check if those are working for you and send me a short notice.
Expand Down Expand Up @@ -111,10 +107,6 @@ Uninstall-TransportAgent -Identity "Exchange DKIM"

Follow the install instructions but execute `.\uninstall.ps1` instead.

## Known bugs

* [unconfirmed] When using internal Receive Connectors as Relay, unicode characters may break and will be replaced with '?'. See: Issue #2

## Notes for developers

### Required DLLs for developing
Expand Down Expand Up @@ -150,6 +142,9 @@ If you want to debug the .dll on your Exchange Server, you need to install [Visu

## Changelog

* 18.01.2013 [1.5.2]:
Fixed message subject and body unicode encoding bug
Added support for Exchange 2013 CU1, CU2, CU3
* 27.11.2013 [1.5.1]:
Added support for Exchange 2013
* 26.11.2013 [1.5]:
Expand All @@ -165,3 +160,4 @@ If you want to debug the .dll on your Exchange Server, you need to install [Visu
## TODO

* Allow use of relaxed or any combination between relaxed and simple
* Change install script to automatically detect exchange version. If not supported, allow user to upload .dll and then notify developer.
2 changes: 1 addition & 1 deletion Src/Exchange.DkimSigner/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
<customSection>
<general LogLevel="3" HeadersToSign="From; Subject; To; Date; Message-ID;" Algorithm="RsaSha1"/>
</customSection>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
13 changes: 6 additions & 7 deletions Src/Exchange.DkimSigner/DefaultDkimSigner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ public string SourceMessage(Stream inputStream)
/// Writes a signed version of the unsigned MIME message in the input stream
/// to the output stream.
/// </summary>
/// <param name="inputStream">The input stream.</param>
/// <param name="inputStream">The input stream byte data.</param>
/// <param name="outputStream">The output stream.</param>
public void Sign(string inputsource, Stream outputStream, string signeddkim)
public void Sign(byte[] inputBytes, Stream outputStream, string signeddkim)
{
if (this.disposed)
{
Expand All @@ -255,7 +255,7 @@ public void Sign(string inputsource, Stream outputStream, string signeddkim)
//var canonicalizedHeaders = this.GetCanonicalizedHeaders(inputStream);
//var signedDkimHeader = this.GetSignedDkimHeader(unsignedDkimHeader, canonicalizedHeaders);

WriteSignedMimeMessage(inputsource, outputStream, signeddkim);
WriteSignedMimeMessage(inputBytes, outputStream, signeddkim);
}

/// <summary>
Expand Down Expand Up @@ -285,21 +285,20 @@ private static bool IsMatch(Stream stream, byte[] candidate)
/// <summary>
/// Writes the message containing the signed DKIM-Signature header to the output stream.
/// </summary>
/// <param name="input">The stream containing the original MIME message.</param>
/// <param name="input">The bytes from the stream containing the original MIME message.</param>
/// <param name="output">The stream containing the output MIME message.</param>
/// <param name="signedDkimHeader">The signed DKIM-Signature header.</param>
private static void WriteSignedMimeMessage(string input, Stream output, string signedDkimHeader)
private static void WriteSignedMimeMessage(byte[] inputBytes, Stream output, string signedDkimHeader)
{
byte[] headerBuffer;
byte[] inputBytes;

headerBuffer = Encoding.ASCII.GetBytes(signedDkimHeader);
output.Write(headerBuffer, 0, headerBuffer.Length);

inputBytes = Encoding.ASCII.GetBytes(input);
output.Write(inputBytes, 0, inputBytes.Length);
}


/// <summary>
/// Releases unmanaged and - optionally - managed resources
/// </summary>
Expand Down
30 changes: 26 additions & 4 deletions Src/Exchange.DkimSigner/DkimSigningRoutingAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,18 @@ private void SignMailItem(MailItem mailItem)

if (dkim.Length != 0)
{
string source = this.dkimSigner.SourceMessage(inputStream);
Logger.LogInformation("Signing mail with header: " + dkim);

inputStream.Close();

Logger.LogInformation("Signing mail with header: " + dkim);
inputStream.Seek(0, SeekOrigin.Begin);
byte[] inputBuffer = ReadFully(inputStream);
inputStream.Close();

using (var outputStream = mailItem.GetMimeWriteStream())
{
try
{
this.dkimSigner.Sign(source, outputStream, dkim);
this.dkimSigner.Sign(inputBuffer, outputStream, dkim);
}
catch (Exception ex)
{
Expand All @@ -106,9 +107,30 @@ private void SignMailItem(MailItem mailItem)

outputStream.Close();
}

}
}
}
}

/// <summary>
/// Slurp the stream and convert it to a binary array.
/// http://stackoverflow.com/a/221941/869402
/// </summary>
/// <param name="input">The stream to read</param>
/// <returns>All the data from the stream as byte array</returns>
public static byte[] ReadFully(Stream input)
{
byte[] buffer = new byte[16 * 1024];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
return ms.ToArray();
}
}
}
}
Loading

0 comments on commit 6071a23

Please sign in to comment.