copied Crypto from sandbox to trunk

This commit is contained in:
Peter Schojer 2008-10-31 09:06:54 +00:00
parent 5b31c46b16
commit 4975ac2c44
55 changed files with 6576 additions and 11 deletions

30
Crypto/Crypto_VS71.sln Normal file
View File

@ -0,0 +1,30 @@
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Crypto", "Crypto_VS71.vcproj", "{eeee7259-32e9-4d56-b023-c733940ab2a0}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestSuite", "testsuite\TestSuite_VS71.vcproj", "{c1b1bb96-5198-48eb-ab48-9a0a0b54fb15}"
ProjectSection(ProjectDependencies) = postProject
{eeee7259-32e9-4d56-b023-c733940ab2a0} = {eeee7259-32e9-4d56-b023-c733940ab2a0}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
debug_shared = debug_shared
release_shared = release_shared
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{eeee7259-32e9-4d56-b023-c733940ab2a0}.debug_shared.ActiveCfg = debug_shared|Win32
{eeee7259-32e9-4d56-b023-c733940ab2a0}.debug_shared.Build.0 = debug_shared|Win32
{eeee7259-32e9-4d56-b023-c733940ab2a0}.release_shared.ActiveCfg = release_shared|Win32
{eeee7259-32e9-4d56-b023-c733940ab2a0}.release_shared.Build.0 = release_shared|Win32
{c1b1bb96-5198-48eb-ab48-9a0a0b54fb15}.debug_shared.ActiveCfg = debug_shared|Win32
{c1b1bb96-5198-48eb-ab48-9a0a0b54fb15}.debug_shared.Build.0 = debug_shared|Win32
{c1b1bb96-5198-48eb-ab48-9a0a0b54fb15}.release_shared.ActiveCfg = release_shared|Win32
{c1b1bb96-5198-48eb-ab48-9a0a0b54fb15}.release_shared.Build.0 = release_shared|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal

229
Crypto/Crypto_VS71.vcproj Normal file
View File

@ -0,0 +1,229 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="Crypto"
ProjectGUID="{eeee7259-32e9-4d56-b023-c733940ab2a0}"
RootNamespace="Crypto"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared"
ConfigurationType="2"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".\include;..\Foundation\include;..\NetSSL_OpenSSL\include;..\Net\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;POCO_DLL;Crypto_EXPORTS;OPENSSL_NO_DEPRECATED"
StringPooling="TRUE"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
BufferSecurityCheck="TRUE"
TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="TRUE"
RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundationd.lib"
OutputFile="..\bin\PocoCryptod.dll"
LinkIncremental="2"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories="..\lib"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="..\bin\PocoCryptod.pdb"
SubSystem="1"
OptimizeForWindows98="1"
ImportLibrary="..\lib\PocoCryptod.lib"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="release_shared|Win32"
OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared"
ConfigurationType="2"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="4"
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="TRUE"
FavorSizeOrSpeed="1"
OmitFramePointers="TRUE"
OptimizeForProcessor="3"
AdditionalIncludeDirectories=".\include;..\Foundation\include;..\NetSSL_OpenSSL\include;..\Net\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;POCO_DLL;Crypto_EXPORTS;OPENSSL_NO_DEPRECATED"
GeneratePreprocessedFile="0"
KeepComments="FALSE"
StringPooling="TRUE"
RuntimeLibrary="2"
BufferSecurityCheck="FALSE"
TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="TRUE"
RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="0"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundation.lib"
OutputFile="..\bin\PocoCrypto.dll"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories="..\lib"
GenerateDebugInformation="FALSE"
ProgramDatabaseFile=""
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
OptimizeForWindows98="1"
ImportLibrary="..\lib\PocoCrypto.lib"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="CryptoCore"
Filter="">
<Filter
Name="Header Files"
Filter="">
<File
RelativePath=".\include\Poco\Crypto\Cipher.h">
</File>
<File
RelativePath=".\include\Poco\Crypto\CipherFactory.h">
</File>
<File
RelativePath=".\include\Poco\Crypto\CipherImpl.h">
</File>
<File
RelativePath=".\include\Poco\Crypto\CipherKey.h">
</File>
<File
RelativePath=".\include\Poco\Crypto\CipherKeyImpl.h">
</File>
<File
RelativePath=".\include\Poco\Crypto\Crypto.h">
</File>
<File
RelativePath=".\include\Poco\Crypto\CryptoStream.h">
</File>
<File
RelativePath=".\include\Poco\Crypto\CryptoTransform.h">
</File>
<File
RelativePath=".\include\Poco\Crypto\RSACipherImpl.h">
</File>
<File
RelativePath=".\include\Poco\Crypto\RSADigestEngine.h">
</File>
<File
RelativePath=".\include\Poco\Crypto\RSAKey.h">
</File>
<File
RelativePath=".\include\Poco\Crypto\RSAKeyImpl.h">
</File>
</Filter>
<Filter
Name="Source Files"
Filter="">
<File
RelativePath=".\src\Cipher.cpp">
</File>
<File
RelativePath=".\src\CipherFactory.cpp">
</File>
<File
RelativePath=".\src\CipherImpl.cpp">
</File>
<File
RelativePath=".\src\CipherKey.cpp">
</File>
<File
RelativePath=".\src\CipherKeyImpl.cpp">
</File>
<File
RelativePath=".\src\CryptoStream.cpp">
</File>
<File
RelativePath=".\src\CryptoTransform.cpp">
</File>
<File
RelativePath=".\src\RSACipherImpl.cpp">
</File>
<File
RelativePath=".\src\RSADigestEngine.cpp">
</File>
<File
RelativePath=".\src\RSAKey.cpp">
</File>
<File
RelativePath=".\src\RSAKeyImpl.cpp">
</File>
</Filter>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

26
Crypto/Crypto_VS80.sln Normal file
View File

