-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+initial commit
- Loading branch information
Steven
authored
Dec 13, 2018
0 parents
commit cf303ac
Showing
8 changed files
with
520 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Created by SharpDevelop. | ||
* User: C3rebro | ||
* Date: 12.12.2018 | ||
* Time: 22:43 | ||
* | ||
* To change this template use Tools | Options | Coding | Edit Standard Headers. | ||
*/ | ||
using System; | ||
using System.IO; | ||
using System.Text; | ||
using System.Reflection; | ||
using System.Security.Cryptography; | ||
|
||
namespace LDAP2CSV | ||
{ | ||
/// <summary> | ||
/// Description of Crypto. | ||
/// </summary> | ||
public static class Crypto | ||
{ | ||
// Create byte array for additional entropy when using Protect method. | ||
static byte [] s_aditionalEntropy = Encoding.Default.GetBytes( | ||
string.Format("{0},{1},{2}", | ||
Assembly.GetExecutingAssembly().GetName().Version.MajorRevision, | ||
Assembly.GetExecutingAssembly().GetName().Version.MinorRevision, | ||
Assembly.GetExecutingAssembly().GetName().Version.Build)); | ||
|
||
static string pathToCredFile = Path.Combine(Environment.CurrentDirectory, "cred.lcv"); | ||
|
||
public static int Protect( string cred ) | ||
{ | ||
try | ||
{ | ||
//pipe character is used as seperator username|pwd | ||
if(cred.Contains("|")) | ||
{ | ||
if(File.Exists(pathToCredFile)) | ||
File.Delete(pathToCredFile); | ||
|
||
// Encrypt the data using DataProtectionScope.LocalMachine. The result can be decrypted | ||
// only on the same machine. | ||
File.AppendAllText(pathToCredFile, | ||
Encoding.Default.GetString( | ||
ProtectedData.Protect(Encoding.Default.GetBytes(cred), s_aditionalEntropy, DataProtectionScope.LocalMachine ) | ||
), Encoding.Default); | ||
|
||
return 0; | ||
} else | ||
return 1; | ||
|
||
} | ||
|
||
catch(Exception e) | ||
{ | ||
LogWriter.CreateLogEntry(string.Format("ERROR:{0} {1}", e.Message, (e.InnerException != null) ? e.InnerException.Message : string.Empty)); | ||
return 1; | ||
} | ||
} | ||
|
||
public static string Unprotect() | ||
{ | ||
try | ||
{ | ||
//Decrypt the data using DataProtectionScope.CurrentUser. | ||
return Encoding.Default.GetString( | ||
ProtectedData.Unprotect(File.ReadAllBytes(pathToCredFile), s_aditionalEntropy, DataProtectionScope.LocalMachine ) | ||
); | ||
} | ||
catch (Exception e) | ||
{ | ||
LogWriter.CreateLogEntry(string.Format("ERROR:{0} {1}", e.Message, (e.InnerException != null) ? e.InnerException.Message : string.Empty)); | ||
return null; | ||
} | ||
} | ||
|
||
private static byte[] CreateRandomEntropy() | ||
{ | ||
// Create a byte array to hold the random value. | ||
byte[] entropy = new byte[16]; | ||
|
||
// Create a new instance of the RNGCryptoServiceProvider. | ||
// Fill the array with a random value. | ||
new RNGCryptoServiceProvider().GetBytes(entropy); | ||
|
||
// Return the array. | ||
return entropy; | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build"> | ||
<PropertyGroup> | ||
<ProjectGuid>{5C986A48-3AE5-46E5-B098-430BE541C4AF}</ProjectGuid> | ||
<ProjectTypeGuids>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>LDAP2CSV</RootNamespace> | ||
<AssemblyName>LDAP2CSV</AssemblyName> | ||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<NoWin32Manifest>False</NoWin32Manifest> | ||
<SignAssembly>False</SignAssembly> | ||
<DelaySign>False</DelaySign> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<Prefer32Bit>True</Prefer32Bit> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DebugSymbols>True</DebugSymbols> | ||
<DebugType>Full</DebugType> | ||
<Optimize>False</Optimize> | ||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<StartAction>Project</StartAction> | ||
<StartArguments>LDAP://10.0.0.4:389/dc=mainframe,dc=shansen-online,dc=de -C -f ou=* -a cn,uniquemember,sn,givenName,uid,asdasd3qad32 -o C:\temp\export.csv</StartArguments> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DebugSymbols>False</DebugSymbols> | ||
<DebugType>None</DebugType> | ||
<Optimize>True</Optimize> | ||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<StartAction>Project</StartAction> | ||
<StartArguments>-c ou=people,dc=example,dc=de|password</StartArguments> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Microsoft.CSharp"> | ||
<RequiredTargetFramework>4.0</RequiredTargetFramework> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core"> | ||
<RequiredTargetFramework>3.5</RequiredTargetFramework> | ||
</Reference> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Data.DataSetExtensions"> | ||
<RequiredTargetFramework>3.5</RequiredTargetFramework> | ||
</Reference> | ||
<Reference Include="System.DirectoryServices" /> | ||
<Reference Include="System.DirectoryServices.Protocols" /> | ||
<Reference Include="System.Linq" /> | ||
<Reference Include="System.Security" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="System.Xml.Linq"> | ||
<RequiredTargetFramework>3.5</RequiredTargetFramework> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Crypto.cs" /> | ||
<Compile Include="LogWriter.cs" /> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="app.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 2012 | ||
# SharpDevelop 5.1 | ||
VisualStudioVersion = 12.0.20827.3 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LDAP2CSV", "LDAP2CSV.csproj", "{5C986A48-3AE5-46E5-B098-430BE541C4AF}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{5C986A48-3AE5-46E5-B098-430BE541C4AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{5C986A48-3AE5-46E5-B098-430BE541C4AF}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{5C986A48-3AE5-46E5-B098-430BE541C4AF}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{5C986A48-3AE5-46E5-B098-430BE541C4AF}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Steven | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Created by SharpDevelop. | ||
* Date: 31.08.2017 | ||
* Time: 20:32 | ||
* | ||
*/ | ||
|
||
using System; | ||
using System.IO; | ||
using System.Reflection; | ||
|
||
namespace LDAP2CSV | ||
{ | ||
/// <summary> | ||
/// Description of LogWriter. | ||
/// </summary> | ||
public static class LogWriter | ||
{ | ||
private static StreamWriter textStream; | ||
|
||
private static readonly string _logFileName = "err.log"; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="entry"></param> | ||
public static void CreateLogEntry(string entry) | ||
{ | ||
string _logFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Assembly.GetExecutingAssembly().GetName().Name, "log"); | ||
|
||
if (!Directory.Exists(_logFilePath)) | ||
Directory.CreateDirectory(_logFilePath); | ||
try | ||
{ | ||
if (!File.Exists(Path.Combine(_logFilePath, _logFileName))) | ||
textStream = File.CreateText(Path.Combine(_logFilePath, _logFileName)); | ||
else | ||
textStream = File.AppendText(Path.Combine(_logFilePath, _logFileName)); | ||
textStream.WriteAsync(string.Format("{0}" + Environment.NewLine, entry.Replace("\r\n", "; ").Insert(0,DateTime.Now.ToString() + " "))); | ||
textStream.Close(); | ||
textStream.Dispose(); | ||
} | ||
catch | ||
{ | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.