diff --git a/Crypto/Crypto_vs100.sln b/Crypto/Crypto_vs100.sln
new file mode 100644
index 000000000..b80a755b9
--- /dev/null
+++ b/Crypto/Crypto_vs100.sln
@@ -0,0 +1,60 @@
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Crypto", "Crypto_vs100.vcxproj", "{EEEE7259-32E9-4D56-B023-C733940AB2A0}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestSuite", "testsuite\TestSuite_vs100.vcxproj", "{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
+ debug_static_mt|Win32 = debug_static_mt|Win32
+ release_static_mt|Win32 = release_static_mt|Win32
+ debug_static_md|Win32 = debug_static_md|Win32
+ release_static_md|Win32 = release_static_md|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}.debug_shared|Win32.Deploy.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
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.release_shared|Win32.Deploy.0 = release_shared|Win32
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.debug_static_mt|Win32.ActiveCfg = debug_static_mt|Win32
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.debug_static_mt|Win32.Build.0 = debug_static_mt|Win32
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.debug_static_mt|Win32.Deploy.0 = debug_static_mt|Win32
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.release_static_mt|Win32.ActiveCfg = release_static_mt|Win32
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.release_static_mt|Win32.Build.0 = release_static_mt|Win32
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.release_static_mt|Win32.Deploy.0 = release_static_mt|Win32
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.debug_static_md|Win32.ActiveCfg = debug_static_md|Win32
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.debug_static_md|Win32.Build.0 = debug_static_md|Win32
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.debug_static_md|Win32.Deploy.0 = debug_static_md|Win32
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.release_static_md|Win32.ActiveCfg = release_static_md|Win32
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.release_static_md|Win32.Build.0 = release_static_md|Win32
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.release_static_md|Win32.Deploy.0 = release_static_md|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}.debug_shared|Win32.Deploy.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
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.release_shared|Win32.Deploy.0 = release_shared|Win32
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.debug_static_mt|Win32.ActiveCfg = debug_static_mt|Win32
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.debug_static_mt|Win32.Build.0 = debug_static_mt|Win32
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.debug_static_mt|Win32.Deploy.0 = debug_static_mt|Win32
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.release_static_mt|Win32.ActiveCfg = release_static_mt|Win32
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.release_static_mt|Win32.Build.0 = release_static_mt|Win32
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.release_static_mt|Win32.Deploy.0 = release_static_mt|Win32
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.debug_static_md|Win32.ActiveCfg = debug_static_md|Win32
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.debug_static_md|Win32.Build.0 = debug_static_md|Win32
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.debug_static_md|Win32.Deploy.0 = debug_static_md|Win32
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.release_static_md|Win32.ActiveCfg = release_static_md|Win32
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.release_static_md|Win32.Build.0 = release_static_md|Win32
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.release_static_md|Win32.Deploy.0 = release_static_md|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/Crypto/Crypto_vs100.vcxproj b/Crypto/Crypto_vs100.vcxproj
new file mode 100644
index 000000000..242803ff6
--- /dev/null
+++ b/Crypto/Crypto_vs100.vcxproj
@@ -0,0 +1,302 @@
+
+
+
+
+ debug_shared
+ Win32
+
+
+ debug_static_md
+ Win32
+
+
+ debug_static_mt
+ Win32
+
+
+ release_shared
+ Win32
+
+
+ release_static_md
+ Win32
+
+
+ release_static_mt
+ Win32
+
+
+
+ Crypto
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}
+ Crypto
+ Win32Proj
+
+
+
+ StaticLibrary
+ MultiByte
+
+
+ StaticLibrary
+ MultiByte
+
+
+ StaticLibrary
+ MultiByte
+
+
+ StaticLibrary
+ MultiByte
+
+
+ DynamicLibrary
+ MultiByte
+
+
+ DynamicLibrary
+ MultiByte
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <_ProjectFileVersion>10.0.30319.1
+ ..\bin\
+ obj\$(Configuration)\
+ true
+ ..\bin\
+ obj\$(Configuration)\
+ false
+ ..\lib\
+ obj\$(Configuration)\
+ ..\lib\
+ obj\$(Configuration)\
+ ..\lib\
+ obj\$(Configuration)\
+ ..\lib\
+ obj\$(Configuration)\
+ PocoCryptod
+ PocoCryptomdd
+ PocoCryptomtd
+ PocoCrypto
+ PocoCryptomd
+ PocoCryptomt
+
+
+
+ Disabled
+ .\include;..\Foundation\include;%(AdditionalIncludeDirectories)
+ WIN32;_DEBUG;_WINDOWS;_USRDLL;Crypto_EXPORTS;%(PreprocessorDefinitions)
+ true
+ true
+ EnableFastChecks
+ MultiThreadedDebugDLL
+ true
+ true
+ true
+ true
+
+ Level3
+ EditAndContinue
+ Default
+ %(DisableSpecificWarnings)
+
+
+ ws2_32.lib;iphlpapi.lib;libeay32mdd.lib;ssleay32mdd.lib;%(AdditionalDependencies)
+ ..\bin\PocoCryptod.dll
+ true
+ true
+ ..\bin\PocoCryptod.pdb
+ ..\lib;%(AdditionalLibraryDirectories)
+ Console
+ ..\lib\PocoCryptod.lib
+ MachineX86
+
+
+
+
+ Disabled
+ OnlyExplicitInline
+ true
+ Speed
+ true
+ .\include;..\Foundation\include;%(AdditionalIncludeDirectories)
+ WIN32;NDEBUG;_WINDOWS;_USRDLL;Crypto_EXPORTS;%(PreprocessorDefinitions)
+ true
+ MultiThreadedDLL
+ false
+ true
+ true
+ true
+
+ Level3
+
+ Default
+ %(DisableSpecificWarnings)
+
+
+ ws2_32.lib;iphlpapi.lib;libeay32md.lib;ssleay32md.lib;%(AdditionalDependencies)
+ ..\bin\PocoCrypto.dll
+ true
+ false
+ ..\lib;%(AdditionalLibraryDirectories)
+ Console
+ true
+ true
+ ..\lib\PocoCrypto.lib
+ MachineX86
+
+
+
+
+ Disabled
+ .\include;..\Foundation\include;%(AdditionalIncludeDirectories)
+ WIN32;_DEBUG;_WINDOWS;POCO_STATIC;%(PreprocessorDefinitions)
+ true
+ true
+ EnableFastChecks
+ MultiThreadedDebug
+ true
+ true
+ true
+ true
+
+ ..\lib\PocoCryptomtd.pdb
+ Level3
+ EditAndContinue
+ Default
+ %(DisableSpecificWarnings)
+
+
+ ..\lib\PocoCryptomtd.lib
+
+
+
+
+ Disabled
+ OnlyExplicitInline
+ true
+ Speed
+ true
+ .\include;..\Foundation\include;%(AdditionalIncludeDirectories)
+ WIN32;NDEBUG;_WINDOWS;POCO_STATIC;%(PreprocessorDefinitions)
+ true
+ MultiThreaded
+ false
+ true
+ true
+ true
+
+ Level3
+
+ Default
+ %(DisableSpecificWarnings)
+
+
+ ..\lib\PocoCryptomt.lib
+
+
+
+
+ Disabled
+ .\include;..\Foundation\include;%(AdditionalIncludeDirectories)
+ WIN32;_DEBUG;_WINDOWS;POCO_STATIC;%(PreprocessorDefinitions)
+ true
+ true
+ EnableFastChecks
+ MultiThreadedDebugDLL
+ true
+ true
+ true
+ true
+
+ ..\lib\PocoCryptomdd.pdb
+ Level3
+ EditAndContinue
+ Default
+ %(DisableSpecificWarnings)
+
+
+ ..\lib\PocoCryptomdd.lib
+
+
+
+
+ Disabled
+ OnlyExplicitInline
+ true
+ Speed
+ true
+ .\include;..\Foundation\include;%(AdditionalIncludeDirectories)
+ WIN32;NDEBUG;_WINDOWS;POCO_STATIC;%(PreprocessorDefinitions)
+ true
+ MultiThreadedDLL
+ false
+ true
+ true
+ true
+
+ ..\lib\PocoCryptomd.pdb
+ Level3
+
+ Default
+ %(DisableSpecificWarnings)
+
+
+ ws2_32.lib;iphlpapi.lib;libeay32md.lib;ssleay32md.lib;%(AdditionalDependencies)
+ ..\lib\PocoCryptomd.lib
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Crypto/Crypto_vs100.vcxproj.filters b/Crypto/Crypto_vs100.vcxproj.filters
new file mode 100644
index 000000000..3416764fa
--- /dev/null
+++ b/Crypto/Crypto_vs100.vcxproj.filters
@@ -0,0 +1,126 @@
+
+
+
+
+ {494614b9-ff62-40c6-91bb-bee55822a32e}
+
+
+ {30fa87c2-b839-4e52-b062-de65113e61e6}
+
+
+ {9c8f63cf-3ed3-4862-aa28-ca44827a72fd}
+
+
+ {6e2c751b-f898-414c-91df-2e2e104e9d1c}
+
+
+ {e10faa98-897c-4f37-b917-ca21a0a19d70}
+
+
+ {18391081-1244-4748-9bb5-8c5051c06e3a}
+
+
+ {2489f73e-efa2-417c-8529-a381b58a8c4b}
+
+
+ {73afffe0-13d5-4f60-b6ba-f87ff4579693}
+
+
+ {be3fb73d-748e-48a5-8fe4-e08a86aa031a}
+
+
+ {9e89bb4f-2da8-4ba1-a29a-4a89016afa13}
+
+
+ {14d5d623-0dd2-4e61-be3a-6eebb5138c6e}
+
+
+ {953bd7b6-fa63-457d-a46f-f766e0a23659}
+
+
+
+
+ Cipher\Header Files
+
+
+ Cipher\Header Files
+
+
+ Cipher\Header Files
+
+
+ Cipher\Header Files
+
+
+ Cipher\Header Files
+
+
+ Cipher\Header Files
+
+
+ Cipher\Header Files
+
+
+ RSA\Header Files
+
+
+ RSA\Header Files
+
+
+ RSA\Header Files
+
+
+ RSA\Header Files
+
+
+ Certificate\Header Files
+
+
+ CryptoCore\Header Files
+
+
+ CryptoCore\Header Files
+
+
+
+
+ Cipher\Source Files
+
+
+ Cipher\Source Files
+
+
+ Cipher\Source Files
+
+
+ Cipher\Source Files
+
+
+ Cipher\Source Files
+
+
+ Cipher\Source Files
+
+
+ Cipher\Source Files
+
+
+ RSA\Source Files
+
+
+ RSA\Source Files
+
+
+ RSA\Source Files
+
+
+ RSA\Source Files
+
+
+ Certificate\Source Files
+
+
+ CryptoCore\Source Files
+
+
+
\ No newline at end of file
diff --git a/Crypto/Crypto_vs100.vcxproj.user b/Crypto/Crypto_vs100.vcxproj.user
new file mode 100644
index 000000000..ace9a86ac
--- /dev/null
+++ b/Crypto/Crypto_vs100.vcxproj.user
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/Crypto/Crypto_x64_vs100.sln b/Crypto/Crypto_x64_vs100.sln
new file mode 100644
index 000000000..e08df516b
--- /dev/null
+++ b/Crypto/Crypto_x64_vs100.sln
@@ -0,0 +1,60 @@
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Crypto", "Crypto_x64_vs100.vcxproj", "{EEEE7259-32E9-4D56-B023-C733940AB2A0}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestSuite", "testsuite\TestSuite_x64_vs100.vcxproj", "{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|x64 = debug_shared|x64
+ release_shared|x64 = release_shared|x64
+ debug_static_mt|x64 = debug_static_mt|x64
+ release_static_mt|x64 = release_static_mt|x64
+ debug_static_md|x64 = debug_static_md|x64
+ release_static_md|x64 = release_static_md|x64
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.debug_shared|x64.ActiveCfg = debug_shared|x64
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.debug_shared|x64.Build.0 = debug_shared|x64
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.debug_shared|x64.Deploy.0 = debug_shared|x64
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.release_shared|x64.ActiveCfg = release_shared|x64
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.release_shared|x64.Build.0 = release_shared|x64
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.release_shared|x64.Deploy.0 = release_shared|x64
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.debug_static_mt|x64.ActiveCfg = debug_static_mt|x64
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.debug_static_mt|x64.Build.0 = debug_static_mt|x64
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.debug_static_mt|x64.Deploy.0 = debug_static_mt|x64
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.release_static_mt|x64.ActiveCfg = release_static_mt|x64
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.release_static_mt|x64.Build.0 = release_static_mt|x64
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.release_static_mt|x64.Deploy.0 = release_static_mt|x64
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.debug_static_md|x64.ActiveCfg = debug_static_md|x64
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.debug_static_md|x64.Build.0 = debug_static_md|x64
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.debug_static_md|x64.Deploy.0 = debug_static_md|x64
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.release_static_md|x64.ActiveCfg = release_static_md|x64
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.release_static_md|x64.Build.0 = release_static_md|x64
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}.release_static_md|x64.Deploy.0 = release_static_md|x64
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.debug_shared|x64.ActiveCfg = debug_shared|x64
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.debug_shared|x64.Build.0 = debug_shared|x64
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.debug_shared|x64.Deploy.0 = debug_shared|x64
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.release_shared|x64.ActiveCfg = release_shared|x64
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.release_shared|x64.Build.0 = release_shared|x64
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.release_shared|x64.Deploy.0 = release_shared|x64
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.debug_static_mt|x64.ActiveCfg = debug_static_mt|x64
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.debug_static_mt|x64.Build.0 = debug_static_mt|x64
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.debug_static_mt|x64.Deploy.0 = debug_static_mt|x64
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.release_static_mt|x64.ActiveCfg = release_static_mt|x64
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.release_static_mt|x64.Build.0 = release_static_mt|x64
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.release_static_mt|x64.Deploy.0 = release_static_mt|x64
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.debug_static_md|x64.ActiveCfg = debug_static_md|x64
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.debug_static_md|x64.Build.0 = debug_static_md|x64
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.debug_static_md|x64.Deploy.0 = debug_static_md|x64
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.release_static_md|x64.ActiveCfg = release_static_md|x64
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.release_static_md|x64.Build.0 = release_static_md|x64
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}.release_static_md|x64.Deploy.0 = release_static_md|x64
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/Crypto/Crypto_x64_vs100.vcxproj b/Crypto/Crypto_x64_vs100.vcxproj
new file mode 100644
index 000000000..de327dfcb
--- /dev/null
+++ b/Crypto/Crypto_x64_vs100.vcxproj
@@ -0,0 +1,300 @@
+
+
+
+
+ debug_shared
+ x64
+
+
+ debug_static_md
+ x64
+
+
+ debug_static_mt
+ x64
+
+
+ release_shared
+ x64
+
+
+ release_static_md
+ x64
+
+
+ release_static_mt
+ x64
+
+
+
+ Crypto
+ {EEEE7259-32E9-4D56-B023-C733940AB2A0}
+ Crypto
+ Win32Proj
+
+
+
+ StaticLibrary
+ MultiByte
+
+
+ StaticLibrary
+ MultiByte
+
+
+ StaticLibrary
+ MultiByte
+
+
+ StaticLibrary
+ MultiByte
+
+
+ DynamicLibrary
+ MultiByte
+
+
+ DynamicLibrary
+ MultiByte
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <_ProjectFileVersion>10.0.30319.1
+ ..\bin64\
+ obj64\$(Configuration)\
+ true
+ ..\bin64\
+ obj64\$(Configuration)\
+ false
+ ..\lib64\
+ obj64\$(Configuration)\
+ ..\lib64\
+ obj64\$(Configuration)\
+ ..\lib64\
+ obj64\$(Configuration)\
+ ..\lib64\
+ obj64\$(Configuration)\
+ PocoCrypto64d
+ PocoCryptomdd
+ PocoCryptomtd
+ PocoCrypto64
+ PocoCryptomd
+ PocoCryptomt
+
+
+
+ Disabled
+ .\include;..\Foundation\include;%(AdditionalIncludeDirectories)
+ WIN32;_DEBUG;_WINDOWS;_USRDLL;Crypto_EXPORTS;%(PreprocessorDefinitions)
+ true
+ true
+ EnableFastChecks
+ MultiThreadedDebugDLL
+ true
+ true
+ true
+ true
+
+ Level3
+ ProgramDatabase
+ Default
+ %(DisableSpecificWarnings)
+
+
+ ws2_32.lib;iphlpapi.lib;libeay32mdd.lib;ssleay32mdd.lib;%(AdditionalDependencies)
+ ..\bin64\PocoCrypto64d.dll
+ true
+ true
+ ..\bin64\PocoCrypto64d.pdb
+ ..\lib64;%(AdditionalLibraryDirectories)
+ Console
+ ..\lib64\PocoCryptod.lib
+ MachineX64
+
+
+
+
+ Disabled
+ OnlyExplicitInline
+ true
+ Speed
+ true
+ .\include;..\Foundation\include;%(AdditionalIncludeDirectories)
+ WIN32;NDEBUG;_WINDOWS;_USRDLL;Crypto_EXPORTS;%(PreprocessorDefinitions)
+ true
+ MultiThreadedDLL
+ false
+ true
+ true
+ true
+
+ Level3
+
+ Default
+ %(DisableSpecificWarnings)
+
+
+ ws2_32.lib;iphlpapi.lib;libeay32md.lib;ssleay32md.lib;%(AdditionalDependencies)
+ ..\bin64\PocoCrypto64.dll
+ true
+ false
+ ..\lib64;%(AdditionalLibraryDirectories)
+ Console
+ true
+ true
+ ..\lib64\PocoCrypto.lib
+ MachineX64
+
+
+
+
+ Disabled
+ .\include;..\Foundation\include;%(AdditionalIncludeDirectories)
+ WIN32;_DEBUG;_WINDOWS;POCO_STATIC;%(PreprocessorDefinitions)
+ true
+ true
+ EnableFastChecks
+ MultiThreadedDebug
+ true
+ true
+ true
+ true
+
+ ..\lib64\PocoCryptomtd.pdb
+ Level3
+ ProgramDatabase
+ Default
+ %(DisableSpecificWarnings)
+
+
+ ..\lib64\PocoCryptomtd.lib
+
+
+
+
+ Disabled
+ OnlyExplicitInline
+ true
+ Speed
+ true
+ .\include;..\Foundation\include;%(AdditionalIncludeDirectories)
+ WIN32;NDEBUG;_WINDOWS;POCO_STATIC;%(PreprocessorDefinitions)
+ true
+ MultiThreaded
+ false
+ true
+ true
+ true
+
+ Level3
+
+ Default
+ %(DisableSpecificWarnings)
+
+
+ ..\lib64\PocoCryptomt.lib
+
+
+
+
+ Disabled
+ .\include;..\Foundation\include;%(AdditionalIncludeDirectories)
+ WIN32;_DEBUG;_WINDOWS;POCO_STATIC;%(PreprocessorDefinitions)
+ true
+ true
+ EnableFastChecks
+ MultiThreadedDebugDLL
+ true
+ true
+ true
+ true
+
+ ..\lib64\PocoCryptomdd.pdb
+ Level3
+ ProgramDatabase
+ Default
+ %(DisableSpecificWarnings)
+
+
+ ..\lib64\PocoCryptomdd.lib
+
+
+
+
+ Disabled
+ OnlyExplicitInline
+ true
+ Speed
+ true
+ .\include;..\Foundation\include;%(AdditionalIncludeDirectories)
+ WIN32;NDEBUG;_WINDOWS;POCO_STATIC;%(PreprocessorDefinitions)
+ true
+ MultiThreadedDLL
+ false
+ true
+ true
+ true
+
+ Level3
+
+ Default
+ %(DisableSpecificWarnings)
+
+
+ ..\lib64\PocoCryptomd.lib
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Crypto/Crypto_x64_vs100.vcxproj.filters b/Crypto/Crypto_x64_vs100.vcxproj.filters
new file mode 100644
index 000000000..264735bda
--- /dev/null
+++ b/Crypto/Crypto_x64_vs100.vcxproj.filters
@@ -0,0 +1,126 @@
+
+
+
+
+ {fb87242a-c5c9-427d-8c5b-ff7e973a09d2}
+
+
+ {29625e7a-4c64-4f46-a160-696f5df0bf0f}
+
+
+ {863b337e-7970-47a3-8c3a-ac7ca18fff1a}
+
+
+ {9bfb5ff5-db5b-4920-b1fa-4f670bb6ed15}
+
+
+ {987d81ee-3336-4a5c-9bda-1e58081dea22}
+
+
+ {7fd9a8fd-a722-4926-a7ed-3b4bc1bd51d3}
+
+
+ {8ac4a3ba-cfae-43d5-997d-c2a61fdfd88b}
+
+
+ {78a5514f-52e9-437f-98ac-c03037383c4a}
+
+
+ {e986f474-79c0-4f8e-aace-1fa5b5c8b609}
+
+
+ {0a48cb3b-08ac-4a8c-9197-1d02406f7e58}
+
+
+ {3ac5d95d-62d7-46c2-8acb-7e3b2b5e24f0}
+
+
+ {52c2a894-ba8f-4207-83c1-7c10309b15fc}
+
+
+
+
+ Cipher\Header Files
+
+
+ Cipher\Header Files
+
+
+ Cipher\Header Files
+
+
+ Cipher\Header Files
+
+
+ Cipher\Header Files
+
+
+ Cipher\Header Files
+
+
+ Cipher\Header Files
+
+
+ RSA\Header Files
+
+
+ RSA\Header Files
+
+
+ RSA\Header Files
+
+
+ RSA\Header Files
+
+
+ Certificate\Header Files
+
+
+ CryptoCore\Header Files
+
+
+ CryptoCore\Header Files
+
+
+
+
+ Cipher\Source Files
+
+
+ Cipher\Source Files
+
+
+ Cipher\Source Files
+
+
+ Cipher\Source Files
+
+
+ Cipher\Source Files
+
+
+ Cipher\Source Files
+
+
+ Cipher\Source Files
+
+
+ RSA\Source Files
+
+
+ RSA\Source Files
+
+
+ RSA\Source Files
+
+
+ RSA\Source Files
+
+
+ Certificate\Source Files
+
+
+ CryptoCore\Source Files
+
+
+
\ No newline at end of file
diff --git a/Crypto/Crypto_x64_vs100.vcxproj.user b/Crypto/Crypto_x64_vs100.vcxproj.user
new file mode 100644
index 000000000..ace9a86ac
--- /dev/null
+++ b/Crypto/Crypto_x64_vs100.vcxproj.user
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/Crypto/include/Poco/Crypto/Cipher.h b/Crypto/include/Poco/Crypto/Cipher.h
index 44c4f5f3b..3802121f9 100644
--- a/Crypto/include/Poco/Crypto/Cipher.h
+++ b/Crypto/include/Poco/Crypto/Cipher.h
@@ -112,9 +112,12 @@ public:
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
+ ENC_NONE = 0x00, /// Plain binary output
+ ENC_BASE64 = 0x01, /// Base64-encoded output
+ ENC_BINHEX = 0x02, /// BinHex-encoded output
+ ENC_BASE64_NO_LF = 0x81, /// Base64-encoded output, no linefeeds
+ ENC_BINHEX_NO_LF = 0x82, /// BinHex-encoded output, no linefeeds
+
};
virtual ~Cipher();
diff --git a/Crypto/include/Poco/Crypto/CipherFactory.h b/Crypto/include/Poco/Crypto/CipherFactory.h
index e4c20128e..080b3bb15 100644
--- a/Crypto/include/Poco/Crypto/CipherFactory.h
+++ b/Crypto/include/Poco/Crypto/CipherFactory.h
@@ -86,8 +86,6 @@ public:
/// Returns the default CipherFactory.
private:
- static int _instanceCount;
-
CipherFactory(const CipherFactory&);
CipherFactory& operator = (const CipherFactory&);
};
diff --git a/Crypto/include/Poco/Crypto/CipherImpl.h b/Crypto/include/Poco/Crypto/CipherImpl.h
index 706f4fd85..70ab556d7 100644
--- a/Crypto/include/Poco/Crypto/CipherImpl.h
+++ b/Crypto/include/Poco/Crypto/CipherImpl.h
@@ -1,90 +1,91 @@
-//
-// CipherImpl.h
-//
-// $Id: //poco/Main/Crypto/include/Poco/Crypto/CipherImpl.h#3 $
-//
-// Library: Crypto
-// Package: Cipher
-// 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
-
-
-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
+//
+// CipherImpl.h
+//
+// $Id: //poco/1.4/Crypto/include/Poco/Crypto/CipherImpl.h#1 $
+//
+// Library: Crypto
+// Package: Cipher
+// 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 "Poco/Crypto/OpenSSLInitializer.h"
+#include
+
+
+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;
+ OpenSSLInitializer _openSSLInitializer;
+};
+
+
+//
+// Inlines
+//
+inline const std::string& CipherImpl::name() const
+{
+ return _key.name();
+}
+
+
+} } // namespace Poco::Crypto
+
+
+#endif // Crypto_CipherImpl_INCLUDED
diff --git a/Crypto/include/Poco/Crypto/CipherKey.h b/Crypto/include/Poco/Crypto/CipherKey.h
index 9d2ce9799..28b502ff0 100644
--- a/Crypto/include/Poco/Crypto/CipherKey.h
+++ b/Crypto/include/Poco/Crypto/CipherKey.h
@@ -1,204 +1,204 @@
-//
-// CipherKey.h
-//
-// $Id: //poco/Main/Crypto/include/Poco/Crypto/CipherKey.h#2 $
-//
-// Library: Crypto
-// Package: Cipher
-// 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
- /// 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";
- /// std::string salt("asdff8723lasdf(**923412");
- /// 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 using the given
- /// cipher name, passphrase, salt value and iteration count.
-
- CipherKey(const std::string& name,
- const ByteVec& key,
- const ByteVec& iv);
- /// Creates a new CipherKeyImpl object using the given cipher
- /// name, key and initialization vector.
-
- CipherKey(const std::string& name);
- /// Creates a new CipherKeyImpl object. Autoinitializes key and
- /// initialization vector.
-
- ~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;
-};
-
-
-//
-// inlines
-//
-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
+//
+// CipherKey.h
+//
+// $Id: //poco/1.4/Crypto/include/Poco/Crypto/CipherKey.h#1 $
+//
+// Library: Crypto
+// Package: Cipher
+// 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
+ /// 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";
+ /// std::string salt("asdff8723lasdf(**923412");
+ /// 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 using the given
+ /// cipher name, passphrase, salt value and iteration count.
+
+ CipherKey(const std::string& name,
+ const ByteVec& key,
+ const ByteVec& iv);
+ /// Creates a new CipherKeyImpl object using the given cipher
+ /// name, key and initialization vector.
+
+ CipherKey(const std::string& name);
+ /// Creates a new CipherKeyImpl object. Autoinitializes key and
+ /// initialization vector.
+
+ ~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;
+};
+
+
+//
+// inlines
+//
+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
diff --git a/Crypto/include/Poco/Crypto/CipherKeyImpl.h b/Crypto/include/Poco/Crypto/CipherKeyImpl.h
index 859347a49..d3f9cb0ef 100644
--- a/Crypto/include/Poco/Crypto/CipherKeyImpl.h
+++ b/Crypto/include/Poco/Crypto/CipherKeyImpl.h
@@ -1,190 +1,192 @@
-//
-// CipherKeyImpl.h
-//
-// $Id: //poco/Main/Crypto/include/Poco/Crypto/CipherKeyImpl.h#2 $
-//
-// Library: Crypto
-// Package: Cipher
-// 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
-
-
-struct evp_cipher_st;
-typedef struct evp_cipher_st EVP_CIPHER;
-
-
-namespace Poco {
-namespace Crypto {
-
-
-class CipherKeyImpl: public RefCountedObject
- /// An implementation of the CipherKey class for OpenSSL's crypto library.
-{
-public:
- typedef std::vector ByteVec;
- typedef Poco::AutoPtr 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, using
- /// the given cipher name, passphrase, salt value
- /// and iteration count.
-
- CipherKeyImpl(const std::string& name,
- const ByteVec& key,
- const ByteVec& iv);
- /// Creates a new CipherKeyImpl object, using the
- /// given cipher name, key and initialization vector.
-
- CipherKeyImpl(const std::string& name);
- /// Creates a new CipherKeyImpl object. Autoinitializes key
- /// and initialization vector.
-
- 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
+//
+// CipherKeyImpl.h
+//
+// $Id: //poco/1.4/Crypto/include/Poco/Crypto/CipherKeyImpl.h#1 $
+//
+// Library: Crypto
+// Package: Cipher
+// 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/Crypto/OpenSSLInitializer.h"
+#include "Poco/RefCountedObject.h"
+#include "Poco/AutoPtr.h"
+#include
+
+
+struct evp_cipher_st;
+typedef struct evp_cipher_st EVP_CIPHER;
+
+
+namespace Poco {
+namespace Crypto {
+
+
+class CipherKeyImpl: public RefCountedObject
+ /// An implementation of the CipherKey class for OpenSSL's crypto library.
+{
+public:
+ typedef std::vector ByteVec;
+ typedef Poco::AutoPtr 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, using
+ /// the given cipher name, passphrase, salt value
+ /// and iteration count.
+
+ CipherKeyImpl(const std::string& name,
+ const ByteVec& key,
+ const ByteVec& iv);
+ /// Creates a new CipherKeyImpl object, using the
+ /// given cipher name, key and initialization vector.
+
+ CipherKeyImpl(const std::string& name);
+ /// Creates a new CipherKeyImpl object. Autoinitializes key
+ /// and initialization vector.
+
+ 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;
+ OpenSSLInitializer _openSSLInitializer;
+};
+
+
+//
+// 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
diff --git a/Crypto/include/Poco/Crypto/Crypto.h b/Crypto/include/Poco/Crypto/Crypto.h
index 19ea7757e..d63f7370d 100644
--- a/Crypto/include/Poco/Crypto/Crypto.h
+++ b/Crypto/include/Poco/Crypto/Crypto.h
@@ -42,6 +42,12 @@
#define Crypto_Crypto_INCLUDED
+#if defined(__APPLE__)
+// OS X 10.7 deprecates some OpenSSL functions
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+
+
#include "Poco/Foundation.h"
@@ -93,21 +99,37 @@ enum RSAPaddingMode
//
#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
+ #pragma comment(lib, "PocoCrypto" POCO_LIB_SUFFIX)
#endif
#endif
+namespace Poco {
+namespace Crypto {
+
+
+void Crypto_API initializeCrypto();
+ /// Initialize the Crypto library, as well as the underlying OpenSSL
+ /// libraries, by calling OpenSSLInitializer::initialize().
+ ///
+ /// Should be called before using any class from the Crypto library.
+ /// The Crypto library will be initialized automatically, through
+ /// OpenSSLInitializer instances held by various Crypto classes
+ /// (Cipher, CipherKey, RSAKey, X509Certificate).
+ /// However, it is recommended to call initializeCrypto()
+ /// in any case at application startup.
+ ///
+ /// Can be called multiple times; however, for every call to
+ /// initializeCrypto(), a matching call to uninitializeCrypto()
+ /// must be performed.
+
+
+void Crypto_API uninitializeCrypto();
+ /// Uninitializes the Crypto library by calling
+ /// OpenSSLInitializer::uninitialize().
+
+
+} } // namespace Poco::Crypto
+
+
#endif // Crypto_Crypto_INCLUDED
diff --git a/Crypto/include/Poco/Crypto/CryptoStream.h b/Crypto/include/Poco/Crypto/CryptoStream.h
index e431c998a..ea2919dc6 100644
--- a/Crypto/include/Poco/Crypto/CryptoStream.h
+++ b/Crypto/include/Poco/Crypto/CryptoStream.h
@@ -145,8 +145,66 @@ public:
~CryptoOutputStream();
/// Destroys the CryptoOutputStream.
- void close();
- /// Flushes all buffers and finishes the encryption.
+ void close();
+ /// Flushes all buffers and finishes the encryption.
+};
+
+
+class Crypto_API DecryptingInputStream: public CryptoIOS, public std::istream
+ /// This stream decrypts all data passing through it using the given
+ /// Cipher.
+{
+public:
+ DecryptingInputStream(std::istream& istr, Cipher& cipher, std::streamsize bufferSize = 8192);
+ /// Create a new DecryptingInputStream object using the given cipher.
+
+ ~DecryptingInputStream();
+ /// Destroys the DecryptingInputStream.
+};
+
+
+class Crypto_API DecryptingOutputStream: public CryptoIOS, public std::ostream
+ /// This stream decrypts all data passing through it using the given
+ /// Cipher.
+{
+public:
+ DecryptingOutputStream(std::ostream& ostr, Cipher& cipher, std::streamsize bufferSize = 8192);
+ /// Create a new DecryptingOutputStream object using the given cipher.
+
+ ~DecryptingOutputStream();
+ /// Destroys the DecryptingOutputStream.
+
+ void close();
+ /// Flushes all buffers and finishes the decryption.
+};
+
+
+class Crypto_API EncryptingInputStream: public CryptoIOS, public std::istream
+ /// This stream encrypts all data passing through it using the given
+ /// Cipher.
+{
+public:
+ EncryptingInputStream(std::istream& istr, Cipher& cipher, std::streamsize bufferSize = 8192);
+ /// Create a new EncryptingInputStream object using the given cipher.
+
+ ~EncryptingInputStream();
+ /// Destroys the EncryptingInputStream.
+};
+
+
+class Crypto_API EncryptingOutputStream: public CryptoIOS, public std::ostream
+ /// This stream encrypts all data passing through it using the given
+ /// Cipher.
+{
+public:
+ EncryptingOutputStream(std::ostream& ostr, Cipher& cipher, std::streamsize bufferSize = 8192);
+ /// Create a new EncryptingOutputStream object using the given cipher.
+
+ ~EncryptingOutputStream();
+ /// Destroys the EncryptingOutputStream.
+
+ void close();
+ /// Flushes all buffers and finishes the encryption.
};
diff --git a/Crypto/include/Poco/Crypto/CryptoTransform.h b/Crypto/include/Poco/Crypto/CryptoTransform.h
index 6f419e011..cfa75eb98 100644
--- a/Crypto/include/Poco/Crypto/CryptoTransform.h
+++ b/Crypto/include/Poco/Crypto/CryptoTransform.h
@@ -74,13 +74,13 @@ public:
/// 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
+ /// inputLength + blockSize() - 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()
+ /// space for at least two blocks, ie.
+ /// length >= 2*blockSize()
/// must be true. Returns the number of bytes written to the output
/// buffer.
};
diff --git a/Crypto/include/Poco/Crypto/OpenSSLInitializer.h b/Crypto/include/Poco/Crypto/OpenSSLInitializer.h
index 513eda56a..4f36cbdb1 100644
--- a/Crypto/include/Poco/Crypto/OpenSSLInitializer.h
+++ b/Crypto/include/Poco/Crypto/OpenSSLInitializer.h
@@ -1,101 +1,133 @@
-//
-// OpenSSLInitializer.h
-//
-// $Id: //poco/Main/Crypto/include/Poco/Crypto/OpenSSLInitializer.h#1 $
-//
-// Library: Crypto
-// Package: CryptoCore
-// Module: OpenSSLInitializer
-//
-// Definition of the OpenSSLInitializer class.
-//
-// Copyright (c) 2006-2009, 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_OpenSSLInitializer_INCLUDED
-#define Crypto_OpenSSLInitializer_INCLUDED
-
-
-#include "Poco/Crypto/Crypto.h"
-#include "Poco/Mutex.h"
-
-
-extern "C"
-{
- struct CRYPTO_dynlock_value
- {
- Poco::FastMutex _mutex;
- };
-}
-
-
-namespace Poco {
-namespace Crypto {
-
-
-class Crypto_API OpenSSLInitializer
- /// Initalizes the OpenSSL library.
- ///
- /// The class ensures the earliest initialization and the
- /// latest shutdown of the OpenSSL library.
-{
-public:
- OpenSSLInitializer();
- /// Automatically initialize OpenSSL on startup.
-
- ~OpenSSLInitializer();
- /// Automatically shut down OpenSSL on exit.
-
- static void initialize();
- /// Initializes the OpenSSL machinery.
-
- static void uninitialize();
- /// Shuts down the OpenSSL machinery.
-
-protected:
- enum
- {
- SEEDSIZE = 256
- };
-
- // OpenSSL multithreading support
- static void lock(int mode, int n, const char* file, int line);
- static unsigned long id();
- static struct CRYPTO_dynlock_value* dynlockCreate(const char* file, int line);
- static void dynlock(int mode, struct CRYPTO_dynlock_value* lock, const char* file, int line);
- static void dynlockDestroy(struct CRYPTO_dynlock_value* lock, const char* file, int line);
-
-private:
- static Poco::FastMutex* _mutexes;
- static int _rc;
-};
-
-
-} } // namespace Poco::Crypto
-
-
-#endif // Crypto_OpenSSLInitializer_INCLUDED
+//
+// OpenSSLInitializer.h
+//
+// $Id: //poco/1.4/Crypto/include/Poco/Crypto/OpenSSLInitializer.h#1 $
+//
+// Library: Crypto
+// Package: CryptoCore
+// Module: OpenSSLInitializer
+//
+// Definition of the OpenSSLInitializer class.
+//
+// Copyright (c) 2006-2009, 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_OpenSSLInitializer_INCLUDED
+#define Crypto_OpenSSLInitializer_INCLUDED
+
+
+#include "Poco/Crypto/Crypto.h"
+#include "Poco/Mutex.h"
+#include
+#ifdef OPENSSL_FIPS
+#include
+#endif
+
+
+extern "C"
+{
+ struct CRYPTO_dynlock_value
+ {
+ Poco::FastMutex _mutex;
+ };
+}
+
+
+namespace Poco {
+namespace Crypto {
+
+
+class Crypto_API OpenSSLInitializer
+ /// Initalizes the OpenSSL library.
+ ///
+ /// The class ensures the earliest initialization and the
+ /// latest shutdown of the OpenSSL library.
+{
+public:
+ OpenSSLInitializer();
+ /// Automatically initialize OpenSSL on startup.
+
+ ~OpenSSLInitializer();
+ /// Automatically shut down OpenSSL on exit.
+
+ static void initialize();
+ /// Initializes the OpenSSL machinery.
+
+ static void uninitialize();
+ /// Shuts down the OpenSSL machinery.
+
+ static bool isFIPSEnabled();
+ // Returns true if FIPS mode is enabled, false otherwise.
+
+ static void enableFIPSMode(bool enabled);
+ // Enable or disable FIPS mode. If FIPS is not available, this method doesn't do anything.
+
+protected:
+ enum
+ {
+ SEEDSIZE = 256
+ };
+
+ // OpenSSL multithreading support
+ static void lock(int mode, int n, const char* file, int line);
+ static unsigned long id();
+ static struct CRYPTO_dynlock_value* dynlockCreate(const char* file, int line);
+ static void dynlock(int mode, struct CRYPTO_dynlock_value* lock, const char* file, int line);
+ static void dynlockDestroy(struct CRYPTO_dynlock_value* lock, const char* file, int line);
+
+private:
+ static Poco::FastMutex* _mutexes;
+ static Poco::FastMutex _mutex;
+ static int _rc;
+};
+
+
+//
+// inlines
+//
+inline bool OpenSSLInitializer::isFIPSEnabled()
+{
+#ifdef OPENSSL_FIPS
+ return FIPS_mode() ? true : false;
+#else
+ return false;
+#endif
+}
+
+
+inline void OpenSSLInitializer::enableFIPSMode(bool enabled)
+{
+#ifdef OPENSSL_FIPS
+ FIPS_mode_set(enabled);
+#endif
+}
+
+
+} } // namespace Poco::Crypto
+
+
+#endif // Crypto_OpenSSLInitializer_INCLUDED
diff --git a/Crypto/include/Poco/Crypto/RSACipherImpl.h b/Crypto/include/Poco/Crypto/RSACipherImpl.h
index c532ca2d7..69f193d7e 100644
--- a/Crypto/include/Poco/Crypto/RSACipherImpl.h
+++ b/Crypto/include/Poco/Crypto/RSACipherImpl.h
@@ -1,97 +1,99 @@
-//
-// RSACipherImpl.h
-//
-// $Id: //poco/Main/Crypto/include/Poco/Crypto/RSACipherImpl.h#2 $
-//
-// Library: Crypto
-// Package: RSA
-// 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
-
-
-namespace Poco {
-namespace Crypto {
-
-
-class RSACipherImpl: public Cipher
- /// An implementation of the Cipher class for
- /// assymetric (public-private key) encryption
- /// based on the the RSA algorithm in OpenSSL's
- /// crypto library.
- ///
- /// Encryption is using the public key, decryption
- /// requires the private key.
-{
-public:
- RSACipherImpl(const RSAKey& key, RSAPaddingMode paddingMode);
- /// Creates a new RSACipherImpl object for the given RSAKey
- /// and using the given padding mode.
-
- 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;
- RSAPaddingMode _paddingMode;
-};
-
-
-//
-// Inlines
-//
-inline const std::string& RSACipherImpl::name() const
-{
- return _key.name();
-}
-
-
-} } // namespace Poco::Crypto
-
-
-#endif // Crypto_RSACipherImpl_INCLUDED
+//
+// RSACipherImpl.h
+//
+// $Id: //poco/1.4/Crypto/include/Poco/Crypto/RSACipherImpl.h#1 $
+//
+// Library: Crypto
+// Package: RSA
+// 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 "Poco/Crypto/OpenSSLInitializer.h"
+#include
+
+
+namespace Poco {
+namespace Crypto {
+
+
+class RSACipherImpl: public Cipher
+ /// An implementation of the Cipher class for
+ /// assymetric (public-private key) encryption
+ /// based on the the RSA algorithm in OpenSSL's
+ /// crypto library.
+ ///
+ /// Encryption is using the public key, decryption
+ /// requires the private key.
+{
+public:
+ RSACipherImpl(const RSAKey& key, RSAPaddingMode paddingMode);
+ /// Creates a new RSACipherImpl object for the given RSAKey
+ /// and using the given padding mode.
+
+ 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;
+ RSAPaddingMode _paddingMode;
+ OpenSSLInitializer _openSSLInitializer;
+};
+
+
+//
+// Inlines
+//
+inline const std::string& RSACipherImpl::name() const
+{
+ return _key.name();
+}
+
+
+} } // namespace Poco::Crypto
+
+
+#endif // Crypto_RSACipherImpl_INCLUDED
diff --git a/Crypto/include/Poco/Crypto/RSADigestEngine.h b/Crypto/include/Poco/Crypto/RSADigestEngine.h
index df9bdaf30..de73e3b76 100644
--- a/Crypto/include/Poco/Crypto/RSADigestEngine.h
+++ b/Crypto/include/Poco/Crypto/RSADigestEngine.h
@@ -1,128 +1,128 @@
-//
-// RSADigestEngine.h
-//
-// $Id: //poco/Main/Crypto/include/Poco/Crypto/RSADigestEngine.h#2 $
-//
-// Library: Crypto
-// Package: RSA
-// 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/MD5Engine.h"
-#include "Poco/SHA1Engine.h"
-#include
-#include
-#include
-
-
-namespace Poco {
-namespace Crypto {
-
-
-class Crypto_API RSADigestEngine: public Poco::DigestEngine
- /// This class implements a Poco::DigestEngine that can be
- /// used to compute a secure digital signature.
- ///
- /// First another Poco::DigestEngine (Poco::MD5Engine
- /// or Poco::SHA1Engine) is used to compute a cryptographic
- /// hash of the data to be signed. Then, the hash value is
- /// encrypted, using the RSA private key.
- ///
- /// To verify a signature, pass it to the verify()
- /// member function. It will decrypt the signature
- /// using the RSA public key and compare the resulting
- /// hash with the actual hash of the data.
-{
-public:
- enum DigestType
- {
- DIGEST_MD5,
- DIGEST_SHA1
- };
-
- RSADigestEngine(const RSAKey& key, DigestType digestType = DIGEST_SHA1);
- /// Creates the RSADigestEngine with the given RSA key,
- /// using the SHA-1 hash algorithm.
-
- ~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();
- /// Finishes the computation of the digest
- /// (the first time it's called) and
- /// returns the message digest.
- ///
- /// Can be called multiple times.
-
- const DigestEngine::Digest& signature();
- /// Signs the digest using the RSA algorithm
- /// and the private key (teh first time it's
- /// called) and returns the result.
- ///
- /// Can be called multiple times.
-
- bool verify(const DigestEngine::Digest& signature);
- /// Verifies the data against the signature.
- ///
- /// Returns true if the signature can be verified, false otherwise.
-
-protected:
- void updateImpl(const void* data, unsigned length);
-
-private:
- RSAKey _key;
- Poco::DigestEngine& _engine;
- int _type;
- Poco::DigestEngine::Digest _digest;
- Poco::DigestEngine::Digest _signature;
- Poco::MD5Engine _md5Engine;
- Poco::SHA1Engine _sha1Engine;
-};
-
-
-} } // namespace Poco::Crypto
-
-
-#endif // Crypto_RSADigestEngine_INCLUDED
+//
+// RSADigestEngine.h
+//
+// $Id: //poco/1.4/Crypto/include/Poco/Crypto/RSADigestEngine.h#1 $
+//
+// Library: Crypto
+// Package: RSA
+// 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/MD5Engine.h"
+#include "Poco/SHA1Engine.h"
+#include
+#include
+#include
+
+
+namespace Poco {
+namespace Crypto {
+
+
+class Crypto_API RSADigestEngine: public Poco::DigestEngine
+ /// This class implements a Poco::DigestEngine that can be
+ /// used to compute a secure digital signature.
+ ///
+ /// First another Poco::DigestEngine (Poco::MD5Engine
+ /// or Poco::SHA1Engine) is used to compute a cryptographic
+ /// hash of the data to be signed. Then, the hash value is
+ /// encrypted, using the RSA private key.
+ ///
+ /// To verify a signature, pass it to the verify()
+ /// member function. It will decrypt the signature
+ /// using the RSA public key and compare the resulting
+ /// hash with the actual hash of the data.
+{
+public:
+ enum DigestType
+ {
+ DIGEST_MD5,
+ DIGEST_SHA1
+ };
+
+ RSADigestEngine(const RSAKey& key, DigestType digestType = DIGEST_SHA1);
+ /// Creates the RSADigestEngine with the given RSA key,
+ /// using the SHA-1 hash algorithm.
+
+ ~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();
+ /// Finishes the computation of the digest
+ /// (the first time it's called) and
+ /// returns the message digest.
+ ///
+ /// Can be called multiple times.
+
+ const DigestEngine::Digest& signature();
+ /// Signs the digest using the RSA algorithm
+ /// and the private key (teh first time it's
+ /// called) and returns the result.
+ ///
+ /// Can be called multiple times.
+
+ bool verify(const DigestEngine::Digest& signature);
+ /// Verifies the data against the signature.
+ ///
+ /// Returns true if the signature can be verified, false otherwise.
+
+protected:
+ void updateImpl(const void* data, unsigned length);
+
+private:
+ RSAKey _key;
+ Poco::DigestEngine& _engine;
+ int _type;
+ Poco::DigestEngine::Digest _digest;
+ Poco::DigestEngine::Digest _signature;
+ Poco::MD5Engine _md5Engine;
+ Poco::SHA1Engine _sha1Engine;
+};
+
+
+} } // namespace Poco::Crypto
+
+
+#endif // Crypto_RSADigestEngine_INCLUDED
diff --git a/Crypto/include/Poco/Crypto/RSAKey.h b/Crypto/include/Poco/Crypto/RSAKey.h
index cb7dc1c89..bcf253820 100644
--- a/Crypto/include/Poco/Crypto/RSAKey.h
+++ b/Crypto/include/Poco/Crypto/RSAKey.h
@@ -1,136 +1,145 @@
-//
-// RSAKey.h
-//
-// $Id: //poco/Main/Crypto/include/Poco/Crypto/RSAKey.h#4 $
-//
-// Library: Crypto
-// Package: RSA
-// 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 Crypto {
-
-
-class X509Certificate;
-
-
-class Crypto_API RSAKey
- /// This class stores an RSA key pair, consisting
- /// of private and public key. Storage of the private
- /// key is optional.
- ///
- /// If a private key is available, the RSAKey can be
- /// used for decrypting data (encrypted with the public key)
- /// or computing secure digital signatures.
-{
-public:
- enum KeyLength
- {
- KL_512 = 512,
- KL_1024 = 1024,
- KL_2048 = 2048,
- KL_4096 = 4096
- };
-
- enum Exponent
- {
- EXP_SMALL = 0,
- EXP_LARGE
- };
-
- explicit RSAKey(const X509Certificate& cert);
- /// Extracts the RSA public key from the given certificate.
-
- RSAKey(KeyLength keyLength, Exponent exp);
- /// Creates the RSAKey. Creates a new public/private keypair using the given parameters.
- /// Can be used to sign data and verify signatures.
-
- RSAKey(const std::string& publicKeyFile, const std::string& privateKeyFile = "", const std::string& privateKeyPassphrase = "");
- /// Creates the RSAKey, by reading public and private key from the given files and
- /// using the given passphrase for the private key. Can only by used for signing if
- /// a private key is available.
-
- RSAKey(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream = 0, const std::string& privateKeyPassphrase = "");
- /// 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 modulus size.
-
- void save(const std::string& publicKeyFile, const std::string& privateKeyFile = "", const std::string& privateKeyPassphrase = "");
- /// Exports the public and private keys to the given files.
- ///
- /// If an empty filename is specified, the corresponding key
- /// is not exported.
-
- void save(std::ostream* pPublicKeyStream, std::ostream* pPrivateKeyStream = 0, const std::string& privateKeyPassphrase = "");
- /// Exports the public and private key to the given streams.
- ///
- /// If a null pointer is passed for a stream, the corresponding
- /// key is not exported.
-
- RSAKeyImpl::Ptr impl();
- /// Returns the impl object.
-
- const std::string& name() const;
- /// Returns "rsa"
-
-private:
- RSAKeyImpl::Ptr _pImpl;
-};
-
-
-//
-// inlines
-//
-inline RSAKeyImpl::Ptr RSAKey::impl()
-{
- return _pImpl;
-}
-
-
-} } // namespace Poco::Crypto
-
-
-#endif // Crypto_RSAKey_INCLUDED
+//
+// RSAKey.h
+//
+// $Id: //poco/1.4/Crypto/include/Poco/Crypto/RSAKey.h#1 $
+//
+// Library: Crypto
+// Package: RSA
+// 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 Crypto {
+
+
+class X509Certificate;
+
+
+class Crypto_API RSAKey
+ /// This class stores an RSA key pair, consisting
+ /// of private and public key. Storage of the private
+ /// key is optional.
+ ///
+ /// If a private key is available, the RSAKey can be
+ /// used for decrypting data (encrypted with the public key)
+ /// or computing secure digital signatures.
+{
+public:
+ enum KeyLength
+ {
+ KL_512 = 512,
+ KL_1024 = 1024,
+ KL_2048 = 2048,
+ KL_4096 = 4096
+ };
+
+ enum Exponent
+ {
+ EXP_SMALL = 0,
+ EXP_LARGE
+ };
+
+ explicit RSAKey(const X509Certificate& cert);
+ /// Extracts the RSA public key from the given certificate.
+
+ RSAKey(KeyLength keyLength, Exponent exp);
+ /// Creates the RSAKey. Creates a new public/private keypair using the given parameters.
+ /// Can be used to sign data and verify signatures.
+
+ RSAKey(const std::string& publicKeyFile, const std::string& privateKeyFile = "", const std::string& privateKeyPassphrase = "");
+ /// Creates the RSAKey, by reading public and private key from the given files and
+ /// using the given passphrase for the private key. Can only by used for signing if
+ /// a private key is available.
+
+ RSAKey(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream = 0, const std::string& privateKeyPassphrase = "");
+ /// 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 modulus size.
+
+ RSAKeyImpl::ByteVec modulus() const;
+ /// Returns the RSA modulus.
+
+ RSAKeyImpl::ByteVec encryptionExponent() const;
+ /// Returns the RSA encryption exponent.
+
+ RSAKeyImpl::ByteVec decryptionExponent() const;
+ /// Returns the RSA decryption exponent.
+
+ void save(const std::string& publicKeyFile, const std::string& privateKeyFile = "", const std::string& privateKeyPassphrase = "");
+ /// Exports the public and private keys to the given files.
+ ///
+ /// If an empty filename is specified, the corresponding key
+ /// is not exported.
+
+ void save(std::ostream* pPublicKeyStream, std::ostream* pPrivateKeyStream = 0, const std::string& privateKeyPassphrase = "");
+ /// Exports the public and private key to the given streams.
+ ///
+ /// If a null pointer is passed for a stream, the corresponding
+ /// key is not exported.
+
+ RSAKeyImpl::Ptr impl() const;
+ /// Returns the impl object.
+
+ const std::string& name() const;
+ /// Returns "rsa"
+
+private:
+ RSAKeyImpl::Ptr _pImpl;
+};
+
+
+//
+// inlines
+//
+inline RSAKeyImpl::Ptr RSAKey::impl() const
+{
+ return _pImpl;
+}
+
+
+} } // namespace Poco::Crypto
+
+
+#endif // Crypto_RSAKey_INCLUDED
diff --git a/Crypto/include/Poco/Crypto/RSAKeyImpl.h b/Crypto/include/Poco/Crypto/RSAKeyImpl.h
index da97b4733..0b1dcd0a2 100644
--- a/Crypto/include/Poco/Crypto/RSAKeyImpl.h
+++ b/Crypto/include/Poco/Crypto/RSAKeyImpl.h
@@ -1,134 +1,150 @@
-//
-// RSAKeyImpl.h
-//
-// $Id: //poco/Main/Crypto/include/Poco/Crypto/RSAKeyImpl.h#3 $
-//
-// Library: Crypto
-// Package: RSA
-// 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"
-#include
-#include
-
-
-struct rsa_st;
-typedef struct rsa_st RSA;
-
-
-namespace Poco {
-namespace Crypto {
-
-
-class X509Certificate;
-
-
-class RSAKeyImpl: public Poco::RefCountedObject
- /// class RSAKeyImpl
-{
-public:
- typedef Poco::AutoPtr Ptr;
-
- explicit RSAKeyImpl(const X509Certificate& cert);
- /// Extracts the RSA public key from the given certificate.
-
- RSAKeyImpl(int keyLength, unsigned long exponent);
- /// Creates the RSAKey. Creates a new public/private keypair using the given parameters.
- /// Can be used to sign data and verify signatures.
-
- RSAKeyImpl(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase);
- /// Creates the RSAKey, by reading public and private key from the given files and
- /// using the given passphrase for the private key. Can only by used for signing if
- /// a private key is available.
-
- RSAKeyImpl(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream, const std::string& privateKeyPassphrase);
- /// 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.
-
- ~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 modulus size.
-
- void save(const std::string& publicKeyFile, const std::string& privateKeyFile = "", const std::string& privateKeyPassphrase = "");
- /// Exports the public and private keys to the given files.
- ///
- /// If an empty filename is specified, the corresponding key
- /// is not exported.
-
- void save(std::ostream* pPublicKeyStream, std::ostream* pPrivateKeyStream = 0, const std::string& privateKeyPassphrase = "");
- /// Exports the public and private key to the given streams.
- ///
- /// If a null pointer is passed for a stream, the corresponding
- /// key is not exported.
-
-private:
- void init(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase);
- void freeRSA();
-
-private:
- RSA* _pRSA;
-};
-
-
-//
-// inlines
-//
-inline RSA* RSAKeyImpl::getRSA()
-{
- return _pRSA;
-}
-
-
-inline const RSA* RSAKeyImpl::getRSA() const
-{
- return _pRSA;
-}
-
-} } // namespace Poco::Crypto
-
-
-#endif // Crypto_RSAKeyImplImpl_INCLUDED
+//
+// RSAKeyImpl.h
+//
+// $Id: //poco/1.4/Crypto/include/Poco/Crypto/RSAKeyImpl.h#1 $
+//
+// Library: Crypto
+// Package: RSA
+// 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/Crypto/OpenSSLInitializer.h"
+#include "Poco/RefCountedObject.h"
+#include "Poco/AutoPtr.h"
+#include
+#include
+#include
+
+
+struct bignum_st;
+struct rsa_st;
+typedef struct bignum_st BIGNUM;
+typedef struct rsa_st RSA;
+
+
+namespace Poco {
+namespace Crypto {
+
+
+class X509Certificate;
+
+
+class RSAKeyImpl: public Poco::RefCountedObject
+ /// class RSAKeyImpl
+{
+public:
+ typedef Poco::AutoPtr Ptr;
+ typedef std::vector ByteVec;
+
+ explicit RSAKeyImpl(const X509Certificate& cert);
+ /// Extracts the RSA public key from the given certificate.
+
+ RSAKeyImpl(int keyLength, unsigned long exponent);
+ /// Creates the RSAKey. Creates a new public/private keypair using the given parameters.
+ /// Can be used to sign data and verify signatures.
+
+ RSAKeyImpl(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase);
+ /// Creates the RSAKey, by reading public and private key from the given files and
+ /// using the given passphrase for the private key. Can only by used for signing if
+ /// a private key is available.
+
+ RSAKeyImpl(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream, const std::string& privateKeyPassphrase);
+ /// 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.
+
+ ~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 modulus size.
+
+ ByteVec modulus() const;
+ /// Returns the RSA modulus.
+
+ ByteVec encryptionExponent() const;
+ /// Returns the RSA encryption exponent.
+
+ ByteVec decryptionExponent() const;
+ /// Returns the RSA decryption exponent.
+
+ void save(const std::string& publicKeyFile, const std::string& privateKeyFile = "", const std::string& privateKeyPassphrase = "");
+ /// Exports the public and private keys to the given files.
+ ///
+ /// If an empty filename is specified, the corresponding key
+ /// is not exported.
+
+ void save(std::ostream* pPublicKeyStream, std::ostream* pPrivateKeyStream = 0, const std::string& privateKeyPassphrase = "");
+ /// Exports the public and private key to the given streams.
+ ///
+ /// If a null pointer is passed for a stream, the corresponding
+ /// key is not exported.
+
+private:
+ void freeRSA();
+
+ static ByteVec convertToByteVec(const BIGNUM* bn);
+
+private:
+ RSA* _pRSA;
+ OpenSSLInitializer _openSSLInitializer;
+};
+
+
+//
+// inlines
+//
+inline RSA* RSAKeyImpl::getRSA()
+{
+ return _pRSA;
+}
+
+
+inline const RSA* RSAKeyImpl::getRSA() const
+{
+ return _pRSA;
+}
+
+} } // namespace Poco::Crypto
+
+
+#endif // Crypto_RSAKeyImplImpl_INCLUDED
diff --git a/Crypto/include/Poco/Crypto/X509Certificate.h b/Crypto/include/Poco/Crypto/X509Certificate.h
index d27079f93..042c172e7 100644
--- a/Crypto/include/Poco/Crypto/X509Certificate.h
+++ b/Crypto/include/Poco/Crypto/X509Certificate.h
@@ -1,197 +1,205 @@
-//
-// X509Certificate.h
-//
-// $Id: //poco/Main/Crypto/include/Poco/Crypto/X509Certificate.h#1 $
-//
-// Library: Crypto
-// Package: Certificate
-// Module: X509Certificate
-//
-// Definition of the X509Certificate class.
-//
-// Copyright (c) 2006-2009, 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_X509Certificate_INCLUDED
-#define Crypto_X509Certificate_INCLUDED
-
-
-#include "Poco/Crypto/Crypto.h"
-#include "Poco/DateTime.h"
-#include "Poco/SharedPtr.h"
-#include
-#include
-#include
-
-
-namespace Poco {
-namespace Crypto {
-
-
-class Crypto_API X509Certificate
- /// This class represents a X509 Certificate.
-{
-public:
- enum NID
- /// Name identifier for extracting information from
- /// a certificate subject's or issuer's distinguished name.
- {
- NID_COMMON_NAME = 13,
- NID_COUNTRY = 14,
- NID_LOCALITY_NAME = 15,
- NID_STATE_OR_PROVINCE = 16,
- NID_ORGANIZATION_NAME = 17,
- NID_ORGANIZATION_UNIT_NAME = 18
- };
-
- explicit X509Certificate(std::istream& istr);
- /// Creates the X509Certificate object by reading
- /// a certificate in PEM format from a stream.
-
- explicit X509Certificate(const std::string& path);
- /// Creates the X509Certificate object by reading
- /// a certificate in PEM format from a file.
-
- explicit X509Certificate(X509* pCert);
- /// Creates the X509Certificate from an existing
- /// OpenSSL certificate. Ownership is taken of
- /// the certificate.
-
- X509Certificate(const X509Certificate& cert);
- /// Creates the certificate by copying another one.
-
- X509Certificate& operator = (const X509Certificate& cert);
- /// Assigns a certificate.
-
- void swap(X509Certificate& cert);
- /// Exchanges the certificate with another one.
-
- ~X509Certificate();
- /// Destroys the X509Certificate.
-
- const std::string& issuerName() const;
- /// Returns the certificate issuer's distinguished name.
-
- std::string issuerName(NID nid) const;
- /// Extracts the information specified by the given
- /// NID (name identifier) from the certificate issuer's
- /// distinguished name.
-
- const std::string& subjectName() const;
- /// Returns the certificate subject's distinguished name.
-
- std::string subjectName(NID nid) const;
- /// Extracts the information specified by the given
- /// NID (name identifier) from the certificate subject's
- /// distinguished name.
-
- std::string commonName() const;
- /// Returns the common name stored in the certificate
- /// subject's distinguished name.
-
- void extractNames(std::string& commonName, std::set& domainNames) const;
- /// Extracts the common name and the alias domain names from the
- /// certificate.
-
- Poco::DateTime validFrom() const;
- /// Returns the date and time the certificate is valid from.
-
- Poco::DateTime expiresOn() const;
- /// Returns the date and time the certificate expires.
-
- void save(std::ostream& stream) const;
- /// Writes the certificate to the given stream.
- /// The certificate is written in PEM format.
-
- void save(const std::string& path) const;
- /// Writes the certificate to the file given by path.
- /// The certificate is written in PEM format.
-
- bool issuedBy(const X509Certificate& issuerCertificate) const;
- /// Checks whether the certificate has been issued by
- /// the issuer given by issuerCertificate. This can be
- /// used to validate a certificate chain.
- ///
- /// Verifies if the certificate has been signed with the
- /// issuer's private key, using the public key from the issuer
- /// certificate.
- ///
- /// Returns true if verification against the issuer certificate
- /// was successfull, false otherwise.
-
- const X509* certificate() const;
- /// Returns the underlying OpenSSL certificate.
-
-protected:
- void load(std::istream& stream);
- /// Loads the certificate from the given stream. The
- /// certificate must be in PEM format.
-
- void load(const std::string& path);
- /// Loads the certificate from the given file. The
- /// certificate must be in PEM format.
-
- void init();
- /// Extracts issuer and subject name from the certificate.
-
-private:
- enum
- {
- NAME_BUFFER_SIZE = 256
- };
-
- std::string _issuerName;
- std::string _subjectName;
- X509* _pCert;
-};
-
-
-//
-// inlines
-//
-inline const std::string& X509Certificate::issuerName() const
-{
- return _issuerName;
-}
-
-
-inline const std::string& X509Certificate::subjectName() const
-{
- return _subjectName;
-}
-
-
-inline const X509* X509Certificate::certificate() const
-{
- return _pCert;
-}
-
-
-} } // namespace Poco::Crypto
-
-
-#endif // Crypto_X509Certificate_INCLUDED
+//
+// X509Certificate.h
+//
+// $Id: //poco/1.4/Crypto/include/Poco/Crypto/X509Certificate.h#1 $
+//
+// Library: Crypto
+// Package: Certificate
+// Module: X509Certificate
+//
+// Definition of the X509Certificate class.
+//
+// Copyright (c) 2006-2009, 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_X509Certificate_INCLUDED
+#define Crypto_X509Certificate_INCLUDED
+
+
+#include "Poco/Crypto/Crypto.h"
+#include "Poco/Crypto/OpenSSLInitializer.h"
+#include "Poco/DateTime.h"
+#include "Poco/SharedPtr.h"
+#include
+#include
+#include
+
+
+namespace Poco {
+namespace Crypto {
+
+
+class Crypto_API X509Certificate
+ /// This class represents a X509 Certificate.
+{
+public:
+ enum NID
+ /// Name identifier for extracting information from
+ /// a certificate subject's or issuer's distinguished name.
+ {
+ NID_COMMON_NAME = 13,
+ NID_COUNTRY = 14,
+ NID_LOCALITY_NAME = 15,
+ NID_STATE_OR_PROVINCE = 16,
+ NID_ORGANIZATION_NAME = 17,
+ NID_ORGANIZATION_UNIT_NAME = 18
+ };
+
+ explicit X509Certificate(std::istream& istr);
+ /// Creates the X509Certificate object by reading
+ /// a certificate in PEM format from a stream.
+
+ explicit X509Certificate(const std::string& path);
+ /// Creates the X509Certificate object by reading
+ /// a certificate in PEM format from a file.
+
+ explicit X509Certificate(X509* pCert);
+ /// Creates the X509Certificate from an existing
+ /// OpenSSL certificate. Ownership is taken of
+ /// the certificate.
+
+ X509Certificate(X509* pCert, bool shared);
+ /// Creates the X509Certificate from an existing
+ /// OpenSSL certificate. Ownership is taken of
+ /// the certificate. If shared is true, the
+ /// certificate's reference count is incremented.
+
+ X509Certificate(const X509Certificate& cert);
+ /// Creates the certificate by copying another one.
+
+ X509Certificate& operator = (const X509Certificate& cert);
+ /// Assigns a certificate.
+
+ void swap(X509Certificate& cert);
+ /// Exchanges the certificate with another one.
+
+ ~X509Certificate();
+ /// Destroys the X509Certificate.
+
+ const std::string& issuerName() const;
+ /// Returns the certificate issuer's distinguished name.
+
+ std::string issuerName(NID nid) const;
+ /// Extracts the information specified by the given
+ /// NID (name identifier) from the certificate issuer's
+ /// distinguished name.
+
+ const std::string& subjectName() const;
+ /// Returns the certificate subject's distinguished name.
+
+ std::string subjectName(NID nid) const;
+ /// Extracts the information specified by the given
+ /// NID (name identifier) from the certificate subject's
+ /// distinguished name.
+
+ std::string commonName() const;
+ /// Returns the common name stored in the certificate
+ /// subject's distinguished name.
+
+ void extractNames(std::string& commonName, std::set& domainNames) const;
+ /// Extracts the common name and the alias domain names from the
+ /// certificate.
+
+ Poco::DateTime validFrom() const;
+ /// Returns the date and time the certificate is valid from.
+
+ Poco::DateTime expiresOn() const;
+ /// Returns the date and time the certificate expires.
+
+ void save(std::ostream& stream) const;
+ /// Writes the certificate to the given stream.
+ /// The certificate is written in PEM format.
+
+ void save(const std::string& path) const;
+ /// Writes the certificate to the file given by path.
+ /// The certificate is written in PEM format.
+
+ bool issuedBy(const X509Certificate& issuerCertificate) const;
+ /// Checks whether the certificate has been issued by
+ /// the issuer given by issuerCertificate. This can be
+ /// used to validate a certificate chain.
+ ///
+ /// Verifies if the certificate has been signed with the
+ /// issuer's private key, using the public key from the issuer
+ /// certificate.
+ ///
+ /// Returns true if verification against the issuer certificate
+ /// was successfull, false otherwise.
+
+ const X509* certificate() const;
+ /// Returns the underlying OpenSSL certificate.
+
+protected:
+ void load(std::istream& stream);
+ /// Loads the certificate from the given stream. The
+ /// certificate must be in PEM format.
+
+ void load(const std::string& path);
+ /// Loads the certificate from the given file. The
+ /// certificate must be in PEM format.
+
+ void init();
+ /// Extracts issuer and subject name from the certificate.
+
+private:
+ enum
+ {
+ NAME_BUFFER_SIZE = 256
+ };
+
+ std::string _issuerName;
+ std::string _subjectName;
+ X509* _pCert;
+ OpenSSLInitializer _openSSLInitializer;
+};
+
+
+//
+// inlines
+//
+inline const std::string& X509Certificate::issuerName() const
+{
+ return _issuerName;
+}
+
+
+inline const std::string& X509Certificate::subjectName() const
+{
+ return _subjectName;
+}
+
+
+inline const X509* X509Certificate::certificate() const
+{
+ return _pCert;
+}
+
+
+} } // namespace Poco::Crypto
+
+
+#endif // Crypto_X509Certificate_INCLUDED
diff --git a/Crypto/samples/genrsakey/genrsakey_vs100.vcxproj b/Crypto/samples/genrsakey/genrsakey_vs100.vcxproj
new file mode 100644
index 000000000..1512679a3
--- /dev/null
+++ b/Crypto/samples/genrsakey/genrsakey_vs100.vcxproj
@@ -0,0 +1,299 @@
+
+
+
+
+ debug_shared
+ Win32
+
+
+ debug_static_md
+ Win32
+
+
+ debug_static_mt
+ Win32
+
+
+ release_shared
+ Win32
+
+
+ release_static_md
+ Win32
+
+
+ release_static_mt
+ Win32
+
+
+
+ genrsakey
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}
+ genrsakey
+ Win32Proj
+
+
+
+ Application
+ MultiByte
+
+
+ Application
+ MultiByte
+
+
+ Application
+ MultiByte
+
+
+ Application
+ MultiByte
+
+
+ Application
+ MultiByte
+
+
+ Application
+ MultiByte
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <_ProjectFileVersion>10.0.30319.1
+ bin\
+ obj\$(Configuration)\
+ true
+ bin\
+ obj\$(Configuration)\
+ false
+ bin\static_mt\
+ obj\$(Configuration)\
+ true
+ bin\static_mt\
+ obj\$(Configuration)\
+ false
+ bin\static_md\
+ obj\$(Configuration)\
+ true
+ bin\static_md\
+ obj\$(Configuration)\
+ false
+ genrsakeyd
+ genrsakeyd
+ genrsakeyd
+ genrsakey
+ genrsakey
+ genrsakey
+
+
+
+ Disabled
+ .\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Util\include;..\..\..\Crypto\include;%(AdditionalIncludeDirectories)
+ WIN32;_DEBUG;_WINDOWS;WINVER=0x0500;%(PreprocessorDefinitions)
+ true
+ true
+ EnableFastChecks
+ MultiThreadedDebugDLL
+ true
+ true
+ true
+ true
+
+ Level3
+ EditAndContinue
+ Default
+ %(DisableSpecificWarnings)
+
+
+ libeay32mdd.lib;ssleay32mdd.lib;ws2_32.lib;iphlpapi.lib;%(AdditionalDependencies)
+ bin\genrsakeyd.exe
+ ..\..\..\lib;%(AdditionalLibraryDirectories)
+ true
+ true
+ bin\genrsakeyd.pdb
+ Console
+ MachineX86
+
+
+
+
+ Disabled
+ OnlyExplicitInline
+ true
+ Speed
+ true
+ .\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Util\include;..\..\..\Crypto\include;%(AdditionalIncludeDirectories)
+ WIN32;NDEBUG;_WINDOWS;WINVER=0x0500;%(PreprocessorDefinitions)
+ true
+ MultiThreadedDLL
+ false
+ true
+ true
+ true
+
+ Level3
+
+ Default
+ %(DisableSpecificWarnings)
+
+
+ libeay32md.lib;ssleay32md.lib;ws2_32.lib;iphlpapi.lib;%(AdditionalDependencies)
+ bin\genrsakey.exe
+ ..\..\..\lib;%(AdditionalLibraryDirectories)
+ false
+ Console
+ true
+ true
+ MachineX86
+
+
+
+
+ Disabled
+ .\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Util\include;..\..\..\Crypto\include;%(AdditionalIncludeDirectories)
+ WIN32;_DEBUG;_WINDOWS;WINVER=0x0500;POCO_STATIC;%(PreprocessorDefinitions)
+ true
+ true
+ EnableFastChecks
+ MultiThreadedDebug
+ true
+ true
+ true
+ true
+
+ Level3
+ EditAndContinue
+ Default
+ %(DisableSpecificWarnings)
+
+
+ iphlpapi.lib;winmm.lib;libeay32mtd.lib;ssleay32mtd.lib;ws2_32.lib;iphlpapi.lib;%(AdditionalDependencies)
+ bin\static_mt\genrsakeyd.exe
+ ..\..\..\lib;%(AdditionalLibraryDirectories)
+ true
+ true
+ bin\static_mt\genrsakeyd.pdb
+ Console
+ MachineX86
+
+
+
+
+ Disabled
+ OnlyExplicitInline
+ true
+ Speed
+ true
+ .\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Util\include;..\..\..\Crypto\include;%(AdditionalIncludeDirectories)
+ WIN32;NDEBUG;_WINDOWS;WINVER=0x0500;POCO_STATIC;%(PreprocessorDefinitions)
+ true
+ MultiThreaded
+ false
+ true
+ true
+ true
+
+ Level3
+
+ Default
+ %(DisableSpecificWarnings)
+
+
+ iphlpapi.lib;winmm.lib;libeay32mt.lib;ssleay32mt.lib;ws2_32.lib;iphlpapi.lib;%(AdditionalDependencies)
+ bin\static_mt\genrsakey.exe
+ ..\..\..\lib;%(AdditionalLibraryDirectories)
+ false
+ Console
+ true
+ true
+ MachineX86
+
+
+
+
+ Disabled
+ .\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Util\include;..\..\..\Crypto\include;%(AdditionalIncludeDirectories)
+ WIN32;_DEBUG;_WINDOWS;WINVER=0x0500;POCO_STATIC;%(PreprocessorDefinitions)
+ true
+ true
+ EnableFastChecks
+ MultiThreadedDebugDLL
+ true
+ true
+ true
+ true
+
+ Level3
+ EditAndContinue
+ Default
+ %(DisableSpecificWarnings)
+
+
+ iphlpapi.lib;winmm.lib;libeay32mdd.lib;ssleay32mdd.lib;ws2_32.lib;iphlpapi.lib;%(AdditionalDependencies)
+ bin\static_md\genrsakeyd.exe
+ ..\..\..\lib;%(AdditionalLibraryDirectories)
+ true
+ true
+ bin\static_md\genrsakeyd.pdb
+ Console
+ MachineX86
+
+
+
+
+ Disabled
+ OnlyExplicitInline
+ true
+ Speed
+ true
+ .\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Util\include;..\..\..\Crypto\include;%(AdditionalIncludeDirectories)
+ WIN32;NDEBUG;_WINDOWS;WINVER=0x0500;POCO_STATIC;%(PreprocessorDefinitions)
+ true
+ MultiThreadedDLL
+ false
+ true
+ true
+ true
+
+ Level3
+
+ Default
+ %(DisableSpecificWarnings)
+
+
+ iphlpapi.lib;winmm.lib;libeay32md.lib;ssleay32md.lib;ws2_32.lib;iphlpapi.lib;%(AdditionalDependencies)
+ bin\static_md\genrsakey.exe
+ ..\..\..\lib;%(AdditionalLibraryDirectories)
+ false
+ Console
+ true
+ true
+ MachineX86
+
+
+
+
+
+
+
+
diff --git a/Crypto/samples/genrsakey/genrsakey_vs100.vcxproj.filters b/Crypto/samples/genrsakey/genrsakey_vs100.vcxproj.filters
new file mode 100644
index 000000000..81471ebd2
--- /dev/null
+++ b/Crypto/samples/genrsakey/genrsakey_vs100.vcxproj.filters
@@ -0,0 +1,16 @@
+
+
+
+
+ {2f5e2e4e-b67c-4294-a0e8-ab365c385188}
+
+
+ {ddceacf3-18d3-4f0e-9c38-52ef1facbdb2}
+
+
+
+
+ Source Files
+
+
+
\ No newline at end of file
diff --git a/Crypto/samples/genrsakey/genrsakey_vs100.vcxproj.user b/Crypto/samples/genrsakey/genrsakey_vs100.vcxproj.user
new file mode 100644
index 000000000..ace9a86ac
--- /dev/null
+++ b/Crypto/samples/genrsakey/genrsakey_vs100.vcxproj.user
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/Crypto/samples/genrsakey/genrsakey_x64_vs100.vcxproj b/Crypto/samples/genrsakey/genrsakey_x64_vs100.vcxproj
new file mode 100644
index 000000000..fdf64b09c
--- /dev/null
+++ b/Crypto/samples/genrsakey/genrsakey_x64_vs100.vcxproj
@@ -0,0 +1,299 @@
+
+
+
+
+ debug_shared
+ x64
+
+
+ debug_static_md
+ x64
+
+
+ debug_static_mt
+ x64
+
+
+ release_shared
+ x64
+
+
+ release_static_md
+ x64
+
+
+ release_static_mt
+ x64
+
+
+
+ genrsakey
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}
+ genrsakey
+ Win32Proj
+
+
+
+ Application
+ MultiByte
+
+
+ Application
+ MultiByte
+
+
+ Application
+ MultiByte
+
+
+ Application
+ MultiByte
+
+
+ Application
+ MultiByte
+
+
+ Application
+ MultiByte
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <_ProjectFileVersion>10.0.30319.1
+ bin64\
+ obj64\$(Configuration)\
+ true
+ bin64\
+ obj64\$(Configuration)\
+ false
+ bin64\static_mt\
+ obj64\$(Configuration)\
+ true
+ bin64\static_mt\
+ obj64\$(Configuration)\
+ false
+ bin64\static_md\
+ obj64\$(Configuration)\
+ true
+ bin64\static_md\
+ obj64\$(Configuration)\
+ false
+ genrsakeyd
+ genrsakeyd
+ genrsakeyd
+ genrsakey
+ genrsakey
+ genrsakey
+
+
+
+ Disabled
+ .\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Util\include;..\..\..\Crypto\include;%(AdditionalIncludeDirectories)
+ WIN32;_DEBUG;_WINDOWS;WINVER=0x0500;%(PreprocessorDefinitions)
+ true
+ true
+ EnableFastChecks
+ MultiThreadedDebugDLL
+ true
+ true
+ true
+ true
+
+ Level3
+ ProgramDatabase
+ Default
+ %(DisableSpecificWarnings)
+
+
+ libeay32mdd.lib;ssleay32mdd.lib;ws2_32.lib;iphlpapi.lib;%(AdditionalDependencies)
+ bin64\genrsakeyd.exe
+ ..\..\..\lib64;%(AdditionalLibraryDirectories)
+ true
+ true
+ bin64\genrsakeyd.pdb
+ Console
+ MachineX64
+
+
+
+
+ Disabled
+ OnlyExplicitInline
+ true
+ Speed
+ true
+ .\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Util\include;..\..\..\Crypto\include;%(AdditionalIncludeDirectories)
+ WIN32;NDEBUG;_WINDOWS;WINVER=0x0500;%(PreprocessorDefinitions)
+ true
+ MultiThreadedDLL
+ false
+ true
+ true
+ true
+
+ Level3
+
+ Default
+ %(DisableSpecificWarnings)
+
+
+ libeay32md.lib;ssleay32md.lib;ws2_32.lib;iphlpapi.lib;%(AdditionalDependencies)
+ bin64\genrsakey.exe
+ ..\..\..\lib64;%(AdditionalLibraryDirectories)
+ false
+ Console
+ true
+ true
+ MachineX64
+
+
+
+
+ Disabled
+ .\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Util\include;..\..\..\Crypto\include;%(AdditionalIncludeDirectories)
+ WIN32;_DEBUG;_WINDOWS;WINVER=0x0500;POCO_STATIC;%(PreprocessorDefinitions)
+ true
+ true
+ EnableFastChecks
+ MultiThreadedDebug
+ true
+ true
+ true
+ true
+
+ Level3
+ ProgramDatabase
+ Default
+ %(DisableSpecificWarnings)
+
+
+ iphlpapi.lib;winmm.lib;libeay32mtd.lib;ssleay32mtd.lib;ws2_32.lib;iphlpapi.lib;%(AdditionalDependencies)
+ bin64\static_mt\genrsakeyd.exe
+ ..\..\..\lib64;%(AdditionalLibraryDirectories)
+ true
+ true
+ bin64\static_mt\genrsakeyd.pdb
+ Console
+ MachineX64
+
+
+
+
+ Disabled
+ OnlyExplicitInline
+ true
+ Speed
+ true
+ .\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Util\include;..\..\..\Crypto\include;%(AdditionalIncludeDirectories)
+ WIN32;NDEBUG;_WINDOWS;WINVER=0x0500;POCO_STATIC;%(PreprocessorDefinitions)
+ true
+ MultiThreaded
+ false
+ true
+ true
+ true
+
+ Level3
+
+ Default
+ %(DisableSpecificWarnings)
+
+
+ iphlpapi.lib;winmm.lib;libeay32mt.lib;ssleay32mt.lib;ws2_32.lib;iphlpapi.lib;%(AdditionalDependencies)
+ bin64\static_mt\genrsakey.exe
+ ..\..\..\lib64;%(AdditionalLibraryDirectories)
+ false
+ Console
+ true
+ true
+ MachineX64
+
+
+
+
+ Disabled
+ .\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Util\include;..\..\..\Crypto\include;%(AdditionalIncludeDirectories)
+ WIN32;_DEBUG;_WINDOWS;WINVER=0x0500;POCO_STATIC;%(PreprocessorDefinitions)
+ true
+ true
+ EnableFastChecks
+ MultiThreadedDebugDLL
+ true
+ true
+ true
+ true
+
+ Level3
+ ProgramDatabase
+ Default
+ %(DisableSpecificWarnings)
+
+
+ iphlpapi.lib;winmm.lib;libeay32mdd.lib;ssleay32mdd.lib;ws2_32.lib;iphlpapi.lib;%(AdditionalDependencies)
+ bin64\static_md\genrsakeyd.exe
+ ..\..\..\lib64;%(AdditionalLibraryDirectories)
+ true
+ true
+ bin64\static_md\genrsakeyd.pdb
+ Console
+ MachineX64
+
+
+
+
+ Disabled
+ OnlyExplicitInline
+ true
+ Speed
+ true
+ .\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Util\include;..\..\..\Crypto\include;%(AdditionalIncludeDirectories)
+ WIN32;NDEBUG;_WINDOWS;WINVER=0x0500;POCO_STATIC;%(PreprocessorDefinitions)
+ true
+ MultiThreadedDLL
+ false
+ true
+ true
+ true
+
+ Level3
+
+ Default
+ %(DisableSpecificWarnings)
+
+
+ iphlpapi.lib;winmm.lib;libeay32md.lib;ssleay32md.lib;ws2_32.lib;iphlpapi.lib;%(AdditionalDependencies)
+ bin64\static_md\genrsakey.exe
+ ..\..\..\lib64;%(AdditionalLibraryDirectories)
+ false
+ Console
+ true
+ true
+ MachineX64
+
+
+
+
+
+
+
+
diff --git a/Crypto/samples/genrsakey/genrsakey_x64_vs100.vcxproj.filters b/Crypto/samples/genrsakey/genrsakey_x64_vs100.vcxproj.filters
new file mode 100644
index 000000000..34b7ea217
--- /dev/null
+++ b/Crypto/samples/genrsakey/genrsakey_x64_vs100.vcxproj.filters
@@ -0,0 +1,16 @@
+
+
+
+
+ {d5e71565-88ad-4723-be38-89454c846186}
+
+
+ {956a2b06-5184-458d-8776-0a95bd329772}
+
+
+
+
+ Source Files
+
+
+
\ No newline at end of file
diff --git a/Crypto/samples/genrsakey/genrsakey_x64_vs100.vcxproj.user b/Crypto/samples/genrsakey/genrsakey_x64_vs100.vcxproj.user
new file mode 100644
index 000000000..ace9a86ac
--- /dev/null
+++ b/Crypto/samples/genrsakey/genrsakey_x64_vs100.vcxproj.user
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/Crypto/samples/genrsakey/src/genrsakey.cpp b/Crypto/samples/genrsakey/src/genrsakey.cpp
index 212d6e341..83e22e20c 100644
--- a/Crypto/samples/genrsakey/src/genrsakey.cpp
+++ b/Crypto/samples/genrsakey/src/genrsakey.cpp
@@ -1,212 +1,218 @@
-//
-// genrsakey.cpp
-//
+//
+// 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
-
-
-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(this, &RSAApp::handleHelp)));
-
- options.addOption(
- Option("?", "?", "display help information on command line arguments")
- .required(false)
- .repeatable(false)
- .callback(OptionCallback(this, &RSAApp::handleHelp)));
-
- options.addOption(
- Option("key", "k", "define the key length")
- .required(false)
- .repeatable(false)
- .argument("512|1024|2048|4096")
- .callback(OptionCallback(this, &RSAApp::handleKeyLength)));
-
- options.addOption(
- Option("exponent", "e", "defines the exponent of the key")
- .required(false)
- .repeatable(false)
- .argument("small|large")
- .callback(OptionCallback(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(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(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& 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)
+//
+// 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
+
+
+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()
+ {
+ Poco::Crypto::initializeCrypto();
+ }
+
+ ~RSAApp()
+ {
+ Poco::Crypto::uninitializeCrypto();
+ }
+
+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(this, &RSAApp::handleHelp)));
+
+ options.addOption(
+ Option("?", "?", "display help information on command line arguments")
+ .required(false)
+ .repeatable(false)
+ .callback(OptionCallback(this, &RSAApp::handleHelp)));
+
+ options.addOption(
+ Option("key", "k", "define the key length")
+ .required(false)
+ .repeatable(false)
+ .argument("512|1024|2048|4096")
+ .callback(OptionCallback(this, &RSAApp::handleKeyLength)));
+
+ options.addOption(
+ Option("exponent", "e", "defines the exponent of the key")
+ .required(false)
+ .repeatable(false)
+ .argument("small|large")
+ .callback(OptionCallback(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(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(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& 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)
diff --git a/Crypto/samples/samples_vs100.sln b/Crypto/samples/samples_vs100.sln
new file mode 100644
index 000000000..f2a18f66f
--- /dev/null
+++ b/Crypto/samples/samples_vs100.sln
@@ -0,0 +1,37 @@
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "genrsakey", "genrsakey\genrsakey_vs100.vcxproj", "{D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ debug_shared|Win32 = debug_shared|Win32
+ release_shared|Win32 = release_shared|Win32
+ debug_static_mt|Win32 = debug_static_mt|Win32
+ release_static_mt|Win32 = release_static_mt|Win32
+ debug_static_md|Win32 = debug_static_md|Win32
+ release_static_md|Win32 = release_static_md|Win32
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.debug_shared|Win32.Build.0 = debug_shared|Win32
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.debug_shared|Win32.Deploy.0 = debug_shared|Win32
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.release_shared|Win32.ActiveCfg = release_shared|Win32
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.release_shared|Win32.Build.0 = release_shared|Win32
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.release_shared|Win32.Deploy.0 = release_shared|Win32
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.debug_static_mt|Win32.ActiveCfg = debug_static_mt|Win32
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.debug_static_mt|Win32.Build.0 = debug_static_mt|Win32
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.debug_static_mt|Win32.Deploy.0 = debug_static_mt|Win32
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.release_static_mt|Win32.ActiveCfg = release_static_mt|Win32
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.release_static_mt|Win32.Build.0 = release_static_mt|Win32
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.release_static_mt|Win32.Deploy.0 = release_static_mt|Win32
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.debug_static_md|Win32.ActiveCfg = debug_static_md|Win32
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.debug_static_md|Win32.Build.0 = debug_static_md|Win32
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.debug_static_md|Win32.Deploy.0 = debug_static_md|Win32
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.release_static_md|Win32.ActiveCfg = release_static_md|Win32
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.release_static_md|Win32.Build.0 = release_static_md|Win32
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.release_static_md|Win32.Deploy.0 = release_static_md|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/Crypto/samples/samples_x64_vs100.sln b/Crypto/samples/samples_x64_vs100.sln
new file mode 100644
index 000000000..8fe3e1038
--- /dev/null
+++ b/Crypto/samples/samples_x64_vs100.sln
@@ -0,0 +1,37 @@
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "genrsakey", "genrsakey\genrsakey_x64_vs100.vcxproj", "{D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ debug_shared|x64 = debug_shared|x64
+ release_shared|x64 = release_shared|x64
+ debug_static_mt|x64 = debug_static_mt|x64
+ release_static_mt|x64 = release_static_mt|x64
+ debug_static_md|x64 = debug_static_md|x64
+ release_static_md|x64 = release_static_md|x64
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.debug_shared|x64.ActiveCfg = debug_shared|x64
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.debug_shared|x64.Build.0 = debug_shared|x64
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.debug_shared|x64.Deploy.0 = debug_shared|x64
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.release_shared|x64.ActiveCfg = release_shared|x64
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.release_shared|x64.Build.0 = release_shared|x64
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.release_shared|x64.Deploy.0 = release_shared|x64
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.debug_static_mt|x64.ActiveCfg = debug_static_mt|x64
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.debug_static_mt|x64.Build.0 = debug_static_mt|x64
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.debug_static_mt|x64.Deploy.0 = debug_static_mt|x64
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.release_static_mt|x64.ActiveCfg = release_static_mt|x64
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.release_static_mt|x64.Build.0 = release_static_mt|x64
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.release_static_mt|x64.Deploy.0 = release_static_mt|x64
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.debug_static_md|x64.ActiveCfg = debug_static_md|x64
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.debug_static_md|x64.Build.0 = debug_static_md|x64
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.debug_static_md|x64.Deploy.0 = debug_static_md|x64
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.release_static_md|x64.ActiveCfg = release_static_md|x64
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.release_static_md|x64.Build.0 = release_static_md|x64
+ {D6BE1AD9-4CB6-3184-8DF8-5210AE7D6947}.release_static_md|x64.Deploy.0 = release_static_md|x64
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/Crypto/src/Cipher.cpp b/Crypto/src/Cipher.cpp
index b89d75c63..58719b909 100644
--- a/Crypto/src/Cipher.cpp
+++ b/Crypto/src/Cipher.cpp
@@ -93,16 +93,26 @@ void Cipher::encrypt(std::istream& source, std::ostream& sink, Encoding encoding
break;
case ENC_BASE64:
+ case ENC_BASE64_NO_LF:
{
Poco::Base64Encoder encoder(sink);
+ if (encoding == ENC_BASE64_NO_LF)
+ {
+ encoder.rdbuf()->setLineLength(0);
+ }
StreamCopier::copyStream(encryptor, encoder);
encoder.close();
}
break;
case ENC_BINHEX:
+ case ENC_BINHEX_NO_LF:
{
Poco::HexBinaryEncoder encoder(sink);
+ if (encoding == ENC_BINHEX_NO_LF)
+ {
+ encoder.rdbuf()->setLineLength(0);
+ }
StreamCopier::copyStream(encryptor, encoder);
encoder.close();
}
@@ -126,6 +136,7 @@ void Cipher::decrypt(std::istream& source, std::ostream& sink, Encoding encoding
break;
case ENC_BASE64:
+ case ENC_BASE64_NO_LF:
{
Poco::Base64Decoder decoder(source);
StreamCopier::copyStream(decoder, decryptor);
@@ -134,6 +145,7 @@ void Cipher::decrypt(std::istream& source, std::ostream& sink, Encoding encoding
break;
case ENC_BINHEX:
+ case ENC_BINHEX_NO_LF:
{
Poco::HexBinaryDecoder decoder(source);
StreamCopier::copyStream(decoder, decryptor);
diff --git a/Crypto/src/CipherFactory.cpp b/Crypto/src/CipherFactory.cpp
index 171cb65fc..974940d0c 100644
--- a/Crypto/src/CipherFactory.cpp
+++ b/Crypto/src/CipherFactory.cpp
@@ -50,35 +50,25 @@ 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();
- }
+}
+
+
+namespace
+{
+ static Poco::SingletonHolder holder;
}
CipherFactory& CipherFactory::defaultFactory()
{
- static Poco::SingletonHolder holder;
- return *holder.get();
+ return *holder.get();
}
diff --git a/Crypto/src/CipherImpl.cpp b/Crypto/src/CipherImpl.cpp
index b930b4da8..e7aef7b5c 100644
--- a/Crypto/src/CipherImpl.cpp
+++ b/Crypto/src/CipherImpl.cpp
@@ -176,7 +176,7 @@ namespace
CipherImpl::CipherImpl(const CipherKey& key):
- _key(key)
+ _key(key)
{
}
diff --git a/Crypto/src/CipherKey.cpp b/Crypto/src/CipherKey.cpp
index 65c445431..4b570c055 100644
--- a/Crypto/src/CipherKey.cpp
+++ b/Crypto/src/CipherKey.cpp
@@ -1,72 +1,67 @@
-//
-// CipherKey.cpp
-//
-// $Id: //poco/Main/Crypto/src/CipherKey.cpp#2 $
-//
-// Library: Crypto
-// Package: Cipher
-// 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
+//
+// CipherKey.cpp
+//
+// $Id: //poco/1.4/Crypto/src/CipherKey.cpp#1 $
+//
+// Library: Crypto
+// Package: Cipher
+// 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
diff --git a/Crypto/src/CipherKeyImpl.cpp b/Crypto/src/CipherKeyImpl.cpp
index a7b9abd31..fabbead67 100644
--- a/Crypto/src/CipherKeyImpl.cpp
+++ b/Crypto/src/CipherKeyImpl.cpp
@@ -1,218 +1,218 @@
-//
-// CipherKeyImpl.cpp
-//
-// $Id: //poco/Main/Crypto/src/CipherKeyImpl.cpp#3 $
-//
-// Library: Crypto
-// Package: Cipher
-// 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
-#include
-
-
-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(key),
- _iv(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");
-}
-
-
-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(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 = static_cast(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(password.data()),
- static_cast(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
+//
+// CipherKeyImpl.cpp
+//
+// $Id: //poco/1.4/Crypto/src/CipherKeyImpl.cpp#1 $
+//
+// Library: Crypto
+// Package: Cipher
+// 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
+#include
+
+
+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(key),
+ _iv(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");
+}
+
+
+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(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 = static_cast(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(password.data()),
+ static_cast(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
diff --git a/Crypto/src/CryptoStream.cpp b/Crypto/src/CryptoStream.cpp
index e373f3a5d..67327b64e 100644
--- a/Crypto/src/CryptoStream.cpp
+++ b/Crypto/src/CryptoStream.cpp
@@ -54,35 +54,29 @@ namespace Crypto {
//
-CryptoStreamBuf::CryptoStreamBuf(
- std::istream& istr,
- CryptoTransform* pTransform,
- std::streamsize bufferSize) :
- Poco::BufferedStreamBuf(bufferSize, std::ios::in),
- _pTransform(pTransform),
- _pIstr(&istr),
- _pOstr(0),
- _eof(false),
- _buffer(bufferSize)
+CryptoStreamBuf::CryptoStreamBuf(std::istream& istr, CryptoTransform* pTransform, std::streamsize bufferSize):
+ Poco::BufferedStreamBuf(bufferSize, std::ios::in),
+ _pTransform(pTransform),
+ _pIstr(&istr),
+ _pOstr(0),
+ _eof(false),
+ _buffer(static_cast(bufferSize))
{
- poco_check_ptr(pTransform);
- poco_assert(bufferSize >= 2 * pTransform->blockSize());
+ poco_check_ptr (pTransform);
+ poco_assert (bufferSize > 2 * pTransform->blockSize());
}
-CryptoStreamBuf::CryptoStreamBuf(
- std::ostream& ostr,
- CryptoTransform* pTransform,
- std::streamsize bufferSize) :
- Poco::BufferedStreamBuf(bufferSize, std::ios::out),
- _pTransform(pTransform),
- _pIstr(0),
- _pOstr(&ostr),
- _eof(false),
- _buffer(bufferSize)
+CryptoStreamBuf::CryptoStreamBuf(std::ostream& ostr, CryptoTransform* pTransform, std::streamsize bufferSize):
+ Poco::BufferedStreamBuf(bufferSize, std::ios::out),
+ _pTransform(pTransform),
+ _pIstr(0),
+ _pOstr(&ostr),
+ _eof(false),
+ _buffer(static_cast(bufferSize))
{
- poco_check_ptr(pTransform);
- poco_assert(bufferSize >= 2 * pTransform->blockSize());
+ poco_check_ptr (pTransform);
+ poco_assert (bufferSize > 2 * pTransform->blockSize());
}
@@ -116,7 +110,7 @@ void CryptoStreamBuf::close()
_pOstr = 0;
// Finalize transformation.
- int n = _pTransform->finalize(_buffer.begin(), static_cast(_buffer.size()));
+ std::streamsize n = _pTransform->finalize(_buffer.begin(), static_cast(_buffer.size()));
if (n > 0)
{
@@ -137,12 +131,12 @@ int CryptoStreamBuf::readFromDevice(char* buffer, std::streamsize length)
while (!_eof)
{
- int m = static_cast(length) - count - static_cast(_pTransform->blockSize() - 1);
+ int m = (static_cast(length) - count)/2 - static_cast(_pTransform->blockSize());
// 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())
+ // comparison might give false results for m < 0.
+ if (m <= 0)
break;
int n = 0;
@@ -158,18 +152,18 @@ int CryptoStreamBuf::readFromDevice(char* buffer, std::streamsize length)
_eof = true;
// No more data, finalize transformation
- count += _pTransform->finalize(
+ count += static_cast(_pTransform->finalize(
reinterpret_cast(buffer + count),
- length - count);
+ static_cast(length) - count));
}
else
{
// Transform next chunk of data
- count += _pTransform->transform(
+ count += static_cast(_pTransform->transform(
_buffer.begin(),
n,
reinterpret_cast(buffer + count),
- length - count);
+ static_cast(length) - count));
}
}
@@ -182,18 +176,18 @@ int CryptoStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
if (!_pOstr)
return 0;
- std::size_t maxChunkSize = _buffer.size() - (_pTransform->blockSize() - 1);
+ std::size_t maxChunkSize = _buffer.size()/2;
std::size_t count = 0;
while (count < length)
{
// Truncate chunk size so that the maximum output fits into _buffer.
- std::size_t n = length - count;
+ std::size_t n = static_cast(length) - count;
if (n > maxChunkSize)
n = maxChunkSize;
// Transform next chunk of data
- int k = _pTransform->transform(
+ std::streamsize k = _pTransform->transform(
reinterpret_cast(buffer + count),
static_cast(n),
_buffer.begin(),
@@ -221,21 +215,15 @@ int CryptoStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
//
-CryptoIOS::CryptoIOS(
- std::istream& istr,
- CryptoTransform* pTransform,
- std::streamsize bufferSize) :
- _buf(istr, pTransform, bufferSize)
+CryptoIOS::CryptoIOS(std::istream& istr, CryptoTransform* pTransform, std::streamsize bufferSize):
+ _buf(istr, pTransform, bufferSize)
{
poco_ios_init(&_buf);
}
-CryptoIOS::CryptoIOS(
- std::ostream& ostr,
- CryptoTransform* pTransform,
- std::streamsize bufferSize) :
- _buf(ostr, pTransform, bufferSize)
+CryptoIOS::CryptoIOS(std::ostream& ostr, CryptoTransform* pTransform, std::streamsize bufferSize):
+ _buf(ostr, pTransform, bufferSize)
{
poco_ios_init(&_buf);
}
@@ -257,22 +245,16 @@ CryptoStreamBuf* CryptoIOS::rdbuf()
//
-CryptoInputStream::CryptoInputStream(
- std::istream& istr,
- CryptoTransform* pTransform,
- std::streamsize bufferSize) :
- CryptoIOS(istr, pTransform, bufferSize),
- std::istream(&_buf)
+CryptoInputStream::CryptoInputStream(std::istream& istr, CryptoTransform* pTransform, std::streamsize bufferSize):
+ CryptoIOS(istr, pTransform, bufferSize),
+ std::istream(&_buf)
{
}
-CryptoInputStream::CryptoInputStream(
- std::istream& istr,
- Cipher& cipher,
- std::streamsize bufferSize) :
- CryptoIOS(istr, cipher.createEncryptor(), bufferSize),
- std::istream(&_buf)
+CryptoInputStream::CryptoInputStream(std::istream& istr, Cipher& cipher, std::streamsize bufferSize):
+ CryptoIOS(istr, cipher.createEncryptor(), bufferSize),
+ std::istream(&_buf)
{
}
@@ -287,22 +269,16 @@ CryptoInputStream::~CryptoInputStream()
//
-CryptoOutputStream::CryptoOutputStream(
- std::ostream& ostr,
- CryptoTransform* pTransform,
- std::streamsize bufferSize) :
- CryptoIOS(ostr, pTransform, bufferSize),
- std::ostream(&_buf)
+CryptoOutputStream::CryptoOutputStream(std::ostream& ostr, CryptoTransform* pTransform, std::streamsize bufferSize):
+ CryptoIOS(ostr, pTransform, bufferSize),
+ std::ostream(&_buf)
{
}
-CryptoOutputStream::CryptoOutputStream(
- std::ostream& ostr,
- Cipher& cipher,
- std::streamsize bufferSize):
- CryptoIOS(ostr, cipher.createDecryptor(), bufferSize),
- std::ostream(&_buf)
+CryptoOutputStream::CryptoOutputStream(std::ostream& ostr, Cipher& cipher, std::streamsize bufferSize):
+ CryptoIOS(ostr, cipher.createDecryptor(), bufferSize),
+ std::ostream(&_buf)
{
}
@@ -314,7 +290,87 @@ CryptoOutputStream::~CryptoOutputStream()
void CryptoOutputStream::close()
{
- _buf.close();
+ _buf.close();
+}
+
+
+//
+// EncryptingInputStream
+//
+
+
+EncryptingInputStream::EncryptingInputStream(std::istream& istr, Cipher& cipher, std::streamsize bufferSize):
+ CryptoIOS(istr, cipher.createEncryptor(), bufferSize),
+ std::istream(&_buf)
+{
+}
+
+
+EncryptingInputStream::~EncryptingInputStream()
+{
+}
+
+
+//
+// EncryptingOuputStream
+//
+
+
+EncryptingOutputStream::EncryptingOutputStream(std::ostream& ostr, Cipher& cipher, std::streamsize bufferSize):
+ CryptoIOS(ostr, cipher.createEncryptor(), bufferSize),
+ std::ostream(&_buf)
+{
+}
+
+
+EncryptingOutputStream::~EncryptingOutputStream()
+{
+}
+
+
+void EncryptingOutputStream::close()
+{
+ _buf.close();
+}
+
+
+//
+// DecryptingInputStream
+//
+
+
+DecryptingInputStream::DecryptingInputStream(std::istream& istr, Cipher& cipher, std::streamsize bufferSize):
+ CryptoIOS(istr, cipher.createDecryptor(), bufferSize),
+ std::istream(&_buf)
+{
+}
+
+
+DecryptingInputStream::~DecryptingInputStream()
+{
+}
+
+
+//
+// DecryptingOuputStream
+//
+
+
+DecryptingOutputStream::DecryptingOutputStream(std::ostream& ostr, Cipher& cipher, std::streamsize bufferSize):
+ CryptoIOS(ostr, cipher.createDecryptor(), bufferSize),
+ std::ostream(&_buf)
+{
+}
+
+
+DecryptingOutputStream::~DecryptingOutputStream()
+{
+}
+
+
+void DecryptingOutputStream::close()
+{
+ _buf.close();
}
diff --git a/Crypto/src/OpenSSLInitializer.cpp b/Crypto/src/OpenSSLInitializer.cpp
index 4f55e1f36..0f6bd4a16 100644
--- a/Crypto/src/OpenSSLInitializer.cpp
+++ b/Crypto/src/OpenSSLInitializer.cpp
@@ -1,150 +1,172 @@
-//
-// OpenSSLInitializer.cpp
-//
-// $Id: //poco/Main/Crypto/src/OpenSSLInitializer.cpp#1 $
-//
-// Library: Crypto
-// Package: CryotpCore
-// Module: OpenSSLInitializer
-//
-// Copyright (c) 2006-2009, 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/OpenSSLInitializer.h"
-#include "Poco/RandomStream.h"
-#include "Poco/Thread.h"
-#include
-#include
-#include
-#include
-
-
-using Poco::RandomInputStream;
-using Poco::Thread;
-using Poco::FastMutex;
-
-
-namespace Poco {
-namespace Crypto {
-
-
-FastMutex* OpenSSLInitializer::_mutexes(0);
-int OpenSSLInitializer::_rc(0);
-
-
-static OpenSSLInitializer initializer;
-
-
-OpenSSLInitializer::OpenSSLInitializer()
-{
- initialize();
-}
-
-
-OpenSSLInitializer::~OpenSSLInitializer()
-{
- uninitialize();
-}
-
-
-void OpenSSLInitializer::initialize()
-{
- if (++_rc == 1)
- {
- poco_assert (1 == SSL_library_init()); // always returns 1
- SSL_load_error_strings();
-
- char seed[SEEDSIZE];
- RandomInputStream rnd;
- rnd.read(seed, sizeof(seed));
- RAND_seed(seed, SEEDSIZE);
-
- int nMutexes = CRYPTO_num_locks();
- _mutexes = new FastMutex[nMutexes];
- CRYPTO_set_locking_callback(&OpenSSLInitializer::lock);
-#ifndef POCO_OS_FAMILY_WINDOWS // SF# 1828231: random unhandled exceptions when linking with ssl
- CRYPTO_set_id_callback(&OpenSSLInitializer::id);
-#endif
- CRYPTO_set_dynlock_create_callback(&OpenSSLInitializer::dynlockCreate);
- CRYPTO_set_dynlock_lock_callback(&OpenSSLInitializer::dynlock);
- CRYPTO_set_dynlock_destroy_callback(&OpenSSLInitializer::dynlockDestroy);
- }
-}
-
-
-void OpenSSLInitializer::uninitialize()
-{
- if (--_rc == 0)
- {
- EVP_cleanup();
- ERR_free_strings();
- CRYPTO_set_locking_callback(0);
- delete [] _mutexes;
- }
-}
-
-
-void OpenSSLInitializer::lock(int mode, int n, const char* file, int line)
-{
- if (mode & CRYPTO_LOCK)
- _mutexes[n].lock();
- else
- _mutexes[n].unlock();
-}
-
-
-unsigned long OpenSSLInitializer::id()
-{
- Thread* pThread = Thread::current();
- return pThread ? pThread->id() : 0;
-}
-
-
-struct CRYPTO_dynlock_value* OpenSSLInitializer::dynlockCreate(const char* file, int line)
-{
- return new CRYPTO_dynlock_value;
-}
-
-
-void OpenSSLInitializer::dynlock(int mode, struct CRYPTO_dynlock_value* lock, const char* file, int line)
-{
- poco_check_ptr (lock);
-
- if (mode & CRYPTO_LOCK)
- lock->_mutex.lock();
- else
- lock->_mutex.unlock();
-}
-
-
-void OpenSSLInitializer::dynlockDestroy(struct CRYPTO_dynlock_value* lock, const char* file, int line)
-{
- delete lock;
-}
-
-
-} } // namespace Poco::Crypto
+//
+// OpenSSLInitializer.cpp
+//
+// $Id: //poco/1.4/Crypto/src/OpenSSLInitializer.cpp#1 $
+//
+// Library: Crypto
+// Package: CryotpCore
+// Module: OpenSSLInitializer
+//
+// Copyright (c) 2006-2009, 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/OpenSSLInitializer.h"
+#include "Poco/RandomStream.h"
+#include "Poco/Thread.h"
+#include
+#include
+#include
+#include
+#if SSLEAY_VERSION_NUMBER >= 0x0907000L
+#include
+#endif
+
+
+using Poco::RandomInputStream;
+using Poco::Thread;
+
+
+namespace Poco {
+namespace Crypto {
+
+
+Poco::FastMutex* OpenSSLInitializer::_mutexes(0);
+Poco::FastMutex OpenSSLInitializer::_mutex;
+int OpenSSLInitializer::_rc(0);
+
+
+OpenSSLInitializer::OpenSSLInitializer()
+{
+ initialize();
+}
+
+
+OpenSSLInitializer::~OpenSSLInitializer()
+{
+ uninitialize();
+}
+
+
+void OpenSSLInitializer::initialize()
+{
+ Poco::FastMutex::ScopedLock lock(_mutex);
+
+ if (++_rc == 1)
+ {
+#if OPENSSL_VERSION_NUMBER >= 0x0907000L
+ OPENSSL_config(NULL);
+#endif
+ SSL_library_init();
+ SSL_load_error_strings();
+ OpenSSL_add_all_algorithms();
+
+ char seed[SEEDSIZE];
+ RandomInputStream rnd;
+ rnd.read(seed, sizeof(seed));
+ RAND_seed(seed, SEEDSIZE);
+
+ int nMutexes = CRYPTO_num_locks();
+ _mutexes = new Poco::FastMutex[nMutexes];
+ CRYPTO_set_locking_callback(&OpenSSLInitializer::lock);
+#ifndef POCO_OS_FAMILY_WINDOWS // SF# 1828231: random unhandled exceptions when linking with ssl
+ CRYPTO_set_id_callback(&OpenSSLInitializer::id);
+#endif
+ CRYPTO_set_dynlock_create_callback(&OpenSSLInitializer::dynlockCreate);
+ CRYPTO_set_dynlock_lock_callback(&OpenSSLInitializer::dynlock);
+ CRYPTO_set_dynlock_destroy_callback(&OpenSSLInitializer::dynlockDestroy);
+ }
+}
+
+
+void OpenSSLInitializer::uninitialize()
+{
+ Poco::FastMutex::ScopedLock lock(_mutex);
+
+ if (--_rc == 0)
+ {
+ EVP_cleanup();
+ ERR_free_strings();
+ CRYPTO_set_locking_callback(0);
+ delete [] _mutexes;
+ }
+}
+
+
+void OpenSSLInitializer::lock(int mode, int n, const char* file, int line)
+{
+ if (mode & CRYPTO_LOCK)
+ _mutexes[n].lock();
+ else
+ _mutexes[n].unlock();
+}
+
+
+unsigned long OpenSSLInitializer::id()
+{
+ // Note: we use an old-style C cast here because
+ // neither static_cast<> nor reinterpret_cast<>
+ // work uniformly across all platforms.
+ return (unsigned long) Poco::Thread::currentTid();
+}
+
+
+struct CRYPTO_dynlock_value* OpenSSLInitializer::dynlockCreate(const char* file, int line)
+{
+ return new CRYPTO_dynlock_value;
+}
+
+
+void OpenSSLInitializer::dynlock(int mode, struct CRYPTO_dynlock_value* lock, const char* file, int line)
+{
+ poco_check_ptr (lock);
+
+ if (mode & CRYPTO_LOCK)
+ lock->_mutex.lock();
+ else
+ lock->_mutex.unlock();
+}
+
+
+void OpenSSLInitializer::dynlockDestroy(struct CRYPTO_dynlock_value* lock, const char* file, int line)
+{
+ delete lock;
+}
+
+
+void initializeCrypto()
+{
+ OpenSSLInitializer::initialize();
+}
+
+
+void uninitializeCrypto()
+{
+ OpenSSLInitializer::uninitialize();
+}
+
+
+} } // namespace Poco::Crypto
diff --git a/Crypto/src/RSACipherImpl.cpp b/Crypto/src/RSACipherImpl.cpp
index 735deeb47..ed8c7ea01 100644
--- a/Crypto/src/RSACipherImpl.cpp
+++ b/Crypto/src/RSACipherImpl.cpp
@@ -1,333 +1,340 @@
-//
-// RSACipherImpl.cpp
-//
-// $Id: //poco/Main/Crypto/src/RSACipherImpl.cpp#2 $
-//
-// Library: Crypto
-// Package: RSA
-// 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
-#include
-#include
-
-
-namespace Poco {
-namespace Crypto {
-
-
-namespace
-{
- 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);
- }
-
-
- int mapPaddingMode(RSAPaddingMode paddingMode)
- {
- switch (paddingMode)
- {
- case RSA_PADDING_PKCS1:
- return RSA_PKCS1_PADDING;
- case RSA_PADDING_PKCS1_OAEP:
- return RSA_PKCS1_OAEP_PADDING;
- case RSA_PADDING_SSLV23:
- return RSA_SSLV23_PADDING;
- case RSA_PADDING_NONE:
- return RSA_NO_PADDING;
- default:
- poco_bugcheck();
- return RSA_NO_PADDING;
- }
- }
-
-
- class RSAEncryptImpl: public CryptoTransform
- {
- public:
- enum
- {
- OVERFLOW = 11
- };
-
- RSAEncryptImpl(const RSA* pRSA, RSAPaddingMode paddingMode);
- ~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:
- const RSA* _pRSA;
- RSAPaddingMode _paddingMode;
- std::streamsize _pos;
- unsigned char* _pBuf;
- };
-
-
- RSAEncryptImpl::RSAEncryptImpl(const RSA* pRSA, RSAPaddingMode paddingMode):
- _pRSA(pRSA),
- _paddingMode(paddingMode),
- _pos(0),
- _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 = static_cast(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(_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(_pRSA), mapPaddingMode(_paddingMode));
- if (rc == -1)
- throwError();
- }
-
- return rc;
- }
-
-
- class RSADecryptImpl: public CryptoTransform
- {
- public:
- enum
- {
- OVERFLOW = 11
- };
-
- RSADecryptImpl(const RSA* pRSA, RSAPaddingMode paddingMode);
- ~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:
- const RSA* _pRSA;
- RSAPaddingMode _paddingMode;
- std::streamsize _pos;
- unsigned char* _pBuf;
- };
-
-
- RSADecryptImpl::RSADecryptImpl(const RSA* pRSA, RSAPaddingMode paddingMode):
- _pRSA(pRSA),
- _paddingMode(paddingMode),
- _pos(0),
- _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 = static_cast(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(_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(_pRSA), mapPaddingMode(_paddingMode));
- if (rc == -1)
- throwError();
- }
-
- return rc;
- }
-}
-
-
-RSACipherImpl::RSACipherImpl(const RSAKey& key, RSAPaddingMode paddingMode):
- _key(key),
- _paddingMode(paddingMode)
-{
-}
-
-
-RSACipherImpl::~RSACipherImpl()
-{
-}
-
-
-CryptoTransform* RSACipherImpl::createEncryptor()
-{
- return new RSAEncryptImpl(_key.impl()->getRSA(), _paddingMode);
-}
-
-
-CryptoTransform* RSACipherImpl::createDecryptor()
-{
- return new RSADecryptImpl(_key.impl()->getRSA(), _paddingMode);
-}
-
-
-} } // namespace Poco::Crypto
+//
+// RSACipherImpl.cpp
+//
+// $Id: //poco/1.4/Crypto/src/RSACipherImpl.cpp#1 $
+//
+// Library: Crypto
+// Package: RSA
+// 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
+#include
+#include
+
+
+namespace Poco {
+namespace Crypto {
+
+
+namespace
+{
+ 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);
+ }
+
+
+ int mapPaddingMode(RSAPaddingMode paddingMode)
+ {
+ switch (paddingMode)
+ {
+ case RSA_PADDING_PKCS1:
+ return RSA_PKCS1_PADDING;
+ case RSA_PADDING_PKCS1_OAEP:
+ return RSA_PKCS1_OAEP_PADDING;
+ case RSA_PADDING_SSLV23:
+ return RSA_SSLV23_PADDING;
+ case RSA_PADDING_NONE:
+ return RSA_NO_PADDING;
+ default:
+ poco_bugcheck();
+ return RSA_NO_PADDING;
+ }
+ }
+
+
+ class RSAEncryptImpl: public CryptoTransform
+ {
+ public:
+ RSAEncryptImpl(const RSA* pRSA, RSAPaddingMode paddingMode);
+ ~RSAEncryptImpl();
+
+ std::size_t blockSize() const;
+ std::size_t maxDataSize() 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 RSA* _pRSA;
+ RSAPaddingMode _paddingMode;
+ std::streamsize _pos;
+ unsigned char* _pBuf;
+ };
+
+
+ RSAEncryptImpl::RSAEncryptImpl(const RSA* pRSA, RSAPaddingMode paddingMode):
+ _pRSA(pRSA),
+ _paddingMode(paddingMode),
+ _pos(0),
+ _pBuf(0)
+ {
+ _pBuf = new unsigned char[blockSize()];
+ }
+
+
+ RSAEncryptImpl::~RSAEncryptImpl()
+ {
+ delete [] _pBuf;
+ }
+
+
+ std::size_t RSAEncryptImpl::blockSize() const
+ {
+ return RSA_size(_pRSA);
+ }
+
+
+ std::size_t RSAEncryptImpl::maxDataSize() const
+ {
+ std::size_t size = blockSize();
+ switch (_paddingMode)
+ {
+ case RSA_PADDING_PKCS1:
+ case RSA_PADDING_SSLV23:
+ size -= 11;
+ break;
+ case RSA_PADDING_PKCS1_OAEP:
+ size -= 41;
+ break;
+ default:
+ break;
+ }
+ return size;
+ }
+
+
+ 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 maxSize = static_cast(maxDataSize());
+ std::streamsize rsaSize = static_cast(blockSize());
+ poco_assert_dbg(_pos <= maxSize);
+ 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 (maxSize >= _pos);
+ std::streamsize missing = maxSize - _pos;
+ if (missing == 0)
+ {
+ poco_assert (outputLength >= rsaSize);
+ int n = RSA_public_encrypt(static_cast(maxSize), _pBuf, output, const_cast(_pRSA), mapPaddingMode(_paddingMode));
+ if (n == -1)
+ throwError();
+ rc += n;
+ output += n;
+ outputLength -= n;
+ _pos = 0;
+
+ }
+ else
+ {
+ if (missing > inputLength)
+ missing = inputLength;
+
+ std::memcpy(_pBuf + _pos, input, static_cast(missing));
+ input += missing;
+ _pos += missing;
+ inputLength -= missing;
+ }
+ }
+ return rc;
+ }
+
+
+ std::streamsize RSAEncryptImpl::finalize(unsigned char* output, std::streamsize length)
+ {
+ poco_assert (length >= blockSize());
+ poco_assert (_pos <= maxDataSize());
+ int rc = 0;
+ if (_pos > 0)
+ {
+ rc = RSA_public_encrypt(static_cast(_pos), _pBuf, output, const_cast(_pRSA), mapPaddingMode(_paddingMode));
+ if (rc == -1) throwError();
+ }
+ return rc;
+ }
+
+
+ class RSADecryptImpl: public CryptoTransform
+ {
+ public:
+ RSADecryptImpl(const RSA* pRSA, RSAPaddingMode paddingMode);
+ ~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:
+ const RSA* _pRSA;
+ RSAPaddingMode _paddingMode;
+ std::streamsize _pos;
+ unsigned char* _pBuf;
+ };
+
+
+ RSADecryptImpl::RSADecryptImpl(const RSA* pRSA, RSAPaddingMode paddingMode):
+ _pRSA(pRSA),
+ _paddingMode(paddingMode),
+ _pos(0),
+ _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 = static_cast(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(static_cast(rsaSize), _pBuf, output, const_cast(_pRSA), mapPaddingMode(_paddingMode));
+ if (tmp == -1)
+ throwError();
+ rc += tmp;
+ output += tmp;
+ outputLength -= tmp;
+ _pos = 0;
+
+ }
+ else
+ {
+ if (missing > inputLength)
+ missing = inputLength;
+
+ std::memcpy(_pBuf + _pos, input, static_cast(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(static_cast(_pos), _pBuf, output, const_cast(_pRSA), mapPaddingMode(_paddingMode));
+ if (rc == -1)
+ throwError();
+ }
+ return rc;
+ }
+}
+
+
+RSACipherImpl::RSACipherImpl(const RSAKey& key, RSAPaddingMode paddingMode):
+ _key(key),
+ _paddingMode(paddingMode)
+{
+}
+
+
+RSACipherImpl::~RSACipherImpl()
+{
+}
+
+
+CryptoTransform* RSACipherImpl::createEncryptor()
+{
+ return new RSAEncryptImpl(_key.impl()->getRSA(), _paddingMode);
+}
+
+
+CryptoTransform* RSACipherImpl::createDecryptor()
+{
+ return new RSADecryptImpl(_key.impl()->getRSA(), _paddingMode);
+}
+
+
+} } // namespace Poco::Crypto
diff --git a/Crypto/src/RSADigestEngine.cpp b/Crypto/src/RSADigestEngine.cpp
index 0c9e2579a..289560f9a 100644
--- a/Crypto/src/RSADigestEngine.cpp
+++ b/Crypto/src/RSADigestEngine.cpp
@@ -1,113 +1,113 @@
-//
-// RSADigestEngine.cpp
-//
-// $Id: //poco/Main/Crypto/src/RSADigestEngine.cpp#3 $
-//
-// Library: Crypto
-// Package: RSA
-// 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
-
-
-namespace Poco {
-namespace Crypto {
-
-
-RSADigestEngine::RSADigestEngine(const RSAKey& key, DigestType digestType):
- _key(key),
- _engine(digestType == DIGEST_MD5 ? static_cast(_md5Engine) : static_cast(_sha1Engine)),
- _type(digestType == DIGEST_MD5 ? NID_md5 : NID_sha1)
-{
-}
-
-
-RSADigestEngine::~RSADigestEngine()
-{
-}
-
-
-unsigned RSADigestEngine::digestLength() const
-{
- return _engine.digestLength();
-}
-
-
-void RSADigestEngine::reset()
-{
- _engine.reset();
- _digest.clear();
- _signature.clear();
-}
-
-
-const DigestEngine::Digest& RSADigestEngine::digest()
-{
- if (_digest.empty())
- {
- _digest = _engine.digest();
- }
- return _digest;
-}
-
-
-const DigestEngine::Digest& RSADigestEngine::signature()
-{
- if (_signature.empty())
- {
- digest();
- _signature.resize(_key.size());
- unsigned sigLen = static_cast(_signature.size());
- RSA_sign(_type, &_digest[0], static_cast(_digest.size()), &_signature[0], &sigLen, _key.impl()->getRSA());
- // truncate _sig to sigLen
- if (sigLen < _signature.size())
- _signature.resize(sigLen);
- }
- return _signature;
-}
-
-
-bool RSADigestEngine::verify(const DigestEngine::Digest& sig)
-{
- digest();
- DigestEngine::Digest sigCpy = sig; // copy becausse RSA_verify can modify sigCpy
- int ret = RSA_verify(_type, &_digest[0], static_cast(_digest.size()), &sigCpy[0], static_cast(sigCpy.size()), _key.impl()->getRSA());
- return ret != 0;
-}
-
-
-void RSADigestEngine::updateImpl(const void* data, unsigned length)
-{
- _engine.update(data, length);
-}
-
-
-} } // namespace Poco::Crypto
+//
+// RSADigestEngine.cpp
+//
+// $Id: //poco/1.4/Crypto/src/RSADigestEngine.cpp#1 $
+//
+// Library: Crypto
+// Package: RSA
+// 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
+
+
+namespace Poco {
+namespace Crypto {
+
+
+RSADigestEngine::RSADigestEngine(const RSAKey& key, DigestType digestType):
+ _key(key),
+ _engine(digestType == DIGEST_MD5 ? static_cast(_md5Engine) : static_cast(_sha1Engine)),
+ _type(digestType == DIGEST_MD5 ? NID_md5 : NID_sha1)
+{
+}
+
+
+RSADigestEngine::~RSADigestEngine()
+{
+}
+
+
+unsigned RSADigestEngine::digestLength() const
+{
+ return _engine.digestLength();
+}
+
+
+void RSADigestEngine::reset()
+{
+ _engine.reset();
+ _digest.clear();
+ _signature.clear();
+}
+
+
+const DigestEngine::Digest& RSADigestEngine::digest()
+{
+ if (_digest.empty())
+ {
+ _digest = _engine.digest();
+ }
+ return _digest;
+}
+
+
+const DigestEngine::Digest& RSADigestEngine::signature()
+{
+ if (_signature.empty())
+ {
+ digest();
+ _signature.resize(_key.size());
+ unsigned sigLen = static_cast(_signature.size());
+ RSA_sign(_type, &_digest[0], static_cast(_digest.size()), &_signature[0], &sigLen, _key.impl()->getRSA());
+ // truncate _sig to sigLen
+ if (sigLen < _signature.size())
+ _signature.resize(sigLen);
+ }
+ return _signature;
+}
+
+
+bool RSADigestEngine::verify(const DigestEngine::Digest& sig)
+{
+ digest();
+ DigestEngine::Digest sigCpy = sig; // copy becausse RSA_verify can modify sigCpy
+ int ret = RSA_verify(_type, &_digest[0], static_cast(_digest.size()), &sigCpy[0], static_cast(sigCpy.size()), _key.impl()->getRSA());
+ return ret != 0;
+}
+
+
+void RSADigestEngine::updateImpl(const void* data, unsigned length)
+{
+ _engine.update(data, length);
+}
+
+
+} } // namespace Poco::Crypto
diff --git a/Crypto/src/RSAKey.cpp b/Crypto/src/RSAKey.cpp
index 71d3c2c7e..6575f64e0 100644
--- a/Crypto/src/RSAKey.cpp
+++ b/Crypto/src/RSAKey.cpp
@@ -1,104 +1,127 @@
-//
-// RSAKey.cpp
-//
-// $Id: //poco/Main/Crypto/src/RSAKey.cpp#4 $
-//
-// Library: Crypto
-// Package: RSA
-// 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
-
-
-namespace Poco {
-namespace Crypto {
-
-
-RSAKey::RSAKey(const 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& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase):
- _pImpl(new RSAKeyImpl(publicKeyFile, privateKeyFile, privateKeyPassphrase))
-{
-}
-
-
-RSAKey::RSAKey(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream, const std::string& privateKeyPassphrase):
- _pImpl(new RSAKeyImpl(pPublicKeyStream, pPrivateKeyStream, privateKeyPassphrase))
-{
-}
-
-
-RSAKey::~RSAKey()
-{
-}
-
-
-int RSAKey::size() const
-{
- return _pImpl->size();
-}
-
-
-void RSAKey::save(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase)
-{
- _pImpl->save(publicKeyFile, privateKeyFile, privateKeyPassphrase);
-}
-
-
-void RSAKey::save(std::ostream* pPublicKeyStream, std::ostream* pPrivateKeyStream, const std::string& privateKeyPassphrase)
-{
- _pImpl->save(pPublicKeyStream, pPrivateKeyStream, privateKeyPassphrase);
-}
-
-
-const std::string& RSAKey::name() const
-{
- static const std::string n("rsa");
- return n;
-}
-
-
-} } // namespace Poco::Crypto
+//
+// RSAKey.cpp
+//
+// $Id: //poco/1.4/Crypto/src/RSAKey.cpp#1 $
+//
+// Library: Crypto
+// Package: RSA
+// 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
+
+
+namespace Poco {
+namespace Crypto {
+
+
+RSAKey::RSAKey(const X509Certificate& cert):
+ _pImpl(new RSAKeyImpl(cert))
+{
+}
+
+
+RSAKey::RSAKey(KeyLength keyLength, Exponent exp):
+ _pImpl(0)
+{
+ int keyLen = keyLength;
+ unsigned long expVal = RSA_3;
+ if (exp == EXP_LARGE)
+ expVal = RSA_F4;
+ _pImpl = new RSAKeyImpl(keyLen, expVal);
+}
+
+
+RSAKey::RSAKey(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase):
+ _pImpl(new RSAKeyImpl(publicKeyFile, privateKeyFile, privateKeyPassphrase))
+{
+}
+
+
+RSAKey::RSAKey(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream, const std::string& privateKeyPassphrase):
+ _pImpl(new RSAKeyImpl(pPublicKeyStream, pPrivateKeyStream, privateKeyPassphrase))
+{
+}
+
+
+RSAKey::~RSAKey()
+{
+}
+
+
+int RSAKey::size() const
+{
+ return _pImpl->size();
+}
+
+
+RSAKeyImpl::ByteVec RSAKey::modulus() const
+{
+ return _pImpl->modulus();
+}
+
+
+RSAKeyImpl::ByteVec RSAKey::encryptionExponent() const
+{
+ return _pImpl->encryptionExponent();
+}
+
+
+RSAKeyImpl::ByteVec RSAKey::decryptionExponent() const
+{
+ return _pImpl->decryptionExponent();
+}
+
+
+void RSAKey::save(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase)
+{
+ _pImpl->save(publicKeyFile, privateKeyFile, privateKeyPassphrase);
+}
+
+
+void RSAKey::save(std::ostream* pPublicKeyStream, std::ostream* pPrivateKeyStream, const std::string& privateKeyPassphrase)
+{
+ _pImpl->save(pPublicKeyStream, pPrivateKeyStream, privateKeyPassphrase);
+}
+
+
+namespace
+{
+ static const std::string RSA("rsa");
+}
+
+
+const std::string& RSAKey::name() const
+{
+ return RSA;
+}
+
+
+} } // namespace Poco::Crypto
diff --git a/Crypto/src/RSAKeyImpl.cpp b/Crypto/src/RSAKeyImpl.cpp
index b5f8d74bb..1eb4102fe 100644
--- a/Crypto/src/RSAKeyImpl.cpp
+++ b/Crypto/src/RSAKeyImpl.cpp
@@ -1,291 +1,339 @@
-//
-// RSAKeyImpl.cpp
-//
-// $Id: //poco/Main/Crypto/src/RSAKeyImpl.cpp#3 $
-//
-// Library: Crypto
-// Package: RSA
-// 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/Crypto/X509Certificate.h"
-#include "Poco/FileStream.h"
-#include "Poco/StreamCopier.h"
-#include "Poco/TemporaryFile.h"
-#include
-#include
-
-
-namespace Poco {
-namespace Crypto {
-
-
-RSAKeyImpl::RSAKeyImpl(const X509Certificate& cert):
- _pRSA(0)
-{
- const X509* pCert = cert.certificate();
- EVP_PKEY* pKey = X509_get_pubkey(const_cast(pCert));
-
- RSA* pRSA = pKey->pkey.rsa;
- _pRSA = RSAPublicKey_dup(pRSA);
-}
-
-
-RSAKeyImpl::RSAKeyImpl(int keyLength, unsigned long exponent):
- _pRSA(0)
-{
-#if OPENSSL_VERSION_NUMBER >= 0x00908000L
- _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");
-#else
- _pRSA = RSA_generate_key(keyLength, exponent, 0, 0);
- if (!_pRSA) throw Poco::InvalidArgumentException("Failed to create RSA context");
-#endif
-}
-
-
-RSAKeyImpl::RSAKeyImpl(
- const std::string& publicKeyFile,
- const std::string& privateKeyFile,
- const std::string& privateKeyPassphrase):
- _pRSA(0)
-{
- init(publicKeyFile, privateKeyFile, privateKeyPassphrase);
-}
-
-
-RSAKeyImpl::RSAKeyImpl(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream, const std::string& privateKeyPassphrase):
- _pRSA(0)
-{
- // due to C lib not supporting streams, we create two temporary files
- std::string publicKeyFile;
- Poco::TemporaryFile pubFile;
- if (pPublicKeyStream)
- {
- if (!pubFile.createFile())
- throw Poco::CreateFileException("Cannot create temporary file for writing public key");
- publicKeyFile = pubFile.path();
- Poco::FileOutputStream fout(publicKeyFile);
- Poco::StreamCopier::copyStream(*pPublicKeyStream, fout);
- }
- std::string privateKeyFile;
- Poco::TemporaryFile privFile;
- if (pPrivateKeyStream)
- {
- if (!privFile.createFile())
- throw Poco::CreateFileException("Cannot create temporary file for writing private key");
- privateKeyFile = privFile.path();
- Poco::FileOutputStream fout(privateKeyFile);
- Poco::StreamCopier::copyStream(*pPrivateKeyStream, fout);
-
- }
- init(publicKeyFile, privateKeyFile, privateKeyPassphrase);
-}
-
-
-void RSAKeyImpl::init(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase)
-{
- poco_assert_dbg(_pRSA == 0);
-
- _pRSA = RSA_new();
- if (!publicKeyFile.empty())
- {
- BIO* out = BIO_new(BIO_s_file());
- if (!out) throw Poco::IOException("Cannot create BIO for reading public key", publicKeyFile);
- int rc = BIO_read_filename(out, publicKeyFile.c_str());
- if (rc)
- {
- RSA* pubKey = PEM_read_bio_RSAPublicKey(out, &_pRSA, 0, 0);
- BIO_free(out);
- if (!pubKey)
- {
- freeRSA();
- throw Poco::FileException("Failed to load public key", publicKeyFile);
- }
- }
- else
- {
- freeRSA();
- throw Poco::FileNotFoundException("Public key file", publicKeyFile);
- }
- }
-
- if (!privateKeyFile.empty())
- {
- BIO* out = BIO_new(BIO_s_file());
- if (!out) throw Poco::IOException("Cannot create BIO for reading private key", privateKeyFile);
- int rc = BIO_read_filename(out, privateKeyFile.c_str());
- if (rc)
- {
- RSA* privKey = 0;
- if (privateKeyPassphrase.empty())
- privKey = PEM_read_bio_RSAPrivateKey(out, &_pRSA, 0, 0);
- else
- privKey = PEM_read_bio_RSAPrivateKey(out, &_pRSA, 0, const_cast(privateKeyPassphrase.c_str()));
- BIO_free(out);
- if (!privKey)
- {
- freeRSA();
- throw Poco::FileException("Failed to load private key", privateKeyFile);
- }
- }
- else
- {
- freeRSA();
- throw Poco::FileNotFoundException("Private key file", privateKeyFile);
- }
- }
-}
-
-
-RSAKeyImpl::~RSAKeyImpl()
-{
- freeRSA();
-}
-
-
-void RSAKeyImpl::freeRSA()
-{
- if (_pRSA)
- RSA_free(_pRSA);
- _pRSA = 0;
-}
-
-
-int RSAKeyImpl::size() const
-{
- return RSA_size(_pRSA);
-}
-
-
-void RSAKeyImpl::save(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase)
-{
- if (!publicKeyFile.empty())
- {
- BIO* out = BIO_new(BIO_s_file());
- if (!out) throw Poco::IOException("Cannot create BIO for writing public key file", publicKeyFile);
- try
- {
- if (BIO_write_filename(out, const_cast(publicKeyFile.c_str())))
- {
- if (!PEM_write_bio_RSAPublicKey(out, _pRSA))
- throw Poco::WriteFileException("Failed to write public key to file", publicKeyFile);
- }
- else throw Poco::CreateFileException("Cannot create public key file");
- }
- catch (...)
- {
- BIO_free(out);
- throw;
- }
- BIO_free(out);
- }
-
- if (!privateKeyFile.empty())
- {
- BIO* out = BIO_new(BIO_s_file());
- if (!out) throw Poco::IOException("Cannot create BIO for writing private key file", privateKeyFile);
- try
- {
- if (BIO_write_filename(out, const_cast(privateKeyFile.c_str())))
- {
- int rc = 0;
- if (privateKeyPassphrase.empty())
- rc = PEM_write_bio_RSAPrivateKey(out, _pRSA, EVP_des_ede3_cbc(), 0, 0, 0, 0);
- else
- rc = PEM_write_bio_RSAPrivateKey(out, _pRSA, EVP_des_ede3_cbc(),
- reinterpret_cast(const_cast(privateKeyPassphrase.c_str())),
- static_cast(privateKeyPassphrase.length()), 0, 0);
- if (!rc) throw Poco::FileException("Failed to write private key to file", privateKeyFile);
- }
- else throw Poco::CreateFileException("Cannot create private key file", privateKeyFile);
- }
- catch (...)
- {
- BIO_free(out);
- throw;
- }
- BIO_free(out);
- }
-}
-
-
-void RSAKeyImpl::save(std::ostream* pPublicKeyStream, std::ostream* pPrivateKeyStream, const std::string& privateKeyPassphrase)
-{
- if (!pPublicKeyStream && !pPrivateKeyStream) return;
-
- // due to C lib not supporting streams, we create two temporary files
- std::string publicKeyFile;
- Poco::TemporaryFile pubFile;
- if (pPublicKeyStream)
- {
- publicKeyFile = pubFile.path();
- if (!pubFile.createFile())
- throw Poco::CreateFileException("Cannot create temporary public file");
- }
- std::string privateKeyFile;
- Poco::TemporaryFile privFile;
- if (pPrivateKeyStream)
- {
- privateKeyFile = privFile.path();
- if (!privFile.createFile())
- throw Poco::FileException("Cannot crate temporary private key file");
- }
- save(publicKeyFile, privateKeyFile, privateKeyPassphrase);
-
- // now copy everything from the temp files to the original streams
- if (pPublicKeyStream)
- {
- Poco::FileInputStream istr(publicKeyFile);
- Poco::StreamCopier::copyStream(istr, *pPublicKeyStream);
- }
- if (pPrivateKeyStream)
- {
- Poco::FileInputStream istr(privateKeyFile);
- Poco::StreamCopier::copyStream(istr, *pPrivateKeyStream);
- }
-}
-
-
-} } // namespace Poco::Crypto
+//
+// RSAKeyImpl.cpp
+//
+// $Id: //poco/1.4/Crypto/src/RSAKeyImpl.cpp#1 $
+//
+// Library: Crypto
+// Package: RSA
+// 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/Crypto/X509Certificate.h"
+#include "Poco/FileStream.h"
+#include "Poco/StreamCopier.h"
+#include
+#include
+#include
+#include
+#if OPENSSL_VERSION_NUMBER >= 0x00908000L
+#include
+#endif
+
+
+namespace Poco {
+namespace Crypto {
+
+
+RSAKeyImpl::RSAKeyImpl(const X509Certificate& cert):
+ _pRSA(0)
+{
+ const X509* pCert = cert.certificate();
+ EVP_PKEY* pKey = X509_get_pubkey(const_cast(pCert));
+ _pRSA = EVP_PKEY_get1_RSA(pKey);
+}
+
+
+RSAKeyImpl::RSAKeyImpl(int keyLength, unsigned long exponent):
+ _pRSA(0)
+{
+#if OPENSSL_VERSION_NUMBER >= 0x00908000L
+ _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");
+#else
+ _pRSA = RSA_generate_key(keyLength, exponent, 0, 0);
+ if (!_pRSA) throw Poco::InvalidArgumentException("Failed to create RSA context");
+#endif
+}
+
+
+RSAKeyImpl::RSAKeyImpl(
+ const std::string& publicKeyFile,
+ const std::string& privateKeyFile,
+ const std::string& privateKeyPassphrase):
+ _pRSA(0)
+{
+ poco_assert_dbg(_pRSA == 0);
+
+ _pRSA = RSA_new();
+ if (!publicKeyFile.empty())
+ {
+ BIO* bio = BIO_new(BIO_s_file());
+ if (!bio) throw Poco::IOException("Cannot create BIO for reading public key", publicKeyFile);
+ int rc = BIO_read_filename(bio, publicKeyFile.c_str());
+ if (rc)
+ {
+ RSA* pubKey = PEM_read_bio_RSAPublicKey(bio, &_pRSA, 0, 0);
+ BIO_free(bio);
+ if (!pubKey)
+ {
+ freeRSA();
+ throw Poco::FileException("Failed to load public key", publicKeyFile);
+ }
+ }
+ else
+ {
+ freeRSA();
+ throw Poco::FileNotFoundException("Public key file", publicKeyFile);
+ }
+ }
+
+ if (!privateKeyFile.empty())
+ {
+ BIO* bio = BIO_new(BIO_s_file());
+ if (!bio) throw Poco::IOException("Cannot create BIO for reading private key", privateKeyFile);
+ int rc = BIO_read_filename(bio, privateKeyFile.c_str());
+ if (rc)
+ {
+ RSA* privKey = 0;
+ if (privateKeyPassphrase.empty())
+ privKey = PEM_read_bio_RSAPrivateKey(bio, &_pRSA, 0, 0);
+ else
+ privKey = PEM_read_bio_RSAPrivateKey(bio, &_pRSA, 0, const_cast(privateKeyPassphrase.c_str()));
+ BIO_free(bio);
+ if (!privKey)
+ {
+ freeRSA();
+ throw Poco::FileException("Failed to load private key", privateKeyFile);
+ }
+ }
+ else
+ {
+ freeRSA();
+ throw Poco::FileNotFoundException("Private key file", privateKeyFile);
+ }
+ }
+}
+
+
+RSAKeyImpl::RSAKeyImpl(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream, const std::string& privateKeyPassphrase):
+ _pRSA(0)
+{
+ poco_assert_dbg(_pRSA == 0);
+
+ _pRSA = RSA_new();
+ if (pPublicKeyStream)
+ {
+ std::string publicKeyData;
+ Poco::StreamCopier::copyToString(*pPublicKeyStream, publicKeyData);
+ BIO* bio = BIO_new_mem_buf(const_cast(publicKeyData.data()), static_cast(publicKeyData.size()));
+ if (!bio) throw Poco::IOException("Cannot create BIO for reading public key");
+ RSA* publicKey = PEM_read_bio_RSAPublicKey(bio, &_pRSA, 0, 0);
+ BIO_free(bio);
+ if (!publicKey)
+ {
+ freeRSA();
+ throw Poco::FileException("Failed to load public key");
+ }
+ }
+
+ if (pPrivateKeyStream)
+ {
+ std::string privateKeyData;
+ Poco::StreamCopier::copyToString(*pPrivateKeyStream, privateKeyData);
+ BIO* bio = BIO_new_mem_buf(const_cast(privateKeyData.data()), static_cast(privateKeyData.size()));
+ if (!bio) throw Poco::IOException("Cannot create BIO for reading private key");
+ RSA* privateKey = 0;
+ if (privateKeyPassphrase.empty())
+ privateKey = PEM_read_bio_RSAPrivateKey(bio, &_pRSA, 0, 0);
+ else
+ privateKey = PEM_read_bio_RSAPrivateKey(bio, &_pRSA, 0, const_cast(privateKeyPassphrase.c_str()));
+ BIO_free(bio);
+ if (!privateKey)
+ {
+ freeRSA();
+ throw Poco::FileException("Failed to load private key");
+ }
+ }
+}
+
+
+RSAKeyImpl::~RSAKeyImpl()
+{
+ freeRSA();
+}
+
+
+void RSAKeyImpl::freeRSA()
+{
+ if (_pRSA)
+ RSA_free(_pRSA);
+ _pRSA = 0;
+}
+
+
+int RSAKeyImpl::size() const
+{
+ return RSA_size(_pRSA);
+}
+
+
+RSAKeyImpl::ByteVec RSAKeyImpl::modulus() const
+{
+ return convertToByteVec(_pRSA->n);
+}
+
+
+RSAKeyImpl::ByteVec RSAKeyImpl::encryptionExponent() const
+{
+ return convertToByteVec(_pRSA->e);
+}
+
+
+RSAKeyImpl::ByteVec RSAKeyImpl::decryptionExponent() const
+{
+ return convertToByteVec(_pRSA->d);
+}
+
+
+void RSAKeyImpl::save(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase)
+{
+ if (!publicKeyFile.empty())
+ {
+ BIO* bio = BIO_new(BIO_s_file());
+ if (!bio) throw Poco::IOException("Cannot create BIO for writing public key file", publicKeyFile);
+ try
+ {
+ if (BIO_write_filename(bio, const_cast(publicKeyFile.c_str())))
+ {
+ if (!PEM_write_bio_RSAPublicKey(bio, _pRSA))
+ throw Poco::WriteFileException("Failed to write public key to file", publicKeyFile);
+ }
+ else throw Poco::CreateFileException("Cannot create public key file");
+ }
+ catch (...)
+ {
+ BIO_free(bio);
+ throw;
+ }
+ BIO_free(bio);
+ }
+
+ if (!privateKeyFile.empty())
+ {
+ BIO* bio = BIO_new(BIO_s_file());
+ if (!bio) throw Poco::IOException("Cannot create BIO for writing private key file", privateKeyFile);
+ try
+ {
+ if (BIO_write_filename(bio, const_cast(privateKeyFile.c_str())))
+ {
+ int rc = 0;
+ if (privateKeyPassphrase.empty())
+ rc = PEM_write_bio_RSAPrivateKey(bio, _pRSA, EVP_des_ede3_cbc(), 0, 0, 0, 0);
+ else
+ rc = PEM_write_bio_RSAPrivateKey(bio, _pRSA, EVP_des_ede3_cbc(),
+ reinterpret_cast(const_cast(privateKeyPassphrase.c_str())),
+ static_cast(privateKeyPassphrase.length()), 0, 0);
+ if (!rc) throw Poco::FileException("Failed to write private key to file", privateKeyFile);
+ }
+ else throw Poco::CreateFileException("Cannot create private key file", privateKeyFile);
+ }
+ catch (...)
+ {
+ BIO_free(bio);
+ throw;
+ }
+ BIO_free(bio);
+ }
+}
+
+
+void RSAKeyImpl::save(std::ostream* pPublicKeyStream, std::ostream* pPrivateKeyStream, const std::string& privateKeyPassphrase)
+{
+ if (pPublicKeyStream)
+ {
+ BIO* bio = BIO_new(BIO_s_mem());
+ if (!bio) throw Poco::IOException("Cannot create BIO for writing public key");
+ if (!PEM_write_bio_RSAPublicKey(bio, _pRSA))
+ {
+ BIO_free(bio);
+ throw Poco::WriteFileException("Failed to write public key to stream");
+ }
+ char* pData;
+ long size = BIO_get_mem_data(bio, &pData);
+ pPublicKeyStream->write(pData, static_cast(size));
+ BIO_free(bio);
+ }
+
+ if (pPrivateKeyStream)
+ {
+ BIO* bio = BIO_new(BIO_s_mem());
+ if (!bio) throw Poco::IOException("Cannot create BIO for writing public key");
+ int rc = 0;
+ if (privateKeyPassphrase.empty())
+ rc = PEM_write_bio_RSAPrivateKey(bio, _pRSA, EVP_des_ede3_cbc(), 0, 0, 0, 0);
+ else
+ rc = PEM_write_bio_RSAPrivateKey(bio, _pRSA, EVP_des_ede3_cbc(),
+ reinterpret_cast(const_cast(privateKeyPassphrase.c_str())),
+ static_cast(privateKeyPassphrase.length()), 0, 0);
+ if (!rc)
+ {
+ BIO_free(bio);
+ throw Poco::FileException("Failed to write private key to stream");
+ }
+ char* pData;
+ long size = BIO_get_mem_data(bio, &pData);
+ pPrivateKeyStream->write(pData, static_cast(size));
+ BIO_free(bio);
+ }
+}
+
+
+RSAKeyImpl::ByteVec RSAKeyImpl::convertToByteVec(const BIGNUM* bn)
+{
+ int numBytes = BN_num_bytes(bn);
+ ByteVec byteVector(numBytes);
+
+ ByteVec::value_type* buffer = new ByteVec::value_type[numBytes];
+ BN_bn2bin(bn, buffer);
+
+ for (int i = 0; i < numBytes; ++i)
+ byteVector[i] = buffer[i];
+
+ delete [] buffer;
+
+ return byteVector;
+}
+
+
+} } // namespace Poco::Crypto
diff --git a/Crypto/src/X509Certificate.cpp b/Crypto/src/X509Certificate.cpp
index e363f7e0e..ff24ea4c2 100644
--- a/Crypto/src/X509Certificate.cpp
+++ b/Crypto/src/X509Certificate.cpp
@@ -1,290 +1,303 @@
-//
-// X509Certificate.cpp
-//
-// $Id: //poco/Main/Crypto/src/X509Certificate.cpp#1 $
-//
-// Library: Crypto
-// Package: Certificate
-// Module: X509Certificate
-//
-// Copyright (c) 2006-2009, 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/X509Certificate.h"
-#include "Poco/StreamCopier.h"
-#include "Poco/String.h"
-#include "Poco/DateTimeParser.h"
-#include
-#include
-#include
-#include
-#include
-
-
-namespace Poco {
-namespace Crypto {
-
-
-X509Certificate::X509Certificate(std::istream& istr):
- _pCert(0)
-{
- load(istr);
-}
-
-
-X509Certificate::X509Certificate(const std::string& path):
- _pCert(0)
-{
- load(path);
-}
-
-
-X509Certificate::X509Certificate(X509* pCert):
- _pCert(pCert)
-{
- poco_check_ptr(_pCert);
-
- _pCert = X509_dup(_pCert);
- init();
-}
-
-
-X509Certificate::X509Certificate(const X509Certificate& cert):
- _issuerName(cert._issuerName),
- _subjectName(cert._subjectName),
- _pCert(cert._pCert)
-{
- _pCert = X509_dup(_pCert);
-}
-
-
-X509Certificate& X509Certificate::operator = (const X509Certificate& cert)
-{
- X509Certificate tmp(cert);
- swap(tmp);
- return *this;
-}
-
-
-void X509Certificate::swap(X509Certificate& cert)
-{
- using std::swap;
- swap(cert._issuerName, _issuerName);
- swap(cert._subjectName, _subjectName);
- swap(cert._pCert, _pCert);
-}
-
-
-X509Certificate::~X509Certificate()
-{
- X509_free(_pCert);
-}
-
-
-void X509Certificate::load(std::istream& istr)
-{
- poco_assert (!_pCert);
-
- std::stringstream certStream;
- Poco::StreamCopier::copyStream(istr, certStream);
- std::string cert = certStream.str();
-
- BIO *pBIO = BIO_new_mem_buf(const_cast(cert.data()), static_cast(cert.size()));
- if (!pBIO) throw Poco::IOException("Cannot create BIO for reading certificate");
- _pCert = PEM_read_bio_X509(pBIO, 0, 0, 0);
- BIO_free(pBIO);
-
- if (!_pCert) throw Poco::IOException("Faild to load certificate from stream");
-
- init();
-}
-
-
-void X509Certificate::load(const std::string& path)
-{
- poco_assert (!_pCert);
-
- BIO *pBIO = BIO_new(BIO_s_file());
- if (!pBIO) throw Poco::IOException("Cannot create BIO for reading certificate file", path);
- if (!BIO_read_filename(pBIO, path.c_str()))
- {
- BIO_free(pBIO);
- throw Poco::OpenFileException("Cannot open certificate file for reading", path);
- }
-
- _pCert = PEM_read_bio_X509(pBIO, 0, 0, 0);
- BIO_free(pBIO);
-
- if (!_pCert) throw Poco::ReadFileException("Faild to load certificate from", path);
-
- init();
-}
-
-
-void X509Certificate::save(std::ostream& stream) const
-{
- BIO *pBIO = BIO_new(BIO_s_mem());
- if (!pBIO) throw Poco::IOException("Cannot create BIO for writing certificate");
- try
- {
- if (!PEM_write_bio_X509(pBIO, _pCert))
- throw Poco::IOException("Failed to write certificate to stream");
-
- char *pData;
- long size;
- size = BIO_get_mem_data(pBIO, &pData);
- stream.write(pData, size);
- }
- catch (...)
- {
- BIO_free(pBIO);
- throw;
- }
- BIO_free(pBIO);
-}
-
-
-void X509Certificate::save(const std::string& path) const
-{
- BIO *pBIO = BIO_new(BIO_s_file());
- if (!pBIO) throw Poco::IOException("Cannot create BIO for reading certificate file", path);
- if (!BIO_write_filename(pBIO, const_cast(path.c_str())))
- {
- BIO_free(pBIO);
- throw Poco::CreateFileException("Cannot create certificate file", path);
- }
- try
- {
- if (!PEM_write_bio_X509(pBIO, _pCert))
- throw Poco::WriteFileException("Failed to write certificate to file", path);
- }
- catch (...)
- {
- BIO_free(pBIO);
- throw;
- }
- BIO_free(pBIO);
-}
-
-
-void X509Certificate::init()
-{
- char buffer[NAME_BUFFER_SIZE];
- X509_NAME_oneline(X509_get_issuer_name(_pCert), buffer, sizeof(buffer));
- _issuerName = buffer;
- X509_NAME_oneline(X509_get_subject_name(_pCert), buffer, sizeof(buffer));
- _subjectName = buffer;
-}
-
-
-std::string X509Certificate::commonName() const
-{
- return subjectName(NID_COMMON_NAME);
-}
-
-
-std::string X509Certificate::issuerName(NID nid) const
-{
- if (X509_NAME* issuer = X509_get_issuer_name(_pCert))
- {
- char buffer[NAME_BUFFER_SIZE];
- X509_NAME_get_text_by_NID(issuer, nid, buffer, sizeof(buffer));
- return std::string(buffer);
- }
- else return std::string();
-}
-
-
-std::string X509Certificate::subjectName(NID nid) const
-{
- if (X509_NAME* subj = X509_get_subject_name(_pCert))
- {
- char buffer[NAME_BUFFER_SIZE];
- X509_NAME_get_text_by_NID(subj, nid, buffer, sizeof(buffer));
- return std::string(buffer);
- }
- else return std::string();
-}
-
-
-void X509Certificate::extractNames(std::string& cmnName, std::set& domainNames) const
-{
- domainNames.clear();
- if (STACK_OF(GENERAL_NAME)* names = static_cast(X509_get_ext_d2i(_pCert, NID_subject_alt_name, 0, 0)))
- {
- for (int i = 0; i < sk_GENERAL_NAME_num(names); ++i)
- {
- const GENERAL_NAME* name = sk_GENERAL_NAME_value(names, i);
- if (name->type == GEN_DNS)
- {
- const char* data = reinterpret_cast(ASN1_STRING_data(name->d.ia5));
- std::size_t len = ASN1_STRING_length(name->d.ia5);
- domainNames.insert(std::string(data, len));
- }
- }
- GENERAL_NAMES_free(names);
- }
-
- cmnName = commonName();
- if (!cmnName.empty() && domainNames.empty())
- {
- domainNames.insert(cmnName);
- }
-}
-
-
-Poco::DateTime X509Certificate::validFrom() const
-{
- ASN1_TIME* certTime = X509_get_notBefore(_pCert);
- std::string dateTime(reinterpret_cast(certTime->data));
- int tzd;
- return DateTimeParser::parse("%y%m%d%H%M%S", dateTime, tzd);
-}
-
-
-Poco::DateTime X509Certificate::expiresOn() const
-{
- ASN1_TIME* certTime = X509_get_notAfter(_pCert);
- std::string dateTime(reinterpret_cast(certTime->data));
- int tzd;
- return DateTimeParser::parse("%y%m%d%H%M%S", dateTime, tzd);
-}
-
-
-bool X509Certificate::issuedBy(const X509Certificate& issuerCertificate) const
-{
- X509* pCert = const_cast(_pCert);
- X509* pIssuerCert = const_cast(issuerCertificate.certificate());
- EVP_PKEY* pIssuerPublicKey = X509_get_pubkey(pIssuerCert);
- if (!pIssuerPublicKey) throw Poco::InvalidArgumentException("Issuer certificate has no public key");
- int rc = X509_verify(pCert, pIssuerPublicKey);
- EVP_PKEY_free(pIssuerPublicKey);
- return rc != 0;
-}
-
-
-} } // namespace Poco::Crypto
+//
+// X509Certificate.cpp
+//
+// $Id: //poco/1.4/Crypto/src/X509Certificate.cpp#1 $
+//
+// Library: Crypto
+// Package: Certificate
+// Module: X509Certificate
+//
+// Copyright (c) 2006-2009, 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/X509Certificate.h"
+#include "Poco/StreamCopier.h"
+#include "Poco/String.h"
+#include "Poco/DateTimeParser.h"
+#include
+#include
+#include
+#include
+#include
+
+
+namespace Poco {
+namespace Crypto {
+
+
+X509Certificate::X509Certificate(std::istream& istr):
+ _pCert(0)
+{
+ load(istr);
+}
+
+
+X509Certificate::X509Certificate(const std::string& path):
+ _pCert(0)
+{
+ load(path);
+}
+
+
+X509Certificate::X509Certificate(X509* pCert):
+ _pCert(pCert)
+{
+ poco_check_ptr(_pCert);
+
+ init();
+}
+
+
+X509Certificate::X509Certificate(X509* pCert, bool shared):
+ _pCert(pCert)
+{
+ poco_check_ptr(_pCert);
+
+ if (shared)
+ {
+ _pCert->references++;
+ }
+
+ init();
+}
+
+
+X509Certificate::X509Certificate(const X509Certificate& cert):
+ _issuerName(cert._issuerName),
+ _subjectName(cert._subjectName),
+ _pCert(cert._pCert)
+{
+ _pCert = X509_dup(_pCert);
+}
+
+
+X509Certificate& X509Certificate::operator = (const X509Certificate& cert)
+{
+ X509Certificate tmp(cert);
+ swap(tmp);
+ return *this;
+}
+
+
+void X509Certificate::swap(X509Certificate& cert)
+{
+ using std::swap;
+ swap(cert._issuerName, _issuerName);
+ swap(cert._subjectName, _subjectName);
+ swap(cert._pCert, _pCert);
+}
+
+
+X509Certificate::~X509Certificate()
+{
+ X509_free(_pCert);
+}
+
+
+void X509Certificate::load(std::istream& istr)
+{
+ poco_assert (!_pCert);
+
+ std::stringstream certStream;
+ Poco::StreamCopier::copyStream(istr, certStream);
+ std::string cert = certStream.str();
+
+ BIO *pBIO = BIO_new_mem_buf(const_cast(cert.data()), static_cast(cert.size()));
+ if (!pBIO) throw Poco::IOException("Cannot create BIO for reading certificate");
+ _pCert = PEM_read_bio_X509(pBIO, 0, 0, 0);
+ BIO_free(pBIO);
+
+ if (!_pCert) throw Poco::IOException("Faild to load certificate from stream");
+
+ init();
+}
+
+
+void X509Certificate::load(const std::string& path)
+{
+ poco_assert (!_pCert);
+
+ BIO *pBIO = BIO_new(BIO_s_file());
+ if (!pBIO) throw Poco::IOException("Cannot create BIO for reading certificate file", path);
+ if (!BIO_read_filename(pBIO, path.c_str()))
+ {
+ BIO_free(pBIO);
+ throw Poco::OpenFileException("Cannot open certificate file for reading", path);
+ }
+
+ _pCert = PEM_read_bio_X509(pBIO, 0, 0, 0);
+ BIO_free(pBIO);
+
+ if (!_pCert) throw Poco::ReadFileException("Faild to load certificate from", path);
+
+ init();
+}
+
+
+void X509Certificate::save(std::ostream& stream) const
+{
+ BIO *pBIO = BIO_new(BIO_s_mem());
+ if (!pBIO) throw Poco::IOException("Cannot create BIO for writing certificate");
+ try
+ {
+ if (!PEM_write_bio_X509(pBIO, _pCert))
+ throw Poco::IOException("Failed to write certificate to stream");
+
+ char *pData;
+ long size;
+ size = BIO_get_mem_data(pBIO, &pData);
+ stream.write(pData, size);
+ }
+ catch (...)
+ {
+ BIO_free(pBIO);
+ throw;
+ }
+ BIO_free(pBIO);
+}
+
+
+void X509Certificate::save(const std::string& path) const
+{
+ BIO *pBIO = BIO_new(BIO_s_file());
+ if (!pBIO) throw Poco::IOException("Cannot create BIO for reading certificate file", path);
+ if (!BIO_write_filename(pBIO, const_cast(path.c_str())))
+ {
+ BIO_free(pBIO);
+ throw Poco::CreateFileException("Cannot create certificate file", path);
+ }
+ try
+ {
+ if (!PEM_write_bio_X509(pBIO, _pCert))
+ throw Poco::WriteFileException("Failed to write certificate to file", path);
+ }
+ catch (...)
+ {
+ BIO_free(pBIO);
+ throw;
+ }
+ BIO_free(pBIO);
+}
+
+
+void X509Certificate::init()
+{
+ char buffer[NAME_BUFFER_SIZE];
+ X509_NAME_oneline(X509_get_issuer_name(_pCert), buffer, sizeof(buffer));
+ _issuerName = buffer;
+ X509_NAME_oneline(X509_get_subject_name(_pCert), buffer, sizeof(buffer));
+ _subjectName = buffer;
+}
+
+
+std::string X509Certificate::commonName() const
+{
+ return subjectName(NID_COMMON_NAME);
+}
+
+
+std::string X509Certificate::issuerName(NID nid) const
+{
+ if (X509_NAME* issuer = X509_get_issuer_name(_pCert))
+ {
+ char buffer[NAME_BUFFER_SIZE];
+ X509_NAME_get_text_by_NID(issuer, nid, buffer, sizeof(buffer));
+ return std::string(buffer);
+ }
+ else return std::string();
+}
+
+
+std::string X509Certificate::subjectName(NID nid) const
+{
+ if (X509_NAME* subj = X509_get_subject_name(_pCert))
+ {
+ char buffer[NAME_BUFFER_SIZE];
+ X509_NAME_get_text_by_NID(subj, nid, buffer, sizeof(buffer));
+ return std::string(buffer);
+ }
+ else return std::string();
+}
+
+
+void X509Certificate::extractNames(std::string& cmnName, std::set& domainNames) const
+{
+ domainNames.clear();
+ if (STACK_OF(GENERAL_NAME)* names = static_cast(X509_get_ext_d2i(_pCert, NID_subject_alt_name, 0, 0)))
+ {
+ for (int i = 0; i < sk_GENERAL_NAME_num(names); ++i)
+ {
+ const GENERAL_NAME* name = sk_GENERAL_NAME_value(names, i);
+ if (name->type == GEN_DNS)
+ {
+ const char* data = reinterpret_cast(ASN1_STRING_data(name->d.ia5));
+ std::size_t len = ASN1_STRING_length(name->d.ia5);
+ domainNames.insert(std::string(data, len));
+ }
+ }
+ GENERAL_NAMES_free(names);
+ }
+
+ cmnName = commonName();
+ if (!cmnName.empty() && domainNames.empty())
+ {
+ domainNames.insert(cmnName);
+ }
+}
+
+
+Poco::DateTime X509Certificate::validFrom() const
+{
+ ASN1_TIME* certTime = X509_get_notBefore(_pCert);
+ std::string dateTime(reinterpret_cast(certTime->data));
+ int tzd;
+ return DateTimeParser::parse("%y%m%d%H%M%S", dateTime, tzd);
+}
+
+
+Poco::DateTime X509Certificate::expiresOn() const
+{
+ ASN1_TIME* certTime = X509_get_notAfter(_pCert);
+ std::string dateTime(reinterpret_cast(certTime->data));
+ int tzd;
+ return DateTimeParser::parse("%y%m%d%H%M%S", dateTime, tzd);
+}
+
+
+bool X509Certificate::issuedBy(const X509Certificate& issuerCertificate) const
+{
+ X509* pCert = const_cast(_pCert);
+ X509* pIssuerCert = const_cast(issuerCertificate.certificate());
+ EVP_PKEY* pIssuerPublicKey = X509_get_pubkey(pIssuerCert);
+ if (!pIssuerPublicKey) throw Poco::InvalidArgumentException("Issuer certificate has no public key");
+ int rc = X509_verify(pCert, pIssuerPublicKey);
+ EVP_PKEY_free(pIssuerPublicKey);
+ return rc != 0;
+}
+
+
+} } // namespace Poco::Crypto
diff --git a/Crypto/testsuite/TestSuite_vs100.vcxproj b/Crypto/testsuite/TestSuite_vs100.vcxproj
new file mode 100644
index 000000000..5d380d294
--- /dev/null
+++ b/Crypto/testsuite/TestSuite_vs100.vcxproj
@@ -0,0 +1,315 @@
+
+
+
+
+ debug_shared
+ Win32
+
+
+ debug_static_md
+ Win32
+
+
+ debug_static_mt
+ Win32
+
+
+ release_shared
+ Win32
+
+
+ release_static_md
+ Win32
+
+
+ release_static_mt
+ Win32
+
+
+
+ TestSuite
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}
+ TestSuite
+ Win32Proj
+
+
+
+ Application
+ Dynamic
+ MultiByte
+
+
+ Application
+ Dynamic
+ MultiByte
+
+
+ Application
+ Static
+ MultiByte
+
+
+ Application
+ Static
+ MultiByte
+
+
+ Application
+ Dynamic
+ MultiByte
+
+
+ Application
+ Dynamic
+ MultiByte
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <_ProjectFileVersion>10.0.30319.1
+ bin\
+ obj\$(Configuration)\
+ true
+ bin\
+ obj\$(Configuration)\
+ false
+ bin\static_mt\
+ obj\$(Configuration)\
+ true
+ bin\static_mt\
+ obj\$(Configuration)\
+ false
+ bin\static_md\
+ obj\$(Configuration)\
+ true
+ bin\static_md\
+ obj\$(Configuration)\
+ false
+ TestSuited
+ TestSuited
+ TestSuited
+ TestSuite
+ TestSuite
+ TestSuite
+
+
+
+ Disabled
+ ..\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;..\..\Foundation\include;%(AdditionalIncludeDirectories)
+ WIN32;_DEBUG;_WINDOWS;WINVER=0x0500;%(PreprocessorDefinitions)
+ true
+ true
+ EnableFastChecks
+ MultiThreadedDebugDLL
+ true
+ true
+ true
+ true
+
+ Level3
+ EditAndContinue
+ Default
+ %(DisableSpecificWarnings)
+
+
+ CppUnitd.lib;WinTestRunnerd.lib;ws2_32.lib;iphlpapi.lib;libeay32mdd.lib;ssleay32mdd.lib;%(AdditionalDependencies)
+ bin\TestSuited.exe
+ ..\..\lib;%(AdditionalLibraryDirectories)
+ true
+ true
+ bin\TestSuited.pdb
+ Windows
+ MachineX86
+
+
+
+
+ Disabled
+ OnlyExplicitInline
+ true
+ Speed
+ true
+ ..\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;..\..\Foundation\include;%(AdditionalIncludeDirectories)
+ WIN32;NDEBUG;_WINDOWS;WINVER=0x0500;%(PreprocessorDefinitions)
+ true
+ MultiThreadedDLL
+ false
+ true
+ true
+ true
+
+ Level3
+
+ Default
+ %(DisableSpecificWarnings)
+
+
+ CppUnit.lib;WinTestRunner.lib;ws2_32.lib;iphlpapi.lib;libeay32md.lib;ssleay32md.lib;%(AdditionalDependencies)
+ bin\TestSuite.exe
+ ..\..\lib;%(AdditionalLibraryDirectories)
+ false
+ Windows
+ true
+ true
+ MachineX86
+
+
+
+
+ Disabled
+ ..\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;..\..\Foundation\include;%(AdditionalIncludeDirectories)
+ WIN32;_DEBUG;_WINDOWS;WINVER=0x0500;POCO_STATIC;%(PreprocessorDefinitions)
+ true
+ true
+ EnableFastChecks
+ MultiThreadedDebug
+ true
+ true
+ true
+ true
+
+ Level3
+ EditAndContinue
+ Default
+ %(DisableSpecificWarnings)
+
+
+ CppUnitmtd.lib;WinTestRunnermtd.lib;iphlpapi.lib;winmm.lib;nafxcwd.lib;libcmtd.lib;WinTestRunner.res;ws2_32.lib;iphlpapi.lib;libeay32mtd.lib;ssleay32mtd.lib;%(AdditionalDependencies)
+ bin\static_mt\TestSuited.exe
+ ..\..\lib;%(AdditionalLibraryDirectories)
+ nafxcwd.lib;libcmtd.lib;%(IgnoreSpecificDefaultLibraries)
+ true
+ true
+ bin\static_mt\TestSuited.pdb
+ Windows
+ MachineX86
+
+
+
+
+ Disabled
+ OnlyExplicitInline
+ true
+ Speed
+ true
+ ..\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;..\..\Foundation\include;%(AdditionalIncludeDirectories)
+ WIN32;NDEBUG;_WINDOWS;WINVER=0x0500;POCO_STATIC;%(PreprocessorDefinitions)
+ true
+ MultiThreaded
+ false
+ true
+ true
+ true
+
+ Level3
+
+ Default
+ %(DisableSpecificWarnings)
+
+
+ CppUnitmt.lib;WinTestRunnermt.lib;iphlpapi.lib;winmm.lib;nafxcw.lib;libcmt.lib;WinTestRunner.res;ws2_32.lib;iphlpapi.lib;libeay32mt.lib;ssleay32mt.lib;%(AdditionalDependencies)
+ bin\static_mt\TestSuite.exe
+ ..\..\lib;%(AdditionalLibraryDirectories)
+ nafxcw.lib;libcmt.lib;%(IgnoreSpecificDefaultLibraries)
+ false
+ Windows
+ true
+ true
+ MachineX86
+
+
+
+
+ Disabled
+ ..\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;..\..\Foundation\include;%(AdditionalIncludeDirectories)
+ WIN32;_DEBUG;_WINDOWS;WINVER=0x0500;POCO_STATIC;%(PreprocessorDefinitions)
+ true
+ true
+ EnableFastChecks
+ MultiThreadedDebugDLL
+ true
+ true
+ true
+ true
+
+ Level3
+ EditAndContinue
+ Default
+ %(DisableSpecificWarnings)
+
+
+ CppUnitmdd.lib;WinTestRunnermdd.lib;iphlpapi.lib;winmm.lib;WinTestRunner.res;ws2_32.lib;iphlpapi.lib;libeay32mdd.lib;ssleay32mdd.lib;%(AdditionalDependencies)
+ bin\static_md\TestSuited.exe
+ ..\..\lib;%(AdditionalLibraryDirectories)
+ true
+ true
+ bin\static_md\TestSuited.pdb
+ Windows
+ MachineX86
+
+
+
+
+ Disabled
+ OnlyExplicitInline
+ true
+ Speed
+ true
+ ..\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;..\..\Foundation\include;%(AdditionalIncludeDirectories)
+ WIN32;NDEBUG;_WINDOWS;WINVER=0x0500;POCO_STATIC;%(PreprocessorDefinitions)
+ true
+ MultiThreadedDLL
+ false
+ true
+ true
+ true
+
+ Level3
+
+ Default
+ %(DisableSpecificWarnings)
+
+
+ CppUnitmd.lib;WinTestRunnermd.lib;iphlpapi.lib;winmm.lib;WinTestRunner.res;ws2_32.lib;iphlpapi.lib;libeay32md.lib;ssleay32md.lib;%(AdditionalDependencies)
+ bin\static_md\TestSuite.exe
+ ..\..\lib;%(AdditionalLibraryDirectories)
+ false
+ Windows
+ true
+ true
+ MachineX86
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Crypto/testsuite/TestSuite_vs100.vcxproj.filters b/Crypto/testsuite/TestSuite_vs100.vcxproj.filters
new file mode 100644
index 000000000..250f4c930
--- /dev/null
+++ b/Crypto/testsuite/TestSuite_vs100.vcxproj.filters
@@ -0,0 +1,54 @@
+
+
+
+
+ {02debdde-8664-412b-ba6c-4c13197de6f9}
+
+
+ {2311d4f4-8f52-459d-8caa-4febea4f0654}
+
+
+ {536bcab9-b11f-4dc2-bb55-ed2fc7101adf}
+
+
+ {4d25d62e-2b08-4863-8e6e-a37a27784732}
+
+
+ {a197b9e5-7e95-4f57-a438-237041d9a3c4}
+
+
+ {9df90fce-71cf-4b62-af6b-b1edadb7e6e2}
+
+
+ {a248980e-d5c3-41f7-a739-cd98b2f9f766}
+
+
+ {e3b401c0-2adc-4abc-96a3-07d3520ba75d}
+
+
+
+
+ Crypto\Header Files
+
+
+ Crypto\Header Files
+
+
+ _Suite\Header Files
+
+
+
+
+ Crypto\Source Files
+
+
+ Crypto\Source Files
+
+
+ _Suite\Source Files
+
+
+ _Driver\Source Files
+
+
+
\ No newline at end of file
diff --git a/Crypto/testsuite/TestSuite_vs100.vcxproj.user b/Crypto/testsuite/TestSuite_vs100.vcxproj.user
new file mode 100644
index 000000000..ace9a86ac
--- /dev/null
+++ b/Crypto/testsuite/TestSuite_vs100.vcxproj.user
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/Crypto/testsuite/TestSuite_x64_vs100.vcxproj b/Crypto/testsuite/TestSuite_x64_vs100.vcxproj
new file mode 100644
index 000000000..3bc909ec4
--- /dev/null
+++ b/Crypto/testsuite/TestSuite_x64_vs100.vcxproj
@@ -0,0 +1,315 @@
+
+
+
+
+ debug_shared
+ x64
+
+
+ debug_static_md
+ x64
+
+
+ debug_static_mt
+ x64
+
+
+ release_shared
+ x64
+
+
+ release_static_md
+ x64
+
+
+ release_static_mt
+ x64
+
+
+
+ TestSuite
+ {C1B1BB96-5198-48EB-AB48-9A0A0B54FB15}
+ TestSuite
+ Win32Proj
+
+
+
+ Application
+ Dynamic
+ MultiByte
+
+
+ Application
+ Dynamic
+ MultiByte
+
+
+ Application
+ Static
+ MultiByte
+
+
+ Application
+ Static
+ MultiByte
+
+
+ Application
+ Dynamic
+ MultiByte
+
+
+ Application
+ Dynamic
+ MultiByte
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <_ProjectFileVersion>10.0.30319.1
+ bin64\
+ obj64\$(Configuration)\
+ true
+ bin64\
+ obj64\$(Configuration)\
+ false
+ bin64\static_mt\
+ obj64\$(Configuration)\
+ true
+ bin64\static_mt\
+ obj64\$(Configuration)\
+ false
+ bin64\static_md\
+ obj64\$(Configuration)\
+ true
+ bin64\static_md\
+ obj64\$(Configuration)\
+ false
+ TestSuited
+ TestSuited
+ TestSuited
+ TestSuite
+ TestSuite
+ TestSuite
+
+
+
+ Disabled
+ ..\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;..\..\Foundation\include;%(AdditionalIncludeDirectories)
+ WIN32;_DEBUG;_WINDOWS;WINVER=0x0500;%(PreprocessorDefinitions)
+ true
+ true
+ EnableFastChecks
+ MultiThreadedDebugDLL
+ true
+ true
+ true
+ true
+
+ Level3
+ ProgramDatabase
+ Default
+ %(DisableSpecificWarnings)
+
+
+ CppUnitd.lib;WinTestRunnerd.lib;ws2_32.lib;iphlpapi.lib;libeay32mdd.lib;ssleay32mdd.lib;%(AdditionalDependencies)
+ bin64\TestSuited.exe
+ ..\..\lib64;%(AdditionalLibraryDirectories)
+ true
+ true
+ bin64\TestSuited.pdb
+ Windows
+ MachineX64
+
+
+
+
+ Disabled
+ OnlyExplicitInline
+ true
+ Speed
+ true
+ ..\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;..\..\Foundation\include;%(AdditionalIncludeDirectories)
+ WIN32;NDEBUG;_WINDOWS;WINVER=0x0500;%(PreprocessorDefinitions)
+ true
+ MultiThreadedDLL
+ false
+ true
+ true
+ true
+
+ Level3
+
+ Default
+ %(DisableSpecificWarnings)
+
+
+ CppUnit.lib;WinTestRunner.lib;ws2_32.lib;iphlpapi.lib;libeay32md.lib;ssleay32md.lib;%(AdditionalDependencies)
+ bin64\TestSuite.exe
+ ..\..\lib64;%(AdditionalLibraryDirectories)
+ false
+ Windows
+ true
+ true
+ MachineX64
+
+
+
+
+ Disabled
+ ..\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;..\..\Foundation\include;%(AdditionalIncludeDirectories)
+ WIN32;_DEBUG;_WINDOWS;WINVER=0x0500;POCO_STATIC;%(PreprocessorDefinitions)
+ true
+ true
+ EnableFastChecks
+ MultiThreadedDebug
+ true
+ true
+ true
+ true
+
+ Level3
+ ProgramDatabase
+ Default
+ %(DisableSpecificWarnings)
+
+
+ CppUnitmtd.lib;WinTestRunnermtd.lib;iphlpapi.lib;winmm.lib;nafxcwd.lib;libcmtd.lib;WinTestRunner.res;ws2_32.lib;iphlpapi.lib;libeay32mtd.lib;ssleay32mtd.lib;%(AdditionalDependencies)
+ bin64\static_mt\TestSuited.exe
+ ..\..\lib64;%(AdditionalLibraryDirectories)
+ nafxcwd.lib;libcmtd.lib;%(IgnoreSpecificDefaultLibraries)
+ true
+ true
+ bin64\static_mt\TestSuited.pdb
+ Windows
+ MachineX64
+
+
+
+
+ Disabled
+ OnlyExplicitInline
+ true
+ Speed
+ true
+ ..\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;..\..\Foundation\include;%(AdditionalIncludeDirectories)
+ WIN32;NDEBUG;_WINDOWS;WINVER=0x0500;POCO_STATIC;%(PreprocessorDefinitions)
+ true
+ MultiThreaded
+ false
+ true
+ true
+ true
+
+ Level3
+
+ Default
+ %(DisableSpecificWarnings)
+
+
+ CppUnitmt.lib;WinTestRunnermt.lib;iphlpapi.lib;winmm.lib;nafxcw.lib;libcmt.lib;WinTestRunner.res;ws2_32.lib;iphlpapi.lib;libeay32mt.lib;ssleay32mt.lib;%(AdditionalDependencies)
+ bin64\static_mt\TestSuite.exe
+ ..\..\lib64;%(AdditionalLibraryDirectories)
+ nafxcw.lib;libcmt.lib;%(IgnoreSpecificDefaultLibraries)
+ false
+ Windows
+ true
+ true
+ MachineX64
+
+
+
+
+ Disabled
+ ..\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;..\..\Foundation\include;%(AdditionalIncludeDirectories)
+ WIN32;_DEBUG;_WINDOWS;WINVER=0x0500;POCO_STATIC;%(PreprocessorDefinitions)
+ true
+ true
+ EnableFastChecks
+ MultiThreadedDebugDLL
+ true
+ true
+ true
+ true
+
+ Level3
+ ProgramDatabase
+ Default
+ %(DisableSpecificWarnings)
+
+
+ CppUnitmdd.lib;WinTestRunnermdd.lib;iphlpapi.lib;winmm.lib;WinTestRunner.res;ws2_32.lib;iphlpapi.lib;libeay32mdd.lib;ssleay32mdd.lib;%(AdditionalDependencies)
+ bin64\static_md\TestSuited.exe
+ ..\..\lib64;%(AdditionalLibraryDirectories)
+ true
+ true
+ bin64\static_md\TestSuited.pdb
+ Windows
+ MachineX64
+
+
+
+
+ Disabled
+ OnlyExplicitInline
+ true
+ Speed
+ true
+ ..\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;..\..\Foundation\include;%(AdditionalIncludeDirectories)
+ WIN32;NDEBUG;_WINDOWS;WINVER=0x0500;POCO_STATIC;%(PreprocessorDefinitions)
+ true
+ MultiThreadedDLL
+ false
+ true
+ true
+ true
+
+ Level3
+
+ Default
+ %(DisableSpecificWarnings)
+
+
+ CppUnitmd.lib;WinTestRunnermd.lib;iphlpapi.lib;winmm.lib;WinTestRunner.res;ws2_32.lib;iphlpapi.lib;libeay32md.lib;ssleay32md.lib;%(AdditionalDependencies)
+ bin64\static_md\TestSuite.exe
+ ..\..\lib64;%(AdditionalLibraryDirectories)
+ false
+ Windows
+ true
+ true
+ MachineX64
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Crypto/testsuite/TestSuite_x64_vs100.vcxproj.filters b/Crypto/testsuite/TestSuite_x64_vs100.vcxproj.filters
new file mode 100644
index 000000000..1cc4d76bb
--- /dev/null
+++ b/Crypto/testsuite/TestSuite_x64_vs100.vcxproj.filters
@@ -0,0 +1,54 @@
+
+
+
+
+ {45de6552-2469-4aa8-8899-1ba5f38d254e}
+
+
+ {4bee1bf3-cc02-4a05-9641-75f380833200}
+
+
+ {7f034d6f-f9ca-473d-ac5f-8b3c77ded478}
+
+
+ {f60d96dc-db3f-45df-be9d-db76636df680}
+
+
+ {d213663c-3c68-41c6-b524-0106d1081ec9}
+
+
+ {640d3c67-4362-495e-adf0-09a264035999}
+
+
+ {6da1fb8e-0d60-4331-b7c8-b0b1e13f7213}
+
+
+ {4f158ef4-cabf-4331-bdd3-ad8fef86f624}
+
+
+
+
+ Crypto\Header Files
+
+
+ Crypto\Header Files
+
+
+ _Suite\Header Files
+
+
+
+
+ Crypto\Source Files
+
+
+ Crypto\Source Files
+
+
+ _Suite\Source Files
+
+
+ _Driver\Source Files
+
+
+
\ No newline at end of file
diff --git a/Crypto/testsuite/TestSuite_x64_vs100.vcxproj.user b/Crypto/testsuite/TestSuite_x64_vs100.vcxproj.user
new file mode 100644
index 000000000..ace9a86ac
--- /dev/null
+++ b/Crypto/testsuite/TestSuite_x64_vs100.vcxproj.user
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/Crypto/testsuite/src/CryptoTest.cpp b/Crypto/testsuite/src/CryptoTest.cpp
index 0cd473e69..6f15ae033 100644
--- a/Crypto/testsuite/src/CryptoTest.cpp
+++ b/Crypto/testsuite/src/CryptoTest.cpp
@@ -1,156 +1,225 @@
-//
-// CryptoTest.cpp
-//
+//
+// CryptoTest.cpp
+//
// $Id: //poco/Main/Crypto/testsuite/src/CryptoTest.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 "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"
-#include "Poco/Crypto/X509Certificate.h"
-#include
-
-
-using namespace Poco::Crypto;
-
-
-static const std::string APPINF_PEM(
- "-----BEGIN CERTIFICATE-----\n"
- "MIIESzCCAzOgAwIBAgIBATALBgkqhkiG9w0BAQUwgdMxEzARBgNVBAMMCmFwcGlu\n"
- "Zi5jb20xNjA0BgNVBAoMLUFwcGxpZWQgSW5mb3JtYXRpY3MgU29mdHdhcmUgRW5n\n"
- "aW5lZXJpbmcgR21iSDEUMBIGA1UECwwLRGV2ZWxvcG1lbnQxEjAQBgNVBAgMCUNh\n"
- "cmludGhpYTELMAkGA1UEBhMCQVQxHjAcBgNVBAcMFVN0LiBKYWtvYiBpbSBSb3Nl\n"
- "bnRhbDEtMCsGCSqGSIb3DQEJARYeZ3VlbnRlci5vYmlsdHNjaG5pZ0BhcHBpbmYu\n"
- "Y29tMB4XDTA5MDUwNzE0NTY1NloXDTI5MDUwMjE0NTY1NlowgdMxEzARBgNVBAMM\n"
- "CmFwcGluZi5jb20xNjA0BgNVBAoMLUFwcGxpZWQgSW5mb3JtYXRpY3MgU29mdHdh\n"
- "cmUgRW5naW5lZXJpbmcgR21iSDEUMBIGA1UECwwLRGV2ZWxvcG1lbnQxEjAQBgNV\n"
- "BAgMCUNhcmludGhpYTELMAkGA1UEBhMCQVQxHjAcBgNVBAcMFVN0LiBKYWtvYiBp\n"
- "bSBSb3NlbnRhbDEtMCsGCSqGSIb3DQEJARYeZ3VlbnRlci5vYmlsdHNjaG5pZ0Bh\n"
- "cHBpbmYuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA89GolWCR\n"
- "KtLQclJ2M2QtpFqzNC54hUQdR6n8+DAeruH9WFwLSdWW2fEi+jrtd/WEWCdt4PxX\n"
- "F2/eBYeURus7Hg2ZtJGDd3je0+Ygsv7+we4cMN/knaBY7rATqhmnZWk+yBpkf5F2\n"
- "IHp9gBxUaJWmt/bq3XrvTtzrDXpCd4zg4zPXZ8IC8ket5o3K2vnkAOsIsgN+Ffqd\n"
- "4GjF4dsblG6u6E3VarGRLwGtgB8BAZOA/33mV4FHSMkc4OXpAChaK3tM8YhrLw+m\n"
- "XtsfqDiv1825S6OWFCKGj/iX8X2QAkrdB63vXCSpb3de/ByIUfp31PpMlMh6dKo1\n"
- "vf7yj0nb2w0utQIDAQABoyowKDAOBgNVHQ8BAf8EBAMCB4AwFgYDVR0lAQH/BAww\n"
- "CgYIKwYBBQUHAwMwDQYJKoZIhvcNAQEFBQADggEBAM0cpfb4BgiU/rkYe121P581\n"
- "ftg5Ck1PYYda1Fy/FgzbgJh2AwVo/6sn6GF79/QkEcWEgtCMNNO3LMTTddUUApuP\n"
- "jnEimyfmUhIThyud/vryzTMNa/eZMwaAqUQWqLf+AwgqjUsBSMenbSHavzJOpsvR\n"
- "LI0PQ1VvqB+3UGz0JUnBJiKvHs83Fdm4ewPAf3M5fGcIa+Fl2nU5Plzwzskj84f6\n"
- "73ZlEEi3aW9JieNy7RWsMM+1E8Sj2CGRZC4BM9V1Fgnsh4+VHX8Eu7eHucvfeIYx\n"
- "3mmLMoK4sCayL/FGhrUDw5AkWb8tKNpRXY+W60Et281yxQSeWLPIbatVzIWI0/M=\n"
- "-----END CERTIFICATE-----\n"
-);
-
-
-CryptoTest::CryptoTest(const std::string& name): CppUnit::TestCase(name)
-{
-}
-
-
-CryptoTest::~CryptoTest()
-{
-}
-
-
-void CryptoTest::testEncryptDecrypt()
-{
- 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::testEncryptDecryptWithSalt()
-{
- 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::testCertificate()
-{
- std::istringstream certStream(APPINF_PEM);
- X509Certificate cert(certStream);
-
- std::string subjectName(cert.subjectName());
- std::string issuerName(cert.issuerName());
- std::string commonName(cert.commonName());
- std::string country(cert.subjectName(X509Certificate::NID_COUNTRY));
- std::string localityName(cert.subjectName(X509Certificate::NID_LOCALITY_NAME));
- std::string stateOrProvince(cert.subjectName(X509Certificate::NID_STATE_OR_PROVINCE));
- std::string organizationName(cert.subjectName(X509Certificate::NID_ORGANIZATION_NAME));
- std::string organizationUnitName(cert.subjectName(X509Certificate::NID_ORGANIZATION_UNIT_NAME));
-
- assert (subjectName == "/CN=appinf.com/O=Applied Informatics Software Engineering GmbH/OU=Development/ST=Carinthia/C=AT/L=St. Jakob im Rosental/emailAddress=guenter.obiltschnig@appinf.com");
- assert (issuerName == subjectName);
- assert (commonName == "appinf.com");
- assert (country == "AT");
- assert (localityName == "St. Jakob im Rosental");
- assert (stateOrProvince == "Carinthia");
- assert (organizationName == "Applied Informatics Software Engineering GmbH");
- assert (organizationUnitName == "Development");
-
- assert (cert.issuedBy(cert));
-}
-
-
-void CryptoTest::setUp()
-{
-}
-
-
-void CryptoTest::tearDown()
-{
-}
-
-
-CppUnit::Test* CryptoTest::suite()
-{
- CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("CryptoTest");
-
- CppUnit_addTest(pSuite, CryptoTest, testEncryptDecrypt);
- CppUnit_addTest(pSuite, CryptoTest, testEncryptDecryptWithSalt);
- CppUnit_addTest(pSuite, CryptoTest, testCertificate);
-
- return pSuite;
-}
+//
+// 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"
+#include "Poco/Crypto/X509Certificate.h"
+#include "Poco/Crypto/CryptoStream.h"
+#include "Poco/StreamCopier.h"
+#include
+
+
+using namespace Poco::Crypto;
+
+
+static const std::string APPINF_PEM(
+ "-----BEGIN CERTIFICATE-----\n"
+ "MIIESzCCAzOgAwIBAgIBATALBgkqhkiG9w0BAQUwgdMxEzARBgNVBAMMCmFwcGlu\n"
+ "Zi5jb20xNjA0BgNVBAoMLUFwcGxpZWQgSW5mb3JtYXRpY3MgU29mdHdhcmUgRW5n\n"
+ "aW5lZXJpbmcgR21iSDEUMBIGA1UECwwLRGV2ZWxvcG1lbnQxEjAQBgNVBAgMCUNh\n"
+ "cmludGhpYTELMAkGA1UEBhMCQVQxHjAcBgNVBAcMFVN0LiBKYWtvYiBpbSBSb3Nl\n"
+ "bnRhbDEtMCsGCSqGSIb3DQEJARYeZ3VlbnRlci5vYmlsdHNjaG5pZ0BhcHBpbmYu\n"
+ "Y29tMB4XDTA5MDUwNzE0NTY1NloXDTI5MDUwMjE0NTY1NlowgdMxEzARBgNVBAMM\n"
+ "CmFwcGluZi5jb20xNjA0BgNVBAoMLUFwcGxpZWQgSW5mb3JtYXRpY3MgU29mdHdh\n"
+ "cmUgRW5naW5lZXJpbmcgR21iSDEUMBIGA1UECwwLRGV2ZWxvcG1lbnQxEjAQBgNV\n"
+ "BAgMCUNhcmludGhpYTELMAkGA1UEBhMCQVQxHjAcBgNVBAcMFVN0LiBKYWtvYiBp\n"
+ "bSBSb3NlbnRhbDEtMCsGCSqGSIb3DQEJARYeZ3VlbnRlci5vYmlsdHNjaG5pZ0Bh\n"
+ "cHBpbmYuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA89GolWCR\n"
+ "KtLQclJ2M2QtpFqzNC54hUQdR6n8+DAeruH9WFwLSdWW2fEi+jrtd/WEWCdt4PxX\n"
+ "F2/eBYeURus7Hg2ZtJGDd3je0+Ygsv7+we4cMN/knaBY7rATqhmnZWk+yBpkf5F2\n"
+ "IHp9gBxUaJWmt/bq3XrvTtzrDXpCd4zg4zPXZ8IC8ket5o3K2vnkAOsIsgN+Ffqd\n"
+ "4GjF4dsblG6u6E3VarGRLwGtgB8BAZOA/33mV4FHSMkc4OXpAChaK3tM8YhrLw+m\n"
+ "XtsfqDiv1825S6OWFCKGj/iX8X2QAkrdB63vXCSpb3de/ByIUfp31PpMlMh6dKo1\n"
+ "vf7yj0nb2w0utQIDAQABoyowKDAOBgNVHQ8BAf8EBAMCB4AwFgYDVR0lAQH/BAww\n"
+ "CgYIKwYBBQUHAwMwDQYJKoZIhvcNAQEFBQADggEBAM0cpfb4BgiU/rkYe121P581\n"
+ "ftg5Ck1PYYda1Fy/FgzbgJh2AwVo/6sn6GF79/QkEcWEgtCMNNO3LMTTddUUApuP\n"
+ "jnEimyfmUhIThyud/vryzTMNa/eZMwaAqUQWqLf+AwgqjUsBSMenbSHavzJOpsvR\n"
+ "LI0PQ1VvqB+3UGz0JUnBJiKvHs83Fdm4ewPAf3M5fGcIa+Fl2nU5Plzwzskj84f6\n"
+ "73ZlEEi3aW9JieNy7RWsMM+1E8Sj2CGRZC4BM9V1Fgnsh4+VHX8Eu7eHucvfeIYx\n"
+ "3mmLMoK4sCayL/FGhrUDw5AkWb8tKNpRXY+W60Et281yxQSeWLPIbatVzIWI0/M=\n"
+ "-----END CERTIFICATE-----\n"
+);
+
+
+CryptoTest::CryptoTest(const std::string& name): CppUnit::TestCase(name)
+{
+}
+
+
+CryptoTest::~CryptoTest()
+{
+}
+
+
+void CryptoTest::testEncryptDecrypt()
+{
+ Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(CipherKey("aes256"));
+
+ for (std::size_t n = 1; n < MAX_DATA_SIZE; n++)
+ {
+ std::string in(n, 'x');
+ std::string out = pCipher->encryptString(in, Cipher::ENC_NONE);
+ std::string result = pCipher->decryptString(out, Cipher::ENC_NONE);
+ poco_assert (in == result);
+ }
+
+ for (std::size_t n = 1; n < MAX_DATA_SIZE; n++)
+ {
+ std::string in(n, 'x');
+ std::string out = pCipher->encryptString(in, Cipher::ENC_BASE64);
+ std::string result = pCipher->decryptString(out, Cipher::ENC_BASE64);
+ poco_assert (in == result);
+ }
+
+ for (std::size_t n = 1; n < MAX_DATA_SIZE; n++)
+ {
+ std::string in(n, 'x');
+ std::string out = pCipher->encryptString(in, Cipher::ENC_BINHEX);
+ std::string result = pCipher->decryptString(out, Cipher::ENC_BINHEX);
+ poco_assert (in == result);
+ }
+}
+
+
+void CryptoTest::testEncryptDecryptWithSalt()
+{
+ Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(CipherKey("aes256", "simplepwd", "Too much salt"));
+ Cipher::Ptr pCipher2 = CipherFactory::defaultFactory().createCipher(CipherKey("aes256", "simplepwd", "Too much salt"));
+
+ for (std::size_t n = 1; n < MAX_DATA_SIZE; n++)
+ {
+ std::string in(n, 'x');
+ std::string out = pCipher->encryptString(in, Cipher::ENC_NONE);
+ std::string result = pCipher2->decryptString(out, Cipher::ENC_NONE);
+ poco_assert (in == result);
+ }
+
+ for (std::size_t n = 1; n < MAX_DATA_SIZE; n++)
+ {
+ std::string in(n, 'x');
+ std::string out = pCipher->encryptString(in, Cipher::ENC_BASE64);
+ std::string result = pCipher2->decryptString(out, Cipher::ENC_BASE64);
+ poco_assert (in == result);
+ }
+
+ for (std::size_t n = 1; n < MAX_DATA_SIZE; n++)
+ {
+ std::string in(n, 'x');
+ std::string out = pCipher->encryptString(in, Cipher::ENC_BINHEX);
+ std::string result = pCipher2->decryptString(out, Cipher::ENC_BINHEX);
+ poco_assert (in == result);
+ }
+}
+
+
+void CryptoTest::testStreams()
+{
+ Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(CipherKey("aes256"));
+
+ static const std::string SECRET_MESSAGE = "This is a secret message. Don't tell anyone.";
+
+ std::stringstream sstr;
+ EncryptingOutputStream encryptor(sstr, *pCipher);
+ encryptor << SECRET_MESSAGE;
+ encryptor.close();
+
+ DecryptingInputStream decryptor(sstr, *pCipher);
+ std::string result;
+ Poco::StreamCopier::copyToString(decryptor, result);
+
+ assert (result == SECRET_MESSAGE);
+ assert (decryptor.eof());
+ assert (!decryptor.bad());
+
+
+ std::istringstream emptyStream;
+ DecryptingInputStream badDecryptor(emptyStream, *pCipher);
+ Poco::StreamCopier::copyToString(badDecryptor, result);
+
+ assert (badDecryptor.fail());
+ assert (badDecryptor.bad());
+ assert (!badDecryptor.eof());
+}
+
+
+void CryptoTest::testCertificate()
+{
+ std::istringstream certStream(APPINF_PEM);
+ X509Certificate cert(certStream);
+
+ std::string subjectName(cert.subjectName());
+ std::string issuerName(cert.issuerName());
+ std::string commonName(cert.commonName());
+ std::string country(cert.subjectName(X509Certificate::NID_COUNTRY));
+ std::string localityName(cert.subjectName(X509Certificate::NID_LOCALITY_NAME));
+ std::string stateOrProvince(cert.subjectName(X509Certificate::NID_STATE_OR_PROVINCE));
+ std::string organizationName(cert.subjectName(X509Certificate::NID_ORGANIZATION_NAME));
+ std::string organizationUnitName(cert.subjectName(X509Certificate::NID_ORGANIZATION_UNIT_NAME));
+
+ assert (subjectName == "/CN=appinf.com/O=Applied Informatics Software Engineering GmbH/OU=Development/ST=Carinthia/C=AT/L=St. Jakob im Rosental/emailAddress=guenter.obiltschnig@appinf.com");
+ assert (issuerName == subjectName);
+ assert (commonName == "appinf.com");
+ assert (country == "AT");
+ assert (localityName == "St. Jakob im Rosental");
+ assert (stateOrProvince == "Carinthia");
+ assert (organizationName == "Applied Informatics Software Engineering GmbH");
+ assert (organizationUnitName == "Development");
+
+ assert (cert.issuedBy(cert));
+}
+
+
+void CryptoTest::setUp()
+{
+}
+
+
+void CryptoTest::tearDown()
+{
+}
+
+
+CppUnit::Test* CryptoTest::suite()
+{
+ CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("CryptoTest");
+
+ CppUnit_addTest(pSuite, CryptoTest, testEncryptDecrypt);
+ CppUnit_addTest(pSuite, CryptoTest, testEncryptDecryptWithSalt);
+ CppUnit_addTest(pSuite, CryptoTest, testStreams);
+ CppUnit_addTest(pSuite, CryptoTest, testCertificate);
+
+ return pSuite;
+}
diff --git a/Crypto/testsuite/src/CryptoTest.h b/Crypto/testsuite/src/CryptoTest.h
index e5e427359..13e1a1ec7 100644
--- a/Crypto/testsuite/src/CryptoTest.h
+++ b/Crypto/testsuite/src/CryptoTest.h
@@ -1,62 +1,68 @@
-//
-// CryptoTest.h
-//
-// $Id: //poco/Main/Crypto/testsuite/src/CryptoTest.h#2 $
-//
-// 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 testEncryptDecrypt();
- void testEncryptDecryptWithSalt();
- void testCertificate();
-
- void setUp();
- void tearDown();
-
- static CppUnit::Test* suite();
-
-private:
-};
-
-
-#endif // CryptoTest_INCLUDED
+//
+// CryptoTest.h
+//
+// $Id: //poco/1.4/Crypto/testsuite/src/CryptoTest.h#2 $
+//
+// 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:
+ enum
+ {
+ MAX_DATA_SIZE = 10000
+ };
+
+ CryptoTest(const std::string& name);
+ ~CryptoTest();
+
+ void testEncryptDecrypt();
+ void testEncryptDecryptWithSalt();
+ void testStreams();
+ void testCertificate();
+
+ void setUp();
+ void tearDown();
+
+ static CppUnit::Test* suite();
+
+private:
+};
+
+
+#endif // CryptoTest_INCLUDED
diff --git a/Crypto/testsuite/src/Driver.cpp b/Crypto/testsuite/src/Driver.cpp
index 306368d1d..f3d69cadf 100644
--- a/Crypto/testsuite/src/Driver.cpp
+++ b/Crypto/testsuite/src/Driver.cpp
@@ -1,39 +1,65 @@
-//
-// Driver.cpp
-//
+//
+// 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)
+//
+// 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"
+#include "Poco/Crypto/Crypto.h"
+
+
+class CryptoInitializer
+{
+public:
+ CryptoInitializer()
+ {
+ Poco::Crypto::initializeCrypto();
+ }
+
+ ~CryptoInitializer()
+ {
+ Poco::Crypto::uninitializeCrypto();
+ }
+};
+
+
+int main(int ac, char **av)
+{
+ CryptoInitializer ci;
+
+ std::vector args;
+ for (int i = 0; i < ac; ++i)
+ args.push_back(std::string(av[i]));
+ CppUnit::TestRunner runner;
+ runner.addTest("CryptoTestSuite", CryptoTestSuite::suite());
+ return runner.run(args) ? 0 : 1;
+}
diff --git a/Crypto/testsuite/src/RSATest.cpp b/Crypto/testsuite/src/RSATest.cpp
index dfe3d5013..70ca91c05 100644
--- a/Crypto/testsuite/src/RSATest.cpp
+++ b/Crypto/testsuite/src/RSATest.cpp
@@ -1,229 +1,253 @@
-//
-// RSATest.cpp
-//
+//
+// RSATest.cpp
+//
// $Id: //poco/Main/Crypto/testsuite/src/RSATest.cpp#5 $
-//
-// 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/Crypto/X509Certificate.h"
-#include
-
-
-using namespace Poco::Crypto;
-
-
-static const std::string anyPem(
- "-----BEGIN CERTIFICATE-----\r\n"
- "MIICaDCCAdECCQCzfxSsk7yaLjANBgkqhkiG9w0BAQUFADBzMQswCQYDVQQGEwJB\r\n"
- "VDESMBAGA1UECBMJQ2FyaW50aGlhMRIwEAYDVQQHEwlTdC4gSmFrb2IxDzANBgNV\r\n"
- "BAoTBkFwcEluZjEPMA0GA1UEAxMGQXBwSW5mMRowGAYJKoZIhvcNAQkBFgthcHBA\r\n"
- "aW5mLmNvbTAeFw0wNjAzMDExMzA3MzFaFw0wNjAzMzExMzA3MzFaMH4xCzAJBgNV\r\n"
- "BAYTAkFUMRIwEAYDVQQIEwlDYXJpbnRoaWExETAPBgNVBAcTCFN0IEpha29iMRww\r\n"
- "GgYDVQQKExNBcHBsaWVkIEluZm9ybWF0aWNzMQowCAYDVQQDFAEqMR4wHAYJKoZI\r\n"
- "hvcNAQkBFg9pbmZvQGFwcGluZi5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJ\r\n"
- "AoGBAJHGyXDHyCYoWz+65ltNwwZbhwOGnxr9P1WMATuFJh0bPBZxKbZRdbTm9KhZ\r\n"
- "OlvsEIsfgiYdsxURYIqXfEgISYLZcZY0pQwGEOmB+0NeC/+ENSfOlNSthx6zSVlc\r\n"
- "zhJ7+dJOGwepHAiLr1fRuc5jogYLraE+lKTnqAAFfzwvti77AgMBAAEwDQYJKoZI\r\n"
- "hvcNAQEFBQADgYEAY/ZoeY1ukkEJX7259NeoVM0oahlulWV0rlCqyaeosOiDORPT\r\n"
- "m6X1w/5MTCf9VyaD1zukoSZ4QqNVjHFXcXidbB7Tgt3yRuZ5PC5LIFCDPv9mgPne\r\n"
- "mUA70yfctNfza2z3ZiQ6NDkW3mZX+1tmxYIrJQIrkVeYeqf1Gh2nyZrUMcE=\r\n"
- "-----END CERTIFICATE-----\r\n"
- "-----BEGIN RSA PRIVATE KEY-----\r\n"
- "Proc-Type: 4,ENCRYPTED\r\n"
- "DEK-Info: DES-EDE3-CBC,E7AE93C9E49184EA\r\n"
- "\r\n"
- "A2IqzNcWs+I5vzV+i+woDk56+yr58eU0Onw8eEvXkLjnSc58JU4327IF7yUbKWdW\r\n"
- "Q7BYGGOkVFiZ7ANOwviDg5SUhxRDWCcW8dS6/p1vfdQ1C3qj2OwJjkpg0aDBIzJn\r\n"
- "FzgguT3MF3ama77vxv0S3kOfmCj62MLqPGpj5pQ0/1hefRFbL8oAX8bXUN7/rmGM\r\n"
- "Zc0QyzFZv2iQ04dY/6TNclwKPB4H0On4K+8BMs3PRkWA0clCaQaFO2+iwnk3XZfe\r\n"
- "+MsKUEbLCpAQeYspYv1cw38dCdWq1KTP5aJk+oXgwjfX5cAaPTz74NTqTIsCcaTD\r\n"
- "3vy7ukJYFlDR9Kyo7z8rMazYrKJslhnuRH0BhK9st9McwL957j5tZmrKyraCcmCx\r\n"
- "dMAGcsis1va3ayYZpIpFqA4EhYrTM+6N8ZRfUap20+b5IQwHfTQDejUhL6rBwy7j\r\n"
- "Ti5yD83/itoOMyXq2sV/XWfVD5zk/P5iv22O1EAQMhhnPB9K/I/JhuSGQJfn3cNh\r\n"
- "ykOUYT0+vDeSeEVa+FVEP1W35G0alTbKbNs5Tb8KxJ3iDJUxokM//SvPXZy9hOVX\r\n"
- "Y05imB04J15DaGbAHlNzunhuJi7121WV/JRXZRW9diE6hwpD8rwqi3FMuRUmy7U9\r\n"
- "aFA5poKRAYlo9YtZ3YpFyjGKB6MfCQcB2opuSnQ/gbugV41m67uQ4CDwWLaNRkTb\r\n"
- "GlsMBNcHnidg15Bsat5HaB7l250ukrI13Uw1MYdDUzaS3gPfw9aC4F2w0p3U+DPH\r\n"
- "80/zePxtroR7T4/+rI136Rl+aMXDMOEGCX1TVP8rjuZzuRyUSUKC8Q==\r\n"
- "-----END RSA PRIVATE KEY-----\r\n"
- "-----BEGIN CERTIFICATE-----\r\n"
- "MIICXTCCAcYCCQC1Vk/N8qR4AjANBgkqhkiG9w0BAQUFADBzMQswCQYDVQQGEwJB\r\n"
- "VDESMBAGA1UECBMJQ2FyaW50aGlhMRIwEAYDVQQHEwlTdC4gSmFrb2IxDzANBgNV\r\n"
- "BAoTBkFwcEluZjEPMA0GA1UEAxMGQXBwSW5mMRowGAYJKoZIhvcNAQkBFgthcHBA\r\n"
- "aW5mLmNvbTAeFw0wNjAyMjcxMzI3MThaFw0wNjAzMjkxMzI3MThaMHMxCzAJBgNV\r\n"
- "BAYTAkFUMRIwEAYDVQQIEwlDYXJpbnRoaWExEjAQBgNVBAcTCVN0LiBKYWtvYjEP\r\n"
- "MA0GA1UEChMGQXBwSW5mMQ8wDQYDVQQDEwZBcHBJbmYxGjAYBgkqhkiG9w0BCQEW\r\n"
- "C2FwcEBpbmYuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCsFXiPuicN\r\n"
- "Im4oJwF8NuaFN+lgYwcZ6dAO3ILIR3kLA2PxF8HSQLfF8J8a4odZhLhctIMAKTxm\r\n"
- "k0w8TW5qhL8QLdGzY9vzvkgdKOkan2t3sMeXJAfrM1AphTsmgntAQazGZjOj5p4W\r\n"
- "jDnxQ+VXAylqwjHh49eSBxM3wgoscF4iLQIDAQABMA0GCSqGSIb3DQEBBQUAA4GB\r\n"
- "AIpfLdXiKchPvFMhQS8xTtXvrw5dVL3yImUMYs4GQi8RrjGmfGB3yMAR7B/b8v4a\r\n"
- "+ztfusgWAWiUKuSGTk4S8YB0fsFlmOv0WDr+PyZ4Lui/a8opbyzGE7rqpnF/s0GO\r\n"
- "M7uLCNNwIN7WhmxcWV0KZU1wTppoSWPJda1yTbBzF9XP\r\n"
- "-----END CERTIFICATE-----\r\n"
-);
-
-
-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());
- assert (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());
- assert (!eng2.verify(sig));
-}
-
-
-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()
-{
- std::istringstream str(anyPem);
- X509Certificate cert(str);
-
- 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;
-}
+//
+// 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/Crypto/X509Certificate.h"
+#include
+
+
+using namespace Poco::Crypto;
+
+
+static const std::string anyPem(
+ "-----BEGIN CERTIFICATE-----\r\n"
+ "MIICaDCCAdECCQCzfxSsk7yaLjANBgkqhkiG9w0BAQUFADBzMQswCQYDVQQGEwJB\r\n"
+ "VDESMBAGA1UECBMJQ2FyaW50aGlhMRIwEAYDVQQHEwlTdC4gSmFrb2IxDzANBgNV\r\n"
+ "BAoTBkFwcEluZjEPMA0GA1UEAxMGQXBwSW5mMRowGAYJKoZIhvcNAQkBFgthcHBA\r\n"
+ "aW5mLmNvbTAeFw0wNjAzMDExMzA3MzFaFw0wNjAzMzExMzA3MzFaMH4xCzAJBgNV\r\n"
+ "BAYTAkFUMRIwEAYDVQQIEwlDYXJpbnRoaWExETAPBgNVBAcTCFN0IEpha29iMRww\r\n"
+ "GgYDVQQKExNBcHBsaWVkIEluZm9ybWF0aWNzMQowCAYDVQQDFAEqMR4wHAYJKoZI\r\n"
+ "hvcNAQkBFg9pbmZvQGFwcGluZi5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJ\r\n"
+ "AoGBAJHGyXDHyCYoWz+65ltNwwZbhwOGnxr9P1WMATuFJh0bPBZxKbZRdbTm9KhZ\r\n"
+ "OlvsEIsfgiYdsxURYIqXfEgISYLZcZY0pQwGEOmB+0NeC/+ENSfOlNSthx6zSVlc\r\n"
+ "zhJ7+dJOGwepHAiLr1fRuc5jogYLraE+lKTnqAAFfzwvti77AgMBAAEwDQYJKoZI\r\n"
+ "hvcNAQEFBQADgYEAY/ZoeY1ukkEJX7259NeoVM0oahlulWV0rlCqyaeosOiDORPT\r\n"
+ "m6X1w/5MTCf9VyaD1zukoSZ4QqNVjHFXcXidbB7Tgt3yRuZ5PC5LIFCDPv9mgPne\r\n"
+ "mUA70yfctNfza2z3ZiQ6NDkW3mZX+1tmxYIrJQIrkVeYeqf1Gh2nyZrUMcE=\r\n"
+ "-----END CERTIFICATE-----\r\n"
+ "-----BEGIN RSA PRIVATE KEY-----\r\n"
+ "Proc-Type: 4,ENCRYPTED\r\n"
+ "DEK-Info: DES-EDE3-CBC,E7AE93C9E49184EA\r\n"
+ "\r\n"
+ "A2IqzNcWs+I5vzV+i+woDk56+yr58eU0Onw8eEvXkLjnSc58JU4327IF7yUbKWdW\r\n"
+ "Q7BYGGOkVFiZ7ANOwviDg5SUhxRDWCcW8dS6/p1vfdQ1C3qj2OwJjkpg0aDBIzJn\r\n"
+ "FzgguT3MF3ama77vxv0S3kOfmCj62MLqPGpj5pQ0/1hefRFbL8oAX8bXUN7/rmGM\r\n"
+ "Zc0QyzFZv2iQ04dY/6TNclwKPB4H0On4K+8BMs3PRkWA0clCaQaFO2+iwnk3XZfe\r\n"
+ "+MsKUEbLCpAQeYspYv1cw38dCdWq1KTP5aJk+oXgwjfX5cAaPTz74NTqTIsCcaTD\r\n"
+ "3vy7ukJYFlDR9Kyo7z8rMazYrKJslhnuRH0BhK9st9McwL957j5tZmrKyraCcmCx\r\n"
+ "dMAGcsis1va3ayYZpIpFqA4EhYrTM+6N8ZRfUap20+b5IQwHfTQDejUhL6rBwy7j\r\n"
+ "Ti5yD83/itoOMyXq2sV/XWfVD5zk/P5iv22O1EAQMhhnPB9K/I/JhuSGQJfn3cNh\r\n"
+ "ykOUYT0+vDeSeEVa+FVEP1W35G0alTbKbNs5Tb8KxJ3iDJUxokM//SvPXZy9hOVX\r\n"
+ "Y05imB04J15DaGbAHlNzunhuJi7121WV/JRXZRW9diE6hwpD8rwqi3FMuRUmy7U9\r\n"
+ "aFA5poKRAYlo9YtZ3YpFyjGKB6MfCQcB2opuSnQ/gbugV41m67uQ4CDwWLaNRkTb\r\n"
+ "GlsMBNcHnidg15Bsat5HaB7l250ukrI13Uw1MYdDUzaS3gPfw9aC4F2w0p3U+DPH\r\n"
+ "80/zePxtroR7T4/+rI136Rl+aMXDMOEGCX1TVP8rjuZzuRyUSUKC8Q==\r\n"
+ "-----END RSA PRIVATE KEY-----\r\n"
+ "-----BEGIN CERTIFICATE-----\r\n"
+ "MIICXTCCAcYCCQC1Vk/N8qR4AjANBgkqhkiG9w0BAQUFADBzMQswCQYDVQQGEwJB\r\n"
+ "VDESMBAGA1UECBMJQ2FyaW50aGlhMRIwEAYDVQQHEwlTdC4gSmFrb2IxDzANBgNV\r\n"
+ "BAoTBkFwcEluZjEPMA0GA1UEAxMGQXBwSW5mMRowGAYJKoZIhvcNAQkBFgthcHBA\r\n"
+ "aW5mLmNvbTAeFw0wNjAyMjcxMzI3MThaFw0wNjAzMjkxMzI3MThaMHMxCzAJBgNV\r\n"
+ "BAYTAkFUMRIwEAYDVQQIEwlDYXJpbnRoaWExEjAQBgNVBAcTCVN0LiBKYWtvYjEP\r\n"
+ "MA0GA1UEChMGQXBwSW5mMQ8wDQYDVQQDEwZBcHBJbmYxGjAYBgkqhkiG9w0BCQEW\r\n"
+ "C2FwcEBpbmYuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCsFXiPuicN\r\n"
+ "Im4oJwF8NuaFN+lgYwcZ6dAO3ILIR3kLA2PxF8HSQLfF8J8a4odZhLhctIMAKTxm\r\n"
+ "k0w8TW5qhL8QLdGzY9vzvkgdKOkan2t3sMeXJAfrM1AphTsmgntAQazGZjOj5p4W\r\n"
+ "jDnxQ+VXAylqwjHh49eSBxM3wgoscF4iLQIDAQABMA0GCSqGSIb3DQEBBQUAA4GB\r\n"
+ "AIpfLdXiKchPvFMhQS8xTtXvrw5dVL3yImUMYs4GQi8RrjGmfGB3yMAR7B/b8v4a\r\n"
+ "+ztfusgWAWiUKuSGTk4S8YB0fsFlmOv0WDr+PyZ4Lui/a8opbyzGE7rqpnF/s0GO\r\n"
+ "M7uLCNNwIN7WhmxcWV0KZU1wTppoSWPJda1yTbBzF9XP\r\n"
+ "-----END CERTIFICATE-----\r\n"
+);
+
+
+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(), static_cast(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(), static_cast(msg.length()));
+ assert (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(), static_cast(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(), static_cast(msgManip.length()));
+ assert (!eng2.verify(sig));
+}
+
+
+void RSATest::testRSACipher()
+{
+ Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(RSAKey(RSAKey::KL_1024, RSAKey::EXP_SMALL));
+ for (std::size_t n = 1; n <= 1200; n++)
+ {
+ std::string val(n, 'x');
+ std::string enc = pCipher->encryptString(val);
+ std::string dec = pCipher->decryptString(enc);
+ assert (dec == val);
+ }
+}
+
+
+void RSATest::testRSACipherLarge()
+{
+ std::vector sizes;
+ sizes.push_back (2047);
+ sizes.push_back (2048);
+ sizes.push_back (2049);
+ sizes.push_back (4095);
+ sizes.push_back (4096);
+ sizes.push_back (4097);
+ sizes.push_back (8191);
+ sizes.push_back (8192);
+ sizes.push_back (8193);
+ sizes.push_back (16383);
+ sizes.push_back (16384);
+ sizes.push_back (16385);
+
+ Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(RSAKey(RSAKey::KL_1024, RSAKey::EXP_SMALL));
+ for (std::vector::const_iterator it = sizes.begin(); it != sizes.end(); ++it)
+ {
+ std::string val(*it, 'x');
+ std::string enc = pCipher->encryptString(val);
+ std::string dec = pCipher->decryptString(enc);
+ assert (dec == val);
+ }
+}
+
+
+void RSATest::testCertificate()
+{
+ std::istringstream str(anyPem);
+ X509Certificate cert(str);
+ RSAKey publicKey(cert);
+ std::istringstream str2(anyPem);
+ RSAKey privateKey(0, &str2, "test");
+ Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(publicKey);
+ Cipher::Ptr pCipher2 = CipherFactory::defaultFactory().createCipher(privateKey);
+ std::string val("lets do some encryption");
+
+ std::string enc = pCipher->encryptString(val);
+ std::string dec = pCipher2->decryptString(enc);
+ assert (dec == 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, testRSACipher);
+ CppUnit_addTest(pSuite, RSATest, testRSACipherLarge);
+ CppUnit_addTest(pSuite, RSATest, testCertificate);
+
+ return pSuite;
+}
diff --git a/Crypto/testsuite/src/RSATest.h b/Crypto/testsuite/src/RSATest.h
index 7d76e7fc0..48aed503a 100644
--- a/Crypto/testsuite/src/RSATest.h
+++ b/Crypto/testsuite/src/RSATest.h
@@ -1,65 +1,65 @@
-//
-// RSATest.h
-//
+//
+// 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
+//
+// 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 testRSACipher();
+ void testRSACipherLarge();
+ void testCertificate();
+
+ void setUp();
+ void tearDown();
+
+ static CppUnit::Test* suite();
+
+private:
+};
+
+
+#endif // RSATest_INCLUDED
diff --git a/Crypto/testsuite/src/WinCEDriver.cpp b/Crypto/testsuite/src/WinCEDriver.cpp
new file mode 100644
index 000000000..411e320e8
--- /dev/null
+++ b/Crypto/testsuite/src/WinCEDriver.cpp
@@ -0,0 +1,70 @@
+//
+// WinCEDriver.cpp
+//
+// $Id: //poco/1.4/Crypto/testsuite/src/WinCEDriver.cpp#1 $
+//
+// Console-based test driver for Windows CE.
+//
+// Copyright (c) 2004-2010, 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"
+#include "Poco/Crypto/Crypto.h"
+#include
+
+
+class CryptoInitializer
+{
+public:
+ CryptoInitializer()
+ {
+ Poco::Crypto::initializeCrypto();
+ }
+
+ ~CryptoInitializer()
+ {
+ Poco::Crypto::uninitializeCrypto();
+ }
+};
+
+
+int _tmain(int argc, wchar_t* argv[])
+{
+ CryptoInitializer ci;
+
+ std::vector args;
+ for (int i = 0; i < argc; ++i)
+ {
+ char buffer[1024];
+ std::wcstombs(buffer, argv[i], sizeof(buffer));
+ args.push_back(std::string(buffer));
+ }
+ CppUnit::TestRunner runner;
+ runner.addTest("CryptoTestSuite", CryptoTestSuite::suite());
+ return runner.run(args) ? 0 : 1;
+}
diff --git a/Crypto/testsuite/src/WinDriver.cpp b/Crypto/testsuite/src/WinDriver.cpp
index 8aaf22503..8f8ea9137 100644
--- a/Crypto/testsuite/src/WinDriver.cpp
+++ b/Crypto/testsuite/src/WinDriver.cpp
@@ -1,50 +1,68 @@
-//
-// WinDriver.cpp
-//
+//
+// 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;
+//
+// 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"
+#include "Poco/Crypto/Crypto.h"
+
+
+class CryptoInitializer
+{
+public:
+ CryptoInitializer()
+ {
+ Poco::Crypto::initializeCrypto();
+ }
+
+ ~CryptoInitializer()
+ {
+ Poco::Crypto::uninitializeCrypto();
+ }
+};
+
+
+class TestDriver: public CppUnit::WinTestRunnerApp
+{
+ void TestMain()
+ {
+ CryptoInitializer ci;
+
+ CppUnit::WinTestRunner runner;
+ runner.addTest(CryptoTestSuite::suite());
+ runner.run();
+ }
+};
+
+
+TestDriver theDriver;