@ -0,0 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Crypto_VS80", "Crypto_VS80.vcproj", "{EEEE7259-32E9-4D56-B023-C733940AB2A0}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestSuite", "testsuite\TestSuite_VS80.vcproj", "{C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
debug_shared|Win32 = debug_shared|Win32
release_shared|Win32 = release_shared|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EEEE7259-32E9-4D56-B023-C733940AB2A0}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
{EEEE7259-32E9-4D56-B023-C733940AB2A0}.debug_shared|Win32.Build.0 = debug_shared|Win32
{EEEE7259-32E9-4D56-B023-C733940AB2A0}.release_shared|Win32.ActiveCfg = release_shared|Win32
{EEEE7259-32E9-4D56-B023-C733940AB2A0}.release_shared|Win32.Build.0 = release_shared|Win32
{C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
{C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.debug_shared|Win32.Build.0 = debug_shared|Win32
{C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.release_shared|Win32.ActiveCfg = release_shared|Win32
{C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.release_shared|Win32.Build.0 = release_shared|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

313
Crypto/Crypto_VS80.vcproj Normal file
View File

@ -0,0 +1,313 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Name="Crypto_VS80"
ProjectGUID="{EEEE7259-32E9-4D56-B023-C733940AB2A0}"
RootNamespace="Crypto"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared"
ConfigurationType="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".\include;..\Foundation\include;..\NetSSL_OpenSSL\include;..\Net\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;POCO_DLL;Crypto_EXPORTS;OPENSSL_NO_DEPRECATED"
StringPooling="true"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
BufferSecurityCheck="true"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="4"
CompileAs="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundationd.lib libeay32mtd.lib ssleay32mtd.lib"
OutputFile="..\bin\PocoCryptod.dll"
LinkIncremental="2"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="..\lib"
GenerateDebugInformation="true"
ProgramDatabaseFile="..\bin\PocoCryptod.pdb"
SubSystem="1"
OptimizeForWindows98="0"
ImportLibrary="..\lib\PocoCryptod.lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="release_shared|Win32"
OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared"
ConfigurationType="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="4"
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories=".\include;..\Foundation\include;..\NetSSL_OpenSSL\include;..\Net\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;POCO_DLL;Crypto_EXPORTS;OPENSSL_NO_DEPRECATED"
GeneratePreprocessedFile="0"
KeepComments="false"
StringPooling="true"
RuntimeLibrary="2"
BufferSecurityCheck="false"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="0"
CompileAs="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundation.lib libeay32mt.lib ssleay32mt.lib"
OutputFile="..\bin\PocoCrypto.dll"
LinkIncremental="1"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="..\lib"
GenerateDebugInformation="false"
ProgramDatabaseFile=""
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
OptimizeForWindows98="0"
ImportLibrary="..\lib\PocoCrypto.lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="CryptoCore"
>
<Filter
Name="Header Files"
>
<File
RelativePath=".\include\Poco\Crypto\Cipher.h"
>
</File>
<File
RelativePath=".\include\Poco\Crypto\CipherFactory.h"
>
</File>
<File
RelativePath=".\include\Poco\Crypto\CipherImpl.h"
>
</File>
<File
RelativePath=".\include\Poco\Crypto\CipherKey.h"
>
</File>
<File
RelativePath=".\include\Poco\Crypto\CipherKeyImpl.h"
>
</File>
<File
RelativePath=".\include\Poco\Crypto\Crypto.h"
>
</File>
<File
RelativePath=".\include\Poco\Crypto\CryptoStream.h"
>
</File>
<File
RelativePath=".\include\Poco\Crypto\CryptoTransform.h"
>
</File>
<File
RelativePath=".\include\Poco\Crypto\RSACipherImpl.h"
>
</File>
<File
RelativePath=".\include\Poco\Crypto\RSADigestEngine.h"
>
</File>
<File
RelativePath=".\include\Poco\Crypto\RSAKey.h"
>
</File>
<File
RelativePath=".\include\Poco\Crypto\RSAKeyImpl.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\Cipher.cpp"
>
</File>
<File
RelativePath=".\src\CipherFactory.cpp"
>
</File>
<File
RelativePath=".\src\CipherImpl.cpp"
>
</File>
<File
RelativePath=".\src\CipherKey.cpp"
>
</File>
<File
RelativePath=".\src\CipherKeyImpl.cpp"
>
</File>
<File
RelativePath=".\src\CryptoStream.cpp"
>
</File>
<File
RelativePath=".\src\CryptoTransform.cpp"
>
</File>
<File
RelativePath=".\src\RSACipherImpl.cpp"
>
</File>
<File
RelativePath=".\src\RSADigestEngine.cpp"
>
</File>
<File
RelativePath=".\src\RSAKey.cpp"
>
</File>
<File
RelativePath=".\src\RSAKeyImpl.cpp"
>
</File>
</Filter>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

28
Crypto/Crypto_VS90.sln Normal file
View File

@ -0,0 +1,28 @@
Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Crypto", "Crypto_VS90.vcproj", "{EEEE7259-32E9-4D56-B023-C733940AB2A0}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestSuite", "testsuite\TestSuite_VS90.vcproj", "{C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}"
ProjectSection(ProjectDependencies) = postProject
{EEEE7259-32E9-4D56-B023-C733940AB2A0} = {EEEE7259-32E9-4D56-B023-C733940AB2A0}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
debug_shared|Win32 = debug_shared|Win32
release_shared|Win32 = release_shared|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EEEE7259-32E9-4D56-B023-C733940AB2A0}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
{EEEE7259-32E9-4D56-B023-C733940AB2A0}.debug_shared|Win32.Build.0 = debug_shared|Win32
{EEEE7259-32E9-4D56-B023-C733940AB2A0}.release_shared|Win32.ActiveCfg = release_shared|Win32
{EEEE7259-32E9-4D56-B023-C733940AB2A0}.release_shared|Win32.Build.0 = release_shared|Win32
{C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
{C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.debug_shared|Win32.Build.0 = debug_shared|Win32
{C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.release_shared|Win32.ActiveCfg = release_shared|Win32
{C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.release_shared|Win32.Build.0 = release_shared|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

313
Crypto/Crypto_VS90.vcproj Normal file
View File

@ -0,0 +1,313 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Name="Crypto"
ProjectGUID="{eeee7259-32e9-4d56-b023-c733940ab2a0}"
RootNamespace="Crypto"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared"
ConfigurationType="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".\include;..\Foundation\include;..\NetSSL_OpenSSL\include;..\Net\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;POCO_DLL;Crypto_EXPORTS;OPENSSL_NO_DEPRECATED"
StringPooling="true"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
BufferSecurityCheck="true"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="4"
CompileAs="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundationd.lib libeay32mdd.lib ssleay32mdd.lib"
ShowProgress="0"
OutputFile="..\bin\PocoCryptod.dll"
LinkIncremental="2"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="..\lib"
GenerateDebugInformation="true"
ProgramDatabaseFile="..\bin\PocoCryptod.pdb"
SubSystem="1"
OptimizeForWindows98="0"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
ImportLibrary="..\lib\PocoCryptod.lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="release_shared|Win32"
OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared"
ConfigurationType="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="4"
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories=".\include;..\Foundation\include;..\NetSSL_OpenSSL\include;..\Net\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;POCO_DLL;Crypto_EXPORTS"
GeneratePreprocessedFile="0"
KeepComments="false"
StringPooling="true"
RuntimeLibrary="2"
BufferSecurityCheck="false"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="0"
CompileAs="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundation.lib libeay32mt.lib ssleay32mt.lib"
OutputFile="..\bin\PocoCrypto.dll"
LinkIncremental="1"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="..\lib"
GenerateDebugInformation="false"
ProgramDatabaseFile=""
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
OptimizeForWindows98="0"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
ImportLibrary="..\lib\PocoCrypto.lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="CryptoCore"
>
<Filter
Name="Header Files"
>
<File
RelativePath=".\include\Poco\Crypto\Cipher.h"
>
</File>
<File
RelativePath=".\include\Poco\Crypto\CipherFactory.h"
>
</File>
<File
RelativePath=".\include\Poco\Crypto\CipherImpl.h"
>
</File>
<File
RelativePath=".\include\Poco\Crypto\CipherKey.h"
>
</File>
<File
RelativePath=".\include\Poco\Crypto\CipherKeyImpl.h"
>
</File>
<File
RelativePath=".\include\Poco\Crypto\Crypto.h"
>
</File>
<File
RelativePath=".\include\Poco\Crypto\CryptoStream.h"
>
</File>
<File
RelativePath=".\include\Poco\Crypto\CryptoTransform.h"
>
</File>
<File
RelativePath=".\include\Poco\Crypto\RSACipherImpl.h"
>
</File>
<File
RelativePath=".\include\Poco\Crypto\RSADigestEngine.h"
>
</File>
<File
RelativePath=".\include\Poco\Crypto\RSAKey.h"
>
</File>
<File
RelativePath=".\include\Poco\Crypto\RSAKeyImpl.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\Cipher.cpp"
>
</File>
<File
RelativePath=".\src\CipherFactory.cpp"
>
</File>
<File
RelativePath=".\src\CipherImpl.cpp"
>
</File>
<File
RelativePath=".\src\CipherKey.cpp"
>
</File>
<File
RelativePath=".\src\CipherKeyImpl.cpp"
>
</File>
<File
RelativePath=".\src\CryptoStream.cpp"
>
</File>
<File
RelativePath=".\src\CryptoTransform.cpp"
>
</File>
<File
RelativePath=".\src\RSACipherImpl.cpp"
>
</File>
<File
RelativePath=".\src\RSADigestEngine.cpp"
>
</File>
<File
RelativePath=".\src\RSAKey.cpp"
>
</File>
<File
RelativePath=".\src\RSAKeyImpl.cpp"
>
</File>
</Filter>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

20
Crypto/Makefile Normal file
View File

@ -0,0 +1,20 @@
#
# Makefile
#
# $Id$
#
# Makefile for Poco Crypto
#
include $(POCO_BASE)/build/rules/global
SYSLIBS += -lssl -lcrypto
objects = Cipher CipherFactory CipherImpl CipherKey CipherKeyImpl CryptoStream CryptoTransform \
RSACipherImpl RSAKey RSAKeyImpl RSADigestEngine
target = PocoCrypto
target_version = $(LIBVERSION)
target_libs = PocoNetSSL PocoNet PocoFoundation
include $(POCO_BASE)/build/rules/lib

View File

@ -0,0 +1,156 @@
//
// Cipher.h
//
// $Id$
//
// Library: Crypto
// Package: CryptoCore
// Module: Cipher
//
// Definition of the Cipher class.
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef Crypto_Cipher_INCLUDED
#define Crypto_Cipher_INCLUDED
#include "Poco/Crypto/Crypto.h"
#include "Poco/RefCountedObject.h"
#include "Poco/AutoPtr.h"
#include <vector>
namespace Poco {
namespace Crypto {
class CryptoTransform;
class Crypto_API Cipher: public Poco::RefCountedObject
/// Represents the abstract base class from which all implementations of
/// symmetric/assymetric encryption algorithms must inherit. Use the CipherFactory
/// class to obtain an instance of this class:
///
/// CipherFactory& factory = CipherFactory::defaultFactory();
/// // Creates a 256-bit AES cipher
/// Cipher* pCipher = factory.createCipher(CipherKey("aes-256"));
/// Cipher* pRSACipher = factory.createCipher(RSAKey(RSAKey::KL_1024, RSAKey::EXP_SMALL));
///
/// Check the different Key constructors on how to initialize/create
/// a key. The above example auto-generates random keys.
///
/// Note that you won't be able to decrypt data encrypted with a random key
/// once the Cipher is destroyed unless you persist the generated key and IV.
/// An example usage for random keys is to encrypt data saved in a temporary
/// file.
///
/// Once your key is set up, you can use the Cipher object to encrypt or
/// decrypt strings or, in conjunction with a CryptoInputStream or a
/// CryptoOutputStream, to encrypt streams of data.
///
/// Since encrypted strings will contain arbitary binary data that will cause
/// problems in applications that are not binary-safe (eg., when sending
/// encrypted data in e-mails), the encryptString() and decryptString() can
/// encode (or decode, respectively) encrypted data using a "transport encoding".
/// Supported encodings are Base64 and BinHex.
///
/// The following example encrypts and decrypts a string utilizing Base64
/// encoding:
///
/// std::string plainText = "This is my secret information";
/// std::string encrypted = pCipher->encryptString(plainText, Cipher::ENC_BASE64);
/// std::string decrypted = pCipher->decryptString(encrypted, Cipher::ENC_BASE64);
///
/// In order to encrypt a stream of data (eg. to encrypt files), you can use
/// a CryptoStream:
///
/// // Create an output stream that will encrypt all data going through it
/// // and write pass it to the underlying file stream.
/// Poco::FileOutputStream sink("encrypted.dat");
/// CryptoOutputStream encryptor(sink, pCipher->createEncryptor());
///
/// Poco::FileInputStream source("source.txt");
/// Poco::StreamCopier::copyStream(source, encryptor);
///
/// // Always close output streams to flush all internal buffers
/// encryptor.close();
/// sink.close();
{
public:
typedef Poco::AutoPtr<Cipher> Ptr;
typedef std::vector<unsigned char> ByteVec;
enum Encoding
/// Transport encoding to use for encryptString() and decryptString().
{
ENC_NONE, /// Plain binary output
ENC_BASE64, /// Base64-encoded output
ENC_BINHEX /// BinHex-encoded output
};
virtual ~Cipher();
/// Destroys the Cipher.
virtual const std::string& name() const = 0;
/// Returns the name of the Cipher.
virtual CryptoTransform* createEncryptor() = 0;
/// Creates an encrytor object to be used with a CryptoStream.
virtual CryptoTransform* createDecryptor() = 0;
/// Creates a decryptor object to be used with a CryptoStream.
virtual std::string encryptString(const std::string& str, Encoding encoding = ENC_NONE);
/// Directly encrypt a string and encode it using the given encoding.
virtual std::string decryptString(const std::string& str, Encoding encoding = ENC_NONE);
/// Directly decrypt a string that is encoded with the given encoding.
virtual void encrypt(std::istream& source, std::ostream& sink, Encoding encoding = ENC_NONE);
/// Directly encrypts an input stream and encodes it using the given encoding.
virtual void decrypt(std::istream& source, std::ostream& sink, Encoding encoding = ENC_NONE);
/// Directly decrypt an input stream that is encoded with the given encoding.
protected:
Cipher();
/// Creates a new Cipher object.
private:
Cipher(const Cipher&);
Cipher& operator = (const Cipher&);
};
} } // namespace Poco::Crypto
#endif // Crypto_Cipher_INCLUDED

View File

@ -0,0 +1,100 @@
//
// CipherFactory.h
//
// $Id$
//
// Library: Crypto
// Package: CryptoCore
// Module: CipherFactory
//
// Definition of the CipherFactory class.
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef Crypto_CipherFactory_INCLUDED
#define Crypto_CipherFactory_INCLUDED
#include "Poco/Crypto/Crypto.h"
namespace Poco {
namespace Crypto {
class Cipher;
class CipherKey;
class RSAKey;
class Crypto_API CipherFactory
/// A factory for Cipher objects. See the Cipher class for examples on how to
/// use the CipherFactory.
{
public:
CipherFactory();
/// Creates a new CipherFactory object.
virtual ~CipherFactory();
/// Destroys the CipherFactory.
Cipher* createCipher(const CipherKey& key);
/// Creates a Cipher object for the given Cipher name. Valid cipher names
/// depend on the OpenSSL version the library is linked with; see the output
/// of
///
/// openssl enc --help
///
/// for a list of supported block and stream ciphers.
///
/// Common examples are:
///
/// * AES: "aes-128", "aes-256"
/// * DES: "des", "des3"
/// * Blowfish: "bf"
Cipher* createCipher(const RSAKey& key);
/// Creates a RSACipher
static CipherFactory& defaultFactory();
/// Returns the default CipherFactory.
private:
static int _instanceCount;
CipherFactory(const CipherFactory&);
CipherFactory& operator = (const CipherFactory&);
};
} } // namespace Poco::Crypto
#endif // Crypto_CipherFactory_INCLUDED

View File

@ -0,0 +1,90 @@
//
// CipherImpl.h
//
// $Id: //poco/Main/Crypto/include/Poco/Crypto/CipherImpl.h#2 $
//
// Library: Crypto
// Package: CryptoCore
// Module: CipherImpl
//
// Definition of the CipherImpl class.
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef Crypto_CipherImpl_INCLUDED
#define Crypto_CipherImpl_INCLUDED
#include "Poco/Crypto/Crypto.h"
#include "Poco/Crypto/Cipher.h"
#include "Poco/Crypto/CipherKey.h"
#include <openssl/evp.h>
namespace Poco {
namespace Crypto {
class CipherImpl : public Cipher
/// An implementation of the Cipher class for OpenSSL's crypto library.
{
public:
CipherImpl(const CipherKey& key);
/// Creates a new CipherImpl object for the given CipherKey.
virtual ~CipherImpl();
/// Destroys the CipherImpl.
const std::string& name() const;
/// Returns the name of the Cipher.
CryptoTransform* createEncryptor();
/// Creates an encrytor object.
CryptoTransform* createDecryptor();
/// Creates a decrytor object.
private:
CipherKey _key;
};
//
// Inlines
//
inline const std::string& CipherImpl::name() const
{
return _key.name();
}
} } // namespace Poco::Crypto
#endif // Crypto_CipherImpl_INCLUDED

View File

@ -0,0 +1,196 @@
//
// CipherKey.h
//
// $Id: //poco/Main/Crypto/include/Poco/Crypto/CipherKey.h#1 $
//
// Library: Crypto
// Package: CryptoCore
// Module: CipherKey
//
// Definition of the CipherKey class.
//
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef Crypto_CipherKey_INCLUDED
#define Crypto_CipherKey_INCLUDED
#include "Poco/Crypto/Crypto.h"
#include "Poco/Crypto/CipherKeyImpl.h"
namespace Poco {
namespace Crypto {
class Crypto_API CipherKey
/// class CipherKey stores the key information for decryption/encryption of data.
/// To create a random key, using the following code:
///
/// CipherKey key("aes-256");
///
/// Note that you won't be able to decrypt data encrypted with a random key
/// once the Cipher is destroyed unless you persist the generated key and IV.
/// An example usage for random keys is to encrypt data saved in a temporary
/// file.
///
/// To create a key using a human-readable password
/// string, use the following code. We create a AES Cipher and
/// use a salt value to make the key more robust:
///
/// std::string password = "secret";
/// CipherKey key("aes-256", password, salt);
///
{
public:
typedef CipherKeyImpl::Mode Mode;
typedef CipherKeyImpl::ByteVec ByteVec;
enum
{
DEFAULT_ITERATION_COUNT = 2000 /// Default iteration count to use with
/// generateKey(). RSA security recommends
/// an iteration count of at least 1000.
};
CipherKey(const std::string& name,
const std::string& passphrase,
const std::string& salt = "",
int iterationCount = DEFAULT_ITERATION_COUNT);
/// Creates a new CipherKeyImpl object
CipherKey(const std::string& name,
const ByteVec& key,
const ByteVec& iv);
/// Creates a new CipherKeyImpl object
CipherKey(const std::string& name);
/// Creates a new CipherKeyImpl object. Autoinitializes key and iv
~CipherKey();
/// Destroys the CipherKeyImpl.
const std::string& name() const;
/// Returns the name of the Cipher.
int keySize() const;
/// Returns the key size of the Cipher.
int blockSize() const;
/// Returns the block size of the Cipher.
int ivSize() const;
/// Returns the IV size of the Cipher.
Mode mode() const;
/// Returns the Cipher's mode of operation.
const ByteVec& getKey() const;
/// Returns the key for the Cipher.
void setKey(const ByteVec& key);
/// Sets the key for the Cipher.
const ByteVec& getIV() const;
/// Returns the initialization vector (IV) for the Cipher.
void setIV(const ByteVec& iv);
/// Sets the initialization vector (IV) for the Cipher.
CipherKeyImpl::Ptr impl();
/// Returns the impl object
private:
CipherKeyImpl::Ptr _pImpl;
};
inline const std::string& CipherKey::name() const
{
return _pImpl->name();
}
inline int CipherKey::keySize() const
{
return _pImpl->keySize();
}
inline int CipherKey::blockSize() const
{
return _pImpl->blockSize();
}
inline int CipherKey::ivSize() const
{
return _pImpl->ivSize();
}
inline CipherKey::Mode CipherKey::mode() const
{
return _pImpl->mode();
}
inline const CipherKey::ByteVec& CipherKey::getKey() const
{
return _pImpl->getKey();
}
inline void CipherKey::setKey(const CipherKey::ByteVec& key)
{
_pImpl->setKey(key);
}
inline const CipherKey::ByteVec& CipherKey::getIV() const
{
return _pImpl->getIV();
}
inline void CipherKey::setIV(const CipherKey::ByteVec& iv)
{
_pImpl->setIV(iv);
}
inline CipherKeyImpl::Ptr CipherKey::impl()
{
return _pImpl;
}
} } // namespace Poco::Crypto
#endif // Crypto_CipherKey_INCLUDED

View File

@ -0,0 +1,186 @@
//
// CipherKeyImpl.h
//
// $Id: //poco/Main/Crypto/include/Poco/Crypto/CipherKeyImpl.h#1 $
//
// Library: Crypto
// Package: CryptoCore
// Module: CipherKeyImpl
//
// Definition of the CipherKeyImpl class.
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef Crypto_CipherKeyImpl_INCLUDED
#define Crypto_CipherKeyImpl_INCLUDED
#include "Poco/Crypto/Crypto.h"
#include "Poco/RefCountedObject.h"
#include "Poco/AutoPtr.h"
#include <vector>
struct evp_cipher_st;
typedef struct evp_cipher_st EVP_CIPHER;
namespace Poco {
namespace Crypto {
class CipherKeyImpl : public RefCountedObject
/// An implementation of the Cipher class for OpenSSL's crypto library.
{
public:
typedef std::vector<unsigned char> ByteVec;
typedef Poco::AutoPtr<CipherKeyImpl> Ptr;
enum Mode
/// Cipher mode of operation. This mode determines how multiple blocks
/// are connected; this is essential to improve security.
{
MODE_STREAM_CIPHER, /// Stream cipher
MODE_ECB, /// Electronic codebook (plain concatenation)
MODE_CBC, /// Cipher block chaining (default)
MODE_CFB, /// Cipher feedback
MODE_OFB /// Output feedback
};
CipherKeyImpl(const std::string& name,
const std::string& passphrase,
const std::string& salt,
int iterationCount);
/// Creates a new CipherKeyImpl object
CipherKeyImpl(const std::string& name,
const ByteVec& key,
const ByteVec& iv);
/// Creates a new CipherKeyImpl object
CipherKeyImpl(const std::string& name);
/// Creates a new CipherKeyImpl object. Autoinitializes key and iv
virtual ~CipherKeyImpl();
/// Destroys the CipherKeyImpl.
const std::string& name() const;
/// Returns the name of the Cipher.
int keySize() const;
/// Returns the key size of the Cipher.
int blockSize() const;
/// Returns the block size of the Cipher.
int ivSize() const;
/// Returns the IV size of the Cipher.
Mode mode() const;
/// Returns the Cipher's mode of operation.
const ByteVec& getKey() const;
/// Returns the key for the Cipher.
void setKey(const ByteVec& key);
/// Sets the key for the Cipher.
const ByteVec& getIV() const;
/// Returns the initialization vector (IV) for the Cipher.
void setIV(const ByteVec& iv);
/// Sets the initialization vector (IV) for the Cipher.
const EVP_CIPHER* cipher();
/// Returns the cipher object
private:
void generateKey(const std::string& passphrase,
const std::string& salt,
int iterationCount);
/// Generates key and IV from a password and optional salt string.
void generateKey();
/// Generates key and IV from random data
void getRandomBytes(ByteVec& vec, std::size_t count);
/// Stores random bytes in vec
private:
const EVP_CIPHER* _pCipher;
std::string _name;
ByteVec _key;
ByteVec _iv;
};
//
// Inlines
//
inline const std::string& CipherKeyImpl::name() const
{
return _name;
}
inline const CipherKeyImpl::ByteVec& CipherKeyImpl::getKey() const
{
return _key;
}
inline void CipherKeyImpl::setKey(const ByteVec& key)
{
poco_assert(key.size() == keySize());
_key = key;
}
inline const CipherKeyImpl::ByteVec& CipherKeyImpl::getIV() const
{
return _iv;
}
inline void CipherKeyImpl::setIV(const ByteVec& iv)
{
poco_assert(iv.size() == ivSize());
_iv = iv;
}
inline const EVP_CIPHER* CipherKeyImpl::cipher()
{
return _pCipher;
}
} } // namespace Poco::Crypto
#endif // Crypto_CipherKeyImpl_INCLUDED

View File

@ -0,0 +1,92 @@
//
// Crypto.h
//
// $Id$
//
// Library: Crypto
// Package: CryptoCore
// Module: Crypto
//
// Basic definitions for the Poco Crypto library.
// This file must be the first file included by every other Crypto
// header file.
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef Crypto_Crypto_INCLUDED
#define Crypto_Crypto_INCLUDED
#include "Poco/Foundation.h"
//
// The following block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the Crypto_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// Crypto_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
//
#if defined(_WIN32) && defined(POCO_DLL)
#if defined(Crypto_EXPORTS)
#define Crypto_API __declspec(dllexport)
#else
#define Crypto_API __declspec(dllimport)
#endif
#endif
#if !defined(Crypto_API)
#define Crypto_API
#endif
//
// Automatically link Crypto library.
//
#if defined(_MSC_VER)
#if !defined(POCO_NO_AUTOMATIC_LIBS) && !defined(Crypto_EXPORTS)
#if defined(POCO_DLL)
#if defined(_DEBUG)
#pragma comment(lib, "PocoCryptod.lib")
#else
#pragma comment(lib, "PocoCrypto.lib")
#endif
#else
#if defined(_DEBUG)
#pragma comment(lib, "PocoCryptomtd.lib")
#else
#pragma comment(lib, "PocoCryptomt.lib")
#endif
#endif
#endif
#endif
#endif // Crypto_Crypto_INCLUDED

View File

@ -0,0 +1,155 @@
//
// CryptoStream.h
//
// $Id$
//
// Library: Crypto
// Package: CryptoCore
// Module: CryptoStream
//
// Definition of the CryptoStreamBuf, CryptoInputStream and CryptoOutputStream
// classes.
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef Crypto_CryptoStream_INCLUDED
#define Crypto_CryptoStream_INCLUDED
#include "Poco/Crypto/Crypto.h"
#include "Poco/BufferedStreamBuf.h"
#include "Poco/Buffer.h"
#include <iostream>
namespace Poco {
namespace Crypto {
class CryptoTransform;
class Cipher;
class Crypto_API CryptoStreamBuf : public Poco::BufferedStreamBuf
/// This stream buffer performs cryptographic transformation on the data
/// going through it.
{
public:
CryptoStreamBuf(std::istream& istr, CryptoTransform* pTransform, std::size_t bufferSize = 8192);
CryptoStreamBuf(std::ostream& ostr, CryptoTransform* pTransform,
std::size_t bufferSize = 8192);
virtual ~CryptoStreamBuf();
void close();
protected:
int readFromDevice(char* buffer, std::streamsize length);
int writeToDevice(const char* buffer, std::streamsize length);
private:
CryptoTransform* _pTransform;
std::istream* _pIstr;
std::ostream* _pOstr;
bool _eof;
Poco::Buffer<unsigned char> _buffer;
CryptoStreamBuf(const CryptoStreamBuf&);
CryptoStreamBuf& operator = (const CryptoStreamBuf&);
};
class Crypto_API CryptoIOS : public virtual std::ios
/// The base class for CryptoInputStream and CryptoOutputStream.
///
/// This class is needed to ensure correct initialization order of the
/// stream buffer and base classes.
{
public:
CryptoIOS(std::istream& istr, CryptoTransform* pTransform,
std::size_t bufferSize = 8192);
CryptoIOS(std::ostream& ostr, CryptoTransform* pTransform,
std::size_t bufferSize = 8192);
~CryptoIOS();
CryptoStreamBuf* rdbuf();
protected:
CryptoStreamBuf _buf;
};
class Crypto_API CryptoInputStream : public CryptoIOS, public std::istream
/// This stream transforms all data passing through it using the given
/// CryptoTransform.
///
/// Use a CryptoTransform object provided by Cipher::createEncrytor() or
/// Cipher::createDecryptor() to create an encrypting or decrypting stream,
/// respectively.
{
public:
CryptoInputStream(std::istream& istr, CryptoTransform* pTransform, std::size_t bufferSize = 8192);
/// Create a new CryptoInputStream object. The CryptoInputStream takes the
/// ownership of the given CryptoTransform object.
CryptoInputStream(std::istream& istr, Cipher& cipher, std::size_t bufferSize = 8192);
/// Create a new encrypting CryptoInputStream object using the given cipher.
~CryptoInputStream();
};
class Crypto_API CryptoOutputStream : public CryptoIOS, public std::ostream
/// This stream transforms all data passing through it using the given
/// CryptoTransform.
///
/// Use a CryptoTransform object provided by Cipher::createEncrytor() or
/// Cipher::createDecryptor() to create an encrypting or decrypting stream,
/// respectively.
///
/// After all data has been passed through the stream, close() must be called
/// to ensure completion of cryptographic transformation.
{
public:
CryptoOutputStream(std::ostream& ostr, CryptoTransform* pTransform, std::size_t bufferSize = 8192);
/// Create a new CryptoOutputStream object. The CryptoOutputStream takes the
/// ownership of the given CryptoTransform object.
CryptoOutputStream(std::ostream& ostr, Cipher& cipher, std::size_t bufferSize = 8192);
/// Create a new decrypting CryptoOutputStream object using the given cipher.
~CryptoOutputStream();
void close();
};
} } // namespace Poco::Crypto
#endif // Crypto_CryptoStream_INCLUDED

View File

@ -0,0 +1,91 @@
//
// CryptoTransform.h
//
// $Id$
//
// Library: Crypto
// Package: CryptoCore
// Module: CryptoTransform
//
// Definition of the CryptoTransform class.
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef Crypto_CryptoTransform_INCLUDED
#define Crypto_CryptoTransform_INCLUDED
#include "Poco/Crypto/Crypto.h"
namespace Poco {
namespace Crypto {
class Crypto_API CryptoTransform
/// This interface represents the basic operations for cryptographic
/// transformations to be used with a CryptoInputStream or a
/// CryptoOutputStream.
///
/// Implementations of this class are returned by the Cipher class to
/// perform encryption or decryption of data.
{
public:
CryptoTransform();
/// Creates a new CryptoTransform object.
virtual ~CryptoTransform();
/// Destroys the CryptoTransform.
virtual std::size_t blockSize() const = 0;
/// Returns the block size for this CryptoTransform.
virtual std::streamsize transform(
const unsigned char* input,
std::streamsize inputLength,
unsigned char* output,
std::streamsize outputLength) = 0;
/// Transforms a chunk of data. The inputLength is arbitrary and does not
/// need to be a multiple of the block size. The output buffer has a maximum
/// capacity of the given outputLength that must be at least
/// inputLength + bufferSize() - 1
/// Returns the number of bytes written to the output buffer.
virtual std::streamsize finalize(unsigned char* output, std::streamsize length) = 0;
/// Finalizes the transformation. The output buffer must contain enough
/// space for at least one block, ie.
/// length >= bufferSize()
/// must be true. Returns the number of bytes written to the output
/// buffer.
};
} } // namespace Poco::Crypto
#endif // Crypto_CryptoTransform_INCLUDED

View File

@ -0,0 +1,90 @@
//
// RSACipherImpl.h
//
// $Id: //poco/Main/Crypto/include/Poco/Crypto/RSACipherImpl.h#1 $
//
// Library: Crypto
// Package: CryptoCore
// Module: RSACipherImpl
//
// Definition of the RSACipherImpl class.
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef Crypto_RSACipherImpl_INCLUDED
#define Crypto_RSACipherImpl_INCLUDED
#include "Poco/Crypto/Crypto.h"
#include "Poco/Crypto/Cipher.h"
#include "Poco/Crypto/RSAKey.h"
#include <openssl/evp.h>
namespace Poco {
namespace Crypto {
class RSACipherImpl : public Cipher
/// An implementation of the RSA class for OpenSSL's crypto library.
{
public:
RSACipherImpl(const RSAKey& key);
/// Creates a new RSACipherImpl object for the given RSAKey.
virtual ~RSACipherImpl();
/// Destroys the RSACipherImpl.
const std::string& name() const;
/// Returns the name of the Cipher.
CryptoTransform* createEncryptor();
/// Creates an encrytor object.
CryptoTransform* createDecryptor();
/// Creates a decrytor object.
private:
RSAKey _key;
};
//
// Inlines
//
inline const std::string& RSACipherImpl::name() const
{
return _key.name();
}
} } // namespace Poco::Crypto
#endif // Crypto_RSACipherImpl_INCLUDED

View File

@ -0,0 +1,96 @@
//
// RSADigestEngine.h
//
// $Id: //poco/Main/Crypto/include/Poco/Crypto/RSADigestEngine.h#1 $
//
// Library: Crypto
// Package: CryptoCore
// Module: RSADigestEngine
//
// Definition of the RSADigestEngine class.
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef Crypto_RSADigestEngine_INCLUDED
#define Crypto_RSADigestEngine_INCLUDED
#include "Poco/Crypto/Crypto.h"
#include "Poco/Crypto/RSAKey.h"
#include "Poco/DigestEngine.h"
#include "Poco/SHA1Engine.h"
#include <openssl/rsa.h>
#include <istream>
#include <ostream>
namespace Poco {
namespace Crypto {
class Crypto_API RSADigestEngine: public Poco::DigestEngine
/// RSADigestEngine is the implementation class for RSADigestEngine
{
public:
RSADigestEngine(const RSAKey& key);
/// Creates the RSADigestEngine with the given key
~RSADigestEngine();
/// Destroys the RSADigestEngine.
unsigned digestLength() const;
/// Returns the length of the digest in bytes.
void reset();
/// Resets the engine so that a new
/// digest can be computed.
const DigestEngine::Digest& digest();
const DigestEngine::Digest& signature();
/// Signs the data
void verify(const DigestEngine::Digest& signature);
/// Verifies the data against the signature
protected:
void updateImpl(const void* data, unsigned length);
private:
RSAKey _key;
DigestEngine::Digest _sig;
SHA1Engine _sha1;
};
} } // namespace Poco::Crypto
#endif // Crypto_RSADigestEngine_INCLUDED

View File

@ -0,0 +1,124 @@
//
// RSAKey.h
//
// $Id: //poco/Main/Crypto/include/Poco/Crypto/RSAKey.h#3 $
//
// Library: Crypto
// Package: CryptoCore
// Module: RSAKey
//
// Definition of the RSAKey class.
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef Crypto_RSAKey_INCLUDED
#define Crypto_RSAKey_INCLUDED
#include "Poco/Crypto/Crypto.h"
#include "Poco/Crypto/RSAKeyImpl.h"
namespace Poco {
namespace Net {
class X509Certificate;
}
namespace Crypto {
class Crypto_API RSAKey
/// Stores an RSAKey
{
public:
enum KeyLength
{
KL_512 = 512,
KL_1024 = 1024,
KL_2048 = 2048,
KL_4096 = 4096
};
enum Exponent
{
EXP_SMALL = 0,
EXP_LARGE
};
RSAKey(const Poco::Net::X509Certificate& cert);
/// Extracts the RSAKey from the certificate
RSAKey(KeyLength keyLength, Exponent exp);
/// Creates the RSAKey. Creates a new public/private keypair using the given parameters.
/// Can be used to sign and verify a stream
RSAKey(const std::string& publicKeyFile,
const std::string& privateKeyFile="",
const std::string& privateKeyPwd="");
/// Creates the RSAKey. Can only by used for signing if privateKeyFile
/// is not empty.
RSAKey(std::istream* pPubKey,
std::istream* pPrivKey = 0,
const std::string& privateKeyPwd="");
/// Creates the RSAKey. Can only by used for signing if pPrivKey
/// is not null. If a private key file is specified, you don't need to
/// specify a public key file. OpenSSL will auto-create it from the private key.
~RSAKey();
/// Destroys the RSAKey.
int size() const;
/// Returns the RSA_size
void save(const std::string& pubKeyFile, const std::string& privKeyFile="", const std::string& privKeyPwd="");
/// Exports the keys to the given files. pubKeyFile/privKeyFile can be empty
void save(std::ostream* pPubKey, std::ostream* pPrivKey = 0, const std::string& privateKeyPwd = "");
/// Exports the keys to the given streams. pPubKey/pPrivKey can be empty
RSAKeyImpl::Ptr impl();
/// Returns the impl object
const std::string& name() const;
/// Returns "rsa"
private:
RSAKeyImpl::Ptr _pImpl;
};
inline RSAKeyImpl::Ptr RSAKey::impl()
{
return _pImpl;
}
} } // namespace Poco::Crypto
#endif // Crypto_RSAKey_INCLUDED

View File

@ -0,0 +1,120 @@
//
// RSAKeyImpl.h
//
// $Id: //poco/Main/Crypto/include/Poco/Crypto/RSAKeyImpl.h#2 $
//
// Library: Crypto
// Package: CryptoCore
// Module: RSAKeyImpl
//
// Definition of the RSAKeyImpl class.
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef Crypto_RSAKeyImplImpl_INCLUDED
#define Crypto_RSAKeyImplImpl_INCLUDED
#include "Poco/Crypto/Crypto.h"
#include "Poco/RefCountedObject.h"
#include "Poco/AutoPtr.h"
struct rsa_st;
typedef struct rsa_st RSA;
namespace Poco {
namespace Net {
class X509Certificate;
}
namespace Crypto {
class RSAKeyImpl: public Poco::RefCountedObject
/// class RSAKeyImpl
{
public:
typedef Poco::AutoPtr<RSAKeyImpl> Ptr;
RSAKeyImpl(const Poco::Net::X509Certificate& cert);
/// Extracts the RSAKey from the certificate
RSAKeyImpl(int keyLength, unsigned long exponent);
/// Creates the RSAKeyImpl.
RSAKeyImpl(const std::string& publicKey, const std::string& privateKeyFile, const std::string& privateKeyPwd);
/// Creates the RSAKeyImpl.
RSAKeyImpl(std::istream* pPubKey, std::istream* pPrivKey, const std::string& privateKeyPwd);
/// Creates the RSAKeyImpl. privKey is an optional parameter which can be null.
~RSAKeyImpl();
/// Destroys the RSAKeyImpl.
RSA* getRSA();
/// Returns the openssl rsa object
const RSA* getRSA() const;
/// Returns the openssl rsa object
int size() const;
/// Returns the RSA_size
void save(const std::string& pubKeyFile, const std::string& privKeyFile, const std::string& privKeyPwd);
/// Exports the keys to the given files. privKeyFile can be empty
void save(std::ostream* pPubKey, std::ostream* pPrivKey, const std::string& privateKeyPwd);
/// Exports the keys to the given streams. Can be empty
private:
void init(const std::string& pubKeyFile, const std::string& privKeyFile, const std::string& privKeyPwd);
/// Initializes the object
void freeRSA();
// Deletes the RSA object
private:
RSA* _pRSA;
};
inline RSA* RSAKeyImpl::getRSA()
{
return _pRSA;
}
inline const RSA* RSAKeyImpl::getRSA() const
{
return _pRSA;
}
} } // namespace Poco::Crypto
#endif // Crypto_RSAKeyImplImpl_INCLUDED

12
Crypto/samples/Makefile Normal file
View File

@ -0,0 +1,12 @@
#
# Makefile
#
# $Id: //poco/Main/Util/samples/Makefile#3 $
#
# Makefile for Poco Util Samples
#
.PHONY: projects
clean all: projects
projects:
$(MAKE) -C genrsakey $(MAKECMDGOALS)

View File

@ -0,0 +1,17 @@
#
# Makefile
#
# $Id: //poco/Main/template/sample.make#4 $
#
# Makefile for Poco genrsakey
#
include $(POCO_BASE)/build/rules/global
objects = genrsakey
target = genrsakey
target_version = 1
target_libs = PocoCrypto PocoUtil PocoXML PocoFoundation
include $(POCO_BASE)/build/rules/exec

View File

@ -0,0 +1,149 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="genrsakey"
ProjectGUID="{5347F6C5-C0ED-4583-92FB-560764B59938}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared"
ConfigurationType="1"
UseOfMFC="2"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include;..\..\..\Crypto\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
BufferSecurityCheck="TRUE"
TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="TRUE"
RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundationd.lib PocoXMLd.lib PocoNetd.lib PocoUtild.lib"
OutputFile="bin/genrsakeyd.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="bin/genrsakeyd.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="release_shared|Win32"
OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared"
ConfigurationType="1"
UseOfMFC="2"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="4"
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="TRUE"
FavorSizeOrSpeed="1"
OmitFramePointers="TRUE"
OptimizeForWindowsApplication="TRUE"
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include;..\..\..\Crypto\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
StringPooling="TRUE"
RuntimeLibrary="2"
BufferSecurityCheck="FALSE"
TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="TRUE"
RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundation.lib PocoXML.lib PocoNet.lib PocoUtil.lib"
OutputFile="bin/genrsakey.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="FALSE"
ProgramDatabaseFile=""
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Header Files"
Filter="">
</Filter>
<Filter
Name="Source Files"
Filter="">
<File
RelativePath=".\src\genrsakey.cpp">
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,211 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Name="genrsakey"
ProjectGUID="{5347F6C5-C0ED-4583-92FB-560764B59938}"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared"
ConfigurationType="1"
UseOfMFC="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include;..\..\..\Crypto\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
BufferSecurityCheck="true"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundationd.lib PocoXMLd.lib PocoNetd.lib PocoUtild.lib"
OutputFile="bin/genrsakeyd.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="true"
ProgramDatabaseFile="bin/genrsakeyd.pdb"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="release_shared|Win32"
OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared"
ConfigurationType="1"
UseOfMFC="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="4"
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include;..\..\..\Crypto\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
StringPooling="true"
RuntimeLibrary="2"
BufferSecurityCheck="false"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundation.lib PocoXML.lib PocoNet.lib PocoUtil.lib"
OutputFile="bin/genrsakey.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="false"
ProgramDatabaseFile=""
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Header Files"
>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\genrsakey.cpp"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,211 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Name="genrsakey_VS90"
ProjectGUID="{5347F6C5-C0ED-4583-92FB-560764B59938}"
RootNamespace="genrsakey_VS90"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared"
ConfigurationType="1"
UseOfMFC="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include;..\..\..\Crypto\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
BufferSecurityCheck="true"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundationd.lib PocoXMLd.lib PocoNetd.lib PocoUtild.lib"
OutputFile="bin/genrsakeyd.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="true"
ProgramDatabaseFile="bin/genrsakeyd.pdb"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="release_shared|Win32"
OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared"
ConfigurationType="1"
UseOfMFC="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="4"
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include;..\..\..\Crypto\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
StringPooling="true"
RuntimeLibrary="2"
BufferSecurityCheck="false"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundation.lib PocoXML.lib PocoNet.lib PocoUtil.lib"
OutputFile="bin/genrsakey.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="false"
ProgramDatabaseFile=""
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Header Files"
>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\genrsakey.cpp"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,212 @@
//
// genrsakey.cpp
//
// $Id: //poco/Main/Crypto/samples/genrsakey/src/genrsakey.cpp#1 $
//
// This sample demonstrates the XYZ class.
//
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Util/Application.h"
#include "Poco/Util/Option.h"
#include "Poco/Util/OptionException.h"
#include "Poco/Util/OptionSet.h"
#include "Poco/Util/HelpFormatter.h"
#include "Poco/Util/AbstractConfiguration.h"
#include "Poco/AutoPtr.h"
#include "Poco/NumberFormatter.h"
#include "Poco/NumberParser.h"
#include "Poco/String.h"
#include "Poco/Crypto/RSAKey.h"
#include <iostream>
using Poco::Util::Application;
using Poco::Util::Option;
using Poco::Util::OptionSet;
using Poco::Util::HelpFormatter;
using Poco::Util::AbstractConfiguration;
using Poco::Util::OptionCallback;
using Poco::AutoPtr;
using Poco::NumberParser;
using Poco::Crypto::RSAKey;
class RSAApp: public Application
/// This sample demonstrates some of the features of the Util::Application class,
/// such as configuration file handling and command line arguments processing.
///
/// Try genrsakey --help (on Unix platforms) or genrsakey /help (elsewhere) for
/// more information.
{
public:
RSAApp():
_helpRequested(false),
_length(RSAKey::KL_1024),
_exp(RSAKey::EXP_LARGE),
_name(),
_pwd()
{
}
protected:
void initialize(Application& self)
{
loadConfiguration(); // load default configuration files, if present
Application::initialize(self);
}
void uninitialize()
{
Application::uninitialize();
}
void reinitialize(Application& self)
{
Application::reinitialize(self);
}
void defineOptions(OptionSet& options)
{
Application::defineOptions(options);
options.addOption(
Option("help", "h", "display help information on command line arguments")
.required(false)
.repeatable(false)
.callback(OptionCallback<RSAApp>(this, &RSAApp::handleHelp)));
options.addOption(
Option("?", "?", "display help information on command line arguments")
.required(false)
.repeatable(false)
.callback(OptionCallback<RSAApp>(this, &RSAApp::handleHelp)));
options.addOption(
Option("key", "k", "define the key length")
.required(false)
.repeatable(false)
.argument("512|1024|2048|4096")
.callback(OptionCallback<RSAApp>(this, &RSAApp::handleKeyLength)));
options.addOption(
Option("exponent", "e", "defines the exponent of the key")
.required(false)
.repeatable(false)
.argument("small|large")
.callback(OptionCallback<RSAApp>(this, &RSAApp::handleExponent)));
options.addOption(
Option("file", "f", "defines the file base name. creates a file.pub and a file.priv")
.required(true)
.repeatable(false)
.argument("filebasename")
.callback(OptionCallback<RSAApp>(this, &RSAApp::handleFilePrefix)));
options.addOption(
Option("password", "p", "defines the password used to encrypt the private key file. If not defined user will be asked via stdin to provide in")
.required(false)
.repeatable(false)
.argument("pwd")
.callback(OptionCallback<RSAApp>(this, &RSAApp::handlePassword)));
}
void handleHelp(const std::string& name, const std::string& value)
{
_helpRequested = true;
displayHelp();
stopOptionsProcessing();
}
void handleKeyLength(const std::string& name, const std::string& value)
{
int keyLen = Poco::NumberParser::parse(value);
if (keyLen == 512 || keyLen == 1024 || keyLen == 2048 || keyLen == 4096)
_length = (RSAKey::KeyLength)keyLen;
else
throw Poco::Util::IncompatibleOptionsException("Illegal key length value");
}
void handleExponent(const std::string& name, const std::string& value)
{
if (Poco::icompare(value, "small") == 0)
_exp = RSAKey::EXP_SMALL;
else
_exp = RSAKey::EXP_LARGE;
}
void handleFilePrefix(const std::string& name, const std::string& value)
{
if (value.empty())
throw Poco::Util::IncompatibleOptionsException("Empty file prefix forbidden");
_name = value;
}
void handlePassword(const std::string& name, const std::string& value)
{
_pwd = value;
}
void displayHelp()
{
HelpFormatter helpFormatter(options());
helpFormatter.setCommand(commandName());
helpFormatter.setUsage("OPTIONS");
helpFormatter.setHeader("Application for generating RSA public/private key pairs.");
helpFormatter.format(std::cout);
}
int main(const std::vector<std::string>& args)
{
if (!_helpRequested)
{
logger().information("Generating key with length " + Poco::NumberFormatter::format((int)_length));
logger().information(std::string("Exponent is ") + ((_exp == RSAKey::EXP_SMALL)?"small":"large"));
logger().information("Generating key");
RSAKey key(_length, _exp);
logger().information("Generating key: DONE");
std::string pubFile(_name + ".pub");
std::string privFile(_name + ".priv");
logger().information("Saving key to " + pubFile + " and " + privFile);
key.save(pubFile, privFile, _pwd);
logger().information("Key saved");
}
return Application::EXIT_OK;
}
private:
bool _helpRequested;
RSAKey::KeyLength _length;
RSAKey::Exponent _exp;
std::string _name;
std::string _pwd;
};
POCO_APP_MAIN(RSAApp)

View File

@ -0,0 +1,21 @@
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "genrsakey", "genrsakey\genrsakey_VS71.vcproj", "{5347F6C5-C0ED-4583-92FB-560764B59938}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
debug_shared = debug_shared
release_shared = release_shared
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{5347F6C5-C0ED-4583-92FB-560764B59938}.debug_shared.ActiveCfg = debug_shared|Win32
{5347F6C5-C0ED-4583-92FB-560764B59938}.debug_shared.Build.0 = debug_shared|Win32
{5347F6C5-C0ED-4583-92FB-560764B59938}.release_shared.ActiveCfg = release_shared|Win32
{5347F6C5-C0ED-4583-92FB-560764B59938}.release_shared.Build.0 = release_shared|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "genrsakey", "genrsakey\genrsakey_VS80.vcproj", "{5347F6C5-C0ED-4583-92FB-560764B59938}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
debug_shared|Win32 = debug_shared|Win32
release_shared|Win32 = release_shared|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5347F6C5-C0ED-4583-92FB-560764B59938}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
{5347F6C5-C0ED-4583-92FB-560764B59938}.debug_shared|Win32.Build.0 = debug_shared|Win32
{5347F6C5-C0ED-4583-92FB-560764B59938}.release_shared|Win32.ActiveCfg = release_shared|Win32
{5347F6C5-C0ED-4583-92FB-560764B59938}.release_shared|Win32.Build.0 = release_shared|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "genrsakey_VS90", "genrsakey\genrsakey_VS90.vcproj", "{5347F6C5-C0ED-4583-92FB-560764B59938}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
debug_shared|Win32 = debug_shared|Win32
release_shared|Win32 = release_shared|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5347F6C5-C0ED-4583-92FB-560764B59938}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
{5347F6C5-C0ED-4583-92FB-560764B59938}.debug_shared|Win32.Build.0 = debug_shared|Win32
{5347F6C5-C0ED-4583-92FB-560764B59938}.release_shared|Win32.ActiveCfg = release_shared|Win32
{5347F6C5-C0ED-4583-92FB-560764B59938}.release_shared|Win32.Build.0 = release_shared|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

152
Crypto/src/Cipher.cpp Normal file
View File

@ -0,0 +1,152 @@
//
// Cipher.cpp
//
// $Id$
//
// Library: Crypto
// Package: CryptoCore
// Module: Cipher
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Crypto/Cipher.h"
#include "Poco/Crypto/CryptoStream.h"
#include "Poco/Crypto/CryptoTransform.h"
#include "Poco/Base64Encoder.h"
#include "Poco/Base64Decoder.h"
#include "Poco/HexBinaryEncoder.h"
#include "Poco/HexBinaryDecoder.h"
#include "Poco/StreamCopier.h"
#include "Poco/Exception.h"
#include <sstream>
#include <memory>
namespace Poco {
namespace Crypto {
Cipher::Cipher()
{
}
Cipher::~Cipher()
{
}
std::string Cipher::encryptString(const std::string& str, Encoding encoding)
{
std::istringstream source(str);
std::ostringstream sink;
encrypt(source, sink, encoding);
return sink.str();
}
std::string Cipher::decryptString(const std::string& str, Encoding encoding)
{
std::istringstream source(str);
std::ostringstream sink;
decrypt(source, sink, encoding);
return sink.str();
}
void Cipher::encrypt(std::istream& source, std::ostream& sink, Encoding encoding)
{
CryptoInputStream encryptor(source, createEncryptor());
switch (encoding)
{
case ENC_NONE:
StreamCopier::copyStream(encryptor, sink);
break;
case ENC_BASE64:
{
Poco::Base64Encoder encoder(sink);
StreamCopier::copyStream(encryptor, encoder);
encoder.close();
break;
}
case ENC_BINHEX:
{
Poco::HexBinaryEncoder encoder(sink);
StreamCopier::copyStream(encryptor, encoder);
encoder.close();
break;
}
default:
throw Poco::InvalidArgumentException("Invalid argument", "encoding");
}
}
void Cipher::decrypt(std::istream& source, std::ostream& sink, Encoding encoding)
{
CryptoOutputStream decryptor(sink, createDecryptor());
switch (encoding)
{
case ENC_NONE:
StreamCopier::copyStream(source, decryptor);
decryptor.close();
break;
case ENC_BASE64:
{
Poco::Base64Decoder decoder(source);
StreamCopier::copyStream(decoder, decryptor);
decryptor.close();
break;
}
case ENC_BINHEX:
{
Poco::HexBinaryDecoder decoder(source);
StreamCopier::copyStream(decoder, decryptor);
decryptor.close();
break;
}
default:
throw Poco::InvalidArgumentException("Invalid argument", "encoding");
}
}
} } // namespace Poco::Crypto

View File

@ -0,0 +1,99 @@
//
// CipherFactory.cpp
//
// $Id$
//
// Library: Crypto
// Package: CryptoCore
// Module: CipherFactory
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Crypto/CipherFactory.h"
#include "Poco/Crypto/Cipher.h"
#include "Poco/Crypto/CipherKey.h"
#include "Poco/Crypto/RSAKey.h"
#include "Poco/Crypto/CipherImpl.h"
#include "Poco/Crypto/RSACipherImpl.h"
#include "Poco/Exception.h"
#include "Poco/SingletonHolder.h"
#include <openssl/evp.h>
#include <openssl/err.h>
namespace Poco {
namespace Crypto {
int CipherFactory::_instanceCount = 0;
CipherFactory::CipherFactory()
{
if (_instanceCount == 0)
{
OpenSSL_add_all_algorithms();
ERR_load_crypto_strings();
}
++_instanceCount;
}
CipherFactory::~CipherFactory()
{
--_instanceCount;
if (_instanceCount == 0)
{
ERR_free_strings();
EVP_cleanup();
}
}
CipherFactory& CipherFactory::defaultFactory()
{
static Poco::SingletonHolder<CipherFactory> holder;
return *holder.get();
}
Cipher* CipherFactory::createCipher(const CipherKey& key)
{
return new CipherImpl(key);
}
Cipher* CipherFactory::createCipher(const RSAKey& key)
{
return new RSACipherImpl(key);
}
} } // namespace Poco::Crypto

200
Crypto/src/CipherImpl.cpp Normal file
View File

@ -0,0 +1,200 @@
//
// CipherImpl.cpp
//
// $Id$
//
// Library: Crypto
// Package: CryptoCore
// Module: CipherImpl
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Crypto/CipherImpl.h"
#include "Poco/Crypto/CryptoTransform.h"
#include "Poco/Exception.h"
#include <openssl/err.h>
namespace Poco {
namespace Crypto {
static void throwError()
{
unsigned long err;
std::string msg;
while ((err = ERR_get_error()))
{
if (!msg.empty())
msg.append("; ");
msg.append(ERR_error_string(err, 0));
}
throw Poco::IOException(msg);
}
class CryptoTransformImpl : public CryptoTransform
{
public:
typedef Cipher::ByteVec ByteVec;
enum Direction
{
DIR_ENCRYPT,
DIR_DECRYPT
};
CryptoTransformImpl(
const EVP_CIPHER* pCipher,
const ByteVec& key,
const ByteVec& iv,
Direction dir);
~CryptoTransformImpl();
std::size_t blockSize() const;
std::streamsize transform(
const unsigned char* input,
std::streamsize inputLength,
unsigned char* output,
std::streamsize outputLength);
std::streamsize finalize(
unsigned char* output,
std::streamsize length);
private:
const EVP_CIPHER* _pCipher;
EVP_CIPHER_CTX _ctx;
ByteVec _key;
ByteVec _iv;
};
CryptoTransformImpl::CryptoTransformImpl(
const EVP_CIPHER* pCipher,
const ByteVec& key,
const ByteVec& iv,
Direction dir) :
_pCipher(pCipher),
_key(key),
_iv(iv)
{
EVP_CipherInit(
&_ctx,
_pCipher,
&_key[0],
&_iv[0],
(dir == DIR_ENCRYPT) ? 1 : 0);
}
CryptoTransformImpl::~CryptoTransformImpl()
{
EVP_CIPHER_CTX_cleanup(&_ctx);
}
std::size_t CryptoTransformImpl::blockSize() const
{
return EVP_CIPHER_CTX_block_size(&_ctx);
}
std::streamsize CryptoTransformImpl::transform(
const unsigned char* input,
std::streamsize inputLength,
unsigned char* output,
std::streamsize outputLength)
{
poco_assert (outputLength >= (inputLength + blockSize() - 1));
int outLen = static_cast<int>(outputLength);
int rc = EVP_CipherUpdate(
&_ctx,
output,
&outLen,
input,
static_cast<int>(inputLength));
if (rc == 0)
throwError();
outputLength = static_cast<std::streamsize>(outLen);
return outputLength;
}
std::streamsize CryptoTransformImpl::finalize(
unsigned char* output,
std::streamsize length)
{
poco_assert (length >= blockSize());
int len = static_cast<int>(length);
// Use the '_ex' version that does not perform implicit cleanup since we
// will call EVP_CIPHER_CTX_cleanup() from the dtor as there is no
// guarantee that finalize() will be called if an error occurred.
int rc = EVP_CipherFinal_ex(&_ctx, output, &len);
if (rc == 0)
throwError();
length = static_cast<std::streamsize>(len);
return length;
}
CipherImpl::CipherImpl(const CipherKey& key):
_key(key)
{
}
CipherImpl::~CipherImpl()
{
}
CryptoTransform* CipherImpl::createEncryptor()
{
CipherKeyImpl::Ptr p = _key.impl();
return new CryptoTransformImpl(p->cipher(), p->getKey(), p->getIV(),
CryptoTransformImpl::DIR_ENCRYPT);
}
CryptoTransform* CipherImpl::createDecryptor()
{
CipherKeyImpl::Ptr p = _key.impl();
return new CryptoTransformImpl(p->cipher(), p->getKey(), p->getIV(),
CryptoTransformImpl::DIR_DECRYPT);
}
} } // namespace Poco::Crypto

72
Crypto/src/CipherKey.cpp Normal file
View File

@ -0,0 +1,72 @@
//
// CipherKey.cpp
//
// $Id: //poco/Main/Crypto/src/CipherKey.cpp#1 $
//
// Library: Crypto
// Package: CryptoCore
// Module: CipherKey
//
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Crypto/CipherKey.h"
namespace Poco {
namespace Crypto {
CipherKey::CipherKey(const std::string& name,
const std::string& passphrase,
const std::string& salt,
int iterationCount):
_pImpl(new CipherKeyImpl(name, passphrase, salt, iterationCount))
{
}
CipherKey::CipherKey(const std::string& name,
const ByteVec& key,
const ByteVec& iv):
_pImpl(new CipherKeyImpl(name, key, iv))
{
}
CipherKey::CipherKey(const std::string& name):
_pImpl(new CipherKeyImpl(name))
{
}
CipherKey::~CipherKey()
{
}
} } // namespace Poco::Crypto

View File

@ -0,0 +1,219 @@
//
// CipherKeyImpl.cpp
//
// $Id: //poco/Main/Crypto/src/CipherKeyImpl.cpp#1 $
//
// Library: Crypto
// Package: CryptoCore
// Module: CipherKeyImpl
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Crypto/CipherKeyImpl.h"
#include "Poco/Crypto/CryptoTransform.h"
#include "Poco/Crypto/CipherFactory.h"
#include "Poco/Exception.h"
#include "Poco/RandomStream.h"
#include <openssl/err.h>
#include <openssl/evp.h>
namespace Poco {
namespace Crypto {
CipherKeyImpl::CipherKeyImpl(const std::string& name,
const std::string& passphrase,
const std::string& salt,
int iterationCount):
_pCipher(0),
_name(name),
_key(),
_iv()
{
//dummy access to Cipherfactory so that the EVP lib is initilaized
CipherFactory::defaultFactory();
_pCipher = EVP_get_cipherbyname(name.c_str());
if (!_pCipher)
throw Poco::NotFoundException("Cipher " + name + " was not found");
_key = ByteVec(keySize());
_iv = ByteVec(ivSize());
generateKey(passphrase, salt, iterationCount);
}
CipherKeyImpl::CipherKeyImpl(const std::string& name,
const ByteVec& key,
const ByteVec& iv):
_pCipher(0),
_name(name),
_key(),
_iv()
{
//dummy access to Cipherfactory so that the EVP lib is initilaized
CipherFactory::defaultFactory();
_pCipher = EVP_get_cipherbyname(name.c_str());
if (!_pCipher)
throw Poco::NotFoundException("Cipher " + name + " was not found");
_key = ByteVec(keySize());
_iv = ByteVec(ivSize());
}
CipherKeyImpl::CipherKeyImpl(const std::string& name):
_pCipher(0),
_name(name),
_key(),
_iv()
{
//dummy access to Cipherfactory so that the EVP lib is initilaized
CipherFactory::defaultFactory();
_pCipher = EVP_get_cipherbyname(name.c_str());
if (!_pCipher)
throw Poco::NotFoundException("Cipher " + name + " was not found");
_key = ByteVec(keySize());
_iv = ByteVec(ivSize());
generateKey();
}
CipherKeyImpl::~CipherKeyImpl()
{
}
CipherKeyImpl::Mode CipherKeyImpl::mode() const
{
switch (EVP_CIPHER_mode(_pCipher))
{
case EVP_CIPH_STREAM_CIPHER:
return MODE_STREAM_CIPHER;
case EVP_CIPH_ECB_MODE:
return MODE_ECB;
case EVP_CIPH_CBC_MODE:
return MODE_CBC;
case EVP_CIPH_CFB_MODE:
return MODE_CFB;
case EVP_CIPH_OFB_MODE:
return MODE_OFB;
}
throw Poco::IllegalStateException("Unexpected value of EVP_CIPHER_mode()");
}
void CipherKeyImpl::generateKey()
{
ByteVec vec;
getRandomBytes(vec, keySize());
setKey(vec);
getRandomBytes(vec, ivSize());
setIV(vec);
}
void CipherKeyImpl::getRandomBytes(ByteVec& vec, std::size_t count)
{
Poco::RandomInputStream random;
vec.clear();
vec.reserve(count);
for (int i = 0; i < count; ++i)
vec.push_back(static_cast<unsigned char>(random.get()));
}
void CipherKeyImpl::generateKey(
const std::string& password,
const std::string& salt,
int iterationCount)
{
unsigned char keyBytes[EVP_MAX_KEY_LENGTH];
unsigned char ivBytes[EVP_MAX_IV_LENGTH];
// OpenSSL documentation specifies that the salt must be an 8-byte array.
unsigned char saltBytes[8];
if (!salt.empty())
{
int len = salt.size();
// Create the salt array from the salt string
for (int i = 0; i < 8; ++i)
saltBytes[i] = salt.at(i % len);
for (int i = 8; i < len; ++i)
saltBytes[i % 8] ^= salt.at(i);
}
// Now create the key and IV, using the MD5 digest algorithm.
int keySize = EVP_BytesToKey(
_pCipher,
EVP_md5(),
(salt.empty() ? 0 : saltBytes),
reinterpret_cast<const unsigned char*>(password.data()),
password.size(),
iterationCount,
keyBytes,
ivBytes);
// Copy the buffers to our member byte vectors.
_key.assign(keyBytes, keyBytes + keySize);
if (ivSize() == 0)
_iv.clear();
else
_iv.assign(ivBytes, ivBytes + ivSize());
}
int CipherKeyImpl::keySize() const
{
return EVP_CIPHER_key_length(_pCipher);
}
int CipherKeyImpl::blockSize() const
{
return EVP_CIPHER_block_size(_pCipher);
}
int CipherKeyImpl::ivSize() const
{
return EVP_CIPHER_iv_length(_pCipher);
}
} } // namespace Poco::Crypto

321
Crypto/src/CryptoStream.cpp Normal file
View File

@ -0,0 +1,321 @@
//
// CryptoStream.cpp
//
// $Id$
//
// Library: Crypto
// Package: CryptoCore
// Module: CryptoStream
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Crypto/CryptoStream.h"
#include "Poco/Crypto/CryptoTransform.h"
#include "Poco/Crypto/Cipher.h"
#include "Poco/Exception.h"
#include <algorithm>
#undef min
#undef max
namespace Poco {
namespace Crypto {
//
// CryptoStreamBuf
//
CryptoStreamBuf::CryptoStreamBuf(
std::istream& istr,
CryptoTransform* pTransform,
std::size_t bufferSize) :
Poco::BufferedStreamBuf(bufferSize, std::ios::in),
_pTransform(pTransform),
_pIstr(&istr),
_pOstr(0),
_eof(false),
_buffer(bufferSize)
{
poco_check_ptr(pTransform);
poco_assert(bufferSize >= 2 * pTransform->blockSize());
}
CryptoStreamBuf::CryptoStreamBuf(
std::ostream& ostr,
CryptoTransform* pTransform,
std::size_t bufferSize) :
Poco::BufferedStreamBuf(bufferSize, std::ios::out),
_pTransform(pTransform),
_pIstr(0),
_pOstr(&ostr),
_eof(false),
_buffer(bufferSize)
{
poco_check_ptr(pTransform);
poco_assert(bufferSize >= 2 * pTransform->blockSize());
}
CryptoStreamBuf::~CryptoStreamBuf()
{
try
{
close();
}
catch (...)
{
}
delete _pTransform;
}
void CryptoStreamBuf::close()
{
sync();
if (_pIstr)
{
_pIstr = 0;
}
else if (_pOstr)
{
// Close can be called multiple times. By zeroing the pointer we make
// sure that we call finalize() only once, even if an exception is
// thrown.
std::ostream* pOstr = _pOstr;
_pOstr = 0;
// Finalize transformation.
int n = _pTransform->finalize(_buffer.begin(), _buffer.size());
if (n > 0)
{
pOstr->write(reinterpret_cast<char*>(_buffer.begin()), n);
if (!pOstr->good())
throw Poco::IOException("Output stream failure");
}
}
}
int CryptoStreamBuf::readFromDevice(char* buffer, std::streamsize length)
{
if (!_pIstr)
return 0;
int count = 0;
while (!_eof)
{
int m = length - count - (_pTransform->blockSize() - 1);
// Make sure we can read at least one more block. Explicitely check
// for m < 0 since blockSize() returns an unsigned int and the
// comparison might give fals results for m < 0.
if (m < 0 || m < _pTransform->blockSize())
break;
int n = 0;
if (_pIstr->good())
{
_pIstr->read(reinterpret_cast<char*>(_buffer.begin()), m);
n = static_cast<int>(_pIstr->gcount());
}
if (n == 0)
{
_eof = true;
// No more data, finalize transformation
count += _pTransform->finalize(
reinterpret_cast<unsigned char*>(buffer + count),
length - count);
}
else
{
// Transform next chunk of data
count += _pTransform->transform(
_buffer.begin(),
n,
reinterpret_cast<unsigned char*>(buffer + count),
length - count);
}
}
return count;
}
int CryptoStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
{
if (!_pOstr)
return 0;
int maxChunkSize = _buffer.size() - (_pTransform->blockSize() - 1);
int count = 0;
while (count < length)
{
// Truncate chunk size so that the maximum output fits into _buffer.
int n = length - count;
if (n > maxChunkSize)
n = maxChunkSize;
// Transform next chunk of data
int k = _pTransform->transform(
reinterpret_cast<const unsigned char*>(buffer + count),
n,
_buffer.begin(),
_buffer.size());
// Attention: (n != k) might be true. In count, we have to track how
// many bytes from buffer have been consumed, not how many bytes have
// been written to _pOstr!
count += n;
if (k > 0)
{
_pOstr->write(reinterpret_cast<const char*>(_buffer.begin()), k);
if (!_pOstr->good())
throw Poco::IOException("Output stream failure");
}
}
return count;
}
//
// CryptoIOS
//
CryptoIOS::CryptoIOS(
std::istream& istr,
CryptoTransform* pTransform,
std::size_t bufferSize) :
_buf(istr, pTransform, bufferSize)
{
poco_ios_init(&_buf);
}
CryptoIOS::CryptoIOS(
std::ostream& ostr,
CryptoTransform* pTransform,
std::size_t bufferSize) :
_buf(ostr, pTransform, bufferSize)
{
poco_ios_init(&_buf);
}
CryptoIOS::~CryptoIOS()
{
}
CryptoStreamBuf* CryptoIOS::rdbuf()
{
return &_buf;
}
//
// CryptoInputStream
//
CryptoInputStream::CryptoInputStream(
std::istream& istr,
CryptoTransform* pTransform,
std::size_t bufferSize) :
CryptoIOS(istr, pTransform, bufferSize),
std::istream(&_buf)
{
}
CryptoInputStream::CryptoInputStream(
std::istream& istr,
Cipher& cipher,
std::size_t bufferSize) :
CryptoIOS(istr, cipher.createEncryptor(), bufferSize),
std::istream(&_buf)
{
}
CryptoInputStream::~CryptoInputStream()
{
}
//
// CryptoOutputStream
//
CryptoOutputStream::CryptoOutputStream(
std::ostream& ostr,
CryptoTransform* pTransform,
std::size_t bufferSize) :
CryptoIOS(ostr, pTransform, bufferSize),
std::ostream(&_buf)
{
}
CryptoOutputStream::CryptoOutputStream(
std::ostream& ostr,
Cipher& cipher,
std::size_t bufferSize):
CryptoIOS(ostr, cipher.createDecryptor(), bufferSize),
std::ostream(&_buf)
{
}
CryptoOutputStream::~CryptoOutputStream()
{
}
void CryptoOutputStream::close()
{
_buf.close();
}
} } // namespace Poco::Crypto

View File

@ -0,0 +1,54 @@
//
// CryptoTransform.cpp
//
// $Id$
//
// Library: Crypto
// Package: CryptoCore
// Module: CryptoTransform
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Crypto/CryptoTransform.h"
namespace Poco {
namespace Crypto {
CryptoTransform::CryptoTransform()
{
}
CryptoTransform::~CryptoTransform()
{
}
} } // namespace Poco::Crypto

View File

@ -0,0 +1,318 @@
//
// RSACipherImpl.cpp
//
// $Id: //poco/Main/Crypto/src/RSACipherImpl.cpp#1 $
//
// Library: Crypto
// Package: CryptoCore
// Module: RSACipherImpl
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Crypto/RSACipherImpl.h"
#include "Poco/Crypto/CryptoTransform.h"
#include "Poco/Exception.h"
#include <openssl/err.h>
#include <openssl/rsa.h>
#include <string>
namespace Poco {
namespace Crypto {
static void throwError()
{
unsigned long err;
std::string msg;
while ((err = ERR_get_error()))
{
if (!msg.empty())
msg.append("; ");
msg.append(ERR_error_string(err, 0));
}
throw Poco::IOException(msg);
}
class RSAEncryptImpl : public CryptoTransform
{
public:
enum
{
OVERFLOW = 11
};
RSAEncryptImpl(
const RSA* pRSA);
~RSAEncryptImpl();
std::size_t blockSize() const;
std::streamsize transform(
const unsigned char* input,
std::streamsize inputLength,
unsigned char* output,
std::streamsize outputLength);
std::streamsize finalize(
unsigned char* output,
std::streamsize length);
private:
std::streamsize _pos;
const RSA* _pRSA;
unsigned char* _pBuf;
};
RSAEncryptImpl::RSAEncryptImpl(
const RSA* pRSA):
_pos(0),
_pRSA(pRSA),
_pBuf(0)
{
_pBuf = new unsigned char[blockSize()];
}
RSAEncryptImpl::~RSAEncryptImpl()
{
delete _pBuf;
}
std::size_t RSAEncryptImpl::blockSize() const
{
return RSA_size(_pRSA);
}
std::streamsize RSAEncryptImpl::transform(
const unsigned char* input,
std::streamsize inputLength,
unsigned char* output,
std::streamsize outputLength)
{
// always fill up the buffer before writing!
std::streamsize rsaSize = blockSize();
poco_assert_dbg(_pos <= rsaSize);
poco_assert (outputLength >= rsaSize);
int rc = 0;
while (inputLength > 0)
{
// check how many data bytes we are missing to get the buffer full
poco_assert_dbg (rsaSize >= _pos);
std::streamsize missing = rsaSize - _pos;
if (missing == 0)
{
poco_assert (outputLength >= rsaSize);
int tmp = RSA_public_encrypt(rsaSize, _pBuf, output, const_cast<RSA*>(_pRSA), RSA_NO_PADDING);
if (tmp == -1)
throwError();
rc += tmp;
output += tmp;
outputLength -= tmp;
_pos = 0;
}
else
{
if (missing > inputLength)
missing = inputLength;
std::memcpy(_pBuf+_pos, input, missing);
input += missing;
_pos += missing;
inputLength -= missing;
}
}
return rc;
}
std::streamsize RSAEncryptImpl::finalize(
unsigned char* output,
std::streamsize length)
{
poco_assert (length >= blockSize());
int rc = 0;
if (_pos > 0)
{
rc = RSA_public_encrypt(_pos, _pBuf, output, const_cast<RSA*>(_pRSA), RSA_PKCS1_PADDING);
if (rc == -1)
throwError();
}
return rc;
}
class RSADecryptImpl : public CryptoTransform
{
public:
enum
{
OVERFLOW = 11
};
RSADecryptImpl(
const RSA* pRSA);
~RSADecryptImpl();
std::size_t blockSize() const;
std::streamsize transform(
const unsigned char* input,
std::streamsize inputLength,
unsigned char* output,
std::streamsize outputLength);
std::streamsize finalize(
unsigned char* output,
std::streamsize length);
private:
std::streamsize _pos;
const RSA* _pRSA;
unsigned char* _pBuf;
};
RSADecryptImpl::RSADecryptImpl(
const RSA* pRSA):
_pos(0),
_pRSA(pRSA),
_pBuf(0)
{
_pBuf = new unsigned char[blockSize()];
}
RSADecryptImpl::~RSADecryptImpl()
{
delete _pBuf;
}
std::size_t RSADecryptImpl::blockSize() const
{
return RSA_size(_pRSA);
}
std::streamsize RSADecryptImpl::transform(
const unsigned char* input,
std::streamsize inputLength,
unsigned char* output,
std::streamsize outputLength)
{
// always fill up the buffer before decrypting!
std::streamsize rsaSize = blockSize();
poco_assert_dbg(_pos <= rsaSize);
poco_assert (outputLength >= rsaSize);
int rc = 0;
while (inputLength > 0)
{
// check how many data bytes we are missing to get the buffer full
poco_assert_dbg (rsaSize >= _pos);
std::streamsize missing = rsaSize - _pos;
if (missing == 0)
{
int tmp = RSA_private_decrypt(rsaSize, _pBuf, output, const_cast<RSA*>(_pRSA), RSA_NO_PADDING);
if (tmp == -1)
throwError();
rc += tmp;
output += tmp;
outputLength -= tmp;
_pos = 0;
}
else
{
if (missing > inputLength)
missing = inputLength;
std::memcpy(_pBuf+_pos, input, missing);
input += missing;
_pos += missing;
inputLength -= missing;
}
}
return rc;
}
std::streamsize RSADecryptImpl::finalize(
unsigned char* output,
std::streamsize length)
{
poco_assert (length >= blockSize());
int rc = 0;
if (_pos > 0)
{
rc = RSA_private_decrypt(_pos, _pBuf, output, const_cast<RSA*>(_pRSA), RSA_PKCS1_PADDING);
if (rc == -1)
throwError();
}
return rc;
}
RSACipherImpl::RSACipherImpl(const RSAKey& key):
_key(key)
{
}
RSACipherImpl::~RSACipherImpl()
{
}
CryptoTransform* RSACipherImpl::createEncryptor()
{
return new RSAEncryptImpl(_key.impl()->getRSA());
}
CryptoTransform* RSACipherImpl::createDecryptor()
{
return new RSADecryptImpl(_key.impl()->getRSA());
}
} } // namespace Poco::Crypto

View File

@ -0,0 +1,106 @@
//
// RSADigestEngine.cpp
//
// $Id: //poco/Main/Crypto/src/RSADigestEngine.cpp#2 $
//
// Library: Crypto
// Package: CryptoCore
// Module: RSADigestEngine
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Crypto/RSADigestEngine.h"
#include <openssl/pem.h>
namespace Poco {
namespace Crypto {
RSADigestEngine::RSADigestEngine(const RSAKey& key):
_key(key),
_sig(),
_sha1()
{
_sig = DigestEngine::Digest(key.size());
}
RSADigestEngine::~RSADigestEngine()
{
}
unsigned RSADigestEngine::digestLength() const
{
return _sha1.digestLength();
}
void RSADigestEngine::reset()
{
_sha1.reset();
_sig = DigestEngine::Digest(_key.size());
}
const DigestEngine::Digest& RSADigestEngine::digest()
{
return _sha1.digest();
}
const DigestEngine::Digest& RSADigestEngine::signature()
{
const DigestEngine::Digest& digest = _sha1.digest();
unsigned int sigLen = _sig.size();
RSA_sign(NID_sha1, &digest[0], (unsigned int)digest.size(), &_sig[0], &sigLen, _key.impl()->getRSA());
// truncate _sig to sigLen
if (sigLen < _sig.size())
_sig.resize(sigLen);
return _sig;
}
void RSADigestEngine::verify(const DigestEngine::Digest& sig)
{
const DigestEngine::Digest& digest = _sha1.digest();
DigestEngine::Digest sigCpy = sig; // copy becausse RSA_verify can modify sigCpy
int ret = RSA_verify(NID_sha1, &digest[0], (unsigned int)digest.size(), &sigCpy[0], (unsigned int)sigCpy.size(), _key.impl()->getRSA());
if (ret == 0)
throw Poco::DataFormatException("Signature does not match");
}
void RSADigestEngine::updateImpl(const void* data, unsigned length)
{
_sha1.update(data, length);
}
} } // namespace Poco::Crypto

105
Crypto/src/RSAKey.cpp Normal file
View File

@ -0,0 +1,105 @@
//
// RSAKey.cpp
//
// $Id: //poco/Main/Crypto/src/RSAKey.cpp#3 $
//
// Library: Crypto
// Package: CryptoCore
// Module: RSAKey
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Crypto/RSAKey.h"
#include <openssl/rsa.h>
namespace Poco {
namespace Crypto {
RSAKey::RSAKey(const Poco::Net::X509Certificate& cert):
_pImpl(new RSAKeyImpl(cert))
{
}
RSAKey::RSAKey(KeyLength keyLength, Exponent exp):
_pImpl(0)
{
int keyLen = keyLength;
unsigned long expVal = RSA_3;
if (expVal == EXP_LARGE)
expVal = RSA_F4;
_pImpl = new RSAKeyImpl(keyLen, expVal);
}
RSAKey::RSAKey(const std::string& publicKey, const std::string& privateKeyFile, const std::string& pwd):
_pImpl(new RSAKeyImpl(publicKey, privateKeyFile, pwd))
{
}
RSAKey::RSAKey(std::istream* pPubKey,
std::istream* pPrivKey,
const std::string& privateKeyPwd):
_pImpl(new RSAKeyImpl(pPubKey, pPrivKey, privateKeyPwd))
{
}
RSAKey::~RSAKey()
{
}
int RSAKey::size() const
{
return _pImpl->size();
}
void RSAKey::save(const std::string& pubKeyFile, const std::string& privKeyFile, const std::string& privKeyPwd)
{
_pImpl->save(pubKeyFile, privKeyFile, privKeyPwd);
}
void RSAKey::save(std::ostream* pPubKey, std::ostream* pPrivKey, const std::string& privateKeyPwd)
{
_pImpl->save(pPubKey, pPrivKey, privateKeyPwd);
}
const std::string& RSAKey::name() const
{
static const std::string n("rsa");
return n;
}
} } // namespace Poco::Crypto

272
Crypto/src/RSAKeyImpl.cpp Normal file
View File

@ -0,0 +1,272 @@
//
// RSAKeyImpl.cpp
//
// $Id: //poco/Main/Crypto/src/RSAKeyImpl.cpp#2 $
//
// Library: Crypto
// Package: CryptoCore
// Module: RSAKeyImpl
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Crypto/RSAKeyImpl.h"
#include "Poco/FileStream.h"
#include "Poco/StreamCopier.h"
#include "Poco/TemporaryFile.h"
#include "Poco/Net/SSLManager.h"
#include "Poco/Net/X509Certificate.h"
#include <openssl/pem.h>
#include <openssl/rsa.h>
namespace Poco {
namespace Crypto {
RSAKeyImpl::RSAKeyImpl(const Poco::Net::X509Certificate& cert):
_pRSA(0)
{
const X509* pCert = cert.certificate();
EVP_PKEY* pKey = X509_get_pubkey(const_cast<X509*>(pCert));
RSA* pRSA = pKey->pkey.rsa;
_pRSA = RSAPublicKey_dup(pRSA);
}
RSAKeyImpl::RSAKeyImpl(int keyLength, unsigned long exponent):
_pRSA(0)
{
//dummy access to SSLMananger so that the SSLInitializer of NetSSL gets called!
Poco::Net::SSLManager::instance();
_pRSA = RSA_new();
int ret = 0;
BIGNUM *bn = 0;
try
{
bn = BN_new();
BN_set_word(bn, exponent);
ret = RSA_generate_key_ex(_pRSA, keyLength, bn, 0);
BN_free(bn);
}
catch(...)
{
BN_free(bn);
throw;
}
if (!ret)
throw Poco::InvalidArgumentException("Failed to create RSA context");
}
RSAKeyImpl::RSAKeyImpl(
const std::string& publicKey,
const std::string& privateKeyFile,
const std::string& privateKeyPwd):
_pRSA(0)
{
//dummy access to SSLMananger so that the SSLInitializer of NetSSL gets called!
Poco::Net::SSLManager::instance();
init(publicKey, privateKeyFile, privateKeyPwd);
}
RSAKeyImpl::RSAKeyImpl(std::istream* pubKey, std::istream* privKey, const std::string& privKeyPwd):
_pRSA(0)
{
//dummy access to SSLMananger so that the SSLInitializer of NetSSL gets called!
Poco::Net::SSLManager::instance();
// due to C lib not supporting streams, we create two temporary files
std::string pubKeyFile;
Poco::TemporaryFile pubFile;
if (pubKey)
{
if (!pubFile.createFile())
throw Poco::FileException("No temporary file could be created for public file!");
pubKeyFile = pubFile.path();
Poco::FileOutputStream fout(pubKeyFile);
Poco::StreamCopier::copyStream(*pubKey, fout);
}
std::string privKeyFile;
Poco::TemporaryFile privFile;
if (privKey)
{
if (!privFile.createFile())
throw Poco::FileException("No temporary file could be created for private file!");
privKeyFile = privFile.path();
Poco::FileOutputStream fout(privKeyFile);
Poco::StreamCopier::copyStream(*privKey, fout);
}
init(pubKeyFile, privKeyFile, privKeyPwd);
}
void RSAKeyImpl::init(const std::string& pubKeyFile, const std::string& privKeyFile, const std::string& privKeyPwd)
{
poco_assert_dbg(_pRSA == 0);
_pRSA = RSA_new();
if (!pubKeyFile.empty())
{
BIO *out=BIO_new(BIO_s_file());
const char* pFN = pubKeyFile.c_str();
BIO_read_filename(out, (void*)pFN);
if (out)
{
RSA* pubKey = PEM_read_bio_RSAPublicKey(out, &_pRSA, 0, 0);
BIO_free(out);
if (!pubKey)
{
freeRSA();
throw Poco::FileException("Failed to load public key: " + pubKeyFile);
}
}
else
{
freeRSA();
throw Poco::FileNotFoundException("Public key file not found: " + pubKeyFile);
}
}
if (!privKeyFile.empty())
{
BIO* out=BIO_new(BIO_s_file());
const char* pFN = privKeyFile.c_str();
BIO_read_filename(out, (void*)pFN);
if (out)
{
RSA* privKey = 0;
if (privKeyPwd.empty())
privKey = PEM_read_bio_RSAPrivateKey(out, &_pRSA, 0, 0);
else
privKey = PEM_read_bio_RSAPrivateKey(out, &_pRSA, 0, (void*)privKeyPwd.c_str());
BIO_free(out);
if (!privKey)
{
freeRSA();
throw Poco::FileException("Failed to load private key: " + privKeyFile);
}
}
else
{
freeRSA();
throw Poco::FileNotFoundException("Private key file not found: " + privKeyFile);
}
}
}
RSAKeyImpl::~RSAKeyImpl()
{
}
void RSAKeyImpl::freeRSA()
{
if (_pRSA)
RSA_free(_pRSA);
_pRSA = 0;
}
int RSAKeyImpl::size() const
{
return RSA_size(_pRSA);
}
void RSAKeyImpl::save(const std::string& pubKeyFile, const std::string& privKeyFile, const std::string& privKeyPwd)
{
if (!pubKeyFile.empty())
{
BIO *out=BIO_new(BIO_s_file());
const char* pFN = pubKeyFile.c_str();
BIO_write_filename(out, (void*)pFN);
if (!PEM_write_bio_RSAPublicKey(out,_pRSA))
throw Poco::FileException("Failed to write public key to file:" + pubKeyFile);
BIO_free(out);
}
if (!privKeyFile.empty())
{
BIO *out=BIO_new(BIO_s_file());
const char* pFN = privKeyFile.c_str();
BIO_write_filename(out, (void*)pFN);
int ret = 0;
if (privKeyPwd.empty())
ret = PEM_write_bio_RSAPrivateKey(out, _pRSA, EVP_des_ede3_cbc(), 0, 0, 0, 0);
else
ret = PEM_write_bio_RSAPrivateKey(out, _pRSA, EVP_des_ede3_cbc(), (unsigned char *)privKeyPwd.c_str(), privKeyPwd.length(), 0, 0);
if (!ret)
throw Poco::FileException("Failed to write private key to file:" + privKeyFile);
BIO_free(out);
}
}
void RSAKeyImpl::save(std::ostream* pPubKey, std::ostream* pPrivKey, const std::string& privateKeyPwd)
{
if (!pPubKey && !pPrivKey)
return;
// due to C lib not supporting streams, we create two temporary files
std::string pubKeyFile;
Poco::TemporaryFile pubFile;
if (pPubKey)
{
pubKeyFile = pubFile.path();
if (!pubFile.createFile())
throw Poco::FileException("No temporary file could be created for public file!");
}
std::string privKeyFile;
Poco::TemporaryFile privFile;
if (pPrivKey)
{
if (!privFile.createFile())
throw Poco::FileException("No temporary file could be created for private file!");
privKeyFile = privFile.path();
}
save(pubKeyFile, privKeyFile, privateKeyPwd);
// now copy everything from the temp files to the original streams
if (pPubKey)
{
Poco::FileInputStream fPub(pubKeyFile);
Poco::StreamCopier::copyStream(fPub, *pPubKey);
}
if (pPrivKey)
{
Poco::FileInputStream fPriv(privKeyFile);
Poco::StreamCopier::copyStream(fPriv, *pPrivKey);
}
}
} } // namespace Poco::Crypto

18
Crypto/testsuite/Makefile Normal file
View File

@ -0,0 +1,18 @@
#
# Makefile
#
# $Id: //poco/Main/Crypto/testsuite/Makefile#1 $
#
# Makefile for Poco Crypto testsuite
#
include $(POCO_BASE)/build/rules/global
objects = CryptoTestSuite Driver \
CryptoTest RSATest
target = testrunner
target_version = 1
target_libs = PocoCrypto PocoFoundation CppUnit
include $(POCO_BASE)/build/rules/exec

View File

@ -0,0 +1,191 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="TestSuite"
ProjectGUID="{c1b1bb96-5198-48eb-ab48-9a0a0b54fb15}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared"
ConfigurationType="1"
UseOfMFC="2"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\include;..\..\Foundation\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;..\..\NetSSL_OpenSSL\include;..\..\Net\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
BufferSecurityCheck="TRUE"
TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="TRUE"
RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="CppUnitd.lib WinTestRunnerd.lib PocoFoundationd.lib "
OutputFile="bin/TestSuited.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\lib"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="bin/TestSuited.pdb"
SubSystem="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="release_shared|Win32"
OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared"
ConfigurationType="1"
UseOfMFC="2"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="4"
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="TRUE"
FavorSizeOrSpeed="1"
OmitFramePointers="TRUE"
OptimizeForWindowsApplication="TRUE"
AdditionalIncludeDirectories="..\include;..\..\Foundation\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;..\..\NetSSL_OpenSSL\include;..\..\Net\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
StringPooling="TRUE"
RuntimeLibrary="2"
BufferSecurityCheck="FALSE"
TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="TRUE"
RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="CppUnit.lib WinTestRunner.lib PocoFoundation.lib"
OutputFile="bin/TestSuite.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\lib"
GenerateDebugInformation="FALSE"
ProgramDatabaseFile=""
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Crypto"
Filter="">
<Filter
Name="Header Files"
Filter="">
<File
RelativePath=".\src\CryptoTest.h">
</File>
<File
RelativePath=".\src\RSATest.h">
</File>
</Filter>
<Filter
Name="Source Files"
Filter="">
<File
RelativePath=".\src\CryptoTest.cpp">
</File>
<File
RelativePath=".\src\RSATest.cpp">
</File>
</Filter>
</Filter>
<Filter
Name="_Suite"
Filter="">
<Filter
Name="Header Files"
Filter="">
<File
RelativePath=".\src\CryptoTestSuite.h">
</File>
</Filter>
<Filter
Name="Source Files"
Filter="">
<File
RelativePath=".\src\CryptoTestSuite.cpp">
</File>
</Filter>
</Filter>
<Filter
Name="_Driver"
Filter="">
<Filter
Name="Source Files"
Filter="">
<File
RelativePath=".\src\WinDriver.cpp">
</File>
</Filter>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,259 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Name="TestSuite"
ProjectGUID="{C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared"
ConfigurationType="1"
UseOfMFC="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\include;..\..\Foundation\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;..\..\NetSSL_OpenSSL\include;..\..\Net\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
BufferSecurityCheck="true"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="CppUnitd.lib WinTestRunnerd.lib PocoFoundationd.lib "
OutputFile="bin/TestSuited.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\lib"
GenerateDebugInformation="true"
ProgramDatabaseFile="bin/TestSuited.pdb"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="release_shared|Win32"
OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared"
ConfigurationType="1"
UseOfMFC="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="4"
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories="..\include;..\..\Foundation\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;..\..\NetSSL_OpenSSL\include;..\..\Net\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
StringPooling="true"
RuntimeLibrary="2"
BufferSecurityCheck="false"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="CppUnit.lib WinTestRunner.lib PocoFoundation.lib"
OutputFile="bin/TestSuite.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\lib"
GenerateDebugInformation="false"
ProgramDatabaseFile=""
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Crypto"
>
<Filter
Name="Header Files"
>
<File
RelativePath=".\src\CryptoTest.h"
>
</File>
<File
RelativePath=".\src\RSATest.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\CryptoTest.cpp"
>
</File>
<File
RelativePath=".\src\RSATest.cpp"
>
</File>
</Filter>
</Filter>
<Filter
Name="_Suite"
>
<Filter
Name="Header Files"
>
<File
RelativePath=".\src\CryptoTestSuite.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\CryptoTestSuite.cpp"
>
</File>
</Filter>
</Filter>
<Filter
Name="_Driver"
>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\WinDriver.cpp"
>
</File>
</Filter>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,258 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Name="TestSuite"
ProjectGUID="{c1b1bb96-5198-48eb-ab48-9a0a0b54fb15}"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared"
ConfigurationType="1"
UseOfMFC="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\include;..\..\Foundation\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;..\..\NetSSL_OpenSSL\include;..\..\Net\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
BufferSecurityCheck="true"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="CppUnitd.lib WinTestRunnerd.lib PocoFoundationd.lib "
OutputFile="bin/TestSuited.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\lib"
GenerateDebugInformation="true"
ProgramDatabaseFile="bin/TestSuited.pdb"
SubSystem="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="release_shared|Win32"
OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared"
ConfigurationType="1"
UseOfMFC="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="4"
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories="..\include;..\..\Foundation\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;..\..\NetSSL_OpenSSL\include;..\..\Net\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
StringPooling="true"
RuntimeLibrary="2"
BufferSecurityCheck="false"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="CppUnit.lib WinTestRunner.lib PocoFoundation.lib"
OutputFile="bin/TestSuite.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\lib"
GenerateDebugInformation="false"
ProgramDatabaseFile=""
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Crypto"
>
<Filter
Name="Header Files"
>
<File
RelativePath=".\src\CryptoTest.h"
>
</File>
<File
RelativePath=".\src\RSATest.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\CryptoTest.cpp"
>
</File>
<File
RelativePath=".\src\RSATest.cpp"
>
</File>
</Filter>
</Filter>
<Filter
Name="_Suite"
>
<Filter
Name="Header Files"
>
<File
RelativePath=".\src\CryptoTestSuite.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\CryptoTestSuite.cpp"
>
</File>
</Filter>
</Filter>
<Filter
Name="_Driver"
>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\WinDriver.cpp"
>
</File>
</Filter>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,97 @@
//
// CryptoTest.cpp
//
// $Id: //poco/Main/Crypto/testsuite/src/CryptoTest.cpp#2 $
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "CryptoTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/Crypto/CipherFactory.h"
#include "Poco/Crypto/Cipher.h"
#include "Poco/Crypto/CipherKey.h"
using namespace Poco::Crypto;
CryptoTest::CryptoTest(const std::string& name): CppUnit::TestCase(name)
{
}
CryptoTest::~CryptoTest()
{
}
void CryptoTest::testEncoding()
{
Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(CipherKey("aes256"));
std::string in("1234567890");
std::string out = pCipher->encryptString(in, Cipher::ENC_BASE64);
std::string result = pCipher->decryptString(out, Cipher::ENC_BASE64);
poco_assert (in == result);
}
void CryptoTest::testEncoding2()
{
Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(CipherKey("aes256", "simplepwd", "Too much salt"));
std::string in("1234567890");
std::string out = pCipher->encryptString(in, Cipher::ENC_BASE64);
Cipher::Ptr pCipher2 = CipherFactory::defaultFactory().createCipher(CipherKey("aes256", "simplepwd", "Too much salt"));
std::string result = pCipher2->decryptString(out, Cipher::ENC_BASE64);
poco_assert (in == result);
}
void CryptoTest::setUp()
{
}
void CryptoTest::tearDown()
{
}
CppUnit::Test* CryptoTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("CryptoTest");
CppUnit_addTest(pSuite, CryptoTest, testEncoding);
CppUnit_addTest(pSuite, CryptoTest, testEncoding2);
return pSuite;
}

View File

@ -0,0 +1,61 @@
//
// CryptoTest.h
//
// $Id: //poco/Main/Crypto/testsuite/src/CryptoTest.h#1 $
//
// Definition of the CryptoTest class.
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef CryptoTest_INCLUDED
#define CryptoTest_INCLUDED
#include "Poco/Crypto/Crypto.h"
#include "CppUnit/TestCase.h"
class CryptoTest: public CppUnit::TestCase
{
public:
CryptoTest(const std::string& name);
~CryptoTest();
void testEncoding();
void testEncoding2();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // CryptoTest_INCLUDED

View File

@ -0,0 +1,46 @@
//
// CryptoTestSuite.cpp
//
// $Id: //poco/Main/Crypto/testsuite/src/CryptoTestSuite.cpp#1 $
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "CryptoTestSuite.h"
#include "CryptoTest.h"
#include "RSATest.h"
CppUnit::Test* CryptoTestSuite::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("CryptoTestSuite");
pSuite->addTest(CryptoTest::suite());
pSuite->addTest(RSATest::suite());
return pSuite;
}

View File

@ -0,0 +1,49 @@
//
// CryptoTestSuite.h
//
// $Id: //poco/Main/Crypto/testsuite/src/CryptoTestSuite.h#1 $
//
// Definition of the CryptoTestSuite class.
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef CryptoTestSuite_INCLUDED
#define CryptoTestSuite_INCLUDED
#include "CppUnit/TestSuite.h"
class CryptoTestSuite
{
public:
static CppUnit::Test* suite();
};
#endif // CryptoTestSuite_INCLUDED

View File

@ -0,0 +1,39 @@
//
// Driver.cpp
//
// $Id: //poco/Main/Crypto/testsuite/src/Driver.cpp#1 $
//
// Console-based test driver for Poco Crypto.
//
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "CppUnit/TestRunner.h"
#include "CryptoTestSuite.h"
CppUnitMain(CryptoTestSuite)

View File

@ -0,0 +1,186 @@
//
// RSATest.cpp
//
// $Id: //poco/Main/Crypto/testsuite/src/RSATest.cpp#3 $
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "RSATest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/Crypto/RSADigestEngine.h"
#include "Poco/Crypto/CipherFactory.h"
#include "Poco/Crypto/Cipher.h"
#include "Poco/Net/X509Certificate.h"
#include "Poco/Net/Context.h"
#include <sstream>
using namespace Poco::Crypto;
using namespace Poco::Net;
RSATest::RSATest(const std::string& name): CppUnit::TestCase(name)
{
}
RSATest::~RSATest()
{
}
void RSATest::testNewKeys()
{
RSAKey key(RSAKey::KL_1024, RSAKey::EXP_SMALL);
std::ostringstream strPub;
std::ostringstream strPriv;
key.save(&strPub, &strPriv, "testpwd");
std::string pubKey = strPub.str();
std::string privKey = strPriv.str();
//now do the round trip
std::istringstream iPub(pubKey);
std::istringstream iPriv(privKey);
RSAKey key2(&iPub, &iPriv, "testpwd");
std::istringstream iPriv2(privKey);
RSAKey key3(0, &iPriv2, "testpwd");
std::ostringstream strPub3;
key3.save(&strPub3);
std::string pubFromPrivate = strPub3.str();
assert (pubFromPrivate == pubKey);
}
void RSATest::testSign()
{
std::string msg("Test this sign message");
RSAKey key(RSAKey::KL_2048, RSAKey::EXP_LARGE);
RSADigestEngine eng(key);
eng.update(msg.c_str(), msg.length());
const Poco::DigestEngine::Digest& sig = eng.signature();
std::string hexDig = Poco::DigestEngine::digestToHex(sig);
//verify
std::ostringstream strPub;
key.save(&strPub);
std::string pubKey = strPub.str();
std::istringstream iPub(pubKey);
RSAKey keyPub(&iPub);
RSADigestEngine eng2(key);
eng2.update(msg.c_str(), msg.length());
eng2.verify(sig);
}
void RSATest::testSignManipulated()
{
std::string msg("Test this sign message");
std::string msgManip("Test that sign message");
RSAKey key(RSAKey::KL_2048, RSAKey::EXP_LARGE);
RSADigestEngine eng(key);
eng.update(msg.c_str(), msg.length());
const Poco::DigestEngine::Digest& sig = eng.signature();
std::string hexDig = Poco::DigestEngine::digestToHex(sig);
//verify
std::ostringstream strPub;
key.save(&strPub);
std::string pubKey = strPub.str();
std::istringstream iPub(pubKey);
RSAKey keyPub(&iPub);
RSADigestEngine eng2(key);
eng2.update(msgManip.c_str(), msgManip.length());
try
{
eng2.verify(sig);
fail("must fail");
}
catch(Poco::DataFormatException&)
{
}
}
void RSATest::createRSACipher()
{
Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(RSAKey(RSAKey::KL_1024,RSAKey::EXP_SMALL));
std::string val("lets do some encryption");
std::string enc = pCipher->encryptString(val);
std::string dec = pCipher->decryptString(enc);
assert (dec == val);
}
void RSATest::createRSACipherLarge()
{
Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(RSAKey(RSAKey::KL_1024,RSAKey::EXP_SMALL));
std::string val(16385, 'x');
std::string enc = pCipher->encryptString(val);
std::string dec = pCipher->decryptString(enc);
assert (dec == val);
}
void RSATest::testCertificate()
{
X509Certificate cert("any.pem");
Context::Ptr pContext(new Context("", "", false));
bool ok = cert.verify("www.appinf.com", pContext);
RSAKey key(cert);
Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(key);
std::string val("lets do some encryption");
std::string enc = pCipher->encryptString(val);
}
void RSATest::setUp()
{
}
void RSATest::tearDown()
{
}
CppUnit::Test* RSATest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("RSATest");
CppUnit_addTest(pSuite, RSATest, testNewKeys);
CppUnit_addTest(pSuite, RSATest, testSign);
CppUnit_addTest(pSuite, RSATest, testSignManipulated);
CppUnit_addTest(pSuite, RSATest, createRSACipher);
CppUnit_addTest(pSuite, RSATest, createRSACipherLarge);
CppUnit_addTest(pSuite, RSATest, testCertificate);
return pSuite;
}

View File

@ -0,0 +1,65 @@
//
// RSATest.h
//
// $Id: //poco/Main/Crypto/testsuite/src/RSATest.h#3 $
//
// Definition of the RSATest class.
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef RSATest_INCLUDED
#define RSATest_INCLUDED
#include "Poco/Crypto/Crypto.h"
#include "CppUnit/TestCase.h"
class RSATest: public CppUnit::TestCase
{
public:
RSATest(const std::string& name);
~RSATest();
void testNewKeys();
void testSign();
void testSignManipulated();
void createRSACipher();
void createRSACipherLarge();
void testCertificate();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // RSATest_INCLUDED

View File

@ -0,0 +1,50 @@
//
// WinDriver.cpp
//
// $Id: //poco/Main/Crypto/testsuite/src/WinDriver.cpp#1 $
//
// Windows test driver for Poco Crypto.
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "WinTestRunner/WinTestRunner.h"
#include "CryptoTestSuite.h"
class TestDriver: public CppUnit::WinTestRunnerApp
{
void TestMain()
{
CppUnit::WinTestRunner runner;
runner.addTest(CryptoTestSuite::suite());
runner.run();
}
};
TestDriver theDriver;

Binary file not shown.

View File

@ -37,7 +37,7 @@
// Categories
//
//
// Values are 32 bit values layed out as follows:
// Values are 32 bit values laid out as follows:
//
// 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
@ -77,7 +77,7 @@
//
// MessageText:
//
// Fatal
// Fatal
//
#define POCO_CTG_FATAL 0x00000001L
@ -86,7 +86,7 @@
//
// MessageText:
//
// Critical
// Critical
//
#define POCO_CTG_CRITICAL 0x00000002L
@ -95,7 +95,7 @@
//
// MessageText:
//
// Error
// Error
//
#define POCO_CTG_ERROR 0x00000003L
@ -104,7 +104,7 @@
//
// MessageText:
//
// Warning
// Warning
//
#define POCO_CTG_WARNING 0x00000004L
@ -113,7 +113,7 @@
//
// MessageText:
//
// Notice
// Notice
//
#define POCO_CTG_NOTICE 0x00000005L
@ -122,7 +122,7 @@
//
// MessageText:
//
// Information
// Information
//
#define POCO_CTG_INFORMATION 0x00000006L
@ -131,7 +131,7 @@
//
// MessageText:
//
// Debug
// Debug
//
#define POCO_CTG_DEBUG 0x00000007L
@ -140,7 +140,7 @@
//
// MessageText:
//
// Trace
// Trace
//
#define POCO_CTG_TRACE 0x00000008L
@ -152,7 +152,7 @@
//
// MessageText:
//
// %1
// %1
//
#define POCO_MSG_LOG 0x00001000L

View File

@ -1,2 +1,2 @@
LANGUAGE 0x9,0x1
1 11 MSG00001.bin
1 11 "MSG00001.bin"

Binary file not shown.